efi_loader: implement MCastIPtoMAC
[oweals/u-boot.git] / common / image-fdt.c
index 94089b2215ca4b37be1a16b27417da953d804c4b..4247dcee0c4f71d6626ffa31337c9313ff45b335 100644 (file)
@@ -11,6 +11,7 @@
 #include <common.h>
 #include <fdt_support.h>
 #include <fdtdec.h>
+#include <env.h>
 #include <errno.h>
 #include <image.h>
 #include <linux/libfdt.h>
@@ -33,7 +34,7 @@ static void fdt_error(const char *msg)
        puts(" - must RESET the board to recover.\n");
 }
 
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
 static const image_header_t *image_get_fdt(ulong fdt_addr)
 {
        const image_header_t *fdt_hdr = map_sysmem(fdt_addr, 0);
@@ -71,10 +72,10 @@ static const image_header_t *image_get_fdt(ulong fdt_addr)
 static void boot_fdt_reserve_region(struct lmb *lmb, uint64_t addr,
                                    uint64_t size)
 {
-       int ret;
+       long ret;
 
        ret = lmb_reserve(lmb, addr, size);
-       if (!ret) {
+       if (ret >= 0) {
                debug("   reserving fdt memory region: addr=%llx size=%llx\n",
                      (unsigned long long)addr, (unsigned long long)size);
        } else {
@@ -263,7 +264,7 @@ error:
 int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
                bootm_headers_t *images, char **of_flat_tree, ulong *of_size)
 {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
        const image_header_t *fdt_hdr;
        ulong           load, load_end;
        ulong           image_start, image_data, image_end;
@@ -279,12 +280,11 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
        int             fdt_noffset;
 #endif
        const char *select = NULL;
-       int             ok_no_fdt = 0;
 
        *of_flat_tree = NULL;
        *of_size = 0;
 
-       img_addr = simple_strtoul(argv[0], NULL, 16);
+       img_addr = (argc == 0) ? load_addr : simple_strtoul(argv[0], NULL, 16);
        buf = map_sysmem(img_addr, 0);
 
        if (argc > 2)
@@ -345,7 +345,7 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
                 */
                buf = map_sysmem(fdt_addr, 0);
                switch (genimg_get_format(buf)) {
-#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+#if CONFIG_IS_ENABLED(LEGACY_IMAGE_FORMAT)
                case IMAGE_FORMAT_LEGACY:
                        /* verify fdt_addr points to a valid image header */
                        printf("## Flattened Device Tree from Legacy Image at %08lx\n",
@@ -462,17 +462,24 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
                struct andr_img_hdr *hdr = buf;
                ulong fdt_data, fdt_len;
 
-               if (android_image_get_second(hdr, &fdt_data, &fdt_len) != 0)
-                       goto no_fdt;
+               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;
 
-               fdt_blob = (char *)fdt_data;
-               if (fdt_check_header(fdt_blob) != 0)
-                       goto no_fdt;
+                       debug("## Using FDT in Android image second area\n");
+               } else {
+                       fdt_addr = env_get_hex("fdtaddr", 0);
+                       if (!fdt_addr)
+                               goto no_fdt;
 
-               if (fdt_totalsize(fdt_blob) != fdt_len)
-                       goto error;
+                       fdt_blob = map_sysmem(fdt_addr, 0);
+                       if (fdt_check_header(fdt_blob))
+                               goto no_fdt;
 
-               debug("## Using FDT found in Android image second area\n");
+                       debug("## Using FDT at ${fdtaddr}=Ox%lx\n", fdt_addr);
+               }
 #endif
        } else {
                debug("## No Flattened Device Tree\n");
@@ -487,14 +494,9 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
        return 0;
 
 no_fdt:
-       ok_no_fdt = 1;
+       debug("Continuing to boot without FDT\n");
+       return 0;
 error:
-       *of_flat_tree = NULL;
-       *of_size = 0;
-       if (!select && ok_no_fdt) {
-               debug("Continuing to boot without FDT\n");
-               return 0;
-       }
        return 1;
 }