ramips: use nvmem to get mikrotik mac
authorRosen Penev <rosenp@gmail.com>
Sat, 24 Aug 2024 19:35:03 +0000 (12:35 -0700)
committerHauke Mehrtens <hauke@hauke-m.de>
Sat, 12 Oct 2024 20:26:56 +0000 (22:26 +0200)
73a9f9f857947bc63fef1aefb7e2e4b906fb9d2b added support. Let's use it.
Calibration data is not yet supported.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/16256
Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
target/linux/ramips/dts/mt7621_mikrotik.dtsi
target/linux/ramips/dts/mt7621_mikrotik_ltap-2hnd.dts
target/linux/ramips/dts/mt7621_mikrotik_routerboard-750gr3.dts
target/linux/ramips/dts/mt7621_mikrotik_routerboard-760igs.dts
target/linux/ramips/dts/mt7621_mikrotik_routerboard-7xx.dtsi
target/linux/ramips/dts/mt7621_mikrotik_routerboard-m11g.dts
target/linux/ramips/dts/mt7621_mikrotik_routerboard-m33g.dts
target/linux/ramips/mt7621/base-files/etc/board.d/02_network
target/linux/ramips/mt7621/base-files/etc/hotplug.d/firmware/10-ath9k-eeprom
target/linux/ramips/mt7621/config-6.6

index ace194c6d60a0e216b49c5db0dcb8abbfc8dc5ba..67892cc1a022c2723751b6315ffc51c736872519 100644 (file)
 
                                hard_config {
                                        read-only;
+
+                                       nvmem-layout {
+                                               compatible = "mikrotik,routerboot-nvmem";
+
+                                               macaddr_hard: base-mac-address {
+                                                       #nvmem-cell-cells = <1>;
+                                               };
+                                       };
                                };
 
                                partition@10000 {
index b5e38071f14207a0c74a9cef6d5cb7f122fdf24a..a3e3d8f4ce2bc98ab65d026188c73200eda28892 100644 (file)
@@ -11,6 +11,7 @@
                led-failsafe = &led_usr;
                led-running = &led_usr;
                led-upgrade = &led_usr;
+               label-mac-device = &ethernet;
        };
 
        ath9k-leds {
 
 &ethernet {
        pinctrl-0 = <&mdio_pins>, <&rgmii1_pins>;
+
+       nvmem-cells = <&macaddr_hard 0>;
+       nvmem-cell-names = "mac-address";
 };
 
 &switch0 {
                compatible = "pci168c,0030";
                reg = <0x0000 0 0 0 0>;
                qca,no-eeprom;
+               nvmem-cells = <&macaddr_hard 1>;
+               nvmem-cell-names = "mac-address";
                gpio-controller;
                #gpio-cells = <2>;
        };
index faa4e53f097ca9544f03a4a993b30c9a9fb59828..6357dceb6d44ba556fc183b6debe7394a9f66f77 100644 (file)
@@ -11,6 +11,7 @@
                led-failsafe = &led_usr;
                led-running = &led_usr;
                led-upgrade = &led_usr;
+               label-mac-device = &gmac1;
        };
 
        leds {
@@ -40,6 +41,9 @@
        status = "okay";
        label = "wan";
        phy-handle = <&ethphy0>;
+
+       nvmem-cells = <&macaddr_hard 0>;
+       nvmem-cell-names = "mac-address";
 };
 
 &ethphy0 {
index 8b88cfe0a31e5e19590b0ecca30bd474031620ec..c9d07cf96ccf68dc1d9b5280e62b7aa77df07a89 100644 (file)
@@ -11,6 +11,7 @@
                led-failsafe = &led_pwr;
                led-running = &led_pwr;
                led-upgrade = &led_pwr;
+               label-mac-device = &port0;
        };
 
        leds {
@@ -51,6 +52,9 @@
        label = "sfp";
        phy-mode = "rgmii-rxid";
        phy-handle = <&ephy7>;
+
+       nvmem-cells = <&macaddr_hard 5>;
+       nvmem-cell-names = "mac-address";
 };
 
 &i2c {
index b8fae51c3b3a79034f47c15ebd6fa4ad813b74c2..cdca47f8b8c77aba6c94126f51385aadf0e0bb92 100644 (file)
 
 &switch0 {
        ports {
-               port@0 {
+               port0: port@0 {
                        status = "okay";
                        label = "wan";
+
+                       nvmem-cells = <&macaddr_hard 0>;
+                       nvmem-cell-names = "mac-address";
                };
 
                port@1 {
                        status = "okay";
                        label = "lan2";
+
+                       nvmem-cells = <&macaddr_hard 1>;
+                       nvmem-cell-names = "mac-address";
                };
 
                port@2 {
                        status = "okay";
                        label = "lan3";
+
+                       nvmem-cells = <&macaddr_hard 2>;
+                       nvmem-cell-names = "mac-address";
                };
 
                port@3 {
                        status = "okay";
                        label = "lan4";
+
+                       nvmem-cells = <&macaddr_hard 3>;
+                       nvmem-cell-names = "mac-address";
                };
 
                port@4 {
                        status = "okay";
                        label = "lan5";
+
+                       nvmem-cells = <&macaddr_hard 4>;
+                       nvmem-cell-names = "mac-address";
                };
        };
 };
index 5f9ee90e7cc09bd7144762f2fe9259268a41ca27..89ef5fb3fd694fc2e5ef017bb8b2271f1504e8cb 100644 (file)
@@ -9,6 +9,7 @@
                led-failsafe = &led_usr;
                led-running = &led_usr;
                led-upgrade = &led_usr;
+               label-mac-device = &ethernet;
        };
 
        leds {
@@ -68,6 +69,9 @@
 
 &ethernet {
        pinctrl-0 = <&mdio_pins>, <&rgmii1_pins>;
+
+       nvmem-cells = <&macaddr_hard 0>;
+       nvmem-cell-names = "mac-address";
 };
 
 &switch0 {
@@ -75,6 +79,9 @@
                port@0 {
                        status = "okay";
                        label = "lan";
+
+                       nvmem-cells = <&macaddr_hard 1>;
+                       nvmem-cell-names = "mac-address";
                };
        };
 };
index 5e762615292a59ba7107727e32b356e0b44c4da1..e26d3cee2e9c310446c60972907de2bade398b88 100644 (file)
@@ -9,6 +9,7 @@
                led-failsafe = &led_usr;
                led-running = &led_usr;
                led-upgrade = &led_usr;
+               label-mac-device = &gmac1;
        };
 
        leds {
@@ -94,6 +95,9 @@
        status = "okay";
        label = "wan";
        phy-handle = <&ethphy0>;
+
+       nvmem-cells = <&macaddr_hard 0>;
+       nvmem-cell-names = "mac-address";
 };
 
 &ethphy0 {
                port@1 {
                        status = "okay";
                        label = "lan1";
+
+                       nvmem-cells = <&macaddr_hard 1>;
+                       nvmem-cell-names = "mac-address";
                };
 
                port@2 {
                        status = "okay";
                        label = "lan2";
+
+                       nvmem-cells = <&macaddr_hard 2>;
+                       nvmem-cell-names = "mac-address";
                };
        };
 };
