[OpenWrt-Devel,2/3] ipq-wifi: select board-2.bin at runtime

Message ID da1c83e052af2a8aaf8343deef4b7757f4395feb.1515579309.git.tommyhebb@gmail.com
State Superseded
Delegated to: John Crispin
Headers show
Series
  • [OpenWrt-Devel,1/3] build: allow custom config names in mkits.sh
Related show

Commit Message

Thomas Hebb Jan. 10, 2018, 10:15 a.m.
Currently, we solve the problem of different IPQ4019 boards needing
different sets of Wi-Fi calibration data (board-2.bin) by using an
ipq-wifi-* package to overwrite board-2.bin in the filesystem. This
presents a problem when we need the same image to support multiple
boards, as we do for the upcoming Netgear EX6100v2 and EX6150v2
support.

To solve this, re-architect the board-2.bin selection mechanism:
Instead of overwriting board-2.bin, install each version with a name
that indicates the board it's for: for example, board-2-nbg6617.bin.
Add a hotplug script to select and symlink a board-specific file if
present and otherwise fall back to the QCA-provided file, which is
now installed as board-2-generic.bin.

Signed-off-by: Thomas Hebb <tommyhebb@gmail.com>
---
 package/firmware/ath10k-firmware/Makefile          | 42 +++++++++++++++++++++-
 .../files/12-ath10k-dynamic-boarddata              | 23 ++++++++++++
 package/firmware/ipq-wifi/Makefile                 | 24 +++++--------
 3 files changed, 73 insertions(+), 16 deletions(-)
 create mode 100644 package/firmware/ath10k-firmware/files/12-ath10k-dynamic-boarddata

Comments

Mathias Kresin Jan. 11, 2018, 6:23 a.m. | #1
10.01.2018 11:15, Thomas Hebb:
> Currently, we solve the problem of different IPQ4019 boards needing
> different sets of Wi-Fi calibration data (board-2.bin) by using an
> ipq-wifi-* package to overwrite board-2.bin in the filesystem. This
> presents a problem when we need the same image to support multiple
> boards, as we do for the upcoming Netgear EX6100v2 and EX6150v2
> support.

I don't get what kind of issue do you have with this approach. Why not 
just add ipq-wifi-ex6100v2 to the DEVICE_PACKAGES of your EX6150v2.

I'm quite sure I miss here something. Which either means it is to early 
for me or the commit message doesn't provide the whole picture.

Mathias
Mathias Kresin Jan. 11, 2018, 6:44 a.m. | #2
11.01.2018 07:23, Mathias Kresin:
> 10.01.2018 11:15, Thomas Hebb:
>> Currently, we solve the problem of different IPQ4019 boards needing
>> different sets of Wi-Fi calibration data (board-2.bin) by using an
>> ipq-wifi-* package to overwrite board-2.bin in the filesystem. This
>> presents a problem when we need the same image to support multiple
>> boards, as we do for the upcoming Netgear EX6100v2 and EX6150v2
>> support.
> 
> I don't get what kind of issue do you have with this approach. Why not 
> just add ipq-wifi-ex6100v2 to the DEVICE_PACKAGES of your EX6150v2.
> 
> I'm quite sure I miss here something. Which either means it is to early 
> for me or the commit message doesn't provide the whole picture.

After reviewing your Netgear EX6100v2/EX6150v2 support patch I got your 
issue. One image for two boards where the distinction of the board is 
done in userspace and each board requires a different board-2.bin.

