Skip to main content
Visitor II
August 1, 2022
Solved

How to read otp register in linux?

  • August 1, 2022
  • 3 replies
  • 2642 views

I need to store a password for encryption in otp registers. I configured device tree in tfa:

&bsec{

status = "okay";

secure-status = "okay";

enc_pass: enc_pass@0x170 {

 reg = <0x170 0x10>;

 st,non-secure-otp;

 };

};

&nvmem_layout {

    nvmem-cells = <&enc_pass>;

    nvmem-cell-names = "enc_pass";

};

And in uboot and kernel:

&bsec{

status = "okay";

enc_pass: enc_pass@0x170 {

 reg = <0x170 0x10>;

 st,non-secure-otp;

 };

};

NVMEM is configured in kernel defconfig. I can read and write to set otp register in uboot, but i cant read data in linux.

I tried this:

hexdump -C -v /sys/bus/nvmem/devices/stm32-romem0/nvmem

and

dd if=/sys/bus/nvmem/devices/stm32-romem0/nvmem of=/tmp/file

And i have that error:

stm32-romem 5c005000.efuse: Can't read data32 (-5)

hexdump: /sys/bus/nvmem/devices/stm32-romem0/nvmem: Input/output error

    This topic has been closed for replies.
    Best answer by OlivierK

    Hi MJerm.1 (Community Member)

    If you are using OpenSTLinux DV3.1 then you should point to the previous wiki version:

    https://wiki.st.com/stm32mpu-ecosystem-v3/wiki/NVMEM_overview#How_to_read_BSEC_lower_OTPs_using_NVMEM

    Using the DV3.1 version, and the wiki 3.1, I can read upper OTP from linux as OTP57 is by default unprotected in the BSEC on DK2 board.

    root@stm32mp1:~# dd if=/sys/bus/nvmem/devices/stm32-romem0/nvmem of=/tmp/file sk

    ip=57 bs=4 count=2 status=none                          

    root@stm32mp1:~# hexdump -C -v /tmp/file 

    00000000 00 80 e1 42 7c d1 00 00              |...B|...| 

    Also, no issues found with the starter package DV4.0 /OP-TEE image and the current wiki, with the hexdump command.

    root@stm32mp1:~# hexdump -C -v /sys/bus/nvmem/devices/stm32-romem0/nvmem 

    00000000 17 00 00 00 80 80 00 00 00 00 20 a0 00 00 00 00 |.......... .....|

    00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    00000030 ed f0 f5 7c 2a 00 34 00 18 51 38 34 38 32 38 36 |...|*.4..Q848286|

    00000040 e1 75 95 12 65 13 31 3b 40 01 85 7a 1a 14 bd 06 |.u..e.1;@..z....|

    00000050 3b 00 f2 5d 00 00 00 00 00 00 00 00 6e 30 16 40 |;..]........n0.@|

    00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000e0 00 00 00 00 00 80 e1 42 7c ed 00 00 02 43 72 12 |.......B|....Cr.|  

    000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000180 

    After unprotecting all the upper OTP...

    root@stm32mp1:~# hexdump -C -v /sys/bus/nvmem/devices/stm32-romem0/nvmem     

    00000000 17 00 00 00 80 80 00 00 00 00 20 a0 00 00 00 00 |.......... .....|  

    00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000030 ed f0 f5 7c 2a 00 34 00 18 51 38 34 38 32 38 36 |...|*.4..Q848286|  

    00000040 e1 75 95 12 65 13 31 3b 40 01 85 7a 1a 14 bd 06 |.u..e.1;@..z....|  

    00000050 3b 00 f2 5d 00 00 00 00 00 00 00 00 6e 30 16 40 |;..]........n0.@|  

    00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000a0 4d 4c 9b a0 00 ba 21 1d 92 89 ac fb 5a a4 0f 28 |ML....!.....Z..(|  

    000000b0 49 8f 2f b0 8d 8d 2c bd c6 39 c1 af df ac e7 7a |I./...,..9.....z|  

    000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000e0 00 00 00 00 00 80 e1 42 7c ed 00 00 00 00 00 00 |.......B|.......|  

    000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000180                                   

    3 replies

    OlivierKAnswer
    Technical Moderator
    August 2, 2022

    Hi MJerm.1 (Community Member)

    If you are using OpenSTLinux DV3.1 then you should point to the previous wiki version:

    https://wiki.st.com/stm32mpu-ecosystem-v3/wiki/NVMEM_overview#How_to_read_BSEC_lower_OTPs_using_NVMEM

    Using the DV3.1 version, and the wiki 3.1, I can read upper OTP from linux as OTP57 is by default unprotected in the BSEC on DK2 board.

    root@stm32mp1:~# dd if=/sys/bus/nvmem/devices/stm32-romem0/nvmem of=/tmp/file sk

    ip=57 bs=4 count=2 status=none                          

    root@stm32mp1:~# hexdump -C -v /tmp/file 

    00000000 00 80 e1 42 7c d1 00 00              |...B|...| 

    Also, no issues found with the starter package DV4.0 /OP-TEE image and the current wiki, with the hexdump command.

    root@stm32mp1:~# hexdump -C -v /sys/bus/nvmem/devices/stm32-romem0/nvmem 

    00000000 17 00 00 00 80 80 00 00 00 00 20 a0 00 00 00 00 |.......... .....|

    00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    00000030 ed f0 f5 7c 2a 00 34 00 18 51 38 34 38 32 38 36 |...|*.4..Q848286|

    00000040 e1 75 95 12 65 13 31 3b 40 01 85 7a 1a 14 bd 06 |.u..e.1;@..z....|

    00000050 3b 00 f2 5d 00 00 00 00 00 00 00 00 6e 30 16 40 |;..]........n0.@|

    00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|

    000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000e0 00 00 00 00 00 80 e1 42 7c ed 00 00 02 43 72 12 |.......B|....Cr.|  

    000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000180 

    After unprotecting all the upper OTP...

    root@stm32mp1:~# hexdump -C -v /sys/bus/nvmem/devices/stm32-romem0/nvmem     

    00000000 17 00 00 00 80 80 00 00 00 00 20 a0 00 00 00 00 |.......... .....|  

    00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000030 ed f0 f5 7c 2a 00 34 00 18 51 38 34 38 32 38 36 |...|*.4..Q848286|  

    00000040 e1 75 95 12 65 13 31 3b 40 01 85 7a 1a 14 bd 06 |.u..e.1;@..z....|  

    00000050 3b 00 f2 5d 00 00 00 00 00 00 00 00 6e 30 16 40 |;..]........n0.@|  

    00000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000a0 4d 4c 9b a0 00 ba 21 1d 92 89 ac fb 5a a4 0f 28 |ML....!.....Z..(|  

    000000b0 49 8f 2f b0 8d 8d 2c bd c6 39 c1 af df ac e7 7a |I./...,..9.....z|  

    000000c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000d0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    000000e0 00 00 00 00 00 80 e1 42 7c ed 00 00 00 00 00 00 |.......B|.......|  

    000000f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000100 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000110 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000120 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000130 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000140 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000150 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000160 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000170 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|  

    00000180                                   

    MJerm.1Author
    Visitor II
    August 4, 2022

    Thank you, it helped, I didn't notice that the version had already changed

    Technical Moderator
    August 4, 2022

    In order to give better visibility on the answered topics, please click on 'Select as Best' on the reply which solved your issue or answered your question. See also 'Best Answers'