]> git.sur5r.net Git - u-boot/blobdiff - common/spl/spl_fit.c
Merge git://git.denx.de/u-boot-dm
[u-boot] / common / spl / spl_fit.c
index 128af1bbd675039e5acf5f8db570045816394328..5b51a28a086c7f9308b912ba3a0263e621ddca6f 100644 (file)
@@ -1,14 +1,13 @@
+// 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>
 #include <errno.h>
 #include <image.h>
-#include <libfdt.h>
+#include <linux/libfdt.h>
 #include <spl.h>
 
 #ifndef CONFIG_SYS_BOOTM_LEN
@@ -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;
@@ -173,25 +180,35 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
        int align_len = ARCH_DMA_MINALIGN - 1;
        uint8_t image_comp = -1, type = -1;
        const void *data;
+       bool external_data = false;
+
+       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))
                load_addr = image_info->load_addr;
 
-       if (!fit_image_get_data_offset(fit, node, &offset)) {
-               /* External data */
+       if (!fit_image_get_data_position(fit, node, &offset)) {
+               external_data = true;
+       } else if (!fit_image_get_data_offset(fit, node, &offset)) {
                offset += base_offset;
+               external_data = true;
+       }
+
+       if (external_data) {
+               /* External data */
                if (fit_image_get_data_size(fit, node, &len))
                        return -ENOENT;
 
@@ -200,9 +217,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);
 
-               if (info->read(info,
-                              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_offset,
                               nr_sectors, (void *)load_ptr) != nr_sectors)
                        return -EIO;
 
@@ -220,6 +244,15 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
                src = (void *)data;
        }
 
+#ifdef CONFIG_SPL_FIT_SIGNATURE
+       printf("## Checking hash(es) for Image %s ... ",
+              fit_get_name(fit, node, NULL));
+       if (!fit_image_verify_with_data(fit, node,
+                                        src, length))
+               return -EPERM;
+       puts("OK\n");
+#endif
+
 #ifdef CONFIG_SPL_FIT_IMAGE_POST_PROCESS
        board_fit_image_post_process(&src, &length);
 #endif
@@ -275,8 +308,10 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 
        /* Make the load-address of the FDT available for the SPL framework */
        spl_image->fdt_addr = (void *)image_info.load_addr;
+#if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
        /* Try to make space, so we can inject details on the loadables */
        ret = fdt_shrink_to_minimum(spl_image->fdt_addr, 8192);
+#endif
 
        return ret;
 }
@@ -284,8 +319,10 @@ static int spl_fit_append_fdt(struct spl_image_info *spl_image,
 static int spl_fit_record_loadable(const void *fit, int images, int index,
                                   void *blob, struct spl_image_info *image)
 {
+       int ret = 0;
+#if !CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
        char *name;
-       int node, ret;
+       int node;
 
        ret = spl_fit_get_image_name(fit, images, "loadables",
                                     index, &name);
@@ -298,9 +335,19 @@ static int spl_fit_record_loadable(const void *fit, int images, int index,
                                  image->size, image->entry_point,
                                  fdt_getprop(fit, node, "type", NULL),
                                  fdt_getprop(fit, node, "os", NULL));
+#endif
        return ret;
 }
 
+static int spl_fit_image_get_os(const void *fit, int noffset, uint8_t *os)
+{
+#if CONFIG_IS_ENABLED(FIT_IMAGE_TINY)
+       return -ENOTSUPP;
+#else
+       return fit_image_get_os(fit, noffset, os);
+#endif
+}
+
 int spl_load_simple_fit(struct spl_image_info *spl_image,
                        struct spl_load_info *info, ulong sector, void *fit)
 {
@@ -355,6 +402,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)
@@ -362,7 +423,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);
@@ -392,7 +454,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
         * For backward compatibility, we treat the first node that is
         * as a U-Boot image, if no OS-type has been declared.
         */
-       if (!fit_image_get_os(fit, node, &spl_image->os))
+       if (!spl_fit_image_get_os(fit, node, &spl_image->os))
                debug("Image OS is %s\n", genimg_get_os_name(spl_image->os));
 #if !defined(CONFIG_SPL_OS_BOOT)
        else
@@ -420,7 +482,7 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,
                if (ret < 0)
                        continue;
 
-               if (!fit_image_get_os(fit, node, &os_type))
+               if (!spl_fit_image_get_os(fit, node, &os_type))
                        debug("Loadable is %s\n", genimg_get_os_name(os_type));
 
                if (os_type == IH_OS_U_BOOT) {