Mathias
Christian Lamparter Jan. 11, 2018, 5:36 p.m. | #3
On Thursday, January 11, 2018 7:44:33 AM CET Mathias Kresin wrote:
> 11.01.2018 07:23, Mathias Kresin:
> > 10.01.2018 11:15, Thomas Hebb:
> >> Currently, we solve the problem of different IPQ4019 boards needing
> >> different sets of Wi-Fi calibration data (board-2.bin) by using an
> >> ipq-wifi-* package to overwrite board-2.bin in the filesystem. This
> >> presents a problem when we need the same image to support multiple
> >> boards, as we do for the upcoming Netgear EX6100v2 and EX6150v2
> >> support.
> > 
> > I don't get what kind of issue do you have with this approach. Why not 
> > just add ipq-wifi-ex6100v2 to the DEVICE_PACKAGES of your EX6150v2.
> > 
> > I'm quite sure I miss here something. Which either means it is to early 
> > for me or the commit message doesn't provide the whole picture.
> 
> After reviewing your Netgear EX6100v2/EX6150v2 support patch I got your 
> issue. One image for two boards where the distinction of the board is 
> done in userspace and each board requires a different board-2.bin.

Wait! It is possible to do this now:
Sven Eckelmann added support for extracting the variant from the DT.
"ath10k: search DT for qcom,ath10k-calibration-variant" [0]

So, if Thomas splits the EX6100v2 and EX6150v2 image. He could have
two separate dts. This way, each device can have its unique
"qcom,ath10k-calibration-variant" and both can share a single 
board-2.bin.

@Thomas, it's possible to get the EX6100v2/EX6150v2 board.bin into
the official board-2.bin. The process is explained on the linux-wireless
wiki:
<https://wireless.wiki.kernel.org/en/users/drivers/ath10k/boardfiles>
It would be great if you could post the raw board.bin files there
too.

Christian

[0] <https://patchwork.kernel.org/patch/10102251/>
Matthew McClintock Jan. 16, 2018, 2:50 p.m. | #4
On Thu, Jan 11, 2018 at 11:36 AM, Christian Lamparter
<chunkeey@gmail.com> wrote:
> On Thursday, January 11, 2018 7:44:33 AM CET Mathias Kresin wrote:
>> 11.01.2018 07:23, Mathias Kresin:
>> > 10.01.2018 11:15, Thomas Hebb:
>> >> Currently, we solve the problem of different IPQ4019 boards needing
>> >> different sets of Wi-Fi calibration data (board-2.bin) by using an
>> >> ipq-wifi-* package to overwrite board-2.bin in the filesystem. This
>> >> presents a problem when we need the same image to support multiple
>> >> boards, as we do for the upcoming Netgear EX6100v2 and EX6150v2
>> >> support.
>> >
>> > I don't get what kind of issue do you have with this approach. Why not
>> > just add ipq-wifi-ex6100v2 to the DEVICE_PACKAGES of your EX6150v2.
>> >
>> > I'm quite sure I miss here something. Which either means it is to early
>> > for me or the commit message doesn't provide the whole picture.
>>
>> After reviewing your Netgear EX6100v2/EX6150v2 support patch I got your
>> issue. One image for two boards where the distinction of the board is
>> done in userspace and each board requires a different board-2.bin.
>
> Wait! It is possible to do this now:
> Sven Eckelmann added support for extracting the variant from the DT.
> "ath10k: search DT for qcom,ath10k-calibration-variant" [0]
>
> So, if Thomas splits the EX6100v2 and EX6150v2 image. He could have
> two separate dts. This way, each device can have its unique
> "qcom,ath10k-calibration-variant" and both can share a single
> board-2.bin.
>
> @Thomas, it's possible to get the EX6100v2/EX6150v2 board.bin into
> the official board-2.bin. The process is explained on the linux-wireless
> wiki:
> <https://wireless.wiki.kernel.org/en/users/drivers/ath10k/boardfiles>
> It would be great if you could post the raw board.bin files there
> too.

There are also tools to repackage here:
https://github.com/qca/qca-swiss-army-knife

So you could make your own with just the calibration ones you were
interested in (to save space?) or just add your missing ones to a
custom board-2.bin.

-M

Patch

