[openwrt/openwrt] ramips: convert HiWiFi devices MAC address to NVMEM format
LEDE Commits
lede-commits at lists.infradead.org
Sun Jun 8 10:40:56 PDT 2025
hauke pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/9e08350b10584fb88459544589434d1d9c81e5a5
commit 9e08350b10584fb88459544589434d1d9c81e5a5
Author: Shiji Yang <yangshiji66 at outlook.com>
AuthorDate: Sat Mar 15 10:00:10 2025 +0800
ramips: convert HiWiFi devices MAC address to NVMEM format
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 at outlook.com>
Link: https://github.com/openwrt/openwrt/pull/18251
Signed-off-by: Hauke Mehrtens <hauke at hauke-m.de>
---
target/linux/ramips/dts/mt7620a_hiwifi_hc5661.dts | 1 +
target/linux/ramips/dts/mt7620a_hiwifi_hc5761.dts | 5 ++--
target/linux/ramips/dts/mt7620a_hiwifi_hc5861.dts | 5 ++--
target/linux/ramips/dts/mt7620a_hiwifi_hc5x61.dtsi | 26 ++++++++++++-------
target/linux/ramips/dts/mt7621_hiwifi_hc5962.dts | 29 +++++++++++++++++++---
.../linux/ramips/dts/mt7628an_hiwifi_hc5761a.dts | 4 +--
.../linux/ramips/dts/mt7628an_hiwifi_hc5861b.dts | 2 +-
.../linux/ramips/dts/mt7628an_hiwifi_hc5x61a.dtsi | 27 ++++++++++++--------
.../mt7620/base-files/etc/board.d/02_network | 5 +---
.../etc/hotplug.d/ieee80211/10_fix_wifi_mac | 12 ++-------
.../mt7621/base-files/etc/board.d/02_network | 6 -----
.../etc/hotplug.d/ieee80211/10_fix_wifi_mac | 7 ++----
.../mt76x8/base-files/etc/board.d/02_network | 5 +---
.../etc/hotplug.d/ieee80211/10_fix_wifi_mac | 9 ++-----
14 files changed, 76 insertions(+), 67 deletions(-)
diff --git a/target/linux/ramips/dts/mt7620a_hiwifi_hc5661.dts b/target/linux/ramips/dts/mt7620a_hiwifi_hc5661.dts
index 90ce3c92d7..3d1c169765 100644
--- a/target/linux/ramips/dts/mt7620a_hiwifi_hc5661.dts
+++ b/target/linux/ramips/dts/mt7620a_hiwifi_hc5661.dts
@@ -5,6 +5,7 @@
model = "HiWiFi HC5661";
aliases {
+ label-mac-device = ðernet;
led-boot = &led_system;
led-failsafe = &led_system;
led-running = &led_system;
diff --git a/target/linux/ramips/dts/mt7620a_hiwifi_hc5761.dts b/target/linux/ramips/dts/mt7620a_hiwifi_hc5761.dts
index f37b663973..7b5cd0675b 100644
--- a/target/linux/ramips/dts/mt7620a_hiwifi_hc5761.dts
+++ b/target/linux/ramips/dts/mt7620a_hiwifi_hc5761.dts
@@ -5,6 +5,7 @@
model = "HiWiFi HC5761";
aliases {
+ label-mac-device = ðernet;
led-boot = &led_system;
led-failsafe = &led_system;
led-running = &led_system;
@@ -63,8 +64,8 @@
&pcie0 {
mt76 at 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>;
};
};
diff --git a/target/linux/ramips/dts/mt7620a_hiwifi_hc5861.dts b/target/linux/ramips/dts/mt7620a_hiwifi_hc5861.dts
index fcd4040292..8b99655cdd 100644
--- a/target/linux/ramips/dts/mt7620a_hiwifi_hc5861.dts
+++ b/target/linux/ramips/dts/mt7620a_hiwifi_hc5861.dts
@@ -5,6 +5,7 @@
model = "HiWiFi HC5861";
aliases {
+ label-mac-device = ðernet;
led-boot = &led_system;
led-failsafe = &led_system;
led-running = &led_system;
@@ -95,8 +96,8 @@
wifi at 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>;
};
};
diff --git a/target/linux/ramips/dts/mt7620a_hiwifi_hc5x61.dtsi b/target/linux/ramips/dts/mt7620a_hiwifi_hc5x61.dtsi
index 6a602b8411..34412cd7f4 100644
--- a/target/linux/ramips/dts/mt7620a_hiwifi_hc5x61.dtsi
+++ b/target/linux/ramips/dts/mt7620a_hiwifi_hc5x61.dtsi
@@ -68,10 +68,6 @@
eeprom_factory_8000: eeprom at 8000 {
reg = <0x8000 0x200>;
};
-
- macaddr_factory_4: macaddr at 4 {
- reg = <0x4 0x6>;
- };
};
};
@@ -91,6 +87,18 @@
label = "bdinfo";
reg = <0xfe0000 0x10000>;
read-only;
+
+ nvmem-layout {
+ compatible = "fixed-layout";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ macaddr_bdinfo_18a: macaddr at 18a {
+ compatible = "mac-base";
+ reg = <0x18a 0x11>;
+ #nvmem-cell-cells = <1>;
+ };
+ };
};
partition at ff0000 {
@@ -103,10 +111,10 @@
};
ðernet {
- 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 {
@@ -114,8 +122,8 @@
};
&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 {
diff --git a/target/linux/ramips/dts/mt7621_hiwifi_hc5962.dts b/target/linux/ramips/dts/mt7621_hiwifi_hc5962.dts
index 5a8f32d723..ade82efa39 100644
--- a/target/linux/ramips/dts/mt7621_hiwifi_hc5962.dts
+++ b/target/linux/ramips/dts/mt7621_hiwifi_hc5962.dts
@@ -9,6 +9,7 @@
model = "HiWiFi HC5962";
aliases {
+ label-mac-device = &gmac0;
led-boot = &led_system;
led-failsafe = &led_system;
led-running = &led_status;
@@ -116,6 +117,18 @@
label = "bdinfo";
reg = <0x21c0000 0x80000>;
read-only;
+
+ nvmem-layout {
+ compatible = "fixed-layout";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ macaddr_bdinfo_18a: macaddr at 18a {
+ compatible = "mac-base";
+ reg = <0x18a 0x11>;
+ #nvmem-cell-cells = <1>;
+ };
+ };
};
ubiconcat1: partition at 2240000 {
@@ -132,8 +145,8 @@
&pcie0 {
mt76 at 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>;
};
};
@@ -141,16 +154,24 @@
&pcie1 {
mt76 at 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 = <ðphy4>;
+
+ nvmem-cells = <&macaddr_bdinfo_18a 1>;
+ nvmem-cell-names = "mac-address";
};
ðphy4 {
diff --git a/target/linux/ramips/dts/mt7628an_hiwifi_hc5761a.dts b/target/linux/ramips/dts/mt7628an_hiwifi_hc5761a.dts
index eedf534017..44086698c5 100644
--- a/target/linux/ramips/dts/mt7628an_hiwifi_hc5761a.dts
+++ b/target/linux/ramips/dts/mt7628an_hiwifi_hc5761a.dts
@@ -73,8 +73,8 @@
&pcie0 {
wifi at 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>;
};
};
diff --git a/target/linux/ramips/dts/mt7628an_hiwifi_hc5861b.dts b/target/linux/ramips/dts/mt7628an_hiwifi_hc5861b.dts
index 44ebef2ad5..7db5a6bc43 100644
--- a/target/linux/ramips/dts/mt7628an_hiwifi_hc5861b.dts
+++ b/target/linux/ramips/dts/mt7628an_hiwifi_hc5861b.dts
@@ -43,7 +43,7 @@
wifi at 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 {
diff --git a/target/linux/ramips/dts/mt7628an_hiwifi_hc5x61a.dtsi b/target/linux/ramips/dts/mt7628an_hiwifi_hc5x61a.dtsi
index 4b114c9414..99fc46d351 100644
--- a/target/linux/ramips/dts/mt7628an_hiwifi_hc5x61a.dtsi
+++ b/target/linux/ramips/dts/mt7628an_hiwifi_hc5x61a.dtsi
@@ -9,6 +9,7 @@
compatible = "hiwifi,hc5x61a", "mediatek,mt7628an-soc";
aliases {
+ label-mac-device = ðernet;
led-boot = &led_system;
led-failsafe = &led_system;
led-running = &led_system;
@@ -73,14 +74,6 @@
eeprom_factory_8000: eeprom at 8000 {
reg = <0x8000 0x200>;
};
-
- macaddr_factory_4: macaddr at 4 {
- reg = <0x4 0x6>;
- };
-
- macaddr_factory_2e: macaddr at 2e {
- reg = <0x2e 0x6>;
- };
};
};
@@ -100,6 +93,18 @@
label = "bdinfo";
reg = <0xfe0000 0x10000>;
read-only;
+
+ nvmem-layout {
+ compatible = "fixed-layout";
+ #address-cells = <1>;
+ #size-cells = <1>;
+
+ macaddr_bdinfo_18a: macaddr at 18a {
+ compatible = "mac-base";
+ reg = <0x18a 0x11>;
+ #nvmem-cell-cells = <1>;
+ };
+ };
};
partition at ff0000 {
@@ -112,13 +117,13 @@
};
ðernet {
- 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";
};
diff --git a/target/linux/ramips/mt7620/base-files/etc/board.d/02_network b/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
index 9f436a2e8f..208cb647d3 100644
--- a/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/mt7620/base-files/etc/board.d/02_network
@@ -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)
diff --git a/target/linux/ramips/mt7620/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac b/target/linux/ramips/mt7620/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
index aa0ad99158..4c6c7cedba 100644
--- a/target/linux/ramips/mt7620/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
+++ b/target/linux/ramips/mt7620/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
@@ -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
diff --git a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
index a274dd0d99..31c3f143a0 100644
--- a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network
@@ -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
diff --git a/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac b/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
index c1c6ec749b..d2da8a227b 100644
--- a/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
+++ b/target/linux/ramips/mt7621/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
@@ -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)
diff --git a/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network b/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
index cd9199a7d1..ef29d9b328 100644
--- a/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
+++ b/target/linux/ramips/mt76x8/base-files/etc/board.d/02_network
@@ -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|\
diff --git a/target/linux/ramips/mt76x8/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac b/target/linux/ramips/mt76x8/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
index c9e205a0fc..57518445fc 100644
--- a/target/linux/ramips/mt76x8/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
+++ b/target/linux/ramips/mt76x8/base-files/etc/hotplug.d/ieee80211/10_fix_wifi_mac
@@ -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
More information about the lede-commits
mailing list