10-rt2x00-eeprom 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. rt2x00_eeprom_die() {
  3. echo "rt2x00 eeprom: " "$*"
  4. exit 1
  5. }
  6. rt2x00_eeprom_extract() {
  7. local part=$1
  8. local offset=$2
  9. local count=$3
  10. local mtd
  11. . /lib/functions.sh
  12. mtd=$(find_mtd_part $part)
  13. [ -n "$mtd" ] || \
  14. rt2x00_eeprom_die "no mtd device found for partition $part"
  15. dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
  16. rt2x00_eeprom_die "failed to extract from $mtd"
  17. }
  18. rt2x00_eeprom_set_macaddr() {
  19. local macaddr=$1
  20. [ -n "$macaddr" ] || \
  21. rt2x00_eeprom_die "invalid wlan mac address"
  22. macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \
  23. conv=notrunc bs=1 seek=4 count=6 2>/dev/null || \
  24. rt2x00_eeprom_die "failed to write mac address to eeprom file"
  25. }
  26. FW="/lib/firmware/$FIRMWARE"
  27. [ -e "$FW" ] && exit 0
  28. . /lib/ramips.sh
  29. . /lib/functions/system.sh
  30. board=$(ramips_board_name)
  31. case "$FIRMWARE" in
  32. "soc_wmac.eeprom")
  33. case $board in
  34. *)
  35. rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!"
  36. ;;
  37. esac
  38. ;;
  39. "rt2x00pci_1_0.eeprom")
  40. case $board in
  41. cy-swr1100)
  42. rt2x00_eeprom_extract "factory" 8192 512
  43. ;;
  44. br-6475nd | rt-n56u | whr-600d | whr-1166d)
  45. rt2x00_eeprom_extract "factory" 32768 512
  46. ;;
  47. tiny-ac)
  48. local wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR)
  49. rt2x00_eeprom_extract "factory" 0 512
  50. rt2x00_eeprom_set_macaddr $wifi_mac
  51. ;;
  52. esac
  53. ;;
  54. esac