2010-07-31 11:07:32     Compiling stand alone OTP programmer on BF522

Document created by Aaronwu Employee on Aug 22, 2013
Version 1Show Document
  • View in full screen mode

2010-07-31 11:07:32     Compiling stand alone OTP programmer on BF522

Reggy Perrin (UNITED STATES)

Message: 91961   

 

Hi folks,

 

Trying to compile a program to call bfrom_OtpRead and bfrom_OtpWrite, but need to understand how to set up  a makefile. 

 

Source code is:

 

#include <blackfin.h>

#include <bfrom.h>

main(int argc,char *argv[]) {

    u32 return_code;

    const u32 OTP_init_value = 0x1454874b;

    u64 uniqueIdUpper;

    char id_str[40];

    int len = 33;

 

    bfrom_OtpCommand(OTP_INIT, OTP_init_value);

    bfrom_OtpRead(0x004, OTP_UPPER_HALF, &unique);

    bfrom_OtpRead(0x004, OTP_LOWER_HALF, &unique);

    bfrom_OtpCommand(OTP_CLOSE, OTP_init_value);

}

 

My current error is:

 

 

 

In file included from /opt/uclinux-dist/linux-2.6.x/arch/blackfin/include/asm/blackfin.h:94,

 

                 from writeotp.c:2:

 

/opt/uclinux-dist/linux-2.6.x/arch/blackfin/include/asm/bfin-global.h:57: error: expected unqualified-id before string constant

 

Currently, I'm trying:

 

 

 

bfin-linux-uclibc-g++ -DCONFIG_BF522 -mcpu=bf522-0.2 \

     -I/opt/uclinux-dist/linux-2.6.x/include/ \

     -I/opt/uclinux-dist/linux-2.6.x/arch/blackfin/include \

     -I/opt/uclinux-dist/linux-2.6.x/arch/blackfin/include \

     -I/opt/uclinux-dist/linux-2.6.x/arch/blackfin/mach-bf527/include \

     -I/opt/uclinux-dist/linux-2.6.x/arch/blackfin/include/asm/ \

     -Wl,-rpath-link,/opt/uclinux-dist/staging/usr/lib \

     -L/opt/uclinux-dist/staging/usr/lib \

     -o writeotp writeotp.c

 

Is there an example somewhere that shows how to set up the include directories properly?

 

TIA

 

RP

QuoteReplyEditDelete

 

 

2010-07-31 12:34:02     Re: Compiling stand alone OTP programmer on BF522

Mike Frysinger (UNITED STATES)

Message: 91964   

 

what exactly do you mean by "standalone" ?

QuoteReplyEditDelete

 

 

2010-07-31 13:54:05     Re: Compiling stand alone OTP programmer on BF522

Reggy Perrin (UNITED STATES)

Message: 91965   

 

By standalone, I mean a method to read/write the OTP from a program that runs on the device. 

 

For instance, if we want to program a value to the OTP, it appears we can use:

 

    u-boot

    bfrom_OtpWrite in a program running within the system

    /dev/bfin-otp (not sure if this method would be more appropriate)

 

If option #3 is preferred, I have another set of questions:

 

From a kernel module, we can read OTP register 0x004 (the Blackfin chip ID, I believe).  The relevant lines are:

 

    return_code = bfrom_OtpRead(0x004, OTP_UPPER_HALF, &uniqueIdUpper);

    return_code = bfrom_OtpRead(0x004, OTP_LOWER_HALF, &uniqueIdLower);

 

However, when using /dev/bfin-otp, we must use:

 

dd if=/dev/bfin-otp of=otp.bin bs=8 skip=8 count=2; hexdump otp.bin

 

I don't quite understand how skip=8 equates to register 0x004.  I got that value from trial/error, and comparing the output from the kernel module (using bfrom_OtpRead, which I assume is correct).

 

When using fopen(), the following (determined empirically) works:

 

    fp = fopen("/dev/bfin-otp","rb");

    fseek( fp,0x040,SEEK_SET );

    fread( (char*)&uniqueLower,8,1,fp );

        fread( (char*)&uniqueUpper,8,1,fp );

 

So, can I assume that each register's offset within /dev/bfin-otp is 0x10 * register?  i.e. if I wanted to use CPS 0x18, that would be offset 0x180 in the /dev/bfin-otp?

 

RP

QuoteReplyEditDelete

 

 

2010-07-31 13:59:24     Re: Compiling stand alone OTP programmer on BF522

Reggy Perrin (UNITED STATES)

Message: 91966   

 

Also, if we use /dev/bfin-otp, how do we issue this command:

 

bfrom_OtpWrite(0x01C, OTP_LOCK, NULL);

 

to lock that register?

 

RP

QuoteReplyEditDelete

 

 

2010-07-31 13:59:53     Re: Compiling stand alone OTP programmer on BF522

Mike Frysinger (UNITED STATES)

Message: 91967   

 

if you want to access OTP from Linux userspace, the only supported option is /dev/bfin-otp

 

