]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
ramips: convert HiWiFi devices MAC address to NVMEM format
authorShiji Yang <yangshiji66@outlook.com>
Sat, 15 Mar 2025 02:00:10 +0000 (10:00 +0800)
committerHauke Mehrtens <hauke@hauke-m.de>
Sun, 8 Jun 2025 17:37:49 +0000 (19:37 +0200)
For all HiWiFi series devices, the base MAC address is stored on
"bdinfo" partition, offset 0x18a, ASCII text format. The recently
introduced "mac-base" nvmem layout can handle the ASCII text now,
so it's time to move MAC address configurations to dts. There is
no valid MAC info in the "factory" partition, hence they will be
replaced with the correct ones.

Tested on HiWiFi HC5661A and HC5861.

Signed-off-by: Shiji Yang <yangshiji66@outlook.com>
Link: https://github.com/openwrt/openwrt/pull/18251
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
14 files changed:
target/linux/ramips/dts/mt7620a_hiwifi_hc5661.dts
target/linux/ramips/dts/mt7620a_hiwifi_hc5761.dts
target/linux/ramips/dts/mt7620a_hiwifi_hc5861.dts
target/linux/ramips/dts/mt7620a_hiwifi_hc5x61.dtsi
target/linux/ramips/dts/mt7621_hiwifi_hc5962.dts
target/linux/ramips/dts/mt7628an_hiwifi_hc5761a.dts
target/linux/ramips/dts/mt7628an_hiwifi_hc5861b.dts
target/linux/ramips/dts/mt7628an_hiwifi_hc5x61a.dtsi
target/linux/ramips/mt7620/base-files/etc/board.d/02_network
target/linux/ramips/mt7620/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
target/linux/ramips/mt7621/base-files/etc/board.d/02_network
target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
target/linux/ramips/mt76x8/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac

index 90ce3c92d78c538a51c30364ba3608c8225b5fd7..3d1c1697658763728d91cbfba29bc49d89499672 100644 (file)
@@ -5,6 +5,7 @@
        model = "HiWiFi HC5661";
 
        aliases {
+               label-mac-device = &ethernet;
                led-boot = &led_system;
                led-failsafe = &led_system;
                led-running = &led_system;
index f37b663973de3b4b4024d7af986a3fd043b03d5f..7b5cd0675bbf20f6ce2b019fcf0692515b1fc89b 100644 (file)
@@ -5,6 +5,7 @@
        model = "HiWiFi HC5761";
 
        aliases {
+               label-mac-device = &ethernet;
                led-boot = &led_system;
                led-failsafe = &led_system;
                led-running = &led_system;
@@ -63,8 +64,8 @@
 &pcie0 {
        mt76@0,0 {
                reg = <0x0000 0 0 0 0>;
-               nvmem-cells = <&eeprom_factory_8000>;
-               nvmem-cell-names = "eeprom";
+               nvmem-cells = <&eeprom_factory_8000>, <&macaddr_bdinfo_18a 0>;
+               nvmem-cell-names = "eeprom", "mac-address";
                ieee80211-freq-limit = <5000000 6000000>;
        };
 };
index fcd40402921a03542b12d2604460582ce2f5ddad..8b99655cdd7419079b5d1d4417f1351168ebb5e3 100644 (file)
@@ -5,6 +5,7 @@
        model = "HiWiFi HC5861";
 
        aliases {
+               label-mac-device = &ethernet;
                led-boot = &led_system;
                led-failsafe = &led_system;
                led-running = &led_system;
@@ -95,8 +96,8 @@
        wifi@0,0 {
                compatible = "pci14c3,7662";
                reg = <0x0000 0 0 0 0>;
-               nvmem-cells = <&eeprom_factory_8000>;
-               nvmem-cell-names = "eeprom";
+               nvmem-cells = <&eeprom_factory_8000>, <&macaddr_bdinfo_18a 0>;
+               nvmem-cell-names = "eeprom", "mac-address";
                ieee80211-freq-limit = <5000000 6000000>;
        };
 };
index 6a602b841168a5cb93e6a3f22c796dcbbf28ddb7..34412cd7f412789367322227db0cd5ed03d0a994 100644 (file)
                                        eeprom_factory_8000: eeprom@8000 {
                                                reg = <0x8000 0x200>;
                                        };
-
-                                       macaddr_factory_4: macaddr@4 {
-                                               reg = <0x4 0x6>;
-                                       };
                                };
                        };
 
                                label = "bdinfo";
                                reg = <0xfe0000 0x10000>;
                                read-only;
