diff mbox series

[05/13] x86: zboot: Create separate functions for the logic

Message ID 20231204002944.897949-6-sjg@chromium.org
State Accepted
Commit 42a99d0df66d3092dfc1c922de9143448a863118
Delegated to: Tom Rini
Headers show
Series Complete decoupling of zboot logic from commands | expand

Commit Message

Simon Glass Dec. 4, 2023, 12:29 a.m. UTC
Separate out the commands from the logic. This will eventually allow
the logic to be used when CONFIG_CMDLINE is not enabled.

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

 cmd/x86/zboot.c | 66 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 52 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/cmd/x86/zboot.c b/cmd/x86/zboot.c
index 03cab1d67ebf..f5c90a8ba896 100644
--- a/cmd/x86/zboot.c
+++ b/cmd/x86/zboot.c
@@ -10,8 +10,7 @@ 
 #include <vsprintf.h>
 #include <asm/zimage.h>
 
-static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
-			  char *const argv[])
+static void zboot_start(int argc, char *const argv[])
 {
 	const char *s;
 
@@ -53,6 +52,27 @@  static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 	}
 	if (argc >= 7)
 		state.cmdline = env_get(argv[6]);
+}
+
+static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
+			  char *const argv[])
+{
+	zboot_start(argc, argv);
+
+	return 0;
+}
+
+static int _zboot_load(void)
+{
+	int ret;
+
+	ret = zboot_load();
+	if (!ret)
+		ret = env_set_hex("zbootbase", map_to_sysmem(state.base_ptr));
+	if (!ret)
+		ret = env_set_hex("zbootaddr", state.load_address);
+	if (ret)
+		return ret;
 
 	return 0;
 }
@@ -60,18 +80,13 @@  static int do_zboot_start(struct cmd_tbl *cmdtp, int flag, int argc,
 static int do_zboot_load(struct cmd_tbl *cmdtp, int flag, int argc,
 			 char *const argv[])
 {
-	if (zboot_load())
-		return CMD_RET_FAILURE;
-
-	if (env_set_hex("zbootbase", map_to_sysmem(state.base_ptr)) ||
-	    env_set_hex("zbootaddr", state.load_address))
+	if (_zboot_load())
 		return CMD_RET_FAILURE;
 
 	return 0;
 }
 
-static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
-			  char *const argv[])
+static int _zboot_setup(void)
 {
 	struct boot_params *base_ptr = state.base_ptr;
 
@@ -87,24 +102,47 @@  static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
 	return 0;
 }
 
-static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
-			 char *const argv[])
+static int do_zboot_setup(struct cmd_tbl *cmdtp, int flag, int argc,
+			  char *const argv[])
+{
+	return _zboot_setup();
+}
+
+static void zboot_info(void)
 {
 	printf("Kernel loaded at %08lx, setup_base=%p\n",
 	       state.load_address, state.base_ptr);
+}
+
+static int do_zboot_info(struct cmd_tbl *cmdtp, int flag, int argc,
+			 char *const argv[])
+{
+	zboot_info();
 
 	return 0;
 }
 
+static int _zboot_go(void)
+{
+	int ret;
+
+	ret = zboot_go();
+
+	return ret;
+}
+
 static int do_zboot_go(struct cmd_tbl *cmdtp, int flag, int argc,
 		       char *const argv[])
 {
 	int ret;
 
-	ret = zboot_go();
-	printf("Kernel returned! (err=%d)\n", ret);
+	ret = _zboot_go();
+	if (ret) {
+		printf("Kernel returned! (err=%d)\n", ret);
+		return CMD_RET_FAILURE;
+	}
 
-	return CMD_RET_FAILURE;
+	return 0;
 }
 
 static int do_zboot_dump(struct cmd_tbl *cmdtp, int flag, int argc,