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 "%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_chksum
() {
127 local mac_offset
=$
(($2))
128 local chksum_offset
=$
(($3))
135 xor_mac
="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}"
137 xor_fw_mac
=$
(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib
/firmware
/$FIRMWARE)
138 xor_fw_mac
="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}"
140 xor_fw_chksum
=$
(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib
/firmware
/$FIRMWARE)
141 xor_fw_chksum
=$
(xor
$xor_fw_chksum $xor_fw_mac $xor_mac)
143 printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \
144 dd of
=$target conv
=notrunc bs
=1 seek
=$chksum_offset count
=2
147 caldata_patch_mac
() {
149 local mac_offset
=$
(($2))
150 local chksum_offset
=$3
153 [ -z "$mac" -o -z "$mac_offset" ] && return
155 [ -n "$target" ] || target
=/lib
/firmware
/$FIRMWARE
157 [ -n "$chksum_offset" ] && caldata_patch_chksum
"$mac" "$mac_offset" "$chksum_offset" "$target"
159 macaddr_2bin
$mac |
dd of
=$target conv
=notrunc oflag
=seek_bytes bs
=6 seek
=$mac_offset count
=1 || \
160 caldata_die
"failed to write MAC address to eeprom file"
167 caldata_patch_mac
"$mac" 0x2 "" "$target"
170 ath9k_patch_mac_crc
() {
173 local chksum_offset
=$
((mac_offset
- 10))
176 caldata_patch_mac
"$mac" "$mac_offset" "$chksum_offset" "$target"
183 caldata_patch_mac
"$mac" 0x6 0x2 "$target"