82_patch_ath10k 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/bin/sh
  2. . /lib/functions/system.sh
  3. . /lib/ar71xx.sh
  4. do_patch_ath10k_firmware() {
  5. local firmware_file="/lib/firmware/ath10k/QCA988X/hw2.0/firmware-5.bin"
  6. # bail out if firmware does not exist
  7. [ -f "$firmware_file" ] || {
  8. return
  9. }
  10. local mac_offset=276
  11. local mac_length=6
  12. local default_mac="00:03:07:12:34:56"
  13. local current_mac="$(hexdump -v -n $mac_length -s $mac_offset -e '5/1 "%02x:" 1/1 "%02x"' $firmware_file 2>/dev/null)"
  14. # check if mac address was already patched
  15. [ "$default_mac" = "$current_mac" ] || {
  16. return
  17. }
  18. # some boards have bogus mac in otp (= directly in the PCIe card's EEPROM).
  19. # we have to patch the default mac in the firmware because we cannot change
  20. # the otp.
  21. case $(ar71xx_board_name) in
  22. dgl-5500-a1 | tew-823dru)
  23. local mac
  24. mac=$(mtd_get_mac_ascii nvram wlan1_mac)
  25. cp $firmware_file /tmp/ath10k-firmware.bin
  26. macaddr_2bin $mac | dd of=/tmp/ath10k-firmware.bin \
  27. conv=notrunc bs=1 seek=$mac_offset count=$mac_length
  28. ;;
  29. esac
  30. [ -f /tmp/ath10k-firmware.bin ] || {
  31. return
  32. }
  33. cp /tmp/ath10k-firmware.bin $firmware_file
  34. rm /tmp/ath10k-firmware.bin
  35. }
  36. check_patch_ath10k_firmware() {
  37. case $(ar71xx_board_name) in
  38. dgl-5500-a1 | tew-823dru)
  39. do_patch_ath10k_firmware
  40. ;;
  41. esac
  42. }
  43. boot_hook_add preinit_main check_patch_ath10k_firmware