Olimex Support Forum

OLinuXino Android / Linux boards and System On Modules => RT5350F => Topic started by: vinczo on January 05, 2017, 05:17:16 PM

Title: [SOLVED] Why are MAC adresses regenerated at reboot?
Post by: vinczo on January 05, 2017, 05:17:16 PM

I am working on Olinuxino-RT5350F chip with OpenWRT firmware.
I have the following interfaces:
Code: [Select]
I realised that after each reboot the MAC adress is regenerated for eth0, vlans (eth0.1,eth0.2) and wlan0.
There is only br-lan that keeps the same MAC adress after each reboot.

However, if I reflash the chip (with the same OpenWRT firmware), the MAC adress is changed for all interfaces br-lan included.

Note, that when I say MAC adress is changed, it is the full MAC adress that is changed  (Organisationally Unique Identifier included)!

Any insight would be very helpful,
Thanks in advance,

Title: Re: Why are MAC adresses regenerated at reboot?
Post by: zgyarmati on January 31, 2017, 07:36:29 PM
 The MAC addresses of the wlan0 and the eth0 interfaces (theoretically at least) are set by the first bytes of the 'factory' flash partition, and as a fallback, if those values are not set, the driver generates random MAC address at each boot.
 It seems that those bytes on the flash are not set in the Olimex provided images (which would be the ideal case). This issue also affects me as well, but i haven't really dig into this, i'll post my findings if any...
Title: Re: Why are MAC adresses regenerated at reboot?
Post by: LubOlimex on February 01, 2017, 11:23:21 AM
As zgyarmati suggested, by default we don’t set any MAC in the eeprom so MAC addressing is controlled by the OpenWRT Linux.

There are different methods to achieve what you want. One less obvious method that might be easier for production would be again using the rt5350f_factory.eeprom and set the MAC address for each board. Open the latest eeprom with e hex editor and type desired MAC address. Refer to this picture on where to edit: http://i.imgur.com/RNUw7LW.jpg

Find the pdf guide that can be used to understand the eeprom content here: https://github.com/OLIMEX/OLINUXINO/raw/master/SOFTWARE/RT5350F/Prebuilt%20images/mtd2%20recovery/RT307x_RT357x-EEPROM_Content_V1.62.pdf

When the file is ready follow the same procedure to update the eeprom as suggested here: https://github.com/OLIMEX/OLINUXINO/blob/master/SOFTWARE/RT5350F/Prebuilt%20images/mtd2%20recovery/README.md

Other than the method described above refer to the "more legit" practices proposed by OpenWRT community. There are several wiki articles on the subject, for example this one: https://wiki.openwrt.org/doc/uci/dhcp – I also recommend you to check on the OpenWRT forums for more user experience.

Best regards,
Title: Re: Why are MAC adresses regenerated at reboot?
Post by: zgyarmati on February 01, 2017, 05:28:10 PM
Some supplemental notes:

1. It's also possible to flash this value with an SPI programmer, as described here: https://www.olimex.com/wiki/RT5350F-OLinuXino#Upload_prebuilt_images_using_programmer_tool (might be better in a production run)

2. A MAC address contains 6 octets (while on the screenshot 8 is highlighted), so enough to set the 4:9 bytes

3. The value set on the factory partition sets both the eth0 and the wlan0 MAC address to the same value.
Title: Re: Why are MAC adresses regenerated at reboot?
Post by: Syd on April 12, 2017, 11:34:46 AM

I contacted an industrialist, the latter told me that they were installing and integrating EEPROMs containing a Mac address of type SPI or I2C.

I went on a 25AA02E48I component containing a single MAC address issued by MicroChip.

In the of_get_mac_address_mtd function, the address is searched in the DTS ( with mtd-mac-address keyword).

Code: [Select]
int of_get_mac_address_mtd(struct device_node *np, void *mac)

We find it (on offset 0x4) :
Code: [Select]
        ethernet@10100000 {
                mtd-mac-address = <&factory 0x4>;

And the reference factory was define for a partition ( wifi eeprom ).

Code: [Select]
    factory: partition@40000 {
            label = "factory";
            reg = <0x40000 0x10000>;

So , i search to change eeprom reference on another SPI flash like 25AAE48I (with offset 0xfa).

But, i didn't find good way , or drivers for it.

need few help ... thx  ;D

Title: Re: Why are MAC adresses regenerated at reboot?
Post by: Syd on April 18, 2017, 11:36:39 AM

Ok, i try a simple issu :

here, we need to active the Kernel misc module for AT25 eeprom.

Code: [Select]

                        m25p80@1 {
                            #address-cells = <1>;
                            #size-cells = <1>;
                            compatible = "at25";
                            reg = <1>;
                            linux,modalias = "m25p80", "at25";
                            spi-max-frequency = <1000000>;

                            at25,byte-len = <0x100>;
                            at25,addr-mode = <1>;
                            at25,page-size = <16>;

and read Mac address on eeprom with script for the Wireless config :

Code: [Select]

NEWMAC==$(hexdump -C -s 250 -n 6 /sys/bus/spi/devices/spi32766.1/eeprom | awk  'NR==1 {  printf $2":"$3":"$4":"$5":"$6":"$7"\n" }')

logger "Applying random MAC address to WAN (${NEWMAC})..."

uci set network.wan.macaddr=${NEWMAC}
uci commit network