ar71xx: extract ath10k wifi board.bin for the OpenMesh OM5P-ACv2 board
[openwrt/staging/wigyori.git] / target / linux / ar71xx / base-files / etc / hotplug.d / firmware / 11-ath10k-caldata
1 #!/bin/sh
2
3 ath10kcal_die() {
4 echo "ath10cal: " "$*"
5 exit 1
6 }
7
8 ath10kcal_from_file() {
9 local source=$1
10 local offset=$2
11 local count=$3
12
13 dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
14 ath10kcal_die "failed to extract calibration data from $source"
15 }
16
17 ath10kcal_extract() {
18 local part=$1
19 local offset=$2
20 local count=$3
21 local mtd
22
23 mtd=$(find_mtd_chardev $part)
24 [ -n "$mtd" ] || \
25 ath10kcal_die "no mtd device found for partition $part"
26
27 dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
28 ath10kcal_die "failed to extract calibration data from $mtd"
29 }
30
31 ath10kcal_patch_mac() {
32 local mac=$1
33
34 [ -z "$mac" ] && return
35
36 macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6
37 }
38
39 [ -e /lib/firmware/$FIRMWARE ] && exit 0
40
41 . /lib/ar71xx.sh
42 . /lib/functions.sh
43 . /lib/functions/system.sh
44
45 board=$(ar71xx_board_name)
46
47 case "$FIRMWARE" in
48 "ath10k/cal-pci-0000:00:00.0.bin")
49 case $board in
50 dlan-pro-1200-ac)
51 ath10kcal_extract "art" 20480 2116
52 ;;
53 mc-mac1200r)
54 ath10kcal_extract "art" 20480 2116
55 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -1)
56 ;;
57 tl-wdr6500-v2)
58 ath10kcal_extract "art" 20480 2116
59 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
60 ;;
61 r6100)
62 ath10kcal_extract "caldata" 20480 2116
63 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) +2)
64 ;;
65 qihoo-c301)
66 ath10kcal_extract "radiocfg" 20480 2116
67 ath10kcal_patch_mac $(mtd_get_mac_ascii devdata wlan5mac)
68 ;;
69 esr1750 | \
70 epg5000)
71 ath10kcal_extract "caldata" 20480 2116
72 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
73 ;;
74 mr1750 | \
75 om5p-acv2)
76 ath10kcal_extract "ART" 20480 2116
77 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
78 ;;
79 unifiac)
80 ath10kcal_extract "EEPROM" 20480 2116
81 ;;
82 esac
83 ;;
84 "ath10k/cal-pci-0000:01:00.0.bin")
85 case $board in
86 archer-c5 | \
87 archer-c7)
88 ath10kcal_extract "art" 20480 2116
89 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
90 ;;
91 nbg6616 | \
92 nbg6716)
93 ath10kcal_extract "RFdata" 20480 2116
94 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
95 ;;
96 rb-911g-5hpacd)
97 ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 20480 2116
98 ;;
99 om5p-ac)
100 ath10kcal_extract "ART" 20480 2116
101 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
102 ;;
103 esac
104 ;;
105 *)
106 exit 1
107 ;;
108 esac