Skip to main content
SYun.5
Visitor II
April 12, 2023
Question

How to read OTP with NVMEM kernel space API ( NVMEM providers and NVMEM consumers).

  • April 12, 2023
  • 1 reply
  • 2070 views

I'm now trying to read OTP 13~15 from remoteproc driver to enc/decrypt m4 firmware.


_legacyfs_online_stmicro_images_0693W00000bhtyLQAQ.pngFrom NVMEM overview. I learn below information

  1. OTP 13~15 are non-secured area​
  2. The name of device is "stm32-romem0"
  3. NVMEM kernel API


_legacyfs_online_stmicro_images_0693W00000bhuKLQAY.png
_legacyfs_online_stmicro_images_0693W00000bhuPHQAY.pngI can successfully get OTP 13~15 from user space.

To get OTP 13~15 in linux kernel I write code that read nvmem device with the NVMEM kernel API.

I define a match function​​

int rproc_nvmem_match(struct device *dev, const void *data){

const char *device_name = dev_name(dev);

const char *p_name = data;

int length = strlen(p_name);

if (memcmp(p_name, device_name, length) != 0) return 0;

return 1;

}

​Then, use nvmem_device_find and nvmem_device_read to read OTP 13~15. ( I use offset both 0x5C005234 and 0x234. )

u8 *buf_uniqueId;

buf_uniqueId = kmalloc(24, GFP_KERNEL);

struct nvmem_device *nvmem = nvmem_device_find("stm32-romem0", rproc_nvmem_match);

int err = nvmem_device_read(nvmem, 0x234, 24, (void*)buf_uniqueId);

if (!nvmem)

printk("nvmem error");

printk("err : %d", err);

But I can't get OTP 13~15. I get "err : -22" from minicom.

I don't know which part is wrong. Is there any configuration to use nvmem driver or my code is wrong?

Can you give me a example code to read OTP from linux kernel?

This topic has been closed for replies.

1 reply

PatrickF
ST Employee
May 10, 2023

Hi @SYun.5​ 

does this page helps ?

https://wiki.st.com/stm32mpu/wiki/OP-TEE_OTP_overview

Regards.

In order to give better visibility on the answered topics, please click on 'Best Answer' on the reply which solved your issue or answered your question.Tip of the day: Try Sidekick STM32 AI agent