11-ath10k-caldata 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #!/bin/sh
  2. # xor multiple hex values of the same length
  3. xor() {
  4. local val
  5. local ret="0x$1"
  6. local retlen=${#1}
  7. shift
  8. while [ -n "$1" ]; do
  9. val="0x$1"
  10. ret=$((ret ^ val))
  11. shift
  12. done
  13. printf "%0${retlen}x" "$ret"
  14. }
  15. ath10kcal_die() {
  16. echo "ath10cal: " "$*"
  17. exit 1
  18. }
  19. ath10kcal_extract() {
  20. local part=$1
  21. local offset=$2
  22. local count=$3
  23. local mtd
  24. mtd=$(find_mtd_chardev $part)
  25. [ -n "$mtd" ] || \
  26. ath10kcal_die "no mtd device found for partition $part"
  27. dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
  28. ath10kcal_die "failed to extract calibration data from $mtd"
  29. }
  30. ath10kcal_ubi_extract() {
  31. local part=$1
  32. local offset=$2
  33. local count=$3
  34. local ubidev
  35. local ubi
  36. . /lib/upgrade/nand.sh
  37. ubidev=$(nand_find_ubi $CI_UBIPART)
  38. ubi=$(nand_find_volume $ubidev $part)
  39. [ -n "$ubi" ] || \
  40. ath10kcal_die "no UBI volume found for $part"
  41. dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
  42. ath10kcal_die "failed to extract from $ubi"
  43. }
  44. ath10kcal_patch_mac_crc() {
  45. local mac=$1
  46. local mac_offset=6
  47. local chksum_offset=2
  48. local xor_mac
  49. local xor_fw_mac
  50. local xor_fw_chksum
  51. [ -z "$mac" ] && return
  52. xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
  53. xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}"
  54. macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6
  55. xor_mac=${mac//:/}
  56. xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}"
  57. xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
  58. xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac)
  59. printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \
  60. dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2
  61. }
  62. ath10kcal_is_caldata_valid() {
  63. local expected="$1"
  64. magic=$(hexdump -v -n 2 -e '1/1 "%02x"' /lib/firmware/$FIRMWARE)
  65. [[ "$magic" == "$expected" ]]
  66. return $?
  67. }
  68. [ -e /lib/firmware/$FIRMWARE ] && exit 0
  69. . /lib/functions.sh
  70. . /lib/functions/system.sh
  71. board=$(board_name)
  72. case "$FIRMWARE" in
  73. "ath10k/cal-pci-0000:01:00.0.bin")
  74. case "$board" in
  75. meraki,mr33)
  76. ath10kcal_ubi_extract "ART" 36864 2116
  77. ath10kcal_is_caldata_valid "4408" || ath10kcal_extract "ART" 36864 2116
  78. ath10kcal_patch_mac_crc $(macaddr_add $(get_mac_binary "/sys/bus/i2c/devices/0-0050/eeprom" 102) +1)
  79. ;;
  80. esac
  81. ;;
  82. "ath10k/pre-cal-pci-0000:01:00.0.bin")
  83. case "$board" in
  84. asus,map-ac2200)
  85. ath10kcal_ubi_extract "Factory" 36864 12064
  86. ln -sf /lib/firmware/ath10k/pre-cal-pci-0000\:00\:00.0.bin \
  87. /lib/firmware/ath10k/QCA9888/hw2.0/board.bin
  88. ;;
  89. openmesh,a62)
  90. ath10kcal_extract "0:ART" 36864 12064
  91. ;;
  92. esac
  93. ;;
  94. "ath10k/pre-cal-ahb-a000000.wifi.bin")
  95. case "$board" in
  96. 8dev,jalapeno |\
  97. glinet,gl-b1300 |\
  98. linksys,ea6350v3 |\
  99. qcom,ap-dk01.1-c1)
  100. ath10kcal_extract "ART" 4096 12064
  101. ;;
  102. asus,map-ac2200)
  103. ath10kcal_ubi_extract "Factory" 4096 12064
  104. ;;
  105. asus,rt-ac58u)
  106. CI_UBIPART=UBI_DEV
  107. ath10kcal_ubi_extract "Factory" 4096 12064
  108. ;;
  109. avm,fritzbox-4040)
  110. /usr/bin/fritz_cal_extract -i 1 -s 0x400 -e 0x207 -l 12064 -o /lib/firmware/$FIRMWARE $(find_mtd_chardev "urlader_config")
  111. ;;
  112. meraki,mr33)
  113. ath10kcal_ubi_extract "ART" 4096 12064
  114. ath10kcal_is_caldata_valid "202f" || ath10kcal_extract "ART" 4096 12064
  115. ath10kcal_patch_mac_crc $(macaddr_add $(get_mac_binary "/sys/bus/i2c/devices/0-0050/eeprom" 102) +2)
  116. ;;
  117. netgear,ex6100v2 |\
  118. netgear,ex6150v2)
  119. ath10kcal_extract "ART" 4096 12064
  120. ath10kcal_patch_mac_crc $(mtd_get_mac_binary dnidata 0)
  121. ;;
  122. compex,wpj428 |\
  123. engenius,eap1300 |\
  124. openmesh,a42 |\
  125. openmesh,a62)
  126. ath10kcal_extract "0:ART" 4096 12064
  127. ;;
  128. zyxel,nbg6617 |\
  129. zyxel,wre6606)
  130. ath10kcal_extract "ART" 4096 12064
  131. ath10kcal_patch_mac_crc $(macaddr_add $(cat /sys/class/net/eth0/address) -2)
  132. ;;
  133. esac
  134. ;;
  135. "ath10k/pre-cal-ahb-a800000.wifi.bin")
  136. case "$board" in
  137. 8dev,jalapeno |\
  138. glinet,gl-b1300 |\
  139. linksys,ea6350v3 |\
  140. qcom,ap-dk01.1-c1)
  141. ath10kcal_extract "ART" 20480 12064
  142. ;;
  143. asus,map-ac2200)
  144. ath10kcal_ubi_extract "Factory" 20480 12064
  145. ;;
  146. asus,rt-ac58u)
  147. CI_UBIPART=UBI_DEV
  148. ath10kcal_ubi_extract "Factory" 20480 12064
  149. ;;
  150. avm,fritzbox-4040)
  151. /usr/bin/fritz_cal_extract -i 1 -s 0x400 -e 0x208 -l 12064 -o /lib/firmware/$FIRMWARE $(find_mtd_chardev "urlader_config")
  152. ;;
  153. meraki,mr33)
  154. ath10kcal_ubi_extract "ART" 20480 12064
  155. ath10kcal_is_caldata_valid "202f" || ath10kcal_extract "ART" 20480 12064
  156. ath10kcal_patch_mac_crc $(macaddr_add $(get_mac_binary "/sys/bus/i2c/devices/0-0050/eeprom" 102) +3)
  157. ;;
  158. netgear,ex6100v2 |\
  159. netgear,ex6150v2)
  160. ath10kcal_extract "ART" 20480 12064
  161. ath10kcal_patch_mac_crc $(mtd_get_mac_binary dnidata 12)
  162. ;;
  163. compex,wpj428 |\
  164. engenius,eap1300 |\
  165. openmesh,a42 |\
  166. openmesh,a62)
  167. ath10kcal_extract "0:ART" 20480 12064
  168. ;;
  169. zyxel,nbg6617 |\
  170. zyxel,wre6606)
  171. ath10kcal_extract "ART" 20480 12064
  172. ath10kcal_patch_mac_crc $(macaddr_add $(cat /sys/class/net/eth0/address) -1)
  173. ;;
  174. esac
  175. ;;
  176. *)
  177. exit 1
  178. ;;
  179. esac