ath79: put all devices in alphabetical order in scripts
[openwrt/openwrt.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 ath9k_eeprom_extract "art" 20480 1088
57 ;;
58 "netgear,wnr612-v2"|\
59 "on,n150r"|\
60 "pcs,cap324"|\
61 "tplink,tl-mr3220-v1"|\
62 "tplink,tl-mr3420-v1"|\
63 "tplink,tl-wr2543-v1"|\
64 "tplink,tl-wr740n-v2"|\
65 "tplink,tl-wr841-v7"|\
66 "ubnt,unifi")
67 ath9k_eeprom_extract "art" 4096 2048
68 ;;
69 *)
70 ath9k_eeprom_die "board $board is not supported yet"
71 ;;
72 esac
73 ;;
74 esac