ipq40xx: dynamically build board-2.bin for Mikrotik
[openwrt/staging/chunkeey.git] / target / linux / ipq40xx / base-files / etc / hotplug.d / firmware / 11-ath10k-caldata
index e0b4eed6f2b94481007de0a2d7e7fc090e51e0a6..0182823bc23cfd81aebef1812ceeff230c2d57df 100644 (file)
@@ -6,6 +6,46 @@
 
 board=$(board_name)
 
 
 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
 case "$FIRMWARE" in
 "ath10k/cal-pci-0000:01:00.0.bin")
        case "$board" in
@@ -238,6 +278,16 @@ case "$FIRMWARE" in
                ;;
        esac
        ;;
                ;;
        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
        ;;
 *)
        exit 1
        ;;