Skip to contentSkip to conversation

add i.MX8 container loading support

PATCH Superseded Peng Fan 1 participant 6 messages Jun 19, 2019

Subsystems (4)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

v2 cover add i.MX8 container loading support

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

CI: https://travis-ci.org/MrVan/u-boot/builds/547161366

V2:
Drop cleanup Makefile since V1, that patch is not correct. Rebased on master

Peng Fan (5):
spl: Add function to get u-boot raw sector
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

 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/imx8qxp_mek/README              |   4 +-
 board/freescale/imx8qxp_mek/uboot-container.cfg |  13 +++
 common/spl/spl_mmc.c                            |  21 ++++-
 configs/imx8qxp_mek_defconfig                   |   5 +-
 include/spl.h                                   |  12 +++
 11 files changed, 260 insertions(+), 10 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/imx8qxp_mek/uboot-container.cfg
Signature · 1 line
2.16.4
author
#1 lore raw

PATCH v2 1/5 spl: Add function to get u-boot raw sector

Add a weak function spl_mmc_get_uboot_raw_sector to get u-boot raw sector. At default it returns CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR. Users can overwrite it to return customized offset.

This is to support i.MX8 specific image type container image type.

Cc Tien Fong Chee <[email protected]>
Cc Peng Fan <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc York Sun <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Alex Kiernan <[email protected]>
---
 common/spl/spl_mmc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
common/spl/spl_mmc.c +9 -2
index 324d91c884..bf53a1dadf 100644
@@ -149,6 +149,13 @@ static int spl_mmc_find_device(struct mmc **mmcp, u32 boot_device)
 	return 0;
 }
 
+#ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
+unsigned long __weak spl_mmc_get_uboot_raw_sector(struct mmc *mmc)
+{
+	return CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR;
+}
+#endif
+
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_PARTITION
 static int mmc_load_image_raw_partition(struct spl_image_info *spl_image,
 					struct mmc *mmc, int partition)
@@ -181,7 +188,7 @@ static int mmc_load_image_raw_partition(struct spl_image_info *spl_image,
 
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 	return mmc_load_image_raw_sector(spl_image, mmc,
-			info.start + CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
+			info.start + spl_mmc_get_uboot_raw_sector(mmc));
 #else
 	return mmc_load_image_raw_sector(spl_image, mmc, info.start);
 #endif
@@ -366,7 +373,7 @@ int spl_mmc_load_image(struct spl_image_info *spl_image,
 #endif
 #ifdef CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_USE_SECTOR
 		err = mmc_load_image_raw_sector(spl_image, mmc,
-			CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR);
+			spl_mmc_get_uboot_raw_sector(mmc));
 		if (!err)
 			return err;
 #endif
Signature · 1 line
2.16.4
author
#2 lore raw

PATCH v2 2/5 imx8: support parsing i.MX8 Container file

In reply to Peng Fan

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
new file mode 100644
index 0000000000..c1e5700859
@@ -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
index bbe323d5ca..e9496cb611 100644
@@ -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
index 31ad169ccf..19690110a5 100644
@@ -5,3 +5,7 @@
 #
 
 obj-y += cpu.o iomux.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
author
#3 lore raw

PATCH v2 3/5 spl: mmc: support loading i.MX container format file

In reply to Peng Fan

i.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.

Cc Simon Goldschmidt <[email protected]>
Cc Tien Fong Chee <[email protected]>
Cc York Sun <[email protected]>
Cc Marek Vasut <[email protected]>
Cc Alex Kiernan <[email protected]>
Cc Simon Glass <[email protected]>
Cc Philipp Tomsich <[email protected]>
Cc Kever Yang <[email protected]>
Cc Heiko Schocher <[email protected]>
---
 common/spl/spl_mmc.c | 10 ++++++++++
 include/spl.h        | 12 ++++++++++++
 2 files changed, 22 insertions(+)
common/spl/spl_mmc.c +10 -0
index bf53a1dadf..6320af055b 100644
@@ -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
index a9aaef345f..e280685b68 100644
@@ -125,6 +125,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
author
#4 lore raw

PATCH v2 4/5 imx: add container target

In reply to Peng Fan

To 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
index c55ffa265f..09b354bea9 100644
@@ -1333,9 +1333,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
index 898478fc4a..6de81408f8 100644
@@ -89,6 +89,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
@@ -157,10 +162,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
index e9496cb611..d17760e333 100644
@@ -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
author
#5 lore raw

PATCH v2 5/5 imx8qxp_mek: switch to use container image

In reply to Peng Fan

Because 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
index f32290e3a2..6dc151b166 100644
@@ -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=528
+$ dd if=u-boot.cnt of=flash.bin bs=512 seek=528
 
 Flash the binary into the SD card
 =================================
board/freescale/imx8qxp_mek/uboot-container.cfg new file +13 -0
new file mode 100644
index 0000000000..8165811818
@@ -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
index d735d34b8b..5d6c5f968f 100644
@@ -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