Fresh pull from upstream
[librecmc/librecmc.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 mac_offset=276
16         local mac_length=6
17         local default_mac="00:03:07:12:34:56"
18         local current_mac="$(hexdump -v -n $mac_length -s $mac_offset -e '5/1 "%02x:" 1/1 "%02x"' $firmware_file  2>/dev/null)"
19
20         # check if mac address was already patched
21         [ "$default_mac" = "$current_mac" ] || {
22                 return
23         }
24
25         # some boards have bogus mac in otp (= directly in the PCIe card's EEPROM).
26         # we have to patch the default mac in the firmware because we cannot change
27         # the otp.
28         case $(ar71xx_board_name) in
29                 dgl-5500-a1 | tew-823dru)
30                         local mac
31                         mac=$(mtd_get_mac_ascii nvram wlan1_mac)
32
33                         cp $firmware_file /tmp/ath10k-firmware.bin
34                         macaddr_2bin $mac | dd of=/tmp/ath10k-firmware.bin \
35                                 conv=notrunc bs=1 seek=$mac_offset count=$mac_length
36
37                 ;;
38         esac
39         [ -f /tmp/ath10k-firmware.bin ] || {
40                 return
41         }
42         cp /tmp/ath10k-firmware.bin $firmware_file
43         rm /tmp/ath10k-firmware.bin
44 }
45
46 check_patch_ath10k_firmware() {
47         case $(ar71xx_board_name) in
48                 dgl-5500-a1 | tew-823dru)
49                         do_patch_ath10k_firmware
50                 ;;
51         esac
52 }
53
54 boot_hook_add preinit_main check_patch_ath10k_firmware