diff options
Diffstat (limited to 'arch/arm/mach-imx')
-rw-r--r-- | arch/arm/mach-imx/Kconfig | 13 | ||||
-rw-r--r-- | arch/arm/mach-imx/Makefile | 2 | ||||
-rw-r--r-- | arch/arm/mach-imx/cmd_dek.c | 4 | ||||
-rw-r--r-- | arch/arm/mach-imx/ele_ahab.c | 4 | ||||
-rw-r--r-- | arch/arm/mach-imx/image-container.c | 4 | ||||
-rw-r--r-- | arch/arm/mach-imx/imx8/ahab.c | 4 | ||||
-rw-r--r-- | arch/arm/mach-imx/parse-container.c | 157 | ||||
-rw-r--r-- | arch/arm/mach-imx/spl_imx_romapi.c | 8 |
8 files changed, 14 insertions, 182 deletions
diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index 44e1e1628b..abd48d4258 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -194,19 +194,6 @@ config IMX_DCD_ADDR This information is shared with the user via mkimage -l just so the image can be signed. -config SPL_LOAD_IMX_CONTAINER - bool "Enable SPL loading U-Boot as a i.MX Container image" - depends on SPL - help - This is to let SPL could load i.MX Container image - -config IMX_CONTAINER_CFG - string "i.MX Container config file" - depends on SPL - help - This is to specific the cfg file for generating container - image which will be loaded by SPL. - config IOMUX_LPSR bool diff --git a/arch/arm/mach-imx/Makefile b/arch/arm/mach-imx/Makefile index 6904cf3880..a3b44c93e3 100644 --- a/arch/arm/mach-imx/Makefile +++ b/arch/arm/mach-imx/Makefile @@ -79,7 +79,7 @@ obj-$(CONFIG_CMD_NANDBCB) += cmd_nandbcb.o endif ifeq ($(CONFIG_SPL_BUILD),y) -obj-$(CONFIG_SPL_LOAD_IMX_CONTAINER) += image-container.o parse-container.o +obj-$(CONFIG_SPL_LOAD_IMX_CONTAINER) += image-container.o endif ifeq ($(SOC),$(filter $(SOC),imx8ulp imx9)) diff --git a/arch/arm/mach-imx/cmd_dek.c b/arch/arm/mach-imx/cmd_dek.c index 6fa5b41fcd..2f389dbe8d 100644 --- a/arch/arm/mach-imx/cmd_dek.c +++ b/arch/arm/mach-imx/cmd_dek.c @@ -18,12 +18,12 @@ #include <mapmem.h> #include <tee.h> #ifdef CONFIG_IMX_SECO_DEK_ENCAP +#include <imx_container.h> #include <firmware/imx/sci/sci.h> -#include <asm/mach-imx/image.h> #endif #ifdef CONFIG_IMX_ELE_DEK_ENCAP +#include <imx_container.h> #include <asm/mach-imx/ele_api.h> -#include <asm/mach-imx/image.h> #endif #include <cpu_func.h> diff --git a/arch/arm/mach-imx/ele_ahab.c b/arch/arm/mach-imx/ele_ahab.c index 785b0d6ec3..295c055ad0 100644 --- a/arch/arm/mach-imx/ele_ahab.c +++ b/arch/arm/mach-imx/ele_ahab.c @@ -6,12 +6,12 @@ #include <common.h> #include <command.h> #include <errno.h> +#include <imx_container.h> #include <asm/io.h> #include <asm/mach-imx/ele_api.h> #include <asm/mach-imx/sys_proto.h> #include <asm/arch-imx/cpu.h> #include <asm/arch/sys_proto.h> -#include <asm/mach-imx/image.h> #include <console.h> #include <cpu_func.h> #include <asm/global_data.h> @@ -343,7 +343,7 @@ int authenticate_os_container(ulong addr) } phdr = (struct container_hdr *)addr; - if (phdr->tag != 0x87 || phdr->version != 0x0) { + if (!valid_container_hdr(phdr)) { printf("Error: Wrong container header\n"); return -EFAULT; } diff --git a/arch/arm/mach-imx/image-container.c b/arch/arm/mach-imx/image-container.c index 0285bbdaf2..c9455fe222 100644 --- a/arch/arm/mach-imx/image-container.c +++ b/arch/arm/mach-imx/image-container.c @@ -5,6 +5,7 @@ #include <common.h> #include <errno.h> +#include <imx_container.h> #include <log.h> #include <malloc.h> #include <asm/io.h> @@ -12,7 +13,6 @@ #include <spi_flash.h> #include <spl.h> #include <nand.h> -#include <asm/mach-imx/image.h> #include <asm/arch/sys_proto.h> #include <asm/mach-imx/boot_mode.h> @@ -50,7 +50,7 @@ int get_container_size(ulong addr, u16 *header_length) u32 max_offset = 0, img_end; phdr = (struct container_hdr *)addr; - if (phdr->tag != 0x87 || phdr->version != 0x0) { + if (!valid_container_hdr(phdr)) { debug("Wrong container header\n"); return -EFAULT; } diff --git a/arch/arm/mach-imx/imx8/ahab.c b/arch/arm/mach-imx/imx8/ahab.c index b58b14ca9b..994becccef 100644 --- a/arch/arm/mach-imx/imx8/ahab.c +++ b/arch/arm/mach-imx/imx8/ahab.c @@ -6,6 +6,7 @@ #include <common.h> #include <command.h> #include <errno.h> +#include <imx_container.h> #include <log.h> #include <asm/global_data.h> #include <asm/io.h> @@ -13,7 +14,6 @@ #include <asm/mach-imx/sys_proto.h> #include <asm/arch-imx/cpu.h> #include <asm/arch/sys_proto.h> -#include <asm/mach-imx/image.h> #include <console.h> #include <cpu_func.h> #include "u-boot/sha256.h" @@ -146,7 +146,7 @@ int authenticate_os_container(ulong addr) } phdr = (struct container_hdr *)addr; - if (phdr->tag != 0x87 && phdr->version != 0x0) { + if (!valid_container_hdr(phdr)) { printf("Error: Wrong container header\n"); return -EFAULT; } diff --git a/arch/arm/mach-imx/parse-container.c b/arch/arm/mach-imx/parse-container.c deleted file mode 100644 index e2a9e2b273..0000000000 --- a/arch/arm/mach-imx/parse-container.c +++ /dev/null @@ -1,157 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright 2018-2021 NXP - */ - -#include <common.h> -#include <stdlib.h> -#include <errno.h> -#include <log.h> -#include <spl.h> -#include <asm/mach-imx/image.h> -#ifdef CONFIG_AHAB_BOOT -#include <asm/mach-imx/ahab.h> -#endif - -static struct boot_img_t *read_auth_image(struct spl_image_info *spl_image, - struct spl_load_info *info, - struct container_hdr *container, - int image_index, - u32 container_sector) -{ - struct boot_img_t *images; - ulong sector; - u32 sectors; - - if (image_index > container->num_images) { - debug("Invalid image number\n"); - return NULL; - } - - images = (struct boot_img_t *)((u8 *)container + - sizeof(struct container_hdr)); - - if (images[image_index].offset % info->bl_len) { - printf("%s: image%d offset not aligned to %u\n", - __func__, image_index, info->bl_len); - return NULL; - } - - sectors = roundup(images[image_index].size, info->bl_len) / - info->bl_len; - sector = images[image_index].offset / info->bl_len + - container_sector; - - debug("%s: container: %p sector: %lu sectors: %u\n", __func__, - container, sector, sectors); - if (info->read(info, sector, sectors, - (void *)images[image_index].entry) != sectors) { - printf("%s wrong\n", __func__); - return NULL; - } - -#ifdef CONFIG_AHAB_BOOT - if (ahab_verify_cntr_image(&images[image_index], image_index)) - return NULL; -#endif - - return &images[image_index]; -} - -static int read_auth_container(struct spl_image_info *spl_image, - struct spl_load_info *info, ulong sector) -{ - struct container_hdr *container = NULL; - u16 length; - u32 sectors; - int i, size, ret = 0; - - size = roundup(CONTAINER_HDR_ALIGNMENT, info->bl_len); - sectors = size / info->bl_len; - - /* - * It will not override the ATF code, so safe to use it here, - * no need malloc - */ - container = malloc(size); - if (!container) - return -ENOMEM; - - debug("%s: container: %p sector: %lu sectors: %u\n", __func__, - container, sector, sectors); - if (info->read(info, sector, sectors, container) != sectors) { - ret = -EIO; - goto end; - } - - if (container->tag != 0x87 && container->version != 0x0) { - printf("Wrong container header"); - ret = -ENOENT; - goto end; - } - - if (!container->num_images) { - printf("Wrong container, no image found"); - ret = -ENOENT; - goto end; - } - - length = container->length_lsb + (container->length_msb << 8); - debug("Container length %u\n", length); - - if (length > CONTAINER_HDR_ALIGNMENT) { - size = roundup(length, info->bl_len); - sectors = size / info->bl_len; - - free(container); - container = malloc(size); - if (!container) - return -ENOMEM; - - debug("%s: container: %p sector: %lu sectors: %u\n", - __func__, container, sector, sectors); - if (info->read(info, sector, sectors, container) != - sectors) { - ret = -EIO; - goto end; - } - } - -#ifdef CONFIG_AHAB_BOOT - ret = ahab_auth_cntr_hdr(container, length); - if (ret) - goto end_auth; -#endif - - for (i = 0; i < container->num_images; i++) { - struct boot_img_t *image = read_auth_image(spl_image, info, - container, i, - sector); - - if (!image) { - ret = -EINVAL; - goto end_auth; - } - - if (i == 0) { - spl_image->load_addr = image->dst; - spl_image->entry_point = image->entry; - } - } - -end_auth: -#ifdef CONFIG_AHAB_BOOT - ahab_auth_release(); -#endif - -end: - free(container); - - return ret; -} - -int spl_load_imx_container(struct spl_image_info *spl_image, - struct spl_load_info *info, ulong sector) -{ - return read_auth_container(spl_image, info, sector); -} diff --git a/arch/arm/mach-imx/spl_imx_romapi.c b/arch/arm/mach-imx/spl_imx_romapi.c index c4a4185eed..93d48e56ac 100644 --- a/arch/arm/mach-imx/spl_imx_romapi.c +++ b/arch/arm/mach-imx/spl_imx_romapi.c @@ -6,11 +6,11 @@ #include <common.h> #include <errno.h> #include <image.h> +#include <imx_container.h> #include <log.h> #include <asm/global_data.h> #include <linux/libfdt.h> #include <spl.h> -#include <asm/mach-imx/image.h> #include <asm/arch/sys_proto.h> DECLARE_GLOBAL_DATA_PTR; @@ -111,7 +111,8 @@ static int spl_romapi_load_image_seekable(struct spl_image_info *spl_image, load.read = spl_romapi_read_seekable; load.priv = &pagesize; return spl_load_simple_fit(spl_image, &load, offset / pagesize, header); - } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) { + } else if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) && + valid_container_hdr((void *)header)) { struct spl_load_info load; memset(&load, 0, sizeof(load)); @@ -202,7 +203,8 @@ static u8 *search_container_header(u8 *p, int size) for (i = 0; i < size; i += 4) { hdr = p + i; - if (*(hdr + 3) == 0x87 && *hdr == 0 && (*(hdr + 1) != 0 || *(hdr + 2) != 0)) + if (valid_container_hdr((void *)hdr) && + (*(hdr + 1) != 0 || *(hdr + 2) != 0)) return p + i; } |