]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: uci-defaults: refactor and expand fwenv ethaddr hack
authorLars Gierth <larsg@systemli.org>
Thu, 28 May 2026 23:33:24 +0000 (01:33 +0200)
committerMarkus Stockhausen <markus.stockhausen@gmx.de>
Fri, 19 Jun 2026 15:43:51 +0000 (17:43 +0200)
With the upcoming addition of the Hasivo F5800W-12S+ switch model,
another invariant of the u-boot env ethaddr fixup will be neccessary.
While previously all devices used the exact "zero" dummy ethaddr,
this new Hasivo ends in :10 instead of :00.

Make the hack work based on the 5-byte prefix of the ethaddr.
The currently known possible values for the 6th byte are 0x00 and 0x10.
This can be further expanded in the future if neccessary.

The separate XGS1010-12-A1 case doesn't need to deal with ethaddr prefixes
as it only covers one single device with one single dummy ethaddr.

Also use this opportunity to add more documentation,
and extract the common json and fw_setenv logic to a separate function.

Signed-off-by: Lars Gierth <larsg@systemli.org>
Link: https://github.com/openwrt/openwrt/pull/23443
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
target/linux/realtek/base-files/etc/board.d/02_network
target/linux/realtek/base-files/etc/uci-defaults/99_fwenv-store-ethaddr

index cdd5ded1dac26b1a79d687e2eb1c7d1052885779..eed572aaf33e6b89f44ea02c9235f64fcb39e3bc 100644 (file)
@@ -103,7 +103,8 @@ realtek_setup_macs()
        tplink,tl-st1008f-v2|\
        zyxel,xgs1010-12-a1)
                lan_mac=$(mtd_get_mac_ascii u-boot-env ethaddr)
-               [ -z "$lan_mac" ] || [ "$lan_mac" = "00:e0:4c:00:00:00" ] && lan_mac=$(macaddr_random)
+               mac_prefix=$(echo "$lan_mac" | cut -d: -f1-5)
+               [ -z "$lan_mac" ] || [ "$mac_prefix" = "00:e0:4c:00:00" ] && lan_mac=$(macaddr_random)
                lan_mac_start=$lan_mac
                eth0_mac=$lan_mac
                ;;
index 3d9e7953114cbd495a94c8d295499ac4f7bbbcd5..f6974f96f9d482e02c28aa83c85ef5583a8e0ada 100644 (file)
@@ -11,48 +11,53 @@ BOARD_CFG=/etc/board.json
 
 # Some devices make it hard or impossible to acquire a usable ethaddr / MAC address
 # of the device. Some store it in weird places, some ship with only the common
-# Realtek dummy ethaddr, and some are outright broken.
+# Realtek dummy ethaddr, and some are outright broken. Often the MAC address
+# isn't printed on the case label either.
 #
 # For these devices, we generate a random ethaddr in /etc/board.d/02_network,
-# which is stored in /etc/board.json. Here we take this random ethaddr and
-# persist it in the U-Boot environment, so that it survives sysupgrades.
+# which is saved in /etc/board.json.
+#
+# Here we take this random ethaddr and store it in the U-Boot environment,
+# so that it survives sysupgrades and factory resets.
+
+store_board_ethaddr() {
+       local board_ethaddr
+       json_init
+       json_load_file "$BOARD_CFG"
+       json_select network_device
+       json_select eth0
+       json_get_var board_ethaddr macaddr
+       json_cleanup
+       [ -n "$board_ethaddr" ] && fw_setenv ethaddr "$board_ethaddr"
+}
 
 case "$(board_name)" in
+# F1100W-4SX-4XGT and its variants ship with the dummy ethaddr in the u-boot
+# environment, and the real ethaddr stored in RUNTIME/RUNTIME2 JFFS2 partitions,
+# which would be annoying to deal with. Also ethaddr isn't printed on the case.
+#
+# TL-ST1008F v2 ships with a dummy ethaddr because it's an unmanaged switch.
+#
+# We store the random ethaddr if the currently stored ethaddr is empty or dummy.
 hasivo,f1100w-4sx-4xgt|\
 hasivo,f1100w-4sx-4xgt-512mb|\
 tplink,tl-st1008f-v2)
        env_ethaddr=$(macaddr_canonicalize "$(fw_printenv -n ethaddr 2>/dev/null)")
+       ethaddr_prefix=$(echo "$env_ethaddr" | cut -d: -f1-5)
 
-       # F1100W-4SX-4XGT and its variants ship with the dummy ethaddr in the u-boot
-       # environment, and the real ethaddr stored in RUNTIME/RUNTIME2 JFFS2 partitions,
-       # which would be annoying to deal with. Also ethaddr isn't printed on the case.
-       #
-       # TL-ST1008F v2 ships with a dummy ethaddr because it's an unmanaged switch.
-       #
-       # We persist the random ethaddr if the currently stored ethaddr is empty or dummy.
-       if [ -z "$env_ethaddr" ] || [ "$env_ethaddr" = "00:e0:4c:00:00:00" ]; then
-               json_init
-               json_load_file "$BOARD_CFG"
-               json_select network_device
-               json_select eth0
-               json_get_var board_ethaddr macaddr
-               [ -n "$board_ethaddr" ] && fw_setenv ethaddr "$board_ethaddr"
+       if [ -z "$env_ethaddr" ] || [ "$ethaddr_prefix" = "00:e0:4c:00:00" ]; then
+               store_board_ethaddr
        fi
        ;;
+# This device ships with an empty environment (invalid CRC). If it is still in
+# that state, we don't want to modify it, because that would write the defaults
+# of the userspace U-Boot tools (which differ from the ones in the bootloader).
+# Thus, we don't do anything here if the ethaddr variable is empty.
 zyxel,xgs1010-12-a1)
        env_ethaddr=$(macaddr_canonicalize "$(fw_printenv -n ethaddr 2>/dev/null)")
 
-       # This device ships with an empty environment (invalid CRC). If it is still in
-       # that state, we don't want to modify it, because that would write the defaults
-       # of the userspace U-Boot tools (which differ from the ones in the bootloader).
-       # Thus, we don't do anything here if the ethaddr variable is empty.
        if [ "$env_ethaddr" = "00:e0:4c:00:00:00" ]; then
-               json_init
-               json_load_file "$BOARD_CFG"
-               json_select network_device
-               json_select eth0
-               json_get_var board_ethaddr macaddr
-               [ -n "$board_ethaddr" ] && fw_setenv ethaddr "$board_ethaddr"
+               store_board_ethaddr
        fi
        ;;
 esac