]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - common/bootm.c
imx6q: engicam: Use SPL_LOAD_FIT for MMC boards
[people/ms/u-boot.git] / common / bootm.c
index 34f60bbb5319e0fe8bea2c8ac0c5db85fdcae76f..adb12137c7b5ce6bbb69b39c64a7c022f7d7b3b0 100644 (file)
@@ -13,6 +13,7 @@
 #include <fdt_support.h>
 #include <lmb.h>
 #include <malloc.h>
+#include <mapmem.h>
 #include <asm/io.h>
 #include <linux/lzo.h>
 #include <lzma/LzmaTypes.h>
@@ -40,6 +41,8 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
+bootm_headers_t images;                /* pointers to os/initrd/fdt images */
+
 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);
@@ -52,8 +55,8 @@ static void boot_start_lmb(bootm_headers_t *images)
 
        lmb_init(&images->lmb);
 
-       mem_start = getenv_bootm_low();
-       mem_size = getenv_bootm_size();
+       mem_start = env_get_bootm_low();
+       mem_size = env_get_bootm_size();
 
        lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
 
@@ -69,7 +72,7 @@ static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc,
                       char * const argv[])
 {
        memset((void *)&images, 0, sizeof(images));
-       images.verify = getenv_yesno("verify");
+       images.verify = env_get_yesno("verify");
 
        boot_start_lmb(&images);
 
@@ -107,7 +110,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
                images.os.arch = image_get_arch(os_hdr);
                break;
 #endif
-#if defined(CONFIG_FIT)
+#if IMAGE_ENABLE_FIT
        case IMAGE_FORMAT_FIT:
                if (fit_image_get_type(images.fit_hdr_os,
                                       images.fit_noffset_os,
@@ -179,7 +182,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
                /* Kernel entry point is the setup.bin */
        } else if (images.legacy_hdr_valid) {
                images.ep = image_get_ep(&images.legacy_hdr_os_copy);
-#if defined(CONFIG_FIT)
+#if IMAGE_ENABLE_FIT
        } else if (images.fit_uname_os) {
                int ret;
 
@@ -200,12 +203,28 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
                images.ep += images.os.load;
        }
 
-       images.os.start = (ulong)os_hdr;
+       images.os.start = map_to_sysmem(os_hdr);
 
        return 0;
 }
 
-static int bootm_find_ramdisk(int flag, int argc, char * const argv[])
+/**
+ * bootm_find_images - wrapper to find and locate various images
+ * @flag: Ignored Argument
+ * @argc: command argument count
+ * @argv: command argument list
+ *
+ * boot_find_images() will attempt to load an available ramdisk,
+ * flattened device tree, as well as specifically marked
+ * "loadable" images (loadables are FIT only)
+ *
+ * Note: bootm_find_images will skip an image if it is not found
+ *
+ * @return:
+ *     0, if all existing images were loaded correctly
+ *     1, if an image is found but corrupted, or invalid
+ */
+int bootm_find_images(int flag, int argc, char * const argv[])
 {
        int ret;
 
@@ -217,14 +236,7 @@ static int bootm_find_ramdisk(int flag, int argc, char * const argv[])
                return 1;
        }
 
-       return 0;
-}
-
-#if defined(CONFIG_OF_LIBFDT)
-static int bootm_find_fdt(int flag, int argc, char * const argv[])
-{
-       int ret;
-
+#if IMAGE_ENABLE_OF_LIBFDT
        /* find flattened device tree */
        ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,
                           &images.ft_addr, &images.ft_len);
@@ -232,21 +244,27 @@ static int bootm_find_fdt(int flag, int argc, char * const argv[])
                puts("Could not find a valid device tree\n");
                return 1;
        }
-
        set_working_fdt_addr((ulong)images.ft_addr);
-
-       return 0;
-}
 #endif
 
-int bootm_find_ramdisk_fdt(int flag, int argc, char * const argv[])
-{
-       if (bootm_find_ramdisk(flag, argc, argv))
+#if IMAGE_ENABLE_FIT
+#if defined(CONFIG_FPGA)
+       /* find bitstreams */
+       ret = boot_get_fpga(argc, argv, &images, IH_ARCH_DEFAULT,
+                           NULL, NULL);
+       if (ret) {
+               printf("FPGA image is corrupted or invalid\n");
                return 1;
+       }
+#endif
 
-#if defined(CONFIG_OF_LIBFDT)
-       if (bootm_find_fdt(flag, argc, argv))
+       /* find all of the loadables */
+       ret = boot_get_loadable(argc, argv, &images, IH_ARCH_DEFAULT,
+                              NULL, NULL);
+       if (ret) {
+               printf("Loadable(s) is corrupt or invalid\n");
                return 1;
+       }
 #endif
 
        return 0;
@@ -260,7 +278,7 @@ static int bootm_find_other(cmd_tbl_t *cmdtp, int flag, int argc,
             (images.os.type == IH_TYPE_MULTI)) &&
            (images.os.os == IH_OS_LINUX ||
                 images.os.os == IH_OS_VXWORKS))
-               return bootm_find_ramdisk_fdt(flag, argc, argv);
+               return bootm_find_images(flag, argc, argv);
 
        return 0;
 }
@@ -383,6 +401,15 @@ int bootm_decomp_image(int comp, ulong load, ulong image_start, int type,
                break;
        }
 #endif /* CONFIG_LZO */
