image: Add crypto_algo struct for RSA info
[oweals/u-boot.git] / common / image-fit.c
index 8a0ca2a8038db5f3aba06cf1cc5244988b6d056f..77dc011dc3bfc25f5e9d084f54bb25192dda9367 100644 (file)
@@ -11,9 +11,9 @@
 
 #ifdef USE_HOSTCC
 #include "mkimage.h"
-#include <image.h>
 #include <time.h>
 #else
+#include <linux/compiler.h>
 #include <common.h>
 #include <errno.h>
 #include <mapmem.h>
@@ -21,6 +21,7 @@
 DECLARE_GLOBAL_DATA_PTR;
 #endif /* !USE_HOSTCC*/
 
+#include <image.h>
 #include <bootstage.h>
 #include <u-boot/crc.h>
 #include <u-boot/md5.h>
@@ -147,7 +148,7 @@ int fit_get_subimage_count(const void *fit, int images_noffset)
  * @p: pointer to prefix string
  *
  * fit_print_contents() formats a multi line FIT image contents description.
- * The routine prints out FIT image properties (root node level) follwed by
+ * The routine prints out FIT image properties (root node level) followed by
  * the details of each component image.
  *
  * returns:
@@ -249,7 +250,7 @@ void fit_print_contents(const void *fit)
  * @p: pointer to prefix string
  * @type: Type of information to print ("hash" or "sign")
  *
- * fit_image_print_data() lists properies for the processed hash node
+ * fit_image_print_data() lists properties for the processed hash node
  *
  * This function avoid using puts() since it prints a newline on the host
  * but does not in U-Boot.
