]> git.sur5r.net Git - u-boot/blobdiff - common/image-fit.c
fit: Verify all configuration signatures
[u-boot] / common / image-fit.c
index 9224456b612a31930cd048700bccc631ad3f13a4..8d39a243f8d1e874a69a24df7d56df87028c142e 100644 (file)
@@ -474,7 +474,7 @@ void fit_image_print(const void *fit, int image_noffset, const char *p)
        fit_image_get_comp(fit, image_noffset, &comp);
        printf("%s  Compression:  %s\n", p, genimg_get_comp_name(comp));
 
-       ret = fit_image_get_data(fit, image_noffset, &data, &size);
+       ret = fit_image_get_data_and_size(fit, image_noffset, &data, &size);
 
 #ifndef USE_HOSTCC
        printf("%s  Data Start:   ", p);
@@ -542,7 +542,9 @@ void fit_image_print(const void *fit, int image_noffset, const char *p)
                }
        }
 }
-
+#else
+void fit_print_contents(const void *fit) { }
+void fit_image_print(const void *fit, int image_noffset, const char *p) { }
 #endif /* !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_FIT_PRINT) */
 
 /**
@@ -938,6 +940,54 @@ int fit_image_get_data_size(const void *fit, int noffset, int *data_size)
        return 0;
 }
 
+/**
+ * fit_image_get_data_and_size - get data and its size including
+ *                              both embedded and external data
+ * @fit: pointer to the FIT format image header
+ * @noffset: component image node offset
+ * @data: double pointer to void, will hold data property's data address
+ * @size: pointer to size_t, will hold data property's data size
+ *
+ * fit_image_get_data_and_size() finds data and its size including
+ * both embedded and external data. If the property is found
+ * its data start address and size are returned to the caller.
+ *
+ * returns:
+ *     0, on success
+ *     otherwise, on failure
+ */
+int fit_image_get_data_and_size(const void *fit, int noffset,
+                               const void **data, size_t *size)
+{
+       bool external_data = false;
+       int offset;
+       int len;
+       int ret;
+
+       if (!fit_image_get_data_position(fit, noffset, &offset)) {
+               external_data = true;
+       } else if (!fit_image_get_data_offset(fit, noffset, &offset)) {
+               external_data = true;
+               /*
+                * For FIT with external data, figure out where
+                * the external images start. This is the base
+                * for the data-offset properties in each image.
+                */
+               offset += ((fdt_totalsize(fit) + 3) & ~3);
+       }
+
+       if (external_data) {
+               debug("External Data\n");
+               ret = fit_image_get_data_size(fit, noffset, &len);
+               *data = fit + offset;
+               *size = len;
+       } else {
+               ret = fit_image_get_data(fit, noffset, data, size);
+       }
+
+       return ret;
+}
+
 /**
  * fit_image_hash_get_algo - get hash algorithm name
  * @fit: pointer to the FIT format image header
@@ -1236,7 +1286,7 @@ int fit_image_verify(const void *fit, int image_noffset)
        char            *err_msg = "";
 
        /* Get image data and data length */
-       if (fit_image_get_data(fit, image_noffset, &data, &size)) {
+       if (fit_image_get_data_and_size(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),
@@ -1723,6 +1773,8 @@ static const char *fit_get_image_type_property(int type)
                return FIT_LOADABLE_PROP;
        case IH_TYPE_FPGA:
                return FIT_FPGA_PROP;
+       case IH_TYPE_STANDALONE:
+               return FIT_STANDALONE_PROP;
        }
 
        return "unknown";
@@ -1786,24 +1838,26 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
                                        BOOTSTAGE_SUB_NO_UNIT_NAME);
                        return -ENOENT;
                }
+
                fit_base_uname_config = fdt_get_name(fit, cfg_noffset, NULL);
                printf("   Using '%s' configuration\n", fit_base_uname_config);
-               if (image_type == IH_TYPE_KERNEL) {
-                       /* Remember (and possibly verify) this config */
+               /* Remember this config */
+               if (image_type == IH_TYPE_KERNEL)
                        images->fit_uname_cfg = fit_base_uname_config;
-                       if (IMAGE_ENABLE_VERIFY && images->verify) {
-                               puts("   Verifying Hash Integrity ... ");
-                               if (fit_config_verify(fit, cfg_noffset)) {
-                                       puts("Bad Data Hash\n");
-                                       bootstage_error(bootstage_id +
-                                               BOOTSTAGE_SUB_HASH);
-                                       return -EACCES;
-                               }
-                               puts("OK\n");
+
+               if (IMAGE_ENABLE_VERIFY && images->verify) {
+                       puts("   Verifying Hash Integrity ... ");
+                       if (fit_config_verify(fit, cfg_noffset)) {
+                               puts("Bad Data Hash\n");
+                               bootstage_error(bootstage_id +
+                                       BOOTSTAGE_SUB_HASH);
+                               return -EACCES;
                        }
-                       bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
+                       puts("OK\n");
                }
 
+               bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
+
                noffset = fit_conf_get_prop_node(fit, cfg_noffset,
                                                 prop_name);
                fit_uname = fit_get_name(fit, noffset, NULL);
@@ -1872,7 +1926,7 @@ int fit_image_load(bootm_headers_t *images, ulong addr,
        bootstage_mark(bootstage_id + BOOTSTAGE_SUB_CHECK_ALL_OK);
 
        /* get image data address and length */
-       if (fit_image_get_data(fit, noffset, &buf, &size)) {
+       if (fit_image_get_data_and_size(fit, noffset, &buf, &size)) {
                printf("Could not find %s subimage data!\n", prop_name);
                bootstage_error(bootstage_id + BOOTSTAGE_SUB_GET_DATA);
                return -ENOENT;