
Detect the image type before going the route to boot OS. Last kernel image sets the entry point.
Signed-off-by: York Sun york.sun@nxp.com
---
Kconfig | 7 +++++ common/spl/spl_fit.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ include/image.h | 4 +++ 3 files changed, 83 insertions(+)
diff --git a/Kconfig b/Kconfig index 1cf990d..e850941 100644 --- a/Kconfig +++ b/Kconfig @@ -239,6 +239,13 @@ config SPL_FIT_IMAGE_POST_PROCESS injected into the FIT creation (i.e. the blobs would have been pre- processed before being added to the FIT image).
+config SPL_FIT_IMAGE_SECURE_VALIDATE + bool "Enable validation of FIT image after loaded by SPL" + depends on SPL_LOAD_FIT && SPL_OS_BOOT && CHAIN_OF_TRUST + help + Enable secure boot validation on OS FIT image before extracting + individual images. + endif # FIT
config OF_BOARD_SETUP diff --git a/common/spl/spl_fit.c b/common/spl/spl_fit.c index aae556f..cf23628 100644 --- a/common/spl/spl_fit.c +++ b/common/spl/spl_fit.c @@ -123,6 +123,9 @@ static int get_aligned_image_size(struct spl_load_info *info, int data_size, return (data_size + info->bl_len - 1) / info->bl_len; }
+#ifndef CONFIG_SYS_BOOTM_LEN +#define CONFIG_SYS_BOOTM_LEN 0x800000 +#endif int spl_load_simple_fit(struct spl_image_info *spl_image, struct spl_load_info *info, ulong sector, void *fit) { @@ -136,6 +139,12 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, int base_offset, align_len = ARCH_DMA_MINALIGN - 1; int src_sector; void *dst, *src; +#ifdef CONFIG_SPL_FIT + const void *data; + size_t d_size; + int len; + uint8_t type, image_comp; +#endif
/* * Figure out where the external images start. This is the base for the @@ -180,7 +189,19 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, return -1; }
+#ifdef CONFIG_SPL_FIT + data = fdt_getprop(fit, node, "type", &len); + if (data == NULL) { + printf("Cannot get image type\n"); + return -1; + } + type = genimg_get_type_id(data); + if (type == IH_TYPE_KERNEL) + goto boot_kernel; +#endif + /* Get its information and set up the spl_image structure */ + data_offset = fdt_getprop_u32(fit, node, "data-offset"); data_size = fdt_getprop_u32(fit, node, "data-size"); load = fdt_getprop_u32(fit, node, "load"); @@ -254,4 +275,55 @@ int spl_load_simple_fit(struct spl_image_info *spl_image, memcpy(dst, src, fdt_len);
return 0; + +#ifdef CONFIG_SPL_FIT +boot_kernel: +#ifdef CONFIG_SPL_FIT_IMAGE_SECURE_VALIDATE + board_fit_image_secure_validate(fit); +#endif + for (; node >= 0; node = fdt_next_subnode(fit, node)) { + data = fdt_getprop(fit, node, "os", &len); + if (data == NULL) + spl_image->os = -1; + else + spl_image->os = genimg_get_os_id(data); + + data = fdt_getprop(fit, node, "type", &len); + if (data == NULL) { + printf("Cannot get image type\n"); + return -1; + } + load = fdt_getprop_u32(fit, node, "load"); + type = genimg_get_type_id(data); + if (type == IH_TYPE_KERNEL) { + spl_image->load_addr = load; + spl_image->entry_point = load; + } + dst = (void *)load; + if (fit_image_get_data(fit, node, &data, &d_size)) { + printf("Cannot get image data/size\n"); + return -1; + } + if (fit_image_get_comp(fit, node, &image_comp)) + printf("Cannot get image compression format.\n"); + + debug("%s size %lx, data %p, %s\n", + genimg_get_type_name(type), + (ulong)d_size, dst, + genimg_get_comp_name(image_comp)); + if (image_comp == IH_COMP_GZIP && type == IH_TYPE_KERNEL) { +#ifdef CONFIG_SPL_GZIP + if (gunzip(dst, CONFIG_SYS_BOOTM_LEN, (void *)data, &d_size)) + puts("Uncompressing error\n"); +#else + puts("GZIP is not enabled\n"); + return -EINVAL; +#endif + } else { + memcpy(dst, data, d_size); + } + } + + return 0; +#endif } diff --git a/include/image.h b/include/image.h index 3f26f9b..10f5544 100644 --- a/include/image.h +++ b/include/image.h @@ -1274,6 +1274,10 @@ int board_fit_config_name_match(const char *name); void board_fit_image_post_process(void **p_image, size_t *p_size); #endif /* CONFIG_SPL_FIT_IMAGE_POST_PROCESS */
+#ifdef CONFIG_SPL_FIT_IMAGE_SECURE_VALIDATE +void board_fit_image_secure_validate(void *fit); +#endif + /** * Mapping of image types to function handlers to be invoked on the associated * loaded images