diff options
| author | Tom Rini <[email protected]> | 2026-06-17 14:25:13 -0600 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-06-17 14:25:13 -0600 |
| commit | 298d44464dc63a4f3f5489150acd7958f359f9bd (patch) | |
| tree | ec957d141f83eace08ffb8730cee5125a6e2aed3 | |
| parent | 3838059689b28747533b56f535bce45798f69870 (diff) | |
| parent | e41a770f3800f9c0d2f74fedc04eea09a29a3776 (diff) | |
Merge patch series "Fixes, cleanup and a test for the SPL FIT "full" loader"
Francesco Valla <[email protected]> says:
This patch set contains a collection of small fixes and cleanups for the
"full" FIT loader that can be used for the SPL. The main beneficiary is
the falcon boot flow, but the same loader can be used also for U-Boot
proper.
Patch 1 was part of another set, but I decided to put it here for a
better separation between plumbing (here) and new features (there). I
kept the Reviewed-by tag collected from Simon in that occasion.
Patch 6 introduces a new unit test covering most of the code that is
being cleaned up.
The set was tested on a i.MX93 FRDM, both with and without signature and
to boot both U-Boot proper and the Linux kernel directly (i.e., falcon
boot).
Link: https://lore.kernel.org/r/[email protected]
| -rw-r--r-- | arch/sandbox/cpu/spl.c | 37 | ||||
| -rw-r--r-- | arch/sandbox/include/asm/spl.h | 14 | ||||
| -rw-r--r-- | boot/image-fit.c | 2 | ||||
| -rw-r--r-- | common/spl/spl_fit.c | 47 | ||||
| -rw-r--r-- | test/image/spl_load_os.c | 11 |
5 files changed, 81 insertions, 30 deletions
diff --git a/arch/sandbox/cpu/spl.c b/arch/sandbox/cpu/spl.c index 7ee4975523e..1668b58d3fb 100644 --- a/arch/sandbox/cpu/spl.c +++ b/arch/sandbox/cpu/spl.c @@ -265,6 +265,43 @@ int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image) return 0; } +int sandbox_spl_load_fit_full(char *fname, int maxlen, + struct spl_image_info *image) +{ + struct legacy_img_hdr *header; + long long size; + int ret; + int fd; + + ret = sandbox_find_next_phase(fname, maxlen, true); + if (ret) { + printf("%s not found, error %d\n", fname, ret); + return log_msg_ret("nph", ret); + } + + log_debug("reading from %s\n", fname); + fd = os_open(fname, OS_O_RDONLY); + if (fd < 0) { + printf("Failed to open '%s'\n", fname); + return log_msg_ret("ope", -errno); + } + + if (os_get_filesize(fname, &size)) + return log_msg_ret("fis", -ENOENT); + + header = spl_get_load_buffer(0, size); + + if (os_read(fd, header, size) != size) + return log_msg_ret("rea", -EIO); + os_close(fd); + + ret = spl_load_fit_image(image, header); + if (ret) + return log_msg_ret("slf", ret); + + return 0; +} + static int upl_load_from_image(struct spl_image_info *spl_image, struct spl_boot_device *bootdev) { diff --git a/arch/sandbox/include/asm/spl.h b/arch/sandbox/include/asm/spl.h index d824b2123a2..49a613ba92d 100644 --- a/arch/sandbox/include/asm/spl.h +++ b/arch/sandbox/include/asm/spl.h @@ -46,4 +46,18 @@ int sandbox_find_next_phase(char *fname, int maxlen, bool use_img); */ int sandbox_spl_load_fit(char *fname, int maxlen, struct spl_image_info *image); +/** + * sandbox_spl_load_fit_full() - Load the next phase from a FIT with the "full" loader + * + * Loads a FIT containing the next phase and sets it up for booting, using the + * "full" FIT loader + * + * @fname: Returns filename loaded + * @maxlen: Maximum length for @fname including \0 + * @image: Place to put SPL-image information + * Return: 0 if OK, -ve on error + */ +int sandbox_spl_load_fit_full(char *fname, int maxlen, + struct spl_image_info *image); + #endif diff --git a/boot/image-fit.c b/boot/image-fit.c index 937654b6223..044a40e1910 100644 --- a/boot/image-fit.c +++ b/boot/image-fit.c @@ -1492,7 +1492,7 @@ int fit_image_verify(const void *fit, int image_noffset) size_t size; char *err_msg = ""; - if (IS_ENABLED(CONFIG_FIT_SIGNATURE) && strchr(name, '@')) { + if (CONFIG_IS_ENABLED(FIT_SIGNATURE) && strchr(name, '@')) { /* * We don't support this since libfdt considers names with the * name root but different @ suffix to be equal diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index 46ebcabe56a..d89384449b3 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -775,7 +775,7 @@ static int spl_simple_fit_parse(struct spl_fit_info *ctx) if (ctx->conf_node < 0) return -EINVAL; - if (IS_ENABLED(CONFIG_SPL_FIT_SIGNATURE)) { + if (CONFIG_IS_ENABLED(FIT_SIGNATURE)) { printf("## Checking hash(es) for config %s ... ", fit_get_name(ctx->fit, ctx->conf_node, NULL)); if (fit_config_verify(ctx->fit, ctx->conf_node)) @@ -955,22 +955,12 @@ int spl_load_fit_image(struct spl_image_info *spl_image, int idx, conf_noffset; int ret; -#ifdef CONFIG_SPL_FIT_SIGNATURE - images.verify = 1; -#endif + images.verify = CONFIG_IS_ENABLED(FIT_SIGNATURE); + ret = fit_image_load(&images, virt_to_phys((void *)header), - NULL, &fit_uname_config, - IH_ARCH_DEFAULT, IH_TYPE_STANDALONE, -1, - FIT_LOAD_OPTIONAL, &fw_data, &fw_len); - if (ret >= 0) { - printf("DEPRECATED: 'standalone = ' property."); - printf("Please use either 'firmware =' or 'kernel ='\n"); - } else { - ret = fit_image_load(&images, virt_to_phys((void *)header), - NULL, &fit_uname_config, IH_ARCH_DEFAULT, - IH_TYPE_FIRMWARE, -1, FIT_LOAD_OPTIONAL, - &fw_data, &fw_len); - } + NULL, &fit_uname_config, IH_ARCH_DEFAULT, + IH_TYPE_FIRMWARE, -1, FIT_LOAD_OPTIONAL, + &fw_data, &fw_len); if (ret < 0) { ret = fit_image_load(&images, virt_to_phys((void *)header), @@ -993,21 +983,21 @@ int spl_load_fit_image(struct spl_image_info *spl_image, debug(PHASE_PROMPT "payload image: %32s load addr: 0x%lx size: %d\n", spl_image->name, spl_image->load_addr, spl_image->size); -#ifdef CONFIG_SPL_FIT_SIGNATURE - images.verify = 1; -#endif + images.verify = CONFIG_IS_ENABLED(FIT_SIGNATURE); + ret = fit_image_load(&images, virt_to_phys((void *)header), NULL, &fit_uname_config, IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1, FIT_LOAD_OPTIONAL, &dt_data, &dt_len); if (ret >= 0) { - spl_image->fdt_addr = (void *)dt_data; - if (spl_image->os == IH_OS_U_BOOT) { /* HACK: U-Boot expects FDT at a specific address */ - fdt_hack = spl_image->load_addr + spl_image->size; - fdt_hack = (fdt_hack + 3) & ~3; - debug("Relocating FDT to %p\n", spl_image->fdt_addr); - memcpy((void *)fdt_hack, spl_image->fdt_addr, dt_len); + fdt_hack = ALIGN(spl_image->load_addr + spl_image->size, 8); + debug("Relocating FDT to %p\n", (void *)fdt_hack); + memcpy(map_sysmem(fdt_hack, dt_len), + map_sysmem(dt_data, 0), dt_len); + spl_image->fdt_addr = (void *)fdt_hack; + } else { + spl_image->fdt_addr = (void *)dt_data; } } @@ -1021,10 +1011,9 @@ int spl_load_fit_image(struct spl_image_info *spl_image, FIT_LOADABLE_PROP, idx, NULL), uname; idx++) { -#ifdef CONFIG_SPL_FIT_SIGNATURE - images.verify = 1; -#endif - ret = fit_image_load(&images, (ulong)header, + images.verify = CONFIG_IS_ENABLED(FIT_SIGNATURE); + + ret = fit_image_load(&images, virt_to_phys((void *)header), &uname, &fit_uname_config, IH_ARCH_DEFAULT, IH_TYPE_LOADABLE, -1, FIT_LOAD_OPTIONAL_NON_ZERO, diff --git a/test/image/spl_load_os.c b/test/image/spl_load_os.c index d17cf116a0e..ba9d7979a09 100644 --- a/test/image/spl_load_os.c +++ b/test/image/spl_load_os.c @@ -21,3 +21,14 @@ static int spl_test_load(struct unit_test_state *uts) } SPL_TEST(spl_test_load, 0); +static int spl_test_load_fit_full(struct unit_test_state *uts) +{ + struct spl_image_info image; + char fname[256]; + + ut_assertok(sandbox_spl_load_fit_full(fname, sizeof(fname), &image)); + + return 0; +} +SPL_TEST(spl_test_load_fit_full, 0); + |
