From 00fc82f17cff9295387d516384ecdc443acb1b22 Mon Sep 17 00:00:00 2001 From: Bradley Morgan Date: Sat, 3 Oct 2026 18:57:38 +0000 Subject: tashaboot: arm64 bringup, semihosting payload loader consoles on the pl011 the dtb points at, walks the memory node and chosen, loads an arm64 kernel Image over semihosting and jumps to it with the documented register state. string functions, printf and libfdt are vendored from lk (lk2nd) and u-boot so the libc surface is the one those projects already proved. built and booted on qemu virt, payload exits clean through semihosting. --- common/load.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 common/load.c (limited to 'common/load.c') diff --git a/common/load.c b/common/load.c new file mode 100644 index 0000000..4669c0b --- /dev/null +++ b/common/load.c @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * load.c - pull the payload into RAM. semihosting is the qemu path, + * flash and block devices follow the same shape once they exist. + * + * Copyright (C) 2026 Bradley Morgan + */ + +#include +#include +#include +#include +#include + +/* + * load fname into mem_base. the header decides the real placement, so + * we read the whole file first and let tb_image_setup place it. + */ +int tb_load_semihosting(const char *fname, uintptr_t load_addr, + uintptr_t mem_base, uint32 mem_size, + struct tb_image *img) +{ + struct Image_header *ih = (struct Image_header *)load_addr; + long fd; + long len; + long ret; + + fd = smh_open(fname, MODE_READ | MODE_BINARY); + if (fd < 0) + return fd; + + len = smh_flen(fd); + if (len < 0) { + smh_close(fd); + return len; + } + + if ((uint32)len > mem_size) { + smh_close(fd); + return -2; + } + + /* header first so placement is known before the big copy */ + ret = smh_read(fd, (void *)load_addr, sizeof(*ih)); + if (ret != sizeof(*ih)) { + smh_close(fd); + return -3; + } + + if (tb_image_setup(load_addr, mem_base, mem_size, img)) { + smh_close(fd); + return -4; + } + + if (img->load != load_addr) { + /* the image wants to sit elsewhere, copy it there */ + memmove((void *)img->load, (void *)load_addr, + sizeof(*ih)); + } + + ret = smh_read(fd, (void *)(img->load + sizeof(*ih)), + len - sizeof(*ih)); + if (ret != len - sizeof(*ih)) { + smh_close(fd); + return -5; + } + + smh_close(fd); + return 0; +} -- cgit v1.2.3