cmd: bootm: add a stage pre-load
authorPhilippe Reynes <philippe.reynes@softathome.com>
Mon, 28 Mar 2022 20:57:00 +0000 (22:57 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 31 Mar 2022 18:12:01 +0000 (14:12 -0400)
Add a stage pre-load to the command bootm.
Right now, this stage may be used to read a
header and check the signature of the full
image.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
boot/bootm.c
cmd/Kconfig
cmd/bootm.c
include/image.h

index 00c00ae..714406a 100644 (file)
@@ -87,6 +87,33 @@ static int bootm_start(struct cmd_tbl *cmdtp, int flag, int argc,
        return 0;
 }
 
+static ulong bootm_data_addr(int argc, char *const argv[])
+{
+       ulong addr;
+
+       if (argc > 0)
+               addr = simple_strtoul(argv[0], NULL, 16);
+       else
+               addr = image_load_addr;
+
+       return addr;
+}
+
+static int bootm_pre_load(struct cmd_tbl *cmdtp, int flag, int argc,
+                         char *const argv[])
+{
+       ulong data_addr = bootm_data_addr(argc, argv);
+       int ret = 0;
+
+       if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD))
+               ret = image_pre_load(data_addr);
+
+       if (ret)
+               ret = CMD_RET_FAILURE;
+
+       return ret;
+}
+
 static int bootm_find_os(struct cmd_tbl *cmdtp, int flag, int argc,
                         char *const argv[])
 {
@@ -677,6 +704,9 @@ int do_bootm_states(struct cmd_tbl *cmdtp, int flag, int argc,
        if (states & BOOTM_STATE_START)
                ret = bootm_start(cmdtp, flag, argc, argv);
 
+       if (!ret && (states & BOOTM_STATE_PRE_LOAD))
+               ret = bootm_pre_load(cmdtp, flag, argc, argv);
+
        if (!ret && (states & BOOTM_STATE_FINDOS))
                ret = bootm_find_os(cmdtp, flag, argc, argv);
 
@@ -866,6 +896,9 @@ static const void *boot_get_kernel(struct cmd_tbl *cmdtp, int flag, int argc,
                                              &fit_uname_config,
                                              &fit_uname_kernel);
 
+       if (CONFIG_IS_ENABLED(CMD_BOOTM_PRE_LOAD))
+               img_addr += image_load_offset;
+
        bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
 
        /* check image type, for FIT images get FIT kernel node */
index 1d84012..7bd9546 100644 (file)
@@ -194,6 +194,16 @@ config CMD_BOOTM
        help
          Boot an application image from the memory.
 
+config CMD_BOOTM_PRE_LOAD
+       bool "enable pre-load on bootm"
+       depends on CMD_BOOTM
+       depends on IMAGE_PRE_LOAD
+       default n
+       help
+         Enable support of stage pre-load for the bootm command.
+        This stage allow to check or modify the image provided
+        to the bootm command.
+
 config BOOTM_EFI
        bool "Support booting UEFI FIT images"
        depends on CMD_BOOTEFI && CMD_BOOTM && FIT
index e8b7066..87d40d4 100644 (file)
@@ -70,7 +70,8 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc,
        if (c) {
                state = (long)c->cmd;
                if (state == BOOTM_STATE_START)
-                       state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER;
+                       state |= BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOS |
+                                BOOTM_STATE_FINDOTHER;
        } else {
                /* Unrecognized command */
                return CMD_RET_USAGE;
@@ -126,7 +127,7 @@ int do_bootm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
        }
 
        return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
-               BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
+               BOOTM_STATE_FINDOS | BOOTM_STATE_PRE_LOAD | BOOTM_STATE_FINDOTHER |
                BOOTM_STATE_LOADOS |
 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
                BOOTM_STATE_RAMDISK |
index fbcf70f..496b7af 100644 (file)
@@ -351,6 +351,7 @@ typedef struct bootm_headers {
 #define        BOOTM_STATE_OS_PREP     (0x00000100)
 #define        BOOTM_STATE_OS_FAKE_GO  (0x00000200)    /* 'Almost' run the OS */
 #define        BOOTM_STATE_OS_GO       (0x00000400)
+#define        BOOTM_STATE_PRE_LOAD    0x00000800
        int             state;
 
 #if defined(CONFIG_LMB) && !defined(USE_HOSTCC)