c2d87f58de987e283c1ab95d67ee0082ef2f1e28
[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 "ubnt,unifi")
54 ath9k_eeprom_extract "art" 4096 2048
55 ;;
56 *)
57 ath9k_eeprom_die "board $board is not supported yet"
58 ;;
59 esac
60 ;;
61 esac