Skip to contentSkip to conversation

ufs: rpmb: route OP-TEE RPMB secure storage over UFS

PATCH In review Jorge Ramirez-Ortiz 2 participants 8 messages Oct 18 – Oct 19

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v6 cover ufs: rpmb: route OP-TEE RPMB secure storage over UFS

OP-TEE secure storage (CFG_RPMB_FS) relies on an RPMB partition, but U-Boot's OP-TEE RPMB supplicant only speaks the legacy single-command interface, which is bound to eMMC. SoCs that are UFS-only and have no eMMC (for example the Qualcomm SA8775P) therefore cannot back OP-TEE secure storage from U-Boot today. This series adds that support.

It introduces the transport-agnostic OP-TEE RPMB "subsystem" interface (PROBE_RESET / PROBE_NEXT / FRAMES), where the normal world enumerates the RPMB device and reports its kind, size and CID, then carries the signed frames. The legacy eMMC supplicant is preserved unchanged, only renamed to rpmb_emmc.c, with the new UFS backend added as a separate rpmb_ufs.c; the two are mutually exclusive via Kconfig (SUPPORT_UFS_RPMB depends on !SUPPORT_EMMC_RPMB) because the OP-TEE supplicant handles a single RPMB transport. The subsystem interface is UFS-only for now; eMMC can be migrated onto it later as the legacy path is retired.

On top of that it adds a UFS RPMB transport that moves JEDEC RPMB frames to and from the RPMB Well-Known LUN using SCSI SECURITY PROTOCOL IN/OUT. The per-region 16-byte CID is derived by BLAKE2b-hashing the exact device-id string the Linux kernel builds (ufshcd_create_device_id() plus a "-R<region>" suffix), so OP-TEE derives an RPMB key that matches the one Linux would use.

The first patch is a standalone UFS descriptor fix the RPMB path depends on (UTF-16BE string decoding). A small preparatory patch surfaces the RESPONSE UPIU sense data from ufs_scsi_exec() so the transport can retry only on a power-on UNIT ATTENTION; the transport patch also bounces unaligned frames through a DMA-aligned buffer for the RPMB WLUN.

Note: reading UFS descriptors reliably also requires the descriptor data-segment cache-invalidation fix, which has already been posted and merged separately, so this series is based on top of it.

Tested on the Qualcomm IQ-9075-EVK (SA8775P): OP-TEE with CFG_RPMB_FS programs the RPMB key through U-Boot and reads/writes secure-storage objects, with the derived CID matching the Linux UFS device_id ABI.

On the CID derivation (patch 4/6): the BLAKE2b / 16-byte scheme is kept as-is because it mirrors mainline Linux's ufshcd_create_device_id() and OP-TEE's HUK-based key derivation (an OP-TEE ABI, not a GP/JEDEC spec). Per the v5 list discussion, this does not preclude vendor-specific CID
backends: they can be added on top later via Kconfig or weak per-platform hooks without changing this series.

Dependencies:
Linux kernel (merged):
https://lore.kernel.org/linux-scsi/[email protected]/
OP-TEE (merged):
https://github.com/OP-TEE/optee_os/pull/7881
https://github.com/OP-TEE/optee_os/pull/8007

v6:
- Rebased onto current master (was v2026.10-rc4-479); resolved the optee_private.h overlap with the new OP-TEE service-enumeration code (PTA_CMD_GET_DEVICES_RPMB).
- ufs: RPMB transport (3/6): retry the SECURITY PROTOCOL only on a power-on/reset UNIT ATTENTION (ASC 29h, any ASCQ) instead of on any UNIT ATTENTION sense key, so transient conditions such as 2Ah MODE PARAMETERS CHANGED are no longer retried. Matches the Linux UFS RPMB WLUN retry (commit a8a34238e5e6). Reported-by Stanley Jhu.
- optee: RPMB subsystem (6/6): drop the duplicate OPTEE_RPC_SHM_TYPE_APPL define and use the existing OPTEE_MSG_RPC_SHM_TYPE_APPL from optee_msg.h (the PROBE_RESET/PROBE_NEXT/FRAMES command IDs and OPTEE_RPC_RPMB_UFS are new and kept). Per Ilias.
- Collected tags: Acked-by Neil Armstrong (1, 2), Reviewed-by Ilias Apalodimas (5), Acked-by Ilias Apalodimas (6).

