public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Alexandru Gagniuc <mr.nuke.me@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH 3/6] spl: LOAD_FIT_FULL: Relocate FDT for u-boot payloads
Date: Thu, 11 Mar 2021 15:32:06 -0600	[thread overview]
Message-ID: <20210311213209.4013010-4-mr.nuke.me@gmail.com> (raw)
In-Reply-To: <20210311213209.4013010-1-mr.nuke.me@gmail.com>

U-Boot expects the FDT to be located right after the _end
linker symbol (see fdtdec.c: board_fdt_blob_setup())

The "basic" LOAD_FIT path is aware of this limitation, and relocates
the FDT at the expected location. Guessing the expected location
probably only works reliably on 32-bit arm, and it feels like a hack.
One proposal would be to pass the FDT address to u-boot
(e.g. using 'r2' on arm platforms).

The variable is named "fdt_hack" to remind future contributors that,
"hey! we should fix the underlying problem". However, that is beyond
the scope of this patch.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
---
 common/spl/spl.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 8f6c8dba6f..e63f05bb33 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -201,6 +201,7 @@ static int spl_load_fit_image(struct spl_image_info *spl_image,
 {
 	bootm_headers_t images;
 	const char *fit_uname_config = NULL;
+	uintptr_t fdt_hack;
 	const char *uname;
 	ulong fw_data = 0, dt_data = 0, img_data = 0;
 	ulong fw_len = 0, dt_len = 0, img_len = 0;
@@ -233,9 +234,18 @@ static int spl_load_fit_image(struct spl_image_info *spl_image,
 	ret = fit_image_load(&images, (ulong)header, NULL, &fit_uname_config,
 		       IH_ARCH_DEFAULT, IH_TYPE_FLATDT, -1,
 		       FIT_LOAD_OPTIONAL, &dt_data, &dt_len);
-	if (ret >= 0)
+	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);
+		}
+	}
+
 	conf_noffset = fit_conf_get_node((const void *)header,
 					 fit_uname_config);
 	if (conf_noffset <= 0)
-- 
2.26.2

  parent reply	other threads:[~2021-03-11 21:32 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11 21:32 [PATCH 0/6] SPL: FIT: Fix some omissions of SPL_LOAD_FIT_FULL and bootm Alexandru Gagniuc
2021-03-11 21:32 ` [PATCH 1/6] spl: LOAD_FIT_FULL: Fix selection of the "fdt" node Alexandru Gagniuc
2021-03-29  7:43   ` Simon Glass
2021-03-11 21:32 ` [PATCH 2/6] spl: LOAD_FIT_FULL: Do not hard-code os to IH_OS_U_BOOT Alexandru Gagniuc
2021-03-29  7:43   ` Simon Glass
2021-03-30 17:54     ` Alex G.
2021-04-14 19:38       ` Simon Glass
2021-03-11 21:32 ` Alexandru Gagniuc [this message]
2021-03-29  7:43   ` [PATCH 3/6] spl: LOAD_FIT_FULL: Relocate FDT for u-boot payloads Simon Glass
2021-03-29 17:36     ` Alex G.
2021-03-11 21:32 ` [PATCH 4/6] spl: LOAD_FIT_FULL: Support 'kernel' and 'firmware' properties Alexandru Gagniuc
2021-03-29  7:43   ` Simon Glass
2021-03-29 17:49     ` Alex G.
2021-03-11 21:32 ` [PATCH 5/6] image-fit: Accept IH_TYPE_FIRMWARE in fit_image_load() as valid Alexandru Gagniuc
2021-03-29  7:43   ` Simon Glass
2021-03-11 21:32 ` [PATCH 6/6] image-fit: Accept OP-TEE images when booting a FIT Alexandru Gagniuc
2021-03-29  7:43   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210311213209.4013010-4-mr.nuke.me@gmail.com \
    --to=mr.nuke.me@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox