10-ath9k-eeprom 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 bs=1 skip=$offset count=$count 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 bs=1 skip=$offset count=$count 2>/dev/null || \
  30. ath9k_eeprom_die "failed to extract from $ubi"
  31. }
  32. ath9k_patch_firmware_mac() {
  33. local mac=$1
  34. [ -z "$mac" ] && return
  35. macaddr_2bin $mac | dd of=/lib/firmware/$FIRMWARE conv=notrunc bs=1 seek=2 count=6
  36. }
  37. board=$(board_name)
  38. case "$FIRMWARE" in
  39. "pci_wmac0.eeprom")
  40. case $board in
  41. wndr4700)
  42. . /lib/upgrade/nand.sh
  43. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  44. ath9k_ubi_eeprom_extract "caldata" 20480 4096
  45. else
  46. ath9k_eeprom_extract "wifi_data" 20480 4096
  47. ath9k_patch_firmware_mac $(mtd_get_mac_binary wifi_data 12)
  48. fi
  49. ;;
  50. *)
  51. ath9k_eeprom_die "board $board is not supported yet"
  52. ;;
  53. esac
  54. ;;
  55. "pci_wmac1.eeprom")
  56. case $board in
  57. wndr4700)
  58. . /lib/upgrade/nand.sh
  59. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  60. ath9k_ubi_eeprom_extract "caldata" 4096 4096
  61. else
  62. ath9k_eeprom_extract "wifi_data" 4096 4096
  63. ath9k_patch_firmware_mac $(mtd_get_mac_binary wifi_data 0)
  64. fi
  65. ;;
  66. *)
  67. ath9k_eeprom_die "board $board is not supported yet"
  68. ;;
  69. esac
  70. ;;
  71. esac