]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_bootm.c
build: Use generic boot logo matching
[karo-tx-uboot.git] / common / cmd_bootm.c
index f7595c0311955b58acffa6efd2b19a209576ec48..7438469d091721a6dcba15ec2263ef7b086dc743 100644 (file)
@@ -47,7 +47,6 @@
 #endif
 
 #if defined(CONFIG_OF_LIBFDT)
-#include <fdt.h>
 #include <libfdt.h>
 #include <fdt_support.h>
 #endif
@@ -80,10 +79,16 @@ static int image_info(unsigned long addr);
 #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)
 static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 #endif
 
-#ifdef CONFIG_SILENT_CONSOLE
+#include <linux/err.h>
+#include <nand.h>
+
+#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
 static void fixup_silent_linux(void);
 #endif
 
@@ -123,6 +128,9 @@ static boot_os_fn do_bootm_rtems;
 #if defined(CONFIG_BOOTM_OSE)
 static boot_os_fn do_bootm_ose;
 #endif
+#if defined(CONFIG_BOOTM_PLAN9)
+static boot_os_fn do_bootm_plan9;
+#endif
 #if defined(CONFIG_CMD_ELF)
 static boot_os_fn do_bootm_vxworks;
 static boot_os_fn do_bootm_qnxelf;
@@ -149,6 +157,9 @@ static boot_os_fn *boot_os[] = {
 #if defined(CONFIG_BOOTM_OSE)
        [IH_OS_OSE] = do_bootm_ose,
 #endif
+#if defined(CONFIG_BOOTM_PLAN9)
+       [IH_OS_PLAN9] = do_bootm_plan9,
+#endif
 #if defined(CONFIG_CMD_ELF)
        [IH_OS_VXWORKS] = do_bootm_vxworks,
        [IH_OS_QNX] = do_bootm_qnxelf,
@@ -447,9 +458,7 @@ static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
 
        /* Don't start if "autostart" is set to "no" */
        if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
-               char buf[32];
-               sprintf(buf, "%lX", images.os.image_len);
-               setenv("filesize", buf);
+               setenv_hex("filesize", images.os.image_len);
                return 0;
        }
        appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
@@ -498,7 +507,8 @@ static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
                return CMD_RET_USAGE;
        }
 
