ath79: fix MAC addresses for ethernet on ZyXEL NBG6716
authorAdrian Schmutzler <freifunk@adrianschmutzler.de>
Tue, 7 Apr 2020 10:31:48 +0000 (12:31 +0200)
committerAdrian Schmutzler <freifunk@adrianschmutzler.de>
Wed, 8 Apr 2020 14:59:14 +0000 (16:59 +0200)
MAC addresses of the ethernet devices (eth0 & eth1) are randomly set at
boot time by the ag71xx driver, because it is currently not possible to
retrieve MAC addresses in ASCII format within the DTS file.
This commit works around this behaviour by setting the MAC addresses
during the preinit phase.

The same has been implemented recently for the Siemens WS-AP3610 in
d2b8ccb1c04d ("ath79: add support for Siemens WS-AP3610").

MAC assignment in vendor firmware is as follows:

use   vendor   address     OpenWrt
2g    wifi0    ethaddr     -> wlan1
5g    wifi1    ethaddr +1  -> wlan0
lan   eth1     ethaddr +2  -> eth0
wan   eth0     ethaddr +3  -> eth1

ethaddr is retrieved by $(mtd_get_mac_ascii u-boot-env ethaddr)

Note that both Wifi and ethernet indexing is swapped in OpenWrt
compared to vendor firmware.

Suggested-by: Guillaume Lefebvre <guillaume@zelig.ch>
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
Tested-by: Kevin Gagnon <kevin_gagnon@videotron.ca>
target/linux/ath79/nand/base-files/etc/board.d/02_network
target/linux/ath79/nand/base-files/lib/preinit/10_fix_eth_mac.sh [new file with mode: 0644]

index 1626ec31cacbc6196a1f65087eb1748fbf494616..b2191eed92f9fab380aabd78a23d8543a55053ba 100755 (executable)
@@ -48,10 +48,6 @@ ath79_setup_macs()
        netgear,wndr4500-v3)
                wan_mac=$(mtd_get_mac_binary caldata 0x6)
                ;;
-       zyxel,nbg6716)
-               lan_mac=$(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +2)
-               wan_mac=$(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +3)
-               ;;
        esac
 
        [ -n "$lan_mac" ] && ucidef_set_interface_macaddr "lan" $lan_mac
diff --git a/target/linux/ath79/nand/base-files/lib/preinit/10_fix_eth_mac.sh b/target/linux/ath79/nand/base-files/lib/preinit/10_fix_eth_mac.sh
new file mode 100644 (file)
index 0000000..fdd8381
--- /dev/null
@@ -0,0 +1,14 @@
+. /lib/functions.sh
+. /lib/functions/system.sh
+
+preinit_set_mac_address() {
+       case $(board_name) in
+       zyxel,nbg6716)
+               ethaddr=$(mtd_get_mac_ascii u-boot-env ethaddr)
+               ip link set dev eth0 address $(macaddr_add $ethaddr 2)
+               ip link set dev eth1 address $(macaddr_add $ethaddr 3)
+               ;;
+       esac
+}
+
+boot_hook_add preinit_main preinit_set_mac_address