add i.MX8 container loading support
Subsystems (4)
v4 cover add i.MX8 container loading support
V4:
Added a new patch for documentation, nothing else changed.
CI: https://travis-ci.org/MrVan/u-boot/builds/575206934
V3:
Drops patch 1/5 from V2, add 8QM support, nothing else changed.
V2:
Drop cleanup Makefile since V1, that patch is not correct. Rebased on master
The V2 version:
https://patchwork.ozlabs.org/cover/1118413/
The V1 version:
https://patchwork.ozlabs.org/cover/1096334/
This patchset is to support i.MX8 container loading from SPL, i.MX8 AHAB secure boot not support FIT image, so we need to use container image.
Currently still use a fixed offset for the 2nd container(u-boot.cnt), future patches will drop this fixed offset and use dynamaic offset according to the size of 1st container for spl.
Only MMC is supported now, future patches will also support SPI/NOR/NAND following similar style as mmc part, if the mmc part is ok.
Based on the comments in https://patchwork.ozlabs.org/patch/1096336/
So I think we have agreed the approach, the only comments that not addressed from Lukasz is add doc for the container format. The detailed format could be found in RM
https://www.nxp.com/docs/en/reference-manual/IMX8DQXPRM.pdf
Chapter 5.9.4 High Level Container Format
Peng Fan (6):
imx8: support parsing i.MX8 Container file
spl: mmc: support loading i.MX container format file
imx: add container target
imx8qxp_mek: switch to use container image
imx8qm_mek: switch to use container image
doc: imx: mkimage: introduce i.MX8 image format
Makefile | 8 ++ arch/arm/include/asm/arch-imx8/image.h | 56 +++++++++++ arch/arm/mach-imx/Makefile | 14 ++- arch/arm/mach-imx/imx8/Kconfig | 13 +++ arch/arm/mach-imx/imx8/Makefile | 4 + arch/arm/mach-imx/imx8/parse-container.c | 120 ++++++++++++++++++++++++ board/freescale/imx8qm_mek/README | 4 +- board/freescale/imx8qm_mek/uboot-container.cfg | 13 +++ board/freescale/imx8qxp_mek/README | 4 +- board/freescale/imx8qxp_mek/uboot-container.cfg | 13 +++ common/spl/spl_mmc.c | 10 ++ configs/imx8qm_mek_defconfig | 8 +- configs/imx8qxp_mek_defconfig | 5 +- doc/imx/mkimage/imx8image.txt | 45 +++++++++ include/spl.h | 12 +++ 15 files changed, 315 insertions(+), 14 deletions(-) create mode 100644 arch/arm/include/asm/arch-imx8/image.h create mode 100644 arch/arm/mach-imx/imx8/parse-container.c create mode 100644 board/freescale/imx8qm_mek/uboot-container.cfg create mode 100644 board/freescale/imx8qxp_mek/uboot-container.cfg create mode 100644 doc/imx/mkimage/imx8image.txt
Signature · 1 line
2.16.4
PATCH v4 1/6 imx8: support parsing i.MX8 Container file
Add parsing i.MX8 Container file support, this is to let SPL could load images in a container file to destination address.
--- arch/arm/include/asm/arch-imx8/image.h | 56 +++++++++++++++ arch/arm/mach-imx/imx8/Kconfig | 6 ++ arch/arm/mach-imx/imx8/Makefile | 4 ++ arch/arm/mach-imx/imx8/parse-container.c | 120 +++++++++++++++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 arch/arm/include/asm/arch-imx8/image.h create mode 100644 arch/arm/mach-imx/imx8/parse-container.c
arch/arm/include/asm/arch-imx8/image.h new file +56 -0
@@ -0,0 +1,56 @@ +/* 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 + +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; +#endif
arch/arm/mach-imx/imx8/Kconfig +6 -0
@@ -23,6 +23,12 @@ config IMX8QXP config SYS_SOC default "imx8" +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.MX8 Container image + choice prompt "i.MX8 board select" optional
arch/arm/mach-imx/imx8/Makefile +4 -0
@@ -5,3 +5,7 @@ # obj-y += cpu.o iomux.o misc.o + +ifdef CONFIG_SPL_BUILD +obj-$(CONFIG_SPL_LOAD_IMX_CONTAINER) += parse-container.o +endif
arch/arm/mach-imx/imx8/parse-container.c new file +120 -0
120 lines not on this page · raw message
Signature · 1 line
2.16.4
PATCH v4 2/6 spl: mmc: support loading i.MX container format file
In reply to Peng Fani.MX8 only support AHAB secure boot with Container format image, we could not use FIT to support secure boot, so introduce container support to let SPL could load container images.
--- common/spl/spl_mmc.c | 10 ++++++++++ include/spl.h | 12 ++++++++++++ 2 files changed, 22 insertions(+)
common/spl/spl_mmc.c +10 -0
@@ -79,6 +79,16 @@ 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 )) { +struct spl_load_info load; + + load.dev = mmc; + load.priv =NULL ; + load.filename =NULL ; + load.bl_len = mmc->read_bl_len; + load.read = h_spl_load_read; + + ret =spl_load_imx_container (spl_image, &load, sector); }else { ret =mmc_load_legacy (spl_image, mmc, sector, header); }
include/spl.h +12 -0
@@ -134,6 +134,18 @@ int spl_load_simple_fit(struct spl_image_info *spl_image,#define SPL_COPY_PAYLOAD_ONLY 1#define SPL_FIT_FOUND 2 +/** +* spl_load_imx_container() - Loads a imx container image from a device. +* @spl_image: Image description to set up +* @info: Structure containing the information required to load data. +* @sector: Sector number where container image is located in the device +* +* Reads the container image @sector in the device. Loads u-boot image to +* specified load address. +*/ +int spl_load_imx_container (struct spl_image_info *spl_image, +struct spl_load_info *info,ulong sector); +/* SPL common functions */ void preloader_console_init (void );u32 spl_boot_device (void );
Signature · 1 line
2.16.4
PATCH v4 3/6 imx: add container target
In reply to Peng FanTo support SPL loading container file, add a new Makefile target, and introduce a new Kconfig file to source the cfg file which will be parsed by mkimage.
--- Makefile | 8 ++++++++ arch/arm/mach-imx/Makefile | 14 ++++++++++++-- arch/arm/mach-imx/imx8/Kconfig | 7 +++++++ 3 files changed, 27 insertions(+), 2 deletions(-)
Makefile +8 -0
@@ -1324,9 +1324,17 @@ SPL: spl/u-boot-spl.bin FORCE $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@ ifeq ($(CONFIG_ARCH_IMX8M)$(CONFIG_ARCH_IMX8), y) +ifeq ($(CONFIG_SPL_LOAD_IMX_CONTAINER), y) +u-boot.cnt: u-boot.bin FORCE + $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@ + +flash.bin: spl/u-boot-spl.bin u-boot.cnt FORCE + $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@ +else flash.bin: spl/u-boot-spl.bin u-boot.itb FORCE $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@ endif +endif u-boot-with-spl.imx u-boot-with-nand-spl.imx: SPL u-boot.bin FORCE $(Q)$(MAKE) $(build)=arch/arm/mach-imx $@
arch/arm/mach-imx/Makefile +12 -2
@@ -90,6 +90,11 @@ IMX_CONFIG = $(CONFIG_IMX_CONFIG:"%"=%) $(Q)mkdir -p $(dir $@) $(call if_changed_dep,cpp_cfg) +IMX_CONTAINER_CFG = $(CONFIG_IMX_CONTAINER_CFG:"%"=%) +container.cfg: $(IMX_CONTAINER_CFG) FORCE + $(Q)mkdir -p $(dir $@) + $(call if_changed_dep,cpp_cfg) + ifeq ($(CONFIG_ARCH_IMX8), y) CNTR_DEPFILES := $(srctree)/tools/imx_cntr_image.sh IMAGE_TYPE := imx8image
@@ -158,10 +163,15 @@ SPL: MKIMAGEFLAGS_flash.bin = -n spl/u-boot-spl.cfgout -T $(IMAGE_TYPE) -e 0x100000 flash.bin: MKIMAGEOUTPUT = flash.log -flash.bin: spl/u-boot-spl.bin u-boot.itb FORCE -ifeq ($(SPL_DEPFILE_EXISTS),0) +MKIMAGEFLAGS_u-boot.cnt = -n container.cfg -T $(IMAGE_TYPE) -e 0x100000 +u-boot.cnt: MKIMAGEOUTPUT = u-boot.cnt.log + +ifeq ($(CONFIG_SPL_LOAD_IMX_CONTAINER), y) +u-boot.cnt: u-boot.bin container.cfg FORCE $(call if_changed,mkimage) endif +flash.bin: spl/u-boot-spl.bin FORCE + $(call if_changed,mkimage) endif else
arch/arm/mach-imx/imx8/Kconfig +7 -0
@@ -29,6 +29,13 @@ config SPL_LOAD_IMX_CONTAINER help This is to let SPL could load i.MX8 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. + choice prompt "i.MX8 board select" optional
Signature · 1 line
2.16.4
PATCH v4 4/6 imx8qxp_mek: switch to use container image
In reply to Peng FanBecause FIT could not be used for AHAB secure boot on i.MX8, so switch to use container image that could let SPL verify ATF and U-Boot with AHAB.
Note: The AHAB related code has not been added.
--- board/freescale/imx8qxp_mek/README | 4 +--- board/freescale/imx8qxp_mek/uboot-container.cfg | 13 +++++++++++++ configs/imx8qxp_mek_defconfig | 5 ++--- 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 board/freescale/imx8qxp_mek/uboot-container.cfg
board/freescale/imx8qxp_mek/README +1 -3
@@ -39,11 +39,9 @@ $ cp imx-sc-firmware-0.7/mx8qx-mek-scfw-tcm.bin . Build U-Boot ============ -$ export ATF_LOAD_ADDR=0x80000000 -$ export BL33_LOAD_ADDR=0x80020000 $ make imx8qxp_mek_defconfig $ make flash.bin -$ dd if=u-boot.itb of=flash.bin bs=512 seek=1984 +$ dd if=u-boot.cnt of=flash.bin bs=512 seek=1984 Flash the binary into the SD card =================================
board/freescale/imx8qxp_mek/uboot-container.cfg new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2019 NXP + */ + +#define __ASSEMBLY__ + +/* This file is to create a container image could be loaded by SPL */ +BOOT_FROM SD 0x400 +SOC_TYPE IMX8QX +CONTAINER +IMAGE A35 bl31.bin 0x80000000 +IMAGE A35 u-boot.bin CONFIG_SYS_TEXT_BASE
configs/imx8qxp_mek_defconfig +2 -3
@@ -7,15 +7,14 @@ CONFIG_SPL_GPIO_SUPPORT=y CONFIG_SPL_LIBCOMMON_SUPPORT=y CONFIG_SPL_LIBGENERIC_SUPPORT=y CONFIG_SYS_MALLOC_F_LEN=0x4000 +CONFIG_SPL_LOAD_IMX_CONTAINER=y +CONFIG_IMX_CONTAINER_CFG="board/freescale/imx8qxp_mek/uboot-container.cfg" CONFIG_TARGET_IMX8QXP_MEK=y CONFIG_SPL_MMC_SUPPORT=y CONFIG_SPL_SERIAL_SUPPORT=y CONFIG_SPL_DRIVERS_MISC_SUPPORT=y CONFIG_NR_DRAM_BANKS=3 CONFIG_SPL=y -CONFIG_FIT=y -CONFIG_SPL_LOAD_FIT=y -CONFIG_SPL_FIT_GENERATOR="arch/arm/mach-imx/mkimage_fit_atf.sh" CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/imx8qxp_mek/imximage.cfg" CONFIG_BOOTDELAY=3 CONFIG_LOG=y
Signature · 1 line
2.16.4
PATCH v4 5/6 imx8qm_mek: switch to use container image
In reply to Peng FanBecause FIT could not be used for AHAB secure boot on i.MX8, so switch to use container image that could let SPL verify ATF and U-Boot with AHAB.
Enable HUSH_PARSER in defconfig to make run netboot could work.
Note: The AHAB related code has not been added.
--- board/freescale/imx8qm_mek/README | 4 +--- board/freescale/imx8qm_mek/uboot-container.cfg | 13 +++++++++++++ configs/imx8qm_mek_defconfig | 8 +++++--- 3 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 board/freescale/imx8qm_mek/uboot-container.cfg
board/freescale/imx8qm_mek/README +1 -3
@@ -39,11 +39,9 @@ $ cp imx-sc-firmware-0.7/mx8qm-mek-scfw-tcm.bin . Build U-Boot ============ -$ export ATF_LOAD_ADDR=0x80000000 -$ export BL33_LOAD_ADDR=0x80020000 $ make imx8qm_mek_defconfig $ make flash.bin -$ dd if=u-boot.itb of=flash.bin bs=512 seek=1984 +$ dd if=u-boot.cnt of=flash.bin bs=512 seek=1984 Flash the binary into the SD card =================================
board/freescale/imx8qm_mek/uboot-container.cfg new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * Copyright 2019 NXP + */ + +#define __ASSEMBLY__ + +/* This file is to create a container image could be loaded by SPL */ +BOOT_FROM SD 0x400 +SOC_TYPE IMX8QM +CONTAINER +IMAGE A35 bl31.bin 0x80000000 +IMAGE A35 u-boot.bin CONFIG_SYS_TEXT_BASE
configs/imx8qm_mek_defconfig +5 -3
@@ -6,23 +6,25 @@ CONFIG_SYS_TEXT_BASE=0x80020000 CONFIG_SPL_GPIO_SUPPORT=y CONFIG_SPL_LIBCOMMON_SUPPORT=y CONFIG_SPL_LIBGENERIC_SUPPORT=y +CONFIG_SYS_MALLOC_F_LEN=0x4000 +CONFIG_SPL_LOAD_IMX_CONTAINER=y +CONFIG_IMX_CONTAINER_CFG="board/freescale/imx8qm_mek/uboot-container.cfg" CONFIG_TARGET_IMX8QM_MEK=y CONFIG_SPL_MMC_SUPPORT=y CONFIG_SPL_SERIAL_SUPPORT=y CONFIG_SPL_DRIVERS_MISC_SUPPORT=y CONFIG_NR_DRAM_BANKS=3 CONFIG_SPL=y -CONFIG_FIT=y -CONFIG_SPL_LOAD_FIT=y -CONFIG_SPL_FIT_GENERATOR="arch/arm/mach-imx/mkimage_fit_atf.sh" CONFIG_SYS_EXTRA_OPTIONS="IMX_CONFIG=board/freescale/imx8qm_mek/imximage.cfg" CONFIG_BOOTDELAY=3 CONFIG_LOG=y CONFIG_SPL_BOARD_INIT=y +CONFIG_SPL_SYS_MALLOC_SIMPLE=y CONFIG_SPL_SEPARATE_BSS=y CONFIG_SPL_POWER_SUPPORT=y CONFIG_SPL_POWER_DOMAIN=y CONFIG_SPL_WATCHDOG_SUPPORT=y +CONFIG_HUSH_PARSER=y CONFIG_CMD_CPU=y # CONFIG_CMD_IMPORTENV is not set CONFIG_CMD_CLK=y
Signature · 1 line
2.16.4
PATCH v4 6/6 doc: imx: mkimage: introduce i.MX8 image format
In reply to Peng FanIntroduce i.MX8 container set configuration file and add example
--- doc/imx/mkimage/imx8image.txt | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 doc/imx/mkimage/imx8image.txt
doc/imx/mkimage/imx8image.txt new file +45 -0
@@ -0,0 +1,45 @@ +Introduction: +============= + +This documentation entry describes the i.MX8 container format and how +to use. + +A Boot image consists of: + - Primary Boot Container Set + - Optional Secondary Boot Container Set + +The imx8image only support the Primary Boot Container Set. + +The Primary Boot Container Set contains two containers. The 1st container +only contain the SECO firmware image, the 2nd container can contain +multiple images and typically have: + - SCF FW image + - M4 FW image + - AP FW image + +For more details, refer i.MX8 Reference Mannual Chapter 5 +"System Boot and section", "5.9 (Boot image) of the processor's manual" + +Configuration file: +================== +BOOT_FROM [sd|emmc_fastboot|fspi|nand_4k|nand_8k|nand_16k] [sector_size] + - indicates the boot media +SOC_TYPE [IMX8QM|IMX8QX] + - indicates the soc +APPEND [ahab container image] + - indicates the ahah image that will be put in the 1st container + When creating container image will be loaded by SPL, this entry + should not this included +CONTAINER + - indicates to create the 2nd container +IMAGE [SCU|M40|M41|A35|A53|A72] [image file] [load address] + - indicates images will be put in the 2nd container + +Example: +======= +BOOT_FROM SD 0x400 +SOC_TYPE IMX8QM +APPEND mx8qm-ahab-container.img +CONTAINER +IMAGE SCU mx8qm-mek-scfw-tcm.bin +IMAGE A35 spl/u-boot-spl.bin 0x00100000
Signature · 1 line
2.16.4