Skip to contentSkip to conversation

firmware: ti_sci: zero the secure_hdr in do_xfer

PATCH In review Dhruva Gole 2 participants 5 messages Jan 30, 2024 – Feb 7, 2024 Texas instruments' system control interface (TISCI) protocol driver

lore
Share & tools
lore
#0 lore raw

v5 cover firmware: ti_sci: zero the secure_hdr in do_xfer

This series adds a fix to make the initial 4 bytes of the secure_hdr to be 0 as per the protocol requirement as of now. Also, inorder to provide a little more context to people add a comment to explain why secure calls are made from uboot

For context, please refer to the discussion from the first patch here:
https://lore.kernel.org/all/[email protected]/

Boot tested for sanity on AM62x SK and J721S2:
https://gist.github.com/DhruvaG2000/9ca35d1261e8b30f1c2d4a514b9cd941

Changelog:

v4 --> v5
Pick Nishanth's review and also s/sizeof(var)/sizeof(*var) in 1/2

v3 --> v4
Improve commit message in 1/2 and add comment in 2/2

v2 --> v3
Address Kamlesh's comment on v2: use sizeof(struct ti_sci_secure_msg_hdr)

v1 --> v2
Rebased on top of latest master branch

Cc Nishanth Menon <[email protected]>
Cc Tom Rini <[email protected]>
Cc Neha Francis <[email protected]>
Cc Manorit Chawdhry <[email protected]>
Cc Vignesh Raghavendra <[email protected]>
Cc Kamlesh Gurudasani <[email protected]>
Cc Andrew Davis <[email protected]>

Dhruva Gole (2):
firmware: ti_sci: fix the secure_hdr in do_xfer
firmware: ti_sci: Add comment explaining the is_secure code

 drivers/firmware/ti_sci.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

base-commit: d5c0c990c3128401810514c66b41b386096d206e
prerequisite-patch-id: 2ed0c527b6ebf850744d9ff0eca0300a125f7796

Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/2 firmware: ti_sci: fix the secure_hdr in do_xfer

The ti_sci driver in U-Boot has support for secure_msg as part of it's do_xfer function. This let's U-boot send secure messages during boot up.

The protocol to send such secure messages is described as part of the struct ti_sci_secure_msg_hdr. As part of this, there are 2 fields for checksum and reserved that occupy the first 4 bytes of any secure message. This is called as the secure_hdr.

As of now, the secure_hdr needs to be 0 init-ed before sending secure messages. However the existing code was never putting the zero-inited vars into the secure_buf, leading to possibility of the first 4 bytes of secure_buf being possibly garbage.

Fix this by initialising the secure_hdr itself to the secure_buf location, thus when we make secure_hdr members 0, it automatically ensures the first 4 bytes of secure_buf are 0.

Fixes 32cd25128bd849 ("firmware: Add basic support for TI System Control Interface (TI SCI)")
---
 drivers/firmware/ti_sci.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/firmware/ti_sci.c +6 -6
index 6e9f93e9a302..b77ac36af284 100644
@@ -236,21 +236,21 @@ static int ti_sci_do_xfer(struct ti_sci_info *info,
 {
 	struct k3_sec_proxy_msg *msg = &xfer->tx_message;
 	u8 secure_buf[info->desc->max_msg_size];
-	struct ti_sci_secure_msg_hdr secure_hdr;
+	struct ti_sci_secure_msg_hdr *secure_hdr = (struct ti_sci_secure_msg_hdr *)secure_buf;
 	int ret;
 
 	if (info->is_secure) {
 		/* ToDo: get checksum of the entire message */
-		secure_hdr.checksum = 0;
-		secure_hdr.reserved = 0;
-		memcpy(&secure_buf[sizeof(secure_hdr)], xfer->tx_message.buf,
+		secure_hdr->checksum = 0;
+		secure_hdr->reserved = 0;
+		memcpy(&secure_buf[sizeof(*secure_hdr)], xfer->tx_message.buf,
 		       xfer->tx_message.len);
 
 		xfer->tx_message.buf = (u32 *)secure_buf;
-		xfer->tx_message.len += sizeof(secure_hdr);
+		xfer->tx_message.len += sizeof(*secure_hdr);
 
 		if (xfer->rx_len)
-			xfer->rx_len += sizeof(secure_hdr);
+			xfer->rx_len += sizeof(*secure_hdr);
 	}
 
 	/* Send the message */
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH V5 1/2] firmware: ti_sci: fix the secure_hdr in do_xfer

Quoted 13 lines · Dhruva Gole

The ti_sci driver in U-Boot has support for secure_msg as part of it's do_xfer function. This let's U-boot send secure messages during boot up.

The protocol to send such secure messages is described as part of the struct ti_sci_secure_msg_hdr. As part of this, there are 2 fields for checksum and reserved that occupy the first 4 bytes of any secure message. This is called as the secure_hdr.

As of now, the secure_hdr needs to be 0 init-ed before sending secure messages. However the existing code was never putting the zero-inited vars into the secure_buf, leading to possibility of the first 4 bytes of secure_buf being possibly garbage.

Quoted 7 lines

Fix this by initialising the secure_hdr itself to the secure_buf location, thus when we make secure_hdr members 0, it automatically ensures the first 4 bytes of secure_buf are 0.

Fixes 32cd25128bd849 ("firmware: Add basic support for TI System Control Interface (TI SCI)")

Applied to u-boot/master, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH v5 2/2 firmware: ti_sci: Add comment explaining the is_secure code

In reply to Dhruva Gole

Add a comment to explain the code under is_secure condition of ti_sci_do_xfer. This will help avoid confusion amongst people who may in future touch upon this code.

---
 drivers/firmware/ti_sci.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/firmware/ti_sci.c +6 -0
index b77ac36af284..ee0921855881 100644
@@ -239,6 +239,12 @@ static int ti_sci_do_xfer(struct ti_sci_info *info,
 	struct ti_sci_secure_msg_hdr *secure_hdr = (struct ti_sci_secure_msg_hdr *)secure_buf;
 	int ret;
 
+	/*
+	 * The reason why we need the is_secure code is because of boot R5.
+	 * boot R5 starts off in "secure mode" when it hands off from Boot
+	 * ROM over to the Secondary bootloader. The initial set of calls
+	 * we have to make need to be on a secure pipe.
+	 */
 	if (info->is_secure) {
 		/* ToDo: get checksum of the entire message */
 		secure_hdr->checksum = 0;
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH V5 2/2] firmware: ti_sci: Add comment explaining the is_secure code

Quoted 6 lines · Dhruva Gole

Add a comment to explain the code under is_secure condition of ti_sci_do_xfer. This will help avoid confusion amongst people who may in future touch upon this code.

Applied to u-boot/master, thanks!

Signature · 1 line
Tom