diff --git a/package/firmware/ath10k-firmware/Makefile b/package/firmware/ath10k-firmware/Makefile
index 1c6f4dfb7f..99e0551a25 100644
--- a/package/firmware/ath10k-firmware/Makefile
+++ b/package/firmware/ath10k-firmware/Makefile
@@ -193,6 +193,7 @@  $(Package/ath10k-firmware-default)
   TITLE:=ath10k firmware for IPQ/QCA4019 devices
   SECTION:=firmware
   CATEGORY:=Firmware
+  DEPENDS:=+ath10k-dynamic-boarddata
 endef
 
 define Package/ath10k-firmware-qca6174
@@ -221,7 +222,7 @@  define Package/ath10k-firmware-qca4019/install
 	$(INSTALL_DIR) $(1)/lib/firmware/ath10k/QCA4019/hw1.0
 	$(INSTALL_DATA) \
 		$(PKG_BUILD_DIR)/QCA4019/hw1.0/board-2.bin \
-		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/
+		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/board-2-generic.bin
 	$(INSTALL_DATA) \
 		$(PKG_BUILD_DIR)/QCA4019/hw1.0/3.2.1/firmware-5.bin_10.4-3.2.1-00058 \
 		$(1)/lib/firmware/ath10k/QCA4019/hw1.0/firmware-5.bin
@@ -341,6 +342,43 @@  define Package/ath10k-firmware-qca9888-ct/install
 		$(1)/lib/firmware/ath10k/QCA9888/hw2.0/firmware-5.bin
 endef
 
+# We currently only support dynamic selection of board-2.bin for QCA4019.
+# To add support for another chip:
+#
+#  1. Change the relevant ath10k-firmware package to install board-2.bin
+#     as board-2-generic.bin.
+#  2. Make that package depend on ath10k-dynamic-boarddata.
+#  3. Add the customized board-2.bin files to the ipq-wifi package, ensuring
+#     that they are placed alongside board-2-generic.bin and are named
+#     board-2-<board_name>.bin. On boot, the dynamic boarddata script will
+#     select and symlink the correct file.
+
+define Package/ath10k-dynamic-boarddata
+  SECTION:=firmware
+  CATEGORY:=Firmware
+  TITLE:=hotplug script to dynamically select ath10k board-2.bin
+endef
+
+define Package/ath10k-dynamic-boarddata/description
+Several IPQ4019 boards require custom Wi-Fi calibration data but reuse BMI
+IDs that are in QCA's stock calibration data. As such, it's not possible to
+store calibration for all of these boards in a single board-2.bin, as the
+ath10k driver expects. This package provides a hotplug script that
+determines the board we're running on and symlinks board-2.bin to the
+appropriate version at runtime.
+
+Note that this package does not provide any board-specific versions of
+board-2.bin. In order for it to be useful, you must also include one or
+more of the ipq-wifi-* packages.
+endef
+
+define Package/ath10k-dynamic-boarddata/install
+	$(INSTALL_DIR) $(1)/etc/hotplug.d/firmware
+	$(INSTALL_DATA) \
+		./files/12-ath10k-dynamic-boarddata \
+		$(1)/etc/hotplug.d/firmware/
+endef
+
 $(eval $(call BuildPackage,ath10k-firmware-qca9887))
 $(eval $(call BuildPackage,ath10k-firmware-qca9888))
 $(eval $(call BuildPackage,ath10k-firmware-qca988x))
@@ -354,3 +392,5 @@  $(eval $(call BuildPackage,ath10k-firmware-qca988x-ct))
 $(eval $(call BuildPackage,ath10k-firmware-qca99x0-ct))
 $(eval $(call BuildPackage,ath10k-firmware-qca9984-ct))
 $(eval $(call BuildPackage,ath10k-firmware-qca9888-ct))