index 12098f0bbfa6a8f6c3740a45b4b81a7bc7a5985c..471f9ecfbda49c3b544353ca53e06500b0c029a2 100644 (file)
@@ -299,10 +299,6 @@ ramips_setup_macs()
                wan_mac=$(mtd_get_mac_ascii Config wan_hwaddr)
                label_mac=$lan_mac
                ;;
-       mikrotik,ltap-2hnd)
-               label_mac=$(cat "/sys/firmware/mikrotik/hard_config/mac_base")
-               lan_mac=$label_mac
-               ;;
        tplink,er605-v2)
                CI_UBIPART="firmware"
                label_mac=$(mtd_get_mac_uci_config_ubi "tddp")
@@ -314,14 +310,6 @@ ramips_setup_macs()
                wwan_mac=$(macaddr_add $label_mac 1)
                ucidef_set_interface "wwan0" device "/dev/cdc-wdm0" protocol "qmi" macaddr "$wwan_mac"
                ;;
-       mikrotik,routerboard-750gr3|\
-       mikrotik,routerboard-760igs|\
-       mikrotik,routerboard-m11g|\
-       mikrotik,routerboard-m33g)
-               label_mac=$(cat "/sys/firmware/mikrotik/hard_config/mac_base")
-               wan_mac=$label_mac
-               lan_mac=$(macaddr_add $label_mac 1)
-               ;;
        ruijie,rg-ew1200g-pro-v1.1)
                lan_mac=$(mtd_get_mac_ascii product_info ethaddr)
                wan_mac=$(macaddr_add "$lan_mac" 8)
index 0bf5e85cd0134d3687ed0733f761597c88cdaa32..a334d1a5a08a686eb74cfb0c868670fde6781589 100644 (file)
@@ -4,26 +4,13 @@
 
 . /lib/functions/caldata.sh
 
-caldata_mikrotik_ath9k() {
-       local offset=$(($1))
-       local count=$(($2))
-       local macaddr=$3
-       local wlan_data="/sys/firmware/mikrotik/hard_config/wlan_data"
-
-       caldata_from_file $wlan_data $offset $count /tmp/$FIRMWARE
-       ath9k_patch_mac "$macaddr" /tmp/$FIRMWARE
-       caldata_sysfsload_from_file /tmp/$FIRMWARE 0x0 $count
-       rm -f /tmp/$FIRMWARE
-}
-
 board=$(board_name)
 
 case "$FIRMWARE" in
 "ath9k-eeprom-pci-0000:01:00.0.bin")
        case $board in
        mikrotik,ltap-2hnd)
-               mac_base="$(cat /sys/firmware/mikrotik/hard_config/mac_base)"
-               caldata_mikrotik_ath9k 0x5000 0x440 $(macaddr_add "$mac_base" 1)
+               caldata_sysfsload_from_file "/sys/firmware/mikrotik/hard_config/wlan_data" 0x5000 0x440
                ;;
        *)
                caldata_die "board $board is not supported yet"
index adbb7c846540b08b602a6f94caa015e7f486521d..5e10f03ac18af2f4ff27b0db50fceaad4273f6cc 100644 (file)
@@ -202,7 +202,7 @@ CONFIG_NO_HZ_IDLE=y
 CONFIG_NR_CPUS=4
 CONFIG_NVMEM=y
 CONFIG_NVMEM_LAYOUTS=y
-# CONFIG_NVMEM_LAYOUT_MIKROTIK is not set
+CONFIG_NVMEM_LAYOUT_MIKROTIK=y
 CONFIG_NVMEM_LAYOUT_U_BOOT_ENV=y
 CONFIG_OF=y
 CONFIG_OF_ADDRESS=y