HowTo write Mac Address in EEPROM

Started by Morzilla, September 21, 2013, 12:22:42 PM

Previous topic - Next topic

Morzilla

Hello! I need to generate a unique code for every Olinuxino A10S Board for an activation system. I need a static property, such as Mac Address or CPU Serial, but in both of this cases, there are some problems: Firts, the mac address change on every boot (the EMAC Chip does not store a static mac address) and the Serial CPU Number is 000000000. I know that I can store a static Mac Address entry in script.bin, but this is NOT a secure method for what I want to do (you can copy the script.bin from one board to another to clone the only thing that I use for the licenze key).

Maybe can you help me how to write the mac address (or any other string) in the 2Kb EEPROM?

Thanks!

Morzilla

@ Olimex:

Please, can you answer to my question, I need to know how to read/write the 2Kb EEPROM on Olinuxino A10S with Debian, because there isn't documentation about this feature.

Thanks!

Zaccheo

@Olimex
Why you say "2KB EEPROM for MAC address storage and more" in specs if you cannot help us to use it?

olimex

EEPROM is connected to I2C! so you read/write to it via I2C with I2CTOOL for inatance

selfbg

You could use i2c-tools:

#apt-get install i2c-tools


Then use:

#i2cdetect -y -r 1

You will see some devices: 0x50, 0x51, 0x52....

The EEPROM is at address 0x50.

To store some data use:

#i2cset -y -f 1 0x50 <register> <data>


And to read data:

#i2cget -y -f 2 0x50 <register> c


Now some explanation:
1 - this is the i2c-bus (/dev/i2c-1)
0x50 - the address of the EEPROM
<register> - some register, for example 0x55
<data> - some data, for example 0xFF
c - this means that the device first write register, then read

For more info view:

#i2cdetect
#i2cget
#i2cset


And:
http://www.atmel.com/Images/doc3256.pdf

Zaccheo

Many thanks to Olimex and Selfbg for the example!

Morzilla


mindrunner

#7
Hi! :)
Unfortunately this is not working for me! I have got two uImages with different behaviour.


root@a10s-10:~# uname -a
Linux a10s-10 3.0.76+ #5 PREEMPT Thu Jun 13 10:32:41 EEST 2013 armv7l GNU/Linux

This one is copied from some prebuild images and is always genarating a random MAC Address while booting.



root@a10s-10:~# uname -a
Linux a10s-10 3.4.43+ #5 PREEMPT Sun Aug 11 01:08:16 CEST 2013 armv7l GNU/Linux

This one is self compiled and always has a fixed MAC address. While booting it tells me:
Quotesunxi_emac Using MAC from SID: xx:xx:xx:xx:xx:xx


Both are ignoring my EEPROM settings. Maybe I am missing something?

Thanks!


Edit:
Well, I found out that there was a patch in 3.4 for generating a unique and fixed MAC Address from SID. So this explains the different behaviour. But if I want to use a different one, I have to store it in EEPROM.

My stock EEPROM looks like this:
root@a10s-10:~# i2cdump -y -f 1 0x50
No size specified (using byte-data access)
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
10: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
20: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
30: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
40: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
50: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
60: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
70: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
80: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
90: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
a0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
b0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
c0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
d0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
e0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ................
f0: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff    ...............


Where exactly has the MAC address to be saved? I tried to set it at the beginning. I also tried to modify every byte of the EEPROM, but every time the address is auto generated.

What am I missing here?


olimex

you should use the EEPROM as storage, i.e. not only to store the MAC address there, but later to read it and set it from what you read
writing some MAC address in the EEPROM will not lead to automatically MAC address set!

mindrunner

Yeah, was thinking about this. Then everything is fine. Thanks! :)