@@ -314,7 +315,7 @@ static void fit_image_print_data(const void *fit, int noffset, const char *p,
  * @noffset: offset of the hash or signature node
  * @p: pointer to prefix string
  *
- * This lists properies for the processed hash node
+ * This lists properties for the processed hash node
  *
  * returns:
  *     no returned results
@@ -344,7 +345,7 @@ static void fit_image_print_verification_data(const void *fit, int noffset,
  * @image_noffset: offset of the component image node
  * @p: pointer to prefix string
  *
- * fit_image_print() lists all mandatory properies for the processed component
+ * fit_image_print() lists all mandatory properties for the processed component
  * image. If present, hash nodes are printed out as well. Load
  * address for images of type firmware is also printed out. Since the load
  * address is not mandatory for firmware images, it will be output as
@@ -422,7 +423,8 @@ void fit_image_print(const void *fit, int image_noffset, const char *p)
        }
 
        if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
-           (type == IH_TYPE_FIRMWARE) || (type == IH_TYPE_RAMDISK)) {
+           (type == IH_TYPE_FIRMWARE) || (type == IH_TYPE_RAMDISK) ||
+           (type == IH_TYPE_FPGA)) {
                ret = fit_image_get_load(fit, image_noffset, &load);
                printf("%s  Load Address: ", p);
                if (ret)
@@ -458,10 +460,10 @@ void fit_image_print(const void *fit, int image_noffset, const char *p)
  * fit_get_desc - get node description property
  * @fit: pointer to the FIT format image header
  * @noffset: node offset
- * @desc: double pointer to the char, will hold pointer to the descrption
+ * @desc: double pointer to the char, will hold pointer to the description
  *
  * fit_get_desc() reads description property from a given node, if
- * description is found pointer to it is returened in third call argument.
+ * description is found pointer to it is returned in third call argument.
  *
  * returns:
  *     0, on success
@@ -486,8 +488,8 @@ int fit_get_desc(const void *fit, int noffset, char **desc)
  * @noffset: node offset
  * @timestamp: pointer to the time_t, will hold read timestamp
  *
- * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
- * is found and has a correct size its value is retured in third call
+ * fit_get_timestamp() reads timestamp property from given node, if timestamp
+ * is found and has a correct size its value is returned in third call
  * argument.
  *
  * returns:
@@ -519,7 +521,7 @@ int fit_get_timestamp(const void *fit, int noffset, time_t *timestamp)
  * @fit: pointer to the FIT format image header
  * @image_uname: component image node unit name
  *
- * fit_image_get_node() finds a component image (withing the '/images'
+ * fit_image_get_node() finds a component image (within the '/images'
  * node) of a provided unit name. If image is found its node offset is
  * returned to the caller.
  *
@@ -988,7 +990,7 @@ static int fit_image_check_hash(const void *fit, int noffset, const void *data,
 }
 
 /**
- * fit_image_verify - verify data intergity
+ * fit_image_verify - verify data integrity
  * @fit: pointer to the FIT format image header
  * @image_noffset: component image node offset
  *
@@ -1024,7 +1026,7 @@ int fit_image_verify(const void *fit, int image_noffset)
        }
 
        /* Process all hash subnodes of the component image node */
-       fdt_for_each_subnode(fit, noffset, image_noffset) {
+       fdt_for_each_subnode(noffset, fit, image_noffset) {
                const char *name = fit_get_name(fit, noffset, NULL);
 
                /*
@@ -1072,7 +1074,7 @@ error:
 }
 
 /**
- * fit_all_image_verify - verify data intergity for all images
+ * fit_all_image_verify - verify data integrity for all images
  * @fit: pointer to the FIT format image header
  *
  * fit_all_image_verify() goes over all images in the FIT and
@@ -1379,8 +1381,8 @@ int fit_conf_find_compat(const void *fit, const void *fdt)
  * @fit: pointer to the FIT format image header
  * @conf_uname: configuration node unit name
  *
- * fit_conf_get_node() finds a configuration (withing the '/configurations'
- * parant node) of a provided unit name. If configuration is found its node
+ * fit_conf_get_node() finds a configuration (within the '/configurations'
+ * parent node) of a provided unit name. If configuration is found its node
  * offset is returned to the caller.
  *
  * When NULL is provided in second argument fit_conf_get_node() will search
@@ -1446,7 +1448,7 @@ int fit_conf_get_prop_node(const void *fit, int noffset,
  * @noffset: offset of the configuration node
  * @p: pointer to prefix string
  *
- * fit_conf_print() lists all mandatory properies for the processed
+ * fit_conf_print() lists all mandatory properties for the processed
  * configuration node.
  *
  * returns:
@@ -1455,7 +1457,7 @@ int fit_conf_get_prop_node(const void *fit, int noffset,
 void fit_conf_print(const void *fit, int noffset, const char *p)
 {
        char *desc;
-       char *uname;
+       const char *uname;
        int ret;
        int loadables_index;
 
@@ -1467,7 +1469,7 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
        else
                printf("%s\n", desc);
 
-       uname = (char *)fdt_getprop(fit, noffset, FIT_KERNEL_PROP, NULL);
+       uname = fdt_getprop(fit, noffset, FIT_KERNEL_PROP, NULL);
        printf("%s  Kernel:       ", p);
        if (uname == NULL)
                printf("unavailable\n");
@@ -1475,26 +1477,23 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
                printf("%s\n", uname);
 
        /* Optional properties */
-       uname = (char *)fdt_getprop(fit, noffset, FIT_RAMDISK_PROP, NULL);
+       uname = fdt_getprop(fit, noffset, FIT_RAMDISK_PROP, NULL);
        if (uname)
                printf("%s  Init Ramdisk: %s\n", p, uname);
 
-       uname = (char *)fdt_getprop(fit, noffset, FIT_FDT_PROP, NULL);
+       uname = fdt_getprop(fit, noffset, FIT_FDT_PROP, NULL);
        if (uname)
                printf("%s  FDT:          %s\n", p, uname);
 
-       uname = (char *)fdt_getprop(fit, noffset, FIT_FPGA_PROP, NULL);
+       uname = fdt_getprop(fit, noffset, FIT_FPGA_PROP, NULL);
        if (uname)
                printf("%s  FPGA:         %s\n", p, uname);
 
        /* Print out all of the specified loadables */
        for (loadables_index = 0;
-            fdt_get_string_index(fit, noffset,
-                       FIT_LOADABLE_PROP,
-                       loadables_index,
-                       (const char **)&uname) == 0;
-            loadables_index++)
-       {
+            uname = fdt_stringlist_get(fit, noffset, FIT_LOADABLE_PROP,
+                                       loadables_index, NULL), uname;
+            loadables_index++) {
                if (loadables_index == 0) {
                        printf("%s  Loadables:    ", p);
                } else {
@@ -1506,6 +1505,12 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
 
 static int fit_image_select(const void *fit, int rd_noffset, int verify)
 {
+#if !defined(USE_HOSTCC) && defined(CONFIG_FIT_IMAGE_POST_PROCESS)
+       const void *data;
+       size_t size;
+       int ret;
+#endif
+
        fit_image_print(fit, rd_noffset, "   ");
 
        if (verify) {
@@ -1517,6 +1522,23 @@ static int fit_image_select(const void *fit, int rd_noffset, int verify)
                puts("OK\n");
        }
 
+#if !defined(USE_HOSTCC) && defined(CONFIG_FIT_IMAGE_POST_PROCESS)
+       ret = fit_image_get_data(fit, rd_noffset, &data, &size);
+       if (ret)
+               return ret;
+
+       /* perform any post-processing on the image data */
+       board_fit_image_post_process((void **)&data, &size);
+
+       /*
+        * update U-Boot's understanding of the "data" property start address
+        * and size according to the performed post-processing
+        */
+       ret = fdt_setprop((void *)fit, rd_noffset, FIT_DATA_PROP, data, size);
+       if (ret)
+               return ret;
+#endif
+
        return 0;
 }
 
@@ -1535,13 +1557,13 @@ int fit_get_node_from_config(bootm_headers_t *images, const char *prop_name,
        cfg_noffset = fit_conf_get_node(fit_hdr, images->fit_uname_cfg);
        if (cfg_noffset < 0) {
                debug("*  %s: no such config\n", prop_name);
-               return -ENOENT;
+               return -EINVAL;
        }
 
        noffset = fit_conf_get_prop_node(fit_hdr, cfg_noffset, prop_name);
        if (noffset < 0) {
                debug("*  %s: no '%s' in config\n", prop_name, prop_name);
-               return -ENOLINK;
+               return -ENOENT;
        }
 
        return noffset;
@@ -1557,7 +1579,7 @@ static const char *fit_get_image_type_property(int type)
 {
        /*
         * This is sort-of available in the uimage_type[] table in image.c
-        * but we don't have access to the sohrt name, and "fdt" is different
+        * but we don't have access to the short name, and "fdt" is different
         * anyway. So let's just keep it here.
         */
        switch (type) {
@@ -1571,6 +1593,8 @@ static const char *fit_get_image_type_property(int type)
                return FIT_SETUP_PROP;
        case IH_TYPE_LOADABLE:
                return FIT_LOADABLE_PROP;
+       case IH_TYPE_FPGA:
+               return FIT_FPGA_PROP;
        }
 
        return "unknown";
@@ -1681,12 +1705,14 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
 
        bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL);
        type_ok = fit_image_check_type(fit, noffset, image_type) ||
-               (image_type == IH_TYPE_KERNEL &&
-                       fit_image_check_type(fit, noffset,
-                                            IH_TYPE_KERNEL_NOLOAD));
+                 fit_image_check_type(fit, noffset, IH_TYPE_FIRMWARE) ||
+                 (image_type == IH_TYPE_KERNEL &&
+                  fit_image_check_type(fit, noffset, IH_TYPE_KERNEL_NOLOAD));
 
        os_ok = image_type == IH_TYPE_FLATDT ||
+               image_type == IH_TYPE_FPGA ||
                fit_image_check_os(fit, noffset, IH_OS_LINUX) ||
+               fit_image_check_os(fit, noffset, IH_OS_U_BOOT) ||
                fit_image_check_os(fit, noffset, IH_OS_OPENRTOS);
 
        /*