10-ath9k-eeprom 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/bin/sh
  2. [ -e /lib/firmware/$FIRMWARE ] && exit 0
  3. . /lib/apm821xx.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=$(apm821xx_board_name)
  39. case "$FIRMWARE" in
  40. "pci_wmac0.eeprom")
  41. case $board in
  42. wndr4700)
  43. . /lib/upgrade/nand.sh
  44. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  45. ath9k_ubi_eeprom_extract "caldata" 20480 4096
  46. else
  47. ath9k_eeprom_extract "wifi_data" 20480 4096
  48. ath9k_patch_firmware_mac $(mtd_get_mac_binary wifi_data 12)
  49. fi
  50. ;;
  51. *)
  52. ath9k_eeprom_die "board $board is not supported yet"
  53. ;;
  54. esac
  55. ;;
  56. "pci_wmac1.eeprom")
  57. case $board in
  58. wndr4700)
  59. . /lib/upgrade/nand.sh
  60. if [ -n "$(nand_find_volume ubi0 caldata)" ]; then
  61. ath9k_ubi_eeprom_extract "caldata" 4096 4096
  62. else
  63. ath9k_eeprom_extract "wifi_data" 4096 4096
  64. ath9k_patch_firmware_mac $(mtd_get_mac_binary wifi_data 0)
  65. fi
  66. ;;
  67. *)
  68. ath9k_eeprom_die "board $board is not supported yet"
  69. ;;
  70. esac
  71. ;;
  72. esac