Read and Write OTP register from linux

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Read and Write OTP register from linux

Jump to solution
9,069 Views
dgotfroi
Contributor IV

Hello,

I'm working on a project using IMX28.

For this project, I would like to store (On chip and not in the SD Card memory) the serial number of my board and an crypto key (not for secure boot, only for communication cryptography).

I think On-Chip OTP can do the trick.

But I would like to know how to read and write OTP registers directly from embedded linux ?

I'm using Freescale Yocto dizzy for the compilation (https://github.com/Freescale/fsl-community-bsp-platform -b dizzy).

Many thanks for your help,

Damien

Labels (3)
Tags (2)
0 Kudos
Reply
1 Solution
5,633 Views
dgotfroi
Contributor IV

Hello,

I finally used the patch from Stephan Wahren ([PATCH RFC V3 0/3] mxs: add ocotp support for i.MX23 and i.MX28 ).

I have now read only access to OCOTP in "/sys/devices/soc0/80000000.apb/80000000.apbh/8002c000.ocotp/fuses/"

Many thanks for your help, my issue is solved.

View solution in original post

0 Kudos
Reply
10 Replies
5,633 Views
Yuri
NXP Employee
NXP Employee

  You may use Linux sysfs options of Linux, for example as shown in the following

thread :

How to read i.MX6DQ unique ID.


Have a great day,
Yuri

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
5,633 Views
dgotfroi
Contributor IV

Hello,

Thanks for your answers.

Yuri, How can I use your solution ? I don't have any option for OCOTP in the virtual/kernel menuconfig, so I don't have "fsl_otp" directory in "/sys".

I use yocto dizzy.

Many thanks,

Damien

EDIT : Is HW_OCOTP_CRYPTO used for secure boot ? Or can I store an AES key in this register (not use for secure boot, only use for communication encryption). I will use secure boot in the future with another key.

0 Kudos
Reply
5,633 Views
Yuri
NXP Employee
NXP Employee

> Is HW_OCOTP_CRYPTO used for secure boot ?

Yes.

Regards,

Yuri.

0 Kudos
Reply
5,633 Views
Yuri
NXP Employee
NXP Employee

  I am afraid community BSP release does not support the OTP.
Nevertheless :

OTP can accessed via /sys/fsl_otp if enabled below kernel config:

  Device Drivers

    Character devices

      <*>Freescale On-Chip OTP Memory Support


Generally for i.MX28 it is higly recommended to use the the OTP tools.

https://www.freescale.com/webapp/Download?colCode=IMX_OPT_TOOLS&appType=license&location=null&fasp=1...

Regards,

Yuri.

0 Kudos
Reply
5,633 Views
dgotfroi
Contributor IV

Thanks for your help.

But i'm afraid, I didn't have this options in my kernel config :

Capture.PNG.png

I use BitBurner.exe from OTP tools to burn OTP fuses, but I need to read these fuses from linux.

Is there a way to burn fuses directly from linux ? I tried with memtool but it doesn't seem to work.

> Is HW_OCOTP_CRYPTO used for secure boot ?

Yes.

So I only have 128 bits to store 160 bits :smileyconfused:.

0 Kudos
Reply
5,634 Views
dgotfroi
Contributor IV

Hello,

I finally used the patch from Stephan Wahren ([PATCH RFC V3 0/3] mxs: add ocotp support for i.MX23 and i.MX28 ).

I have now read only access to OCOTP in "/sys/devices/soc0/80000000.apb/80000000.apbh/8002c000.ocotp/fuses/"

Many thanks for your help, my issue is solved.

0 Kudos
Reply
5,633 Views
emptyfridge
Contributor III

Hi there,

I'm working with kernel 4.9.21 on a i.MX28. I've configured the mxs-ocotp driver and I can read out the hexdump

from the nvmem device.

hexdump /sys/bus/platform/drivers/mxs-ocotp/8002c000.ocotp/mxs-ocotp0/nvmem
0000000 0000 0000 0000 0000 0000 0000 0000 0000
*
0000020 ffd9 c302 0000 0000 0000 0000 0000 0000
0000030 0000 0000 0000 0000 0000 0000 0000 0000
0000040 ffff c302 0000 0000 0000 0000 0000 0000
0000050 0000 0000 0000 0000 0000 0000 0000 0000
*
0000120 0000 000c 0000 0000 0000 0000 0000 0000
0000130 0000 0000 0000 0000 0000 0000 0000 0000
0000140 0105 853b 0000 0000 0000 0000 0000 0000
0000150 312e d449 0000 0000 0000 0000 0000 0000
0000160 01e3 ade5 0000 0000 0000 0000 0000 0000
0000170 0000 0000 0000 0000 0000 0000 0000 0000
*
0000190 01e3 ade5 0000 0000 0000 0000 0000 0000
00001a0 0000 0000 0000 0000 0000 0000 0000 0000
*
0000210 0000 0010 0000 0000 0000 0000 0000 0000
0000220 0000 0000 0000 0000 0000 0000 0000 0000
*
00002a0

So far so good... Now I want to write the MAC addr into the otp register. first of all, there is no implementation for a write function in the mx-ocotp.c. I've now added one, by my self. Now my question is, how can I write the in the correct way my parameters to this function...? 

I'm pretty sure there is a simple way to write this stuff....

or does anyone know a better solution for this issue?

Here is the implementation:

static int mxs_ocotp_write(void *context, unsigned int offset,
                          void *val, size_t bytes)
{
        /* We don't want to support writing */
        printk("Writing otp would be nice....!!!!!!\n");
        printk("offset: %i, value: %lu, bytes: %i ....!!!!!!\n", offset, val, bytes);
        return 0;
}               

static struct nvmem_config ocotp_config = {
        .name = "mxs-ocotp",
        .read_only = false,     
        .stride = 16,           
        .word_size = 4,         
        .owner = THIS_MODULE,
        .reg_read = mxs_ocotp_read,
        .reg_write = mxs_ocotp_write,
};

Thanks for your help.

cheers

Tom

0 Kudos
Reply
5,633 Views
saurabh206
Senior Contributor III

Hi

Damien

You can use memtool utility.

Thanks

Saurabh

0 Kudos
Reply
5,633 Views
dgotfroi
Contributor IV

Hi,

Thanks for your answer.

Is it a native embedded tool ? I can not find it either on my embedded linux, neither on the freescale BSP (on my host machine).

Many thanks,

Damien

0 Kudos
Reply
5,633 Views
saurabh206
Senior Contributor III

Hi Damien

You can build with yocto "bitbake imx-test"

Thanks

Saurabh

0 Kudos
Reply