fed76a3e221b95d1459bb99e0652c6c9d5caeb29
[openwrt/openwrt.git] / target / linux / gemini / base-files / lib / preinit / 05_set_ether_mac_gemini
1 #!/bin/sh
2
3 . /lib/functions.sh
4 . /lib/functions/system.sh
5
6 set_ether_mac() {
7 local part
8 local DEVID
9 local MAC1
10 local MAC2
11
12 # Most devices have a standard "VCTL" partition
13 part="$(find_mtd_part VCTL)"
14 if [ -n "$part" ]; then
15 MAC1="$(strings $part |grep MAC|cut -d: -f2|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')"
16 MAC2="$(strings $part |grep MAC|cut -d: -f8|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')"
17
18 ip link set eth0 address "$MAC1" 2>/dev/null
19 ip link set eth1 address "$MAC2" 2>/dev/null
20 return 0
21 fi
22
23 # The DNS-313 has a special field in its RedBoot
24 # binary that we need to check
25 part="$(find_mtd_part RedBoot)"
26 if [ -n "$part" ]; then
27 DEVID="$(dd if=$part bs=1 skip=119508 count=7 2>/dev/null)"
28 if [ "$DEVID" = "dns-313" ]; then
29 MAC1="$(mtd_get_mac_binary RedBoot 119540)"
30 ip link set eth0 address "$MAC1" 2>/dev/null
31 return 0
32 fi
33 fi
34 }
35
36 boot_hook_add preinit_main set_ether_mac