From: Gerhard Sittig Date: Thu, 3 Feb 2022 18:48:58 +0000 (+0100) Subject: kingst-la2016: unconditionally construct MCU firmware filename X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=91aa0f043318df0269bc9247ddaaa1c7785e68d1;p=libsigrok.git kingst-la2016: unconditionally construct MCU firmware filename Always call the MCU firmware download routine that is implemented in the protocol.c source file when the api.c scan routine executes. But only conditionally load the MCU firmware to the probed device when strictly necessary. This makes filename information available to users since these details are essential for the operation of a device, yet keeps intimate firmware implementation details in the appropriate location in the implementation. --- diff --git a/src/hardware/kingst-la2016/api.c b/src/hardware/kingst-la2016/api.c index 3fec45b6..e1a28332 100644 --- a/src/hardware/kingst-la2016/api.c +++ b/src/hardware/kingst-la2016/api.c @@ -517,9 +517,10 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) * this device. */ devc->fw_uploaded = 0; + devc->usb_pid = pid; if (des.iProduct != LA2016_IPRODUCT_INDEX) { sr_info("Uploading MCU firmware to '%s'.", conn_id); - ret = la2016_upload_firmware(sdi, ctx, dev, pid); + ret = la2016_upload_firmware(sdi, ctx, dev, FALSE); if (ret != SR_OK) { sr_err("MCU firmware upload failed."); kingst_la2016_free_sdi(sdi); @@ -529,6 +530,13 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options) usb->address = 0xff; renum_devices = g_slist_append(renum_devices, sdi); continue; + } else { + ret = la2016_upload_firmware(sdi, NULL, NULL, TRUE); + if (ret != SR_OK) { + sr_err("MCU firmware filename check failed."); + kingst_la2016_free_sdi(sdi); + continue; + } } /* diff --git a/src/hardware/kingst-la2016/protocol.c b/src/hardware/kingst-la2016/protocol.c index 21265ab0..2cf67c70 100644 --- a/src/hardware/kingst-la2016/protocol.c +++ b/src/hardware/kingst-la2016/protocol.c @@ -864,28 +864,29 @@ static int get_capture_info(const struct sr_dev_inst *sdi) } SR_PRIV int la2016_upload_firmware(const struct sr_dev_inst *sdi, - struct sr_context *sr_ctx, libusb_device *dev, uint16_t product_id) + struct sr_context *sr_ctx, libusb_device *dev, gboolean skip_upload) { struct dev_context *devc; - char *fw_file; + uint16_t pid; + char *fw; int ret; devc = sdi ? sdi->priv : NULL; + if (!devc || !devc->usb_pid) + return SR_ERR_ARG; + pid = devc->usb_pid; - fw_file = g_strdup_printf(MCU_FWFILE_FMT, product_id); - sr_info("USB PID %04hx, MCU firmware '%s'.", product_id, fw_file); + fw = g_strdup_printf(MCU_FWFILE_FMT, pid); + sr_info("USB PID %04hx, MCU firmware '%s'.", pid, fw); + devc->mcu_firmware = g_strdup(fw); - ret = ezusb_upload_firmware(sr_ctx, dev, USB_CONFIGURATION, fw_file); - if (ret != SR_OK) { - g_free(fw_file); + if (skip_upload) + ret = SR_OK; + else + ret = ezusb_upload_firmware(sr_ctx, dev, USB_CONFIGURATION, fw); + g_free(fw); + if (ret != SR_OK) return ret; - } - - if (devc) { - devc->mcu_firmware = fw_file; - fw_file = NULL; - } - g_free(fw_file); return SR_OK; } diff --git a/src/hardware/kingst-la2016/protocol.h b/src/hardware/kingst-la2016/protocol.h index 5695feaf..37061c2c 100644 --- a/src/hardware/kingst-la2016/protocol.h +++ b/src/hardware/kingst-la2016/protocol.h @@ -150,7 +150,7 @@ struct dev_context { }; SR_PRIV int la2016_upload_firmware(const struct sr_dev_inst *sdi, - struct sr_context *sr_ctx, libusb_device *dev, uint16_t product_id); + struct sr_context *sr_ctx, libusb_device *dev, gboolean skip_upload); SR_PRIV int la2016_identify_device(const struct sr_dev_inst *sdi, gboolean show_message); SR_PRIV int la2016_init_hardware(const struct sr_dev_inst *sdi);