the bfin-otp interface operates on bytes, not pages.  the bfrom funcs operate on pages, not bytes.

 

have you read the documentation ?

  docs.blackfin.uclinux.org/doku.php?id=otp

QuoteReplyEditDelete

 

 

2010-07-31 14:03:28     Re: Compiling stand alone OTP programmer on BF522

Mike Frysinger (UNITED STATES)

Message: 91968   

 

ioctl(fd, OTPLOCK, 0x01C)

 

QuoteReplyEditDelete

 

 

2010-07-31 14:07:13     Re: Compiling stand alone OTP programmer on BF522

Reggy Perrin (UNITED STATES)

Message: 91969   

 

Thanks, MIke.

 

Final question, I assumed that OTP meant I had one shot.  Is it reprogrammable until we execute the command above?  I.e. do I have 1 chance/part to get it right, or do I have the chance to try again?

 

RP

QuoteReplyEditDelete

 

 

2010-07-31 14:19:09     Re: Compiling stand alone OTP programmer on BF522

Mike Frysinger (UNITED STATES)

Message: 91970   

 

whatever the HRM says.  the Linux driver is merely glue between userspace and the bfrom functions.

 

iirc (it's been a while since i messed with OTP, in practice, you can keep "writing" in that you can turn 0's to 1's (or maybe it was the other way around), but the crc field will only work with one write.  after that, the crc wont match, so while the content may still be there, the crc sanity check will fail.

QuoteReplyEditDelete

 

 

2010-08-01 01:08:40     Re: Compiling stand alone OTP programmer on BF522

Reggy Perrin (UNITED STATES)

Message: 91972   

 

Hi Mike,

 

Making some progress, but seem to be at a roadblock.  Code:

 

 

 

fp = open("/dev/bfin-otp",O_RDWR|O_NONBLOCK);

lseek( fp,REGISTER * 0x10,SEEK_SET );

ioctl(fp, MEMUNLOCK, REGISTER);

write( fp,(char*)&serial,sizeof(serial) );

ioctl(fp, MEMLOCK, REGISTER);

close(fp);

 

The debug output is:

 

[   68.800000] bfin_otp_ioctl:176: here i am

[   68.800000] bfin_otp_write:135: here i am

[   68.810000] bfin_otp_write:150: processing page 29 (0x80:lower) from 0285e39c

[   68.820000] bfin_otp_write:157: error from otp: 0x21

[   68.840000] bfin_otp_ioctl:176: here i am

[   68.840000] bfin_otp_ioctl:176: here i am

[   68.850000] bfin_otp_read:45: here i am

[   68.850000] bfin_otp_read:58: processing page 29 (0x0:lower)

 

So, the error 0x21 is OTP_ECC_MULT_ERROR.  I get it seemingly on any register I try, between 0x019 and 0x0DF (I haven't tried every register, but have tried some in each section). 

 

Am I missing a step?  Did I miss something in the documentation?

 

TIA

 

RP

QuoteReplyEditDelete

 

 

2010-08-01 02:56:38     Re: Compiling stand alone OTP programmer on BF522

Mike Frysinger (UNITED STATES)

Message: 91974   

 

if you dump the contents of 0x19..0xDF, what do you see ?

 

how about the CRC ranges 0xE0..0xFF ?

 

you've also made sure that all of your voltage settings are well within the documented ranges for writing right ?  the electrical requirements for writing are much more strict than for reading.

QuoteReplyEditDelete

 

 

2010-08-01 09:14:42     Re: Compiling stand alone OTP programmer on BF522

Reggy Perrin (UNITED STATES)

Message: 91985   

 

Mike,

 

I will be checking the hardware shortly.  When I read the OTP, I am reading all 0's for that entire range (I'm getting the same data with both /dev/bfin-otp and when I do a "otp read 0x50000 0x18 455" from u-boot).

 

RP

QuoteReplyEditDelete

 

 

2010-08-01 09:25:37     Re: Compiling stand alone OTP programmer on BF522

Mike Frysinger (UNITED STATES)

Message: 91986   

 

u-boot's otp command also can write/lock if you want to test with that

QuoteReplyEditDelete

 

 

2010-08-01 09:32:38     Re: Compiling stand alone OTP programmer on BF522

Reggy Perrin (UNITED STATES)

Message: 91987   

 

Mike,

 

I feel like an idiot -- We're using the 522, and thus have to have the VPPOTP = 7V.  I don't have the hardware support to write the OTP at this time, argh.

 

Thanks so much for all your help. 

 

RP

QuoteReplyEditDelete

 

 

2010-08-01 17:48:54     Re: Compiling stand alone OTP programmer on BF522

Mike Frysinger (UNITED STATES)

Message: 91988   

 

this is why some people try and get the part programmed ahead of time ... so they dont need the higher voltage on the actual board that otherwise would be wasteful.  not sure how practical this is for you though.  i'm sure someone gets to figure it out ;).

Attachments

    Outcomes