ramips: add support for D-Link DWR-118-A1
[openwrt/openwrt.git] / target / linux / ramips / base-files / etc / hotplug.d / firmware / 10-rt2x00-eeprom
1 #!/bin/sh
2
3 rt2x00_eeprom_die() {
4 echo "rt2x00 eeprom: " "$*"
5 exit 1
6 }
7
8 rt2x00_eeprom_extract() {
9 local part=$1
10 local offset=$2
11 local count=$3
12 local mtd
13
14 mtd=$(find_mtd_part $part)
15 [ -n "$mtd" ] || \
16 rt2x00_eeprom_die "no mtd device found for partition $part"
17
18 dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
19 rt2x00_eeprom_die "failed to extract from $mtd"
20 }
21
22 jboot_eeprom_extract() {
23 local part=$1
24 local offset=$2
25 local mtd
26
27 mtd=$(find_mtd_part $part)
28 [ -n "$mtd" ] || \
29 rt2x00_eeprom_die "no mtd device found for partition $part"
30
31 jboot_config_read -i $mtd -o $offset -e /lib/firmware/$FIRMWARE 2>/dev/null || \
32 rt2x00_eeprom_die "failed to extract from $mtd"
33 }
34
35 rt2x00_eeprom_set_macaddr() {
36 local macaddr=$1
37
38 [ -n "$macaddr" ] || \
39 rt2x00_eeprom_die "invalid wlan mac address"
40
41 macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \
42 conv=notrunc bs=1 seek=4 count=6 2>/dev/null || \
43 rt2x00_eeprom_die "failed to write mac address to eeprom file"
44 }
45
46 FW="/lib/firmware/$FIRMWARE"
47 [ -e "$FW" ] && exit 0
48
49 . /lib/functions.sh
50 . /lib/functions/system.sh
51
52 board=$(board_name)
53
54 case "$FIRMWARE" in
55 "soc_wmac.eeprom")
56 case $board in
57 dlink,dwr-116-a1|\
58 dlink,dwr-118-a1|\
59 dlink,dwr-118-a2|\
60 dlink,dwr-921-c1|\
61 lava,lr-25g001)
62 wan_mac=$(jboot_config_read -m -i $(find_mtd_part "config") -o 0xE000)
63 wifi_mac=$(macaddr_add "$wan_mac" 1)
64 jboot_eeprom_extract "config" 0xE000
65 rt2x00_eeprom_set_macaddr $wifi_mac
66 ;;
67 tiny-ac)
68 wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR)
69 rt2x00_eeprom_extract "factory" 0 512
70 rt2x00_eeprom_set_macaddr $wifi_mac
71 ;;
72 *)
73 rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!"
74 ;;
75 esac
76 ;;
77 esac