4da611a9f2dda969f796f2eece1ba4cd67760a8a
[openwrt/openwrt.git] / target / linux / ar71xx / base-files / lib / preinit / 82_patch_ath10k
1 #!/bin/sh
2
3 . /lib/functions/system.sh
4 . /lib/ar71xx.sh
5
6
7 do_patch_ath10k_firmware() {
8 local firmware_file="/lib/firmware/ath10k/QCA988X/hw2.0/firmware-5.bin"
9
10 # bail out if firmware does not exist
11 [ -f "$firmware_file" ] || {
12 return
13 }
14
15 local firmware_md5_orig="36768dc68572b3f2660211e20e89f558"
16 local firmware_md5_current="$(md5sum $firmware_file)"
17 local firmware_md5_current="${firmware_md5_current%% *}"
18
19 # verify md5sum before patching
20 [ "$firmware_md5_orig" != "$firmware_md5_current" ] || {
21 return
22 }
23
24 # some boards have bogus mac in otp, patch the default mac in the firmware
25 case $(ar71xx_board_name) in
26 dgl-5500-a1)
27 local mac
28 mac=$(mtd_get_mac_ascii nvram wlan1_mac)
29
30 cp $firmware_file /tmp/ath10k-firmware.bin
31 macaddr_2bin $mac | dd of=/tmp/ath10k-firmware.bin \
32 conv=notrunc bs=1 seek=276 count=6
33
34 ;;
35 esac
36 [ -f /tmp/ath10k-firmware.bin ] || {
37 return
38 }
39 cp /tmp/ath10k-firmware.bin $firmware_file
40 rm /tmp/ath10k-firmware.bin
41 }
42
43 check_patch_ath10k_firmware() {
44 case $(ar71xx_board_name) in
45 dgl-5500-a1)
46 do_patch_ath10k_firmware
47 ;;
48 esac
49 }
50
51 boot_hook_add preinit_main check_patch_ath10k_firmware