1
0

10-ath9k-eeprom 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #!/bin/sh
  2. [ -e /lib/firmware/$FIRMWARE ] && exit 0
  3. . /lib/functions.sh
  4. . /lib/functions/system.sh
  5. ath9k_eeprom_die() {
  6. echo "ath9k eeprom: " "$*"
  7. exit 1
  8. }
  9. ath9k_eeprom_extract() {
  10. local part=$1
  11. local offset=$2
  12. local count=$3
  13. local mtd
  14. mtd=$(find_mtd_chardev $part)
  15. [ -n "$mtd" ] || \
  16. ath9k_eeprom_die "no mtd device found for partition $part"
  17. dd if=$mtd of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \
  18. ath9k_eeprom_die "failed to extract from $mtd"
  19. }
  20. ath9k_ubi_eeprom_extract() {
  21. local part=$1
  22. local offset=$2
  23. local count=$3
  24. local ubidev=$(nand_find_ubi $CI_UBIPART)
  25. local ubi
  26. ubi=$(nand_find_volume $ubidev $part)
  27. [ -n "$ubi" ] || \
  28. ath9k_eeprom_die "no UBI volume found for $part"
  29. dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE iflag=skip_bytes bs=$count skip=$offset count=1 2>/dev/null || \
  30. ath9k_eeprom_die "failed to extract from $ubi"
  31. }
  32. ath9k_eeprom_extract_reverse() {
  33. local part=$1
  34. local offset=$2
  35. local count=$3
  36. local mtd
  37. local reversed
  38. local caldata
  39. mtd=$(find_mtd_chardev "$part")
  40. reversed=$(hexdump -v -s $offset -n $count -e '/1 "%02x "' $mtd)
  41. for byte in $reversed; do
  42. caldata="\x${byte}${caldata}"
  43. done
  44. printf "%b" "$caldata" > /lib/firmware/$FIRMWARE
  45. }
  46. ath9k_patch_firmware_mac() {
  47. local mac=$1
  48. [ -z "$mac" ] && return
  49. macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc oflag=seek_bytes bs=6 seek=2 count=1
  50. }
  51. board=$(board_name)
  52. case "$FIRMWARE" in
  53. "soc_wmac.eeprom")
  54. case $board in
  55. c-55|\
  56. c-60)
  57. ath9k_eeprom_extract "art" 4096 2048
  58. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +1)
  59. ;;
  60. fritz4020|\
  61. fritz450e)
  62. ath9k_eeprom_extract_reverse "urlader" 5441 1088
  63. ;;
  64. mr18)
  65. . /lib/upgrade/nand.sh
  66. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  67. ath9k_ubi_eeprom_extract "caldata" 4096 2048
  68. else
  69. ath9k_eeprom_extract "odm-caldata" 4096 2048
  70. fi
  71. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +1)
  72. ;;
  73. r6100 | \
  74. wndr3700v4 | \
  75. wndr4300)
  76. ath9k_eeprom_extract "caldata" 4096 2048
  77. ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 0)
  78. ;;
  79. rambutan)
  80. ath9k_eeprom_extract "art" 4096 2048
  81. ;;
  82. wlr8100)
  83. ath9k_eeprom_extract "art" 4096 2048
  84. ath9k_patch_firmware_mac $(mtd_get_mac_ascii u-boot-env "ethaddr")
  85. ;;
  86. z1)
  87. . /lib/upgrade/nand.sh
  88. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  89. ath9k_ubi_eeprom_extract "caldata" 4096 2048
  90. else
  91. ath9k_eeprom_extract "origcaldata" 4096 2048
  92. fi
  93. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +2)
  94. ;;
  95. *)
  96. ath9k_eeprom_die "board $board is not supported yet"
  97. ;;
  98. esac
  99. ;;
  100. "pci_wmac0.eeprom")
  101. case $board in
  102. c-55)
  103. ath9k_eeprom_extract "art" 20480 2048
  104. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +2)
  105. ;;
  106. fritz300e)
  107. ath9k_eeprom_extract_reverse "urloader" 5441 1088
  108. ;;
  109. mr18)
  110. . /lib/upgrade/nand.sh
  111. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  112. ath9k_ubi_eeprom_extract "caldata" 20480 2048
  113. else
  114. ath9k_eeprom_extract "odm-caldata" 20480 2048
  115. fi
  116. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +2)
  117. ;;
  118. wndr3700v4 | \
  119. wndr4300)
  120. ath9k_eeprom_extract "caldata" 20480 2048
  121. ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 12)
  122. ;;
  123. z1)
  124. . /lib/upgrade/nand.sh
  125. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  126. ath9k_ubi_eeprom_extract "caldata" 86016 4096
  127. else
  128. ath9k_eeprom_extract "origcaldata" 86016 4096
  129. fi
  130. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +3)
  131. ;;
  132. *)
  133. ath9k_eeprom_die "board $board is not supported yet"
  134. ;;
  135. esac
  136. ;;
  137. "pci_wmac1.eeprom")
  138. case $board in
  139. mr18)
  140. . /lib/upgrade/nand.sh
  141. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  142. ath9k_ubi_eeprom_extract "caldata" 36864 2048
  143. else
  144. ath9k_eeprom_extract "odm-caldata" 36864 2048
  145. fi
  146. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +3)
  147. ;;
  148. *)
  149. ath9k_eeprom_die "board $board is not supported yet"
  150. ;;
  151. esac
  152. ;;
  153. esac