]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
arm: imx: Check header before calling spl_load_imx_container
authorSean Anderson <seanga2@gmail.com>
Sat, 14 Oct 2023 20:47:44 +0000 (16:47 -0400)
committerTom Rini <trini@konsulko.com>
Wed, 18 Oct 2023 00:50:52 +0000 (20:50 -0400)
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>
18 files changed:
MAINTAINERS
arch/arm/include/asm/mach-imx/ahab.h
arch/arm/mach-imx/cmd_dek.c
arch/arm/mach-imx/ele_ahab.c
arch/arm/mach-imx/image-container.c
arch/arm/mach-imx/imx8/ahab.c
arch/arm/mach-imx/parse-container.c
arch/arm/mach-imx/spl_imx_romapi.c
common/spl/spl_mmc.c
common/spl/spl_nand.c
common/spl/spl_nor.c
common/spl/spl_spi.c
configs/deneb_defconfig
configs/giedi_defconfig
configs/imx8qm_mek_defconfig
configs/imx8qxp_mek_defconfig
drivers/usb/gadget/f_sdp.c
include/imx_container.h [moved from arch/arm/include/asm/mach-imx/image.h with 100% similarity]

index 16b17fdd96d1065d6241a1f8418c522700b122d6..67f0fe8c8cf82b32aa3b49c3c9a0f9807d3540b8 100644 (file)
@@ -301,6 +301,7 @@ F:  arch/arm/include/asm/mach-imx/
 F:     board/freescale/*mx*/
 F:     board/freescale/common/
 F:     drivers/serial/serial_mxc.c
+F:     include/imx_container.h
 
 ARM HISILICON
 M:     Peter Griffin <peter.griffin@linaro.org>
index 4222e3db27804288b80178123286e1d76f4f6819..4884f056251025988f14350cda108c4e92a12cdf 100644 (file)
@@ -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);
index 6fa5b41fcd382424fc966a0a02f76749789a3dda..2f389dbe8df0a02ff2addfebad255388c5b1f699 100644 (file)
 #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>
index 6a1ad198f89c1fa2dab4ab4b9aeeaaa74e4c55ee..295c055ad0a9301ec36d4f5096b0627a6fdf0848 100644 (file)
@@ -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>
index eff9e0c4597a51a9b06a58afaa49acf6aeb61606..ebc8021d7cce2e1bea79f1526ee4a5c5efce8db8 100644 (file)
@@ -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>
 
index 44ea63584aa650dc98120d25c90a5fea6e4459e2..994becccefded7fddf3f02c5fc5e91fcb9cbb490 100644 (file)
@@ -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"
index d57f25df6dc5766fe8eca93f4969d435f70125eb..c29cb15f55e3adff0cded027426cb19e15126e0e 100644 (file)
@@ -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
index 80909aec3ea7d753ecc31ca4882ced668cd95b64..93d48e56aca4e3736b3ae7e077b4eae197ca61c8 100644 (file)
@@ -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));
index 02ad32a23e018d9db935848a9dc9ab67f45a537c..67c7ae34a58550b41b7d0b1918f112b15a5e66e5 100644 (file)
@@ -16,6 +16,7 @@
 #include <errno.h>
 #include <mmc.h>
 #include <image.h>
