U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Cc: Fabio Estevam <festevam@nabladev.com>,
	Jonas Karlman <jonas@kwiboo.se>, Simon Glass <sjg@chromium.org>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Jeffy Chen <jeffy.chen@rock-chips.com>,
	Kever Yang <kever.yang@rock-chips.com>,
	Philipp Tomsich <philipp.tomsich@vrull.eu>,
	Tom Rini <trini@konsulko.com>, huang lin <hl@rock-chips.com>
Subject: [PATCH v3 15/15] rockchip: Support legacy images when booting from RAM
Date: Tue,  7 Jul 2026 09:31:13 -0600	[thread overview]
Message-ID: <20260707153135.2048115-16-sjg@chromium.org> (raw)
In-Reply-To: <20260707153135.2048115-1-sjg@chromium.org>

The ramboot loader used for maskrom-mode USB boot only handles FIT
payloads, but the maskrom usb472 image contains a legacy image on
32-bit boards without OP-TEE, since the FIT template requires either
TF-A or OP-TEE. Such boards print 'Trying to boot from RAM' and then
hang.

Use the binman payload symbols to locate a legacy image placed
directly after SPL and load it with spl_load(). This allows boards
like the Luckfox Pico Mini and the Omega4 to run U-Boot entirely from
RAM in maskrom mode

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 arch/arm/mach-rockchip/spl.c | 53 +++++++++++++++++++++++-------------
 1 file changed, 34 insertions(+), 19 deletions(-)

diff --git a/arch/arm/mach-rockchip/spl.c b/arch/arm/mach-rockchip/spl.c
index e989c148079..1322fc000b0 100644
--- a/arch/arm/mach-rockchip/spl.c
+++ b/arch/arm/mach-rockchip/spl.c
@@ -14,6 +14,7 @@
 #include <mapmem.h>
 #include <ram.h>
 #include <spl.h>
+#include <spl_load.h>
 #include <asm/arch-rockchip/bootrom.h>
 #include <asm/arch-rockchip/timer.h>
 #include <asm/global_data.h>
@@ -153,15 +154,14 @@ void spl_board_prepare_for_boot(void)
 	cleanup_before_linux();
 }
 