+
+                               nvmem-layout {
+                                       compatible = "fixed-layout";
+                                       #address-cells = <1>;
+                                       #size-cells = <1>;
+
+                                       macaddr_bdinfo_18a: macaddr@18a {
+                                               compatible = "mac-base";
+                                               reg = <0x18a 0x11>;
+                                               #nvmem-cell-cells = <1>;
+                                       };
+                               };
                        };
 
                        partition@ff0000 {
 };
 
 &ethernet {
-       nvmem-cells = <&macaddr_factory_4>;
-       nvmem-cell-names = "mac-address";
-
        mediatek,portmap = "wllll";
+
+       nvmem-cells = <&macaddr_bdinfo_18a 0>;
+       nvmem-cell-names = "mac-address";
 };
 
 &sdhci {
 };
 
 &wmac {
-       nvmem-cells = <&eeprom_factory_0>;
-       nvmem-cell-names = "eeprom";
+       nvmem-cells = <&eeprom_factory_0>, <&macaddr_bdinfo_18a 0>;
+       nvmem-cell-names = "eeprom", "mac-address";
 };
 
 &state_default {
index 5a8f32d7236fe6d07c4354972f9daad87516bb20..ade82efa3931608723142ad60098815d74a220b9 100644 (file)
@@ -9,6 +9,7 @@
        model = "HiWiFi HC5962";
 
        aliases {
+               label-mac-device = &gmac0;
                led-boot = &led_system;
                led-failsafe = &led_system;
                led-running = &led_status;
                        label = "bdinfo";
                        reg = <0x21c0000 0x80000>;
                        read-only;
+
+                       nvmem-layout {
+                               compatible = "fixed-layout";
+                               #address-cells = <1>;
+                               #size-cells = <1>;
+
+                               macaddr_bdinfo_18a: macaddr@18a {
+                                       compatible = "mac-base";
+                                       reg = <0x18a 0x11>;
+                                       #nvmem-cell-cells = <1>;
+                               };
+                       };
                };
 
                ubiconcat1: partition@2240000 {
 &pcie0 {
        mt76@0,0 {
                reg = <0x0000 0 0 0 0>;
-               nvmem-cells = <&eeprom_factory_0>;
-               nvmem-cell-names = "eeprom";
+               nvmem-cells = <&eeprom_factory_0>, <&macaddr_bdinfo_18a 0>;
+               nvmem-cell-names = "eeprom", "mac-address";
                ieee80211-freq-limit = <2400000 2500000>;
        };
 };
 &pcie1 {
        mt76@0,0 {
                reg = <0x0000 0 0 0 0>;
-               nvmem-cells = <&eeprom_factory_8000>;
-               nvmem-cell-names = "eeprom";
+               nvmem-cells = <&eeprom_factory_8000>, <&macaddr_bdinfo_18a 0>;
+               nvmem-cell-names = "eeprom", "mac-address";
                ieee80211-freq-limit = <5000000 6000000>;
        };
 };
 
+&gmac0 {
+       nvmem-cells = <&macaddr_bdinfo_18a 0>;
+       nvmem-cell-names = "mac-address";
+};
+
 &gmac1 {
        status = "okay";
        label = "wan";
        phy-handle = <&ethphy4>;
+
+       nvmem-cells = <&macaddr_bdinfo_18a 1>;
+       nvmem-cell-names = "mac-address";
 };
 
 &ethphy4 {
index eedf5340177c5bf78e3fe02646ce93b23918f925..44086698c5742036a5bd4cf5f8d4fba8e05c948a 100644 (file)
@@ -73,8 +73,8 @@
 &pcie0 {
        wifi@0,0 {
                reg = <0x0000 0 0 0 0>;
-               nvmem-cells = <&eeprom_factory_8000>;
-               nvmem-cell-names = "eeprom";
+               nvmem-cells = <&eeprom_factory_8000>, <&macaddr_bdinfo_18a 0>;
+               nvmem-cell-names = "eeprom", "mac-address";
                ieee80211-freq-limit = <5000000 6000000>;
        };
 };
index 44ebef2ad5c0a7fbefadb5c346c5568b55878b7f..7db5a6bc4332d0214bf3f7914834cd8a6e802836 100644 (file)
@@ -43,7 +43,7 @@
        wifi@0,0 {
                reg = <0x0000 0 0 0 0>;
                ieee80211-freq-limit = <5000000 6000000>;
-               nvmem-cells = <&eeprom_factory_8000>, <&macaddr_factory_2e>;
+               nvmem-cells = <&eeprom_factory_8000>, <&macaddr_bdinfo_18a 0>;
                nvmem-cell-names = "eeprom", "mac-address";
 
                led {
index 4b114c94145aee8b9a67a43b91a9096ff03b8f8d..99fc46d351abe1f4e717e64bac5bac72e8ae0d15 100644 (file)
@@ -9,6 +9,7 @@
        compatible = "hiwifi,hc5x61a", "mediatek,mt7628an-soc";
 
        aliases {
+               label-mac-device = &ethernet;
                led-boot = &led_system;
                led-failsafe = &led_system;
                led-running = &led_system;
                                        eeprom_factory_8000: eeprom@8000 {
                                                reg = <0x8000 0x200>;
                                        };
-
-                                       macaddr_factory_4: macaddr@4 {
-                                               reg = <0x4 0x6>;
-                                       };
-
-                                       macaddr_factory_2e: macaddr@2e {
-                                               reg = <0x2e 0x6>;
-                                       };
                                };
                        };
 
                                label = "bdinfo";
                                reg = <0xfe0000 0x10000>;
                                read-only;
+
+                               nvmem-layout {
+                                       compatible = "fixed-layout";
+                                       #address-cells = <1>;
+                                       #size-cells = <1>;
+
+                                       macaddr_bdinfo_18a: macaddr@18a {
+                                               compatible = "mac-base";
+                                               reg = <0x18a 0x11>;
+                                               #nvmem-cell-cells = <1>;
+                                       };
+                               };
                        };
 
                        partition@ff0000 {
 };
 
 &ethernet {
-       nvmem-cells = <&macaddr_factory_4>;
+       nvmem-cells = <&macaddr_bdinfo_18a 0>;
        nvmem-cell-names = "mac-address";
 };
 
 &wmac {
        status = "okay";
 
-       nvmem-cells = <&eeprom_factory_0>;
-       nvmem-cell-names = "eeprom";
+       nvmem-cells = <&eeprom_factory_0>, <&macaddr_bdinfo_18a 0>;
+       nvmem-cell-names = "eeprom", "mac-address";
 };
index 9f436a2e8febb5552983ce2280dd2cba355cde51..208cb647d3dde4a668e97c0f5d19a6b1a7ee0993 100644 (file)
@@ -382,10 +382,7 @@ ramips_setup_macs()
        hiwifi,hc5661|\
        hiwifi,hc5761|\
        hiwifi,hc5861)
-               lan_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
-               label_mac=$lan_mac
-               [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
-               wan_mac=$(macaddr_add "$lan_mac" 1)
+               wan_mac=$(macaddr_add "$(cat /sys/class/net/eth0/address)" 1)
                ;;
        iodata,wn-ac1167gr|\
        iodata,wn-ac733gr3)
index aa0ad991582713b2f030784782b6814478a2f2ed..4c6c7cedba8d46705e28ddfdac04485df3f605d8 100644 (file)
@@ -10,17 +10,9 @@ PHYNBR=${DEVPATH##*/phy}
 board=$(board_name)
 
 case "$board" in
-       hiwifi,hc5661)
-               label_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
-               [ "$PHYNBR" = "0" ] && [ -n "$label_mac" ] && \
-               echo -n "$label_mac" > /sys${DEVPATH}/macaddress
-               ;;
        hiwifi,hc5761|\
        hiwifi,hc5861)
-               label_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
-               [ "$PHYNBR" = "1" ] && [ -n "$label_mac" ] && \
-               echo -n "$label_mac" > /sys${DEVPATH}/macaddress
-               [ "$PHYNBR" = "0" ] && [ -n "$label_mac" ] && \
-               macaddr_unsetbit "$label_mac" 6 > /sys${DEVPATH}/macaddress
+               [ "$PHYNBR" = "0" ] && \
+                       macaddr_unsetbit "$(cat /sys${DEVPATH}/macaddress)" 6 > /sys${DEVPATH}/macaddress
                ;;
 esac
index a274dd0d994e08af3ee1ad0795b79b4b31cc4fc3..31c3f143a0b1cb6f6f05d0966ec9515371055d71 100644 (file)
@@ -272,12 +272,6 @@ ramips_setup_macs()
                lan_mac=$(macaddr_add "$label_mac" 1)
                wan_mac=$label_mac
                ;;
-       hiwifi,hc5962)
-               lan_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac")
-               label_mac=$lan_mac
-               [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
-               wan_mac=$(macaddr_add "$lan_mac" 1)
-               ;;
        iodata,wnpr2600g)
                wan_mac=$(mtd_get_mac_ascii u-boot-env wanaddr)
                label_mac=$wan_mac
