]> git.sur5r.net Git - u-boot/blobdiff - common/spl/spl_fit.c
spl: fit: Fix support for loading FPGA bitstream
[u-boot] / common / spl / spl_fit.c
index be92ca4b4fd0f0ce04a6e360429d04e420f2c230..e01b4e578d94190e3324ce3c03d53f3cf43c6c6b 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2016 Google, Inc
  * Written by Simon Glass <sjg@chromium.org>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -141,6 +140,14 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size,
        return (data_size + info->bl_len - 1) / info->bl_len;
 }
 
+#ifdef CONFIG_SPL_FPGA_SUPPORT
+__weak int spl_load_fpga_image(struct spl_load_info *info, size_t length,
+                              int nr_sectors, int sector_offset)
+{
+       return 0;
+}
+#endif
+
 /**
  * spl_load_fit_image(): load the image described in a certain FIT node
  * @info:      points to information about the device to load data from
@@ -162,7 +169,7 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
                              void *fit, ulong base_offset, int node,
                              struct spl_image_info *image_info)
 {
-       int offset;
+       int offset, sector_offset;
        size_t length;
        int len;
        ulong size;
@@ -178,16 +185,19 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
        int ret;
 #endif
 
+       if (IS_ENABLED(CONFIG_SPL_FPGA_SUPPORT) ||
+           (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_GZIP))) {
+               if (fit_image_get_type(fit, node, &type))
+                       puts("Cannot get image type.\n");
+               else
+                       debug("%s ", genimg_get_type_name(type));
+       }
+
        if (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_GZIP)) {
                if (fit_image_get_comp(fit, node, &image_comp))
                        puts("Cannot get image compression format.\n");
                else
                        debug("%s ", genimg_get_comp_name(image_comp));
-
-               if (fit_image_get_type(fit, node, &type))
-                       puts("Cannot get image type.\n");
-               else
-                       debug("%s ", genimg_get_type_name(type));
        }
 
        if (fit_image_get_load(fit, node, &load_addr))
@@ -210,9 +220,16 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
 
                overhead = get_aligned_image_overhead(info, offset);
                nr_sectors = get_aligned_image_size(info, length, offset);
+               sector_offset = sector + get_aligned_image_offset(info, offset);
+
+#ifdef CONFIG_SPL_FPGA_SUPPORT
+               if (type == IH_TYPE_FPGA) {
+                       return spl_load_fpga_image(info, length, nr_sectors,
+                                                  sector_offset);
+               }
+#endif
 
-               if (info->read(info,
-                              sector + get_aligned_image_offset(info, offset),
+               if (info->read(info, sector_offset,
                               nr_sectors, (void *)load_ptr) != nr_sectors)
                        return -EIO;
 
@@ -388,6 +405,20 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
                return -1;
        }
 
+#ifdef CONFIG_SPL_FPGA_SUPPORT
+       node = spl_fit_get_image_node(fit, images, "fpga", 0);
+       if (node >= 0) {
+               /* Load the image and set up the spl_image structure */
+               ret = spl_load_fit_image(info, sector, fit, base_offset, node,
+                                        spl_image);
+               if (ret) {
+                       printf("%s: Cannot load the FPGA: %i\n", __func__, ret);
+                       return ret;
+               }
+               node = -1;
+       }
+#endif
+
        /*
         * Find the U-Boot image using the following search order:
         *   - start at 'firmware' (e.g. an ARM Trusted Firmware)
@@ -395,7 +426,8 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
         *   - fall back to using the first 'loadables' entry
         */
        if (node < 0)
-               node = spl_fit_get_image_node(fit, images, "firmware", 0);
+               node = spl_fit_get_image_node(fit, images, FIT_FIRMWARE_PROP,
+                                             0);
 #ifdef CONFIG_SPL_OS_BOOT
        if (node < 0)
                node = spl_fit_get_image_node(fit, images, FIT_KERNEL_PROP, 0);