All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Enable UFS RPMB-backed OP-TEE secure storage on Genio 720
@ 2026-11-11 10:21 Carlo Caione
  2026-11-11 10:21 ` [PATCH 1/7] ufs: rpmb: validate requests before issuing commands Carlo Caione
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Carlo Caione @ 2026-11-11 10:21 UTC (permalink / raw)
  To: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong, Ilias Apalodimas
  Cc: Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Carlo Caione, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

This series enables UFS RPMB-backed OP-TEE secure storage on Genio 720.
The goal is to support pre-OS services such as EFI variable storage with
the same RPMB device identity used under Linux.

The platform also needs the OP-TEE UFS read fixes [1] and MT8391
platform and hardware-key support [2].

[1] https://github.com/OP-TEE/optee_os/pull/8238
[2] https://github.com/OP-TEE/optee_os/pull/8242

---
Carlo Caione (6):
      ufs: rpmb: validate requests before issuing commands
      ufs: rpmb: stop the model string at its NUL terminator
      tee: optee: keep UFS RPMB discovery state consistent
      tee: optee: enumerate UFS RPMB services when consumers exist
      configs: add a Genio 720 UFS configuration with OP-TEE RPMB
      doc: uefi: mention UFS RPMB for OP-TEE variable storage

Macpaul Lin (1):
      cmd: allow the OP-TEE RPMB command with UFS storage

 cmd/Kconfig                                |  4 ++--
 configs/mt8391_genio_720_evk_ufs_defconfig |  7 +++++++
 doc/develop/uefi/uefi.rst                  |  5 +++--
 drivers/tee/optee/core.c                   |  8 +++++++-
 drivers/tee/optee/optee_private.h          |  9 ++++++++-
 drivers/tee/optee/rpmb_ufs.c               | 18 ++++++++++++++++--
 drivers/ufs/ufs-rpmb.c                     | 22 +++++++++++++++-------
 7 files changed, 58 insertions(+), 15 deletions(-)
---
base-commit: 934995f642a21ca7f35fa9aed5f061394fcba243
change-id: 20261111-genio720-ufs-rpmb-minimal-41e476364217

Best regards,
--  
Carlo Caione <ccaione@baylibre.com>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH 1/7] ufs: rpmb: validate requests before issuing commands
  2026-11-11 10:21 [PATCH 0/7] Enable UFS RPMB-backed OP-TEE secure storage on Genio 720 Carlo Caione
@ 2026-11-11 10:21 ` Carlo Caione
  2026-11-11 10:21 ` [PATCH 2/7] ufs: rpmb: stop the model string at its NUL terminator Carlo Caione
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Carlo Caione @ 2026-11-11 10:21 UTC (permalink / raw)
  To: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong, Ilias Apalodimas
  Cc: Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Carlo Caione, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

Check frame counts and response space before issuing any commands. A
malformed request must not program a key or write data and then fail on
response validation. Use Linux's request shapes so surplus frames cannot
be sent or silently discarded.

Fixes: b3cd7ddbbdd5 ("ufs: add RPMB transport over SCSI SECURITY PROTOCOL")
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 drivers/ufs/ufs-rpmb.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/drivers/ufs/ufs-rpmb.c b/drivers/ufs/ufs-rpmb.c
index d9d35a06439..508eb74d976 100644
--- a/drivers/ufs/ufs-rpmb.c
+++ b/drivers/ufs/ufs-rpmb.c
@@ -157,16 +157,25 @@ int ufs_rpmb_route_frames(struct udevice *scsi_dev, unsigned int region,
 	int ret;
 
 	if (!scsi_dev || reqlen % RPMB_FRAME_SIZE ||
-	    rsplen % RPMB_FRAME_SIZE || !n_req)
+	    rsplen % RPMB_FRAME_SIZE || !n_req || !n_rsp)
 		return -EINVAL;
 
 	request = get_unaligned_be16((u8 *)req + RPMB_FRAME_REQ_OFFSET);
 
+	/*
+	 * Enforce Linux's frame counts before any I/O: a key-programming
+	 * request and a write counter read are a single frame answered by a
+	 * single frame, a data write may span several frames but returns one
+	 * result, and a data read is one request returning several frames.
+	 */
 	switch (request) {
 	case RPMB_REQ_KEY:
 	case RPMB_REQ_WRITE_DATA: {
 		u8 status_frame[RPMB_FRAME_SIZE];
 
+		if (n_rsp != 1 || (request == RPMB_REQ_KEY && n_req != 1))
+			return -EINVAL;
+
 		ret = ufs_rpmb_send(scsi_dev, region, req, n_req);
 		if (ret)
 			return ret;
@@ -178,20 +187,17 @@ int ufs_rpmb_route_frames(struct udevice *scsi_dev, unsigned int region,
 		if (ret)
 			return ret;
 
-		if (n_rsp < 1)
-			return -EINVAL;
-
 		return ufs_rpmb_recv(scsi_dev, region, rsp, 1);
 	}
 	case RPMB_REQ_WCOUNTER:
 	case RPMB_REQ_READ_DATA:
+		if (n_req != 1 || (request == RPMB_REQ_WCOUNTER && n_rsp != 1))
+			return -EINVAL;
+
 		ret = ufs_rpmb_send(scsi_dev, region, req, 1);
 		if (ret)
 			return ret;
 
-		if (n_rsp < 1)
-			return -EINVAL;
-
 		return ufs_rpmb_recv(scsi_dev, region, rsp, n_rsp);
 	default:
 		debug("ufs-rpmb: unsupported request 0x%x\n", request);

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 2/7] ufs: rpmb: stop the model string at its NUL terminator
  2026-11-11 10:21 [PATCH 0/7] Enable UFS RPMB-backed OP-TEE secure storage on Genio 720 Carlo Caione
  2026-11-11 10:21 ` [PATCH 1/7] ufs: rpmb: validate requests before issuing commands Carlo Caione
