ath79: add support for TP-Link TL-WDR4900 v2
[openwrt/staging/wigyori.git] / target / linux / ath79 / base-files / etc / hotplug.d / firmware / 10-ath9k-eeprom
1 #!/bin/sh
2
3 [ -e /lib/firmware/$FIRMWARE ] && exit 0
4
5 . /lib/functions.sh
6 . /lib/functions/system.sh
7
8 ath9k_eeprom_die() {
9 echo "ath9k eeprom: " "$*"
10 exit 1
11 }
12
13 ath9k_eeprom_extract() {
14 local part=$1
15 local offset=$2
16 local count=$3
17 local mtd
18
19 mtd=$(find_mtd_chardev $part)
20 [ -n "$mtd" ] || \
21 ath9k_eeprom_die "no mtd device found for partition $part"
22
23 dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
24 ath9k_eeprom_die "failed to extract from $mtd"
25 }
26
27 ath9k_eeprom_extract_reverse() {
28 local part=$1
29 local offset=$2
30 local count=$3
31 local mtd
32 local reversed
33 local caldata
34
35 mtd=$(find_mtd_chardev "$part")
36 reversed=$(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
37
38 for byte in $reversed; do
39 caldata="\x${byte}${caldata}"
40 done
41
42 printf "%b" "$caldata" > /lib/firmware/$FIRMWARE
43 }
44
45 board=$(board_name)
46
47 case "$FIRMWARE" in
48 "ath9k-eeprom-pci-0000:00:00.0.bin")
49 case $board in
50 avm,fritz300e)
51 ath9k_eeprom_extract_reverse "urloader" 5441 1088
52 ;;
53 ocedo,raccoon|\
54 tplink,tl-wdr3600|\
55 tplink,tl-wdr4300|\
56 tplink,tl-wdr4900-v2)
57 ath9k_eeprom_extract "art" 20480 1088
58 ;;
59 netgear,wnr612-v2|\
60 on,n150r|\
61 pcs,cap324|\
62 tplink,tl-mr3220-v1|\
63 tplink,tl-mr3420-v1|\
64 tplink,tl-wr2543-v1|\
65 tplink,tl-wr740n-v1|\
66 tplink,tl-wr740n-v3|\
67 tplink,tl-wr741-v1|\
68 tplink,tl-wr743nd-v1|\
69 tplink,tl-wr841-v7|\
70 ubnt,unifi)
71 ath9k_eeprom_extract "art" 4096 2048
72 ;;
73 tplink,tl-wr841-v5|\
74 tplink,tl-wr941-v4)
75 ath9k_eeprom_extract "art" 4096 3768
76 ;;
77 *)
78 ath9k_eeprom_die "board $board is not supported yet"
79 ;;
80 esac
81 ;;
82 esac