From 57a36716cfc0fdac0658bd9317e28e28d4d29f68 Mon Sep 17 00:00:00 2001 From: Raymond Mao Date: Mon, 31 Mar 2025 15:40:09 -0700 Subject: [PATCH 1/2] bloblist: fix the overriding of fdt from bloblist When a bloblist is valid and contains fdt, it explicitly means a previous boot stage is passing transfer list compliant with Firmware Handoff specification, thus the fdt from bloblist should not be overridden with the ones from board or env variables. Fixes: 70fe23859437 ("fdt: Allow the devicetree to come from a bloblist") Signed-off-by: Raymond Mao Reviewed-by: Caleb Connolly Reviewed-by: Ilias Apalodimas Reviewed-by: Simon Glass --- lib/fdtdec.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/fdtdec.c b/lib/fdtdec.c index f09c9926a7a..c38738b48c7 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -1708,7 +1708,7 @@ int fdtdec_setup(void) gd->fdt_src = FDTSRC_BLOBLIST; log_debug("Devicetree is in bloblist at %p\n", gd->fdt_blob); - ret = 0; + goto setup_fdt; } else { log_debug("No FDT found in bloblist\n"); ret = -ENOENT; @@ -1752,6 +1752,7 @@ int fdtdec_setup(void) } } +setup_fdt: if (CONFIG_IS_ENABLED(MULTI_DTB_FIT)) setup_multi_dtb_fit(); From bd5dde0346c3e57634c98cc7a8150606d92d8d38 Mon Sep 17 00:00:00 2001 From: Raymond Mao Date: Mon, 31 Mar 2025 15:40:10 -0700 Subject: [PATCH 2/2] env: point fdt address to the fdt in a bloblist Point fdt_addr to the fdt embedded in the bloblist since fdt_addr is a default address for bootefi, bootm and booti to look for the device tree when launching the kernel. Signed-off-by: Raymond Mao --- env/common.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/env/common.c b/env/common.c index a58955a4f42..86122582bc1 100644 --- a/env/common.c +++ b/env/common.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -368,6 +369,18 @@ int env_get_default_into(const char *name, char *buf, unsigned int len) return env_get_from_linear(default_environment, name, buf, len); } +static int env_update_fdt_addr_from_bloblist(void) +{ + /* + * fdt_addr is by default used by booti, bootm and bootefi, + * thus set it to point to the fdt embedded in a bloblist if it exists. + */ + if (!CONFIG_IS_ENABLED(BLOBLIST) || gd->fdt_src != FDTSRC_BLOBLIST) + return 0; + + return env_set_hex("fdt_addr", (uintptr_t)map_to_sysmem(gd->fdt_blob)); +} + void env_set_default(const char *s, int flags) { if (s) { @@ -392,6 +405,10 @@ void env_set_default(const char *s, int flags) gd->flags |= GD_FLG_ENV_READY; gd->flags |= GD_FLG_ENV_DEFAULT; + + /* This has to be done after GD_FLG_ENV_READY is set */ + if (env_update_fdt_addr_from_bloblist()) + pr_err("Failed to set fdt_addr to point at DTB\n"); } /* [re]set individual variables to their value in the default environment */ @@ -437,7 +454,9 @@ int env_import(const char *buf, int check, int flags) if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '\0', flags, 0, 0, NULL)) { gd->flags |= GD_FLG_ENV_READY; - return 0; + + /* This has to be done after GD_FLG_ENV_READY is set */ + return env_update_fdt_addr_from_bloblist(); } pr_err("Cannot import environment: errno = %d\n", errno);