10-rt2x00-eeprom 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. rt2x00_eeprom_set_macaddr() {
  18. local macaddr=$1
  19. [ -n "$macaddr" ] || \
  20. rt2x00_eeprom_die "invalid wlan mac address"
  21. macaddr_2bin $macaddr | dd of=/lib/firmware/$FIRMWARE \
  22. conv=notrunc bs=1 seek=4 count=6 2>/dev/null || \
  23. rt2x00_eeprom_die "failed to write mac address to eeprom file"
  24. }
  25. FW="/lib/firmware/$FIRMWARE"
  26. [ -e "$FW" ] && exit 0
  27. . /lib/functions.sh
  28. . /lib/functions/system.sh
  29. board=$(board_name)
  30. case "$FIRMWARE" in
  31. "soc_wmac.eeprom")
  32. case $board in
  33. tiny-ac)
  34. wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR)
  35. rt2x00_eeprom_extract "factory" 0 512
  36. rt2x00_eeprom_set_macaddr $wifi_mac
  37. ;;
  38. *)
  39. rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!"
  40. ;;
  41. esac
  42. ;;
  43. esac