[PATCH v2] common: spl: nand: improve u-boot offsets overriding

Weijie Gao weijie.gao at mediatek.com
Wed Apr 15 09:34:25 CEST 2026


This patch introduces spl_nand_get_uboot_raw_page_redund() to wrap the
CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND macro, similar as what
spl_nand_get_uboot_raw_page() has already done.

The spl_nand_get_uboot_raw_page_redund() is defined to return int to allow
disabling loading redundant u-boot by returning a negative value.
By default if CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND equals
CONFIG_SYS_NAND_U_BOOT_OFFS, spl_nand_get_uboot_raw_page_redund() will
return -1.

This patch also replaces all references to CONFIG_SYS_NAND_U_BOOT_OFFS and
CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND with the return value of the two
functions mentioned above.

Signed-off-by: Weijie Gao <weijie.gao at mediatek.com>
---
 common/spl/spl_nand.c | 40 +++++++++++++++++++++++++++-------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/common/spl/spl_nand.c b/common/spl/spl_nand.c
index f449b31f594..755461dfa57 100644
--- a/common/spl/spl_nand.c
+++ b/common/spl/spl_nand.c
@@ -18,21 +18,34 @@
 
 uint32_t __weak spl_nand_get_uboot_raw_page(void)
 {
-	return CONFIG_SYS_NAND_U_BOOT_OFFS;
+	return IF_ENABLED_INT(CONFIG_SYS_NAND_U_BOOT_LOCATIONS,
+			      CONFIG_SYS_NAND_U_BOOT_OFFS);
+}
+
+int __weak spl_nand_get_uboot_raw_page_redund(void)
+{
+	if (IF_ENABLED_INT(CONFIG_SYS_NAND_U_BOOT_LOCATIONS,
+			   CONFIG_SYS_NAND_U_BOOT_OFFS) ==
+	    IF_ENABLED_INT(CONFIG_SYS_NAND_U_BOOT_LOCATIONS,
+			   CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND))
+		return -1;
+
+	return IF_ENABLED_INT(CONFIG_SYS_NAND_U_BOOT_LOCATIONS,
+			      CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND);
 }
 
 #if defined(CONFIG_SPL_NAND_RAW_ONLY)
 static int spl_nand_load_image(struct spl_image_info *spl_image,
 			struct spl_boot_device *bootdev)
 {
+	u32 offs = spl_nand_get_uboot_raw_page();
+
 	nand_init();
 
 	printf("Loading U-Boot from 0x%08x (size 0x%08x) to 0x%08x\n",
-	       CONFIG_SYS_NAND_U_BOOT_OFFS, CFG_SYS_NAND_U_BOOT_SIZE,
-	       CFG_SYS_NAND_U_BOOT_DST);
+	       offs, CFG_SYS_NAND_U_BOOT_SIZE, CFG_SYS_NAND_U_BOOT_DST);
 
-	nand_spl_load_image(spl_nand_get_uboot_raw_page(),
-			    CFG_SYS_NAND_U_BOOT_SIZE,
+	nand_spl_load_image(offs, CFG_SYS_NAND_U_BOOT_SIZE,
 			    map_sysmem(CFG_SYS_NAND_U_BOOT_DST,
 				       CFG_SYS_NAND_U_BOOT_SIZE));
 	spl_set_header_raw_uboot(spl_image);
@@ -127,6 +140,7 @@ static int spl_nand_load_image_os(struct spl_image_info *spl_image,
 static int spl_nand_load_image(struct spl_image_info *spl_image,
 			       struct spl_boot_device *bootdev)
 {
+	u32 offs = spl_nand_get_uboot_raw_page();
 	int err;
 
 #ifdef CONFIG_SPL_NAND_SOFTECC
@@ -155,14 +169,14 @@ static int spl_nand_load_image(struct spl_image_info *spl_image,
 #endif
 #endif
 	/* Load u-boot */
-	err = spl_nand_load_element(spl_image, bootdev, spl_nand_get_uboot_raw_page());
-#ifdef CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
-#if CONFIG_SYS_NAND_U_BOOT_OFFS != CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND
-	if (err)
-		err = spl_nand_load_element(spl_image, bootdev,
-					    CONFIG_SYS_NAND_U_BOOT_OFFS_REDUND);
-#endif
-#endif
+	err = spl_nand_load_element(spl_image, bootdev, offs);
+	if (err) {
+		int offs_redund = spl_nand_get_uboot_raw_page_redund();
+
+		if (offs_redund >= 0 && offs != offs_redund)
+			err = spl_nand_load_element(spl_image, bootdev,
+						    offs_redund);
+	}
 	nand_deselect();
 	return err;
 }
-- 
2.45.2



More information about the U-Boot mailing list