#!/bin/sh
#
# wlan-board -- the phone's own WLAN board data for ath10k, before the
# driver loads (stage 1, after firmware-partitions): the persist partition's
# bdwlan.bin (the board data the vendor's software uses; it matches none of
# the generic bdwlan.* files in the modem partition), wrapped by
# ath10k-board into /run/makronix-firmware/ath10k/WCN3990/hw1.0/board-2.bin
# under the names ath10k asks for when the chip has no board id (0xff).
# persist is ext4 and mounted read-only without journal replay (noload): it
# is the vendor's and must not change.  Nothing to do on a phone without it.

PERSIST=/run/makronix-partitions/persist
OUT=/run/makronix-firmware/ath10k/WCN3990/hw1.0

dev=
for u in /sys/class/block/*/uevent; do
	grep -qx PARTNAME=persist "$u" && { d=${u%/uevent}; dev=/dev/${d##*/}; break; }
done
[ -n "$dev" ] || exit 0

mkdir -p "$PERSIST"
grep -q " $PERSIST " /proc/mounts ||
	mount -t ext4 -o ro,noload,nosuid,nodev,noexec "$dev" "$PERSIST" || exit 1
[ -s "$PERSIST/bdwlan.bin" ] || exit 0

mkdir -p "$OUT"
/usr/libexec/makronix/ath10k-board "$PERSIST/bdwlan.bin" "$OUT/board-2.bin" \
	"bus=snoc,qmi-board-id=ff,qmi-chip-id=30224" "bus=snoc,qmi-board-id=ff" &&
	echo "wlan-board: $OUT/board-2.bin from $dev (persist) bdwlan.bin" > /dev/kmsg
