spl: Convert spl_spi_load_image() to use linker list
[oweals/u-boot.git] / common / spl / spl_fit.c
index a828f72da84fa798cfd4f903ab19d7501a8636d3..be86072c24e8138dc66be8be456d70ffe931ea4e 100644 (file)
@@ -77,7 +77,7 @@ static int spl_fit_select_fdt(const void *fdt, int images, int *fdt_offsetp)
        for (node = fdt_first_subnode(fdt, conf);
             node >= 0;
             node = fdt_next_subnode(fdt, node)) {
-               name = fdt_getprop(fdt, node, "name", &len);
+               name = fdt_getprop(fdt, node, "description", &len);
                printf("   %s\n", name);
        }
 #endif
@@ -115,8 +115,10 @@ static int get_aligned_image_overhead(struct spl_load_info *info, int offset)
 static int get_aligned_image_size(struct spl_load_info *info, int data_size,
                                  int offset)
 {
+       data_size = data_size + get_aligned_image_overhead(info, offset);
+
        if (info->filename)
-               return data_size + get_aligned_image_overhead(info, offset);
+               return data_size;
 
        return (data_size + info->bl_len - 1) / info->bl_len;
 }
@@ -132,7 +134,7 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
        int data_offset, data_size;
        int base_offset, align_len = ARCH_DMA_MINALIGN - 1;
        int src_sector;
-       void *dst;
+       void *dst, *src;
 
        /*
         * Figure out where the external images start. This is the base for the
@@ -156,8 +158,8 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
         * In fact the FIT has its own load address, but we assume it cannot
         * be before CONFIG_SYS_TEXT_BASE.
         */
-       fit = (void *)(CONFIG_SYS_TEXT_BASE - size - info->bl_len);
-       fit = (void *)ALIGN((ulong)fit, 8);
+       fit = (void *)((CONFIG_SYS_TEXT_BASE - size - info->bl_len -
+                       align_len) & ~align_len);
        sectors = get_aligned_image_size(info, size, 0);
        count = info->read(info, sector, sectors, fit);
        debug("fit read sector %lx, sectors=%d, dst=%p, count=%lu\n",
@@ -206,8 +208,13 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
                return -EIO;
        debug("image: dst=%p, data_offset=%x, size=%x\n", dst, data_offset,
              data_size);
-       memcpy(dst, dst + get_aligned_image_overhead(info, data_offset),
-              data_size);
+       src = dst + get_aligned_image_overhead(info, data_offset);
+
+#ifdef CONFIG_SPL_FIT_IMAGE_POST_PROCESS
+       board_fit_image_post_process((void **)&src, (size_t *)&data_size);
+#endif
+
+       memcpy(dst, src, data_size);
 
        /* Figure out which device tree the board wants to use */
        fdt_len = spl_fit_select_fdt(fit, images, &fdt_offset);
@@ -236,8 +243,14 @@ int spl_load_simple_fit(struct spl_load_info *info, ulong sector, void *fit)
         */
        debug("fdt: dst=%p, data_offset=%x, size=%x\n", dst, fdt_offset,
              fdt_len);
-       memcpy(load_ptr + data_size,
-              dst + get_aligned_image_overhead(info, fdt_offset), fdt_len);
+       src = dst + get_aligned_image_overhead(info, fdt_offset);
+       dst = load_ptr + data_size;
+
+#ifdef CONFIG_SPL_FIT_IMAGE_POST_PROCESS
+       board_fit_image_post_process((void **)&src, (size_t *)&fdt_len);
+#endif
+
+       memcpy(dst, src, fdt_len);
 
        return 0;
 }