v5:
- ufs: decode string descriptors: added a Fixes: tag; the EFI file_open() callers now pass UTF16_LITTLE_ENDIAN (UEFI CHAR16 / FAT paths are little-endian by origin) instead of UTF16_HOST_ENDIAN. UTF16_HOST_ENDIAN is kept in the enum to mirror the kernel's utf16s_to_utf8s().
- ufs: new patch "surface sense data from ufs_scsi_exec()": copy the RESPONSE UPIU sense data into the SCSI command so callers can read the sense key. No current caller inspects it, so behaviour is unchanged.
- ufs: RPMB transport: retry the SECURITY PROTOCOL only on a UNIT ATTENTION sense key (using the surfaced sense data) rather than on any error; build the status frame with put_unaligned_be16(); move GEOMETRY_DESC_RPMB_RW_SIZE to the per-region CID patch that first uses it.
- Series is now 6 patches (was 5).

v4:
- ufs: decode string descriptors: dropped the in-place ufshcd_str_desc_to_cpu() byte-swap helper; instead added an endian argument to utf16_to_utf8() (UTF16_HOST/LITTLE/BIG_ENDIAN) and decode with UTF16_BIG_ENDIAN, mirroring the kernel's utf16s_to_utf8s(). Existing EFI callers pass UTF16_HOST_ENDIAN.
- ufs: RPMB transport: build the SECURITY PROTOCOL CDB with put_unaligned_be16()/put_unaligned_be32(); drop the rpmb_frame_request() helper in favour of get_unaligned_be16(); move ufs_rpmb_read_geometry() to the patch that first uses it so it is not an unused static function during git bisect.
- ufs: per-region CID/size: reject an out-of-range device-reported logical block size before shifting and split the size computation into separate statements for readability; order <u-boot/...> after <linux/...>; note that the serial hex encoding matches the kernel device-id ABI.

v3:
- Renamed the legacy eMMC supplicant to rpmb_emmc.c (was rpmb_legacy.c) and kept it as a pure 100% rename: the UFS RPMB subsystem backend now lives in its own rpmb_ufs.c instead of being folded into rpmb.c, so the eMMC path is left byte-for-byte unchanged.
- Added CONFIG_UFS_RPMB_CONTROLLER to select the RPMB-owning UFS controller on boards with more than one UFS controller.
- Reworked the commit messages to lead with the motivation rather than the implementation detail.

v2:
- Squashed the standalone "retry SECURITY PROTOCOL on power-on UNIT ATTENTION" and "bounce unaligned frames through a DMA-aligned buffer" patches into the UFS RPMB transport patch; the series is now 5 patches.
- Reused the existing ufshcd_read_desc_param() (now exported) for all descriptor reads instead of adding a new ufshcd_read_descriptor() wrapper.
- Moved the SECURITY PROTOCOL IN/OUT opcodes to the generic SCSI header as SCSI_SECURITY_PROTOCOL_IN/OUT instead of private UFS defines.
- Factored the UTF-16BE string-descriptor byte-swap into a ufshcd_str_desc_to_cpu() helper.
- Dropped the ufs_rpmb_get_scsi_dev() wrapper; callers now use uclass_get_device(UCLASS_SCSI, ...) directly.

Jorge Ramirez-Ortiz (6):
ufs: decode string descriptors as UTF-16 big-endian
ufs: surface sense data from ufs_scsi_exec()
ufs: add RPMB transport over SCSI SECURITY PROTOCOL
ufs: derive the per-region RPMB CID and size for OP-TEE
optee: rename rpmb.c to rpmb_emmc.c
optee: implement the RPMB subsystem interface for UFS

 drivers/tee/optee/Makefile                |   3 +-
 drivers/tee/optee/optee_msg_supplicant.h  |   6 +
 drivers/tee/optee/optee_private.h         |  41 +++
 drivers/tee/optee/{rpmb.c => rpmb_emmc.c} |   0
 drivers/tee/optee/rpmb_ufs.c              | 141 +++++++++
 drivers/tee/optee/supplicant.c            |   9 +
 drivers/ufs/Kconfig                       |  21 ++
 drivers/ufs/Makefile                      |   1 +
 drivers/ufs/ufs-rpmb.c                    | 367 ++++++++++++++++++++++
 drivers/ufs/ufs-uclass.c                  |  38 ++-
 drivers/ufs/ufs.h                         |   7 +
 include/charset.h                         |  17 +-
 include/scsi.h                            |   2 +
 include/ufs.h                             |  10 +
 lib/charset.c                             |  15 +-
 lib/efi_loader/efi_file.c                 |   4 +-
 16 files changed, 670 insertions(+), 12 deletions(-)
 rename drivers/tee/optee/{rpmb.c => rpmb_emmc.c} (100%)
 create mode 100644 drivers/tee/optee/rpmb_ufs.c
 create mode 100644 drivers/ufs/ufs-rpmb.c

