]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_bootm.c
Clarify bootm OS arguments
[karo-tx-uboot.git] / common / cmd_bootm.c
index 15f4599d45f28f5f005403abb9908c8cd07e0317..6a6241d32798d7d97f740f39e99a80ecf8698a3b 100644 (file)
@@ -93,11 +93,6 @@ static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 static void fixup_silent_linux(void);
 #endif
 
-static image_header_t *image_get_kernel(ulong img_addr, int verify);
-#if defined(CONFIG_FIT)
-static int fit_check_kernel(const void *fit, int os_noffset, int verify);
-#endif
-
 static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
                                char * const argv[], bootm_headers_t *images,
                                ulong *os_data, ulong *os_len);
@@ -109,9 +104,18 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
  *  - verified image architecture (PPC) and type (KERNEL or MULTI),
  *  - loaded (first part of) image to header load address,
  *  - disabled interrupts.
+ *
+ * @flag: Command flags (CMD_FLAG_...)
+ * @argc: Number of arguments. Note that the arguments are shifted down
+ *      so that 0 is the first argument not processed by U-Boot, and
+ *      argc is adjusted accordingly. This avoids confusion as to how
+ *      many arguments are available for the OS.
+ * @images: Pointers to os/initrd/fdt
+ * @return 1 on error. On success the OS boots so this function does
+ * not return.
  */
 typedef int boot_os_fn(int flag, int argc, char * const argv[],
-                       bootm_headers_t *images); /* pointers to os/initrd/fdt */
+                       bootm_headers_t *images);
 
 #ifdef CONFIG_BOOTM_LINUX
 extern boot_os_fn do_bootm_linux;
@@ -306,7 +310,7 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]
 
 #if defined(CONFIG_OF_LIBFDT)
                /* find flattened device tree */
