Add FIT loadable custom processing
Subsystems (3)
v3 cover Add FIT loadable custom processing
Hello all,
To see the background on this see here[0].
As Simon suggested we are now using a linker list to keep any and all TEE specific code out of common files as, unlike kernel, dtb, and ramdisk TEE images may not be used by needed by all users.
The last 5 patches in this series are an example of how one can now add a handler for an image type for their platform.
Thanks,
Andrew
[0] http://lists.denx.de/pipermail/u-boot/2016-November/272614.html
Changes from v2:
- Moved generic OP-TEE definitions to common location
- Check return value from SMC call
- Added patch to add OP-TEE node to kernel fdt, this was missing from the last set to complete the working solution
Changes from v1:
- Added some additional documentation
- Last 4 patches are now the compleate working TEE loading solution for our DRA7xx/AM57xx platforms, not just an example
Andrew F. Davis (5):
image: Add FIT image loadable section custom processing
image: Add Trusted Execution Environment image type
arm: omap5: Add OPTEE node to fdt
board: ti: dra7xx: add FIT image TEE processing
board: ti: am57xx: add FIT image TEE processing
Harinarayan Bhatta (2):
arm: omap5: Add function to make an SMC call on cpu1
arm: omap5: Add TEE loading support
arch/arm/include/asm/omap_common.h | 1 + arch/arm/include/asm/omap_sec_common.h | 6 ++ arch/arm/mach-omap2/omap5/Makefile | 1 + arch/arm/mach-omap2/omap5/fdt.c | 35 +++++++- arch/arm/mach-omap2/omap5/sec-fxns.c | 108 +++++++++++++++++++++++++ arch/arm/mach-omap2/omap5/sec_entry_cpu1.S | 123 +++++++++++++++++++++++++++++ board/ti/am57xx/board.c | 7 ++ board/ti/dra7xx/evm.c | 7 ++ common/image.c | 34 ++++++++ doc/uImage.FIT/source_file_format.txt | 4 +- include/image.h | 31 ++++++++ include/tee/optee.h | 30 +++++++ 12 files changed, 385 insertions(+), 2 deletions(-) create mode 100644 arch/arm/mach-omap2/omap5/sec_entry_cpu1.S create mode 100644 include/tee/optee.h
Signature · 1 line
2.10.2
PATCH v3 1/7 image: Add FIT image loadable section custom processing
To help automate the loading of custom image types we add the ability to define custom handlers for the loadable section types. When we find a compatible type while loading a "loadable" image from a FIT image we run its associated handlers to perform any additional steps needed for loading this image.
--- common/image.c | 33 +++++++++++++++++++++++++++++++++ doc/uImage.FIT/source_file_format.txt | 4 +++- include/image.h | 30 ++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-)
common/image.c +33 -0
@@ -1389,6 +1389,23 @@ int boot_get_fpga(int argc, char * const argv[], bootm_headers_t *images, }#endif +static void fit_loadable_process (uint8_t img_type, +ulong img_data, +ulong img_len) +{ +int i; +const unsigned int count = + ll_entry_count(struct fit_loadable_tbl, fit_loadable); +struct fit_loadable_tbl *fit_loadable_handler = + ll_entry_start(struct fit_loadable_tbl, fit_loadable); +/* For each loadable handler */ +for (i =0 ; i < count; i++, fit_loadable_handler++) +/* matching this type */ +if (fit_loadable_handler->type == img_type) +/* call that handler with this image data */ + fit_loadable_handler->handler (img_data, img_len); +} +int boot_get_loadable (int argc,char *const argv[],bootm_headers_t *images,uint8_t arch,const ulong *ld_start,ulong *const ld_len) {
@@ -1407,6 +1424,7 @@ int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,int conf_noffset;int fit_img_result;const char *uname; +uint8_t img_type;/* Check to see if the images struct has a FIT configuration */ if (!genimg_has_config (images)) {
@@ -1447,6 +1465,21 @@ int boot_get_loadable(int argc, char * const argv[], bootm_headers_t *images,/* Something went wrong! */ return fit_img_result; } + + fit_img_result =fit_image_get_node (buf, uname); +if (fit_img_result <0 ) { +/* Something went wrong! */ +return fit_img_result; + } + fit_img_result =fit_image_get_type (buf, + fit_img_result, + &img_type); +if (fit_img_result <0 ) { +/* Something went wrong! */ +return fit_img_result; + } + +fit_loadable_process (img_type, img_data, img_len); }break ;default :
doc/uImage.FIT/source_file_format.txt +3 -1
@@ -256,7 +256,9 @@ o config at 1 (component image node of a "fpga type"). - loadables : Unit name containing a list of additional binaries to be loaded at their given locations. "loadables" is a comma-separated list - of strings. U-Boot will load each binary at its given start-address. + of strings. U-Boot will load each binary@its given start-address and + may optionaly invoke additional post-processing steps on this binary based + on its component image node type. The FDT blob is required to properly boot FDT based kernel, so the minimal configuration for 2.6 FDT kernel is (kernel, fdt) pair.
include/image.h +30 -0
@@ -1271,4 +1271,34 @@ int board_fit_config_name_match(const char *name);void board_fit_image_post_process (void **p_image,size_t *p_size);#endif /* CONFIG_SPL_FIT_IMAGE_POST_PROCESS */ +/** +* Mapping of image types to function handlers to be invoked on the associated +* loaded images +* +* @type: Type of image, I.E. IH_TYPE_* +* @handler: Function to call on loaded image +*/ +struct fit_loadable_tbl { +int type; +/** +* handler() - Process a loaded image +* +* @data: Pointer to start of loaded image data +* @size: Size of loaded image data +*/ +void (*handler)(ulong data,size_t size); +}; + +/* +* Define a FIT loadable image type handler +* +* _type is a valid uimage_type ID as defined in the "Image Type" enum above +* _handler is the handler function to call after this image type is loaded +*/ +#define U_BOOT_FIT_LOADABLE_HANDLER (_type, _handler) \ + ll_entry_declare(struct fit_loadable_tbl, _function, fit_loadable) = { \ + .type = _type, \ + .handler = _handler, \ + } +#endif /* __IMAGE_H__ */
Signature · 1 line
2.10.2
PATCH v3 1/7 image: Add FIT image loadable section custom processing
Quoted 8 lines · Andrew F. Davis
To help automate the loading of custom image types we add the ability to define custom handlers for the loadable section types. When we find a compatible type while loading a "loadable" image from a FIT image we run its associated handlers to perform any additional steps needed for loading this image.
Signed-off-by Andrew F. Davis <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161203/f34c17fe/attachment.sig>
PATCH v3 2/7 image: Add Trusted Execution Environment image type
In reply to Andrew F. DavisAdd a new image type representing Trusted Execution Environment (TEE) image types. For example, an OP-TEE OS binary image.
--- common/image.c | 1 + include/image.h | 1 + 2 files changed, 2 insertions(+)
common/image.c +1 -0
@@ -165,6 +165,7 @@ static const table_entry_t uimage_type[] = { { IH_TYPE_ZYNQIMAGE, "zynqimage", "Xilinx Zynq Boot Image" }, { IH_TYPE_ZYNQMPIMAGE, "zynqmpimage", "Xilinx ZynqMP Boot Image" }, { IH_TYPE_FPGA, "fpga", "FPGA Image" }, + { IH_TYPE_TEE, "tee", "Trusted Execution Environment Image",}, { -1, "", "", }, };
include/image.h +1 -0
@@ -279,6 +279,7 @@ enum {IH_TYPE_ZYNQMPIMAGE ,/* Xilinx ZynqMP Boot Image */ IH_TYPE_FPGA ,/* FPGA Image */ IH_TYPE_VYBRIDIMAGE ,/* VYBRID .vyb Image */ +IH_TYPE_TEE ,/* Trusted Execution Environment OS Image */ IH_TYPE_COUNT, /* Number of image types */ };
Signature · 1 line
2.10.2
PATCH v3 2/7 image: Add Trusted Execution Environment image type
Quoted 5 lines · Andrew F. Davis
Add a new image type representing Trusted Execution Environment (TEE) image types. For example, an OP-TEE OS binary image.
Signed-off-by Andrew F. Davis <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161203/de1e137d/attachment.sig>
PATCH v3 3/7 arm: omap5: Add function to make an SMC call on cpu1
In reply to Andrew F. DavisFrom: Harinarayan Bhatta <[email protected]>
On DRA7xx platform, CPU Core 1 is not used in u-boot. However, in some cases it is need to make secure API calls from Core 1. This patch adds an assembly function to make a secure (SMC) call from CPU Core #1.
--- arch/arm/include/asm/omap_common.h | 1 + arch/arm/mach-omap2/omap5/Makefile | 1 + arch/arm/mach-omap2/omap5/sec_entry_cpu1.S | 123 +++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 arch/arm/mach-omap2/omap5/sec_entry_cpu1.S
arch/arm/include/asm/omap_common.h +1 -0
@@ -632,6 +632,7 @@ void omap_smc1(u32 service, u32 val);* security (HS) device variants by doing a specially-formed smc entry. */ u32 omap_smc_sec (u32 service,u32 proc_id,u32 flag,u32 *params); +u32 omap_smc_sec_cpu1 (u32 service,u32 proc_id,u32 flag,u32 *params);void enable_edma3_clocks (void );void disable_edma3_clocks (void );
arch/arm/mach-omap2/omap5/Makefile +1 -0
@@ -15,3 +15,4 @@ obj-y += abb.o obj-y += fdt.o obj-$(CONFIG_IODELAY_RECALIBRATION) += dra7xx_iodelay.o obj-$(CONFIG_TI_SECURE_DEVICE) += sec-fxns.o +obj-$(CONFIG_DRA7XX) += sec_entry_cpu1.o
arch/arm/mach-omap2/omap5/sec_entry_cpu1.S new file +123 -0
123 lines not on this page · raw message
Signature · 1 line
2.10.2
PATCH v3 3/7 arm: omap5: Add function to make an SMC call on cpu1
Quoted 9 lines · Andrew F. Davis
From: Harinarayan Bhatta <[email protected]>
On DRA7xx platform, CPU Core 1 is not used in u-boot. However, in some cases it is need to make secure API calls from Core 1. This patch adds an assembly function to make a secure (SMC) call from CPU Core #1.
Signed-off-by Harinarayan Bhatta <[email protected]>Signed-off-by Andrew F. Davis <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161203/203d1c03/attachment.sig>
PATCH v3 4/7 arm: omap5: Add TEE loading support
In reply to Andrew F. DavisFrom: Harinarayan Bhatta <[email protected]>
secure_tee_install is used to install and initialize a secure TEE OS such as Linaro OP-TEE into the secure world. This function takes in the address where the signed TEE image is loaded as an argument. The signed TEE image consists of a header (struct tee_header), TEE code+data followed by the signature generated using image signing tool from TI security development package (SECDEV). Refer to README.ti-secure for more information.
This function uses 2 new secure APIs.
1. PPA_SERV_HAL_TEE_LOAD_MASTER - Must be called on CPU Core 0. Protected memory for TEE must be reserved before calling this function. This API needs arguments filled into struct ppa_tee_load_info. The TEE image is authenticated and if there are no errors, the control passes to the TEE entry point.
2. PPA_SERV_HAL_TEE_LOAD_SLAVE - Called on other CPU cores only after a TEE_LOAD_MASTER call. Takes no arguments. Checks if TEE was successfully loaded (on core 0) and transfers control to the same TEE entry point.
The code at TEE entry point is expected perform OS initialization steps and return back to non-secure world (U-Boot).
--- arch/arm/include/asm/omap_sec_common.h | 6 ++ arch/arm/mach-omap2/omap5/sec-fxns.c | 108 +++++++++++++++++++++++++++++++++ include/tee/optee.h | 30 +++++++++ 3 files changed, 144 insertions(+) create mode 100644 include/tee/optee.h
arch/arm/include/asm/omap_sec_common.h +6 -0
@@ -51,4 +51,10 @@ int secure_emif_reserve(void);*/ int secure_emif_firewall_lock (void ); +/* +* Invoke a secure HAL API to authenticate and install a Trusted Execution +* Environment (TEE) image. +*/ +int secure_tee_install (u32 tee_image); +#endif /* _OMAP_SEC_COMMON_H_ */
arch/arm/mach-omap2/omap5/sec-fxns.c +108 -0
124 lines not on this page · raw message
include/tee/optee.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* OP-TEE related definitions +* +* (C) Copyright 2016 Linaro Limited +* Andrew F. Davis <[email protected]> +* +* SPDX-License-Identifier: BSD-2-Clause +*/ + +#ifndef _OPTEE_H +#define _OPTEE_H + +#define OPTEE_MAGIC 0x4554504f +#define OPTEE_VERSION 1 +#define OPTEE_ARCH_ARM32 0 +#define OPTEE_ARCH_ARM64 1 + +struct optee_header { +uint32_t magic; +uint8_t version; +uint8_t arch; +uint16_t flags; +uint32_t init_size; +uint32_t init_load_addr_hi; +uint32_t init_load_addr_lo; +uint32_t init_mem_usage; +uint32_t paged_size; +}; + +#endif /* _OPTEE_H */
Signature · 1 line
2.10.2
PATCH v3 4/7 arm: omap5: Add TEE loading support
Quoted 22 lines · Andrew F. Davis
From: Harinarayan Bhatta <[email protected]>
secure_tee_installis used to install and initialize a secure TEE OS such as Linaro OP-TEE into the secure world. This function takes in the address where the signed TEE image is loaded as an argument. The signed TEE image consists of a header (structtee_header), TEE code+data followed by the signature generated using image signing tool from TI security development package (SECDEV). Refer to README.ti-secure for more information.This function uses 2 new secure APIs.
1.
PPA_SERV_HAL_TEE_LOAD_MASTER- Must be called on CPU Core 0. Protected memory for TEE must be reserved before calling this function. This API needs arguments filled into structppa_tee_load_info. The TEE image is authenticated and if there are no errors, the control passes to the TEE entry point.2.
PPA_SERV_HAL_TEE_LOAD_SLAVE- Called on other CPU cores only after aTEE_LOAD_MASTERcall. Takes no arguments. Checks if TEE was successfully loaded (on core 0) and transfers control to the same TEE entry point.
Quoted 5 lines
The code at TEE entry point is expected perform OS initialization steps and return back to non-secure world (U-Boot).
Signed-off-by Harinarayan Bhatta <[email protected]>Signed-off-by Andrew F. Davis <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161129/14fca8fa/attachment.sig>
PATCH v3 4/7 arm: omap5: Add TEE loading support
In reply to Andrew F. DavisQuoted 22 lines · Andrew F. Davis
From: Harinarayan Bhatta <[email protected]>
secure_tee_installis used to install and initialize a secure TEE OS such as Linaro OP-TEE into the secure world. This function takes in the address where the signed TEE image is loaded as an argument. The signed TEE image consists of a header (structtee_header), TEE code+data followed by the signature generated using image signing tool from TI security development package (SECDEV). Refer to README.ti-secure for more information.This function uses 2 new secure APIs.
1.
PPA_SERV_HAL_TEE_LOAD_MASTER- Must be called on CPU Core 0. Protected memory for TEE must be reserved before calling this function. This API needs arguments filled into structppa_tee_load_info. The TEE image is authenticated and if there are no errors, the control passes to the TEE entry point.2.
PPA_SERV_HAL_TEE_LOAD_SLAVE- Called on other CPU cores only after aTEE_LOAD_MASTERcall. Takes no arguments. Checks if TEE was successfully loaded (on core 0) and transfers control to the same TEE entry point.
Quoted 6 lines
The code at TEE entry point is expected perform OS initialization steps and return back to non-secure world (U-Boot).
Signed-off-by Harinarayan Bhatta <[email protected]>Signed-off-by Andrew F. Davis <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161203/75e81ece/attachment.sig>
PATCH v3 5/7 arm: omap5: Add OPTEE node to fdt
In reply to Andrew F. DavisAdd an OPTEE node to the FDT when TEE installation has completed successfully. This informs the kernel of the presence of OPTEE.
--- arch/arm/mach-omap2/omap5/fdt.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
arch/arm/mach-omap2/omap5/fdt.c +34 -1
@@ -212,6 +212,38 @@ static int ft_hs_fixup_dram(void *fdt, bd_t *bd)static int ft_hs_fixup_dram (void *fdt,bd_t *bd) {return 0 ; }#endif +static int ft_hs_add_tee (void *fdt,bd_t *bd) +{ +const char *path, *subpath; +int offs; + +extern int tee_loaded; +if (!tee_loaded) +return 0 ; + + path ="/" ; + offs =fdt_path_offset (fdt, path); + + subpath ="firmware" ; + offs =fdt_add_subnode (fdt, offs, subpath); +if (offs <0 ) { +printf ("Could not create %s node.\n" , subpath); +return 1 ; + } + + subpath ="optee" ; + offs =fdt_add_subnode (fdt, offs, subpath); +if (offs <0 ) { +printf ("Could not create %s node.\n" , subpath); +return 1 ; + } + +fdt_setprop_string (fdt, offs,"compatible" ,"linaro,optee-tz" ); +fdt_setprop_string (fdt, offs,"method" ,"smc" ); + +return 0 ; +} +static void ft_hs_fixups (void *fdt,bd_t *bd) {/* Check we are running on an HS/EMU device type */
@@ -219,7 +251,8 @@ static void ft_hs_fixups(void *fdt, bd_t *bd)if ((ft_hs_fixup_crossbar (fdt, bd) ==0 ) && (ft_hs_disable_rng (fdt, bd) ==0 ) && (ft_hs_fixup_sram (fdt, bd) ==0 ) && - (ft_hs_fixup_dram (fdt, bd) ==0 )) + (ft_hs_fixup_dram (fdt, bd) ==0 ) && + (ft_hs_add_tee (fdt, bd) ==0 ))return ; }else {printf ("ERROR: Incorrect device type (GP) detected!" );
Signature · 1 line
2.10.2
PATCH v3 5/7 arm: omap5: Add OPTEE node to fdt
Quoted 4 lines · Andrew F. Davis
Add an OPTEE node to the FDT when TEE installation has completed successfully. This informs the kernel of the presence of OPTEE.
Signed-off-by Andrew F. Davis <[email protected]>
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161130/85257524/attachment.sig>
PATCH v3 5/7 arm: omap5: Add OPTEE node to fdt
In reply to Andrew F. DavisQuoted 5 lines · Andrew F. Davis
Add an OPTEE node to the FDT when TEE installation has completed successfully. This informs the kernel of the presence of OPTEE.
Signed-off-by Andrew F. Davis <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161203/9f13964a/attachment.sig>
PATCH v3 6/7 board: ti: dra7xx: add FIT image TEE processing
In reply to Andrew F. DavisPopulate the corresponding TEE image processing call to be performed during FIT loadable processing.
--- board/ti/dra7xx/evm.c | 7 +++++++ 1 file changed, 7 insertions(+)
board/ti/dra7xx/evm.c +7 -0
@@ -848,4 +848,11 @@ void board_fit_image_post_process(void **p_image, size_t *p_size) {secure_boot_verify_image (p_image, p_size); } + +void board_tee_image_process (ulong tee_image,size_t tee_size) +{ +secure_tee_install ((u32 )tee_image); +} + +U_BOOT_FIT_LOADABLE_HANDLER (IH_TYPE_TEE , board_tee_image_process);#endif
Signature · 1 line
2.10.2
PATCH v3 6/7 board: ti: dra7xx: add FIT image TEE processing
Quoted 6 lines · Andrew F. Davis
Populate the corresponding TEE image processing call to be performed during FIT loadable processing.
Signed-off-by Andrew F. Davis <[email protected]>Reviewed-by Simon Glass <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161203/23d9e6e1/attachment.sig>
PATCH v3 7/7 board: ti: am57xx: add FIT image TEE processing
In reply to Andrew F. DavisPopulate the corresponding TEE image processing call to be performed during FIT loadable processing.
--- board/ti/am57xx/board.c | 7 +++++++ 1 file changed, 7 insertions(+)
board/ti/am57xx/board.c +7 -0
@@ -739,4 +739,11 @@ void board_fit_image_post_process(void **p_image, size_t *p_size) {secure_boot_verify_image (p_image, p_size); } + +void board_tee_image_process (ulong tee_image,size_t tee_size) +{ +secure_tee_install ((u32 )tee_image); +} + +U_BOOT_FIT_LOADABLE_HANDLER (IH_TYPE_TEE , board_tee_image_process);#endif
Signature · 1 line
2.10.2
PATCH v3 7/7 board: ti: am57xx: add FIT image TEE processing
Quoted 5 lines · Andrew F. Davis
Populate the corresponding TEE image processing call to be performed during FIT loadable processing.
Signed-off-by Andrew F. Davis <[email protected]>Reviewed-by Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20161203/3bd45ca4/attachment.sig>