pci: sata_sil: Drop DM_PCI checks
[platform/kernel/u-boot.git] / common / image-fdt.c
index 1d2263d..9441e63 100644 (file)
@@ -15,7 +15,9 @@
 #include <errno.h>
 #include <image.h>
 #include <lmb.h>
+#include <log.h>
 #include <malloc.h>
+#include <asm/global_data.h>
 #include <linux/libfdt.h>
 #include <mapmem.h>
 #include <asm/io.h>
@@ -73,18 +75,20 @@ static const image_header_t *image_get_fdt(ulong fdt_addr)
 #endif
 
 static void boot_fdt_reserve_region(struct lmb *lmb, uint64_t addr,
-                                   uint64_t size)
+                                   uint64_t size, enum lmb_flags flags)
 {
        long ret;
 
-       ret = lmb_reserve(lmb, addr, size);
+       ret = lmb_reserve_flags(lmb, addr, size, flags);
        if (ret >= 0) {
-               debug("   reserving fdt memory region: addr=%llx size=%llx\n",
-                     (unsigned long long)addr, (unsigned long long)size);
+               debug("   reserving fdt memory region: addr=%llx size=%llx flags=%x\n",
+                     (unsigned long long)addr,
+                     (unsigned long long)size, flags);
        } else {
                puts("ERROR: reserving fdt memory region failed ");
-               printf("(addr=%llx size=%llx)\n",
-                      (unsigned long long)addr, (unsigned long long)size);
+               printf("(addr=%llx size=%llx flags=%x)\n",
+                      (unsigned long long)addr,
+                      (unsigned long long)size, flags);
        }
 }
 
@@ -104,6 +108,7 @@ void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
        int i, total, ret;
        int nodeoffset, subnode;
        struct fdt_resource res;
+       enum lmb_flags flags;
 
        if (fdt_check_header(fdt_blob) != 0)
                return;
@@ -113,7 +118,7 @@ void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
        for (i = 0; i < total; i++) {
                if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0)
                        continue;
-               boot_fdt_reserve_region(lmb, addr, size);
+               boot_fdt_reserve_region(lmb, addr, size, LMB_NONE);
        }
 
        /* process reserved-memory */
@@ -125,9 +130,13 @@ void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
                        ret = fdt_get_resource(fdt_blob, subnode, "reg", 0,
                                               &res);
                        if (!ret && fdtdec_get_is_enabled(fdt_blob, subnode)) {
+                               flags = LMB_NONE;
+                               if (fdtdec_get_bool(fdt_blob, subnode,
+                                                   "no-map"))
+                                       flags = LMB_NOMAP;
                                addr = res.start;
                                size = res.end - res.start + 1;
-                               boot_fdt_reserve_region(lmb, addr, size);
+                               boot_fdt_reserve_region(lmb, addr, size, flags);
                        }
 
                        subnode = fdt_next_subnode(fdt_blob, subnode);