-               ret = boot_get_fdt(flag, argc, argv, &images,
+               ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,
                                   &images.ft_addr, &images.ft_len);
                if (ret) {
                        puts("Could not find a valid device tree\n");
@@ -336,12 +340,15 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
        ulong image_len = os.image_len;
        __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
        int no_overlap = 0;
+       void *load_buf, *image_buf;
 #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
        int ret;
 #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
 
        const char *type_name = genimg_get_type_name(os.type);
 
+       load_buf = map_sysmem(load, image_len);
+       image_buf = map_sysmem(image_start, image_len);
        switch (comp) {
        case IH_COMP_NONE:
                if (load == blob_start || load == image_start) {
@@ -349,8 +356,7 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
                        no_overlap = 1;
                } else {
                        printf("   Loading %s ... ", type_name);
-                       memmove_wd((void *)load, (void *)image_start,
-                                       image_len, CHUNKSZ);
+                       memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
                }
                *load_end = load + image_len;
                puts("OK\n");
@@ -358,8 +364,7 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
 #ifdef CONFIG_GZIP
        case IH_COMP_GZIP:
                printf("   Uncompressing %s ... ", type_name);
-               if (gunzip((void *)load, unc_len,
-                               (uchar *)image_start, &image_len) != 0) {
+               if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) {
                        puts("GUNZIP: uncompress, out-of-mem or overwrite "
                                "error - must RESET board to recover\n");
                        if (boot_progress)
@@ -378,9 +383,9 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
                 * use slower decompression algorithm which requires
                 * at most 2300 KB of memory.
                 */
-               int i = BZ2_bzBuffToBuffDecompress((char *)load,
-                                       &unc_len, (char *)image_start, image_len,
-                                       CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
+               int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len,
+                       image_buf, image_len,
+                       CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
                if (i != BZ_OK) {
                        printf("BUNZIP2: uncompress or overwrite error %d "
                                "- must RESET board to recover\n", i);
@@ -397,9 +402,8 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
                SizeT lzma_len = unc_len;
                printf("   Uncompressing %s ... ", type_name);
 
-               ret = lzmaBuffToBuffDecompress(
-                       (unsigned char *)load, &lzma_len,
-                       (unsigned char *)image_start, image_len);
+               ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
+                                              image_buf, image_len);
                unc_len = lzma_len;
                if (ret != SZ_OK) {
                        printf("LZMA: uncompress or overwrite error %d "
@@ -415,9 +419,8 @@ static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
        case IH_COMP_LZO:
                printf("   Uncompressing %s ... ", type_name);
 
-               ret = lzop_decompress((const unsigned char *)image_start,
-                                         image_len, (unsigned char *)load,
-                                         &unc_len);
+               ret = lzop_decompress(image_buf, image_len, load_buf,
+                                     &unc_len);
                if (ret != LZO_E_OK) {
                        printf("LZO: uncompress or overwrite error %d "
                              "- must RESET board to recover\n", ret);
@@ -463,7 +466,7 @@ static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
                return 0;
        }
        appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
-       (*appl)(argc-1, &argv[1]);
+       (*appl)(argc, argv);
        return 0;
 }
 
@@ -492,17 +495,15 @@ static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
        cmd_tbl_t *c;
        boot_os_fn *boot_fn;
 
-       c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
+       c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
+       argc--; argv++;
 
        if (c) {
                state = (long)c->cmd;
 
                /* treat start special since it resets the state machine */
-               if (state == BOOTM_STATE_START) {
-                       argc--;
-                       argv++;
+               if (state == BOOTM_STATE_START)
                        return bootm_start(cmdtp, flag, argc, argv);
-               }
        } else {
                /* Unrecognized command */
                return CMD_RET_USAGE;
@@ -617,11 +618,12 @@ int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 #endif
 
        /* determine if we have a sub command */
-       if (argc > 1) {
+       argc--; argv++;
+       if (argc > 0) {
                char *endp;
 
-               simple_strtoul(argv[1], &endp, 16);
-               /* endp pointing to NULL means that argv[1] was just a
+               simple_strtoul(argv[0], &endp, 16);
+               /* endp pointing to NULL means that argv[0] was just a
                 * valid number, pass it along to the normal bootm processing
                 *
                 * If endp is ':' or '#' assume a FIT identifier so pass
@@ -796,54 +798,6 @@ static image_header_t *image_get_kernel(ulong img_addr, int verify)
        return hdr;
 }
 
-/**
- * fit_check_kernel - verify FIT format kernel subimage
- * @fit_hdr: pointer to the FIT image header
- * os_noffset: kernel subimage node offset within FIT image
- * @verify: data CRC verification flag
- *
- * fit_check_kernel() verifies integrity of the kernel subimage and from
- * specified FIT image.
- *
- * returns:
- *     1, on success
- *     0, on failure
- */
-#if defined(CONFIG_FIT)
-static int fit_check_kernel(const void *fit, int os_noffset, int verify)
-{
-       fit_image_print(fit, os_noffset, "   ");
-
-       if (verify) {
-               puts("   Verifying Hash Integrity ... ");
-               if (!fit_image_verify(fit, os_noffset)) {
-                       puts("Bad Data Hash\n");
-                       bootstage_error(BOOTSTAGE_ID_FIT_CHECK_HASH);
-                       return 0;
-               }
-               puts("OK\n");
-       }
-       bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_ARCH);
-
-       if (!fit_image_check_target_arch(fit, os_noffset)) {
-               puts("Unsupported Architecture\n");
-               bootstage_error(BOOTSTAGE_ID_FIT_CHECK_ARCH);
-               return 0;
-       }
-
-       bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
-       if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL) &&
-           !fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL_NOLOAD)) {
-               puts("Not a kernel image\n");
-               bootstage_error(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
-               return 0;
-       }
-
-       bootstage_mark(BOOTSTAGE_ID_FIT_CHECKED);
-       return 1;
-}
-#endif /* CONFIG_FIT */
-
 /**
  * boot_get_kernel - find kernel image
  * @os_data: pointer to a ulong variable, will hold os data start address
@@ -864,32 +818,28 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
        ulong           img_addr;
        const void *buf;
 #if defined(CONFIG_FIT)
-       const void      *fit_hdr;
        const char      *fit_uname_config = NULL;
        const char      *fit_uname_kernel = NULL;
-       const void      *data;
-       size_t          len;
-       int             cfg_noffset;
        int             os_noffset;
 #endif
 
        /* find out kernel image address */
-       if (argc < 2) {
+       if (argc < 1) {
                img_addr = load_addr;
                debug("*  kernel: default image load address = 0x%08lx\n",
                                load_addr);
 #if defined(CONFIG_FIT)
-       } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
+       } else if (fit_parse_conf(argv[0], load_addr, &img_addr,
                                                        &fit_uname_config)) {
                debug("*  kernel: config '%s' from image at 0x%08lx\n",
                                fit_uname_config, img_addr);
-       } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
+       } else if (fit_parse_subimage(argv[0], load_addr, &img_addr,
                                                        &fit_uname_kernel)) {
                debug("*  kernel: subimage '%s' from image at 0x%08lx\n",
                                fit_uname_kernel, img_addr);
 #endif
        } else {
-               img_addr = simple_strtoul(argv[1], NULL, 16);
+               img_addr = simple_strtoul(argv[0], NULL, 16);
                debug("*  kernel: cmdline image address = 0x%08lx\n", img_addr);
        }
 
@@ -946,84 +896,16 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
                break;
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
-               fit_hdr = buf;
-               printf("## Booting kernel from FIT Image at %08lx ...\n",
-                               img_addr);
-
-               if (!fit_check_format(fit_hdr)) {
-                       puts("Bad FIT kernel image format!\n");
-                       bootstage_error(BOOTSTAGE_ID_FIT_FORMAT);
+               os_noffset = fit_image_load(images, FIT_KERNEL_PROP,
+                               img_addr,
+                               &fit_uname_kernel, fit_uname_config,
+                               IH_ARCH_DEFAULT, IH_TYPE_KERNEL,
+                               BOOTSTAGE_ID_FIT_KERNEL_START,
+                               FIT_LOAD_IGNORED, os_data, os_len);
+               if (os_noffset < 0)
                        return NULL;
-               }
-               bootstage_mark(BOOTSTAGE_ID_FIT_FORMAT);
-
-               if (!fit_uname_kernel) {
-                       /*
-                        * no kernel image node unit name, try to get config
-                        * node first. If config unit node name is NULL
-                        * fit_conf_get_node() will try to find default config
-                        * node
-                        */
-                       bootstage_mark(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
-#ifdef CONFIG_FIT_BEST_MATCH
-                       if (fit_uname_config)
-                               cfg_noffset =
-                                       fit_conf_get_node(fit_hdr,
-                                                         fit_uname_config);
-                       else
-                               cfg_noffset =
-                                       fit_conf_find_compat(fit_hdr,
-                                                            gd->fdt_blob);
-#else
-                       cfg_noffset = fit_conf_get_node(fit_hdr,
-                                                       fit_uname_config);
-#endif
-                       if (cfg_noffset < 0) {
-                               bootstage_error(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
-                               return NULL;
-                       }
-                       /* save configuration uname provided in the first
-                        * bootm argument
-                        */
-                       images->fit_uname_cfg = fdt_get_name(fit_hdr,
-                                                               cfg_noffset,
-                                                               NULL);
-                       printf("   Using '%s' configuration\n",
-                               images->fit_uname_cfg);
-                       bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
-
-                       os_noffset = fit_conf_get_kernel_node(fit_hdr,
-                                                               cfg_noffset);
-                       fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
-                                                       NULL);
-               } else {
-                       /* get kernel component image node offset */
-                       bootstage_mark(BOOTSTAGE_ID_FIT_UNIT_NAME);
-                       os_noffset = fit_image_get_node(fit_hdr,
-                                                       fit_uname_kernel);
-               }
-               if (os_noffset < 0) {
-                       bootstage_error(BOOTSTAGE_ID_FIT_CONFIG);
-                       return NULL;
-               }
-
-               printf("   Trying '%s' kernel subimage\n", fit_uname_kernel);
-
-               bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE);
-               if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
-                       return NULL;
-
-               /* get kernel image data address and length */
-               if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
-                       puts("Could not find kernel subimage data!\n");
-                       bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR);
-                       return NULL;
-               }
-               bootstage_mark(BOOTSTAGE_ID_FIT_KERNEL_INFO);
 
-               *os_len = len;
-               *os_data = (ulong)data;
-               images->fit_hdr_os = (void *)fit_hdr;
+               images->fit_hdr_os = map_sysmem(img_addr, 0);
                images->fit_uname_os = fit_uname_kernel;
                images->fit_noffset_os = os_noffset;
                break;
@@ -1527,16 +1409,16 @@ static int do_bootm_netbsd(int flag, int argc, char * const argv[],
        consdev = "scc3";
 #endif
 
-       if (argc > 2) {
+       if (argc > 0) {
                ulong len;
                int   i;
 
-               for (i = 2, len = 0; i < argc; i += 1)
+               for (i = 0, len = 0; i < argc; i += 1)
                        len += strlen(argv[i]) + 1;
                cmdline = malloc(len);
 
-               for (i = 2, len = 0; i < argc; i += 1) {
-                       if (i > 2)
+               for (i = 0, len = 0; i < argc; i += 1) {
+                       if (i > 0)
                                cmdline[len++] = ' ';
                        strcpy(&cmdline[len], argv[i]);
                        len += strlen(argv[i]);
@@ -1820,7 +1702,7 @@ static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
 
 #if defined(CONFIG_OF_LIBFDT)
        /* find flattened device tree */
-       ret = boot_get_fdt(flag, argc, argv, images,
+       ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, images,
                           &images->ft_addr, &images->ft_len);
        if (ret) {
                puts("Could not find a valid device tree\n");
@@ -1833,7 +1715,7 @@ static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
        return 0;
 }
 
-static int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        bootm_headers_t images;