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