ar71xx: Do not use a hardcoded ath10k firmware mac address
[openwrt/openwrt.git] / target / linux / ar71xx / base-files / lib / preinit / 82_patch_ath10k
index c5c60efd5703005c4e3b0a0d04d194c55d46dc1c..b6af921449b0284d1e05212bbe618d77744e8a15 100644 (file)
@@ -3,27 +3,36 @@
 . /lib/functions/system.sh
 . /lib/ar71xx.sh
 
-firmware_file="/lib/firmware/ath10k/QCA988X/hw2.0/firmware-3.bin"
-firmware_md5_orig="5163aa8de591f80b06c77f22e9777473"
-firmware_md5_current="$(md5sum $firmware_file)"
-firmware_md5_current="${firmware_md5_current%% *}"
-
 
 do_patch_ath10k_firmware() {
-       # verify md5sum before patching
-       [ "firmware_md5_orig" != "firmware_md5_current" ] || {
+       local firmware_file="/lib/firmware/ath10k/QCA988X/hw2.0/firmware-5.bin"
+
+       # bail out if firmware does not exist
+       [ -f "$firmware_file" ] || {
+               return
+       }
+
+       local mac_offset=276
+       local mac_length=6
+       local default_mac="00:03:07:12:34:56"
+       local current_mac="$(hexdump -v -n $mac_length -s $mac_offset -e '5/1 "%02x:" 1/1 "%02x"' $firmware_file  2>/dev/null)"
+
+       # check if mac address was already patched
+       [ "$default_mac" = "$current_mac" ] || {
                return
        }
 
-       # some boards have bogus mac in otp, patch the default mac in the firmware
+       # some boards have bogus mac in otp (= directly in the PCIe card's EEPROM).
+       # we have to patch the default mac in the firmware because we cannot change
+       # the otp.
        case $(ar71xx_board_name) in
-               dgl-5500-a1)
+               dgl-5500-a1 | tew-823dru)
                        local mac
                        mac=$(mtd_get_mac_ascii nvram wlan1_mac)
 
                        cp $firmware_file /tmp/ath10k-firmware.bin
                        macaddr_2bin $mac | dd of=/tmp/ath10k-firmware.bin \
-                               conv=notrunc bs=1 seek=280 count=6
+                               conv=notrunc bs=1 seek=$mac_offset count=$mac_length
 
                ;;
        esac
@@ -34,4 +43,12 @@ do_patch_ath10k_firmware() {
        rm /tmp/ath10k-firmware.bin
 }
 
-boot_hook_add preinit_main do_patch_ath10k_firmware
+check_patch_ath10k_firmware() {
+       case $(ar71xx_board_name) in
+               dgl-5500-a1 | tew-823dru)
+                       do_patch_ath10k_firmware
+               ;;
+       esac
+}
+
+boot_hook_add preinit_main check_patch_ath10k_firmware