[PATCH 06/45] spl: Split up the board_init_r() function

Simon Glass sjg at chromium.org
Sun Sep 25 17:02:09 CEST 2022


This function is quite long and does two separate things: init and
booting. Split it into two.

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

 common/spl/spl.c | 64 ++++++++++++++++++++++++++++++++++++------------
 1 file changed, 49 insertions(+), 15 deletions(-)

diff --git a/common/spl/spl.c b/common/spl/spl.c
index 55b638209ae..edf24b05162 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -720,16 +720,15 @@ void board_init_f(ulong dummy)
 }
 #endif
 
-void board_init_r(gd_t *dummy1, ulong dummy2)
+/**
+ * spl_init_r() - Set up SPL ready for use
+ *
+ * Calls all required init functions to get SPL up and running
+ *
+ * @return 0 if OK, -ve on error (meaning boot cannot proceed)
+ */
+static int spl_init_r(void)
 {
-	u32 spl_boot_list[] = {
-		BOOT_DEVICE_NONE,
-		BOOT_DEVICE_NONE,
-		BOOT_DEVICE_NONE,
-		BOOT_DEVICE_NONE,
-		BOOT_DEVICE_NONE,
-	};
-	struct spl_image_info spl_image;
 	int ret;
 
 	debug(">>" SPL_TPL_PROMPT "board_init_r()\n");
@@ -741,8 +740,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	gd->flags |= GD_FLG_FULL_MALLOC_INIT;
 #endif
 	if (!(gd->flags & GD_FLG_SPL_INIT)) {
-		if (spl_init())
-			hang();
+		ret = spl_init();
+		if (ret)
+			return log_msg_ret("init", ret);
 	}
 #if !defined(CONFIG_PPC) && !defined(CONFIG_ARCH_MX6)
 	/*
@@ -754,10 +754,9 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	if (CONFIG_IS_ENABLED(BLOBLIST)) {
 		ret = bloblist_init();
 		if (ret) {
-			debug("%s: Failed to set up bloblist: ret=%d\n",
-			      __func__, ret);
+			log_debug("Failed to set up bloblist: ret=%d\n", ret);
 			puts(SPL_TPL_PROMPT "Cannot set up bloblist\n");
-			hang();
+			return log_msg_ret("bl", ret);
 		}
 	}
 	if (CONFIG_IS_ENABLED(HANDOFF)) {
@@ -766,7 +765,7 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 		ret = setup_spl_handoff();
 		if (ret) {
 			puts(SPL_TPL_PROMPT "Cannot set up SPL handoff\n");
-			hang();
+			return log_msg_ret("ho", ret);
 		}
 	}
 
@@ -795,6 +794,29 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 		dm_dump_mem(&mem);
 	}
 
+	return 0;
+}
+
+/**
+ * spl_boot() - Boot into the next U-Boot phase
+ *
+ * Figures out which boot device to use, loads the image and jumps to it
+ *
+ * This function does not return. If something goes wrong, it tries to print a
+ * message, then hangs.
+ */
+static void spl_boot(void)
+{
+	u32 spl_boot_list[] = {
+		BOOT_DEVICE_NONE,
+		BOOT_DEVICE_NONE,
+		BOOT_DEVICE_NONE,
+		BOOT_DEVICE_NONE,
+		BOOT_DEVICE_NONE,
+	};
+	struct spl_image_info spl_image;
+	int ret;
+
 	memset(&spl_image, '\0', sizeof(spl_image));
 #ifdef CONFIG_SYS_SPL_ARGS_ADDR
 	spl_image.arg = (void *)CONFIG_SYS_SPL_ARGS_ADDR;
@@ -880,6 +902,18 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
 	jump_to_image_no_args(&spl_image);
 }
 
+void board_init_r(gd_t *dummy1, ulong dummy2)
+{
+	int ret;
+
+	ret = spl_init_r();
+	if (!ret)
+		spl_boot();
+
+	puts("SPL fail\n");
+	hang();
+}
+
 /*
  * This requires UART clocks to be enabled.  In order for this to work the
  * caller must ensure that the gd pointer is valid.
-- 
2.37.3.998.g577e59143f-goog



More information about the U-Boot mailing list