10-rt2x00-eeprom 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. tiny-ac)
  35. wifi_mac=$(mtd_get_mac_ascii u-boot-env INIC_MAC_ADDR)
  36. rt2x00_eeprom_extract "factory" 0 512
  37. rt2x00_eeprom_set_macaddr $wifi_mac
  38. ;;
  39. *)
  40. rt2x00_eeprom_die "Please define mtd-eeprom in $board DTS file!"
  41. ;;
  42. esac
  43. ;;
  44. esac