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