mach-snapdragon: Enable OP-TEE support
Subsystems (4)
Sumit Garg
reviewerv2 cover mach-snapdragon: Enable OP-TEE support
From: Sumit Garg <[email protected]>
Introduce TF-A and OP-TEE config fragment
Recently upstream TF-A/OP-TEE has started gaining support for Qcom platforms. RB3Gen2 being the first one and more to come. U-Boot in corresponding boot flow is packaged as a position independent executable.
So, lets add a generic U-Boot config fragment for Qcom platforms to support TF-A/OP-TEE based TrustZone stack. Build command:
$ ./scripts/kconfig/merge_config.sh \
configs/qcom_defconfig \
board/qualcomm/tfa-optee.config
$ make -j`nproc` DEVICE_TREE=qcom/qcs6490-rb3gen2---
Changes in v2:
- Add new patch #1 to export OP-TEE message UID check API
- Use OP-TEE message UID check API in order to perform the DT fixup for OP-TEE.
- Switch from new defconfig to a config fragment instead.
Sumit Garg (3):
tee: optee: Export OP-TEE message UID check API
mach-snapdragon: of_fixup: Add OP-TEE DT fixup support board/qualcomm: Introduce TF-A and OP-TEE config fragment
arch/arm/mach-snapdragon/of_fixup.c | 35 +++++++++++++++++++++++++++++ board/qualcomm/tfa-optee.config | 4 ++++ drivers/tee/optee/core.c | 5 +++++ include/tee/optee.h | 9 ++++++++ 4 files changed, 53 insertions(+) create mode 100644 board/qualcomm/tfa-optee.config
Signature · 1 line
2.51.0
Sumit Garg
reviewerPATCH v2 1/3 tee: optee: Export OP-TEE message UID check API
From: Sumit Garg <[email protected]>
OP-TEE message UID check API can be useful to know whether OP-TEE is enabled on not assuming the corresponding SMC call is properly handled if OP-TEE is not supported.
This API can be used by platform code to know OP-TEE presence and on that basis OP-TEE DT node can be added as part of DT fixups for the OP-TEE driver probe to happen for both U-Boot and Linux.
--- drivers/tee/optee/core.c | 5 +++++ include/tee/optee.h | 9 +++++++++ 2 files changed, 14 insertions(+)
drivers/tee/optee/core.c +5 -0
@@ -795,6 +795,11 @@ static optee_invoke_fn *get_invoke_func(struct udevice *dev)return ERR_PTR (-EINVAL ); } +bool is_optee_smc_api (void ) +{ +return is_optee_api (optee_smccc_smc); +} +static int optee_of_to_plat (struct udevice *dev) {struct optee_pdata *pdata =dev_get_plat (dev);
include/tee/optee.h +9 -0
@@ -65,4 +65,13 @@ static inline int optee_copy_fdt_nodes(void *new_blob) }#endif +#if defined(CONFIG_OPTEE ) +bool is_optee_smc_api (void ); +#else +static inline bool is_optee_smc_api (void ) +{ +return false; +} +#endif +#endif /* _OPTEE_H */
Signature · 1 line
2.51.0
Sumit Garg
reviewerPATCH v2 2/3 mach-snapdragon: of_fixup: Add OP-TEE DT fixup support
In reply to Sumit GargFrom: Sumit Garg <[email protected]>
Add support for OP-TEE live tree DT fixup support which enables U-Boot OP-TEE driver to be probed. As well as the EFI DT fixup protocol allows the live tree fixup to be carried over to the OS for the OP-TEE driver in the OS to probe as well.
Note that this fixup only gets applied if OP-TEE support is detected via checking for OP-TEE message UID.
--- arch/arm/mach-snapdragon/of_fixup.c | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
arch/arm/mach-snapdragon/of_fixup.c +35 -0
@@ -25,6 +25,7 @@#include <fdt_support.h> #include <linux/errno.h> #include <stdlib.h> +#include <tee/optee.h> #include <time.h> /* U-Boot only supports USB high-speed mode on Qualcomm platforms with DWC3
@@ -164,6 +165,37 @@ static void fixup_power_domains(struct device_node *root) } } +static void add_optee_node (struct device_node *root) +{ +struct device_node *fw =NULL , *optee =NULL ; +int ret; + + fw =of_find_node_by_path ("/firmware" ); +if (!fw) { +log_err ("Failed to find /firmware node\n" ); +return ; + } + + ret =of_add_subnode (fw,"optee" ,strlen ("optee" ) +1 , &optee); +if (ret) { +log_err ("Failed to add 'maximum-speed' property: %d\n" , ret); +return ; + } + + ret =of_write_prop (optee,"compatible" ,strlen ("linaro,optee-tz" ) +1 , +"linaro,optee-tz" ); +if (ret) { +log_err ("Failed to optee 'compatible' property: %d\n" , ret); +return ; + } + + ret =of_write_prop (optee,"method" ,strlen ("smc" ) +1 ,"smc" ); +if (ret) { +log_err ("Failed to optee 'method' property: %d\n" , ret); +return ; + } +} +#define time_call (func, ...) \ do { \ u64 start = timer_get_us(); \
@@ -178,6 +210,9 @@ static int qcom_of_fixup_nodes(void * __maybe_unused ctx, struct event *event)time_call (fixup_usb_nodes, root);time_call (fixup_power_domains, root); +if (is_optee_smc_api ()) +time_call (add_optee_node, root); +return 0 ; }
Signature · 1 line
2.51.0
Sumit Garg
reviewerPATCH v2 3/3 board/qualcomm: Introduce TF-A and OP-TEE config fragment
In reply to Sumit GargFrom: Sumit Garg <[email protected]>
Recently upstream TF-A/OP-TEE has started gaining support for Qcom platforms. RB3Gen2 being the first one and more to come. U-Boot in corresponding boot flow is packaged as a position independent executable.
So, lets add a generic U-Boot config fragment for Qcom platforms to support TF-A/OP-TEE based TrustZone stack. Build command:
$ ./scripts/kconfig/merge_config.sh \
configs/qcom_defconfig \
board/qualcomm/tfa-optee.config
$ make -j`nproc` DEVICE_TREE=qcom/qcs6490-rb3gen2For more information refer here:
https://trustedfirmware-a.readthedocs.io/en/latest/plat/qti/rb3gen2.html
--- board/qualcomm/tfa-optee.config | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 board/qualcomm/tfa-optee.config
board/qualcomm/tfa-optee.config new file +4 -0
@@ -0,0 +1,4 @@ +# Enables support for TF-A based OP-TEE as the open +# source TrustZone stack on Qcom platforms +CONFIG_TEE=y +CONFIG_OPTEE=y
Signature · 1 line
2.51.0
Re: [PATCH v2 2/3] mach-snapdragon: of_fixup: Add OP-TEE DT fixup support
In reply to Sumit GargQuoted 35 lines · Sumit Garg
From: Sumit Garg <[email protected]>
Add support for OP-TEE live tree DT fixup support which enables U-Boot OP-TEE driver to be probed. As well as the EFI DT fixup protocol allows the live tree fixup to be carried over to the OS for the OP-TEE driver in the OS to probe as well.
Note that this fixup only gets applied if OP-TEE support is detected via checking for OP-TEE message UID.
Signed-off-by Sumit Garg <[email protected]>--- arch/arm/mach-snapdragon/of_fixup.c | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)arch/arm/mach-snapdragon/of_fixup.c +5
-0@@ -25,6 +25,7 @@#include <fdt_support.h> #include <linux/errno.h> #include <stdlib.h> +#include <tee/optee.h> #include <time.h> /* U-Boot only supports USB high-speed mode on Qualcomm platforms with DWC3 @@ -164,6 +165,37 @@ static void fixup_power_domains(struct device_node *root) } } +static void add_optee_node (struct device_node *root) +{ +struct device_node *fw =NULL , *optee =NULL ; +int ret;
arch/arm/mach-snapdragon/of_fixup.c static void fixup_power_domains(struct device_node *root) · line 181
Quoted 10 lines
arch/arm/mach-snapdragon/of_fixup.c +10
-0+ + fw =of_find_node_by_path ("/firmware" ); +if (!fw) { +log_err ("Failed to find /firmware node\n" ); +return ; + } + + ret =of_add_subnode (fw,"optee" ,strlen ("optee" ) +1 , &optee); +if (ret) { +log_err ("Failed to add 'maximum-speed' property: %d\n" , ret);
Failed to add 'optee' subnode??
arch/arm/mach-snapdragon/of_fixup.c static void fixup_power_domains(struct device_node *root) · line 188
Quoted 7 lines
arch/arm/mach-snapdragon/of_fixup.c +7
-0+return ; + } + + ret =of_write_prop (optee,"compatible" ,strlen ("linaro,optee-tz" ) +1 , +"linaro,optee-tz" ); +if (ret) { +log_err ("Failed to optee 'compatible' property: %d\n" , ret);
s/to optee/to add/
arch/arm/mach-snapdragon/of_fixup.c static void fixup_power_domains(struct device_node *root) · line 194
Quoted 6 lines
arch/arm/mach-snapdragon/of_fixup.c +6
-0+return ; + } + + ret =of_write_prop (optee,"method" ,strlen ("smc" ) +1 ,"smc" ); +if (ret) { +log_err ("Failed to optee 'method' property: %d\n" , ret);
s/to optee/to add/
arch/arm/mach-snapdragon/of_fixup.c static void fixup_power_domains(struct device_node *root) · line 183
Quoted 3 lines
arch/arm/mach-snapdragon/of_fixup.c +3
-0+return ; + } +}
Not sure if add_optee_node() should be wrapped within #ifdef CONFIG_OPTEE, due to size concerns.
-Varada
Quoted 17 lines
arch/arm/mach-snapdragon/of_fixup.c +4
-1+#define time_call (func, ...) \ do { \ u64 start = timer_get_us(); \@@ -178,6 +210,9 @@ static int qcom_of_fixup_nodes(void * __maybe_unused ctx, struct event *event)time_call (fixup_usb_nodes, root);time_call (fixup_power_domains, root); +if (is_optee_smc_api ()) +time_call (add_optee_node, root); +return 0 ; } --2.51.0
Sumit Garg
reviewerRe: [PATCH v2 2/3] mach-snapdragon: of_fixup: Add OP-TEE DT fixup support
Quoted 32 lines · Varadarajan Narayanan
Quoted 31 lines · Sumit Garg
From: Sumit Garg <[email protected]>
Add support for OP-TEE live tree DT fixup support which enables U-Boot OP-TEE driver to be probed. As well as the EFI DT fixup protocol allows the live tree fixup to be carried over to the OS for the OP-TEE driver in the OS to probe as well.
Note that this fixup only gets applied if OP-TEE support is detected via checking for OP-TEE message UID.
Signed-off-by Sumit Garg <[email protected]>--- arch/arm/mach-snapdragon/of_fixup.c | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)arch/arm/mach-snapdragon/of_fixup.c +1
-0@@ -25,6 +25,7 @@#include <fdt_support.h> #include <linux/errno.h> #include <stdlib.h> +#include <tee/optee.h> #include <time.h> /* U-Boot only supports USB high-speed mode on Qualcomm platforms with DWC3 @@ -164,6 +165,37 @@ static void fixup_power_domains(struct device_node *root) } }
Quoted 16 lines
Quoted 4 lines
arch/arm/mach-snapdragon/of_fixup.c +4
-0+static void add_optee_node (struct device_node *root) +{ +struct device_node *fw =NULL , *optee =NULL ; +int ret;arch/arm/mach-snapdragon/of_fixup.c static void fixup_power_domains(struct device_node *root) · line 181
Quoted 10 lines
arch/arm/mach-snapdragon/of_fixup.c +10
-0+ + fw =of_find_node_by_path ("/firmware" ); +if (!fw) { +log_err ("Failed to find /firmware node\n" ); +return ; + } + + ret =of_add_subnode (fw,"optee" ,strlen ("optee" ) +1 , &optee); +if (ret) { +log_err ("Failed to add 'maximum-speed' property: %d\n" , ret);Failed to add 'optee' subnode??
Ack
Quoted 11 lines
arch/arm/mach-snapdragon/of_fixup.c static void fixup_power_domains(struct device_node *root) · line 188
Quoted 8 lines
arch/arm/mach-snapdragon/of_fixup.c +7
-0+return ; + } + + ret =of_write_prop (optee,"compatible" ,strlen ("linaro,optee-tz" ) +1 , +"linaro,optee-tz" ); +if (ret) { +log_err ("Failed to optee 'compatible' property: %d\n" , ret);s/to optee/to add/
Ack
Quoted 9 lines
arch/arm/mach-snapdragon/of_fixup.c static void fixup_power_domains(struct device_node *root) · line 194
Quoted 6 lines
arch/arm/mach-snapdragon/of_fixup.c +6
-0+return ; + } + + ret =of_write_prop (optee,"method" ,strlen ("smc" ) +1 ,"smc" ); +if (ret) { +log_err ("Failed to optee 'method' property: %d\n" , ret);s/to optee/to add/
Ack
Quoted 6 lines
arch/arm/mach-snapdragon/of_fixup.c static void fixup_power_domains(struct device_node *root) · line 183
Quoted 3 lines
arch/arm/mach-snapdragon/of_fixup.c +3
-0+return ; + } +}Not sure if
add_optee_node()should be wrapped within #ifdefCONFIG_OPTEE, due to size concerns.
Since on Qcom platforms we intend to support generic board code where we don't have particular size contrains as of now, so it should be fine to leave it as it is.
-Sumit
Quoted 20 lines
-Varada
Quoted 17 lines
arch/arm/mach-snapdragon/of_fixup.c +4
-1+#define time_call (func, ...) \ do { \ u64 start = timer_get_us(); \@@ -178,6 +210,9 @@ static int qcom_of_fixup_nodes(void * __maybe_unused ctx, struct event *event)time_call (fixup_usb_nodes, root);time_call (fixup_power_domains, root); +if (is_optee_smc_api ()) +time_call (add_optee_node, root); +return 0 ; } --2.51.0
Re: [PATCH v2 2/3] mach-snapdragon: of_fixup: Add OP-TEE DT fixup support
In reply to Sumit GargQuoted 66 lines · Sumit Garg
From: Sumit Garg <[email protected]>
Add support for OP-TEE live tree DT fixup support which enables U-Boot OP-TEE driver to be probed. As well as the EFI DT fixup protocol allows the live tree fixup to be carried over to the OS for the OP-TEE driver in the OS to probe as well.
Note that this fixup only gets applied if OP-TEE support is detected via checking for OP-TEE message UID.
Signed-off-by Sumit Garg <[email protected]>--- arch/arm/mach-snapdragon/of_fixup.c | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)arch/arm/mach-snapdragon/of_fixup.c +32
-0@@ -25,6 +25,7 @@#include <fdt_support.h> #include <linux/errno.h> #include <stdlib.h> +#include <tee/optee.h> #include <time.h> /* U-Boot only supports USB high-speed mode on Qualcomm platforms with DWC3 @@ -164,6 +165,37 @@ static void fixup_power_domains(struct device_node *root) } } +static void add_optee_node (struct device_node *root) +{ +struct device_node *fw =NULL , *optee =NULL ; +int ret; + + fw =of_find_node_by_path ("/firmware" ); +if (!fw) { +log_err ("Failed to find /firmware node\n" ); +return ; + } + + ret =of_add_subnode (fw,"optee" ,strlen ("optee" ) +1 , &optee); +if (ret) { +log_err ("Failed to add 'maximum-speed' property: %d\n" , ret); +return ; + } + + ret =of_write_prop (optee,"compatible" ,strlen ("linaro,optee-tz" ) +1 , +"linaro,optee-tz" ); +if (ret) { +log_err ("Failed to optee 'compatible' property: %d\n" , ret); +return ; + } + + ret =of_write_prop (optee,"method" ,strlen ("smc" ) +1 ,"smc" ); +if (ret) { +log_err ("Failed to optee 'method' property: %d\n" , ret); +return ; + } +} +#define time_call (func, ...) \ do { \ u64 start = timer_get_us(); \
arch/arm/mach-snapdragon/of_fixup.c static int qcom_of_fixup_nodes(void * __maybe_unused ctx, struct event *event) · line 214
Quoted 5 lines
arch/arm/mach-snapdragon/of_fixup.c +2
-0@@ -178,6 +210,9 @@ static int qcom_of_fixup_nodes(void * __maybe_unused ctx, struct event *event)time_call (fixup_usb_nodes, root);time_call (fixup_power_domains, root); +if (is_optee_smc_api ()) +time_call (add_optee_node, root);
Since is_optee_smc_api only returns false when CONFIG_OPTEE is disabled, the compiler should drop this, but to help it optimize you should replace with:
if (IS_ENABLED(CONFIG_OPTEE) && is_optee_smc_api()) time_call(add_optee_node, root);
Thanks,
Neil
Quoted 4 lines
arch/arm/mach-snapdragon/of_fixup.c +1
-0+return 0 ; }
Sumit Garg
reviewerRe: [PATCH v2 2/3] mach-snapdragon: of_fixup: Add OP-TEE DT fixup support
Quoted 72 lines · On Fri, Jan 23, 2026 at 11:11:45AM +0100, [email protected] wrote:
Quoted 64 lines · Sumit Garg
From: Sumit Garg <[email protected]>
Add support for OP-TEE live tree DT fixup support which enables U-Boot OP-TEE driver to be probed. As well as the EFI DT fixup protocol allows the live tree fixup to be carried over to the OS for the OP-TEE driver in the OS to probe as well.
Note that this fixup only gets applied if OP-TEE support is detected via checking for OP-TEE message UID.
Signed-off-by Sumit Garg <[email protected]>--- arch/arm/mach-snapdragon/of_fixup.c | 35 +++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)arch/arm/mach-snapdragon/of_fixup.c +32
-0@@ -25,6 +25,7 @@#include <fdt_support.h> #include <linux/errno.h> #include <stdlib.h> +#include <tee/optee.h> #include <time.h> /* U-Boot only supports USB high-speed mode on Qualcomm platforms with DWC3 @@ -164,6 +165,37 @@ static void fixup_power_domains(struct device_node *root) } } +static void add_optee_node (struct device_node *root) +{ +struct device_node *fw =NULL , *optee =NULL ; +int ret; + + fw =of_find_node_by_path ("/firmware" ); +if (!fw) { +log_err ("Failed to find /firmware node\n" ); +return ; + } + + ret =of_add_subnode (fw,"optee" ,strlen ("optee" ) +1 , &optee); +if (ret) { +log_err ("Failed to add 'maximum-speed' property: %d\n" , ret); +return ; + } + + ret =of_write_prop (optee,"compatible" ,strlen ("linaro,optee-tz" ) +1 , +"linaro,optee-tz" ); +if (ret) { +log_err ("Failed to optee 'compatible' property: %d\n" , ret); +return ; + } + + ret =of_write_prop (optee,"method" ,strlen ("smc" ) +1 ,"smc" ); +if (ret) { +log_err ("Failed to optee 'method' property: %d\n" , ret); +return ; + } +} +#define time_call (func, ...) \ do { \ u64 start = timer_get_us(); \arch/arm/mach-snapdragon/of_fixup.c static int qcom_of_fixup_nodes(void * __maybe_unused ctx, struct event *event) · line 213
Quoted 4 lines
arch/arm/mach-snapdragon/of_fixup.c +2
-0@@ -178,6 +210,9 @@ static int qcom_of_fixup_nodes(void * __maybe_unused ctx, struct event *event)time_call (fixup_usb_nodes, root);time_call (fixup_power_domains, root); +if (is_optee_smc_api ()) +time_call (add_optee_node, root);Since
is_optee_smc_apionly returns false whenCONFIG_OPTEEis disabled, the compiler should drop this, but to help it optimize you should replace with:
Quoted 2 lines
if (IS_ENABLED(CONFIG_OPTEE) && is_optee_smc_api()) time_call(add_optee_node, root);
Sure, I will do that for v3.
-Sumit