10-ath9k-eeprom 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. ath9k_eeprom_extract "art" 4096 2048
  44. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +1)
  45. ;;
  46. mr18)
  47. . /lib/upgrade/nand.sh
  48. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  49. ath9k_ubi_eeprom_extract "caldata" 4096 2048
  50. else
  51. ath9k_eeprom_extract "odm-caldata" 4096 2048
  52. fi
  53. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +1)
  54. ;;
  55. r6100 | \
  56. wndr3700v4 | \
  57. wndr4300)
  58. ath9k_eeprom_extract "caldata" 4096 2048
  59. ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 0)
  60. ;;
  61. *)
  62. ath9k_eeprom_die "board $board is not supported yet"
  63. ;;
  64. esac
  65. ;;
  66. "pci_wmac0.eeprom")
  67. case $board in
  68. c-55)
  69. ath9k_eeprom_extract "art" 20480 2048
  70. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary art 0) +2)
  71. ;;
  72. mr18)
  73. . /lib/upgrade/nand.sh
  74. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  75. ath9k_ubi_eeprom_extract "caldata" 20480 2048
  76. else
  77. ath9k_eeprom_extract "odm-caldata" 20480 2048
  78. fi
  79. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +2)
  80. ;;
  81. wndr3700v4 | \
  82. wndr4300)
  83. ath9k_eeprom_extract "caldata" 20480 2048
  84. ath9k_patch_firmware_mac $(mtd_get_mac_binary caldata 12)
  85. ;;
  86. *)
  87. ath9k_eeprom_die "board $board is not supported yet"
  88. ;;
  89. esac
  90. ;;
  91. "pci_wmac1.eeprom")
  92. case $board in
  93. mr18)
  94. . /lib/upgrade/nand.sh
  95. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  96. ath9k_ubi_eeprom_extract "caldata" 36864 2048
  97. else
  98. ath9k_eeprom_extract "odm-caldata" 36864 2048
  99. fi
  100. ath9k_patch_firmware_mac $(macaddr_add $(mtd_get_mac_binary_ubi board-config 102) +3)
  101. ;;
  102. *)
  103. ath9k_eeprom_die "board $board is not supported yet"
  104. ;;
  105. esac
  106. ;;
  107. esac