+
+$(eval $(call BuildPackage,ath10k-dynamic-boarddata))
diff --git a/package/firmware/ath10k-firmware/files/12-ath10k-dynamic-boarddata b/package/firmware/ath10k-firmware/files/12-ath10k-dynamic-boarddata
new file mode 100644
index 0000000000..f9adedf0fc
--- /dev/null
+++ b/package/firmware/ath10k-firmware/files/12-ath10k-dynamic-boarddata
@@ -0,0 +1,23 @@ 
+#!/bin/sh
+
+log() {
+	logger -t ath10k-dynamic-boarddata "$@"
+}
+
+dest="/lib/firmware/$FIRMWARE"
+
+[ -e "$dest" ] && exit 0
+echo "$dest" | grep -qx "/lib/firmware/ath10k/.*/board-2.bin" || exit 0
+
+dir="$(dirname "$dest")"
+board="$(board_name)"
+
+if [ -e "$dir/board-2-$board.bin" ] ; then
+	log "Selecting customized board-2.bin for board \"$board\""
+	ln -s "$dir/board-2-$board.bin" "$dest"
+elif [ -e "$dir/board-2-generic.bin" ] ; then
+	log "Selecting generic board-2.bin"
+	ln -s "$dir/board-2-generic.bin" "$dest"
+else
+	log -p user.err "ERROR: No board-2.bin variant present. QCA Wi-Fi will not work."
+fi
diff --git a/package/firmware/ipq-wifi/Makefile b/package/firmware/ipq-wifi/Makefile
index aec8bf27c2..f2b705e13a 100644
--- a/package/firmware/ipq-wifi/Makefile
+++ b/package/firmware/ipq-wifi/Makefile
@@ -20,35 +20,29 @@  define Package/ipq-wifi-default
   SUBMENU:=ath10k IPQ4019 Boarddata
   SECTION:=firmware
   CATEGORY:=Firmware
-  DEPENDS:=@TARGET_ipq806x +ath10k-firmware-qca4019
+  DEPENDS:=@TARGET_ipq806x +ath10k-firmware-qca4019 +ath10k-dynamic-boarddata
   TITLE:=Custom Board
 endef
 
 define generate-ipq-wifi-package
   define Package/ipq-wifi-$(1)
     $(call Package/ipq-wifi-default)
-    TITLE:=Board for $(3)
-    CONFLICTS:=$(PREV_BOARD)
+    TITLE:=Board for $(2)
   endef
 
   define Package/ipq-wifi-$(1)/description
-This device custom package board-2.bin overwrites the board-2.bin
-file which is supplied by the ath10k-firmware-qca4019 package.
-
-This is package is only necessary for the $(3).
-Don't install it for any other device!
+Device-specific board-2.bin file for the $(2) that can be selected by
+ath10k-dynamic-boarddata.
   endef
 
-  define Package/ipq-wifi-$(1)/install-overlay
+  define Package/ipq-wifi-$(1)/install
 	$(INSTALL_DIR) $$(1)/lib/firmware/ath10k/QCA4019/hw1.0
-	$(INSTALL_DATA) ./$(2) $$(1)/lib/firmware/ath10k/QCA4019/hw1.0/board-2.bin
+	$(INSTALL_DATA) ./board-$(1).bin $$(1)/lib/firmware/ath10k/QCA4019/hw1.0/board-2-$(1).bin
   endef
-
-  PREV_BOARD+=ipq-wifi-$(1)
 endef
 
-$(eval $(call generate-ipq-wifi-package,rt-ac58u,board-rt-ac58u.bin,ASUS RT-AC58U/RT-ACRH13))
-$(eval $(call generate-ipq-wifi-package,fritz4040,board-fritz4040.bin,AVM FRITZBox 4040))
-$(eval $(call generate-ipq-wifi-package,nbg6617,board-nbg6617.bin,ZyXEL NBG6617))
+$(eval $(call generate-ipq-wifi-package,rt-ac58u,ASUS RT-AC58U/RT-ACRH13))
+$(eval $(call generate-ipq-wifi-package,fritz4040,AVM FRITZBox 4040))
+$(eval $(call generate-ipq-wifi-package,nbg6617,ZyXEL NBG6617))
 
 $(foreach PACKAGE,$(ALLWIFIPACKAGES),$(eval $(call BuildPackage,$(PACKAGE))))