Utilite & Trim-Slice Users Forum
http://www.compulab.co.il/utilite-computer/forum/

Set eth1 mac address in U-Boot using the device tree
http://www.compulab.co.il/utilite-computer/forum/viewtopic.php?f=66&t=1986
Page 1 of 1

Author:  johnbock [ Mon Aug 25, 2014 5:14 pm ]
Post subject:  Set eth1 mac address in U-Boot using the device tree

Thanks to valintin's post and the Utilite U-Boot version 2014-04 in combination with kernels starting at version 3.10.17 with device tree support, we can pass the mac address of eth1 (connected to PCIe) from U-Boot to the kernel.

No os configuration. No udev rule. No reading eeprom during boot process...

Obtain mac address of eth1 in U-Boot
Code:
CM-FX6 # i2c dev 0
Setting bus to 0
CM-FX6 # i2c probe
Valid chip addresses: 50 56
CM-FX6 # i2c md 0x50 4 6
0004: xx xx xx xx xx xx    ....p.


Alternative 1
This solution seems more natural as the process 'Alternative 2'.

U-Boot is able to parse and set/correct certain values (in the U-Boot environment) in the given device tree before giving the device tree blob (dtb) to the kernel. The following uses this U-Boot feature.

First, define the path where the mac address is to be set. U-Boot searches the aliases node for references to 'ethernet[0-3]': in our case 'ethernet1 = &eth1;'. Then searches the dtb for the node referenced by the aliases value '&eth1'. When found, creates/overwrites the sub-nodes 'mac-address' and 'local-mac-address'. U-Boot then passes the corrected dtb to the kernel. The kernel in-turn does it's magic and the sets the devices's mac address accordingly.

Now let's correct the node path in the kernel (3.10.17-beta1) device tree. Hopefully, the Compulab peeps will change the following, as soon as possible...
Code:
diff --git a/arch/arm/boot/dts/imx6q-sb-fx6m.dtsi b/arch/arm/boot/dts/imx6q-sb-fx6m.dtsi
index 5a488f8..14da457 100644
--- a/arch/arm/boot/dts/imx6q-sb-fx6m.dtsi
+++ b/arch/arm/boot/dts/imx6q-sb-fx6m.dtsi
@@ -14,9 +14,12 @@
#include "imx6q-sb-fx6x.dtsi"

/ {
-       eth@pcie {
+       aliases {
+               ethernet1 = &eth1;
+       };
+
+       eth1: ethernet@pcie {
                compatible = "intel,i211";
-               local-mac-address = [FF FF FF FF FF FF];
                status = "okay";
        };

@@ -29,4 +32,4 @@
                        gpio-key,wakeup;
                };
        };
-};
\ No newline at end of file
+};

and enable creation of the imx6q-sbc-fx6m.dtb. Unfortunately, this was not enabled in arch/arm/boot/dtb/Makefile for 3.10.17-beta1 (untested)
Code:
diff --git a/arch/arm/boot/dts/Makefile b/arch/arm/boot/dts/Makefile
index c5f9a19..4e64261 100644
--- a/arch/arm/boot/dts/Makefile
+++ b/arch/arm/boot/dts/Makefile
@@ -136,7 +136,10 @@ dtb-$(CONFIG_ARCH_MXC) += \
        imx6sl-evk-csi.dtb \
        imx6sl-evk-ldo.dtb \
        imx6sl-evk-pf200.dtb \
-       vf610-twr.dtb
+       vf610-twr.dtb \
+       imx6q-cm-fx6.dtb \
+       imx6q-sbc-fx6.dtb \
+       imx6q-sbc-fx6m.dtb
dtb-$(CONFIG_ARCH_MXS) += imx23-evk.dtb \
        imx23-olinuxino.dtb \
        imx23-stmp378x_devb.dtb \


then make the dtb and copy it to /boot.
Code:
make dtbs
cp arch/arm/boot/dts/imx6q-sbc-fx6m.dtb /boot


and then set the U-Boot environment variable eth1addr to the correct mac.
Code:
setenv eth1addr xx:xx:xx:xx:xx:xx

After saving the variable to the U-Boot environment and rebooting, the mac addres should be correctly assigned to the device.

Alternative 2
This is still here for reference only...
If you had followed the instuctions below, please remove the follow enivroment variables
Code:
setenv eth1mac
setenv of_set_mac_address

and reset these too
Code:
setenv mmcloadkernel 'load mmc $mmcdev $loadaddr $kernel; load mmc $mmcdev $dtbaddr $dtb'
setenv sataloadkernel 'load sata $satadev $loadaddr $kernel; load sata $satadev $dtbaddr $dtb'


In U-Boot we must set the following...
Code:
setenv dtbaddr 15000000
setenv bootm_low 15000000
setenv dtb imx6q-sbc-fx6m.dtb
setenv kernel zImage

setenv eth1mac 'xx xx xx xx xx xx'

setenv of_set_mac_address 'if env grep eth1mac; then fdt addr $dtbaddr; fdt set /eth@pcie local-mac-address [${eth1mac}]; fi'

setenv mmcloadkernel 'load mmc $mmcdev $loadaddr $kernel; load mmc $mmcdev $dtbaddr $dtb; run of_set_mac_address'
setenv mmcboot 'echo Booting from mmc ...; run mmcargs; bootz ${loadaddr} - ${dtbaddr}'

setenv sataloadkernel 'load sata $satadev $loadaddr $kernel; load sata $satadev $dtbaddr $dtb; run of_set_mac_address'
setenv sataboot 'echo Booting from sata ...; run sataargs; bootz ${loadaddr} - ${dtbaddr}'


Please note:
  • mac address must not contain colons ':'
  • zImage is used, not uImage
  • If Compulab moves the dts path to local-mac-address, this must be adjusted accordingly

Author:  johnbock [ Thu Aug 28, 2014 11:15 am ]
Post subject:  Re: Set eth1 mac address in U-Boot using the device tree

Corrected the above post and describe how U-Boot interacts with the dtb.

Author:  Unicron [ Tue Sep 02, 2014 9:57 am ]
Post subject:  Re: Set eth1 mac address in U-Boot using the device tree

I created u-boot that also sets igb interface mac to eth1address env variable (from eeprom) and pushes /eth@pcie local-mac-address in dtb blob.

http://dev.packages.vyos.net/tmp/cm-fx6-firmware

https://github.com/UnicronNL/u-boot

Author:  johnbock [ Wed Sep 03, 2014 6:15 am ]
Post subject:  Re: Set eth1 mac address in U-Boot using the device tree

Unicron wrote:
I created u-boot that also sets igb interface mac to eth1address env variable (from eeprom) and pushes /eth@pcie local-mac-address in dtb blob.

http://dev.packages.vyos.net/tmp/cm-fx6-firmware

https://github.com/UnicronNL/u-boot



Nice work ;-)

Being I'm abroad, I cannot test this ATM.

Currently, Compulab is working to get support for the cm-fx6 into U-Boot mainline and they have refrained from explicitly setting the MAC address for the FEC interface [1]. It may be advantageous to do the same here [2].

[1] http://lists.denx.de/pipermail/u-boot/2 ... 86699.html
[2] https://github.com/UnicronNL/u-boot/com ... cc3df02245 [482:487]

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/