60e278782fcc937e817b269a048425991a190332
[librecmc/librecmc.git] / target / linux / ar71xx / base-files / lib / preinit / 05_set_iface_mac_ar71xx
1 #
2 # Copyright (C) 2009 OpenWrt.org
3 #
4
5 . /lib/ar71xx.sh
6
7 fetch_mac_from_mtd() {
8         local mtd_part=$1
9         local lan_env=$2
10         local wan_env=$3
11         local mtd mac
12
13         mtd=$(grep $mtd_part /proc/mtd | cut -d: -f1)
14         [ -z $mtd ] && return
15
16         mac=$(grep $lan_env /dev/$mtd | cut -d= -f2)
17         [ ! -z $mac ] && ifconfig eth0 hw ether $mac 2>/dev/null
18
19         mac=$(grep $wan_env /dev/$mtd | cut -d= -f2)
20         [ ! -z $mac ] && ifconfig eth1 hw ether $mac 2>/dev/null
21 }
22
23 preinit_set_mac_address() {
24         case $(ar71xx_board_name) in
25                 c-55)
26                         mac_lan=$(mtd_get_mac_binary art 0)
27                         [ -n "$mac_lan" ] && ifconfig eth0 hw ether "$mac_lan"
28                         ;;
29                 dir-615-c1)
30                         fetch_mac_from_mtd config lan_mac wan_mac
31                         echo 1 > /sys/class/leds/dir-615-c1:green:wancpu/brightness
32                         ;;
33                 dir-615-i1)
34                         fetch_mac_from_mtd nvram sys_lan_mac sys_wan_mac
35                         ;;
36                 mr18)
37                         mac_lan=$(mtd_get_mac_binary_ubi board-config 102)
38                         [ -n "$mac_lan" ] && ifconfig eth0 hw ether "$mac_lan"
39                         ;;
40                 r6100)
41                         mac_lan=$(mtd_get_mac_binary caldata 0)
42                         [ -n "$mac_lan" ] && ifconfig eth1 hw ether "$mac_lan"
43                         mac_wan=$(mtd_get_mac_binary caldata 6)
44                         [ -n "$mac_wan" ] && ifconfig eth0 hw ether "$mac_wan"
45                         ;;
46                 tew-632brp)
47                         fetch_mac_from_mtd config lan_mac wan_mac
48                         ;;
49                 wrt160nl)
50                         fetch_mac_from_mtd nvram lan_hwaddr wan_hwaddr
51                         ;;
52                 z1)
53                         mac_lan=$(mtd_get_mac_binary_ubi board-config 102)
54                         [ -n "$mac_lan" ] && ifconfig eth0 hw ether "$mac_lan"
55                         ;;
56         esac
57 }
58
59 boot_hook_add preinit_main preinit_set_mac_address