From 1bf59628e6b84df3bdd2e467a7cd1039bdcda027 Mon Sep 17 00:00:00 2001 From: AmadeusGhost <42570690+AmadeusGhost@users.noreply.github.com> Date: Thu, 7 Oct 2021 23:09:06 +0800 Subject: [PATCH] ramips: switch all supported devices to nvmem-cells --- .../ramips/dts/mt7620a_xiaomi_miwifi-r3.dts | 123 ++++++++++-------- .../ramips/dts/mt7621_d-team_newifi-d2.dts | 3 +- .../ramips/dts/mt7621_gehua_ghl-r-001.dts | 3 +- target/linux/ramips/dts/mt7621_jcg_y2.dts | 3 +- .../ramips/dts/mt7621_jdcloud_re-sp-01b.dts | 11 +- .../dts/mt7621_netgear_sercomm_bzv.dtsi | 3 +- .../linux/ramips/dts/mt7621_phicomm_k2p.dts | 3 +- .../dts/mt7621_xiaomi_router-ac2100.dtsi | 3 +- .../linux/ramips/dts/mt7621_xiaoyu_xy-c5.dts | 3 +- .../ramips/dts/mt7621_zbtlink_zbt-wg108.dts | 24 +++- .../mt7621/base-files/etc/board.d/02_network | 20 +-- .../etc/hotplug.d/ieee80211/10_fix_wifi_mac | 6 + 12 files changed, 120 insertions(+), 85 deletions(-) diff --git a/target/linux/ramips/dts/mt7620a_xiaomi_miwifi-r3.dts b/target/linux/ramips/dts/mt7620a_xiaomi_miwifi-r3.dts index 0a236615de..a280dced69 100644 --- a/target/linux/ramips/dts/mt7620a_xiaomi_miwifi-r3.dts +++ b/target/linux/ramips/dts/mt7620a_xiaomi_miwifi-r3.dts @@ -53,67 +53,73 @@ #size-cells = <1>; compatible = "mtk,mt7620-nand"; - partition@0 { - label = "Bootloader"; - reg = <0x0 0x40000>; - read-only; - }; + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; - partition@40000 { - label = "Config"; - reg = <0x40000 0x40000>; - }; + partition@0 { + label = "Bootloader"; + reg = <0x0 0x40000>; + read-only; + }; - partition@80000 { - label = "Bdata"; - reg = <0x80000 0x40000>; - read-only; - }; + partition@40000 { + label = "Config"; + reg = <0x40000 0x40000>; + }; - factory: partition@0xc0000 { - label = "factory"; - reg = <0xc0000 0x40000>; - read-only; - }; + partition@80000 { + label = "Bdata"; + reg = <0x80000 0x40000>; + read-only; + }; - partition@100000 { - label = "crash"; - reg = <0x100000 0x40000>; - read-only; - }; + factory: partition@0xc0000 { + label = "factory"; + reg = <0xc0000 0x40000>; + read-only; + }; - partition@140000 { - label = "crash_syslog"; - reg = <0x140000 0x40000>; - read-only; - }; + partition@100000 { + label = "crash"; + reg = <0x100000 0x40000>; + read-only; + }; - partition@180000 { - label = "reserved0"; - reg = <0x180000 0x80000>; - read-only; - }; + partition@140000 { + label = "crash_syslog"; + reg = <0x140000 0x40000>; + read-only; + }; - partition@200000 { - label = "kernel_stock"; - reg = <0x200000 0x400000>; - }; + partition@180000 { + label = "reserved0"; + reg = <0x180000 0x80000>; + read-only; + }; - partition@600000 { - label = "kernel"; - reg = <0x600000 0x400000>; - }; + partition@200000 { + label = "kernel_stock"; + reg = <0x200000 0x400000>; + }; - /* ubi partition is the result of squashing - * next consequent stock partitions: - * - rootfs0 (rootfs partition for stock kernel0), - * - rootfs1 (rootfs partition for stock failsafe kernel1), - * - overlay (used as ubi overlay in stock fw) - * resulting 117,5MiB space for packages. - */ - partition@a00000 { - label = "ubi"; - reg = <0xa00000 0x7600000>; + partition@600000 { + label = "kernel"; + reg = <0x600000 0x400000>; + }; + + /* ubi partition is the result of squashing + * next consequent stock partitions: + * - rootfs0 (rootfs partition for stock kernel0), + * - rootfs1 (rootfs partition for stock failsafe kernel1), + * - overlay (used as ubi overlay in stock fw) + * resulting 117,5MiB space for packages. + */ + partition@a00000 { + label = "ubi"; + reg = <0xa00000 0x7600000>; + }; }; }; }; @@ -133,7 +139,8 @@ ðernet { pinctrl-names = "default"; pinctrl-0 = <&ephy_pins>; - mtd-mac-address = <&factory 0x28>; + nvmem-cells = <&macaddr_factory_28>; + nvmem-cell-names = "mac-address"; mediatek,portmap = "llllw"; }; @@ -167,3 +174,13 @@ }; }; }; + +&factory { + compatible = "nvmem-cells"; + #address-cells = <1>; + #size-cells = <1>; + + macaddr_factory_28: macaddr@28 { + reg = <0x28 0x6>; + }; +}; diff --git a/target/linux/ramips/dts/mt7621_d-team_newifi-d2.dts b/target/linux/ramips/dts/mt7621_d-team_newifi-d2.dts index e0db79fa15..a0100c033c 100644 --- a/target/linux/ramips/dts/mt7621_d-team_newifi-d2.dts +++ b/target/linux/ramips/dts/mt7621_d-team_newifi-d2.dts @@ -151,7 +151,8 @@ ðernet { compatible = "mediatek,ralink-mt7621-eth"; mediatek,switch = <&gsw>; - mtd-mac-address = <&factory 0xe000>; + nvmem-cells = <&macaddr_factory_e000>; + nvmem-cell-names = "mac-address"; }; &switch0 { diff --git a/target/linux/ramips/dts/mt7621_gehua_ghl-r-001.dts b/target/linux/ramips/dts/mt7621_gehua_ghl-r-001.dts index 19a930d723..893e673e4c 100644 --- a/target/linux/ramips/dts/mt7621_gehua_ghl-r-001.dts +++ b/target/linux/ramips/dts/mt7621_gehua_ghl-r-001.dts @@ -113,7 +113,8 @@ ðernet { compatible = "mediatek,ralink-mt7621-eth"; mediatek,switch = <&gsw>; - mtd-mac-address = <&factory 0xe000>; + nvmem-cells = <&macaddr_factory_e000>; + nvmem-cell-names = "mac-address"; }; &switch0 { diff --git a/target/linux/ramips/dts/mt7621_jcg_y2.dts b/target/linux/ramips/dts/mt7621_jcg_y2.dts index b8ee2c2186..e022767b5f 100644 --- a/target/linux/ramips/dts/mt7621_jcg_y2.dts +++ b/target/linux/ramips/dts/mt7621_jcg_y2.dts @@ -91,7 +91,8 @@ ðernet { compatible = "mediatek,ralink-mt7621-eth"; mediatek,switch = <&gsw>; - mtd-mac-address = <&factory 0xe000>; + nvmem-cells = <&macaddr_factory_e000>; + nvmem-cell-names = "mac-address"; }; &switch0 { diff --git a/target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts b/target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts index 3f51f28edd..e54b656fbd 100644 --- a/target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts +++ b/target/linux/ramips/dts/mt7621_jdcloud_re-sp-01b.dts @@ -14,7 +14,6 @@ led-failsafe = &led_red; led-running = &led_green; led-upgrade = &led_blue; - label-mac-device = &gmac0; }; chosen { @@ -75,7 +74,7 @@ read-only; }; - config: partition@30000 { + partition@30000 { label = "config"; reg = <0x30000 0x10000>; read-only; @@ -108,10 +107,6 @@ }; }; -&gmac0 { - mtd-mac-address-ascii = <&config 0x4429>; -}; - &switch0 { ports { port@0 { @@ -138,7 +133,6 @@ &pcie0 { wifi@0,0 { reg = <0x0000 0 0 0 0>; - mtd-mac-address-ascii = <&config 0x4429>; mediatek,mtd-eeprom = <&factory 0x0>; }; }; @@ -146,9 +140,6 @@ &pcie1 { wifi@0,0 { reg = <0x0000 0 0 0 0>; - mtd-mac-address-ascii = <&config 0x4429>; - mtd-mac-address-increment = <0x80>; - mtd-mac-address-increment-byte = <3>; mediatek,mtd-eeprom = <&factory 0x8000>; ieee80211-freq-limit = <5000000 6000000>; }; diff --git a/target/linux/ramips/dts/mt7621_netgear_sercomm_bzv.dtsi b/target/linux/ramips/dts/mt7621_netgear_sercomm_bzv.dtsi index 5d0466e4ae..5536e95db4 100644 --- a/target/linux/ramips/dts/mt7621_netgear_sercomm_bzv.dtsi +++ b/target/linux/ramips/dts/mt7621_netgear_sercomm_bzv.dtsi @@ -164,7 +164,8 @@ ðernet { compatible = "mediatek,ralink-mt7621-eth"; mediatek,switch = <&gsw>; - mtd-mac-address = <&factory 0x4>; + nvmem-cells = <&macaddr_factory_4>; + nvmem-cell-names = "mac-address"; }; &switch0 { diff --git a/target/linux/ramips/dts/mt7621_phicomm_k2p.dts b/target/linux/ramips/dts/mt7621_phicomm_k2p.dts index c542c5a93b..5a58f66905 100644 --- a/target/linux/ramips/dts/mt7621_phicomm_k2p.dts +++ b/target/linux/ramips/dts/mt7621_phicomm_k2p.dts @@ -105,7 +105,8 @@ ðernet { compatible = "mediatek,ralink-mt7621-eth"; mediatek,switch = <&gsw>; - mtd-mac-address = <&factory 0xe000>; + nvmem-cells = <&macaddr_factory_e000>; + nvmem-cell-names = "mac-address"; }; &switch0 { diff --git a/target/linux/ramips/dts/mt7621_xiaomi_router-ac2100.dtsi b/target/linux/ramips/dts/mt7621_xiaomi_router-ac2100.dtsi index 7f128ed2f3..96b4a6d316 100644 --- a/target/linux/ramips/dts/mt7621_xiaomi_router-ac2100.dtsi +++ b/target/linux/ramips/dts/mt7621_xiaomi_router-ac2100.dtsi @@ -27,7 +27,8 @@ ðernet { compatible = "mediatek,ralink-mt7621-eth"; mediatek,switch = <&gsw>; - mtd-mac-address = <&factory 0xe006>; + nvmem-cells = <&macaddr_factory_e000>; + nvmem-cell-names = "mac-address"; }; &switch0 { diff --git a/target/linux/ramips/dts/mt7621_xiaoyu_xy-c5.dts b/target/linux/ramips/dts/mt7621_xiaoyu_xy-c5.dts index 4abaff751d..a943e0f89d 100644 --- a/target/linux/ramips/dts/mt7621_xiaoyu_xy-c5.dts +++ b/target/linux/ramips/dts/mt7621_xiaoyu_xy-c5.dts @@ -87,7 +87,8 @@ ðernet { compatible = "mediatek,ralink-mt7621-eth"; mediatek,switch = <&gsw>; - mtd-mac-address = <&factory 0x4>; + nvmem-cells = <&macaddr_factory_4>; + nvmem-cell-names = "mac-address"; }; &switch0 { diff --git a/target/linux/ramips/dts/mt7621_zbtlink_zbt-wg108.dts b/target/linux/ramips/dts/mt7621_zbtlink_zbt-wg108.dts index 5a670c87fb..b08e063879 100644 --- a/target/linux/ramips/dts/mt7621_zbtlink_zbt-wg108.dts +++ b/target/linux/ramips/dts/mt7621_zbtlink_zbt-wg108.dts @@ -9,10 +9,6 @@ compatible = "zbtlink,zbt-wg108", "mediatek,mt7621-soc"; model = "Zbtlink ZBT-WG108"; - aliases { - label-mac-device = &wifi1; - }; - chosen { bootargs = "console=ttyS0,115200"; }; @@ -76,7 +72,8 @@ }; &gmac0 { - mtd-mac-address = <&factory 0xe000>; + nvmem-cells = <&macaddr_factory_e000>; + nvmem-cell-names = "mac-address"; }; &switch0 { @@ -104,7 +101,8 @@ port@4 { status = "okay"; label = "wan"; - mtd-mac-address = <&factory 0xe006>; + nvmem-cells = <&macaddr_factory_e006>; + nvmem-cell-names = "mac-address"; }; }; }; @@ -132,3 +130,17 @@ &sdhci { status = "okay"; }; + +&factory { + compatible = "nvmem-cells"; + #address-cells = <1>; + #size-cells = <1>; + + macaddr_factory_e000: macaddr@e000 { + reg = <0xe000 0x6>; + }; + + macaddr_factory_e006: macaddr@e006 { + reg = <0xe006 0x6>; + }; +}; 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 a9f77a67a7..5933b6d716 100755 --- a/target/linux/ramips/mt7621/base-files/etc/board.d/02_network +++ b/target/linux/ramips/mt7621/base-files/etc/board.d/02_network @@ -33,6 +33,7 @@ ramips_setup_interfaces() ;; asiarf,ap7621-nv1|\ jcg,q20|\ + jdcloud,re-sp-01b|\ lenovo,newifi-d1|\ mikrotik,routerboard-m33g|\ xiaomi,mi-router-3g|\ @@ -142,7 +143,10 @@ ramips_setup_macs() wan_mac="$(grep -m1 mac= "/dev/mtd${index}" | cut -d= -f2)" lan_mac=$wan_mac ;; - d-team,newifi-d2) + d-team,newifi-d2|\ + phicomm,k2p|\ + xiaomi,mi-router-ac2100|\ + xiaomi,redmi-router-ac2100) lan_mac=$(cat /sys/class/net/eth0/address) wan_mac=$(mtd_get_mac_binary factory 0xe006) ;; @@ -188,6 +192,12 @@ ramips_setup_macs() wan_mac=$(mtd_get_mac_binary factory 0xe006) label_mac=$(mtd_get_mac_binary factory 0x4) ;; + jdcloud,re-sp-01b) + local index="$(find_mtd_index "config")" + label_mac=$(macaddr_canonicalize $(dd if="/dev/mtd${index}" bs=12 skip=17449 iflag=skip_bytes count=1 2>/dev/null)) + lan_mac=$label_mac + wan_mac=$label_mac + ;; linksys,e5600|\ linksys,ea7300-v1|\ linksys,ea7300-v2|\ @@ -211,14 +221,6 @@ ramips_setup_macs() lan_mac=$(mtd_get_mac_binary factory 0x4) wan_mac=$(macaddr_add "$lan_mac" 2) ;; - phicomm,k2p) - wan_mac=$(mtd_get_mac_binary factory 0xe006) - ;; - xiaomi,mi-router-ac2100|\ - xiaomi,redmi-router-ac2100) - lan_mac=$(cat /sys/class/net/eth0/address) - wan_mac=$(mtd_get_mac_binary factory 0xe000) - ;; xiaoyu,xy-c5) wan_mac=$(macaddr_add "$(mtd_get_mac_binary factory 0x4)" 1) ;; 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 711af4e3af..af3f46cc92 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 @@ -29,6 +29,12 @@ case "$board" in [ "$PHYNBR" = "1" ] && \ macaddr_setbit_la "$(mtd_get_mac_binary Factory 0x4)" > /sys${DEVPATH}/macaddress ;; + jdcloud,re-sp-01b) + local index="$(find_mtd_index "config")" + local label_mac=$(macaddr_canonicalize $(dd if="/dev/mtd${index}" bs=12 skip=17449 iflag=skip_bytes count=1 2>/dev/null)) + [ "$PHYNBR" -eq 0 ] && echo $label_mac > /sys${DEVPATH}/macaddress + [ "$PHYNBR" -eq 1 ] && macaddr_add $label_mac 0x800000 > /sys${DEVPATH}/macaddress + ;; linksys,e5600|\ linksys,ea7300-v1|\ linksys,ea7300-v2|\