index c1c6ec749bce690accacd1847ffe42f08e296c32..d2da8a227b804c2c5f218d684687a1f50f5d3d4d 100644 (file)
@@ -110,11 +110,8 @@ case "$board" in
                        macaddr_setbit_la "$(mtd_get_mac_binary factory 0x4)" > /sys${DEVPATH}/macaddress
                ;;
        hiwifi,hc5962)
-               label_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac")
-               [ "$PHYNBR" = "0" ] && [ -n "$label_mac" ] && \
-               echo -n "$label_mac" > /sys${DEVPATH}/macaddress
-               [ "$PHYNBR" = "1" ] && [ -n "$label_mac" ] && \
-               macaddr_unsetbit "$label_mac" 6 > /sys${DEVPATH}/macaddress
+               [ "$PHYNBR" = "1" ] && \
+                       macaddr_unsetbit "$(cat /sys${DEVPATH}/macaddress)" 6 > /sys${DEVPATH}/macaddress
                ;;
        iptime,a3002mesh|\
        iptime,a3004t)
index cd9199a7d13cc33628bc45f6d1aa847ae4f2d817..ef29d9b3289aa75cf2ed773606ec2f9c24e75838 100644 (file)
@@ -290,10 +290,7 @@ ramips_setup_macs()
        hiwifi,hc5661a|\
        hiwifi,hc5761a|\
        hiwifi,hc5861b)
