bc64d5b8ab00ef18c6f4531fe7fbd3ad9f89af7c
[openwrt/openwrt.git] / target / linux / ipq40xx / 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_extract() {
9 local part=$1
10 local offset=$2
11 local count=$3
12 local mtd
13
14 mtd=$(find_mtd_chardev $part)
15 [ -n "$mtd" ] || \
16 ath10kcal_die "no mtd device found for partition $part"
17
18 dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
19 ath10kcal_die "failed to extract calibration data from $mtd"
20 }
21
22 ath10kcal_ubi_extract() {
23 local part=$1
24 local offset=$2
25 local count=$3
26 local ubidev
27 local ubi
28
29 . /lib/upgrade/nand.sh
30
31 ubidev=$(nand_find_ubi $CI_UBIPART)
32 ubi=$(nand_find_volume $ubidev $part)
33 [ -n "$ubi" ] || \
34 ath10kcal_die "no UBI volume found for $part"
35
36 dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
37 ath10kcal_die "failed to extract from $ubi"
38 }
39
40 [ -e /lib/firmware/$FIRMWARE ] && exit 0
41
42 . /lib/functions.sh
43 . /lib/functions/system.sh
44
45 board=$(board_name)
46
47
48 case "$FIRMWARE" in
49 "ath10k/pre-cal-ahb-a000000.wifi.bin")
50 case "$board" in
51 asus,rt-ac58u)
52 CI_UBIPART=UBI_DEV
53 ath10kcal_ubi_extract "Factory" 4096 12064
54 ;;
55 avm,fritzbox-4040)
56 /usr/bin/fritz_cal_extract -i 1 -s 0x400 -e 0x207 -l 12064 -o /lib/firmware/$FIRMWARE $(find_mtd_chardev "urlader_config")
57 ;;
58 glinet,gl-b1300 |\
59 qcom,ap-dk01.1-c1)
60 ath10kcal_extract "ART" 4096 12064
61 ;;
62 openmesh,a42)
63 ath10kcal_extract "0:ART" 4096 12064
64 ;;
65 esac
66 ;;
67 "ath10k/pre-cal-ahb-a800000.wifi.bin")
68 case "$board" in
69 asus,rt-ac58u)
70 CI_UBIPART=UBI_DEV
71 ath10kcal_ubi_extract "Factory" 20480 12064
72 ;;
73 avm,fritzbox-4040)
74 /usr/bin/fritz_cal_extract -i 1 -s 0x400 -e 0x208 -l 12064 -o /lib/firmware/$FIRMWARE $(find_mtd_chardev "urlader_config")
75 ;;
76 glinet,gl-b1300 |\
77 qcom,ap-dk01.1-c1)
78 ath10kcal_extract "ART" 20480 12064
79 ;;
80 openmesh,a42)
81 ath10kcal_extract "0:ART" 20480 12064
82 ;;
83 esac
84 ;;
85 *)
86 exit 1
87 ;;
88 esac