From c2f31c99fef7fe613f6b2f1db012c95c32f1ca08 Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Thu, 29 Nov 2018 14:46:05 +0000 Subject: [PATCH 1/4] warp7: io_storage: Remove DTB from FIP Recently upstreamed changes to OP-TEE mean that it is possible for OP-TEE to provide a DTB overlay directly to subsequent boot stages thus negating the requirement to bundle a DTB in the FIP. This patch switches off the dependency on the DTB in the FIP descriptor instead we will provide the necessary data as an overlay from OP-TEE. Signed-off-by: Bryan O'Donoghue --- plat/imx/imx7/warp7/warp7_bl2_mem_params_desc.c | 10 ---------- plat/imx/imx7/warp7/warp7_io_storage.c | 9 --------- 2 files changed, 19 deletions(-) diff --git a/plat/imx/imx7/warp7/warp7_bl2_mem_params_desc.c b/plat/imx/imx7/warp7/warp7_bl2_mem_params_desc.c index a29e14198..c670d423c 100644 --- a/plat/imx/imx7/warp7/warp7_bl2_mem_params_desc.c +++ b/plat/imx/imx7/warp7/warp7_bl2_mem_params_desc.c @@ -27,16 +27,6 @@ static bl_mem_params_node_t bl2_mem_params_descs[] = { .next_handoff_image_id = BL33_IMAGE_ID, }, - { - .image_id = HW_CONFIG_ID, - SET_STATIC_PARAM_HEAD(ep_info, PARAM_IMAGE_BINARY, - VERSION_2, entry_point_info_t, SECURE | NON_EXECUTABLE), - SET_STATIC_PARAM_HEAD(image_info, PARAM_IMAGE_BINARY, - VERSION_2, image_info_t, 0), - .image_info.image_base = WARP7_DTB_BASE, - .image_info.image_max_size = WARP7_DTB_SIZE, - .next_handoff_image_id = INVALID_IMAGE_ID, - }, { .image_id = BL32_EXTRA1_IMAGE_ID, diff --git a/plat/imx/imx7/warp7/warp7_io_storage.c b/plat/imx/imx7/warp7/warp7_io_storage.c index b9cace090..6f0319d1d 100644 --- a/plat/imx/imx7/warp7/warp7_io_storage.c +++ b/plat/imx/imx7/warp7/warp7_io_storage.c @@ -60,10 +60,6 @@ static const io_uuid_spec_t bl32_uuid_spec = { .uuid = UUID_SECURE_PAYLOAD_BL32, }; -static const io_uuid_spec_t hw_config_uuid_spec = { - .uuid = UUID_HW_CONFIG, -}; - static const io_uuid_spec_t bl32_extra1_uuid_spec = { .uuid = UUID_SECURE_PAYLOAD_BL32_EXTRA1, }; @@ -112,11 +108,6 @@ static const struct plat_io_policy policies[] = { (uintptr_t)&bl32_extra2_uuid_spec, open_fip }, - [HW_CONFIG_ID] = { - &fip_dev_handle, - (uintptr_t)&hw_config_uuid_spec, - open_fip - }, [BL33_IMAGE_ID] = { &fip_dev_handle, (uintptr_t)&bl33_uuid_spec, From e483639ad2fe0f3f9425b218bf6c37b9fbafc78f Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Thu, 29 Nov 2018 15:59:14 +0000 Subject: [PATCH 2/4] warp7: Define DTB overlay address in memory map This patch defines the expected DTB overlay address in the memory map for this platform. Its important that all points in the boot process agree on this memory map even if not all elements utilize it. Signed-off-by: Bryan O'Donoghue --- plat/imx/imx7/warp7/include/platform_def.h | 8 ++++++++ plat/imx/imx7/warp7/warp7_bl2_el3_setup.c | 13 +++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/plat/imx/imx7/warp7/include/platform_def.h b/plat/imx/imx7/warp7/include/platform_def.h index a931c8062..d58382f38 100644 --- a/plat/imx/imx7/warp7/include/platform_def.h +++ b/plat/imx/imx7/warp7/include/platform_def.h @@ -106,6 +106,12 @@ #define WARP7_DTB_BASE (DRAM_BASE + 0x03000000) #define WARP7_DTB_LIMIT (WARP7_DTB_BASE + WARP7_DTB_SIZE) +/* Define the absolute location of DTB Overlay 0x83100000 - 0x83101000 */ +#define WARP7_DTB_OVERLAY_SIZE 0x00001000 +#define WARP7_DTB_OVERLAY_BASE WARP7_DTB_LIMIT +#define WARP7_DTB_OVERLAY_LIMIT (WARP7_DTB_OVERLAY_BASE + \ + WARP7_DTB_OVERLAY_SIZE) + /* * BL2 specific defines. * @@ -142,6 +148,8 @@ * | DDR | BL33/U-BOOT * 0x87800000 +-----------------+ * | DDR | Unallocated + * 0x83101000 +-----------------+ + * | DDR | DTB Overlay * 0x83100000 +-----------------+ * | DDR | DTB * 0x83000000 +-----------------+ diff --git a/plat/imx/imx7/warp7/warp7_bl2_el3_setup.c b/plat/imx/imx7/warp7/warp7_bl2_el3_setup.c index 032ed7b19..08baf1995 100644 --- a/plat/imx/imx7/warp7/warp7_bl2_el3_setup.c +++ b/plat/imx/imx7/warp7/warp7_bl2_el3_setup.c @@ -290,12 +290,13 @@ void bl2_el3_early_platform_setup(u_register_t arg1, u_register_t arg2, imx_wdog_init(); /* Print out the expected memory map */ - VERBOSE("\tOPTEE 0x%08x-0x%08x\n", WARP7_OPTEE_BASE, WARP7_OPTEE_LIMIT); - VERBOSE("\tATF/BL2 0x%08x-0x%08x\n", BL2_RAM_BASE, BL2_RAM_LIMIT); - VERBOSE("\tSHRAM 0x%08x-0x%08x\n", SHARED_RAM_BASE, SHARED_RAM_LIMIT); - VERBOSE("\tFIP 0x%08x-0x%08x\n", WARP7_FIP_BASE, WARP7_FIP_LIMIT); - VERBOSE("\tDTB 0x%08x-0x%08x\n", WARP7_DTB_BASE, WARP7_DTB_LIMIT); - VERBOSE("\tUBOOT/BL33 0x%08x-0x%08x\n", WARP7_UBOOT_BASE, WARP7_UBOOT_LIMIT); + VERBOSE("\tOPTEE 0x%08x-0x%08x\n", WARP7_OPTEE_BASE, WARP7_OPTEE_LIMIT); + VERBOSE("\tATF/BL2 0x%08x-0x%08x\n", BL2_RAM_BASE, BL2_RAM_LIMIT); + VERBOSE("\tSHRAM 0x%08x-0x%08x\n", SHARED_RAM_BASE, SHARED_RAM_LIMIT); + VERBOSE("\tFIP 0x%08x-0x%08x\n", WARP7_FIP_BASE, WARP7_FIP_LIMIT); + VERBOSE("\tDTB-OVERLAY 0x%08x-0x%08x\n", WARP7_DTB_OVERLAY_BASE, WARP7_DTB_OVERLAY_LIMIT); + VERBOSE("\tDTB 0x%08x-0x%08x\n", WARP7_DTB_BASE, WARP7_DTB_LIMIT); + VERBOSE("\tUBOOT/BL33 0x%08x-0x%08x\n", WARP7_UBOOT_BASE, WARP7_UBOOT_LIMIT); } /* From a41d81cdb10e4a59279f781b5a2b71f8be7cf432 Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Fri, 26 Oct 2018 14:19:43 +0100 Subject: [PATCH 3/4] warp7: Enable Trusted Board Boot for WaRP7 This patch enables Trusted Board Boot for warp7. A subsequent patch contains build/run instructions. Signed-off-by: Bryan O'Donoghue Signed-off-by: Jun Nie --- plat/imx/imx7/warp7/platform.mk | 52 ++++++++++++++++++++ plat/imx/imx7/warp7/warp7_io_storage.c | 60 +++++++++++++++++++++++- plat/imx/imx7/warp7/warp7_rotpk.S | 15 ++++++ plat/imx/imx7/warp7/warp7_trusted_boot.c | 31 ++++++++++++ 4 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 plat/imx/imx7/warp7/warp7_rotpk.S create mode 100644 plat/imx/imx7/warp7/warp7_trusted_boot.c diff --git a/plat/imx/imx7/warp7/platform.mk b/plat/imx/imx7/warp7/platform.mk index a77186582..f7bd4ae5b 100644 --- a/plat/imx/imx7/warp7/platform.mk +++ b/plat/imx/imx7/warp7/platform.mk @@ -62,6 +62,43 @@ BL2_SOURCES += common/desc_image_load.c \ plat/imx/imx7/warp7/warp7_image_load.c \ ${XLAT_TABLES_LIB_SRCS} +ifneq (${TRUSTED_BOARD_BOOT},0) + +include drivers/auth/mbedtls/mbedtls_crypto.mk +include drivers/auth/mbedtls/mbedtls_x509.mk + +AUTH_SOURCES := drivers/auth/auth_mod.c \ + drivers/auth/crypto_mod.c \ + drivers/auth/img_parser_mod.c \ + drivers/auth/tbbr/tbbr_cot.c + +BL2_SOURCES += ${AUTH_SOURCES} \ + plat/common/tbbr/plat_tbbr.c \ + plat/imx/imx7/warp7/warp7_trusted_boot.c \ + plat/imx/imx7/warp7/warp7_rotpk.S + +ROT_KEY = $(BUILD_PLAT)/rot_key.pem +ROTPK_HASH = $(BUILD_PLAT)/rotpk_sha256.bin + +$(eval $(call add_define_val,ROTPK_HASH,'"$(ROTPK_HASH)"')) +$(eval $(call MAKE_LIB_DIRS)) + +$(BUILD_PLAT)/bl2/warp7_rotpk.o: $(ROTPK_HASH) + +certificates: $(ROT_KEY) + +$(ROT_KEY): | $(BUILD_PLAT) + @echo " OPENSSL $@" + @if [ ! -f $(ROT_KEY) ]; then \ + openssl genrsa 2048 > $@ 2>/dev/null; \ + fi + +$(ROTPK_HASH): $(ROT_KEY) + @echo " OPENSSL $@" + $(Q)openssl rsa -in $< -pubout -outform DER 2>/dev/null |\ + openssl dgst -sha256 -binary > $@ 2>/dev/null +endif + # Build config flags # ------------------ @@ -86,6 +123,21 @@ USE_COHERENT_MEM := 1 PLAT_WARP7_UART :=1 $(eval $(call add_define,PLAT_WARP7_UART)) +# Add the build options to pack BLx images and kernel device tree +# in the FIP if the platform requires. +ifneq ($(BL2),) +$(eval $(call TOOL_ADD_PAYLOAD,${BUILD_PLAT}/tb_fw.crt,--tb-fw-cert)) +endif +ifneq ($(BL32_EXTRA1),) +$(eval $(call TOOL_ADD_IMG,BL32_EXTRA1,--tos-fw-extra1)) +endif +ifneq ($(BL32_EXTRA2),) +$(eval $(call TOOL_ADD_IMG,BL32_EXTRA2,--tos-fw-extra2)) +endif +ifneq ($(HW_CONFIG),) +$(eval $(call TOOL_ADD_IMG,HW_CONFIG,--hw-config)) +endif + # Verify build config # ------------------- diff --git a/plat/imx/imx7/warp7/warp7_io_storage.c b/plat/imx/imx7/warp7/warp7_io_storage.c index 6f0319d1d..fcfb5036b 100644 --- a/plat/imx/imx7/warp7/warp7_io_storage.c +++ b/plat/imx/imx7/warp7/warp7_io_storage.c @@ -72,6 +72,32 @@ static const io_uuid_spec_t bl33_uuid_spec = { .uuid = UUID_NON_TRUSTED_FIRMWARE_BL33, }; +#if TRUSTED_BOARD_BOOT +static const io_uuid_spec_t tb_fw_cert_uuid_spec = { + .uuid = UUID_TRUSTED_BOOT_FW_CERT, +}; + +static const io_uuid_spec_t trusted_key_cert_uuid_spec = { + .uuid = UUID_TRUSTED_KEY_CERT, +}; + +static const io_uuid_spec_t tos_fw_key_cert_uuid_spec = { + .uuid = UUID_TRUSTED_OS_FW_KEY_CERT, +}; + +static const io_uuid_spec_t tos_fw_cert_uuid_spec = { + .uuid = UUID_TRUSTED_OS_FW_CONTENT_CERT, +}; + +static const io_uuid_spec_t nt_fw_key_cert_uuid_spec = { + .uuid = UUID_NON_TRUSTED_FW_KEY_CERT, +}; + +static const io_uuid_spec_t nt_fw_cert_uuid_spec = { + .uuid = UUID_NON_TRUSTED_FW_CONTENT_CERT, +}; +#endif /* TRUSTED_BOARD_BOOT */ + /* TODO: this structure is replicated multiple times. rationalize it ! */ struct plat_io_policy { uintptr_t *dev_handle; @@ -112,7 +138,39 @@ static const struct plat_io_policy policies[] = { &fip_dev_handle, (uintptr_t)&bl33_uuid_spec, open_fip - } + }, +#if TRUSTED_BOARD_BOOT + [TRUSTED_BOOT_FW_CERT_ID] = { + &fip_dev_handle, + (uintptr_t)&tb_fw_cert_uuid_spec, + open_fip + }, + [TRUSTED_KEY_CERT_ID] = { + &fip_dev_handle, + (uintptr_t)&trusted_key_cert_uuid_spec, + open_fip + }, + [TRUSTED_OS_FW_KEY_CERT_ID] = { + &fip_dev_handle, + (uintptr_t)&tos_fw_key_cert_uuid_spec, + open_fip + }, + [NON_TRUSTED_FW_KEY_CERT_ID] = { + &fip_dev_handle, + (uintptr_t)&nt_fw_key_cert_uuid_spec, + open_fip + }, + [TRUSTED_OS_FW_CONTENT_CERT_ID] = { + &fip_dev_handle, + (uintptr_t)&tos_fw_cert_uuid_spec, + open_fip + }, + [NON_TRUSTED_FW_CONTENT_CERT_ID] = { + &fip_dev_handle, + (uintptr_t)&nt_fw_cert_uuid_spec, + open_fip + }, +#endif /* TRUSTED_BOARD_BOOT */ }; static int open_fip(const uintptr_t spec) diff --git a/plat/imx/imx7/warp7/warp7_rotpk.S b/plat/imx/imx7/warp7/warp7_rotpk.S new file mode 100644 index 000000000..f74b6d25b --- /dev/null +++ b/plat/imx/imx7/warp7/warp7_rotpk.S @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + + .global warp7_rotpk_hash + .global warp7_rotpk_hash_end +warp7_rotpk_hash: + /* DER header */ + .byte 0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, 0x60, 0x86, 0x48 + .byte 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 + /* SHA256 */ + .incbin ROTPK_HASH +warp7_rotpk_hash_end: diff --git a/plat/imx/imx7/warp7/warp7_trusted_boot.c b/plat/imx/imx7/warp7/warp7_trusted_boot.c new file mode 100644 index 000000000..8157cd5c4 --- /dev/null +++ b/plat/imx/imx7/warp7/warp7_trusted_boot.c @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include + +extern char warp7_rotpk_hash[], warp7_rotpk_hash_end[]; + +int plat_get_rotpk_info(void *cookie, void **key_ptr, unsigned int *key_len, + unsigned int *flags) +{ + *key_ptr = warp7_rotpk_hash; + *key_len = warp7_rotpk_hash_end - warp7_rotpk_hash; + *flags = ROTPK_IS_HASH; + + return 0; +} + +int plat_get_nv_ctr(void *cookie, unsigned int *nv_ctr) +{ + *nv_ctr = 0; + + return 0; +} + +int plat_set_nv_ctr(void *cookie, unsigned int nv_ctr) +{ + return 1; +} From 31e4c20de686fc788d4cbd55ff7d2ea92de502a3 Mon Sep 17 00:00:00 2001 From: Bryan O'Donoghue Date: Fri, 26 Oct 2018 16:06:28 +0100 Subject: [PATCH 4/4] docs: warp7: Update WaRP7 description for TBB This patch updates the WaRP7 build descriptions for booting WaRP7 in Trusted Board Boot mode. TBB is the only mode we really intend to support for this board so rather than maintain documentation for the old way of doing it, this patch updates the description for TBB mode only. Signed-off-by: Bryan O'Donoghue --- docs/plat/warp7.rst | 76 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/docs/plat/warp7.rst b/docs/plat/warp7.rst index 51c2609ba..6c04d91ec 100644 --- a/docs/plat/warp7.rst +++ b/docs/plat/warp7.rst @@ -31,15 +31,6 @@ https://git.linaro.org/landing-teams/working/mbl/u-boot.git make warp7_bl33_defconfig; make u-boot.imx arch=ARM CROSS_COMPILE=arm-linux-gnueabihf- -## TF-A: - -https://github.com/ARM-software/arm-trusted-firmware.git - -.. code:: shell - - make CROSS_COMPILE=arm-linux-gnueabihf- PLAT=warp7 ARCH=aarch32 ARM_ARCH_MAJOR=7 ARM_CORTEX_A7=yes AARCH32_SP=optee all - /path/to/u-boot/tools/mkimage -n /path/to/u-boot/u-boot.cfgout -T imximage -e 0x9df00000 -d ./build/warp7/debug/bl2.bin ./build/warp7/debug/bl2.bin.imx - ## OP-TEE: https://github.com/OP-TEE/optee_os.git @@ -48,19 +39,76 @@ https://github.com/OP-TEE/optee_os.git make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- PLATFORM=imx PLATFORM_FLAVOR=mx7swarp7 ARCH=arm CFG_PAGEABLE_ADDR=0 CFG_DT_ADDR=0x83000000 CFG_NS_ENTRY_ADDR=0x87800000 +## TF-A: + +https://github.com/ARM-software/arm-trusted-firmware.git + +The following commands assume that a directory exits in the top-level TFA build +directory "fiptool_images". "fiptool_images" contains + +- u-boot.bin + The binary output from the u-boot instructions above + +- tee-header_v2.bin +- tee-pager_v2.bin +- tee-pageable_v2.bin + Binary outputs from the previous OPTEE build steps + +It is also assumed copy of mbedtls is available on the path path ../mbedtls + https://github.com/ARMmbed/mbedtls.git + At the time of writing HEAD points to 0592ea772aee48ca1e6d9eb84eca8e143033d973 + +.. code:: shell + + mkdir fiptool_images + cp /path/to/optee/out/arm-plat-imx/core/tee-header_v2.bin fiptool_images + cp /path/to/optee/out/arm-plat-imx/core/tee-pager_v2.bin fiptool_images + cp /path/to/optee/out/arm-plat-imx/core/tee-pageable_v2.bin fiptool_images + + make CROSS_COMPILE=${CROSS_COMPILE} PLAT=warp7 ARCH=aarch32 ARM_ARCH_MAJOR=7 \ + ARM_CORTEX_A7=yes AARCH32_SP=optee PLAT_WARP7_UART=1 GENERATE_COT=1 \ + TRUSTED_BOARD_BOOT=1 USE_TBBR_DEFS=1 MBEDTLS_DIR=../mbedtls \ + NEED_BL32=yes BL32=fiptool_images/tee-header_v2.bin \ + BL32_EXTRA1=fiptool_images/tee-pager_v2.bin \ + BL32_EXTRA2=fiptool_images/tee-pageable_v2.bin \ + BL33=fiptool_images/u-boot.bin certificates all + + /path/to/u-boot/tools/mkimage -n /path/to/u-boot/u-boot.cfgout -T imximage -e 0x9df00000 -d ./build/warp7/debug/bl2.bin ./build/warp7/debug/bl2.bin.imx ## FIP: .. code:: shell - mkdir fiptool_images cp /path/to/uboot/u-boot.bin fiptool_images - cp /path/to/optee/out/arm-plat-imx/core/tee-header_v2.bin fiptool_images - cp /path/to/optee/out/arm-plat-imx/core/tee-pager_v2.bin fiptool_images - cp /path/to/optee/out/arm-plat-imx/core/tee-pageable_v2.bin fiptool_images cp /path/to/linux/arch/boot/dts/imx7s-warp.dtb fiptool_images - tools/fiptool/fiptool create --tos-fw fiptool_images/tee-header_v2.bin --tos-fw-extra1 fiptool_images/tee-pager_v2.bin --tos-fw-extra2 fiptool_images/tee-pageable_v2.bin --nt-fw fiptool_images/u-boot.bin --hw-config fiptool_images/imx7s-warp.dtb warp7.fip + tools/cert_create/cert_create -n --rot-key "build/warp7/debug/rot_key.pem" \ + --tfw-nvctr 0 \ + --ntfw-nvctr 0 \ + --trusted-key-cert fiptool_images/trusted-key-cert.key-crt \ + --tb-fw=build/warp7/debug/bl2.bin \ + --tb-fw-cert fiptool_images/trusted-boot-fw.key-crt\ + --tos-fw fiptool_images/tee-header_v2.bin \ + --tos-fw-cert fiptool_images/tee-header_v2.bin.crt \ + --tos-fw-key-cert fiptool_images/tee-header_v2.bin.key-crt \ + --tos-fw-extra1 fiptool_images/tee-pager_v2.bin \ + --tos-fw-extra2 fiptool_images/tee-pageable_v2.bin \ + --nt-fw fiptool_images/u-boot.bin \ + --nt-fw-cert fiptool_images/u-boot.bin.crt \ + --nt-fw-key-cert fiptool_images/u-boot.bin.key-crt \ + --hw-config fiptool_images/imx7s-warp.dtb + + tools/fiptool/fiptool create --tos-fw fiptool_images/tee-header_v2.bin \ + --tos-fw-extra1 fiptool_images/tee-pager_v2.bin \ + --tos-fw-extra2 fiptool_images/tee-pageable_v2.bin \ + --nt-fw fiptool_images/u-boot.bin \ + --hw-config fiptool_images/imx7s-warp.dtb \ + --tos-fw-cert fiptool_images/tee-header_v2.bin.crt \ + --tos-fw-key-cert fiptool_images/tee-header_v2.bin.key-crt \ + --nt-fw-cert fiptool_images/u-boot.bin.crt \ + --nt-fw-key-cert fiptool_images/u-boot.bin.key-crt \ + --trusted-key-cert fiptool_images/trusted-key-cert.key-crt \ + --tb-fw-cert fiptool_images/trusted-boot-fw.key-crt warp7.fip # Deploy Images