1 # Copyright (C) 2019 OpenWrt.org
4 .
/lib
/functions
/system.sh
12 dd if=$source of
=$target iflag
=skip_bytes
,fullblock bs
=$count skip
=$offset count
=1 2>/dev
/null
27 mtd
=$
(find_mtd_chardev
$part)
28 [ -n "$mtd" ] || caldata_die
"no mtd device found for partition $part"
30 caldata_dd
$mtd /lib
/firmware
/$FIRMWARE $count $offset || \
31 caldata_die
"failed to extract calibration data from $mtd"
34 caldata_extract_ubi
() {
41 .
/lib
/upgrade
/nand.sh
43 ubidev
=$
(nand_find_ubi
$CI_UBIPART)
44 ubi
=$
(nand_find_volume
$ubidev $part)
45 [ -n "$ubi" ] || caldata_die
"no UBI volume found for $part"
47 caldata_dd
/dev
/$ubi /lib
/firmware
/$FIRMWARE $count $offset || \
48 caldata_die
"failed to extract calibration data from $ubi"
51 caldata_extract_mmc
() {
57 mmc_part
=$
(find_mmc_part
$part)
58 [ -n "$mmc_part" ] || caldata_die
"no mmc partition found for partition $part"
60 caldata_dd
$mmc_part /lib
/firmware
/$FIRMWARE $count $offset || \
61 caldata_die
"failed to extract calibration data from $mmc_part"
64 caldata_extract_reverse
() {
72 mtd
=$
(find_mtd_chardev
"$part")
73 reversed
=$
(hexdump -v -s $offset -n $count -e '1/1 "%02x "' $mtd)
75 for byte
in $reversed; do
76 caldata
="\x${byte}${caldata}"
79 printf "%b" "$caldata" > /lib
/firmware
/$FIRMWARE
88 [ -n "$target" ] || target
=/lib
/firmware
/$FIRMWARE
90 caldata_dd
$source $target $count $offset || \
91 caldata_die
"failed to extract calibration data from $source"
94 caldata_sysfsload_from_file
() {
98 local target_dir
="/sys/$DEVPATH"
99 local target
="$target_dir/data"
101 [ -d "$target_dir" ] || \
102 caldata_die
"no sysfs dir to write: $target"
104 echo 1 > "$target_dir/loading"
105 caldata_dd
$source $target $count $offset
107 echo 1 > "$target_dir/loading"
108 caldata_die
"failed to extract calibration data from $source"
110 echo 0 > "$target_dir/loading"
118 [ -n "$target" ] || target
=/lib
/firmware
/$FIRMWARE
120 magic
=$
(hexdump -v -n 2 -e '1/1 "%02x"' $target)
121 [ "$magic" = "$expected" ]
125 caldata_patch_data
() {
127 local data_count
=$
((${#1} / 2))
128 local data_offset
=$
(($2))
129 local chksum_offset
=$
(($3))
134 [ -z "$data" -o -z "$data_offset" ] && return
136 [ -n "$target" ] || target
=/lib
/firmware
/$FIRMWARE
138 fw_data
=$
(hexdump -v -n $data_count -s $data_offset -e '1/1 "%02x"' $target)
140 if [ "$data" != "$fw_data" ]; then
142 if [ -n "$chksum_offset" ]; then
143 fw_chksum
=$
(hexdump -v -n 2 -s $chksum_offset -e '1/1 "%02x"' $target)
144 fw_chksum
=$
(xor
$fw_chksum $
(data_2xor_val
$fw_data) $
(data_2xor_val
$data))
146 data_2bin
$fw_chksum | \
147 dd of
=$target conv
=notrunc bs
=1 seek
=$chksum_offset count
=2 || \
148 caldata_die
"failed to write chksum to eeprom file"
152 dd of
=$target conv
=notrunc bs
=1 seek
=$data_offset count
=$data_count || \
153 caldata_die
"failed to write data to eeprom file"
161 caldata_patch_data
"${mac//:/}" 0x2 "" "$target"
164 ath9k_patch_mac_crc
() {
167 local chksum_offset
=$
((mac_offset
- 10))
170 caldata_patch_data
"${mac//:/}" "$mac_offset" "$chksum_offset" "$target"
177 caldata_patch_data
"${mac//:/}" 0x6 0x2 "$target"
186 [ -z "$mac_id" ] && return
188 caldata_patch_data
"${mac//:/}" $
(printf "0x%x" $
(($mac_id * 0x6 + 0xe))) 0xa "$target"
191 ath10k_remove_regdomain
() {
194 caldata_patch_data
"0000" 0xc 0x2 "$target"
197 ath11k_remove_regdomain
() {
202 regdomain
=$
(hexdump -v -n 2 -s 0x34 -e '1/1 "%02x"' $target)
203 caldata_patch_data
"0000" 0x34 0xa "$target"
205 for offset
in 0x450 0x458 0x500 0x5a8; do
206 regdomain_data
=$
(hexdump -v -n 2 -s $offset -e '1/1 "%02x"' $target)
208 if [ "$regdomain" == "$regdomain_data" ]; then
209 caldata_patch_data
"0000" $offset 0xa "$target"
214 ath11k_set_macflag
() {
217 caldata_patch_data
"0100" 0x3e 0xa "$target"