Bluetooth: btrtl: Add firmware format v3 support
PATCH v7 1/1 Bluetooth: btrtl: Add firmware format v3 support
Realtek has introduced a new Bluetooth firmware format, firmware format v3. This is a Realtek-internal specification; the format differences from v2 are documented inline in this patch.
This patch extends the btrtl driver to recognize and parse the new v3 file format, including:
- New signature string and subsection ID definitions
- Extension of btrtl_device_info to store v3-specific metadata
- Logic to extract and load firmware data out of v3
- Maintains compatibility with the existing v2 firmware format
The RTL8922D is the first IC to use firmware format v3. The firmware binary (rtl8922du_fw.bin) payload is approximately 267 KB (0x40a7c bytes), and on a typical boot the full sequence from rtl_load_file() to rtl_finalize_download() completing takes average ~483 ms.
The following is RTL8922D log as expected fw format v3 output:
[ 1.838104] Bluetooth: btrtl_read_chip_id() hci0: RTL: chip_id status=0x00 id=0x3e [ 1.838331] Bluetooth: btrtl_initialize() hci0: RTL: examining hci_ver=0e hci_rev=000d lmp_ver=0e lmp_subver=8922 [ 1.838571] Bluetooth: rtl_read_rom_version() hci0: RTL: rom_version status=0 version=0 [ 1.838821] Bluetooth: btrtl_initialize() hci0: RTL: btrtl_initialize: key id 0 [ 1.838825] Bluetooth: rtl_load_file() hci0: RTL: loading rtl_bt/rtl8922du_fw.bin [ 1.843021] Bluetooth: rtl_load_file() hci0: RTL: loading rtl_bt/rtl8922du_config.bin [ 1.843317] Bluetooth: rtlbt_parse_firmware_v3() hci0: RTL: key id 0 [ 1.843325] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: subsection (f000:00), chip id 62, cut 0x01, len 0000c704 [ 1.843342] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: subsection version: c5900782 [ 1.843347] Bluetooth: rtlbt_parse_config() hci0: RTL: config file: rtl_bt/rtl8922du_config_f000.bin [ 1.843363] Bluetooth: rtlbt_parse_config() hci0: RTL: config file: rtl_bt/rtl8922du_config_f000.bin not found, use default [ 1.843366] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: subsection (f002:00), chip id 62, cut 0x01, len 00034378 [ 1.843417] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: subsection version: 2b84a8b2 [ 1.843421] Bluetooth: rtlbt_parse_config() hci0: RTL: config file: rtl_bt/rtl8922du_config_f002.bin [ 1.843647] Bluetooth: rtlbt_parse_config() hci0: RTL: config file: rtl_bt/rtl8922du_config_f002.bin found [ 1.843654] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: subsection (f000:00), chip id 62, cut 0x01, len 0000c704 [ 1.843658] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: skip, key_id mismatch (1, 0) [ 1.843661] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: subsection (f002:00), chip id 62, cut 0x01, len 00034378 [ 1.843664] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: skip, key_id mismatch (1, 0) [ 1.843672] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: subsection (f000:00), chip id 62, cut 0x01, len 0000c704 [ 1.843674] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: skip, key_id mismatch (2, 0) [ 1.843676] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: subsection (f002:00), chip id 62, cut 0x01, len 00034378 [ 1.843678] Bluetooth: rtlbt_parse_section_v3() hci0: RTL: skip, key_id mismatch (2, 0) [ 1.843680] Bluetooth: rtlbt_parse_firmware_v3() hci0: RTL: firmware section payload total len: 0x00040a7c [ 2.293192] Bluetooth: rtl_finalize_download() hci0: RTL: Watchdog reset status 00 [ 2.293957] Bluetooth: rtl_finalize_download() hci0: RTL: fw version 0x2b84a8b2
---
V6 -> V7:
- Fix smatch warning in btrtl_free(): move the NULL check on btrtl_dev to the very beginning of the function, before any dereference, instead of after it has already been dereferenced multiple times (Reported by kernel test / Dan Carpenter)
- Revise log message to use "subsection" terminology for clarity
- Add informational message when a config file is not found
V5 -> V6:
- Add missing parentheses around the entire is_v3_fw() macro expression to avoid incorrect evaluation with the logical NOT operator on legacy firmware types
- Add NULL check on ic_info->cfg_name before use in rtlbt_parse_config() to avoid NULL pointer dereference when a crafted firmware specifies FW_TYPE_V3_2 on legacy chips without configuration
- Add bounds check to reject patch_image_len < 4 before reading the image version, preventing an out-of-bounds read
- Propagate the return value of rtlbt_parse_config() and abort parsing on failure instead of silently continuing without the required configuration
- Fix a race condition in rtl_check_download_state() by setting the REALTEK_DOWNLOADING flag before issuing the check-download command, instead of after, to avoid missing the completion event
- Split v3 firmware parse/download logic into new btrtl_enh.c to keep btrtl.c size manageable
V4 -> V5:
- Add independent support for RTL8922D section
- Introduce macros to improve code readability
- Document firmware format v3 and its differences
- Align implementation with reviewer feedback
V3 -> V4:
- Rework skb->data access and add clarifying comments
- Fix latent issues
V2 -> V3:
- Address coccinelle warning
V1 -> V2:
- Add missing symbols
- Resolve build warnings
---
--- drivers/bluetooth/Makefile | 2 +- drivers/bluetooth/btrtl.c | 223 +++++++--- drivers/bluetooth/btrtl.h | 109 ++++- drivers/bluetooth/btrtl_enh.c | 811 ++++++++++++++++++++++++++++++++++ drivers/bluetooth/btusb.c | 3 + 5 files changed, 1088 insertions(+), 60 deletions(-) create mode 100644 drivers/bluetooth/btrtl_enh.c
drivers/bluetooth/Makefile +1 -1
@@ -22,7 +22,7 @@ obj-$(CONFIG_BT_MTKSDIO) += btmtksdio.o obj-$(CONFIG_BT_MTKUART) += btmtkuart.o obj-$(CONFIG_BT_QCOMSMD) += btqcomsmd.o obj-$(CONFIG_BT_BCM) += btbcm.o -obj-$(CONFIG_BT_RTL) += btrtl.o +obj-$(CONFIG_BT_RTL) += btrtl_enh.o btrtl.o obj-$(CONFIG_BT_QCA) += btqca.o obj-$(CONFIG_BT_MTK) += btmtk.o
drivers/bluetooth/btrtl.c +165 -58
455 lines not on this page · raw message
drivers/bluetooth/btrtl.h +108 -1
142 lines not on this page · raw message
drivers/bluetooth/btrtl_enh.c new file +811 -0
811 lines not on this page · raw message
drivers/bluetooth/btusb.c +3 -0
@@ -2934,6 +2934,9 @@ static int btusb_recv_event_realtek(struct hci_dev *hdev, struct sk_buff *skb)return 0 ; } +if (skb->data[0 ] ==HCI_VENDOR_PKT ) +return btrtl_recv_event (hdev, skb); +return hci_recv_frame (hdev, skb); }
Signature · 1 line
2.34.1
This is an automated email and please do not reply to this email.
Dear Submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.
----- Output -----
Please resolve the issue and submit the patches again.
---
Regards,
Linux Bluetooth