7b98936ec3595d04522bb0552857ce12c1a2e7fc
[openwrt/staging/wigyori.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 iflag=skip_bytes bs=$count skip=$offset count=1 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 oflag=seek_bytes bs=6 seek=4 count=1 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,dir-510l|\
58 dlink,dwr-116-a1|\
59 dlink,dwr-118-a1|\
60 dlink,dwr-118-a2|\
61 dlink,dwr-921-c1|\
62 dlink,dwr-922-e2|\
63 lava,lr-25g001)
64 wan_mac=$(jboot_config_read -m -i $(find_mtd_part "config") -o 0xE000)
65 wifi_mac=$(macaddr_add "$wan_mac" 1)
66 jboot_eeprom_extract "config" 0xE000
67 rt2x00_eeprom_set_macaddr $wifi_mac
68 ;;
69 dovado,tiny-ac)
70 wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR)
71 rt2x00_eeprom_extract "factory" 0x0 0x200
72 rt2x00_eeprom_set_macaddr $wifi_mac
73 ;;
74 *)
75 rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!"
76 ;;
77 esac
78 ;;
79 esac