Merge git://git.denx.de/u-boot-video
[oweals/u-boot.git] / common / spl / spl_fit.c
index 9d9338caa7645934b8593edfb35fbcac0ba6492c..d2a352ecbe430f1d3e3bfae3ae05bba5f568417c 100644 (file)
 #include <libfdt.h>
 #include <spl.h>
 
-#define FDT_ERROR ((ulong)(-1))
-
-static ulong fdt_getprop_u32(const void *fdt, int node, const char *prop)
-{
-       const u32 *cell;
-       int len;
-
-       cell = fdt_getprop(fdt, node, prop, &len);
-       if (!cell || len != sizeof(*cell))
-               return FDT_ERROR;
-
-       return fdt32_to_cpu(*cell);
-}
-
-/*
- * Iterate over all /configurations subnodes and call a platform specific
- * function to find the matching configuration.
- * Returns the node offset or a negative error number.
- */
-static int spl_fit_find_config_node(const void *fdt)
-{
-       const char *name;
-       int conf, node, len;
-
-       conf = fdt_path_offset(fdt, FIT_CONFS_PATH);
-       if (conf < 0) {
-               debug("%s: Cannot find /configurations node: %d\n", __func__,
-                     conf);
-               return -EINVAL;
-       }
-       for (node = fdt_first_subnode(fdt, conf);
-            node >= 0;
-            node = fdt_next_subnode(fdt, node)) {
-               name = fdt_getprop(fdt, node, "description", &len);
-               if (!name) {
-#ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
-                       printf("%s: Missing FDT description in DTB\n",
-                              __func__);
-#endif
-                       return -EINVAL;
-               }
-               if (board_fit_config_name_match(name))
-                       continue;
-
-               debug("Selecting config '%s'", name);
-
-               return node;
-       }
-
-       return -ENOENT;
-}
-
 /**
  * spl_fit_get_image_node(): By using the matching configuration subnode,
  * retrieve the name of an image, specified by a property name and an index
@@ -82,7 +30,7 @@ static int spl_fit_get_image_node(const void *fit, int images,
        int node, conf_node;
        int len, i;
 
-       conf_node = spl_fit_find_config_node(fit);
+       conf_node = fit_find_config_node(fit);
        if (conf_node < 0) {
 #ifdef CONFIG_SPL_LIBCOMMON_SUPPORT
                printf("No matching DT out of these options:\n");
@@ -234,6 +182,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
        struct spl_image_info image_info;
        int node, images, ret;
        int base_offset, align_len = ARCH_DMA_MINALIGN - 1;
+       int index = 0;
 
        /*
         * Figure out where the external images start. This is the base for the
@@ -278,6 +227,11 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
        if (node < 0) {
                debug("could not find firmware image, trying loadables...\n");
                node = spl_fit_get_image_node(fit, images, "loadables", 0);
+               /*
+                * If we pick the U-Boot image from "loadables", start at
+                * the second image when later loading additional images.
+                */
+               index = 1;
        }
        if (node < 0) {
                debug("%s: Cannot find u-boot image node: %d\n",
@@ -305,6 +259,38 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
         * Align the destination address to ARCH_DMA_MINALIGN.
         */
        image_info.load_addr = spl_image->load_addr + spl_image->size;
-       return spl_load_fit_image(info, sector, fit, base_offset, node,
-                                 &image_info);
+       ret = spl_load_fit_image(info, sector, fit, base_offset, node,
+                                &image_info);
+       if (ret < 0)
+               return ret;
+
+       /* Now check if there are more images for us to load */
+       for (; ; index++) {
+               node = spl_fit_get_image_node(fit, images, "loadables", index);
+               if (node < 0)
+                       break;
+
+               ret = spl_load_fit_image(info, sector, fit, base_offset, node,
+                                        &image_info);
+               if (ret < 0)
+                       continue;
+
+               /*
+                * If the "firmware" image did not provide an entry point,
+                * use the first valid entry point from the loadables.
+                */
+               if (spl_image->entry_point == FDT_ERROR &&
+                   image_info.entry_point != FDT_ERROR)
+                       spl_image->entry_point = image_info.entry_point;
+       }
+
+       /*
+        * If a platform does not provide CONFIG_SYS_UBOOT_START, U-Boot's
+        * Makefile will set it to 0 and it will end up as the entry point
+        * here. What it actually means is: use the load address.
+        */
+       if (spl_image->entry_point == FDT_ERROR || spl_image->entry_point == 0)
+               spl_image->entry_point = spl_image->load_addr;
+
+       return 0;
 }