-       if (images.state >= state) {
+       if (images.state < BOOTM_STATE_START ||
+           images.state >= state) {
                printf("Trying to execute a command out of order\n");
                return CMD_RET_USAGE;
        }
@@ -523,17 +533,14 @@ static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
                case BOOTM_STATE_RAMDISK:
                {
                        ulong rd_len = images.rd_end - images.rd_start;
-                       char str[17];
 
                        ret = boot_ramdisk_high(&images.lmb, images.rd_start,
                                rd_len, &images.initrd_start, &images.initrd_end);
                        if (ret)
                                return ret;
 
-                       sprintf(str, "%lx", images.initrd_start);
-                       setenv("initrd_start", str);
-                       sprintf(str, "%lx", images.initrd_end);
-                       setenv("initrd_end", str);
+                       setenv_hex("initrd_start", images.initrd_start);
+                       setenv_hex("initrd_end", images.initrd_end);
                }
                        break;
 #endif
@@ -592,12 +599,18 @@ int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #ifdef CONFIG_NEEDS_MANUAL_RELOC
        static int relocated = 0;
 
-       /* relocate boot function table */
        if (!relocated) {
                int i;
+
+               /* relocate boot function table */
                for (i = 0; i < ARRAY_SIZE(boot_os); i++)
                        if (boot_os[i] != NULL)
                                boot_os[i] += gd->reloc_off;
+
+               /* relocate names of sub-command table */
+               for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
+                       cmd_bootm_sub[i].name += gd->reloc_off;
+
                relocated = 1;
        }
 #endif
@@ -687,7 +700,7 @@ int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
        bootstage_mark(BOOTSTAGE_ID_CHECK_BOOT_OS);
 
-#ifdef CONFIG_SILENT_CONSOLE
+#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
        if (images.os.os == IH_OS_LINUX)
                fixup_silent_linux();
 #endif
@@ -1049,7 +1062,7 @@ static char bootm_help_text[] =
        "issued in the order below (it's ok to not issue all sub-commands):\n"
        "\tstart [addr [arg ...]]\n"
        "\tloados  - load OS image\n"
-#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
+#if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
        "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
 #endif
 #if defined(CONFIG_OF_LIBFDT)
@@ -1186,7 +1199,7 @@ U_BOOT_CMD(
 /* imls - list all images found in flash */
 /*******************************************************************/
 #if defined(CONFIG_CMD_IMLS)
-static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_imls_nor(void)
 {
        flash_info_t *info;
        int i, j;
@@ -1235,6 +1248,161 @@ next_sector:            ;
                }
 next_bank:     ;
        }
+       return 0;
+}
+#endif
+
+#if defined(CONFIG_CMD_IMLS_NAND)
+static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
+               size_t len)
+{
+       void *imgdata;
+       int ret;
+
+       imgdata = malloc(len);
+       if (!imgdata) {
+               printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
+                               nand_dev, off);
+               printf("   Low memory(cannot allocate memory for image)\n");
+               return -ENOMEM;
+       }
+
+       ret = nand_read_skip_bad(nand, off, &len,
+                       imgdata);
+       if (ret < 0 && ret != -EUCLEAN) {
+               free(imgdata);
+               return ret;
+       }
+
+       if (!image_check_hcrc(imgdata)) {
+               free(imgdata);
+               return 0;
+       }
+
+       printf("Legacy Image at NAND device %d offset %08llX:\n",
+                       nand_dev, off);
+       image_print_contents(imgdata);
+
+       puts("   Verifying Checksum ... ");
+       if (!image_check_dcrc(imgdata))
+               puts("Bad Data CRC\n");
+       else
+               puts("OK\n");
+
+       free(imgdata);
+
+       return 0;
+}
+
+static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
+               size_t len)
+{
+       void *imgdata;
+       int ret;
+
+       imgdata = malloc(len);
+       if (!imgdata) {
+               printf("May be a FIT Image at NAND device %d offset %08llX:\n",
+                               nand_dev, off);
+               printf("   Low memory(cannot allocate memory for image)\n");
+               return -ENOMEM;
+       }
+
+       ret = nand_read_skip_bad(nand, off, &len,
+                       imgdata);
+       if (ret < 0 && ret != -EUCLEAN) {
+               free(imgdata);
+               return ret;
+       }
+
+       if (!fit_check_format(imgdata)) {
+               free(imgdata);
+               return 0;
+       }
+
+       printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
+
+       fit_print_contents(imgdata);
+       free(imgdata);
+
+       return 0;
+}
+
+static int do_imls_nand(void)
+{
+       nand_info_t *nand;
+       int nand_dev = nand_curr_device;
+       size_t len;
+       loff_t off;
+       u32 buffer[16];
+
+       if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
+               puts("\nNo NAND devices available\n");
+               return -ENODEV;
+       }
+
+       printf("\n");
+
+       for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
+               nand = &nand_info[nand_dev];
+               if (!nand->name || !nand->size)
+                       continue;
+
+               for (off = 0; off < nand->size; off += nand->erasesize) {
+                       const image_header_t *header;
+                       int ret;
+
+                       if (nand_block_isbad(nand, off))
+                               continue;
+
+                       len = sizeof(buffer);
+
+                       ret = nand_read(nand, off, &len, (u8 *)buffer);
+                       if (ret < 0 && ret != -EUCLEAN) {
+                               printf("NAND read error %d at offset %08llX\n",
+                                               ret, off);
+                               continue;
+                       }
+
+                       switch (genimg_get_format(buffer)) {
+                       case IMAGE_FORMAT_LEGACY:
+                               header = (const image_header_t *)buffer;
+
+                               len = image_get_image_size(header);
+                               nand_imls_legacyimage(nand, nand_dev, off, len);
+                               break;
+#if defined(CONFIG_FIT)
+                       case IMAGE_FORMAT_FIT:
+                               len = fit_get_size(buffer);
+                               nand_imls_fitimage(nand, nand_dev, off, len);
+                               break;
+#endif
+                       }
+               }
+       }
+
+       return 0;
+}
+#endif
+
+#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
+static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       int ret_nor = 0, ret_nand = 0;
+
+#if defined(CONFIG_CMD_IMLS)
+       ret_nor = do_imls_nor();
+#endif
+
+#if defined(CONFIG_CMD_IMLS_NAND)
+       ret_nand = do_imls_nand();
+#endif
+
+       if (ret_nor)
+               return ret_nor;
+
+       if (ret_nand)
+               return ret_nand;
 
        return (0);
 }
@@ -1243,15 +1411,15 @@ U_BOOT_CMD(
        imls,   1,              1,      do_imls,
        "list all images found in flash",
        "\n"
-       "    - Prints information about all images found at sector\n"
-       "      boundaries in flash."
+       "    - Prints information about all images found at sector/block\n"
+       "      boundaries in nor/nand flash."
 );
 #endif
 
 /*******************************************************************/
 /* helper routines */
 /*******************************************************************/
-#ifdef CONFIG_SILENT_CONSOLE
+#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
 static void fixup_silent_linux(void)
 {
        char buf[256], *start, *end;
@@ -1466,6 +1634,39 @@ static int do_bootm_ose(int flag, int argc, char * const argv[],
 }
 #endif /* CONFIG_BOOTM_OSE */
 
+#if defined(CONFIG_BOOTM_PLAN9)
+static int do_bootm_plan9(int flag, int argc, char * const argv[],
+                          bootm_headers_t *images)
+{
+       void (*entry_point)(void);
+
+       if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
+               return 1;
+
+#if defined(CONFIG_FIT)
+       if (!images->legacy_hdr_valid) {
+               fit_unsupported_reset("Plan 9");
+               return 1;
+       }
+#endif
+
+       entry_point = (void (*)(void))images->ep;
+
+       printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
+               (ulong)entry_point);
+
+       bootstage_mark(BOOTSTAGE_ID_RUN_OS);
+
+       /*
+        * Plan 9 Parameters:
+        *   None
+        */
+       (*entry_point)();
+
+       return 1;
+}
+#endif /* CONFIG_BOOTM_PLAN9 */
+
 #if defined(CONFIG_CMD_ELF)
 static int do_bootm_vxworks(int flag, int argc, char * const argv[],
                             bootm_headers_t *images)
@@ -1644,7 +1845,7 @@ static int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        usb_stop();
 #endif
 
-#ifdef CONFIG_SILENT_CONSOLE
+#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
        fixup_silent_linux();
 #endif
        arch_preboot_os();