Date: Wed, 29 Jan 2025 21:57:20 GMT From: Vladimir Kondratyev <wulf@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: ff4116313eb4 - main - iwmbtfw(8): don't program hardware without existing firmware image Message-ID: <202501292157.50TLvKUR001484@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=ff4116313eb4a5e6c24a688edf5df1e19eb82042 commit ff4116313eb4a5e6c24a688edf5df1e19eb82042 Author: Eygene Ryabinkin <rea@FreeBSD.org> AuthorDate: 2025-01-29 21:56:41 +0000 Commit: Vladimir Kondratyev <wulf@FreeBSD.org> CommitDate: 2025-01-29 21:56:41 +0000 iwmbtfw(8): don't program hardware without existing firmware image One should not start firmware update sequence just to understand that there is no firmware image to program: update sequence for 7260 requires leaving manufacturing mode and in the case of missing firmware file it will trigger complete re-initialization of BT adapter. Which, in turn, will make the USB device to go away and reappear. Since devd(8) has hooks for USB device attachment, in the case of missing firmware it used to - trigger the (failing) firmware download, - which triggers device reset, - which creates USB notification and devd(8) kicks back in. Nice infinite cycle with many notifications via syslog: {{{ Jan 3 09:00:01 kernel: ugen0.2: <vendor 0x8087 product 0x0a2a> at usbus0 Jan 3 09:00:01 kernel: ugen0.2: <vendor 0x8087 product 0x0a2a> at usbus0 (disconnected) Jan 3 09:00:02 kernel: ugen0.2: <vendor 0x8087 product 0x0a2a> at usbus0 Jan 3 09:00:02 kernel: ugen0.2: <vendor 0x8087 product 0x0a2a> at usbus0 (disconnected) }}} Signed-off-by: Eygene Ryabinkin <rea@FreeBSD.org> Reviewed by: wulf MFC after: 1 month --- usr.sbin/bluetooth/iwmbtfw/main.c | 41 +++++++++++++-------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/usr.sbin/bluetooth/iwmbtfw/main.c b/usr.sbin/bluetooth/iwmbtfw/main.c index 497edcb254cf..7af07bb68322 100644 --- a/usr.sbin/bluetooth/iwmbtfw/main.c +++ b/usr.sbin/bluetooth/iwmbtfw/main.c @@ -226,30 +226,6 @@ iwmbt_dump_version_tlv(struct iwmbt_version_tlv *ver) ver->build_num); } -static int -iwmbt_patch_firmware(libusb_device_handle *hdl, const char *firmware_path) -{ - struct iwmbt_firmware fw; - int ret; - - iwmbt_debug("loading %s", firmware_path); - - /* Read in the firmware */ - if (iwmbt_fw_read(&fw, firmware_path) <= 0) { - iwmbt_debug("iwmbt_fw_read() failed"); - return (-1); - } - - /* Load in the firmware */ - ret = iwmbt_patch_fwfile(hdl, &fw); - if (ret < 0) - iwmbt_debug("Loading firmware file failed"); - - /* free it */ - iwmbt_fw_free(&fw); - - return (ret); -} static int iwmbt_init_firmware(libusb_device_handle *hdl, const char *firmware_path, @@ -402,6 +378,7 @@ usage(void) } + /* * Returns 0 on success. */ @@ -409,8 +386,9 @@ static int handle_7260(libusb_device_handle *hdl, char *firmware_dir) { int r; + char *firmware_path; struct iwmbt_version ver; - char *firmware_path = NULL; + struct iwmbt_firmware fw; r = iwmbt_get_version(hdl, &ver); if (r < 0) { @@ -431,16 +409,25 @@ handle_7260(libusb_device_handle *hdl, char *firmware_dir) return 1; iwmbt_debug("firmware_path = %s", firmware_path); + r = iwmbt_fw_read(&fw, firmware_path); + free(firmware_path); + if (r <= 0) { + iwmbt_debug("iwmbt_fw_read() failed"); + return 1; + } + r = iwmbt_enter_manufacturer(hdl); if (r < 0) { iwmbt_debug("iwmbt_enter_manufacturer() failed code %d", r); + iwmbt_fw_free(&fw); return 1; } /* Download firmware */ - r = iwmbt_patch_firmware(hdl, firmware_path); - free(firmware_path); + r = iwmbt_patch_fwfile(hdl, &fw); + iwmbt_fw_free(&fw); if (r < 0) { + iwmbt_debug("Loading firmware file failed"); (void)iwmbt_exit_manufacturer(hdl, IWMBT_MM_EXIT_COLD_RESET); return 1; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202501292157.50TLvKUR001484>