]> sigrok.org Git - libsigrok.git/commitdiff
kingst-la2016: unconditionally construct MCU firmware filename
authorGerhard Sittig <redacted>
Thu, 3 Feb 2022 18:48:58 +0000 (19:48 +0100)
committerGerhard Sittig <redacted>
Sun, 6 Feb 2022 17:53:54 +0000 (18:53 +0100)
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.

src/hardware/kingst-la2016/api.c
src/hardware/kingst-la2016/protocol.c
src/hardware/kingst-la2016/protocol.h

index 3fec45b625ea9b60f2d12810f2e82ad107962d73..e1a2833220f1c2fed6fbb530642d8482bafc8900 100644 (file)
@@ -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;
+                       }
                }
 
                /*
index 21265ab00d557524296dd0ce7d32f441b5fd6fd2..2cf67c707cda7ac201f2f81a33636439c2a0eb00 100644 (file)
@@ -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;
 }
index 5695feaf5a36ddc351576b6670e9124d4e27b6ab..37061c2c5ce8f7dbb9d3484b7a5138ffb6230962 100644 (file)
@@ -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);