]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
base-files: add mtd_get_mac_uci_config()
authorCharles Joynson <ctjoynson@gmail.com>
Sat, 8 Aug 2026 04:40:01 +0000 (00:40 -0400)
committerJonas Jelonek <jelonek.jonas@gmail.com>
Tue, 11 Aug 2026 21:18:26 +0000 (23:18 +0200)
Add mtd_get_mac_uci_config() for reading a MAC address from a UCI-style
config stored in an MTD partition. This is needed to support the
TP-Link ER605 v1; the existing UBI helper already covers the ER605 v2.
Also refactor common sed logic into a shared helper used by both
variants and drop the redundant cat pipe.

TP-Link ER605 v2 device support is unaffected. The one and only MAC
address on the tddp partition for v1/v2 is the label MAC address.

Signed-off-by: Charles Joynson <ctjoynson@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/24331
Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
package/base-files/files/lib/functions/system.sh

index eaed0fba110448ded33a98606942d66d79075158..109f8735926e61cfb5764ee237ce4bd7493877ef 100644 (file)
@@ -136,6 +136,25 @@ mtd_get_mac_encrypted_deco() {
        echo $macaddr
 }
 
+get_mac_uci_config() {
+       local file="$1"
+
+       sed -n 's/^\s*option macaddr\s*'"'"'\?\([0-9A-F:]\+\)'"'"'\?/\1/Ip' "$file" | head -n1
+}
+
+mtd_get_mac_uci_config() {
+       local mtdname="$1"
+       local part
+
+       part=$(find_mtd_part "$mtdname")
+       if [ -z "$part" ]; then
+               echo "mtd_get_mac_uci_config: partition $mtdname not found!" >&2
+               return
+       fi
+
+       get_mac_uci_config "$part"
+}
+
 mtd_get_mac_uci_config_ubi() {
        local volumename="$1"
 
@@ -144,7 +163,7 @@ mtd_get_mac_uci_config_ubi() {
        local ubidev=$(nand_attach_ubi $CI_UBIPART)
        local part=$(nand_find_volume $ubidev $volumename)
 
-       cat "/dev/$part" | sed -n 's/^\s*option macaddr\s*'"'"'\?\([0-9A-F:]\+\)'"'"'\?/\1/Ip'
+       get_mac_uci_config "/dev/$part"
 }
 
 mtd_get_mac_text() {