@@ -177,7 +186,7 @@ int boot_relocate_fdt(struct lmb *lmb, char **of_flat_tree, ulong *of_size)
        /* If fdt_high is set use it to select the relocation address */
        fdt_high = env_get("fdt_high");
        if (fdt_high) {
-               void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
+               void *desired_addr = (void *)hextoul(fdt_high, NULL);
 
                if (((ulong) desired_addr) == ~0UL) {
                        /* All ones means use fdt in place */
@@ -288,7 +297,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
        *of_size = 0;
 
        img_addr = (argc == 0) ? image_load_addr :
-                       simple_strtoul(argv[0], NULL, 16);
+                       hextoul(argv[0], NULL);
        buf = map_sysmem(img_addr, 0);
 
        if (argc > 2)
@@ -320,7 +329,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
                        } else
 #endif
                        {
-                               fdt_addr = simple_strtoul(select, NULL, 16);
+                               fdt_addr = hextoul(select, NULL);
                                debug("*  fdt: cmdline image address = 0x%08lx\n",
                                      fdt_addr);
                        }
@@ -398,7 +407,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
                         */
 #if CONFIG_IS_ENABLED(FIT)
                        /* check FDT blob vs FIT blob */
-                       if (fit_check_format(buf)) {
+                       if (!fit_check_format(buf, IMAGE_SIZE_INVAL)) {
                                ulong load, len;
 
                                fdt_noffset = boot_get_fdt_fit(images,
@@ -406,6 +415,9 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
                                        &fit_uname_config,
                                        arch, &load, &len);
 
+                               if (fdt_noffset < 0)
+                                       goto error;
+
                                images->fit_hdr_fdt = map_sysmem(fdt_addr, 0);
                                images->fit_uname_fdt = fit_uname_fdt;
                                images->fit_noffset_fdt = fdt_noffset;
@@ -425,7 +437,7 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
                        break;
                default:
                        puts("ERROR: Did not find a cmdline Flattened Device Tree\n");
-                       goto no_fdt;
+                       goto error;
                }
 
                printf("   Booting using the fdt blob at %#08lx\n", fdt_addr);
@@ -464,10 +476,20 @@ int boot_get_fdt(int flag, int argc, char *const argv[], uint8_t arch,
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
        } else if (genimg_get_format(buf) == IMAGE_FORMAT_ANDROID) {
                struct andr_img_hdr *hdr = buf;
-               ulong fdt_data, fdt_len;
+               ulong           fdt_data, fdt_len;
+               u32                     fdt_size, dtb_idx;
+               /*
+                * Firstly check if this android boot image has dtb field.
+                */
+               dtb_idx = (u32)env_get_ulong("adtb_idx", 10, 0);
+               if (android_image_get_dtb_by_index((ulong)hdr, dtb_idx, &fdt_addr, &fdt_size)) {
+                       fdt_blob = (char *)map_sysmem(fdt_addr, 0);
+                       if (fdt_check_header(fdt_blob))
+                               goto no_fdt;
 
-               if (!android_image_get_second(hdr, &fdt_data, &fdt_len) &&
-                   !fdt_check_header((char *)fdt_data)) {
+                       debug("## Using FDT in Android image dtb area with idx %u\n", dtb_idx);
+               } else if (!android_image_get_second(hdr, &fdt_data, &fdt_len) &&
+                       !fdt_check_header((char *)fdt_data)) {
                        fdt_blob = (char *)fdt_data;
                        if (fdt_totalsize(fdt_blob) != fdt_len)
                                goto error;
@@ -546,14 +568,33 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,
                printf("ERROR: arch-specific fdt fixup failed\n");
                goto err;
        }
+
+       fdt_ret = optee_copy_fdt_nodes(blob);
+       if (fdt_ret) {
+               printf("ERROR: transfer of optee nodes to new fdt failed: %s\n",
+                      fdt_strerror(fdt_ret));
+               goto err;
+       }
+
        /* Update ethernet nodes */
        fdt_fixup_ethernet(blob);
+#if CONFIG_IS_ENABLED(CMD_PSTORE)
+       /* Append PStore configuration */
+       fdt_fixup_pstore(blob);
+#endif
        if (IMAGE_OF_BOARD_SETUP) {
-               fdt_ret = ft_board_setup(blob, gd->bd);
-               if (fdt_ret) {
-                       printf("ERROR: board-specific fdt fixup failed: %s\n",
-                              fdt_strerror(fdt_ret));
-                       goto err;
+               const char *skip_board_fixup;
+
+               skip_board_fixup = env_get("skip_board_fixup");
+               if (skip_board_fixup && ((int)simple_strtol(skip_board_fixup, NULL, 10) == 1)) {
+                       printf("skip board fdt fixup\n");
+               } else {
+                       fdt_ret = ft_board_setup(blob, gd->bd);
+                       if (fdt_ret) {
+                               printf("ERROR: board-specific fdt fixup failed: %s\n",
+                                      fdt_strerror(fdt_ret));
+                               goto err;
+                       }
                }
        }
        if (IMAGE_OF_SYSTEM_SETUP) {
@@ -565,13 +606,6 @@ int image_setup_libfdt(bootm_headers_t *images, void *blob,
                }
        }
 
-       fdt_ret = optee_copy_fdt_nodes(gd->fdt_blob, blob);
-       if (fdt_ret) {
-               printf("ERROR: transfer of optee nodes to new fdt failed: %s\n",
-                      fdt_strerror(fdt_ret));
-               goto err;
-       }
-
        /* Delete the old LMB reservation */
        if (lmb)
                lmb_free(lmb, (phys_addr_t)(u32)(uintptr_t)blob,