gemini: switch to 4.14
[openwrt/staging/dedeckeh.git] / target / linux / gemini / base-files / lib / preinit / 05_set_ether_mac_gemini
index 499608120e4c3613739ec5a62cbf6f68e12db7ca..1ce5c8067ef09c9874b8975a3527d43c5680e2b2 100644 (file)
@@ -1,13 +1,28 @@
 #!/bin/sh
 
 set_ether_mac() {
+       # Most devices have a standard "VCTL" partition
        CONFIG_PARTITION="$(grep "VCTL" /proc/mtd | cut -d: -f1)"
-       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,^:,,')"
+       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,^:,,')"
 
-       ifconfig eth0 hw ether $MAC1 2>/dev/null
-       ifconfig eth1 hw ether $MAC2 2>/dev/null
+               ifconfig eth0 hw ether $MAC1 2>/dev/null
+               ifconfig eth1 hw ether $MAC2 2>/dev/null
+               return 0
+       fi
+
+       # 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)"
+               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)"
+                       ifconfig eth0 hw ether $MAC1 2>/dev/null
+                       return 0
+               fi
+       fi
 }
 
 boot_hook_add preinit_main set_ether_mac
-