optee: Add support for enumerating RPMB-dependent services
Subsystems (3)
v2 cover optee: Add support for enumerating RPMB-dependent services
This allows to find firmware TPM again with recent OP-TEE versions, possibly also other services. The StMM service was not affected because it is directly invoked by efi_variable_tee when needed, and that is late enough so that all dependencies are available by then.
See patches for further details.
Changes in v2:
- fix build breakages with disabled CONFIGs
- structure code differently between optee core and rpmb
- debug() -> dev_dbg()
Jan
Jan Kiszka (5):
tee: optee: Factor out service enumeration and binding functions
tee: optee: Add support for enumerating services that only need RPMB
tee: optee: Do not warn about TEE_ERROR_STORAGE_NOT_AVAILABLE
mmc: Call back to optee after a successful mmc_init
mmc: Make "MMC Device not found" a debug output
drivers/mmc/mmc-uclass.c | 2 +- drivers/mmc/mmc.c | 4 +++ drivers/mmc/mmc_legacy.c | 2 +- drivers/tee/optee/core.c | 58 +++++++++++++++---------------- drivers/tee/optee/optee_private.h | 24 +++++++++++++ drivers/tee/optee/rpmb.c | 19 ++++++++++ include/tee/optee.h | 6 ++++ 7 files changed, 83 insertions(+), 32 deletions(-)
Signature · 1 line
2.47.3
PATCH v2 1/5 tee: optee: Factor out service enumeration and binding functions
From: Jan Kiszka <[email protected]>
This already avoids code duplication between the different enumeration commands. It will furthermore allow to implement a third one for services with RPMB needs.
--- drivers/tee/optee/core.c | 33 +++++++++++++++++-------------- drivers/tee/optee/optee_private.h | 3 +++ 2 files changed, 21 insertions(+), 15 deletions(-)
drivers/tee/optee/core.c +18 -15
@@ -156,7 +156,7 @@ static int enum_services(struct udevice *dev, struct tee_shm **shm, size_t *counreturn ret; } -static int open_enum_session (struct udevice *dev,u32 *tee_sess) +int optee_open_enum_session (struct udevice *dev,u32 *tee_sess) {const struct tee_optee_ta_uuid pta_uuid =PTA_DEVICE_ENUM ;struct tee_open_session_arg arg = { };
@@ -176,31 +176,34 @@ static int open_enum_session(struct udevice *dev, u32 *tee_sess)return 0 ; } -static int bind_service_drivers (struct udevice *dev) +int optee_bind_services (struct udevice *dev,u32 tee_sess, +unsigned int pta_cmd) {struct tee_shm *service_list =NULL ;size_t service_count; -u32 tee_sess; -int ret, ret2; - - ret =open_enum_session (dev, &tee_sess); -if (ret) -return ret; +int ret; ret =enum_services (dev, &service_list, &service_count, tee_sess, -PTA_CMD_GET_DEVICES ); + pta_cmd);if (!ret && service_count) ret =bind_service_list (dev, service_list, service_count);tee_shm_free (service_list); - service_list =NULL ; - ret2 =enum_services (dev, &service_list, &service_count, tee_sess, -PTA_CMD_GET_DEVICES_SUPP ); -if (!ret2 && service_count) - ret2 =bind_service_list (dev, service_list, service_count); +return ret; +} + +static int bind_service_drivers (struct udevice *dev) +{ +u32 tee_sess; +int ret, ret2; -tee_shm_free (service_list); + ret =optee_open_enum_session (dev, &tee_sess); +if (ret) +return ret; + + ret =optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES ); + ret2 =optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES_SUPP );tee_close_session (dev, tee_sess);
drivers/tee/optee/optee_private.h +3 -0
@@ -27,6 +27,9 @@ struct optee_msg_arg;void optee_suppl_cmd (struct udevice *dev,struct tee_shm *shm_arg,void **page_list); +int optee_open_enum_session (struct udevice *dev,u32 *tee_sess); +int optee_bind_services (struct udevice *dev,u32 tee_sess, +unsigned int pta_cmd);#ifdef CONFIG_SUPPORT_EMMC_RPMB /**
Signature · 1 line
2.47.3
Re: [PATCH v2 1/5] tee: optee: Factor out service enumeration and binding functions
Hi Jan
Quoted 60 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This already avoids code duplication between the different enumeration commands. It will furthermore allow to implement a third one for services with RPMB needs.
Signed-off-by Jan Kiszka <[email protected]>--- drivers/tee/optee/core.c | 33 +++++++++++++++++-------------- drivers/tee/optee/optee_private.h | 3 +++ 2 files changed, 21 insertions(+), 15 deletions(-)drivers/tee/optee/core.c +9
-14@@ -156,7 +156,7 @@ static int enum_services(struct udevice *dev, struct tee_shm **shm, size_t *counreturn ret; } -static int open_enum_session (struct udevice *dev,u32 *tee_sess) +int optee_open_enum_session (struct udevice *dev,u32 *tee_sess) {const struct tee_optee_ta_uuid pta_uuid =PTA_DEVICE_ENUM ;struct tee_open_session_arg arg = { };@@ -176,31 +176,34 @@ static int open_enum_session(struct udevice *dev, u32 *tee_sess)return 0 ; } -static int bind_service_drivers (struct udevice *dev) +int optee_bind_services (struct udevice *dev,u32 tee_sess, +unsigned int pta_cmd) {struct tee_shm *service_list =NULL ;size_t service_count; -u32 tee_sess; -int ret, ret2; - - ret =open_enum_session (dev, &tee_sess); -if (ret) -return ret; +int ret; ret =enum_services (dev, &service_list, &service_count, tee_sess, -PTA_CMD_GET_DEVICES ); + pta_cmd);if (!ret && service_count) ret =bind_service_list (dev, service_list, service_count);tee_shm_free (service_list); - service_list =NULL ; - ret2 =enum_services (dev, &service_list, &service_count, tee_sess, -PTA_CMD_GET_DEVICES_SUPP ); -if (!ret2 && service_count) - ret2 =bind_service_list (dev, service_list, service_count); +return ret; +} + +static int bind_service_drivers (struct udevice *dev)
drivers/tee/optee/core.c static int open_enum_session(struct udevice *dev, u32 *tee_sess) · line 205
Quoted 10 lines
drivers/tee/optee/core.c +8
-1+{ +u32 tee_sess; +int ret, ret2; -tee_shm_free (service_list); + ret =optee_open_enum_session (dev, &tee_sess); +if (ret) +return ret; + + ret =optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES );
Any reason we aren't exiting immediately here?
Quoted 9 lines
drivers/tee/optee/core.c +1
-0+ ret2 =optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES_SUPP );tee_close_session (dev, tee_sess);drivers/tee/optee/optee_private.h +0
-0
drivers/tee/optee/optee_private.h struct optee_msg_arg; · line 35
Quoted 9 lines
drivers/tee/optee/optee_private.h +3
-0@@ -27,6 +27,9 @@ struct optee_msg_arg;void optee_suppl_cmd (struct udevice *dev,struct tee_shm *shm_arg,void **page_list); +int optee_open_enum_session (struct udevice *dev,u32 *tee_sess); +int optee_bind_services (struct udevice *dev,u32 tee_sess, +unsigned int pta_cmd);#ifdef CONFIG_SUPPORT_EMMC_RPMB /**
Cheers
/Ilias
Re: [PATCH v2 1/5] tee: optee: Factor out service enumeration and binding functions
Quoted 68 lines · Ilias Apalodimas
Hi Jan
Quoted 64 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This already avoids code duplication between the different enumeration commands. It will furthermore allow to implement a third one for services with RPMB needs.
Signed-off-by Jan Kiszka <[email protected]>--- drivers/tee/optee/core.c | 33 +++++++++++++++++-------------- drivers/tee/optee/optee_private.h | 3 +++ 2 files changed, 21 insertions(+), 15 deletions(-)drivers/tee/optee/core.c +12
-14@@ -156,7 +156,7 @@ static int enum_services(struct udevice *dev, struct tee_shm **shm, size_t *counreturn ret; } -static int open_enum_session (struct udevice *dev,u32 *tee_sess) +int optee_open_enum_session (struct udevice *dev,u32 *tee_sess) {const struct tee_optee_ta_uuid pta_uuid =PTA_DEVICE_ENUM ;struct tee_open_session_arg arg = { };@@ -176,31 +176,34 @@ static int open_enum_session(struct udevice *dev, u32 *tee_sess)return 0 ; } -static int bind_service_drivers (struct udevice *dev) +int optee_bind_services (struct udevice *dev,u32 tee_sess, +unsigned int pta_cmd) {struct tee_shm *service_list =NULL ;size_t service_count; -u32 tee_sess; -int ret, ret2; - - ret =open_enum_session (dev, &tee_sess); -if (ret) -return ret; +int ret; ret =enum_services (dev, &service_list, &service_count, tee_sess, -PTA_CMD_GET_DEVICES ); + pta_cmd);if (!ret && service_count) ret =bind_service_list (dev, service_list, service_count);tee_shm_free (service_list); - service_list =NULL ; - ret2 =enum_services (dev, &service_list, &service_count, tee_sess, -PTA_CMD_GET_DEVICES_SUPP ); -if (!ret2 && service_count) - ret2 =bind_service_list (dev, service_list, service_count); +return ret; +} + +static int bind_service_drivers (struct udevice *dev) +{ +u32 tee_sess; +int ret, ret2;
Quoted 9 lines
drivers/tee/optee/core.c static int open_enum_session(struct udevice *dev, u32 *tee_sess) · line 205
Quoted 6 lines
drivers/tee/optee/core.c +5
-1-tee_shm_free (service_list); + ret =optee_open_enum_session (dev, &tee_sess); +if (ret) +return ret; + + ret =optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES );Any reason we aren't exiting immediately here?
Just maintained the pre-existing behavior. But I could do this as well:
ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES); if (ret == 0) ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_SUPP);
Simpler, in fact...
Jan
Quoted 21 lines
Quoted 9 lines
drivers/tee/optee/core.c +1
-0+ ret2 =optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES_SUPP );tee_close_session (dev, tee_sess);drivers/tee/optee/optee_private.h +0
-0drivers/tee/optee/optee_private.h struct optee_msg_arg; · line 35
Quoted 9 lines
drivers/tee/optee/optee_private.h +3
-0@@ -27,6 +27,9 @@ struct optee_msg_arg;void optee_suppl_cmd (struct udevice *dev,struct tee_shm *shm_arg,void **page_list); +int optee_open_enum_session (struct udevice *dev,u32 *tee_sess); +int optee_bind_services (struct udevice *dev,u32 tee_sess, +unsigned int pta_cmd);#ifdef CONFIG_SUPPORT_EMMC_RPMB /** Cheers
/Ilias
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Re: [PATCH v2 1/5] tee: optee: Factor out service enumeration and binding functions
Quoted 79 lines · Jan Kiszka
Quoted 68 lines · Ilias Apalodimas
Hi Jan
Quoted 64 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This already avoids code duplication between the different enumeration commands. It will furthermore allow to implement a third one for services with RPMB needs.
Signed-off-by Jan Kiszka <[email protected]>--- drivers/tee/optee/core.c | 33 +++++++++++++++++-------------- drivers/tee/optee/optee_private.h | 3 +++ 2 files changed, 21 insertions(+), 15 deletions(-)drivers/tee/optee/core.c +12
-14@@ -156,7 +156,7 @@ static int enum_services(struct udevice *dev, struct tee_shm **shm, size_t *counreturn ret; } -static int open_enum_session (struct udevice *dev,u32 *tee_sess) +int optee_open_enum_session (struct udevice *dev,u32 *tee_sess) {const struct tee_optee_ta_uuid pta_uuid =PTA_DEVICE_ENUM ;struct tee_open_session_arg arg = { };@@ -176,31 +176,34 @@ static int open_enum_session(struct udevice *dev, u32 *tee_sess)return 0 ; } -static int bind_service_drivers (struct udevice *dev) +int optee_bind_services (struct udevice *dev,u32 tee_sess, +unsigned int pta_cmd) {struct tee_shm *service_list =NULL ;size_t service_count; -u32 tee_sess; -int ret, ret2; - - ret =open_enum_session (dev, &tee_sess); -if (ret) -return ret; +int ret; ret =enum_services (dev, &service_list, &service_count, tee_sess, -PTA_CMD_GET_DEVICES ); + pta_cmd);if (!ret && service_count) ret =bind_service_list (dev, service_list, service_count);tee_shm_free (service_list); - service_list =NULL ; - ret2 =enum_services (dev, &service_list, &service_count, tee_sess, -PTA_CMD_GET_DEVICES_SUPP ); -if (!ret2 && service_count) - ret2 =bind_service_list (dev, service_list, service_count); +return ret; +} + +static int bind_service_drivers (struct udevice *dev) +{ +u32 tee_sess; +int ret, ret2;Quoted 9 lines
drivers/tee/optee/core.c static int open_enum_session(struct udevice *dev, u32 *tee_sess) · line 205
Quoted 6 lines
drivers/tee/optee/core.c +5
-1-tee_shm_free (service_list); + ret =optee_open_enum_session (dev, &tee_sess); +if (ret) +return ret; + + ret =optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES );Any reason we aren't exiting immediately here?
Quoted 9 lines
Just maintained the pre-existing behavior. But I could do this as well:
ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES); if (ret == 0) ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_SUPP);Simpler, in fact...
... but logically different: We only warn if any binding attempt fails, now we would not even attempt the other.
Key question is whether such an error scenario is possible at all, thus only PTA_CMD_GET_DEVICES fails but not PTA_CMD_GET_DEVICES_SUPP.
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Re: [PATCH v2 1/5] tee: optee: Factor out service enumeration and binding functions
Quoted 88 lines · Jan Kiszka
Quoted 86 lines · Jan Kiszka
Quoted 68 lines · Ilias Apalodimas
Hi Jan
Quoted 64 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This already avoids code duplication between the different enumeration commands. It will furthermore allow to implement a third one for services with RPMB needs.
Signed-off-by Jan Kiszka <[email protected]>--- drivers/tee/optee/core.c | 33 +++++++++++++++++-------------- drivers/tee/optee/optee_private.h | 3 +++ 2 files changed, 21 insertions(+), 15 deletions(-)drivers/tee/optee/core.c +12
-14@@ -156,7 +156,7 @@ static int enum_services(struct udevice *dev, struct tee_shm **shm, size_t *counreturn ret; } -static int open_enum_session (struct udevice *dev,u32 *tee_sess) +int optee_open_enum_session (struct udevice *dev,u32 *tee_sess) {const struct tee_optee_ta_uuid pta_uuid =PTA_DEVICE_ENUM ;struct tee_open_session_arg arg = { };@@ -176,31 +176,34 @@ static int open_enum_session(struct udevice *dev, u32 *tee_sess)return 0 ; } -static int bind_service_drivers (struct udevice *dev) +int optee_bind_services (struct udevice *dev,u32 tee_sess, +unsigned int pta_cmd) {struct tee_shm *service_list =NULL ;size_t service_count; -u32 tee_sess; -int ret, ret2; - - ret =open_enum_session (dev, &tee_sess); -if (ret) -return ret; +int ret; ret =enum_services (dev, &service_list, &service_count, tee_sess, -PTA_CMD_GET_DEVICES ); + pta_cmd);if (!ret && service_count) ret =bind_service_list (dev, service_list, service_count);tee_shm_free (service_list); - service_list =NULL ; - ret2 =enum_services (dev, &service_list, &service_count, tee_sess, -PTA_CMD_GET_DEVICES_SUPP ); -if (!ret2 && service_count) - ret2 =bind_service_list (dev, service_list, service_count); +return ret; +} + +static int bind_service_drivers (struct udevice *dev) +{ +u32 tee_sess; +int ret, ret2;Quoted 9 lines
drivers/tee/optee/core.c static int open_enum_session(struct udevice *dev, u32 *tee_sess) · line 205
Quoted 6 lines
drivers/tee/optee/core.c +5
-1-tee_shm_free (service_list); + ret =optee_open_enum_session (dev, &tee_sess); +if (ret) +return ret; + + ret =optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES );Any reason we aren't exiting immediately here?
Just maintained the pre-existing behavior. But I could do this as well:
ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES); if (ret == 0) ret = optee_bind_services(dev, tee_sess, PTA_CMD_GET_DEVICES_SUPP);
Quoted 8 lines
Quoted 2 lines
Simpler, in fact...
... but logically different: We only warn if any binding attempt fails, now we would not even attempt the other.
Key question is whether such an error scenario is possible at all, thus only
PTA_CMD_GET_DEVICESfails but notPTA_CMD_GET_DEVICES_SUPP.
This can happen in the kernel (e.g the emulated RPMB that the supplicant presents), but I don't think it happens in u-boot. However, this is a valid reason not to exit immediately, so I am fine leaving it as is
Cheers
/Ilias
Quoted 6 lines
Jan
--
Siemens AG, Foundational Technologies
Linux Expert Center
PATCH v2 2/5 tee: optee: Add support for enumerating services that only need RPMB
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
Up to OP-TEE 4.4.0, all services that needed a supplicant where returned by PTA_CMD_GET_DEVICES_SUPP. Since then, services that only need a supplicant for the purpose of accessing the RPMB are only enumerated by the new, separate PTA_CMD_GET_DEVICES_RPMB. U-Boot so far lacks support for that, thus no longer finds such services, e.g. fTPM.
Perform the separate enumeration during probe but, as that may fail if the MMC is not probed yet, also provide a callback to trigger a retry when another MMC device becomes available.
--- drivers/tee/optee/core.c | 22 +++++++--------------- drivers/tee/optee/optee_private.h | 21 +++++++++++++++++++++ drivers/tee/optee/rpmb.c | 19 +++++++++++++++++++ include/tee/optee.h | 6 ++++++ 4 files changed, 53 insertions(+), 15 deletions(-)
drivers/tee/optee/core.c +7 -15
@@ -27,19 +27,6 @@*/ #define PTA_DEVICE_ENUM { 0x7011a688, 0xddde, 0x4053, \ { 0xa5, 0xa9, 0x7b, 0x3c, 0x4d, 0xdf, 0x13, 0xb8 } } -/* -* PTA_CMD_GET_DEVICES - List services without supplicant dependencies -* -* [out] memref[0]: List of the UUIDs of service enumerated by OP-TEE -*/ -#define PTA_CMD_GET_DEVICES 0x0 - -/* -* PTA_CMD_GET_DEVICES_SUPP - List services depending on tee supplicant -* -* [out] memref[0]: List of the UUIDs of service enumerated by OP-TEE -*/ -#define PTA_CMD_GET_DEVICES_SUPP 0x1 typedef void (optee_invoke_fn)(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long,
@@ -195,8 +182,8 @@ int optee_bind_services(struct udevice *dev, u32 tee_sess,static int bind_service_drivers (struct udevice *dev) { +int ret, ret2, ret3 =0 ;u32 tee_sess; -int ret, ret2; ret =optee_open_enum_session (dev, &tee_sess);if (ret)
@@ -204,13 +191,18 @@ static int bind_service_drivers(struct udevice *dev) ret =optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES ); ret2 =optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES_SUPP ); +if (CONFIG_IS_ENABLED (SUPPORT_EMMC_RPMB )) + ret3 =optee_bind_services (dev, tee_sess, +PTA_CMD_GET_DEVICES_RPMB );tee_close_session (dev, tee_sess);if (ret)return ret; +if (ret2) +return ret2; -return ret2; +return ret3; }/**
drivers/tee/optee/optee_private.h +21 -0
@@ -9,6 +9,27 @@#include <tee.h> #include <log.h> +/* +* PTA_CMD_GET_DEVICES - List services without supplicant dependencies +* +* [out] memref[0]: List of the UUIDs of service enumerated by OP-TEE +*/ +#define PTA_CMD_GET_DEVICES 0x0 + +/* +* PTA_CMD_GET_DEVICES_SUPP - List services depending on tee supplicant +* +* [out] memref[0]: List of the UUIDs of service enumerated by OP-TEE +*/ +#define PTA_CMD_GET_DEVICES_SUPP 0x1 + +/* +* PTA_CMD_GET_DEVICES_RPMB - List services only depending on RPMB support +* +* [out] memref[0]: List of the UUIDs of service enumerated by OP-TEE +*/ +#define PTA_CMD_GET_DEVICES_RPMB 0x2 +/** * struct optee_private - OP-TEE driver private data * @rpmb_mmc: mmc device for the RPMB partition
drivers/tee/optee/rpmb.c +19 -0
@@ -191,3 +191,22 @@ void optee_suppl_rpmb_release(struct udevice *dev) {release_mmc (dev_get_priv (dev)); } + +void optee_rpmb_available (void ) +{ +struct udevice *dev; +struct uclass *uc; +u32 tee_sess; + + uclass_id_foreach_dev(UCLASS_TEE, dev, uc) { +if (strcmp (dev->driver->name,"optee" ) !=0 ) +continue ; + +if (optee_open_enum_session (dev, &tee_sess) !=0 ) +continue ; + +optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES_RPMB ); + +tee_close_session (dev, tee_sess); + } +}
include/tee/optee.h +6 -0
@@ -74,4 +74,10 @@ static inline bool is_optee_smc_api(void) }#endif +#if defined(CONFIG_OPTEE ) && defined(CONFIG_SUPPORT_EMMC_RPMB ) +void optee_rpmb_available (void ); +#else +static inline void optee_rpmb_available (void ) {} +#endif +#endif /* _OPTEE_H */
Signature · 1 line
2.47.3
Re: [PATCH v2 2/5] tee: optee: Add support for enumerating services that only need RPMB
[...]
Quoted 17 lines · Jan Kiszka
drivers/tee/optee/optee_private.h +1
-0+/** * struct optee_private - OP-TEE driver private data * @rpmb_mmc: mmc device for the RPMB partition drivers/tee/optee/rpmb.c +5
-0@@ -191,3 +191,22 @@ void optee_suppl_rpmb_release(struct udevice *dev) {release_mmc (dev_get_priv (dev)); } + +void optee_rpmb_available (void ) +{ +struct udevice *dev; +struct uclass *uc;
drivers/tee/optee/rpmb.c void optee_suppl_rpmb_release(struct udevice *dev) · line 208
Quoted 10 lines
drivers/tee/optee/rpmb.c +10
-0+u32 tee_sess; + + uclass_id_foreach_dev(UCLASS_TEE, dev, uc) { +if (strcmp (dev->driver->name,"optee" ) !=0 ) +continue ; + +if (optee_open_enum_session (dev, &tee_sess) !=0 ) +continue ; + +optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES_RPMB );
Will this work if devices are bound but not probed? IOW do we need a device_active() check?
Quoted 9 lines
drivers/tee/optee/rpmb.c +4
-0+ +tee_close_session (dev, tee_sess); + } +}include/tee/optee.h +0
-0
include/tee/optee.h static inline bool is_optee_smc_api(void) · line 83
Quoted 10 lines
include/tee/optee.h +6
-0@@ -74,4 +74,10 @@ static inline bool is_optee_smc_api(void) }#endif +#if defined(CONFIG_OPTEE ) && defined(CONFIG_SUPPORT_EMMC_RPMB ) +void optee_rpmb_available (void ); +#else +static inline void optee_rpmb_available (void ) {} +#endif +#endif /* _OPTEE_H */
Thanks
/Ilias
Re: [PATCH v2 2/5] tee: optee: Add support for enumerating services that only need RPMB
Quoted 24 lines · Ilias Apalodimas
[...]
Quoted 21 lines · Jan Kiszka
drivers/tee/optee/optee_private.h +1
-0+/** * struct optee_private - OP-TEE driver private data * @rpmb_mmc: mmc device for the RPMB partition drivers/tee/optee/rpmb.c +9
-0@@ -191,3 +191,22 @@ void optee_suppl_rpmb_release(struct udevice *dev) {release_mmc (dev_get_priv (dev)); } + +void optee_rpmb_available (void ) +{ +struct udevice *dev; +struct uclass *uc; +u32 tee_sess; + + uclass_id_foreach_dev(UCLASS_TEE, dev, uc) { +if (strcmp (dev->driver->name,"optee" ) !=0 )
Quoted 9 lines
drivers/tee/optee/rpmb.c void optee_suppl_rpmb_release(struct udevice *dev) · line 208
Quoted 6 lines
drivers/tee/optee/rpmb.c +6
-0+continue ; + +if (optee_open_enum_session (dev, &tee_sess) !=0 ) +continue ; + +optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES_RPMB );Will this work if devices are bound but not probed? IOW do we need a
device_active()check?
You mean the theoretical case that MMC is probed before optee? Unlikely right now but still valid. Let me add that.
Jan
Quoted 22 lines
Quoted 9 lines
drivers/tee/optee/rpmb.c +4
-0+ +tee_close_session (dev, tee_sess); + } +}include/tee/optee.h +0
-0include/tee/optee.h static inline bool is_optee_smc_api(void) · line 83
Quoted 10 lines
include/tee/optee.h +6
-0@@ -74,4 +74,10 @@ static inline bool is_optee_smc_api(void) }#endif +#if defined(CONFIG_OPTEE ) && defined(CONFIG_SUPPORT_EMMC_RPMB ) +void optee_rpmb_available (void ); +#else +static inline void optee_rpmb_available (void ) {} +#endif +#endif /* _OPTEE_H */ Thanks
/Ilias
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Re: [PATCH v2 2/5] tee: optee: Add support for enumerating services that only need RPMB
Quoted 36 lines · Jan Kiszka
Quoted 24 lines · Ilias Apalodimas
[...]
Quoted 21 lines · Jan Kiszka
drivers/tee/optee/optee_private.h +1
-0+/** * struct optee_private - OP-TEE driver private data * @rpmb_mmc: mmc device for the RPMB partition drivers/tee/optee/rpmb.c +9
-0@@ -191,3 +191,22 @@ void optee_suppl_rpmb_release(struct udevice *dev) {release_mmc (dev_get_priv (dev)); } + +void optee_rpmb_available (void ) +{ +struct udevice *dev; +struct uclass *uc; +u32 tee_sess; + + uclass_id_foreach_dev(UCLASS_TEE, dev, uc) { +if (strcmp (dev->driver->name,"optee" ) !=0 )Quoted 9 lines
drivers/tee/optee/rpmb.c void optee_suppl_rpmb_release(struct udevice *dev) · line 208
Quoted 6 lines
drivers/tee/optee/rpmb.c +6
-0+continue ; + +if (optee_open_enum_session (dev, &tee_sess) !=0 ) +continue ; + +optee_bind_services (dev, tee_sess,PTA_CMD_GET_DEVICES_RPMB );Will this work if devices are bound but not probed? IOW do we need a
device_active()check?
Quoted 2 lines
You mean the theoretical case that MMC is probed before optee? Unlikely right now but still valid. Let me add that.
Yea, I am not sure if anyone can trigger this with preboot commands etc, but I think it's better to have it.
Cheers
/Ilias
Quoted 29 lines
Jan
Quoted 12 lines
Quoted 12 lines
drivers/tee/optee/rpmb.c +4
-0+ +tee_close_session (dev, tee_sess); + } +}include/tee/optee.h +0
-0@@ -74,4 +74,10 @@ static inline bool is_optee_smc_api(void) }#endif Quoted 10 lines
include/tee/optee.h static inline bool is_optee_smc_api(void) · line 83
Quoted 7 lines
include/tee/optee.h +6
-0+#if defined(CONFIG_OPTEE ) && defined(CONFIG_SUPPORT_EMMC_RPMB ) +void optee_rpmb_available (void ); +#else +static inline void optee_rpmb_available (void ) {} +#endif +#endif /* _OPTEE_H */ Thanks
/Ilias--
Siemens AG, Foundational Technologies
Linux Expert Center
PATCH v2 3/5 tee: optee: Do not warn about TEE_ERROR_STORAGE_NOT_AVAILABLE
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
This is a transitional error that is resolved once an RPMB becomes available. Keep it as debug output only.
--- drivers/tee/optee/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/tee/optee/core.c +4 -1
@@ -106,7 +106,10 @@ static int __enum_services(struct udevice *dev, struct tee_shm *shm, size_t *shm ret =tee_invoke_func (dev, &arg,1 , ¶m);if (ret || (arg.ret && arg.ret !=TEE_ERROR_SHORT_BUFFER )) { -dev_err (dev,"Enumeration command 0x%x failed: 0x%x\n" , pta_cmd, arg.ret); +if (arg.ret !=TEE_ERROR_STORAGE_NOT_AVAILABLE ) +dev_err (dev,"Enumeration command 0x%x failed: 0x%x\n" , pta_cmd, arg.ret); +else +dev_dbg (dev,"Enumeration command 0x%x failed due to unavailable storage\n" , pta_cmd);return -EINVAL ; }
Signature · 1 line
2.47.3
Re: [PATCH v2 3/5] tee: optee: Do not warn about TEE_ERROR_STORAGE_NOT_AVAILABLE
Hi Jan
Quoted 15 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This is a transitional error that is resolved once an RPMB becomes available. Keep it as debug output only.
Signed-off-by Jan Kiszka <[email protected]>--- drivers/tee/optee/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/tee/optee/core.c +0
-0
drivers/tee/optee/core.c static int __enum_services(struct udevice *dev, struct tee_shm *shm, size_t *shm · line 112
Quoted 8 lines
drivers/tee/optee/core.c +4
-1@@ -106,7 +106,10 @@ static int __enum_services(struct udevice *dev, struct tee_shm *shm, size_t *shm ret =tee_invoke_func (dev, &arg,1 , ¶m);if (ret || (arg.ret && arg.ret !=TEE_ERROR_SHORT_BUFFER )) { -dev_err (dev,"Enumeration command 0x%x failed: 0x%x\n" , pta_cmd, arg.ret); +if (arg.ret !=TEE_ERROR_STORAGE_NOT_AVAILABLE ) +dev_err (dev,"Enumeration command 0x%x failed: 0x%x\n" , pta_cmd, arg.ret); +else +dev_dbg (dev,"Enumeration command 0x%x failed due to unavailable storage\n" , pta_cmd);
I don't mind changing this and I like the different error messages. Isn't the dgb message useful for users though? Or it is something that's not expected to happen in production systems so we can hide it?
Cheers
/Ilias
Quoted 3 lines
drivers/tee/optee/core.c +0
-0return -EINVAL ; }
Re: [PATCH v2 3/5] tee: optee: Do not warn about TEE_ERROR_STORAGE_NOT_AVAILABLE
Quoted 19 lines · Ilias Apalodimas
Hi Jan
Quoted 16 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This is a transitional error that is resolved once an RPMB becomes available. Keep it as debug output only.
Signed-off-by Jan Kiszka <[email protected]>--- drivers/tee/optee/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/tee/optee/core.c +0
-0@@ -106,7 +106,10 @@ static int __enum_services(struct udevice *dev, struct tee_shm *shm, size_t *shm
Quoted 11 lines
drivers/tee/optee/core.c static int __enum_services(struct udevice *dev, struct tee_shm *shm, size_t *shm · line 112
Quoted 7 lines
drivers/tee/optee/core.c +4
-1ret =tee_invoke_func (dev, &arg,1 , ¶m);if (ret || (arg.ret && arg.ret !=TEE_ERROR_SHORT_BUFFER )) { -dev_err (dev,"Enumeration command 0x%x failed: 0x%x\n" , pta_cmd, arg.ret); +if (arg.ret !=TEE_ERROR_STORAGE_NOT_AVAILABLE ) +dev_err (dev,"Enumeration command 0x%x failed: 0x%x\n" , pta_cmd, arg.ret); +else +dev_dbg (dev,"Enumeration command 0x%x failed due to unavailable storage\n" , pta_cmd);I don't mind changing this and I like the different error messages. Isn't the dgb message useful for users though? Or it is something that's not expected to happen in production systems so we can hide it?
First of all, it's now something that will always happen due to probing of services that need RPMB when there is none yet. And, as explained above, it will be resolved later on. If you user misconfigured the firmware, though, there will be no resolution - but that is a debugging case.
Jan
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center
Ilias Apalodimas
Reviewed-byRe: [PATCH v2 3/5] tee: optee: Do not warn about TEE_ERROR_STORAGE_NOT_AVAILABLE
Quoted 33 lines · Jan Kiszka
Quoted 19 lines · Ilias Apalodimas
Hi Jan
Quoted 16 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This is a transitional error that is resolved once an RPMB becomes available. Keep it as debug output only.
Signed-off-by Jan Kiszka <[email protected]>--- drivers/tee/optee/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/tee/optee/core.c +0
-0@@ -106,7 +106,10 @@ static int __enum_services(struct udevice *dev, struct tee_shm *shm, size_t *shmQuoted 11 lines
drivers/tee/optee/core.c static int __enum_services(struct udevice *dev, struct tee_shm *shm, size_t *shm · line 112
Quoted 7 lines
drivers/tee/optee/core.c +4
-1ret =tee_invoke_func (dev, &arg,1 , ¶m);if (ret || (arg.ret && arg.ret !=TEE_ERROR_SHORT_BUFFER )) { -dev_err (dev,"Enumeration command 0x%x failed: 0x%x\n" , pta_cmd, arg.ret); +if (arg.ret !=TEE_ERROR_STORAGE_NOT_AVAILABLE ) +dev_err (dev,"Enumeration command 0x%x failed: 0x%x\n" , pta_cmd, arg.ret); +else +dev_dbg (dev,"Enumeration command 0x%x failed due to unavailable storage\n" , pta_cmd);I don't mind changing this and I like the different error messages. Isn't the dgb message useful for users though? Or it is something that's not expected to happen in production systems so we can hide it?
Quoted 5 lines
First of all, it's now something that will always happen due to probing of services that need RPMB when there is none yet. And, as explained above, it will be resolved later on. If you user misconfigured the firmware, though, there will be no resolution - but that is a debugging case.
Fair enough
Quoted 6 lines
Jan
--
Siemens AG, Foundational Technologies
Linux Expert Center
PATCH v2 4/5 mmc: Call back to optee after a successful mmc_init
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
This is needed to that OP-TEE can re-enumerate services which need RPMB access that may have become available now.
---
CC: Peng Fan <[email protected]>
CC: Jaehoon Chung <[email protected]>
--- drivers/mmc/mmc.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/mmc/mmc.c +4 -0
@@ -27,6 +27,7 @@#include <linux/list.h> #include <linux/printk.h> #include <div64.h> +#include <tee/optee.h> #include "mmc_private.h" #define DEFAULT_CMD6_TIMEOUT_MS 500
@@ -3168,6 +3169,9 @@ int mmc_init(struct mmc *mmc) mmc->cfg->name); } +if (CONFIG_IS_ENABLED (OPTEE ) && mmc->capacity_rpmb >0 ) +optee_rpmb_available (); +return err; }
Signature · 1 line
2.47.3
Re: [PATCH v2 4/5] mmc: Call back to optee after a successful mmc_init
Quoted 6 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This is needed to that OP-TEE can re-enumerate services which need RPMB access that may have become available now.
Signed-off-by Jan Kiszka <[email protected]>
Re: [PATCH v2 4/5] mmc: Call back to optee after a successful mmc_init
Altera Confidential
________________________________
From: Peng Fan <[email protected]>
Sent: Wednesday, August 26, 2026 2:17:09 pm
To: Jan Kiszka <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Jens Wiklander <[email protected]>; Ilias Apalodimas <[email protected]>; Sai Sree Kartheek Adivi <[email protected]>; Alexander Heinisch <[email protected]>; Kathpalia, Tanmay <[email protected]>; Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>
Subject: Re: [PATCH v2 4/5] mmc: Call back to optee after a successful mmc_init
Quoted 6 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
This is needed to that OP-TEE can re-enumerate services which need RPMB access that may have become available now.
Signed-off-by Jan Kiszka <[email protected]>
PATCH v2 5/5 mmc: Make "MMC Device not found" a debug output
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
Callers of find_mmc_device are generally processing and informing about errors already, e.g.
=> mmc dev 2
MMC Device 2 not found
no mmc device at slot 2
---
CC: Peng Fan <[email protected]>
CC: Jaehoon Chung <[email protected]>
--- drivers/mmc/mmc-uclass.c | 2 +- drivers/mmc/mmc_legacy.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/mmc-uclass.c +1 -1
@@ -319,7 +319,7 @@ struct mmc *find_mmc_device(int dev_num)if (ret) {#if !defined(CONFIG_XPL_BUILD ) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT ) -printf ("MMC Device %d not found\n" , dev_num); +dev_dbg (dev,"MMC Device %d not found\n" , dev_num);#endif return NULL ; }
drivers/mmc/mmc_legacy.c +1 -1
@@ -45,7 +45,7 @@ struct mmc *find_mmc_device(int dev_num) }#if !defined(CONFIG_XPL_BUILD ) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT ) -printf ("MMC Device %d not found\n" , dev_num); +dev_dbg (dev,"MMC Device %d not found\n" , dev_num);#endif return NULL ;
Signature · 1 line
2.47.3
Re: [PATCH v2 5/5] mmc: Make "MMC Device not found" a debug output
Quoted 10 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
Callers of
find_mmc_deviceare generally processing and informing about errors already, e.g.=> mmc dev 2
MMC Device 2 not found
no mmc device at slot 2Signed-off-by Jan Kiszka <[email protected]>
Re: [PATCH v2 5/5] mmc: Make "MMC Device not found" a debug output
Altera Confidential
________________________________
From: Peng Fan <[email protected]>
Sent: Wednesday, August 26, 2026 2:17:24 pm
To: Jan Kiszka <[email protected]>
Cc: U-Boot Mailing List <[email protected]>; Jens Wiklander <[email protected]>; Ilias Apalodimas <[email protected]>; Sai Sree Kartheek Adivi <[email protected]>; Alexander Heinisch <[email protected]>; Kathpalia, Tanmay <[email protected]>; Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>
Subject: Re: [PATCH v2 5/5] mmc: Make "MMC Device not found" a debug output
Quoted 10 lines · Jan Kiszka
From: Jan Kiszka <[email protected]>
Callers of
find_mmc_deviceare generally processing and informing about errors already, e.g.=> mmc dev 2
MMC Device 2 not found
no mmc device at slot 2Signed-off-by Jan Kiszka <[email protected]>
Re: [PATCH v2 5/5] mmc: Make "MMC Device not found" a debug output
In reply to Jan KiszkaQuoted 1 line · Jan Kiszka
From: Jan Kiszka <[email protected]>
[...]
drivers/mmc/mmc-uclass.c struct mmc *find_mmc_device(int dev_num) · line 322
Quoted 10 lines
drivers/mmc/mmc-uclass.c +1
-1@@ -319,7 +319,7 @@ struct mmc *find_mmc_device(int dev_num)if (ret) {#if !defined(CONFIG_XPL_BUILD ) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT ) -printf ("MMC Device %d not found\n" , dev_num); +dev_dbg (dev,"MMC Device %d not found\n" , dev_num);
'dev' might be unitiazed here on failures
Quoted 8 lines
drivers/mmc/mmc-uclass.c +0
-0#endif return NULL ; }drivers/mmc/mmc_legacy.c +0
-0
drivers/mmc/mmc_legacy.c struct mmc *find_mmc_device(int dev_num) · line 51
Quoted 8 lines
drivers/mmc/mmc_legacy.c +1
-1@@ -45,7 +45,7 @@ struct mmc *find_mmc_device(int dev_num) }#if !defined(CONFIG_XPL_BUILD ) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT ) -printf ("MMC Device %d not found\n" , dev_num); +dev_dbg (dev,"MMC Device %d not found\n" , dev_num);#endif return NULL ;
Cheers
/Ilias
Re: [PATCH v2 5/5] mmc: Make "MMC Device not found" a debug output
Quoted 10 lines · Ilias Apalodimas
Quoted 1 line · Jan Kiszka
From: Jan Kiszka <[email protected]>
[...]
Quoted 6 lines
drivers/mmc/mmc-uclass.c +0
-0@@ -319,7 +319,7 @@ struct mmc *find_mmc_device(int dev_num)
Quoted 5 lines
drivers/mmc/mmc-uclass.c struct mmc *find_mmc_device(int dev_num) · line 322
Quoted 4 lines
drivers/mmc/mmc-uclass.c +1
-1if (ret) {#if !defined(CONFIG_XPL_BUILD ) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT ) -printf ("MMC Device %d not found\n" , dev_num); +dev_dbg (dev,"MMC Device %d not found\n" , dev_num);'dev' might be unitiazed here on failures
Yes, good catch. On the failure path of blk_find_device(), 'dev' is not guaranteed to be valid, so using it with dev_dbg() is wrong. I think debug() is the right replacement rather than leaving printf(), e.g.:
debug("MMC Device %d not found\n", dev_num);
Quoted 11 lines
Quoted 11 lines
drivers/mmc/mmc-uclass.c +0
-0#endif return NULL ; }drivers/mmc/mmc_legacy.c +0
-0@@ -45,7 +45,7 @@ struct mmc *find_mmc_device(int dev_num) }
Quoted 4 lines
drivers/mmc/mmc_legacy.c struct mmc *find_mmc_device(int dev_num) · line 49
Quoted 4 lines
drivers/mmc/mmc_legacy.c +1
-1#if !defined(CONFIG_XPL_BUILD ) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT ) -printf ("MMC Device %d not found\n" , dev_num); +dev_dbg (dev,"MMC Device %d not found\n" , dev_num);#endif
Same for the legacy path, which has no 'dev' at all.
Thanks Ilias, you are right. Dropping my Reviewed-by until a fixed version.
Hi Jan
The CI [0] complains on this. My guess is it's due to the dev_dbg changes, but I haven't found time to look into it.
[0]
https://git.u-boot-project.org/u-boot/custodians/u-boot-tpm/-/pipelines/1208
Cheers
/Ilias
Quoted 34 lines · Jan Kiszka
This allows to find firmware TPM again with recent OP-TEE versions, possibly also other services. The StMM service was not affected because it is directly invoked by
efi_variable_teewhen needed, and that is late enough so that all dependencies are available by then.See patches for further details.
Changes in v2:
- fix build breakages with disabled CONFIGs
- structure code differently between optee core and rpmb
-debug()->dev_dbg()Jan
Jan Kiszka (5):
tee: optee: Factor out service enumeration and binding functions
tee: optee: Add support for enumerating services that only need RPMB
tee: optee: Do not warn aboutTEE_ERROR_STORAGE_NOT_AVAILABLE
mmc: Call back to optee after a successfulmmc_init
mmc: Make "MMC Device not found" a debug outputdrivers/mmc/mmc-uclass.c | 2 +- drivers/mmc/mmc.c | 4 +++ drivers/mmc/mmc_legacy.c | 2 +- drivers/tee/optee/core.c | 58 +++++++++++++++---------------- drivers/tee/optee/optee_private.h | 24 +++++++++++++ drivers/tee/optee/rpmb.c | 19 ++++++++++ include/tee/optee.h | 6 ++++ 7 files changed, 83 insertions(+), 32 deletions(-)--
2.47.3
Quoted 9 lines · Ilias Apalodimas
Hi Jan
The CI [0] complains on this. My guess is it's due to the
dev_dbgchanges, but I haven't found time to look into it.[0] https://git.u-boot-project.org/u-boot/custodians/u-boot-tpm/-/
pipelines/1208 <https://git.u-boot-project.org/u-boot/custodians/u-boot-
tpm/-/pipelines/1208>
Yes, looks like (log is cut off, though). Let me sort this our first.
Jan
Quoted 39 lines
Cheers
/IliasOn Sun, 23 Aug 2026 at 22:47, Jan Kiszka <[email protected] <mailto:[email protected]>> wrote:
This allows to find firmware TPM again with recent OP-TEE versions, possibly also other services. The StMM service was not affected because it is directly invoked by
efi_variable_teewhen needed, and that is late enough so that all dependencies are available by then.See patches for further details.
Changes in v2:
- fix build breakages with disabled CONFIGs
- structure code differently between optee core and rpmb
-debug()->dev_dbg()Jan
Jan Kiszka (5):
tee: optee: Factor out service enumeration and binding functions
tee: optee: Add support for enumerating services that only need RPMB
tee: optee: Do not warn aboutTEE_ERROR_STORAGE_NOT_AVAILABLE
mmc: Call back to optee after a successfulmmc_init
mmc: Make "MMC Device not found" a debug outputdrivers/mmc/mmc-uclass.c | 2 +- drivers/mmc/mmc.c | 4 +++ drivers/mmc/mmc_legacy.c | 2 +- drivers/tee/optee/core.c | 58 +++++++++++++++----------------
drivers/tee/optee/optee_private.h| 24 +++++++++++++ drivers/tee/optee/rpmb.c | 19 ++++++++++ include/tee/optee.h | 6 ++++
7 files changed, 83 insertions(+), 32 deletions(-)--
2.47.3
Signature · 2 lines
Siemens AG, Foundational Technologies Linux Expert Center