Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => A20 => Topic started by: chargrilled on January 03, 2015, 02:06:16 PM

Title: Make my MAC address static/fixed using EEPROM
Post by: chargrilled on January 03, 2015, 02:06:16 PM
Hi all,

OK so pretty much what the subject says. 

I have an A20-OLinuXIno-LIME2 which I really do like however I would like to have a couple more and have them use DHCP reservations.  The only issue is the MAC address is being generated on each boot.

At this point I would like to quote part of the LIME2 "feature" list - "2KB EEPROM for MAC address storage and more"

Having looked though this forum and others I am very confused.  How exactly do I use the EEPROM (on I2C-1 0x50-0x57) to configure the MAC for the Linux kernel to us?  What if I bought some MAC addresses how do I get the board to use them??

I am open to other suggestions on how to fix the MAC address as long as the MAC address is not stored on SD/USB/SATA device etc.  So other hardware options are OK as long as I can clone the Linux setup and the boards all retain their own MACs.

Thanks
Title: Re: Make my MAC address static/fixed using EEPROM
Post by: nickvanalst on March 05, 2015, 11:51:48 AM
I would be very interested in this as well.

We are using the SOM with our own board, so we will need to probably integrate the EEPROM our self.
But it would be nice to have some general direction of how it should be implemented!
Title: Re: Make my MAC address static/fixed using EEPROM
Post by: progmetalbg on March 05, 2015, 05:18:31 PM
https://www.olimex.com/forum/index.php?topic=1900.0
http://linux-sunxi.org/Ethernet#Setting_the_MAC_address - software way (not using EEPROM)
Title: Re: Make my MAC address static/fixed using EEPROM
Post by: chargrilled on March 29, 2015, 05:48:49 PM
Thanks progmetalbg.

Little irritating that the Lime2 doesnt have a SID and there isnt a jumper to let us burn one.  hey I still love the board  :).

So if I want to use a single image for multiple boards I guess the only real option is to stop the eth0 coming up on boot (upsets some corporate networks and security teams that audit MACs).  Then on boot read the EEPROM - if blank generate a MAC in one area of the EEPROM and then use that to bring up the eth0.
Title: Re: Make my MAC address static/fixed using EEPROM
Post by: ejsanyo on December 11, 2016, 07:38:54 PM
I successfully made MAC address static by editing /etc/network/interfaces like this:
auto eth0
iface eth0 inet dhcp
hwaddress ether xx:xx:xx:xx:xx:xx

Where "xx" is your MAC
Title: Re: Make my MAC address static/fixed using EEPROM
Post by: sylvain on December 30, 2016, 11:22:12 AM
Hello

There's some interesting infos in https://www.olimex.com/forum/index.php?topic=1900.0 but I've still hasn't found a clear explanation on when and how we should read the MAC from EEPROM and configure it in the network interface.

I have previously used /etc/network/interfaces to set the MAC on OLinuXinos without EEPROM, it it works ok, but that means the MAC is bound to a file in the SD card instead a being bound to the hardware, and this is not how it should be done.

Assuming EEPROM contains the MAC address, and that I want the network interface to be properly configured before DHCP starts:

I'm willing to try stuff, but some general directions would be appreciated :)
Title: Re: Make my MAC address static/fixed using EEPROM
Post by: JohnS on December 30, 2016, 01:16:52 PM
Has been discussed at length on linux-sunxi ML with code.

John
Title: Re: Make my MAC address static/fixed using EEPROM
Post by: sylvain on January 03, 2017, 11:24:37 AM
Hello John

Are those the relevant threads?
https://groups.google.com/forum/#!msg/linux-sunxi/Ze3fshafW-w/ytnIuwjY8rAJ
https://groups.google.com/forum/#!msg/linux-sunxi/98l-zeEtEZY/bVlxkenTAwAJ
https://groups.google.com/forum/#!msg/linux-sunxi/fKvYiCtfils/430rdeQKCQAJ
https://groups.google.com/forum/#!msg/linux-sunxi/QA2FC8rd3q8/1yRssXQKCQAJ

Is the recommended solution for now to rebuild uboot ourselves using those experimental patches?

Would loading the MAC address in uBoot automagically disable the random generation of a new one during boot?

Thanks
Title: Re: Make my MAC address static/fixed using EEPROM
Post by: JohnS on January 04, 2017, 12:47:41 PM
I use the ML so I got them as email and don't use those groups.

As I was happy for the devs to change the code I didn't argue and will get whatever they did when getting newer code.

If you don't like what they did then be sure to tell them with reasons.

John
Title: Re: Make my MAC address static/fixed using EEPROM
Post by: SR-Digitronic on August 29, 2017, 04:59:21 PM
When I understand that patch correctly, you need mainline U-Boot, which makes it unusable when you have to boot from NAND.

You can always manually set a MAC address with an initramfs init script with help of busybox's i2cget and ip command:
ETH0MAC=$(printf %x:%x:%x:%x:%x:%x `i2cget -y -f 1 0x50 0x16` `i2cget -y -f 1 0x50 0x17` `i2cget -y -f 1 0x50 0x18` `i2cget -y -f 1 0x50 0x19` `i2cget -y -f 1 0x50 0x1A` `i2cget -y -f 1 0x50 0x1B`)
if test "${ETH0MAC}" != "ff:ff:ff:ff:ff:ff"; then
    ip link set dev eth0 address ${ETH0MAC}
fi


You can also use a for loop and calculate the addresses, but for that you have to enable math support in your shell. In my case this made sense, since I already had a custom init script for making NAND read only with help of overlayfs.