-#if CONFIG_IS_ENABLED(RAM_DEVICE) && IS_ENABLED(CONFIG_SPL_LOAD_FIT)
+#if CONFIG_IS_ENABLED(RAM_DEVICE)
 binman_sym_declare_optional(ulong, payload, image_pos);
 binman_sym_declare_optional(ulong, payload, size);
 
 static ulong ramboot_load_read(struct spl_load_info *load, ulong sector,
 			       ulong count, void *buf)
 {
-	ulong addr = IF_ENABLED_INT(CONFIG_SPL_LOAD_FIT,
-				    CONFIG_SPL_LOAD_FIT_ADDRESS);
+	ulong addr = (ulong)load->priv;
 
 	memcpy(buf, map_sysmem(addr + sector, 0), count);
 	return count;
@@ -170,29 +170,44 @@ static ulong ramboot_load_read(struct spl_load_info *load, ulong sector,
 static int ramboot_load_image(struct spl_image_info *spl_image,
 			      struct spl_boot_device *bootdev)
 {
-	struct legacy_img_hdr *header;
-	ulong addr = IF_ENABLED_INT(CONFIG_SPL_LOAD_FIT,
-				    CONFIG_SPL_LOAD_FIT_ADDRESS);
 	ulong image_pos = binman_sym(ulong, payload, image_pos);
 	ulong size = binman_sym(ulong, payload, size);
+	struct legacy_img_hdr *header;
+	struct spl_load_info load;
+
+	if (IS_ENABLED(CONFIG_SPL_LOAD_FIT)) {
+		ulong addr = IF_ENABLED_INT(CONFIG_SPL_LOAD_FIT,
+					    CONFIG_SPL_LOAD_FIT_ADDRESS);
+
+		if (addr == CFG_SYS_SDRAM_BASE || addr == CONFIG_SPL_TEXT_BASE)
+			return -ENODEV;
+
+		if (image_pos != BINMAN_SYM_MISSING &&
+		    size != BINMAN_SYM_MISSING) {
+			header = map_sysmem(image_pos, 0);
+			if (image_get_magic(header) == FDT_MAGIC) {
+				memmove(map_sysmem(addr, 0), header, size);
+				memset(header, 0, sizeof(*header));
+			}
+		}
 
-	if (addr == CFG_SYS_SDRAM_BASE || addr == CONFIG_SPL_TEXT_BASE)
-		return -ENODEV;
-
-	if (image_pos != BINMAN_SYM_MISSING && size != BINMAN_SYM_MISSING) {
-		header = map_sysmem(image_pos, 0);
+		header = map_sysmem(addr, 0);
 		if (image_get_magic(header) == FDT_MAGIC) {
-			memmove(map_sysmem(addr, 0), header, size);
-			memset(header, 0, sizeof(*header));
+			spl_load_init(&load, ramboot_load_read,
+				      map_sysmem(addr, 0), 1);
+			return spl_load_simple_fit(spl_image, &load, 0,
+						   header);
 		}
 	}
 
-	header = map_sysmem(addr, 0);
-	if (image_get_magic(header) == FDT_MAGIC) {
-		struct spl_load_info load;
-
-		spl_load_init(&load, ramboot_load_read, NULL, 1);
-		return spl_load_simple_fit(spl_image, &load, 0, header);
+	/* Fall back to a legacy image placed directly after SPL */
+	if (image_pos != BINMAN_SYM_MISSING && size != BINMAN_SYM_MISSING) {
+		header = map_sysmem(image_pos, 0);
+		if (image_get_magic(header) == IH_MAGIC) {
+			spl_load_init(&load, ramboot_load_read,
+				      map_sysmem(image_pos, 0), 1);
+			return spl_load(spl_image, bootdev, &load, size, 0);
+		}
 	}
 
 	return -ENODEV;
-- 
2.43.0


  parent reply	other threads:[~2026-07-07 15:34 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 15:30 [PATCH v3 00/15] rockchip: Add support for the RV1103B, RV1103 and RV1106 Simon Glass
2026-07-07 15:30 ` [PATCH v3 01/15] ARM: dts: Add the RV1103B devicetree files Simon Glass
2026-07-07 15:31 ` [PATCH v3 02/15] pinctrl: rockchip: Add RV1103B support Simon Glass
2026-07-07 15:31 ` [PATCH v3 03/15] clk: rockchip: Add RV1103B clock driver Simon Glass
2026-07-07 15:31 ` [PATCH v3 04/15] tools: rkcommon: Add RV1103B support Simon Glass
2026-07-07 15:31 ` [PATCH v3 05/15] rockchip: spl-boot-order: Add SPI NAND support Simon Glass
2026-07-07 15:31 ` [PATCH v3 06/15] spl: Add SPI NAND support via MTD in SPL Simon Glass
2026-07-07 15:31 ` [PATCH v3 07/15] rockchip: rv1103b: Add SoC support Simon Glass
2026-07-07 15:31 ` [PATCH v3 08/15] omega4-rv1103b: Add the initial support Simon Glass
2026-07-07 15:31 ` [PATCH v3 09/15] tools: rkcommon: Add RV1106 support Simon Glass
2026-07-07 15:31 ` [PATCH v3 10/15] pinctrl: rockchip: " Simon Glass
2026-07-07 15:31 ` [PATCH v3 11/15] ARM: dts: Add the RV1103/RV1106 devicetree files Simon Glass
2026-07-07 15:31 ` [PATCH v3 12/15] clk: rockchip: Add RV1106 clock driver Simon Glass
2026-07-07 15:31 ` [PATCH v3 13/15] rockchip: rv1106: Add SoC support Simon Glass
2026-07-07 15:31 ` [PATCH v3 14/15] luckfox-pico: Add the initial support Simon Glass
2026-07-07 15:31 ` Simon Glass [this message]
2026-07-07 15:35 ` [PATCH v3 00/15] rockchip: Add support for the RV1103B, RV1103 and RV1106 Tom Rini
2026-07-08 22:36   ` Simon Glass
2026-07-09  0:38     ` Tom Rini
2026-07-09  1:27       ` Simon Glass
2026-07-09  1:40         ` Tom Rini

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=20260707153135.2048115-16-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=festevam@nabladev.com \
    --cc=hl@rock-chips.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jeffy.chen@rock-chips.com \
    --cc=jonas@kwiboo.se \
    --cc=kever.yang@rock-chips.com \
    --cc=philipp.tomsich@vrull.eu \
    --cc=trini@konsulko.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