[OpenWrt-Devel] [PATCH 1/3 v2] gemini: Use library functions to assign MAC address

Linus Walleij linus.walleij at linaro.org
Tue Jun 11 17:06:53 EDT 2019


This simplifies the ethernet address extraction script
by using standard library functions to locate the MTD
partitions and extract ethernet address from a binary
offset location in the flash.

Suggested-by: Christian Lamparter <chunkeey at gmail.com>
Signed-off-by: Linus Walleij <linus.walleij at linaro.org>
---
ChangeLog v1->v2:
- New patch prepended to the series
- Hold back switchover to use "ip" rather than "ifconfig".
  ip link set eth0 address 00:50:c2:11:11:11
  returns
  ip: socket(AF_PACKET,2,0): Address family not supported by protocol
  We can fix up the use of "ip" when we know why it's not
  working.
---
 .../lib/preinit/05_set_ether_mac_gemini       | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/target/linux/gemini/base-files/lib/preinit/05_set_ether_mac_gemini b/target/linux/gemini/base-files/lib/preinit/05_set_ether_mac_gemini
index 1ce5c8067ef0..a79ee5057ffc 100644
--- a/target/linux/gemini/base-files/lib/preinit/05_set_ether_mac_gemini
+++ b/target/linux/gemini/base-files/lib/preinit/05_set_ether_mac_gemini
@@ -1,11 +1,14 @@
 #!/bin/sh
 
+. /lib/functions.sh
+. /lib/functions/system.sh
+
 set_ether_mac() {
 	# Most devices have a standard "VCTL" partition
-	CONFIG_PARTITION="$(grep "VCTL" /proc/mtd | cut -d: -f1)"
-	if [ ! -z $CONFIG_PARTITION ] ; then
-		MAC1="$(strings /dev/$CONFIG_PARTITION |grep MAC|cut -d: -f2|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')"
-		MAC2="$(strings /dev/$CONFIG_PARTITION |grep MAC|cut -d: -f8|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')"
+	part=$(find_mtd_part VCTL)
+	if [ ! -z $part ] ; then
+		MAC1="$(strings $part |grep MAC|cut -d: -f2|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')"
+		MAC2="$(strings $part |grep MAC|cut -d: -f8|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')"
 
 		ifconfig eth0 hw ether $MAC1 2>/dev/null
 		ifconfig eth1 hw ether $MAC2 2>/dev/null
@@ -14,11 +17,11 @@ set_ether_mac() {
 
 	# The DNS-313 has a special field in its RedBoot
 	# binary that we need to check
-	CONFIG_PARTITION="$(grep "RedBoot" /proc/mtd | cut -d: -f1)"
-	if [ ! -z $CONFIG_PARTITION ] ; then
-		DEVID="$(dd if=/dev/mtdblock0 bs=1 skip=119508 count=7 2>/dev/null)"
+	part=$(find_mtd_part RedBoot)
+	if [ ! -z $part ] ; then
+		DEVID="$(dd if=$part bs=1 skip=119508 count=7 2>/dev/null)"
 		if [ "x$DEVID" = "xdns-313" ] ; then
-			MAC1="$(dd if=/dev/mtdblock0 bs=1 skip=119540 count=6 2>/dev/null | hexdump -n6 -e '/1 ":%02X"' | sed s/^://g)"
+			MAC1=$(mtd_get_mac_binary RedBoot 119540)
 			ifconfig eth0 hw ether $MAC1 2>/dev/null
 			return 0
 		fi
-- 
2.21.0


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list