3712975fa8be0a12e9f5917690a84f5005188d10
[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 case "$(board_name)" in
13 dlink,dns-313)
14 # The DNS-313 has a special field in its RedBoot
15 # binary that we need to check
16 part="$(find_mtd_part RedBoot)"
17 if [ -n "$part" ]; then
18 DEVID="$(dd if=$part bs=1 skip=119508 count=7 2>/dev/null)"
19 if [ "$DEVID" = "dns-313" ]; then
20 MAC1="$(mtd_get_mac_binary RedBoot 0x1d2f4)"
21 ip link set eth0 address "$MAC1" 2>/dev/null
22 return 0
23 fi
24 fi
25 ;;
26 dlink,dir-685)
27 # The DIR-685 has a special field in its RedBoot
28 # binary that we need to check
29 part=$(find_mtd_part RedBoot)
30 if [ -n "$part" ] ; then
31 DEVID="$(dd if=$part bs=1 skip=81516 count=7 2>/dev/null)"
32 if [ "$DEVID" = "ILI9322" ] ; then
33 MAC1=$(mtd_get_mac_binary RedBoot 0x17340)
34 MAC2=$(mtd_get_mac_binary RedBoot 0x17346)
35 ip link set eth0 address "$MAC1" 2>/dev/null
36 ip link set eth1 address "$MAC2" 2>/dev/null
37 return 0
38 fi
39 fi
40 ;;
41 esac
42
43 # Most devices have a standard "VCTL" partition
44 part="$(find_mtd_part VCTL)"
45 if [ -n "$part" ]; then
46 MAC1="$(strings $part |grep MAC|cut -d: -f2|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')"
47 MAC2="$(strings $part |grep MAC|cut -d: -f8|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')"
48
49 ip link set eth0 address "$MAC1" 2>/dev/null
50 ip link set eth1 address "$MAC2" 2>/dev/null
51 return 0
52 fi
53 }
54
55 boot_hook_add preinit_main set_ether_mac