ipq40xx: dynamically build board-2.bin for Mikrotik
authorChristian Lamparter <chunkeey@gmail.com>
Sun, 6 Feb 2022 00:42:01 +0000 (01:42 +0100)
committerChristian Lamparter <chunkeey@gmail.com>
Thu, 19 May 2022 14:39:11 +0000 (16:39 +0200)
Mikrotik devices ship with the boardfile data right on the board itself.
This script takes the data from the sysfs firmware "wlan_data" to
generate a custom board-2.bin for the ath10k driver to work with.

The qcom,ath10k-calibration-variant in each device's device-tree file
are being removed as well.

Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
target/linux/ipq40xx/base-files/etc/hotplug.d/firmware/11-ath10k-caldata
target/linux/ipq40xx/files/arch/arm/boot/dts/qcom-ipq4018-cap-ac.dts
target/linux/ipq40xx/files/arch/arm/boot/dts/qcom-ipq4018-hap-ac2.dts
target/linux/ipq40xx/files/arch/arm/boot/dts/qcom-ipq4018-sxtsq-5-ac.dts
target/linux/ipq40xx/files/arch/arm/boot/dts/qcom-ipq4019-hap-ac3.dts

index e0b4eed6f2b94481007de0a2d7e7fc090e51e0a6..0182823bc23cfd81aebef1812ceeff230c2d57df 100644 (file)
@@ -6,6 +6,46 @@
 
 board=$(board_name)
 
+board2_add_entry()
+{
+       local file="$1"
+       local offset="$(($2))"
+       local size="$(($3))"
+
+       local id=$(dd iflag=skip_bytes if="$file" bs=1 count=1 skip=$((offset+32)) | hexdump -e '1/1 "%02d"')
+
+       # Qualcomm IDs are in the range of 16 to 30 it seems - taken from the board-2.bin
+       # This is there to skip the missing 2G on the SXTSQ 5 AC
+       [ "$id" -ge 16 -a "$id" -le 30 ] || return 0
+
+       printf "\x00\x00\x00\x00\x58\x2f\x00\x00\x00\x00\x00\x00\x25\x00\x00\x00"
+       printf "bus=ahb,bmi-chip-id=0,bmi-board-id=${id}\x00\x00\x00"
+       printf "\x01\x00\x00\x00\x20\x2f\x00\x00"
+
+       dd iflag=skip_bytes,fullblock if="$file" bs="$size" count=1 skip="$offset" >> "/lib/firmware/$FIRMWARE"
+}
+
+board2_create_for_mikrotik()
+{
+       wlan_data="/sys/firmware/mikrotik/hard_config/wlan_data"
+
+       [ -f "$wlan_data" ] && {
+               (
+                       printf "QCA-ATH10K-BOARD\x00\x00\x00\x00"
+                       board2_add_entry "$wlan_data" 0x2f20 0x2f20
+                       board2_add_entry "$wlan_data" 0xaf20 0x2f20
+               ) >> "/lib/firmware/$FIRMWARE"
+       } || true
+
+       [ -d "$wlan_data" ] && {
+               (
+                       printf "QCA-ATH10K-BOARD\x00\x00\x00\x00"
+                       board2_add_entry "$wlan_data/data_0" 0x2f20 0x2f20
+                       board2_add_entry "$wlan_data/data_2" 0x2f20 0x2f20
+               ) >> "/lib/firmware/$FIRMWARE"
+       } || true
+}
+
 case "$FIRMWARE" in
 "ath10k/cal-pci-0000:01:00.0.bin")
        case "$board" in
@@ -238,6 +278,16 @@ case "$FIRMWARE" in
                ;;
        esac
        ;;
+"ath10k/QCA4019/hw1.0/board-2.bin")
+case "$board" in
+       mikrotik,cap-ac |\
+       mikrotik,hap-ac2 |\
+       mikrotik,hap-ac3 |\
+       mikrotik,sxtsq-5-ac)
+               board2_create_for_mikrotik
+               ;;
+       esac
+       ;;
 *)
        exit 1
        ;;
index 1afbf97f393be42dc3ae8562d216c94cd1e9babb..3ebcb3ba5fb154b507fe844f271550304be717c2 100644 (file)
 
 &wifi0 {
        status = "okay";
-
-       qcom,ath10k-calibration-variant = "MikroTik-cAP-ac";
 };
 
 &wifi1 {
        status = "okay";
-
-       qcom,ath10k-calibration-variant = "MikroTik-cAP-ac";
 };
index d03409b556efca1bbaf6e5813262f20baedc9623..829028b5278c7585dcb97f801b960be2ac814ed9 100644 (file)
 
 &wifi0 {
        status = "okay";
-
-       qcom,ath10k-calibration-variant = "MikroTik-hAP-ac2";
 };
 
 &wifi1 {
        status = "okay";
-
-       qcom,ath10k-calibration-variant = "MikroTik-hAP-ac2";
 };
index fd11229dbb531f4b8650e0c76146bde4e3e09143..f7772951772bf78407a5c63947770d2b91514197 100644 (file)
 
 &wifi1 {
        status = "okay";
-
-       qcom,ath10k-calibration-variant = "MikroTik-SXTsq-5-ac";
 };
 
 &gmac0 {
index 9aa58ffcb460681937e0964e072b6c9b3889f8cc..ebf169d0321b67d7d3af8cbe68b0c73e195a57f3 100644 (file)
 
 &wifi0 {
        status = "okay";
-
-       qcom,ath10k-calibration-variant = "MikroTik-hAP-ac3";
 };
 
 &wifi1 {
        status = "okay";
-
-       qcom,ath10k-calibration-variant = "MikroTik-hAP-ac3";
 };