base-commit: 8d534cec0cc0109a37c0ded8854da03f1526dc0e

Signature · 1 line
2.54.0
#1 lore raw

PATCH v6 1/6 ufs: decode string descriptors as UTF-16 big-endian

UFS string descriptors are UTF-16 big-endian (JESD220), but ufshcd_read_string_desc() decoded them as host-endian and so left dev_desc->model blank.

Give utf16_to_utf8() the source byte order and decode UFS descriptors as big-endian, matching the kernel's utf16s_to_utf8s(). The EFI file-path callers consume little-endian UEFI strings and are marked accordingly.

Fixes 067c1b033282 ("ufs: Call ufs_scsi_bind() from uclass .post_bind")
---
 drivers/ufs/ufs-uclass.c  |  7 ++++---
 include/charset.h         | 17 ++++++++++++++++-
 lib/charset.c             | 15 ++++++++++++++-
 lib/efi_loader/efi_file.c |  4 ++--
 4 files changed, 36 insertions(+), 7 deletions(-)
drivers/ufs/ufs-uclass.c +4 -3
index 6ef01f8e4aa..21aed9f97bd 100644
@@ -1767,11 +1767,12 @@ static int ufshcd_read_string_desc(struct ufs_hba *hba, int desc_index,
 		}
 
 		/*
-		 * the descriptor contains string in UTF16 format
-		 * we need to convert to utf-8 so it can be displayed
+		 * the descriptor contains a big-endian UTF-16 string, convert
+		 * it to utf-8 so it can be displayed
 		 */
 		utf16_to_utf8(buff_ascii,
-			      (uint16_t *)&buf[QUERY_DESC_HDR_SIZE], ascii_len);
+			      (uint16_t *)&buf[QUERY_DESC_HDR_SIZE], ascii_len,
+			      UTF16_BIG_ENDIAN);
 
 		/* replace non-printable or non-ASCII characters with spaces */
 		for (i = 0; i < ascii_len; i++)
include/charset.h +16 -1
index 348bad5883a..79d0ae1ef49 100644
@@ -13,6 +13,19 @@
 
 #define MAX_UTF8_PER_UTF16 3
 
+/**
+ * enum utf16_endian - byte order of a UTF-16 string
+ *
+ * @UTF16_HOST_ENDIAN:	code units are in host byte order
+ * @UTF16_LITTLE_ENDIAN:	code units are little-endian
+ * @UTF16_BIG_ENDIAN:	code units are big-endian
+ */
+enum utf16_endian {
+	UTF16_HOST_ENDIAN,
+	UTF16_LITTLE_ENDIAN,
+	UTF16_BIG_ENDIAN,
+};
+
 /*
  * codepage_437 - Unicode to codepage 437 translation table
  */
@@ -299,9 +312,11 @@ size_t u16_strlcat(u16 *dest, const u16 *src, size_t count);
  * @dest:	the destination buffer to write the utf8 characters
  * @src:	the source utf16 string
  * @size:	the number of utf16 characters to convert
+ * @endian:	byte order of the code units in 'src'
  * Return:	the pointer to the first unwritten byte in 'dest'
  */
-uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size);
+u8 *utf16_to_utf8(u8 *dest, const u16 *src, size_t size,
+		  enum utf16_endian endian);
 
 /**
  * utf_to_cp() - translate Unicode code point to 8bit codepage
lib/charset.c +14 -1
index 182c92a50c4..8ccac4048c0 100644
@@ -5,6 +5,7 @@
  *  Copyright (c) 2017 Rob Clark
  */
 
+#include <asm/byteorder.h>
 #include <charset.h>
 #include <capitalization.h>
 #include <cp437.h>
@@ -458,13 +459,25 @@ size_t u16_strlcat(u16 *dest, const u16 *src, size_t count)
 }
 
 /* Convert UTF-16 to UTF-8.  */
