diff options
author | Eygene Ryabinkin <rea@FreeBSD.org> | 2025-01-29 21:56:41 +0000 |
---|---|---|
committer | Vladimir Kondratyev <wulf@FreeBSD.org> | 2025-01-29 21:56:41 +0000 |
commit | ff4116313eb4a5e6c24a688edf5df1e19eb82042 (patch) | |
tree | c8285ac22969a2b3a4d38052c5a8e7fcf76d6862 | |
parent | 06969db312022277729dd144e3655a90007306ef (diff) |
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
-rw-r--r-- | usr.sbin/bluetooth/iwmbtfw/main.c | 41 |
1 files 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; } |