Merge tag 'tpm-030822' of https://source.denx.de/u-boot/custodians/u-boot-tpm
[platform/kernel/u-boot.git] / cmd / bootm.c
index b82a872..9fe8ce4 100644 (file)
@@ -31,7 +31,6 @@ static int image_info(unsigned long addr);
 #if defined(CONFIG_CMD_IMLS)
 #include <flash.h>
 #include <mtd/cfi_flash.h>
-extern flash_info_t flash_info[]; /* info for FLASH chips */
 #endif
 
 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
@@ -44,6 +43,9 @@ static int do_imls(struct cmd_tbl *cmdtp, int flag, int argc,
 static struct cmd_tbl cmd_bootm_sub[] = {
        U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
        U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
+#ifdef CONFIG_CMD_BOOTM_PRE_LOAD
+       U_BOOT_CMD_MKENT(preload, 0, 1, (void *)BOOTM_STATE_PRE_LOAD, "", ""),
+#endif
 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
        U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
 #endif
@@ -57,6 +59,20 @@ static struct cmd_tbl cmd_bootm_sub[] = {
        U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
 };
 
+#if defined(CONFIG_CMD_BOOTM_PRE_LOAD)
+static ulong bootm_get_addr(int argc, char *const argv[])
+{
+       ulong addr;
+
+       if (argc > 0)
+               addr = hextoul(argv[0], NULL);
+       else
+               addr = image_load_addr;
+
+       return addr;
+}
+#endif
+
 static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc,
                               char *const argv[])
 {
@@ -70,7 +86,12 @@ 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;
+#if defined(CONFIG_CMD_BOOTM_PRE_LOAD)
+               if (state == BOOTM_STATE_PRE_LOAD)
+                       state |= BOOTM_STATE_START;
+#endif
        } else {
                /* Unrecognized command */
                return CMD_RET_USAGE;
@@ -84,6 +105,12 @@ static int do_bootm_subcommand(struct cmd_tbl *cmdtp, int flag, int argc,
 
        ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
 
+#if defined(CONFIG_CMD_BOOTM_PRE_LOAD)
+       if (!ret && (state & BOOTM_STATE_PRE_LOAD))
+               env_set_hex("loadaddr_verified",
+                           bootm_get_addr(argc, argv) + image_load_offset);
+#endif
+
        return ret;
 }
 
@@ -126,7 +153,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 |
@@ -176,6 +203,9 @@ static char bootm_help_text[] =
        "must be\n"
        "issued in the order below (it's ok to not issue all sub-commands):\n"
        "\tstart [addr [arg ...]]\n"
+#if defined(CONFIG_CMD_BOOTM_PRE_LOAD)
+       "\tpreload [addr [arg ..]] - run only the preload stage\n"
+#endif
        "\tloados  - load OS image\n"
 #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
        "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
@@ -338,7 +368,7 @@ static int do_imls_nor(void)
        void *hdr;
 
        for (i = 0, info = &flash_info[0];
-               i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
+               i < CFI_FLASH_BANKS; ++i, ++info) {
 
                if (info->flash_id == FLASH_UNKNOWN)
                        goto next_bank;