10-rt2x00-eeprom 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. mtd=$(find_mtd_part $part)
  12. [ -n "$mtd" ] || \
  13. rt2x00_eeprom_die "no mtd device found for partition $part"
  14. dd if=$mtd of=/lib/firmware/$FIRMWARE bs=1 skip=$offset count=$count 2>/dev/null || \
  15. rt2x00_eeprom_die "failed to extract from $mtd"
  16. }
  17. jboot_eeprom_extract() {
  18. local part=$1
  19. local offset=$2
  20. local mtd
  21. mtd=$(find_mtd_part $part)
  22. [ -n "$mtd" ] || \
  23. rt2x00_eeprom_die "no mtd device found for partition $part"
  24. jboot_config_read -i $mtd -o $offset -e /lib/firmware/$FIRMWARE 2>/dev/null || \
  25. rt2x00_eeprom_die "failed to extract from $mtd"
  26. }
  27. rt2x00_eeprom_set_macaddr() {
  28. local macaddr=$1
  29. [ -n "$macaddr" ] || \
  30. rt2x00_eeprom_die "invalid wlan mac address"
  31. macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \
  32. conv=notrunc bs=1 seek=4 count=6 2>/dev/null || \
  33. rt2x00_eeprom_die "failed to write mac address to eeprom file"
  34. }
  35. FW="/lib/firmware/$FIRMWARE"
  36. [ -e "$FW" ] && exit 0
  37. . /lib/functions.sh
  38. . /lib/functions/system.sh
  39. board=$(board_name)
  40. case "$FIRMWARE" in
  41. "soc_wmac.eeprom")
  42. case $board in
  43. dlink,dwr-116-a1|\
  44. dlink,dwr-118-a1|\
  45. dlink,dwr-118-a2|\
  46. dlink,dwr-921-c1|\
  47. dlink,dwr-922-e2|\
  48. lava,lr-25g001)
  49. wan_mac=$(jboot_config_read -m -i $(find_mtd_part "config") -o 0xE000)
  50. wifi_mac=$(macaddr_add "$wan_mac" 1)
  51. jboot_eeprom_extract "config" 0xE000
  52. rt2x00_eeprom_set_macaddr $wifi_mac
  53. ;;
  54. tiny-ac)
  55. wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR)
  56. rt2x00_eeprom_extract "factory" 0 512
  57. rt2x00_eeprom_set_macaddr $wifi_mac
  58. ;;
  59. *)
  60. rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!"
  61. ;;
  62. esac
  63. ;;
  64. esac