-               lan_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
-               label_mac=$lan_mac
-               [ -n "$lan_mac" ] || lan_mac=$(cat /sys/class/net/eth0/address)
-               wan_mac=$(macaddr_add "$lan_mac" 1)
+               wan_mac=$(macaddr_add "$(cat /sys/class/net/eth0/address)" 1)
                ;;
        iptime,a3|\
        iptime,a604m|\
index c9e205a0fc143b4bfea4095ad6c96e06d1d5b475..57518445fc42c1c123371a353339f8393852ef82 100644 (file)
@@ -10,14 +10,9 @@ PHYNBR=${DEVPATH##*/phy}
 board=$(board_name)
 
 case "$board" in
-       hiwifi,hc5611|\
-       hiwifi,hc5661a|\
        hiwifi,hc5761a|\
        hiwifi,hc5861b)
-               label_mac=$(mtd_get_mac_ascii bdinfo "Vfac_mac ")
-               [ "$PHYNBR" = "0" ] && [ -n "$label_mac" ] && \
-               echo -n "$label_mac" > /sys${DEVPATH}/macaddress
-               [ "$PHYNBR" = "1" ] && [ -n "$label_mac" ] && \
-               macaddr_unsetbit "$label_mac" 6 > /sys${DEVPATH}/macaddress
+               [ "$PHYNBR" = "1" ] && \
+                       macaddr_unsetbit "$(cat /sys${DEVPATH}/macaddress)" 6 > /sys${DEVPATH}/macaddress
                ;;
 esac