netifd: update to latest git HEAD
[openwrt/openwrt.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 iflag=skip_bytes bs=$count skip=$offset count=1 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 cal_size
22
23 mtd=$(find_mtd_chardev $part)
24 [ -n "$mtd" ] || \
25 ath10kcal_die "no mtd device found for partition $part"
26
27 # Check that the calibration data size in header equals the desired size
28 cal_size=$(dd if=$mtd bs=2 count=1 skip=$(( $offset / 2 )) conv=swab 2>/dev/null | hexdump -ve '1/2 "%d"')
29
30 [ "$count" = "$cal_size" ] || \
31 ath10kcal_die "no calibration data found in $part"
32
33 dd if=$mtd of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \
34 ath10kcal_die "failed to extract calibration data from $mtd"
35 }
36
37 ath10kcal_patch_mac() {
38 local mac=$1
39
40 [ -z "$mac" ] && return
41
42 macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc oflag=seek_bytes bs=6 seek=6 count=1
43 }
44
45 [ -e /lib/firmware/$FIRMWARE ] && exit 0
46
47 . /lib/functions.sh
48 . /lib/functions/system.sh
49
50 board=$(board_name)
51
52 case "$FIRMWARE" in
53 "ath10k/cal-pci-0000:00:00.0.bin")
54 case $board in
55 a40|\
56 a60|\
57 mr1750|\
58 mr1750v2|\
59 om5p-acv2)
60 ath10kcal_extract "ART" 20480 2116
61 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
62 ;;
63 archer-c25-v1|\
64 tl-wdr6500-v2)
65 ath10kcal_extract "art" 20480 2116
66 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
67 ;;
68 archer-c7-v4|\
69 archer-c7-v5)
70 ath10kcal_extract "art" 20480 2116
71 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -1)
72 ;;
73 cf-e355ac-v1|\
74 cf-e380ac-v1|\
75 cf-e380ac-v2|\
76 dlan-pro-1200-ac|\
77 e1700ac-v2|\
78 e600gac-v2|\
79 minibox-v3.2|\
80 oolite-v5.2|\
81 oolite-v5.2-dev|\
82 sr3200|\
83 xd3200)
84 ath10kcal_extract "art" 20480 2116
85 ;;
86 dap-2695-a1)
87 ath10kcal_extract "radiocfg" 20480 2116
88 ath10kcal_patch_mac $(mtd_get_mac_ascii bdcfg wlanmac_a)
89 ;;
90 dir-869-a1|\
91 qihoo-c301)
92 ath10kcal_extract "radiocfg" 20480 2116
93 ath10kcal_patch_mac $(mtd_get_mac_ascii devdata wlan5mac)
94 ;;
95 dw33d)
96 ath10kcal_extract "art" 20480 2116
97 ath10kcal_patch_mac $(mtd_get_mac_binary art 18)
98 ;;
99 epg5000|\
100 esr1750)
101 ath10kcal_extract "caldata" 20480 2116
102 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
103 ;;
104 gl-ar750s|\
105 gl-ar750|\
106 tl-wpa8630)
107 ath10kcal_extract "art" 20480 2116
108 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
109 ;;
110 koala)
111 ath10kcal_extract "art" 20480 2116
112 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_binary art 12) +0)
113 ;;
114 mc-mac1200r)
115 ath10kcal_extract "art" 20480 2116
116 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -1)
117 ;;
118 r6100)
119 ath10kcal_extract "caldata" 20480 2116
120 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) +2)
121 ;;
122 rb-952ui-5ac2nd|\
123 rb-wapg-5hact2hnd)
124 ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 20480 2116
125 ;;
126 re355|\
127 re450|\
128 tl-wr902ac-v1)
129 ath10kcal_extract "art" 20480 2116
130 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -2)
131 ;;
132 unifiac-lite|\
133 unifiac-pro)
134 ath10kcal_extract "EEPROM" 20480 2116
135 ;;
136 wi2a-ac200i)
137 ath10kcal_extract "ART" 20480 2116
138 ;;
139 esac
140 ;;
141 "ath10k/cal-pci-0000:01:00.0.bin")
142 case $board in
143 archer-c5|\
144 archer-c7)
145 ath10kcal_extract "art" 20480 2116
146 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
147 ;;
148 nbg6616|\
149 nbg6716)
150 ath10kcal_extract "RFdata" 20480 2116
151 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
152 ;;
153 om5p-ac)
154 ath10kcal_extract "ART" 20480 2116
155 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
156 ;;
157 rb-911g-5hpacd|\
158 rb-921gs-5hpacd-r2|\
159 rb-922uags-5hpacd|\
160 rb-962uigs-5hact2hnt)
161 ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 20480 2116
162 ;;
163 wlr8100)
164 ath10kcal_extract "art" 20480 2116
165 ath10kcal_patch_mac $(macaddr_add $(mtd_get_mac_ascii u-boot-env ethaddr) +1)
166 ;;
167 esac
168 ;;
169 "ath10k/pre-cal-pci-0000:00:00.0.bin")
170 case $board in
171 archer-c58-v1|\
172 archer-c59-v1|\
173 archer-c59-v2|\
174 archer-c60-v1|\
175 cf-e355ac-v2|\
176 cf-e375ac)
177 ath10kcal_extract "art" 20480 12064
178 ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
179 /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
180 ;;
181 archer-c60-v2)
182 ath10kcal_extract "art" 20480 12064
183 ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
184 /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
185 ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -1)
186 ;;
187 cf-e385ac)
188 ath10kcal_extract "art" 20480 12064
189 ;;
190 esac
191 ;;
192 *)
193 exit 1
194 ;;
195 esac