-uint8_t *utf16_to_utf8(uint8_t *dest, const uint16_t *src, size_t size)
+u8 *utf16_to_utf8(u8 *dest, const u16 *src, size_t size,
+		  enum utf16_endian endian)
 {
 	uint32_t code_high = 0;
 
 	while (size--) {
 		uint32_t code = *src++;
 
+		switch (endian) {
+		case UTF16_LITTLE_ENDIAN:
+			code = le16_to_cpu(code);
+			break;
+		case UTF16_BIG_ENDIAN:
+			code = be16_to_cpu(code);
+			break;
+		case UTF16_HOST_ENDIAN:
+			break;
+		}
+
 		if (code_high) {
 			if (code >= 0xDC00 && code <= 0xDFFF) {
 				/* Surrogate pair.  */
lib/efi_loader/efi_file.c +2 -2
index 19b43c4a625..7dee57d594a 100644
@@ -184,7 +184,7 @@ static struct efi_file_handle *file_open(struct file_system *fs,
 	int flen = 0;
 
 	if (file_name) {
-		utf16_to_utf8((u8 *)f0, file_name, 1);
+		utf16_to_utf8((u8 *)f0, file_name, 1, UTF16_LITTLE_ENDIAN);
 		flen = u16_strlen(file_name);
 	}
 
@@ -216,7 +216,7 @@ static struct efi_file_handle *file_open(struct file_system *fs,
 			*p++ = '/';
 		}
 
-		utf16_to_utf8((u8 *)p, file_name, flen);
+		utf16_to_utf8((u8 *)p, file_name, flen, UTF16_LITTLE_ENDIAN);
 
 		if (sanitize_path(fh->path))
 			goto error;

base-commit: 8d534cec0cc0109a37c0ded8854da03f1526dc0e

Signature · 1 line
2.54.0
#2 lore raw

PATCH v6 2/6 ufs: surface sense data from ufs_scsi_exec()

In reply to Jorge Ramirez-Ortiz

On a CHECK CONDITION the UFS device returns SCSI sense data inline in the RESPONSE UPIU, but ufs_scsi_exec() discarded it and reported every failure as a bare -EINVAL, leaving callers unable to tell a transient condition such as a power-on UNIT ATTENTION from a hard error.

Preserve the sense data and SCSI status in the scsi_cmd. No caller inspects them yet, so behaviour is unchanged.

---
 drivers/ufs/ufs-uclass.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)
drivers/ufs/ufs-uclass.c +24 -1
index 21aed9f97bd..3d96a05281c 100644
@@ -1657,6 +1657,22 @@ static void prepare_prdt_table(struct ufs_hba *hba, struct scsi_cmd *pccb)
 	ufshcd_cache_flush(req_desc, sizeof(*req_desc));
 }
 
+/*
+ * On a CHECK CONDITION the sense data is returned inline in the RESPONSE
+ * UPIU; copy it into the SCSI command so callers can inspect the sense key
+ * (for example to tell a transient UNIT ATTENTION from a hard error).
+ */
+static void ufs_scsi_copy_sense(struct ufs_hba *hba, struct scsi_cmd *pccb)
+{
+	u16 len = be16_to_cpu(hba->ucd_rsp_ptr->sr.sense_data_len);
+
+	if (len > RESPONSE_UPIU_SENSE_DATA_LENGTH)
+		len = RESPONSE_UPIU_SENSE_DATA_LENGTH;
+
+	memcpy(pccb->sense_buf, hba->ucd_rsp_ptr->sr.sense_data, len);
+	pccb->sensedatalen = len;
+}
+
 static int ufs_scsi_exec(struct udevice *scsi_dev, struct scsi_cmd *pccb)
 {
 	struct ufs_hba *hba = dev_get_uclass_priv(scsi_dev->parent);
@@ -1664,6 +1680,9 @@ static int ufs_scsi_exec(struct udevice *scsi_dev, struct scsi_cmd *pccb)
 	int ocs, result = 0;
 	u8 scsi_status;
 
+	pccb->status = 0;
+	pccb->sensedatalen = 0;
+
 	ufshcd_prepare_req_desc_hdr(hba, &upiu_flags, pccb->dma_dir);
 	ufshcd_prepare_utp_scsi_cmd_upiu(hba, pccb, upiu_flags);
 	prepare_prdt_table(hba, pccb);
@@ -1683,8 +1702,12 @@ static int ufs_scsi_exec(struct udevice *scsi_dev, struct scsi_cmd *pccb)
 			result = ufshcd_get_rsp_upiu_result(hba->ucd_rsp_ptr);
 
 			scsi_status = result & MASK_SCSI_STATUS;
-			if (scsi_status)
+			if (scsi_status) {
+				pccb->status = scsi_status;
+				if (scsi_status == S_CHECK_COND)
+					ufs_scsi_copy_sense(hba, pccb);
 				return -EINVAL;
+			}
 
 			break;
 		case UPIU_TRANSACTION_REJECT_UPIU:
Signature · 1 line
2.54.0
#3 lore raw

PATCH v6 3/6 ufs: add RPMB transport over SCSI SECURITY PROTOCOL

In reply to Jorge Ramirez-Ortiz

OP-TEE secure storage (CFG_RPMB_FS) needs RPMB, but on UFS-only platforms with no eMMC the OP-TEE RPMB supplicant cannot reach the device's RPMB Well-Known LUN: UFS exposes RPMB through SCSI SECURITY PROTOCOL IN/OUT rather than an eMMC-style partition. Add that transport so RPMB-backed secure storage works on UFS platforms.

---
 drivers/ufs/Kconfig      |  10 +++
 drivers/ufs/Makefile     |   1 +
 drivers/ufs/ufs-rpmb.c   | 186 +++++++++++++++++++++++++++++++++++++++
 drivers/ufs/ufs-uclass.c |   6 +-
 drivers/ufs/ufs.h        |   7 ++
 include/scsi.h           |   2 +
 include/ufs.h            |   4 +
 7 files changed, 213 insertions(+), 3 deletions(-)
 create mode 100644 drivers/ufs/ufs-rpmb.c
drivers/ufs/Kconfig +10 -0
index 6dffdc00b32..a0067b1f203 100644
@@ -92,4 +92,14 @@ config UFS_TI_J721E
 	  This selects the glue layer driver for Cadence controller
 	  present on TI's J721E devices.
 
+config SUPPORT_UFS_RPMB
+	bool "Enable UFS RPMB (Replay Protected Memory Block) support"
+	depends on UFS && OPTEE && !SUPPORT_EMMC_RPMB
+	help
+	  Route OP-TEE RPMB requests to the UFS RPMB Well-Known LUN using
+	  SCSI SECURITY PROTOCOL IN/OUT commands. Required for OP-TEE secure
+	  storage (CFG_RPMB_FS) on UFS-based platforms that have no eMMC.
+	  The OP-TEE supplicant handles a single RPMB transport, so this is
+	  mutually exclusive with the eMMC RPMB supplicant (SUPPORT_EMMC_RPMB).
+
 endmenu
drivers/ufs/Makefile +1 -0
index e7f3c1d30c4..d60440ca119 100644
@@ -13,3 +13,4 @@ obj-$(CONFIG_UFS_RENESAS) += ufs-renesas.o
 obj-$(CONFIG_UFS_RENESAS_GEN5) += ufs-renesas-rcar-gen5.o
 obj-$(CONFIG_UFS_ROCKCHIP) += ufs-rockchip.o
 obj-$(CONFIG_UFS_TI_J721E) += ti-j721e-ufs.o
+obj-$(CONFIG_SUPPORT_UFS_RPMB) += ufs-rpmb.o
drivers/ufs/ufs-rpmb.c new file +186 -0

186 lines not on this page · raw message

drivers/ufs/ufs-uclass.c +3 -3
index 3d96a05281c..2ca4fb2a020 100644
@@ -1458,9 +1458,9 @@ static int ufshcd_map_desc_id_to_length(struct ufs_hba *hba, enum desc_idn desc_
  * ufshcd_read_desc_param - read the specified descriptor parameter
  *
  */
-static int ufshcd_read_desc_param(struct ufs_hba *hba, enum desc_idn desc_id,
-				  int desc_index, u8 param_offset,
-				  u8 *param_read_buf, u8 param_size)
+int ufshcd_read_desc_param(struct ufs_hba *hba, enum desc_idn desc_id,
+			   int desc_index, u8 param_offset,
+			   u8 *param_read_buf, u8 param_size)
 {
 	int ret;
 	u8 *desc_buf;
drivers/ufs/ufs.h +7 -0
index 0f6c93fbce7..9f55735602b 100644
@@ -10,6 +10,9 @@
 struct udevice;
 
 #define UFS_CDB_SIZE	16
+
+#define UFS_UPIU_RPMB_WLUN		0xC4
+
 #define UPIU_TRANSACTION_UIC_CMD 0x1F
 #define UIC_CMD_SIZE (sizeof(u32) * 4)
 #define RESPONSE_UPIU_SENSE_DATA_LENGTH	18
@@ -809,4 +812,8 @@ static inline void ufshcd_rmwl(struct ufs_hba *hba, u32 mask, u32 val, u32 reg)
 
 int ufshcd_probe(struct udevice *dev, struct ufs_hba_ops *hba_ops);
 
+int ufshcd_read_desc_param(struct ufs_hba *hba, enum desc_idn desc_id,
+			   int desc_index, u8 param_offset, u8 *param_read_buf,
+			   u8 param_size);
+
 #endif
include/scsi.h +2 -0
index 93561749b7f..439a7f4fede 100644
@@ -181,6 +181,8 @@ struct scsi_cmd {
 #define SCSI_WRITE_LONG	0x3F		/* Write Long (O) */
 #define SCSI_WRITE_SAME	0x41		/* Write Same (O) */
 #define SCSI_UNMAP	0x42		/* Write 10-Byte (MANDATORY) */
+#define SCSI_SECURITY_PROTOCOL_IN	0xA2	/* Security Protocol In (O) */
+#define SCSI_SECURITY_PROTOCOL_OUT	0xB5	/* Security Protocol Out (O) */
 
 /**
  * enum scsi_cmd_phase - current phase of the SCSI protocol
include/ufs.h +4 -0
index f6e27d90e43..1bec3ce73a4 100644
@@ -20,4 +20,8 @@ int ufs_probe(void);
  */
 int ufs_probe_dev(int index);
 
+int ufs_rpmb_route_frames(struct udevice *scsi_dev, unsigned int region,
+			  void *req, unsigned long reqlen, void *rsp,
+			  unsigned long rsplen);
+
 #endif
Signature · 1 line
2.54.0
#4 lore raw

PATCH v6 4/6 ufs: derive the per-region RPMB CID and size for OP-TEE

In reply to Jorge Ramirez-Ortiz

OP-TEE derives its RPMB authentication key from a device identifier, so U-Boot must supply the exact identifier the Linux kernel uses; otherwise the keys differ and OP-TEE cannot access RPMB storage provisioned under Linux, or vice versa. The RPMB probe also needs each region's size and reliable-write count to enumerate the regions. Provide both so secure storage stays interoperable between U-Boot and Linux on the same device.

---
 drivers/ufs/Kconfig    |   7 +-
 drivers/ufs/ufs-rpmb.c | 181 +++++++++++++++++++++++++++++++++++++++++
 include/ufs.h          |   6 ++
 3 files changed, 192 insertions(+), 2 deletions(-)
drivers/ufs/Kconfig +5 -2
index a0067b1f203..648b58b46e4 100644
@@ -95,11 +95,14 @@ config UFS_TI_J721E
 config SUPPORT_UFS_RPMB
 	bool "Enable UFS RPMB (Replay Protected Memory Block) support"
 	depends on UFS && OPTEE && !SUPPORT_EMMC_RPMB
+	select BLAKE2
 	help
 	  Route OP-TEE RPMB requests to the UFS RPMB Well-Known LUN using
 	  SCSI SECURITY PROTOCOL IN/OUT commands. Required for OP-TEE secure
 	  storage (CFG_RPMB_FS) on UFS-based platforms that have no eMMC.
-	  The OP-TEE supplicant handles a single RPMB transport, so this is
-	  mutually exclusive with the eMMC RPMB supplicant (SUPPORT_EMMC_RPMB).
+	  BLAKE2 is used to derive the fixed-length RPMB CID that matches the
+	  Linux kernel UFS device_id ABI. The OP-TEE supplicant handles a
+	  single RPMB transport, so this is mutually exclusive with the eMMC
+	  RPMB supplicant (SUPPORT_EMMC_RPMB).
 
 endmenu
drivers/ufs/ufs-rpmb.c +181 -0

203 lines not on this page · raw message

include/ufs.h +6 -0
index 1bec3ce73a4..a8b7d370f78 100644
@@ -20,8 +20,14 @@ int ufs_probe(void);
  */
 int ufs_probe_dev(int index);
 
+#define UFS_RPMB_CID_SIZE	16
+#define UFS_RPMB_NUM_REGIONS	4
+
 int ufs_rpmb_route_frames(struct udevice *scsi_dev, unsigned int region,
 			  void *req, unsigned long reqlen, void *rsp,
 			  unsigned long rsplen);
 
+int ufs_rpmb_get_region_info(struct udevice *scsi_dev, unsigned int region,
+			     u8 *size_mult, u8 *rel_wr, u8 *cid);
+
 #endif
Signature · 1 line
2.54.0
#5 lore raw

PATCH v6 5/6 optee: rename rpmb.c to rpmb_emmc.c

In reply to Jorge Ramirez-Ortiz

rpmb.c implements the legacy single-command RPMB supplicant, which is eMMC-only. Rename it to rpmb_emmc.c to make room for a UFS backend.

No functional change.

---
 drivers/tee/optee/Makefile                | 2 +-
 drivers/tee/optee/{rpmb.c => rpmb_emmc.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/tee/optee/{rpmb.c => rpmb_emmc.c} (100%)
drivers/tee/optee/Makefile +1 -1
index 36ac085ef42..d0c7f8dfb12 100644
@@ -3,4 +3,4 @@
 obj-$(CONFIG_OPTEE) += core.o
 obj-y += supplicant.o
 obj-$(CONFIG_DM_I2C) += i2c.o
-obj-$(CONFIG_SUPPORT_EMMC_RPMB) += rpmb.o
+obj-$(CONFIG_SUPPORT_EMMC_RPMB) += rpmb_emmc.o
drivers/tee/optee/rpmb_emmc.c renamed from drivers/tee/optee/rpmb.c +0 -0
similarity index 100%
rename from drivers/tee/optee/rpmb.c
rename to drivers/tee/optee/rpmb_emmc.c
Signature · 1 line
2.54.0
#6 lore raw

PATCH v6 6/6 optee: implement the RPMB subsystem interface for UFS

In reply to Jorge Ramirez-Ortiz

The legacy RPMB supplicant assumes an eMMC device and derives the key from an eMMC-shaped device ID, so it can never reproduce the key Linux derives for a UFS device. Secure storage on UFS-only platforms instead needs the transport-agnostic RPMB subsystem interface, through which the normal world describes the real RPMB device to OP-TEE.

Add a UFS backend for it so OP-TEE derives a key matching Linux and can use RPMB secure storage on UFS. eMMC keeps using the legacy interface.

---
 drivers/tee/optee/Makefile               |   1 +
 drivers/tee/optee/optee_msg_supplicant.h |   6 +
 drivers/tee/optee/optee_private.h        |  41 +++++++
 drivers/tee/optee/rpmb_ufs.c             | 141 +++++++++++++++++++++++
 drivers/tee/optee/supplicant.c           |   9 ++
 drivers/ufs/Kconfig                      |   8 ++
 6 files changed, 206 insertions(+)
 create mode 100644 drivers/tee/optee/rpmb_ufs.c
drivers/tee/optee/Makefile +1 -0
index d0c7f8dfb12..f2af10999a9 100644
@@ -4,3 +4,4 @@ obj-$(CONFIG_OPTEE) += core.o
 obj-y += supplicant.o
 obj-$(CONFIG_DM_I2C) += i2c.o
 obj-$(CONFIG_SUPPORT_EMMC_RPMB) += rpmb_emmc.o
+obj-$(CONFIG_SUPPORT_UFS_RPMB) += rpmb_ufs.o
drivers/tee/optee/optee_msg_supplicant.h +6 -0
index 963cfd47824..a7b569d3e54 100644
@@ -152,6 +152,12 @@
  */
 #define OPTEE_MSG_RPC_CMD_I2C_TRANSFER 21
 
+#define OPTEE_MSG_RPC_CMD_RPMB_PROBE_RESET	22
+#define OPTEE_MSG_RPC_CMD_RPMB_PROBE_NEXT	23
+#define OPTEE_MSG_RPC_CMD_RPMB_FRAMES		24
+
+#define OPTEE_RPC_RPMB_UFS		1
+
 /*
  * Was OPTEE_MSG_RPC_CMD_SQL_FS, which isn't supported any longer
  */
drivers/tee/optee/optee_private.h +41 -0

59 lines not on this page · raw message

drivers/tee/optee/rpmb_ufs.c new file +141 -0

141 lines not on this page · raw message

drivers/tee/optee/supplicant.c +9 -0
index 8a426f53ba8..50b780037fb 100644
@@ -89,6 +89,15 @@ void optee_suppl_cmd(struct udevice *dev, struct tee_shm *shm_arg,
 	case OPTEE_MSG_RPC_CMD_RPMB:
 		optee_suppl_cmd_rpmb(dev, arg);
 		break;
+	case OPTEE_MSG_RPC_CMD_RPMB_PROBE_RESET:
+		optee_suppl_cmd_rpmb_probe_reset(dev, arg);
+		break;
+	case OPTEE_MSG_RPC_CMD_RPMB_PROBE_NEXT:
+		optee_suppl_cmd_rpmb_probe_next(dev, arg);
+		break;
+	case OPTEE_MSG_RPC_CMD_RPMB_FRAMES:
+		optee_suppl_cmd_rpmb_frames(dev, arg);
+		break;
 	case OPTEE_MSG_RPC_CMD_I2C_TRANSFER:
 		optee_suppl_cmd_i2c_transfer(arg);
 		break;
drivers/ufs/Kconfig +8 -0
index 648b58b46e4..f174ca0841d 100644
@@ -105,4 +105,12 @@ config SUPPORT_UFS_RPMB
 	  single RPMB transport, so this is mutually exclusive with the eMMC
 	  RPMB supplicant (SUPPORT_EMMC_RPMB).
 
+config UFS_RPMB_CONTROLLER
+	int "UFS controller index used for RPMB"
+	depends on SUPPORT_UFS_RPMB
+	default 0
+	help
+	  Index of the RPMB-owning UFS controller in the UCLASS_UFS device
+	  list. Leave at 0 unless the board has more than one UFS controller.
+
 endmenu
Signature · 1 line
2.54.0
#7 lore raw
In reply to Jorge Ramirez-Ortiz

Hi,

Quoted 16 lines · Jorge Ramirez-Ortiz

OP-TEE secure storage (CFG_RPMB_FS) relies on an RPMB partition, but U-Boot's OP-TEE RPMB supplicant only speaks the legacy single-command interface, which is bound to eMMC. SoCs that are UFS-only and have no eMMC (for example the Qualcomm SA8775P) therefore cannot back OP-TEE secure storage from U-Boot today. This series adds that support.

It introduces the transport-agnostic OP-TEE RPMB "subsystem" interface (PROBE_RESET / PROBE_NEXT / FRAMES), where the normal world enumerates the RPMB device and reports its kind, size and CID, then carries the signed frames. The legacy eMMC supplicant is preserved unchanged, only renamed to rpmb_emmc.c, with the new UFS backend added as a separate rpmb_ufs.c; the two are mutually exclusive via Kconfig (SUPPORT_UFS_RPMB depends on !SUPPORT_EMMC_RPMB) because the OP-TEE supplicant handles a single RPMB transport. The subsystem interface is UFS-only for now; eMMC can be migrated onto it later as the legacy path is retired.

Quoted 1 line

[...]

Thanks, Applied to https://git.u-boot-project.org/u-boot/custodians/neil.armstrong/u-boot-ufs (u-boot-ufs-next)

[1/6] ufs: decode string descriptors as UTF-16 big-endian

      https://git.u-boot-project.org/u-boot/custodians/neil.armstrong/u-boot-ufs/-/commit/01c4857ccc5d2a04e8c522335308b08c9027f4b3
[2/6] ufs: surface sense data from ufs_scsi_exec()
      https://git.u-boot-project.org/u-boot/custodians/neil.armstrong/u-boot-ufs/-/commit/768aa39691e031acfa53cd7b8bf119e4527cdfb8
[3/6] ufs: add RPMB transport over SCSI SECURITY PROTOCOL
      https://git.u-boot-project.org/u-boot/custodians/neil.armstrong/u-boot-ufs/-/commit/b3cd7ddbbdd57fc4788b7117bf60523cddd90bd8
[4/6] ufs: derive the per-region RPMB CID and size for OP-TEE
      https://git.u-boot-project.org/u-boot/custodians/neil.armstrong/u-boot-ufs/-/commit/87094d8062bdda5b5e45a35d9320b40647e12593
[5/6] optee: rename rpmb.c to rpmb_emmc.c
      https://git.u-boot-project.org/u-boot/custodians/neil.armstrong/u-boot-ufs/-/commit/20334a6bfdc4dcc061925197cb1ccff4d95ddb2c
[6/6] optee: implement the RPMB subsystem interface for UFS
      https://git.u-boot-project.org/u-boot/custodians/neil.armstrong/u-boot-ufs/-/commit/3b39df3bc540dbc8d60d54570673b25d6698153a
Signature · 1 line
Neil