+#include <imx_container.h>
 
 static int mmc_load_legacy(struct spl_image_info *spl_image,
                           struct spl_boot_device *bootdev,
@@ -108,7 +109,8 @@ int mmc_load_image_raw_sector(struct spl_image_info *spl_image,
                load.bl_len = mmc->read_bl_len;
                load.read = h_spl_load_read;
                ret = spl_load_simple_fit(spl_image, &load, sector, 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;
 
                load.dev = mmc;
index 6cc34004f49d918ce336a6cdf574f6153fcdb717..07916bedbb91c607b780c4245a5268f970c50f51 100644 (file)
@@ -7,6 +7,7 @@
 #include <config.h>
 #include <fdt_support.h>
 #include <image.h>
+#include <imx_container.h>
 #include <log.h>
 #include <spl.h>
 #include <asm/io.h>
@@ -99,7 +100,8 @@ static int spl_nand_load_element(struct spl_image_info *spl_image,
                load.bl_len = bl_len;
                load.read = spl_nand_fit_read;
                return spl_load_simple_fit(spl_image, &load, offset / bl_len, 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;
 
                load.dev = NULL;
index c141a9ae62947751d3348026ca84bc87a84fda4c..dd44798207185c750d2ca67b8c650d8226faa123 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <image.h>
+#include <imx_container.h>
 #include <log.h>
 #include <spl.h>
 
@@ -102,7 +103,8 @@ static int spl_nor_load_image(struct spl_image_info *spl_image,
                                           (void *)header);
        }
 #endif
-       if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+       if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+           valid_container_hdr((void *)header)) {
                load.bl_len = 1;
                load.read = spl_nor_load_read;
                return spl_load_imx_container(spl_image, &load,
index d69069a75bfebe3d656299cb3cbb728edc1ab1f8..1427c9478c0ec0dd32fa6c3d833936b50f3198ed 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <common.h>
 #include <image.h>
+#include <imx_container.h>
 #include <log.h>
 #include <spi.h>
 #include <spi_flash.h>
@@ -153,7 +154,8 @@ static int spl_spi_load_image(struct spl_image_info *spl_image,
                        err = spl_load_simple_fit(spl_image, &load,
                                                  payload_offs,
                                                  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;
 
                        load.dev = flash;
index 82869e4e0f9fa0e0b41bc2fe59d47a210ce25565..ee2478aa0bb39242ca15eaf2b22c0b3d0f163f4e 100644 (file)
@@ -44,6 +44,8 @@ CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
 CONFIG_SPL_BSS_START_ADDR=0x128000
 CONFIG_SPL_BSS_MAX_SIZE=0x1000
 CONFIG_SPL_BOARD_INIT=y
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+# CONFIG_SPL_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
 CONFIG_SPL_SYS_MALLOC=y
index b56b736c4365358cf818f3560af0964eac07f323..5e403c90c8c2b7ac225de9db1f14f1012b460f55 100644 (file)
@@ -44,6 +44,8 @@ CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
 CONFIG_SPL_BSS_START_ADDR=0x128000
 CONFIG_SPL_BSS_MAX_SIZE=0x1000
 CONFIG_SPL_BOARD_INIT=y
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+# CONFIG_SPL_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
 CONFIG_SPL_SYS_MALLOC=y
index b9083b0453fa38b7df6f699c648b0143a9e1613f..4c5206306eea26fe9bab60bdb3de3308e42d7183 100644 (file)
@@ -38,6 +38,8 @@ CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
 CONFIG_SPL_BSS_START_ADDR=0x128000
 CONFIG_SPL_BSS_MAX_SIZE=0x1000
 CONFIG_SPL_BOARD_INIT=y
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+# CONFIG_SPL_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
 CONFIG_SPL_SYS_MALLOC=y
index f516b0b55571249e14b8b36bf96e5e0c6052d1d2..f312d3945fb86f1e6459b588f9f44e5e19496af3 100644 (file)
@@ -38,6 +38,8 @@ CONFIG_SPL_HAS_BSS_LINKER_SECTION=y
 CONFIG_SPL_BSS_START_ADDR=0x128000
 CONFIG_SPL_BSS_MAX_SIZE=0x1000
 CONFIG_SPL_BOARD_INIT=y
+# CONFIG_SPL_RAW_IMAGE_SUPPORT is not set
+# CONFIG_SPL_LEGACY_IMAGE_FORMAT is not set
 CONFIG_SPL_SYS_MALLOC_SIMPLE=y
 # CONFIG_SPL_SHARES_INIT_SP_ADDR is not set
 CONFIG_SPL_SYS_MALLOC=y
index 2b3a9c5fd4cdd0eeb7b60b6062cf9d6c11f31181..ee9384fb37ea1a8c6c1ac1ee677e0a7e3ac6ba9a 100644 (file)
@@ -34,6 +34,7 @@
 #include <spl.h>
 #include <image.h>
 #include <imximage.h>
+#include <imx_container.h>
 #include <watchdog.h>
 
 #define HID_REPORT_ID_MASK     0x000000ff
@@ -852,7 +853,8 @@ static int sdp_handle_in_ep(struct spl_image_info *spl_image,
                                return SDP_EXIT;
                        }
 #endif
-                       if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER)) {
+                       if (IS_ENABLED(CONFIG_SPL_LOAD_IMX_CONTAINER) &&
+                           valid_container_hdr((void *)header)) {
                                struct spl_load_info load;
 
                                load.dev = header;