11-ath10k-caldata 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/bin/sh
  2. ath10kcal_die() {
  3. echo "ath10cal: " "$*"
  4. exit 1
  5. }
  6. ath10kcal_from_file() {
  7. local source=$1
  8. local offset=$2
  9. local count=$3
  10. dd if=$source of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
  11. ath10kcal_die "failed to extract calibration data from $source"
  12. }
  13. ath10kcal_extract() {
  14. local part=$1
  15. local offset=$2
  16. local count=$3
  17. local mtd cal_size
  18. mtd=$(find_mtd_chardev $part)
  19. [ -n "$mtd" ] || \
  20. ath10kcal_die "no mtd device found for partition $part"
  21. # Check that the calibration data size in header equals the desired size
  22. cal_size=$(dd if=$mtd bs=2 count=1 skip=$(( $offset / 2 )) conv=swab 2>/dev/null | hexdump -ve '1/2 "%d"')
  23. [ "$count" = "$cal_size" ] || \
  24. ath10kcal_die "no calibration data found in $part"
  25. dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
  26. ath10kcal_die "failed to extract calibration data from $mtd"
  27. }
  28. ath10kcal_patch_mac() {
  29. local mac=$1
  30. [ -z "$mac" ] && return
  31. macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=6 count=6
  32. }
  33. [ -e /lib/firmware/$FIRMWARE ] && exit 0
  34. . /lib/ar71xx.sh
  35. . /lib/functions.sh
  36. . /lib/functions/system.sh
  37. board=$(ar71xx_board_name)
  38. case "$FIRMWARE" in
  39. "ath10k/cal-pci-0000:00:00.0.bin")
  40. case $board in
  41. cf-e380ac-v1|\
  42. cf-e380ac-v2|\
  43. dlan-pro-1200-ac|\
  44. sr3200|\
  45. xd3200)
  46. ath10kcal_extract "art" 20480 2116
  47. ;;
  48. dap-2695-a1)
  49. ath10kcal_extract "radiocfg" 20480 2116
  50. ath10kcal_patch_mac $(mtd_get_mac_ascii bdcfg wlanmac_a)
  51. ;;
  52. dir-869-a1 | \
  53. qihoo-c301)
  54. ath10kcal_extract "radiocfg" 20480 2116
  55. ath10kcal_patch_mac $(mtd_get_mac_ascii devdata wlan5mac)
  56. ;;
  57. dw33d)
  58. ath10kcal_extract "art" 20480 2116
  59. ath10kcal_patch_mac $(mtd_get_mac_binary art 18)
  60. ;;
  61. epg5000 | \
  62. esr1750)
  63. ath10kcal_extract "caldata" 20480 2116
  64. ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
  65. ;;
  66. mc-mac1200r)
  67. ath10kcal_extract "art" 20480 2116
  68. ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -1)
  69. ;;
  70. a40 | \
  71. a60 | \
  72. mr1750 | \
  73. mr1750v2 | \
  74. om5p-acv2)
  75. ath10kcal_extract "ART" 20480 2116
  76. ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
  77. ;;
  78. r6100)
  79. ath10kcal_extract "caldata" 20480 2116
  80. ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) +2)
  81. ;;
  82. re450)
  83. ath10kcal_extract "art" 20480 2116
  84. ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) -2)
  85. ;;
  86. tl-wdr6500-v2)
  87. ath10kcal_extract "art" 20480 2116
  88. ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
  89. ;;
  90. tl-wpa8630)
  91. ath10kcal_extract "art" 20480 2116
  92. ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +1)
  93. ;;
  94. unifiac-lite | \
  95. unifiac-pro)
  96. ath10kcal_extract "EEPROM" 20480 2116
  97. ;;
  98. esac
  99. ;;
  100. "ath10k/cal-pci-0000:01:00.0.bin")
  101. case $board in
  102. archer-c5 | \
  103. archer-c7)
  104. ath10kcal_extract "art" 20480 2116
  105. ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
  106. ;;
  107. nbg6616 | \
  108. nbg6716)
  109. ath10kcal_extract "RFdata" 20480 2116
  110. ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth1/address) -2)
  111. ;;
  112. om5p-ac)
  113. ath10kcal_extract "ART" 20480 2116
  114. ath10kcal_patch_mac $(macaddr_add $(cat /sys/class/net/eth0/address) +16)
  115. ;;
  116. rb-911g-5hpacd)
  117. ath10kcal_from_file "/sys/firmware/routerboot/ext_wlan_data" 20480 2116
  118. ;;
  119. esac
  120. ;;
  121. *)
  122. exit 1
  123. ;;
  124. esac