]> git.sur5r.net Git - u-boot/blobdiff - common/image-fit.c
spi: atcspi200: avoid NULL dereference
[u-boot] / common / image-fit.c
index f6e956ad963a0d2a390c64bed812b23de9d4dbbc..5b93dceae15c045aaefc3061c8fa0456da313a1c 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2013, Google Inc.
  *
@@ -5,8 +6,6 @@
  *
  * (C) Copyright 2000-2006
  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #ifdef USE_HOSTCC
@@ -419,7 +418,8 @@ void fit_image_print(const void *fit, int image_noffset, const char *p)
                printf("%s  Architecture: %s\n", p, genimg_get_arch_name(arch));
        }
 
-       if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_RAMDISK)) {
+       if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_RAMDISK) ||
+           (type == IH_TYPE_FIRMWARE)) {
                fit_image_get_os(fit, image_noffset, &os);
                printf("%s  OS:           %s\n", p, genimg_get_os_name(os));
        }
@@ -1068,34 +1068,14 @@ static int fit_image_check_hash(const void *fit, int noffset, const void *data,
        return 0;
 }
 
-/**
- * fit_image_verify - verify data integrity
- * @fit: pointer to the FIT format image header
- * @image_noffset: component image node offset
- *
- * fit_image_verify() goes over component image hash nodes,
- * re-calculates each data hash and compares with the value stored in hash
- * node.
- *
- * returns:
- *     1, if all hashes are valid
- *     0, otherwise (or on error)
- */
-int fit_image_verify(const void *fit, int image_noffset)
+int fit_image_verify_with_data(const void *fit, int image_noffset,
+                              const void *data, size_t size)
 {
-       const void      *data;
-       size_t          size;
        int             noffset = 0;
        char            *err_msg = "";
        int verify_all = 1;
        int ret;
 
-       /* Get image data and data length */
-       if (fit_image_get_data(fit, image_noffset, &data, &size)) {
-               err_msg = "Can't get image data/size";
-               goto error;
-       }
-
        /* Verify all required signatures */
        if (IMAGE_ENABLE_VERIFY &&
            fit_image_verify_required_sigs(fit, image_noffset, data, size,
@@ -1152,6 +1132,38 @@ error:
        return 0;
 }
 
+/**
+ * fit_image_verify - verify data integrity
+ * @fit: pointer to the FIT format image header
+ * @image_noffset: component image node offset
+ *
+ * fit_image_verify() goes over component image hash nodes,
+ * re-calculates each data hash and compares with the value stored in hash
+ * node.
+ *
+ * returns:
+ *     1, if all hashes are valid
+ *     0, otherwise (or on error)
+ */
+int fit_image_verify(const void *fit, int image_noffset)
+{
+       const void      *data;
+       size_t          size;
+       int             noffset = 0;
+       char            *err_msg = "";
+
+       /* Get image data and data length */
+       if (fit_image_get_data(fit, image_noffset, &data, &size)) {
+               err_msg = "Can't get image data/size";
+               printf("error!\n%s for '%s' hash node in '%s' image node\n",
+                      err_msg, fit_get_name(fit, noffset, NULL),
+                      fit_get_name(fit, image_noffset, NULL));
+               return 0;
+       }
+
+       return fit_image_verify_with_data(fit, image_noffset, data, size);
+}
+
 /**
  * fit_all_image_verify - verify data integrity for all images
  * @fit: pointer to the FIT format image header
@@ -1559,6 +1571,7 @@ int fit_conf_get_prop_node(const void *fit, int noffset,
        return fit_conf_get_prop_node_index(fit, noffset, prop_name, 0);
 }
 
+#if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_FIT_SPL_PRINT)
 /**
  * fit_conf_print - prints out the FIT configuration details
  * @fit: pointer to the FIT format image header
@@ -1577,6 +1590,7 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
        const char *uname;
        int ret;
        int fdt_index, loadables_index;
+       int ndepth;
 
        /* Mandatory properties */
        ret = fit_get_desc(fit, noffset, &desc);
@@ -1598,6 +1612,10 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
        if (uname)
                printf("%s  Init Ramdisk: %s\n", p, uname);
 
+       uname = fdt_getprop(fit, noffset, FIT_FIRMWARE_PROP, NULL);
+       if (uname)
+               printf("%s  Firmware:     %s\n", p, uname);
+
        for (fdt_index = 0;
             uname = fdt_stringlist_get(fit, noffset, FIT_FDT_PROP,
                                        fdt_index, NULL), uname;
@@ -1626,7 +1644,18 @@ void fit_conf_print(const void *fit, int noffset, const char *p)
                }
                printf("%s\n", uname);
        }
+
+       /* Process all hash subnodes of the component configuration node */
+       for (ndepth = 0, noffset = fdt_next_node(fit, noffset, &ndepth);
+            (noffset >= 0) && (ndepth > 0);
+            noffset = fdt_next_node(fit, noffset, &ndepth)) {
+               if (ndepth == 1) {
+                       /* Direct child node of the component configuration node */
+                       fit_image_print_verification_data(fit, noffset, p);
+               }
+       }
 }
+#endif /* !defined(CONFIG_SPL_BUILD) || defined(CONFIG_FIT_SPL_PRINT) */
 
 static int fit_image_select(const void *fit, int rd_noffset, int verify)
 {