@ 2026-11-11 10:21 ` Carlo Caione
  2026-11-12  6:44   ` Jorge Ramirez
  2026-11-11 10:21 ` [PATCH 3/7] tee: optee: keep UFS RPMB discovery state consistent Carlo Caione
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Carlo Caione @ 2026-11-11 10:21 UTC (permalink / raw)
  To: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong, Ilias Apalodimas
  Cc: Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Carlo Caione, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

Some UFS model descriptors contain trailing UTF-16 NULs. Converting them
to spaces changes the RPMB identity, whereas Linux stops at the first
NUL. OP-TEE then derives different keys for the same region in the two
boot stages. Stop at the terminator to preserve a common identity.

Fixes: 87094d8062bd ("ufs: derive the per-region RPMB CID and size for OP-TEE")
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 drivers/ufs/ufs-rpmb.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/ufs/ufs-rpmb.c b/drivers/ufs/ufs-rpmb.c
index 508eb74d976..8b61760f071 100644
--- a/drivers/ufs/ufs-rpmb.c
+++ b/drivers/ufs/ufs-rpmb.c
@@ -270,6 +270,8 @@ static void ufs_rpmb_string_to_ascii(const u8 *raw, char *out, size_t outsz)
 	for (i = 0; i < nchars && n < (int)outsz - 1; i++) {
 		u16 c = get_unaligned_be16(raw + QUERY_DESC_HDR_SIZE + i * 2);
 
+		if (!c)
+			break;
 		out[n++] = (c >= 0x20 && c <= 0x7e) ? (char)c : ' ';
 	}
 	out[n] = '\0';

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 3/7] tee: optee: keep UFS RPMB discovery state consistent
  2026-11-11 10:21 [PATCH 0/7] Enable UFS RPMB-backed OP-TEE secure storage on Genio 720 Carlo Caione
  2026-11-11 10:21 ` [PATCH 1/7] ufs: rpmb: validate requests before issuing commands Carlo Caione
  2026-11-11 10:21 ` [PATCH 2/7] ufs: rpmb: stop the model string at its NUL terminator Carlo Caione
@ 2026-11-11 10:21 ` Carlo Caione
  2026-11-11 11:44   ` Ilias Apalodimas
  2026-11-11 10:21 ` [PATCH 4/7] tee: optee: enumerate UFS RPMB services when consumers exist Carlo Caione
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Carlo Caione @ 2026-11-11 10:21 UTC (permalink / raw)
  To: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong, Ilias Apalodimas
  Cc: Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Carlo Caione, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

Reject frame requests until discovery selects a region, and invalidate
that selection on every discovery failure. Keep the cursor on a region
whose metadata read failed so a retry does not silently skip it.

Fixes: 3b39df3bc540 ("optee: implement the RPMB subsystem interface for UFS")
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 drivers/tee/optee/core.c          |  2 ++
 drivers/tee/optee/optee_private.h |  9 ++++++++-
 drivers/tee/optee/rpmb_ufs.c      | 18 ++++++++++++++++--
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index a47c76811cd..2abdfd99e5d 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -829,6 +829,8 @@ static int optee_probe(struct udevice *dev)
 	u32 sec_caps;
 	int ret;
 
