spl: fit: verify images prior to post processing
authorBen Whitten <ben.whitten@gmail.com>
Thu, 7 Jun 2018 10:37:27 +0000 (11:37 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 10 Jul 2018 20:55:57 +0000 (16:55 -0400)
Verification of hashes needs to take place before any image post
processing, thus matching full FIT image processing.
This allows mechanisms such as encryption be applied to images
prior to fit generation at the spl level.

Signed-off-by: Ben Whitten <ben.whitten@lairdtech.com>
common/spl/spl_fit.c

index e01b4e578d94190e3324ce3c03d53f3cf43c6c6b..5b51a28a086c7f9308b912ba3a0263e621ddca6f 100644 (file)
@@ -181,9 +181,6 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
        uint8_t image_comp = -1, type = -1;
        const void *data;
        bool external_data = false;
-#ifdef CONFIG_SPL_FIT_SIGNATURE
-       int ret;
-#endif
 
        if (IS_ENABLED(CONFIG_SPL_FPGA_SUPPORT) ||
            (IS_ENABLED(CONFIG_SPL_OS_BOOT) && IS_ENABLED(CONFIG_SPL_GZIP))) {
@@ -247,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
@@ -272,16 +278,7 @@ static int spl_load_fit_image(struct spl_load_info *info, ulong sector,
                image_info->entry_point = fdt_getprop_u32(fit, node, "entry");
        }
 
-#ifdef CONFIG_SPL_FIT_SIGNATURE
-       printf("## Checking hash(es) for Image %s ...\n",
-              fit_get_name(fit, node, NULL));
-       ret = fit_image_verify_with_data(fit, node,
-                                        (const void *)load_addr, length);
-       printf("\n");
-       return !ret;
-#else
        return 0;
-#endif
 }
 
 static int spl_fit_append_fdt(struct spl_image_info *spl_image,