[PATCH 03/15] vbe: Allocate space for the FIT header
Simon Glass
sjg at chromium.org
Thu Jan 9 13:29:58 CET 2025
It is convenient to use TEXT_BASE as a place to hold the FIT header, but
this does not work in VPL, since SDRAM is not inited yet.
Allocate the memory instead. Ensure the size is aligned to the media
block-size so that it can be read in directly. Improve the
error-checking for blk_read() and add some more debugging.
Keep the existing TEXT_BASE mechanism in sandbox to avoid an
'Exec format error' when trying to run the image.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
boot/vbe_common.c | 36 ++++++++++++++++++++++++++++--------
1 file changed, 28 insertions(+), 8 deletions(-)
diff --git a/boot/vbe_common.c b/boot/vbe_common.c
index c009337ef3f..d2d20cabe00 100644
--- a/boot/vbe_common.c
+++ b/boot/vbe_common.c
@@ -27,6 +27,7 @@ int vbe_read_fit(struct udevice *blk, ulong area_offset, ulong area_size,
struct bootm_headers images = {};
enum image_phase_t phase;
struct blk_desc *desc;
+ ulong aligned_size;
int node, ret;
void *buf;
@@ -46,20 +47,37 @@ int vbe_read_fit(struct udevice *blk, ulong area_offset, ulong area_size,
if (size > area_size)
return log_msg_ret("fdt", -E2BIG);
log_debug("FIT size %lx\n", size);
+ aligned_size = ALIGN(size, desc->blksz);
/*
* Load the FIT into the SPL memory. This is typically a FIT with
* external data, so this is quite small, perhaps a few KB.
*/
- addr = CONFIG_VAL(TEXT_BASE);
- buf = map_sysmem(addr, size);
- num_blks = DIV_ROUND_UP(size, desc->blksz);
- log_debug("read %lx, %lx blocks to %lx / %p\n", size, num_blks, addr,
- buf);
+ if (IS_ENABLED(CONFIG_SANDBOX)) {
+ addr = CONFIG_VAL(TEXT_BASE);
+ buf = map_sysmem(addr, size);
+ } else {
+ buf = malloc(aligned_size);
+ if (!buf)
+ return log_msg_ret("fit", -ENOMEM);
+ addr = map_to_sysmem(buf);
+ }
+ num_blks = aligned_size / desc->blksz;
+ log_debug("read %lx, %lx blocks to %lx / %p\n", aligned_size, num_blks,
+ addr, buf);
ret = blk_read(blk, blknum, num_blks, buf);
if (ret < 0)
- return log_msg_ret("rd", ret);
-
+ return log_msg_ret("rd3", ret);
+ else if (ret != num_blks)
+ return log_msg_ret("rd4", -EIO);
+ log_debug("check total size %x off_dt_strings %x\n", fdt_totalsize(buf),
+ fdt_off_dt_strings(buf));
+
+#if CONFIG_IS_ENABLED(SYS_MALLOC_F)
+ log_debug("malloc base %lx ptr %x limit %x top %lx\n",
+ gd->malloc_base, gd->malloc_ptr, gd->malloc_limit,
+ gd->malloc_base + gd->malloc_limit);
+#endif
/* figure out the phase to load */
phase = IS_ENABLED(CONFIG_VPL_BUILD) ? IH_PHASE_SPL : IH_PHASE_U_BOOT;
@@ -82,7 +100,9 @@ int vbe_read_fit(struct udevice *blk, ulong area_offset, ulong area_size,
log_debug("loaded to %lx\n", load_addr);
/* For FIT external data, read in the external data */
- if (load_addr + len > addr + size) {
+ log_debug("load_addr %lx len %lx addr %lx aligned_size %lx\n",
+ load_addr, len, addr, aligned_size);
+ if (load_addr + len > addr + aligned_size) {
ulong base, full_size;
void *base_buf;
--
2.34.1
More information about the U-Boot
mailing list