summaryrefslogtreecommitdiff
path: root/target/linux/ar71xx/base-files/lib/preinit/82_patch_ath10k
blob: 4511162ac4a5c68e12ea52f0f82efa009ac85212 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/sh

. /lib/functions/system.sh
. /lib/ar71xx.sh


do_patch_ath10k_firmware() {
	local firmware_file="/lib/firmware/ath10k/QCA988X/hw2.0/firmware-4.bin"

	# bail out if firmware does not exist
	[ -f "$firmware_file" ] || {
		return
	}

	local firmware_md5_orig="ab36ef267d15cfc02317ceeb38e8f548"
	local firmware_md5_current="$(md5sum $firmware_file)"
	local firmware_md5_current="${firmware_md5_current%% *}"

	# verify md5sum before patching
	[ "$firmware_md5_orig" != "$firmware_md5_current" ] || {
		return
	}

	# some boards have bogus mac in otp, patch the default mac in the firmware
	case $(ar71xx_board_name) in
		dgl-5500-a1)
			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=276 count=6

		;;
	esac
	[ -f /tmp/ath10k-firmware.bin ] || {
		return
	}
	cp /tmp/ath10k-firmware.bin $firmware_file
	rm /tmp/ath10k-firmware.bin
}

check_patch_ath10k_firmware() {
	case $(ar71xx_board_name) in
		dgl-5500-a1)
			do_patch_ath10k_firmware
		;;
	esac
}

boot_hook_add preinit_main check_patch_ath10k_firmware