]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/bootm.c
arm, at91, mpddrc: fix typo in ddr2_init()
[karo-tx-uboot.git] / common / bootm.c
index d93d3f3f104cd48da66649ef8201181a7a17e22d..6b3ea8c61b69c180e146cf5607a7780e2726f996 100644 (file)
@@ -9,6 +9,7 @@
 #include <common.h>
 #include <bootstage.h>
 #include <bzlib.h>
+#include <errno.h>
 #include <fdt_support.h>
 #include <lmb.h>
 #include <malloc.h>
@@ -83,6 +84,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
 {
        const void *os_hdr;
        bool ep_found = false;
+       int ret;
 
        /* get kernel image header, start address and length */
        os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
@@ -102,6 +104,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
 
                images.os.end = image_get_image_end(os_hdr);
                images.os.load = image_get_load(os_hdr);
+               images.os.arch = image_get_arch(os_hdr);
                break;
 #endif
 #if defined(CONFIG_FIT)
@@ -129,6 +132,13 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
                        return 1;
                }
 
+               if (fit_image_get_arch(images.fit_hdr_os,
+                                      images.fit_noffset_os,
+                                      &images.os.arch)) {
+                       puts("Can't get image ARCH!\n");
+                       return 1;
+               }
+
                images.os.end = fit_get_end(images.fit_hdr_os);
 
                if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
@@ -144,11 +154,11 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
                images.os.type = IH_TYPE_KERNEL;
                images.os.comp = IH_COMP_NONE;
                images.os.os = IH_OS_LINUX;
-               images.ep = images.os.load;
-               ep_found = true;
 
                images.os.end = android_image_get_end(os_hdr);
                images.os.load = android_image_get_kload(os_hdr);
+               images.ep = images.os.load;
+               ep_found = true;
                break;
 #endif
        default:
@@ -156,8 +166,18 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
                return 1;
        }
 
-       /* find kernel entry point */
-       if (images.legacy_hdr_valid) {
+       /* If we have a valid setup.bin, we will use that for entry (x86) */
+       if (images.os.arch == IH_ARCH_I386 ||
+           images.os.arch == IH_ARCH_X86_64) {
+               ulong len;
+
+               ret = boot_get_setup(&images, IH_ARCH_I386, &images.ep, &len);
+               if (ret < 0 && ret != -ENOENT) {
+                       puts("Could not find a valid setup.bin for x86\n");
+                       return 1;
+               }
+               /* 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)
        } else if (images.fit_uname_os) {
@@ -244,6 +264,7 @@ static int bootm_find_other(cmd_tbl_t *cmdtp, int flag, int argc,
 
        return 0;
 }
+#endif /* USE_HOSTCC */
 
 /**
  * decomp_image() - decompress the operating system
@@ -353,6 +374,7 @@ static int decomp_image(int comp, ulong load, ulong image_start, int type,
        return 0;
 }
 
+#ifndef USE_HOSTCC
 static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
                         int boot_progress)
 {
@@ -723,32 +745,15 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
 #endif
        ulong           img_addr;
        const void *buf;
-#if defined(CONFIG_FIT)
        const char      *fit_uname_config = NULL;
        const char      *fit_uname_kernel = NULL;
+#if defined(CONFIG_FIT)
        int             os_noffset;
 #endif
 
-       /* find out kernel image address */
-       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[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[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[0], NULL, 16);
-               debug("*  kernel: cmdline image address = 0x%08lx\n",
-                     img_addr);
-       }
+       img_addr = genimg_get_kernel_addr_fit(argc < 1 ? NULL : argv[0],
+                                             &fit_uname_config,
+                                             &fit_uname_kernel);
 
        bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
 
@@ -838,5 +843,74 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
 
        return buf;
 }
+#else /* USE_HOSTCC */
+
+void memmove_wd(void *to, void *from, size_t len, ulong chunksz)
+{
+       memmove(to, from, len);
+}
+
+static int bootm_host_load_image(const void *fit, int req_image_type)
+{
+       const char *fit_uname_config = NULL;
+       ulong data, len;
+       bootm_headers_t images;
+       int noffset;
+       ulong load_end;
+       uint8_t image_type;
+       uint8_t imape_comp;
+       void *load_buf;
+       int ret;
+
+       memset(&images, '\0', sizeof(images));
+       images.verify = 1;
+       noffset = fit_image_load(&images, (ulong)fit,
+               NULL, &fit_uname_config,
+               IH_ARCH_DEFAULT, req_image_type, -1,
+               FIT_LOAD_IGNORED, &data, &len);
+       if (noffset < 0)
+               return noffset;
+       if (fit_image_get_type(fit, noffset, &image_type)) {
+               puts("Can't get image type!\n");
+               return -EINVAL;
+       }
+
+       if (fit_image_get_comp(fit, noffset, &imape_comp)) {
+               puts("Can't get image compression!\n");
+               return -EINVAL;
+       }
+
+       /* Allow the image to expand by a factor of 4, should be safe */
+       load_buf = malloc((1 << 20) + len * 4);
+       ret = decomp_image(imape_comp, 0, data, image_type, load_buf,
+                          (void *)data, len, &load_end);
+       free(load_buf);
+       if (ret && ret != BOOTM_ERR_UNIMPLEMENTED)
+               return ret;
+
+       return 0;
+}
+
+int bootm_host_load_images(const void *fit, int cfg_noffset)
+{
+       static uint8_t image_types[] = {
+               IH_TYPE_KERNEL,
+               IH_TYPE_FLATDT,
+               IH_TYPE_RAMDISK,
+       };
+       int err = 0;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(image_types); i++) {
+               int ret;
+
+               ret = bootm_host_load_image(fit, image_types[i]);
+               if (!err && ret && ret != -ENOENT)
+                       err = ret;
+       }
+
+       /* Return the first error we found */
+       return err;
+}
 
 #endif /* ndef USE_HOSTCC */