From 51827f9a8be3def01b837a2809094e2fd2703b6a Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Thu, 2 Sep 2021 11:56:16 +0200 Subject: lib: optee: remove the duplicate CONFIG_OPTEE The configuration CONFIG_OPTEE is defined 2 times: 1- in lib/optee/Kconfig for support of OPTEE images loaded by bootm command 2- in drivers/tee/optee/Kconfig for support of OP-TEE driver. It is abnormal to have the same CONFIG define for 2 purpose; and it is difficult to managed correctly their dependencies. Moreover CONFIG_SPL_OPTEE is defined in common/spl/Kconfig to manage OPTEE image load in SPL. This definition causes an issue with the macro CONFIG_IS_ENABLED(OPTEE) to test the availability of the OP-TEE driver. This patch cleans the configuration dependency with: - CONFIG_OPTEE_IMAGE (renamed) => support of OP-TEE image in U-Boot - CONFIG_SPL_OPTEE_IMAGE (renamed) => support of OP-TEE image in SPL - CONFIG_OPTEE (same) => support of OP-TEE driver in U-Boot - CONFIG_OPTEE_LIB (new) => support of OP-TEE library After this patch, the macro have the correct behavior: - CONFIG_IS_ENABLED(OPTEE_IMAGE) => Load of OP-TEE image is supported - CONFIG_IS_ENABLED(OPTEE) => OP-TEE driver is supported Signed-off-by: Patrick Delaunay --- include/tee/optee.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/tee/optee.h b/include/tee/optee.h index ebdfe5e98d7..2928597b61f 100644 --- a/include/tee/optee.h +++ b/include/tee/optee.h @@ -43,7 +43,7 @@ optee_image_get_load_addr(const struct image_header *hdr) return optee_image_get_entry_point(hdr) - sizeof(struct optee_header); } -#if defined(CONFIG_OPTEE) +#if defined(CONFIG_OPTEE_IMAGE) int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start, unsigned long tzdram_len, unsigned long image_len); #else @@ -57,7 +57,7 @@ static inline int optee_verify_image(struct optee_header *hdr, #endif -#if defined(CONFIG_OPTEE) +#if defined(CONFIG_OPTEE_IMAGE) int optee_verify_bootm_image(unsigned long image_addr, unsigned long image_load_addr, unsigned long image_len); @@ -70,7 +70,7 @@ static inline int optee_verify_bootm_image(unsigned long image_addr, } #endif -#if defined(CONFIG_OPTEE) && defined(CONFIG_OF_LIBFDT) +#if defined(CONFIG_OPTEE_LIB) && defined(CONFIG_OF_LIBFDT) int optee_copy_fdt_nodes(void *new_blob); #else static inline int optee_copy_fdt_nodes(void *new_blob) -- cgit v1.3.1 From 4f53ac2adbc0f4d3bfebee1b414870e228469989 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Thu, 2 Sep 2021 11:56:17 +0200 Subject: tee: add a stub for tee_find_device Add stub for tee_find_device function when CONFIG_TEE is not activated to simplify the caller code. This patch allows to remove the CONFIG_IS_ENABLED(OPTEE) tests for stm32 platform. Signed-off-by: Patrick Delaunay Acked-by: Etienne Carriere Reviewed-by: Jens Wiklander --- arch/arm/mach-stm32mp/fdt.c | 1 - board/st/common/stm32mp_mtdparts.c | 3 +-- include/tee.h | 11 +++++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/arch/arm/mach-stm32mp/fdt.c b/arch/arm/mach-stm32mp/fdt.c index a19e954cf7a..91330a68a49 100644 --- a/arch/arm/mach-stm32mp/fdt.c +++ b/arch/arm/mach-stm32mp/fdt.c @@ -341,7 +341,6 @@ int ft_system_setup(void *blob, struct bd_info *bd) * when FIP is not used by TF-A */ if (CONFIG_IS_ENABLED(STM32MP15x_STM32IMAGE) && - CONFIG_IS_ENABLED(OPTEE) && !tee_find_device(NULL, NULL, NULL, NULL)) stm32_fdt_disable_optee(blob); diff --git a/board/st/common/stm32mp_mtdparts.c b/board/st/common/stm32mp_mtdparts.c index 8b636d62faf..18878424c7a 100644 --- a/board/st/common/stm32mp_mtdparts.c +++ b/board/st/common/stm32mp_mtdparts.c @@ -119,8 +119,7 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) } #ifdef CONFIG_STM32MP15x_STM32IMAGE - if (!serial && CONFIG_IS_ENABLED(OPTEE) && - tee_find_device(NULL, NULL, NULL, NULL)) + if (!serial && tee_find_device(NULL, NULL, NULL, NULL)) tee = true; #endif diff --git a/include/tee.h b/include/tee.h index 2ef29bfc8fa..44e9cd4321b 100644 --- a/include/tee.h +++ b/include/tee.h @@ -307,11 +307,22 @@ bool tee_shm_is_registered(struct tee_shm *shm, struct udevice *dev); * Returns a probed TEE device of the first TEE device matched by the * match() callback or NULL. */ +#if CONFIG_IS_ENABLED(TEE) struct udevice *tee_find_device(struct udevice *start, int (*match)(struct tee_version_data *vers, const void *data), const void *data, struct tee_version_data *vers); +#else +static inline struct udevice *tee_find_device(struct udevice *start, + int (*match)(struct tee_version_data *vers, + const void *data), + const void *data, + struct tee_version_data *vers) +{ + return NULL; +} +#endif /** * tee_get_version() - Query capabilities of TEE device -- cgit v1.3.1 From 26fc66709c0de7732a12fd59dbce5a83eb454bae Mon Sep 17 00:00:00 2001 From: Alexandru Gagniuc Date: Tue, 7 Sep 2021 12:07:06 -0500 Subject: lib: optee: Avoid CONFIG_TZDRAM_* in optee_verify_bootm_image() The configs TZDRAM_BASE and TZDRAM_SIZE are expected to describe the memory allocated to the OPTEE region. according to according to commit c5a6e8bd00cc ("optee: Add optee_verify_bootm_image()"). The TZDRAM is with some limitations, described by "/reserved-memory" nodes in the devicetree. Consequently TZDRAM_BASE and TZDRAM_SIZE can point to imaginary regions which have nothing to do with actual DRAM. They are not used to configure the hardware or set up the Trust Zone Controller (TZC) for OP-TEE -- the devicetree values are used instead. When a valid OP-TEE image does not fall within the region described by these configs, u-boot will refuse to load it. In fact, it mostly serves to cause "bootm" to reject perfectly good OP-TEE images. Ironically, someone has to correctly configure the devicetree for TZDRAM, then go back and enter the same information in Kconfig for "bootm". To remedy this, do not use TZDRAM_BASE and TZDRAM_SIZE in the verification of OPTEE images. Signed-off-by: Alexandru Gagniuc --- include/tee/optee.h | 14 -------------- lib/optee/optee.c | 21 ++++++--------------- 2 files changed, 6 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/tee/optee.h b/include/tee/optee.h index 2928597b61f..5412bc7386e 100644 --- a/include/tee/optee.h +++ b/include/tee/optee.h @@ -43,20 +43,6 @@ optee_image_get_load_addr(const struct image_header *hdr) return optee_image_get_entry_point(hdr) - sizeof(struct optee_header); } -#if defined(CONFIG_OPTEE_IMAGE) -int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start, - unsigned long tzdram_len, unsigned long image_len); -#else -static inline int optee_verify_image(struct optee_header *hdr, - unsigned long tzdram_start, - unsigned long tzdram_len, - unsigned long image_len) -{ - return -EPERM; -} - -#endif - #if defined(CONFIG_OPTEE_IMAGE) int optee_verify_bootm_image(unsigned long image_addr, unsigned long image_load_addr, diff --git a/lib/optee/optee.c b/lib/optee/optee.c index 5676785cb56..766d0d9e3fa 100644 --- a/lib/optee/optee.c +++ b/lib/optee/optee.c @@ -16,15 +16,13 @@ #define optee_hdr_err_msg \ "OPTEE verification error:" \ - "\n\thdr=%p image=0x%08lx magic=0x%08x tzdram 0x%08lx-0x%08lx " \ + "\n\thdr=%p image=0x%08lx magic=0x%08x" \ "\n\theader lo=0x%08x hi=0x%08x size=0x%08lx arch=0x%08x" \ "\n\tuimage params 0x%08lx-0x%08lx\n" #if defined(CONFIG_OPTEE_IMAGE) -int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start, - unsigned long tzdram_len, unsigned long image_len) +static int optee_verify_image(struct optee_header *hdr, unsigned long image_len) { - unsigned long tzdram_end = tzdram_start + tzdram_len; uint32_t tee_file_size; tee_file_size = hdr->init_size + hdr->paged_size + @@ -32,11 +30,7 @@ int optee_verify_image(struct optee_header *hdr, unsigned long tzdram_start, if (hdr->magic != OPTEE_MAGIC || hdr->version != OPTEE_VERSION || - hdr->init_load_addr_hi > tzdram_end || - hdr->init_load_addr_lo < tzdram_start || - tee_file_size > tzdram_len || - tee_file_size != image_len || - (hdr->init_load_addr_lo + tee_file_size) > tzdram_end) { + tee_file_size != image_len) { return -EINVAL; } @@ -48,12 +42,9 @@ int optee_verify_bootm_image(unsigned long image_addr, unsigned long image_len) { struct optee_header *hdr = (struct optee_header *)image_addr; - unsigned long tzdram_start = CONFIG_OPTEE_TZDRAM_BASE; - unsigned long tzdram_len = CONFIG_OPTEE_TZDRAM_SIZE; - int ret; - ret = optee_verify_image(hdr, tzdram_start, tzdram_len, image_len); + ret = optee_verify_image(hdr, image_len); if (ret) goto error; @@ -64,8 +55,8 @@ int optee_verify_bootm_image(unsigned long image_addr, return ret; error: - printf(optee_hdr_err_msg, hdr, image_addr, hdr->magic, tzdram_start, - tzdram_start + tzdram_len, hdr->init_load_addr_lo, + printf(optee_hdr_err_msg, hdr, image_addr, hdr->magic, + hdr->init_load_addr_lo, hdr->init_load_addr_hi, image_len, hdr->arch, image_load_addr, image_load_addr + image_len); -- cgit v1.3.1 From f6953047cb99d50cca0dc73740337b08fbdc1bf8 Mon Sep 17 00:00:00 2001 From: Alexandru Gagniuc Date: Tue, 7 Sep 2021 12:07:08 -0500 Subject: lib: optee: Remove CONFIG_OPTEE_LOAD_ADDR This value is not used by u-boot, and it should not. The load address of an OPTEE image is defined by said image. Either a uImage or a FIT will have a defined load address and entry point. Those values are the correct ones, not CONFIG_OPTEE_LOAD_ADDR. Commit f25006b96e9f ("optee: Add CONFIG_OPTEE_LOAD_ADDR") justifies this config by requiring its presence in u-boot's .config for other images as part of a larger build, claiming it is "the best way". This argument is not persuasive. U-boot's configuration is driven by platform requirements, not the other way around. It seems more likely that the argument is conflating tooling issues with Kconfig. Yocto and buildroot have excellent mechanisms for defining values across the board (pun intended). u-boot's Kconfig is the wrong place to do it. Furthermore, it is not "best" for u-boot because it hardcodes a value which is then not used. In fact the load address that u-boot uses is the one derived from the OPTEE image. Confused yet? I sure was. To prevent future confusion, remove CONFIG_OPTEE_LOAD_ADDR. Signed-off-by: Alexandru Gagniuc --- configs/warp7_defconfig | 1 - include/configs/warp7.h | 5 ----- lib/optee/Kconfig | 7 ------- 3 files changed, 13 deletions(-) (limited to 'include') diff --git a/configs/warp7_defconfig b/configs/warp7_defconfig index 27529dd9916..db8d4f625a2 100644 --- a/configs/warp7_defconfig +++ b/configs/warp7_defconfig @@ -73,6 +73,5 @@ CONFIG_USB_GADGET_DOWNLOAD=y CONFIG_USB_ETHER=y CONFIG_USB_ETH_CDC=y CONFIG_USBNET_HOST_ADDR="de:ad:be:af:00:00" -CONFIG_OPTEE_LOAD_ADDR=0x84000000 CONFIG_OPTEE_TZDRAM_SIZE=0x3000000 CONFIG_BOOTM_OPTEE=y diff --git a/include/configs/warp7.h b/include/configs/warp7.h index 0822eaf5557..74fb988b765 100644 --- a/include/configs/warp7.h +++ b/include/configs/warp7.h @@ -28,10 +28,6 @@ #define BOOT_SCR_STRING "source ${bootscriptaddr}\0" #endif -#ifndef CONFIG_OPTEE_LOAD_ADDR -#define CONFIG_OPTEE_LOAD_ADDR 0 -#endif - #define CONFIG_EXTRA_ENV_SETTINGS \ CONFIG_DFU_ENV_SETTINGS \ "script=boot.scr\0" \ @@ -46,7 +42,6 @@ "fdt_file=imx7s-warp.dtb\0" \ "fdt_addr=" __stringify(CONFIG_SYS_FDT_ADDR)"\0" \ "fdtovaddr=0x83100000\0" \ - "optee_addr=" __stringify(CONFIG_OPTEE_LOAD_ADDR)"\0" \ "boot_fdt=try\0" \ "ip_dyn=yes\0" \ "mmcdev="__stringify(CONFIG_SYS_MMC_ENV_DEV)"\0" \ diff --git a/lib/optee/Kconfig b/lib/optee/Kconfig index 3f8ce49678e..e6834d4d3e1 100644 --- a/lib/optee/Kconfig +++ b/lib/optee/Kconfig @@ -11,13 +11,6 @@ config OPTEE_IMAGE This option enable the OPTEE specific checks done before booting an OPTEE image created with mkimage -config OPTEE_LOAD_ADDR - hex "OPTEE load address" - default 0x00000000 - depends on OPTEE_LIB - help - The load address of the bootable OPTEE binary. - config OPTEE_TZDRAM_SIZE hex "Amount of Trust-Zone RAM for the OPTEE image" default 0x0000000 -- cgit v1.3.1 From 8a47982ed8d40595a83b82b2298753873e597708 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Sat, 11 Sep 2021 17:05:53 -0500 Subject: gpio: Factor out DT flag translation The generic GPIO flags binding is shared across many drivers, some of which need their own xlate function. Factor out the flag translation code from gpio_xlate_offs_flags so it does not need to be duplicated. Signed-off-by: Samuel Holland Reviewed-by: Simon Glass --- drivers/gpio/gpio-uclass.c | 50 +++++++++++++++++++++++++++------------------- include/asm-generic/gpio.h | 8 ++++++++ 2 files changed, 37 insertions(+), 21 deletions(-) (limited to 'include') diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index fde046e8df8..1c5e2e79766 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -186,6 +186,34 @@ int gpio_lookup_name(const char *name, struct udevice **devp, return 0; } +unsigned long gpio_flags_xlate(uint32_t arg) +{ + unsigned long flags = 0; + + if (arg & GPIO_ACTIVE_LOW) + flags |= GPIOD_ACTIVE_LOW; + + /* + * need to test 2 bits for gpio output binding: + * OPEN_DRAIN (0x6) = SINGLE_ENDED (0x2) | LINE_OPEN_DRAIN (0x4) + * OPEN_SOURCE (0x2) = SINGLE_ENDED (0x2) | LINE_OPEN_SOURCE (0x0) + */ + if (arg & GPIO_SINGLE_ENDED) { + if (arg & GPIO_LINE_OPEN_DRAIN) + flags |= GPIOD_OPEN_DRAIN; + else + flags |= GPIOD_OPEN_SOURCE; + } + + if (arg & GPIO_PULL_UP) + flags |= GPIOD_PULL_UP; + + if (arg & GPIO_PULL_DOWN) + flags |= GPIOD_PULL_DOWN; + + return flags; +} + int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc, struct ofnode_phandle_args *args) { @@ -201,27 +229,7 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc, if (args->args_count < 2) return 0; - desc->flags = 0; - if (args->args[1] & GPIO_ACTIVE_LOW) - desc->flags |= GPIOD_ACTIVE_LOW; - - /* - * need to test 2 bits for gpio output binding: - * OPEN_DRAIN (0x6) = SINGLE_ENDED (0x2) | LINE_OPEN_DRAIN (0x4) - * OPEN_SOURCE (0x2) = SINGLE_ENDED (0x2) | LINE_OPEN_SOURCE (0x0) - */ - if (args->args[1] & GPIO_SINGLE_ENDED) { - if (args->args[1] & GPIO_LINE_OPEN_DRAIN) - desc->flags |= GPIOD_OPEN_DRAIN; - else - desc->flags |= GPIOD_OPEN_SOURCE; - } - - if (args->args[1] & GPIO_PULL_UP) - desc->flags |= GPIOD_PULL_UP; - - if (args->args[1] & GPIO_PULL_DOWN) - desc->flags |= GPIOD_PULL_DOWN; + desc->flags = gpio_flags_xlate(args->args[1]); return 0; } diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h index 6de13d925eb..fa9b80722ec 100644 --- a/include/asm-generic/gpio.h +++ b/include/asm-generic/gpio.h @@ -221,6 +221,14 @@ int gpio_requestf(unsigned gpio, const char *fmt, ...) struct fdtdec_phandle_args; +/** + * gpio_flags_xlate() - convert DT flags to internal flags + * + * This routine converts the GPIO_* flags from the generic DT binding to the + * GPIOD_* flags used internally. It can be called from driver xlate functions. + */ +unsigned long gpio_flags_xlate(uint32_t arg); + /** * gpio_xlate_offs_flags() - implementation for common use of dm_gpio_ops.xlate * -- cgit v1.3.1