1
0

10-ath9k-eeprom 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/sh
  2. [ -e /lib/firmware/$FIRMWARE ] && exit 0
  3. . /lib/ar71xx.sh
  4. . /lib/functions.sh
  5. . /lib/functions/system.sh
  6. ath9k_eeprom_die() {
  7. echo "ath9k eeprom: " "$*"
  8. exit 1
  9. }
  10. ath9k_eeprom_extract() {
  11. local part=$1
  12. local offset=$2
  13. local count=$3
  14. local mtd
  15. mtd=$(find_mtd_chardev $part)
  16. [ -n "$mtd" ] || \
  17. ath9k_eeprom_die "no mtd device found for partition $part"
  18. dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
  19. ath9k_eeprom_die "failed to extract from $mtd"
  20. }
  21. ath9k_ubi_eeprom_extract() {
  22. local part=$1
  23. local offset=$2
  24. local count=$3
  25. local ubidev=$(nand_find_ubi $CI_UBIPART)
  26. local ubi
  27. ubi=$(nand_find_volume $ubidev $part)
  28. [ -n "$ubi" ] || \
  29. ath9k_eeprom_die "no UBI volume found for $part"
  30. dd if=/dev/$ubi of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
  31. ath9k_eeprom_die "failed to extract from $ubi"
  32. }
  33. ath9k_patch_firmware_mac() {
  34. local mac=$1
  35. [ -z "$mac" ] && return
  36. macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=2 count=6
  37. }
  38. board=$(ar71xx_board_name)
  39. case "$FIRMWARE" in
  40. "soc_wmac.eeprom")
  41. case $board in
  42. c-55|\
  43. c-60)
  44. ath9k_eeprom_extract "art" 4096 2048
  45. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +1)
  46. ;;
  47. mr18)
  48. . /lib/upgrade/nand.sh
  49. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  50. ath9k_ubi_eeprom_extract "caldata" 4096 2048
  51. else
  52. ath9k_eeprom_extract "odm-caldata" 4096 2048
  53. fi
  54. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +1)
  55. ;;
  56. r6100 | \
  57. wndr3700v4 | \
  58. wndr4300)
  59. ath9k_eeprom_extract "caldata" 4096 2048
  60. ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 0)
  61. ;;
  62. z1)
  63. . /lib/upgrade/nand.sh
  64. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  65. ath9k_ubi_eeprom_extract "caldata" 4096 2048
  66. else
  67. ath9k_eeprom_extract "origcaldata" 4096 2048
  68. fi
  69. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +2)
  70. ;;
  71. *)
  72. ath9k_eeprom_die "board $board is not supported yet"
  73. ;;
  74. esac
  75. ;;
  76. "pci_wmac0.eeprom")
  77. case $board in
  78. c-55)
  79. ath9k_eeprom_extract "art" 20480 2048
  80. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +2)
  81. ;;
  82. mr18)
  83. . /lib/upgrade/nand.sh
  84. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  85. ath9k_ubi_eeprom_extract "caldata" 20480 2048
  86. else
  87. ath9k_eeprom_extract "odm-caldata" 20480 2048
  88. fi
  89. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +2)
  90. ;;
  91. wndr3700v4 | \
  92. wndr4300)
  93. ath9k_eeprom_extract "caldata" 20480 2048
  94. ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 12)
  95. ;;
  96. z1)
  97. . /lib/upgrade/nand.sh
  98. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  99. ath9k_ubi_eeprom_extract "caldata" 86016 4096
  100. else
  101. ath9k_eeprom_extract "origcaldata" 86016 4096
  102. fi
  103. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +3)
  104. ;;
  105. *)
  106. ath9k_eeprom_die "board $board is not supported yet"
  107. ;;
  108. esac
  109. ;;
  110. "pci_wmac1.eeprom")
  111. case $board in
  112. mr18)
  113. . /lib/upgrade/nand.sh
  114. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  115. ath9k_ubi_eeprom_extract "caldata" 36864 2048
  116. else
  117. ath9k_eeprom_extract "odm-caldata" 36864 2048
  118. fi
  119. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +3)
  120. ;;
  121. *)
  122. ath9k_eeprom_die "board $board is not supported yet"
  123. ;;
  124. esac
  125. ;;
  126. esac