[PATCH 2/6] stm32mp: cmd_stm32key: add support of OTP key format 2
Patrice Chotard
patrice.chotard at foss.st.com
Wed Feb 4 11:20:47 CET 2026
From: Thomas Bourgoin <thomas.bourgoin at foss.st.com>
Add support of OTP key format 2 used by OP-TEE.
Key formats are describes in the STM32MPUs references manuals
section OTP mapping.
Signed-off-by: Thomas Bourgoin <thomas.bourgoin at foss.st.com>
Signed-off-by: Patrice Chotard <patrice.chotard at foss.st.com>
---
arch/arm/mach-stm32mp/cmd_stm32key.c | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/arch/arm/mach-stm32mp/cmd_stm32key.c b/arch/arm/mach-stm32mp/cmd_stm32key.c
index 1ceb640e6b2..cd539a626d1 100644
--- a/arch/arm/mach-stm32mp/cmd_stm32key.c
+++ b/arch/arm/mach-stm32mp/cmd_stm32key.c
@@ -41,6 +41,7 @@ struct stm32key {
u16 start;
u8 size;
int (*post_process)(struct udevice *dev, const struct stm32key *key);
+ u32 (*key_format)(u32 value);
};
const struct stm32key stm32mp13_list[] = {
@@ -69,6 +70,8 @@ const struct stm32key stm32mp15_list[] = {
static int post_process_oem_key2(struct udevice *dev, const struct stm32key *key);
static int post_process_edmk_128b(struct udevice *dev, const struct stm32key *key);
+static u32 format1(u32 value);
+static u32 format2(u32 value);
const struct stm32key stm32mp21_list[] = {
[STM32KEY_PKH] = {
@@ -268,6 +271,24 @@ static const struct otp_close *get_otp_close_state(u8 index)
return &stm32mp2x_close_state_otp[index];
}
+/*
+ * Define format wrappers based on reference manual formats
+ * ex for key from NIST vector AES_ECB_256b_test0:
+ * key (bytes) : f9 e8 38 9f ... ef 94 4b e0
+ * format 1 (le32) : 0xf9e8389f ... 0xef944be0
+ * format 2 (le32) : 0x9f38e8f9 ... 0xe04b94ef
+ */
+
+static u32 format1(u32 value)
+{
+ return __be32_to_cpu(value);
+}
+
+static u32 __maybe_unused format2(u32 value)
+{
+ return __le32_to_cpu(value);
+}
+
static int get_misc_dev(struct udevice **dev)
{
int ret;
@@ -282,10 +303,15 @@ static int get_misc_dev(struct udevice **dev)
static void read_key_value(const struct stm32key *key, unsigned long addr)
{
int i;
+ u32 (*format)(u32) = format1;
+
+ /* Use key_format function pointer if defined */
+ if (key->key_format)
+ format = key->key_format;
for (i = 0; i < key->size; i++) {
printf("%s OTP %i: [%08x] %08x\n", key->name, key->start + i,
- (u32)addr, __be32_to_cpu(*(u32 *)addr));
+ (u32)addr, format(*(u32 *)addr));
addr += 4;
}
}
@@ -456,9 +482,14 @@ static int fuse_key_value(struct udevice *dev, const struct stm32key *key, unsig
{
u32 word, val;
int i, ret;
+ u32 (*format)(u32) = format1;
+
+ /* Use key_format function pointer if defined */
+ if (key->key_format)
+ format = key->key_format;
for (i = 0, word = key->start; i < key->size; i++, word++, addr += 4) {
- val = __be32_to_cpu(*(u32 *)addr);
+ val = format(*(u32 *)addr);
if (print)
printf("Fuse %s OTP %i : %08x\n", key->name, word, val);
--
2.43.0
More information about the U-Boot
mailing list