world leader in high performance signal processing
Trace:

Differences

This shows you the differences between two versions of the page.

otp [2009/03/23 14:13]
rgetz Writing is supported - so remove the note.
otp [2010/07/31 20:15] (current)
vapier document the write/lock ioctls
Line 43: Line 43:
 A simple character device driver has been created so you can read/write OTP memory from user space.  The driver can be found at ''linux-2.6.x/drivers/char/bfin-otp.c''. A simple character device driver has been created so you can read/write OTP memory from user space.  The driver can be found at ''linux-2.6.x/drivers/char/bfin-otp.c''.
  
-First enable the driver in your kernel configuration menu:+First enable the driver in your kernel configuration menu.  Obviously, you should only enable writing support if you intend on writing OTP.
 <code> <code>
 Device Drivers  ---> Device Drivers  --->
   Character devices  --->   Character devices  --->
     <*> Blackfin On-Chip OTP Memory Support     <*> Blackfin On-Chip OTP Memory Support
-    [*]   Enable writing support of OTP pages+    [ ]   Enable writing support of OTP pages
 </code> </code>
  
Line 56: Line 56:
 </code> </code>
  
-Then to access the OTP memory, just open ''/dev/bfin-otp'' and use it like a normal character device.  Make sure you only do reads/writes in 64 bit increments (8 bytes), and you can use the standard seek functions to select the half page you want to start reading from.+Then to access the OTP memory, just open ''/dev/bfin-otp'' and use it like a normal character device.  Make sure you only do reads/writes in 64 bit increments (8 bytes or 1 half page), and you can use the standard seek functions to select the half page (in units of bytes) you want to start reading from.
  
 A quick example is to use ''dd'' to read the OTP memory: A quick example is to use ''dd'' to read the OTP memory:
Line 67: Line 67:
 </code> </code>
  
-Notice how the block size was set to 8 bytes (or 64 bits).  Any other increment will result in an error.+Notice how the block size was set to 8 bytes (or 64 bits).  Any other increment will result in an error since the ROM functions only support reading in chunks of half pages. 
 + 
 +==== Writing ==== 
 + 
 +Before you can write to the device, you have to initiate a simple unlock ioctl.  This is to prevent inadvertent writes and has no relation to the ''OTP_LOCK'' operation.  Once you've opened the device and have a file descriptor, issue: 
 +<code c> 
 +#include <sys/ioctl.h> 
 +#include <mtd/mtd-abi.h> 
 +... 
 +    ioctl(fd, MEMUNLOCK); 
 +</code> 
 + 
 +Then use the normal ''write'' and ''lseek'' functions to write out data.  The same limitation mentioned above with valid lengths applies here as well.  You can only program half-pages at a time, so it is up to you to handle this.  The kernel will not split up/overlay writes for you. 
 + 
 +Conversely, once you've finished writing, you should inform the kernel by doing: 
 +<code c>ioctl(fd, MEMLOCK);</code> 
 + 
 +==== Page Locking ==== 
 + 
 +If you wish to lock a page in OTP (the ''OTP_LOCK'' operation), then you can use the ''OTPLOCK'' ioctl: 
 +<code c> 
 +#include <sys/ioctl.h> 
 +#include <mtd/mtd-abi.h> 
 +... 
 +    ioctl(fd, OTPLOCK, 0x1C); 
 +</code> 
 + 
 +This will lock page ''0x1C'' in OTP.