+#ifdef CONFIG_LZ4
+       case IH_COMP_LZ4: {
+               size_t size = unc_len;
+
+               ret = ulz4fn(image_buf, image_len, load_buf, &size);
+               image_len = size;
+               break;
+       }
+#endif /* CONFIG_LZ4 */
        default:
                printf("Unimplemented compression type %d\n", comp);
                return BOOTM_ERR_UNIMPLEMENTED;
@@ -420,7 +447,7 @@ static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
                bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
                return err;
        }
-       flush_cache(load, (*load_end - load) * sizeof(ulong));
+       flush_cache(load, ALIGN(*load_end - load, ARCH_DMA_MINALIGN));
 
        debug("   kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
        bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
@@ -468,7 +495,9 @@ ulong bootm_disable_interrupts(void)
 #ifdef CONFIG_NETCONSOLE
        /* Stop the ethernet stack if NetConsole could have left it up */
        eth_halt();
+# ifndef CONFIG_DM_ETH
        eth_unregister(eth_get_dev());
+# endif
 #endif
 
 #if defined(CONFIG_CMD_USB)
@@ -495,7 +524,7 @@ static void fixup_silent_linux(void)
 {
        char *buf;
        const char *env_val;
-       char *cmdline = getenv("bootargs");
+       char *cmdline = env_get("bootargs");
        int want_silent;
 
        /*
@@ -505,7 +534,7 @@ static void fixup_silent_linux(void)
         *      yes - we always fixup
         *      unset - we rely on the console silent flag
         */
-       want_silent = getenv_yesno("silent_linux");
+       want_silent = env_get_yesno("silent_linux");
        if (want_silent == 0)
                return;
        else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT))
@@ -540,7 +569,7 @@ static void fixup_silent_linux(void)
                env_val = CONSOLE_ARG;
        }
 
-       setenv("bootargs", env_val);
+       env_set("bootargs", env_val);
        debug("after silent fix-up: %s\n", env_val);
        free(buf);
 }
@@ -590,10 +619,8 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
        if (!ret && (states & BOOTM_STATE_FINDOS))
                ret = bootm_find_os(cmdtp, flag, argc, argv);
 
-       if (!ret && (states & BOOTM_STATE_FINDOTHER)) {
+       if (!ret && (states & BOOTM_STATE_FINDOTHER))
                ret = bootm_find_other(cmdtp, flag, argc, argv);
-               argc = 0;       /* consume the args */
-       }
 
        /* Load the OS */
        if (!ret && (states & BOOTM_STATE_LOADOS)) {
@@ -608,10 +635,6 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
                        goto err;
                else if (ret == BOOTM_ERR_OVERLAP)
                        ret = 0;
-#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
-               if (images->os.os == IH_OS_LINUX)
-                       fixup_silent_linux();
-#endif
        }
 
        /* Relocate the ramdisk */
@@ -622,12 +645,12 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
                ret = boot_ramdisk_high(&images->lmb, images->rd_start,
                        rd_len, &images->initrd_start, &images->initrd_end);
                if (!ret) {
-                       setenv_hex("initrd_start", images->initrd_start);
-                       setenv_hex("initrd_end", images->initrd_end);
+                       env_set_hex("initrd_start", images->initrd_start);
+                       env_set_hex("initrd_end", images->initrd_end);
                }
        }
 #endif
-#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
+#if IMAGE_ENABLE_OF_LIBFDT && defined(CONFIG_LMB)
        if (!ret && (states & BOOTM_STATE_FDT)) {
                boot_fdt_add_mem_rsv_regions(&images->lmb, images->ft_addr);
                ret = boot_relocate_fdt(&images->lmb, &images->ft_addr,
@@ -651,18 +674,24 @@ int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
                return 1;
        }
 
+
        /* Call various other states that are not generally used */
        if (!ret && (states & BOOTM_STATE_OS_CMDLINE))
                ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images);
        if (!ret && (states & BOOTM_STATE_OS_BD_T))
                ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
-       if (!ret && (states & BOOTM_STATE_OS_PREP))
+       if (!ret && (states & BOOTM_STATE_OS_PREP)) {
+#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
+               if (images->os.os == IH_OS_LINUX)
+                       fixup_silent_linux();
+#endif
                ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
+       }
 
 #ifdef CONFIG_TRACE
        /* Pretend to run the OS, then run a user command */
        if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) {
-               char *cmd_list = getenv("fakegocmd");
+               char *cmd_list = env_get("fakegocmd");
 
                ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO,
                                images, boot_fn);
@@ -771,7 +800,7 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
        const void *buf;
        const char      *fit_uname_config = NULL;
        const char      *fit_uname_kernel = NULL;
-#if defined(CONFIG_FIT)
+#if IMAGE_ENABLE_FIT
        int             os_noffset;
 #endif
 
@@ -781,9 +810,6 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
 
        bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
 
-       /* copy from dataflash if needed */
-       img_addr = genimg_get_image(img_addr);
-
        /* check image type, for FIT images get FIT kernel node */
        *os_data = *os_len = 0;
        buf = map_sysmem(img_addr, 0);
@@ -832,7 +858,7 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
                bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
                break;
 #endif
-#if defined(CONFIG_FIT)
+#if IMAGE_ENABLE_FIT
        case IMAGE_FORMAT_FIT:
                os_noffset = fit_image_load(images, img_addr,
                                &fit_uname_kernel, &fit_uname_config,