aboutsummaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorSean Anderson <seanga2@gmail.com>2023-10-14 16:47:44 -0400
committerTom Rini <trini@konsulko.com>2023-10-17 20:50:52 -0400
commitab12179b3e9fa8a9c54f9cd5ad6b2c0c185a2191 (patch)
tree64b342311be8492d3d26897ff35da06b3ebff3d8 /arch
parentd401e0b264a21e94a96074ce66c5f8df275cccbe (diff)
downloadu-boot-ab12179b3e9fa8a9c54f9cd5ad6b2c0c185a2191.zip
u-boot-ab12179b3e9fa8a9c54f9cd5ad6b2c0c185a2191.tar.gz
u-boot-ab12179b3e9fa8a9c54f9cd5ad6b2c0c185a2191.tar.bz2
arm: imx: Check header before calling spl_load_imx_container
Make sure we have an IMX header before calling spl_load_imx_container, since if we don't it will fail with -ENOENT. This allows us to fall back to legacy/raw images if they are also enabled. This is a functional change, one which likely should have been in place from the start, but a functional change nonetheless. Previously, all non-IMX8 images (except FITs without FIT_FULL) would be optimized out if the only image load method enabled supported IMX8 images. With this change, support for other image types now has an effect. There are seven boards with SPL_LOAD_IMX_CONTAINER enabled: three with SPL_BOOTROM_SUPPORT: imx93_11x11_evk_ld imx93_11x11_evk imx8ulp_evk and four with SPL_MMC: deneb imx8qxp_mek giedi imx8qm_mek All of these boards also have SPL_RAW_IMAGE_SUPPORT and SPL_LEGACY_IMAGE_FORMAT enabled as well. However, none have FIT support enabled. Of the six load methods affected by this patch, only SPL_MMC and SPL_BOOTROM_SUPPORT are enabled with SPL_LOAD_IMX_CONTAINER. spl_romapi_load_image_seekable does not support legacy or raw images, so there is no growth. However, mmc_load_image_raw_sector does support loading legacy/raw images. Since these images could not have been booted before, I have disabled support for legacy/raw images on these four boards. This reduces bloat from around 800 bytes to around 200. There are no in-tree boards with SPL_LOAD_IMX_CONTAINER and AHAB_BOOT both enabled, so we do not need to worry about potentially falling back to legacy images in a secure boot scenario. Future work could include merging imx_container.h with imx8image.h, since they appear to define mostly the same structures. Signed-off-by: Sean Anderson <seanga2@gmail.com>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/include/asm/mach-imx/ahab.h2
-rw-r--r--arch/arm/include/asm/mach-imx/image.h78
-rw-r--r--arch/arm/mach-imx/cmd_dek.c4
-rw-r--r--arch/arm/mach-imx/ele_ahab.c2
-rw-r--r--arch/arm/mach-imx/image-container.c2
-rw-r--r--arch/arm/mach-imx/imx8/ahab.c2
-rw-r--r--arch/arm/mach-imx/parse-container.c2
-rw-r--r--arch/arm/mach-imx/spl_imx_romapi.c5
8 files changed, 10 insertions, 87 deletions
diff --git a/arch/arm/include/asm/mach-imx/ahab.h b/arch/arm/include/asm/mach-imx/ahab.h
index 4222e3d..4884f05 100644
--- a/arch/arm/include/asm/mach-imx/ahab.h
+++ b/arch/arm/include/asm/mach-imx/ahab.h
@@ -6,7 +6,7 @@
#ifndef __IMX_AHAB_H__
#define __IMX_AHAB_H__
-#include <asm/mach-imx/image.h>
+#include <imx_container.h>
int ahab_auth_cntr_hdr(struct container_hdr *container, u16 length);
int ahab_auth_release(void);
diff --git a/arch/arm/include/asm/mach-imx/image.h b/arch/arm/include/asm/mach-imx/image.h
deleted file mode 100644
index 54cd684..0000000
--- a/arch/arm/include/asm/mach-imx/image.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * Copyright 2018-2019 NXP
- */
-
-#ifndef __CONTAINER_HEADER_H_
-#define __CONTAINER_HEADER_H_
-
-#include <linux/sizes.h>
-#include <linux/types.h>
-
-#define IV_MAX_LEN 32
-#define HASH_MAX_LEN 64
-
-#define CONTAINER_HDR_ALIGNMENT 0x400
-#define CONTAINER_HDR_EMMC_OFFSET 0
-#define CONTAINER_HDR_MMCSD_OFFSET SZ_32K
-#define CONTAINER_HDR_QSPI_OFFSET SZ_4K
-#define CONTAINER_HDR_NAND_OFFSET SZ_128M
-
-#define CONTAINER_HDR_TAG 0x87
-#define CONTAINER_HDR_VERSION 0
-
-struct container_hdr {
- u8 version;
- u8 length_lsb;
- u8 length_msb;
- u8 tag;
- u32 flags;
- u16 sw_version;
- u8 fuse_version;
- u8 num_images;
- u16 sig_blk_offset;
- u16 reserved;
-} __packed;
-
-struct boot_img_t {
- u32 offset;
- u32 size;
- u64 dst;
- u64 entry;
- u32 hab_flags;
- u32 meta;
- u8 hash[HASH_MAX_LEN];
- u8 iv[IV_MAX_LEN];
-} __packed;
-
-struct signature_block_hdr {
- u8 version;
- u8 length_lsb;
- u8 length_msb;
- u8 tag;
- u16 srk_table_offset;
- u16 cert_offset;
- u16 blob_offset;
- u16 signature_offset;
- u32 reserved;
-} __packed;
-
-struct generate_key_blob_hdr {
- u8 version;
- u8 length_lsb;
- u8 length_msb;
- u8 tag;
- u8 flags;
- u8 size;
- u8 algorithm;
- u8 mode;
-} __packed;
-
-int get_container_size(ulong addr, u16 *header_length);
-
-static inline bool valid_container_hdr(struct container_hdr *container)
-{
- return container->tag == CONTAINER_HDR_TAG &&
- container->version == CONTAINER_HDR_VERSION;
-}
-#endif
diff --git a/arch/arm/mach-imx/cmd_dek.c b/arch/arm/mach-imx/cmd_dek.c
index 6fa5b41..2f389db 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 6a1ad19..295c055 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>
diff --git a/arch/arm/mach-imx/image-container.c b/arch/arm/mach-imx/image-container.c
index eff9e0c..ebc8021 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>
diff --git a/arch/arm/mach-imx/imx8/ahab.c b/arch/arm/mach-imx/imx8/ahab.c
index 44ea635..994becc 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"
diff --git a/arch/arm/mach-imx/parse-container.c b/arch/arm/mach-imx/parse-container.c
index d57f25d..c29cb15 100644
--- a/arch/arm/mach-imx/parse-container.c
+++ b/arch/arm/mach-imx/parse-container.c
@@ -7,9 +7,9 @@
#include <common.h>
#include <stdlib.h>
#include <errno.h>
+#include <imx_container.h>
#include <log.h>
#include <spl.h>
-#include <asm/mach-imx/image.h>
#ifdef CONFIG_AHAB_BOOT
#include <asm/mach-imx/ahab.h>
#endif
diff --git a/arch/arm/mach-imx/spl_imx_romapi.c b/arch/arm/mach-imx/spl_imx_romapi.c
index 80909ae..93d48e5 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));