+	optee_suppl_rpmb_init(dev);
+
 	if (!is_optee_api(pdata->invoke_fn)) {
 		dev_err(dev, "OP-TEE api uid mismatch\n");
 		return -ENOENT;
diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h
index 5c72b280058..3f9fea532e4 100644
--- a/drivers/tee/optee/optee_private.h
+++ b/drivers/tee/optee/optee_private.h
@@ -34,7 +34,8 @@
 /**
  * struct optee_private - OP-TEE driver private data
  * @rpmb_next_region:	next UFS RPMB region to report on PROBE_NEXT
- * @rpmb_cur_region:	UFS RPMB region selected by the last PROBE_NEXT
+ * @rpmb_cur_region:	UFS RPMB region selected by the last PROBE_NEXT, or
+ *			UFS_RPMB_NUM_REGIONS while no region is selected
  */
 struct optee_private {
 	unsigned int rpmb_next_region;
@@ -97,6 +98,8 @@ static inline void optee_suppl_rpmb_release(struct udevice *dev)
 #endif
 
 #ifdef CONFIG_SUPPORT_UFS_RPMB
+void optee_suppl_rpmb_init(struct udevice *dev);
+
 void optee_suppl_cmd_rpmb_probe_reset(struct udevice *dev,
 				      struct optee_msg_arg *arg);
 
@@ -106,6 +109,10 @@ void optee_suppl_cmd_rpmb_probe_next(struct udevice *dev,
 void optee_suppl_cmd_rpmb_frames(struct udevice *dev,
 				 struct optee_msg_arg *arg);
 #else
+static inline void optee_suppl_rpmb_init(struct udevice *dev)
+{
+}
+
 static inline void optee_suppl_cmd_rpmb_probe_reset(struct udevice *dev,
 						    struct optee_msg_arg *arg)
 {
diff --git a/drivers/tee/optee/rpmb_ufs.c b/drivers/tee/optee/rpmb_ufs.c
index 0c820e9595d..fbb56305609 100644
--- a/drivers/tee/optee/rpmb_ufs.c
+++ b/drivers/tee/optee/rpmb_ufs.c
@@ -8,6 +8,13 @@
 #include "optee_msg_supplicant.h"
 #include "optee_private.h"
 
+void optee_suppl_rpmb_init(struct udevice *dev)
+{
+	struct optee_private *priv = dev_get_priv(dev);
+
+	priv->rpmb_cur_region = UFS_RPMB_NUM_REGIONS;
+}
+
 static int optee_rpmb_get_dev(struct udevice **scsi_devp)
 {
 	struct udevice *ufs_dev, *scsi_dev;
@@ -32,6 +39,7 @@ void optee_suppl_cmd_rpmb_probe_reset(struct udevice *dev,
 {
 	struct optee_private *priv = dev_get_priv(dev);
 
+	priv->rpmb_cur_region = UFS_RPMB_NUM_REGIONS;
 	if (arg->num_params != 1 ||
 	    arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT) {
 		arg->ret = TEE_ERROR_BAD_PARAMETERS;
@@ -39,7 +47,6 @@ void optee_suppl_cmd_rpmb_probe_reset(struct udevice *dev,
 	}
 
 	priv->rpmb_next_region = 0;
-	priv->rpmb_cur_region = 0;
 
 	arg->params[0].u.value.a = OPTEE_MSG_RPC_SHM_TYPE_APPL;
 	arg->ret = TEE_SUCCESS;
@@ -57,6 +64,7 @@ void optee_suppl_cmd_rpmb_probe_next(struct udevice *dev,
 	ulong cid_size;
 	int ret;
 
+	priv->rpmb_cur_region = UFS_RPMB_NUM_REGIONS;
 	if (arg->num_params != 2 ||
 	    arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT ||
 	    arg->params[1].attr != OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT) {
@@ -78,7 +86,7 @@ void optee_suppl_cmd_rpmb_probe_next(struct udevice *dev,
 	}
 
 	while (priv->rpmb_next_region < UFS_RPMB_NUM_REGIONS) {
-		unsigned int region = priv->rpmb_next_region++;
+		unsigned int region = priv->rpmb_next_region;
 
 		ret = ufs_rpmb_get_region_info(scsi_dev, region, &size_mult,
 					       &rel_wr, cid_buf);
@@ -86,6 +94,7 @@ void optee_suppl_cmd_rpmb_probe_next(struct udevice *dev,
 			arg->ret = TEE_ERROR_GENERIC;
 			return;
 		}
+		priv->rpmb_next_region++;
 		if (!ret)
 			continue;
 
@@ -120,6 +129,11 @@ void optee_suppl_cmd_rpmb_frames(struct udevice *dev,
 		return;
 	}
 
+	if (priv->rpmb_cur_region >= UFS_RPMB_NUM_REGIONS) {
+		arg->ret = TEE_ERROR_ITEM_NOT_FOUND;
+		return;
+	}
+
 	if (optee_rpmb_get_dev(&scsi_dev)) {
 		arg->ret = TEE_ERROR_ITEM_NOT_FOUND;
 		return;

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 4/7] tee: optee: enumerate UFS RPMB services when consumers exist
  2026-11-11 10:21 [PATCH 0/7] Enable UFS RPMB-backed OP-TEE secure storage on Genio 720 Carlo Caione
                   ` (2 preceding siblings ...)
  2026-11-11 10:21 ` [PATCH 3/7] tee: optee: keep UFS RPMB discovery state consistent Carlo Caione
@ 2026-11-11 10:21 ` Carlo Caione
  2026-11-11 10:21 ` [PATCH 5/7] cmd: allow the OP-TEE RPMB command with UFS storage Carlo Caione
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Carlo Caione @ 2026-11-11 10:21 UTC (permalink / raw)
  To: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong, Ilias Apalodimas
  Cc: Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Carlo Caione, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

RPMB-backed service discovery currently runs only with eMMC. With UFS
enabled, services advertised only by PTA_CMD_GET_DEVICES_RPMB are never
bound. Allow the query with either transport.

Skip enumeration when no service drivers are registered, so enabling
UFS support alone does not initialize storage unnecessarily.

Fixes: 3b39df3bc540 ("optee: implement the RPMB subsystem interface for UFS")
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 drivers/tee/optee/core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
index 2abdfd99e5d..53806670b6a 100644
--- a/drivers/tee/optee/core.c
+++ b/drivers/tee/optee/core.c
@@ -194,13 +194,17 @@ static int bind_service_drivers(struct udevice *dev)
 	int ret, ret2, ret3 = 0;
 	u32 tee_sess;
 
+	if (!ll_entry_count(struct optee_service, optee_service))
+		return 0;
+
 	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);
-	if (CONFIG_IS_ENABLED(SUPPORT_EMMC_RPMB))
+	if (CONFIG_IS_ENABLED(SUPPORT_EMMC_RPMB) ||
+	    CONFIG_IS_ENABLED(SUPPORT_UFS_RPMB))
 		ret3 = optee_bind_services(dev, tee_sess,
 					   PTA_CMD_GET_DEVICES_RPMB);
 

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 5/7] cmd: allow the OP-TEE RPMB command with UFS storage
  2026-11-11 10:21 [PATCH 0/7] Enable UFS RPMB-backed OP-TEE secure storage on Genio 720 Carlo Caione
                   ` (3 preceding siblings ...)
  2026-11-11 10:21 ` [PATCH 4/7] tee: optee: enumerate UFS RPMB services when consumers exist Carlo Caione
@ 2026-11-11 10:21 ` Carlo Caione
  2026-11-11 10:21 ` [PATCH 6/7] configs: add a Genio 720 UFS configuration with OP-TEE RPMB Carlo Caione
  2026-11-11 10:21 ` [PATCH 7/7] doc: uefi: mention UFS RPMB for OP-TEE variable storage Carlo Caione
  6 siblings, 0 replies; 16+ messages in thread
From: Carlo Caione @ 2026-11-11 10:21 UTC (permalink / raw)
  To: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong, Ilias Apalodimas
  Cc: Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Carlo Caione, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

From: Macpaul Lin <macpaul.lin@mediatek.com>

CMD_OPTEE_RPMB is restricted to the eMMC transport even though the OP-
TEE persistent-object interface is independent of the storage medium.
Allow it with the UFS RPMB subsystem transport as well, preserving the
existing sandbox path and default.

Signed-off-by: Macpaul Lin <macpaul.lin@mediatek.com>
Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 cmd/Kconfig | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cmd/Kconfig b/cmd/Kconfig
index ace0b2e9c80..6f07eccf16b 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1554,12 +1554,12 @@ config CMD_CLONE
 
 config CMD_OPTEE_RPMB
 	bool "Enable read/write support on RPMB via OPTEE"
-	depends on (SUPPORT_EMMC_RPMB && OPTEE) || SANDBOX_TEE
+	depends on ((SUPPORT_EMMC_RPMB || SUPPORT_UFS_RPMB) && OPTEE) || SANDBOX_TEE
 	default y if SANDBOX_TEE
 	select OPTEE_TA_AVB if SANDBOX_TEE
 	help
 	  Enable the commands for reading, writing persistent named values
-	  in the Replay Protection Memory Block partition in eMMC by
+	  in the Replay Protection Memory Block partition in eMMC or UFS by
 	  using Persistent Objects in OPTEE
 
 config CMD_OPTEE

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 6/7] configs: add a Genio 720 UFS configuration with OP-TEE RPMB
  2026-11-11 10:21 [PATCH 0/7] Enable UFS RPMB-backed OP-TEE secure storage on Genio 720 Carlo Caione
                   ` (4 preceding siblings ...)
  2026-11-11 10:21 ` [PATCH 5/7] cmd: allow the OP-TEE RPMB command with UFS storage Carlo Caione
@ 2026-11-11 10:21 ` Carlo Caione
  2026-11-11 15:32   ` David Lechner
  2026-11-11 10:21 ` [PATCH 7/7] doc: uefi: mention UFS RPMB for OP-TEE variable storage Carlo Caione
  6 siblings, 1 reply; 16+ messages in thread
From: Carlo Caione @ 2026-11-11 10:21 UTC (permalink / raw)
  To: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong, Ilias Apalodimas
  Cc: Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Carlo Caione, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

The Genio 720 board already provides a merged UFS device tree, but its
default configuration selects eMMC. Add a UFS entry point which reuses
the common board configuration and selects the existing UFS overlay.

Enable the OP-TEE client and Qualcomm UFS RPMB transport on this UFS
variant without changing the default eMMC configuration. The device
tree already describes the secure firmware and its reserved memory.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 configs/mt8391_genio_720_evk_ufs_defconfig | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/configs/mt8391_genio_720_evk_ufs_defconfig b/configs/mt8391_genio_720_evk_ufs_defconfig
new file mode 100644
index 00000000000..47904f93e91
--- /dev/null
+++ b/configs/mt8391_genio_720_evk_ufs_defconfig
@@ -0,0 +1,7 @@
+#include <configs/mt8391_genio_720_evk_defconfig>
+
+CONFIG_DEFAULT_DEVICE_TREE="mt8391-genio-720-evk-ufs"
+CONFIG_DEFAULT_FDT_FILE="mt8391-genio-720-evk-ufs"
+CONFIG_TEE=y
+CONFIG_OPTEE=y
+CONFIG_SUPPORT_UFS_RPMB=y

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH 7/7] doc: uefi: mention UFS RPMB for OP-TEE variable storage
  2026-11-11 10:21 [PATCH 0/7] Enable UFS RPMB-backed OP-TEE secure storage on Genio 720 Carlo Caione
                   ` (5 preceding siblings ...)
  2026-11-11 10:21 ` [PATCH 6/7] configs: add a Genio 720 UFS configuration with OP-TEE RPMB Carlo Caione
@ 2026-11-11 10:21 ` Carlo Caione
  2026-11-11 11:41   ` Ilias Apalodimas
  6 siblings, 1 reply; 16+ messages in thread
From: Carlo Caione @ 2026-11-11 10:21 UTC (permalink / raw)
  To: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong, Ilias Apalodimas
  Cc: Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Carlo Caione, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

U-Boot's OP-TEE supplicant can relay RPMB requests to a UFS device when
CONFIG_SUPPORT_UFS_RPMB is enabled, but the UEFI documentation still
names only the eMMC transport for OP-TEE-backed variables. Mention both
options.

Signed-off-by: Carlo Caione <ccaione@baylibre.com>
---
 doc/develop/uefi/uefi.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/doc/develop/uefi/uefi.rst b/doc/develop/uefi/uefi.rst
index 94ddf690440..5dddfba32ca 100644
--- a/doc/develop/uefi/uefi.rst
+++ b/doc/develop/uefi/uefi.rst
@@ -214,10 +214,11 @@ CONFIG_EFI_MM_COMM_TEE=y.
 
 Tianocore EDK II's standalone management mode driver for variables can
 be linked to OP-TEE for this purpose. This module uses the Replay
-Protected Memory Block (RPMB) of an eMMC device for persisting
+Protected Memory Block (RPMB) of an eMMC or UFS device for persisting
 non-volatile variables. When calling the variable services via the
 OP-TEE API U-Boot's OP-TEE supplicant relays calls to the RPMB driver
-which has to be enabled via CONFIG_SUPPORT_EMMC_RPMB=y.
+which has to be enabled via CONFIG_SUPPORT_EMMC_RPMB=y for eMMC or
+CONFIG_SUPPORT_UFS_RPMB=y for UFS.
 
 EDK2 Build instructions
 ***********************

-- 
2.56.0


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH 7/7] doc: uefi: mention UFS RPMB for OP-TEE variable storage
  2026-11-11 10:21 ` [PATCH 7/7] doc: uefi: mention UFS RPMB for OP-TEE variable storage Carlo Caione
@ 2026-11-11 11:41   ` Ilias Apalodimas
  2026-11-11 12:04     ` Carlo Caione
  0 siblings, 1 reply; 16+ messages in thread
From: Ilias Apalodimas @ 2026-11-11 11:41 UTC (permalink / raw)
  To: Carlo Caione
  Cc: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong,
	Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

Carlo,

When we designed and implemented this with Jens it was in theory the
abstraction we aimed for, but has anyone actually tested it?

On Wed, 11 Nov 2026 at 12:21, Carlo Caione <ccaione@baylibre.com> wrote:
>
> U-Boot's OP-TEE supplicant can relay RPMB requests to a UFS device when
> CONFIG_SUPPORT_UFS_RPMB is enabled, but the UEFI documentation still
> names only the eMMC transport for OP-TEE-backed variables. Mention both
> options.
>
> Signed-off-by: Carlo Caione <ccaione@baylibre.com>
> ---


Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>

>
>  doc/develop/uefi/uefi.rst | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/doc/develop/uefi/uefi.rst b/doc/develop/uefi/uefi.rst
> index 94ddf690440..5dddfba32ca 100644
> --- a/doc/develop/uefi/uefi.rst
> +++ b/doc/develop/uefi/uefi.rst
> @@ -214,10 +214,11 @@ CONFIG_EFI_MM_COMM_TEE=y.
>
>  Tianocore EDK II's standalone management mode driver for variables can
>  be linked to OP-TEE for this purpose. This module uses the Replay
> -Protected Memory Block (RPMB) of an eMMC device for persisting
> +Protected Memory Block (RPMB) of an eMMC or UFS device for persisting
>  non-volatile variables. When calling the variable services via the
>  OP-TEE API U-Boot's OP-TEE supplicant relays calls to the RPMB driver
> -which has to be enabled via CONFIG_SUPPORT_EMMC_RPMB=y.
> +which has to be enabled via CONFIG_SUPPORT_EMMC_RPMB=y for eMMC or
> +CONFIG_SUPPORT_UFS_RPMB=y for UFS.
>
>  EDK2 Build instructions
>  ***********************
>
> --
> 2.56.0
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/7] tee: optee: keep UFS RPMB discovery state consistent
  2026-11-11 10:21 ` [PATCH 3/7] tee: optee: keep UFS RPMB discovery state consistent Carlo Caione
@ 2026-11-11 11:44   ` Ilias Apalodimas
  2026-11-11 13:05     ` Carlo Caione
  0 siblings, 1 reply; 16+ messages in thread
From: Ilias Apalodimas @ 2026-11-11 11:44 UTC (permalink / raw)
  To: Carlo Caione
  Cc: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong,
	Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

Hi Carlo,

On Wed, 11 Nov 2026 at 12:21, Carlo Caione <ccaione@baylibre.com> wrote:
>
> Reject frame requests until discovery selects a region, and invalidate
> that selection on every discovery failure. Keep the cursor on a region
> whose metadata read failed so a retry does not silently skip it.
>

The commit message does not explain why any of the above is needed.

Thanks
/Ilias
> Fixes: 3b39df3bc540 ("optee: implement the RPMB subsystem interface for UFS")
> Signed-off-by: Carlo Caione <ccaione@baylibre.com>
> ---
>  drivers/tee/optee/core.c          |  2 ++
>  drivers/tee/optee/optee_private.h |  9 ++++++++-
>  drivers/tee/optee/rpmb_ufs.c      | 18 ++++++++++++++++--
>  3 files changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/tee/optee/core.c b/drivers/tee/optee/core.c
> index a47c76811cd..2abdfd99e5d 100644
> --- a/drivers/tee/optee/core.c
> +++ b/drivers/tee/optee/core.c
> @@ -829,6 +829,8 @@ static int optee_probe(struct udevice *dev)
>         u32 sec_caps;
>         int ret;
>
> +       optee_suppl_rpmb_init(dev);
> +
>         if (!is_optee_api(pdata->invoke_fn)) {
>                 dev_err(dev, "OP-TEE api uid mismatch\n");
>                 return -ENOENT;
> diff --git a/drivers/tee/optee/optee_private.h b/drivers/tee/optee/optee_private.h
> index 5c72b280058..3f9fea532e4 100644
> --- a/drivers/tee/optee/optee_private.h
> +++ b/drivers/tee/optee/optee_private.h
> @@ -34,7 +34,8 @@
>  /**
>   * struct optee_private - OP-TEE driver private data
>   * @rpmb_next_region:  next UFS RPMB region to report on PROBE_NEXT
> - * @rpmb_cur_region:   UFS RPMB region selected by the last PROBE_NEXT
> + * @rpmb_cur_region:   UFS RPMB region selected by the last PROBE_NEXT, or
> + *                     UFS_RPMB_NUM_REGIONS while no region is selected
>   */
>  struct optee_private {
>         unsigned int rpmb_next_region;
> @@ -97,6 +98,8 @@ static inline void optee_suppl_rpmb_release(struct udevice *dev)
>  #endif
>
>  #ifdef CONFIG_SUPPORT_UFS_RPMB
> +void optee_suppl_rpmb_init(struct udevice *dev);
> +
>  void optee_suppl_cmd_rpmb_probe_reset(struct udevice *dev,
>                                       struct optee_msg_arg *arg);
>
> @@ -106,6 +109,10 @@ void optee_suppl_cmd_rpmb_probe_next(struct udevice *dev,
>  void optee_suppl_cmd_rpmb_frames(struct udevice *dev,
>                                  struct optee_msg_arg *arg);
>  #else
> +static inline void optee_suppl_rpmb_init(struct udevice *dev)
> +{
> +}
> +
>  static inline void optee_suppl_cmd_rpmb_probe_reset(struct udevice *dev,
>                                                     struct optee_msg_arg *arg)
>  {
> diff --git a/drivers/tee/optee/rpmb_ufs.c b/drivers/tee/optee/rpmb_ufs.c
> index 0c820e9595d..fbb56305609 100644
> --- a/drivers/tee/optee/rpmb_ufs.c
> +++ b/drivers/tee/optee/rpmb_ufs.c
> @@ -8,6 +8,13 @@
>  #include "optee_msg_supplicant.h"
>  #include "optee_private.h"
>
> +void optee_suppl_rpmb_init(struct udevice *dev)
> +{
> +       struct optee_private *priv = dev_get_priv(dev);
> +
> +       priv->rpmb_cur_region = UFS_RPMB_NUM_REGIONS;
> +}
> +
>  static int optee_rpmb_get_dev(struct udevice **scsi_devp)
>  {
>         struct udevice *ufs_dev, *scsi_dev;
> @@ -32,6 +39,7 @@ void optee_suppl_cmd_rpmb_probe_reset(struct udevice *dev,
>  {
>         struct optee_private *priv = dev_get_priv(dev);
>
> +       priv->rpmb_cur_region = UFS_RPMB_NUM_REGIONS;
>         if (arg->num_params != 1 ||
>             arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT) {
>                 arg->ret = TEE_ERROR_BAD_PARAMETERS;
> @@ -39,7 +47,6 @@ void optee_suppl_cmd_rpmb_probe_reset(struct udevice *dev,
>         }
>
>         priv->rpmb_next_region = 0;
> -       priv->rpmb_cur_region = 0;
>
>         arg->params[0].u.value.a = OPTEE_MSG_RPC_SHM_TYPE_APPL;
>         arg->ret = TEE_SUCCESS;
> @@ -57,6 +64,7 @@ void optee_suppl_cmd_rpmb_probe_next(struct udevice *dev,
>         ulong cid_size;
>         int ret;
>
> +       priv->rpmb_cur_region = UFS_RPMB_NUM_REGIONS;
>         if (arg->num_params != 2 ||
>             arg->params[0].attr != OPTEE_MSG_ATTR_TYPE_VALUE_OUTPUT ||
>             arg->params[1].attr != OPTEE_MSG_ATTR_TYPE_RMEM_OUTPUT) {
> @@ -78,7 +86,7 @@ void optee_suppl_cmd_rpmb_probe_next(struct udevice *dev,
>         }
>
>         while (priv->rpmb_next_region < UFS_RPMB_NUM_REGIONS) {
> -               unsigned int region = priv->rpmb_next_region++;
> +               unsigned int region = priv->rpmb_next_region;
>
>                 ret = ufs_rpmb_get_region_info(scsi_dev, region, &size_mult,
>                                                &rel_wr, cid_buf);
> @@ -86,6 +94,7 @@ void optee_suppl_cmd_rpmb_probe_next(struct udevice *dev,
>                         arg->ret = TEE_ERROR_GENERIC;
>                         return;
>                 }
> +               priv->rpmb_next_region++;
>                 if (!ret)
>                         continue;
>
> @@ -120,6 +129,11 @@ void optee_suppl_cmd_rpmb_frames(struct udevice *dev,
>                 return;
>         }
>
> +       if (priv->rpmb_cur_region >= UFS_RPMB_NUM_REGIONS) {
> +               arg->ret = TEE_ERROR_ITEM_NOT_FOUND;
> +               return;
> +       }
> +
>         if (optee_rpmb_get_dev(&scsi_dev)) {
>                 arg->ret = TEE_ERROR_ITEM_NOT_FOUND;
>                 return;
>
> --
> 2.56.0
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 7/7] doc: uefi: mention UFS RPMB for OP-TEE variable storage
  2026-11-11 11:41   ` Ilias Apalodimas
@ 2026-11-11 12:04     ` Carlo Caione
  0 siblings, 0 replies; 16+ messages in thread
From: Carlo Caione @ 2026-11-11 12:04 UTC (permalink / raw)
  To: Ilias Apalodimas
  Cc: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong,
	Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

On Wed, Nov 11, 2026 at 13:41:38 +0100, Ilias Apalodimas wrote:
> Carlo,

Hi Ilias,
 
> When we designed and implemented this with Jens it was in theory the
> abstraction we aimed for, but has anyone actually tested it?

It was tested on a G720 platform. We created, updated and deleted a
non-volatile EFI variable from U-Boot, backed by the RPMB on UFS.

The stack was this series + the two OP-TEE PRs linked in the cover
letter, using EDK II StandaloneMm.

--
Carlo Caione

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 3/7] tee: optee: keep UFS RPMB discovery state consistent
  2026-11-11 11:44   ` Ilias Apalodimas
@ 2026-11-11 13:05     ` Carlo Caione
  0 siblings, 0 replies; 16+ messages in thread
From: Carlo Caione @ 2026-11-11 13:05 UTC (permalink / raw)
  To: Ilias Apalodimas
  Cc: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong,
	Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

On Wed, Nov 11, 2026 at 13:44:51 +0100, Ilias Apalodimas wrote:
> Hi Carlo,

Hi Ilias,
 
> On Wed, 11 Nov 2026 at 12:21, Carlo Caione <ccaione@baylibre.com> wrote:
> >
> > Reject frame requests until discovery selects a region, and invalidate
> > that selection on every discovery failure. Keep the cursor on a region
> > whose metadata read failed so a retry does not silently skip it.
> >
> 
> The commit message does not explain why any of the above is needed.

fair enough. It is probably a bit of a defensive hardening but it was
something I stumbled upon that felt wrong, not actually (hopefully?)
seen in normal OP-TEE operations but it is supposed to catch discovery
errors and out-of-order RPC sequences.

If you feel this is a bit excessive, I can drop it from V2.

Thanks,

--
Carlo Caione

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 6/7] configs: add a Genio 720 UFS configuration with OP-TEE RPMB
  2026-11-11 10:21 ` [PATCH 6/7] configs: add a Genio 720 UFS configuration with OP-TEE RPMB Carlo Caione
@ 2026-11-11 15:32   ` David Lechner
  0 siblings, 0 replies; 16+ messages in thread
From: David Lechner @ 2026-11-11 15:32 UTC (permalink / raw)
  To: Carlo Caione, u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong,
	Ilias Apalodimas
  Cc: Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, Quentin Schulz, Marek Vasut

On 11/11/26 4:21 AM, Carlo Caione wrote:
> The Genio 720 board already provides a merged UFS device tree, but its
> default configuration selects eMMC. Add a UFS entry point which reuses
> the common board configuration and selects the existing UFS overlay.
> 
> Enable the OP-TEE client and Qualcomm UFS RPMB transport on this UFS

Is it really "Qualcomm" or is it just "upstream"?

> variant without changing the default eMMC configuration. The device
> tree already describes the secure firmware and its reserved memory.
> 
> Signed-off-by: Carlo Caione <ccaione@baylibre.com>
> ---
>  configs/mt8391_genio_720_evk_ufs_defconfig | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/configs/mt8391_genio_720_evk_ufs_defconfig b/configs/mt8391_genio_720_evk_ufs_defconfig
> new file mode 100644
> index 00000000000..47904f93e91
> --- /dev/null
> +++ b/configs/mt8391_genio_720_evk_ufs_defconfig

I prefer not to have a defconfig for every possible combination of features
we could have on these boards. It would get out of hand with different
combinations and make CI much slower. For example, here we would also need
another nearly identical defconfig for genio 520.

Instead, we can add .config fragments in the board folder that can be
combined with the one and only defconfig.

> @@ -0,0 +1,7 @@
> +#include <configs/mt8391_genio_720_evk_defconfig>
> +
> +CONFIG_DEFAULT_DEVICE_TREE="mt8391-genio-720-evk-ufs"
> +CONFIG_DEFAULT_FDT_FILE="mt8391-genio-720-evk-ufs"

We already handle this by `make DEVICE_TREE=...`


> +CONFIG_TEE=y
> +CONFIG_OPTEE=y

We can probably enable the options above in the common defconfig.

> +CONFIG_SUPPORT_UFS_RPMB=y
> 

Then this would go in the config fragment that one would add only when they
actually have RPMB set up.

And how about also enabling EFI_MM_COMM_TEE and CMD_OPTEE_RPMB there?


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/7] ufs: rpmb: stop the model string at its NUL terminator
  2026-11-11 10:21 ` [PATCH 2/7] ufs: rpmb: stop the model string at its NUL terminator Carlo Caione
@ 2026-11-12  6:44   ` Jorge Ramirez
  2026-11-12  7:07     ` Carlo Caione
  0 siblings, 1 reply; 16+ messages in thread
From: Jorge Ramirez @ 2026-11-12  6:44 UTC (permalink / raw)
  To: Carlo Caione
  Cc: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong, Ilias Apalodimas,
	Jorge Ramirez-Ortiz, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

On 11/11/26 11:21:35, Carlo Caione wrote:
> Some UFS model descriptors contain trailing UTF-16 NULs. Converting them
> to spaces changes the RPMB identity, whereas Linux stops at the first
> NUL. OP-TEE then derives different keys for the same region in the two
> boot stages. Stop at the terminator to preserve a common identity.
> 
> Fixes: 87094d8062bd ("ufs: derive the per-region RPMB CID and size for OP-TEE")
> Signed-off-by: Carlo Caione <ccaione@baylibre.com>
> ---
>  drivers/ufs/ufs-rpmb.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/ufs/ufs-rpmb.c b/drivers/ufs/ufs-rpmb.c
> index 508eb74d976..8b61760f071 100644
> --- a/drivers/ufs/ufs-rpmb.c
> +++ b/drivers/ufs/ufs-rpmb.c
> @@ -270,6 +270,8 @@ static void ufs_rpmb_string_to_ascii(const u8 *raw, char *out, size_t outsz)
>  	for (i = 0; i < nchars && n < (int)outsz - 1; i++) {
>  		u16 c = get_unaligned_be16(raw + QUERY_DESC_HDR_SIZE + i * 2);
>  
> +		if (!c)
> +			break;
>  		out[n++] = (c >= 0x20 && c <= 0x7e) ? (char)c : ' ';
>  	}
>  	out[n] = '\0';


have you tested this with Linux - RMPB access from u-boot and linux to confirm?
AFAIR (plus the tests that I run) the code should match.

> 
> -- 
> 2.56.0
> 

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/7] ufs: rpmb: stop the model string at its NUL terminator
  2026-11-12  6:44   ` Jorge Ramirez
@ 2026-11-12  7:07     ` Carlo Caione
  2026-11-12  7:43       ` Jorge Ramirez
  0 siblings, 1 reply; 16+ messages in thread
From: Carlo Caione @ 2026-11-12  7:07 UTC (permalink / raw)
  To: Jorge Ramirez
  Cc: u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong, Ilias Apalodimas,
	Macpaul Lin, Bhupesh Sharma, Neha Malcom Francis, Tom Rini,
	Heinrich Schuchardt, Jens Wiklander, Jan Kiszka, James Hilliard,
	Simon Glass, Johan Jonker, Julien Stephan, David Lechner,
	Quentin Schulz, Marek Vasut

On Thu, Nov 12, 2026 at 07:44:55 +0100, Jorge Ramirez wrote:

Hi Jorge,

> > diff --git a/drivers/ufs/ufs-rpmb.c b/drivers/ufs/ufs-rpmb.c
> > index 508eb74d976..8b61760f071 100644
> > --- a/drivers/ufs/ufs-rpmb.c
> > +++ b/drivers/ufs/ufs-rpmb.c
> > @@ -270,6 +270,8 @@ static void ufs_rpmb_string_to_ascii(const u8 *raw, char *out, size_t outsz)
> >  	for (i = 0; i < nchars && n < (int)outsz - 1; i++) {
> >  		u16 c = get_unaligned_be16(raw + QUERY_DESC_HDR_SIZE + i * 2);
> >  
> > +		if (!c)
> > +			break;
> >  		out[n++] = (c >= 0x20 && c <= 0x7e) ? (char)c : ' ';
> >  	}
> >  	out[n] = '\0';
> 
> 
> have you tested this with Linux - RMPB access from u-boot and linux to confirm?
> AFAIR (plus the tests that I run) the code should match.

Yes, I did on a Genio 720 with a SK hynix HN8T05DJHVX105 UFS device.

The problem was that the device model descriptor contains two trailing
UTF-16 NULs. Linux's utf16s_to_utf8s() stops at the first NUL, while the
original U-Boot helper converts both to spaces:

  Original U-Boot: HN8T05DJHVX105<space><space>
  Linux/patched:  HN8T05DJHVX105

--
Carlo Caione

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH 2/7] ufs: rpmb: stop the model string at its NUL terminator
  2026-11-12  7:07     ` Carlo Caione
@ 2026-11-12  7:43       ` Jorge Ramirez
  0 siblings, 0 replies; 16+ messages in thread
From: Jorge Ramirez @ 2026-11-12  7:43 UTC (permalink / raw)
  To: Carlo Caione
  Cc: Jorge Ramirez, u-boot, GSS_MTK_Uboot_upstream, Neil Armstrong,
	Ilias Apalodimas, Macpaul Lin, Bhupesh Sharma,
	Neha Malcom Francis, Tom Rini, Heinrich Schuchardt,
	Jens Wiklander, Jan Kiszka, James Hilliard, Simon Glass,
	Johan Jonker, Julien Stephan, David Lechner, Quentin Schulz,
	Marek Vasut

On 12/11/26 08:07:36, Carlo Caione wrote:
> On Thu, Nov 12, 2026 at 07:44:55 +0100, Jorge Ramirez wrote:
> 
> Hi Jorge,
> 
> > > diff --git a/drivers/ufs/ufs-rpmb.c b/drivers/ufs/ufs-rpmb.c
> > > index 508eb74d976..8b61760f071 100644
> > > --- a/drivers/ufs/ufs-rpmb.c
> > > +++ b/drivers/ufs/ufs-rpmb.c
> > > @@ -270,6 +270,8 @@ static void ufs_rpmb_string_to_ascii(const u8 *raw, char *out, size_t outsz)
> > >  	for (i = 0; i < nchars && n < (int)outsz - 1; i++) {
> > >  		u16 c = get_unaligned_be16(raw + QUERY_DESC_HDR_SIZE + i * 2);
> > >  
> > > +		if (!c)
> > > +			break;
> > >  		out[n++] = (c >= 0x20 && c <= 0x7e) ? (char)c : ' ';
> > >  	}
> > >  	out[n] = '\0';
> > 
> > 
> > have you tested this with Linux - RMPB access from u-boot and linux to confirm?
> > AFAIR (plus the tests that I run) the code should match.
> 
> Yes, I did on a Genio 720 with a SK hynix HN8T05DJHVX105 UFS device.
> 
> The problem was that the device model descriptor contains two trailing
> UTF-16 NULs. Linux's utf16s_to_utf8s() stops at the first NUL, while the
> original U-Boot helper converts both to spaces:
> 
>   Original U-Boot: HN8T05DJHVX105<space><space>
>   Linux/patched:  HN8T05DJHVX105


ah sure. I see. 

it was just that I remembered an issue I had to work around (cache not
being invalidated on the descriptor on u-boot) so I remembered testing a
similar kind of check but for the wrong reasons.

looks good, thanks!

> 
> --
> Carlo Caione

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2026-11-12  7:43 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-11 10:21 [PATCH 0/7] Enable UFS RPMB-backed OP-TEE secure storage on Genio 720 Carlo Caione
2026-11-11 10:21 ` [PATCH 1/7] ufs: rpmb: validate requests before issuing commands Carlo Caione
2026-11-11 10:21 ` [PATCH 2/7] ufs: rpmb: stop the model string at its NUL terminator Carlo Caione
2026-11-12  6:44   ` Jorge Ramirez
2026-11-12  7:07     ` Carlo Caione
2026-11-12  7:43       ` Jorge Ramirez
2026-11-11 10:21 ` [PATCH 3/7] tee: optee: keep UFS RPMB discovery state consistent Carlo Caione
2026-11-11 11:44   ` Ilias Apalodimas
2026-11-11 13:05     ` Carlo Caione
2026-11-11 10:21 ` [PATCH 4/7] tee: optee: enumerate UFS RPMB services when consumers exist Carlo Caione
2026-11-11 10:21 ` [PATCH 5/7] cmd: allow the OP-TEE RPMB command with UFS storage Carlo Caione
2026-11-11 10:21 ` [PATCH 6/7] configs: add a Genio 720 UFS configuration with OP-TEE RPMB Carlo Caione
2026-11-11 15:32   ` David Lechner
2026-11-11 10:21 ` [PATCH 7/7] doc: uefi: mention UFS RPMB for OP-TEE variable storage Carlo Caione
2026-11-11 11:41   ` Ilias Apalodimas
2026-11-11 12:04     ` Carlo Caione

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.