12-ath9k-eeprom 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #!/bin/sh
  2. # Based on ar71xx 10-ath9k-eeprom
  3. [ -e /lib/firmware/$FIRMWARE ] && exit 0
  4. . /lib/functions.sh
  5. . /lib/functions/system.sh
  6. . /lib/upgrade/nand.sh
  7. # xor multiple hex values of the same length
  8. xor() {
  9. local val
  10. local ret="0x$1"
  11. local retlen=${#1}
  12. shift
  13. while [ -n "$1" ]; do
  14. val="0x$1"
  15. ret=$((ret ^ val))
  16. shift
  17. done
  18. printf "%0${retlen}x" "$ret"
  19. }
  20. ath9k_eeprom_die() {
  21. echo "ath9k eeprom: $*"
  22. exit 1
  23. }
  24. ath9k_eeprom_extract_raw() {
  25. local source=$1
  26. local offset=$2
  27. local swap=$3
  28. local size=4096
  29. local bs=1
  30. local conv=
  31. if [ $swap -gt 0 ]; then
  32. bs=2
  33. conv="conv=swab"
  34. size=$((size / bs))
  35. offset=$((offset / bs))
  36. fi
  37. dd if=$source of=/lib/firmware/$FIRMWARE bs=$bs skip=$offset count=$size $conv 2>/dev/null || \
  38. ath9k_eeprom_die "failed to extract from $mtd"
  39. }
  40. ath9k_eeprom_extract() {
  41. local part=$1
  42. local offset=$2
  43. local swap=$3
  44. local mtd
  45. mtd=$(find_mtd_chardev $part)
  46. [ -n "$mtd" ] || \
  47. ath9k_eeprom_die "no mtd device found for partition $part"
  48. ath9k_eeprom_extract_raw $mtd $offset $swap
  49. }
  50. ath9k_ubi_eeprom_extract() {
  51. local part=$1
  52. local offset=$2
  53. local swap=$3
  54. local ubidev=$(nand_find_ubi $CI_UBIPART)
  55. local ubi
  56. ubi=$(nand_find_volume $ubidev $part)
  57. [ -n "$ubi" ] || \
  58. ath9k_eeprom_die "no UBI volume found for $part"
  59. ath9k_eeprom_extract_raw /dev/$ubi $offset $swap
  60. }
  61. ath9k_patch_fw_mac_crc() {
  62. local mac=$1
  63. local mac_offset=$2
  64. local chksum_offset=$((mac_offset - 10))
  65. ath9k_patch_fw_mac "${mac}" "${mac_offset}" "${chksum_offset}"
  66. }
  67. ath9k_patch_fw_mac() {
  68. local mac=$1
  69. local mac_offset=$2
  70. local chksum_offset=$3
  71. local xor_mac
  72. local xor_fw_mac
  73. local xor_fw_chksum
  74. [ -z "$mac" -o -z "$mac_offset" ] && return
  75. [ -n "$chksum_offset" ] && {
  76. xor_mac=${mac//:/}
  77. xor_mac="${xor_mac:0:4} ${xor_mac:4:4} ${xor_mac:8:4}"
  78. xor_fw_mac=$(hexdump -v -n 6 -s $mac_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
  79. xor_fw_mac="${xor_fw_mac:0:4} ${xor_fw_mac:4:4} ${xor_fw_mac:8:4}"
  80. xor_fw_chksum=$(hexdump -v -n 2 -s $chksum_offset -e '/1 "%02x"' /lib/firmware/$FIRMWARE)
  81. xor_fw_chksum=$(xor $xor_fw_chksum $xor_fw_mac $xor_mac)
  82. printf "%b" "\x${xor_fw_chksum:0:2}\x${xor_fw_chksum:2:2}" | \
  83. dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$chksum_offset count=2
  84. }
  85. macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=$mac_offset count=6
  86. }
  87. case "$FIRMWARE" in
  88. "ath9k-eeprom-pci-0000:00:0e.0.bin" | \
  89. "ath9k-eeprom-pci-0000:01:00.0.bin" | \
  90. "ath9k-eeprom-pci-0000:02:00.0.bin")
  91. board=$(board_name)
  92. case "$board" in
  93. ARV7518PW)
  94. ath9k_eeprom_extract "boardconfig" 1024 1
  95. ;;
  96. ARV8539PW22)
  97. ath9k_eeprom_extract "art" 1024 1
  98. ;;
  99. BTHOMEHUBV2B)
  100. ath9k_eeprom_extract "art" 0 1
  101. ath9k_patch_fw_mac_crc "00:00:00:00:00:00" 524
  102. ;;
  103. BTHOMEHUBV3A)
  104. ath9k_eeprom_extract "art-copy" 0 1
  105. ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_ascii uboot_env ethaddr) +2) 268
  106. ;;
  107. BTHOMEHUBV5A)
  108. ath9k_ubi_eeprom_extract "caldata" 4096 0
  109. ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_binary_ubi caldata 4364) +2) 268
  110. ;;
  111. DGN3500*)
  112. ath9k_eeprom_extract "calibration" 61440 0
  113. ath9k_patch_fw_mac_crc $(macaddr_add $(mtd_get_mac_ascii uboot-env ethaddr) +2) 524
  114. ;;
  115. FRITZ3370|FRITZ7320|FRITZ7360SL)
  116. ath9k_eeprom_extract "urlader" 2437 0
  117. ;;
  118. TDW8970|TDW8980)
  119. ath9k_eeprom_extract "boardconfig" 135168 0
  120. ;;
  121. *)
  122. ath9k_eeprom_die "board $board is not supported yet"
  123. ;;
  124. esac
  125. ;;
  126. esac