1 # Copyright (C) 2019 OpenWrt.org
4 .
/lib
/functions
/system.sh
17 mtd
=$
(find_mtd_chardev
$part)
18 [ -n "$mtd" ] || caldata_die
"no mtd device found for partition $part"
20 dd if=$mtd of
=/lib
/firmware
/$FIRMWARE iflag
=skip_bytes bs
=$count skip
=$offset count
=1 2>/dev
/null || \
21 caldata_die
"failed to extract calibration data from $mtd"
24 caldata_extract_ubi
() {
31 .
/lib
/upgrade
/nand.sh
33 ubidev
=$
(nand_find_ubi
$CI_UBIPART)
34 ubi
=$
(nand_find_volume
$ubidev $part)
35 [ -n "$ubi" ] || caldata_die
"no UBI volume found for $part"
37 dd if=/dev
/$ubi of
=/lib
/firmware
/$FIRMWARE iflag
=skip_bytes bs
=$count skip
=$offset count
=1 2>/dev
/null || \
38 caldata_die
"failed to extract calibration data from $ubi"
41 caldata_extract_reverse
() {
49 mtd
=$
(find_mtd_chardev
"$part")
50 reversed
=$
(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
52 for byte
in $reversed; do
53 caldata
="\x${byte}${caldata}"
56 printf "%b" "$caldata" > /lib
/firmware
/$FIRMWARE
65 [ -n "$target" ] || target
=/lib
/firmware
/$FIRMWARE
67 dd if=$source of
=$target iflag
=skip_bytes bs
=$count skip
=$offset count
=1 2>/dev
/null || \
68 caldata_die
"failed to extract calibration data from $source"
75 [ -n "$target" ] || target
=/lib
/firmware
/$FIRMWARE
77 magic
=$
(hexdump -v -n 2 -e '1/1 "%02x"' $target)
78 [ "$magic" = "$expected" ]
82 caldata_patch_chksum
() {
84 local mac_offset
=$
(($2))
85 local chksum_offset
=$
(($3))
92 xor_mac
="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}"
94 xor_fw_mac
=$
(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib
/firmware
/$FIRMWARE)
95 xor_fw_mac
="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}"
97 xor_fw_chksum
=$
(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib
/firmware
/$FIRMWARE)
98 xor_fw_chksum
=$
(xor
$xor_fw_chksum $xor_fw_mac $xor_mac)
100 printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \
101 dd of
=$target conv
=notrunc bs
=1 seek
=$chksum_offset count
=2
104 caldata_patch_mac
() {
106 local mac_offset
=$
(($2))
107 local chksum_offset
=$3
110 [ -z "$mac" -o -z "$mac_offset" ] && return
112 [ -n "$target" ] || target
=/lib
/firmware
/$FIRMWARE
114 [ -n "$chksum_offset" ] && caldata_patch_chksum
"$mac" "$mac_offset" "$chksum_offset" "$target"
116 macaddr_2bin
$mac |
dd of
=$target conv
=notrunc oflag
=seek_bytes bs
=6 seek
=$mac_offset count
=1 || \
117 caldata_die
"failed to write MAC address to eeprom file"
124 caldata_patch_mac
"$mac" 0x2 "" "$target"
127 ath9k_patch_mac_crc
() {
130 local chksum_offset
=$
((mac_offset
- 10))
133 caldata_patch_mac
"$mac" "$mac_offset" "$chksum_offset" "$target"
140 caldata_patch_mac
"$mac" 0x6 0x2 "$target"