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 <s...@chromium.org>
---

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

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,
-- 
2.43.0.rc2.451.g8631bc7472-goog

Reply via email to