]> sigrok.org Git - libsigrok.git/commitdiff
asix-sigma: Fix firmware path construction
authorMarek Vasut <redacted>
Sun, 20 Apr 2014 15:49:29 +0000 (17:49 +0200)
committerBert Vermeulen <redacted>
Wed, 30 Apr 2014 16:45:50 +0000 (09:45 -0700)
The code silently assumed the firmware path can be no longer than 128 bytes.
This doesn't scale. This patch fixes it in such a way that it completely
rips out the run-time computation of firmware path and instead replaces it
with compile-time computation. It's true this makes the library grow by a
couple bytes, but makes the code cleaner.

Signed-off-by: Marek Vasut <redacted>
hardware/asix-sigma/asix-sigma.c

index 7f49dc2dd8c8c1005a1324f343359ece2fe2ac10..f813edd91196b0e83fa973f5703efc89f615b318 100644 (file)
@@ -86,12 +86,17 @@ static uint8_t logic_mode_start[] = {
        0x2a, 0x3a, 0x40, 0x03, 0x20, 0x38,
 };
 
-static const char *firmware_files[] = {
-       "asix-sigma-50.fw",     /* 50 MHz, supports 8 bit fractions */
-       "asix-sigma-100.fw",    /* 100 MHz */
-       "asix-sigma-200.fw",    /* 200 MHz */
-       "asix-sigma-50sync.fw", /* Synchronous clock from pin */
-       "asix-sigma-phasor.fw", /* Frequency counter */
+static const char *sigma_firmware_files[] = {
+       /* 50 MHz, supports 8 bit fractions */
+       FIRMWARE_DIR "/asix-sigma-50.fw",
+       /* 100 MHz */
+       FIRMWARE_DIR "/asix-sigma-100.fw",
+       /* 200 MHz */
+       FIRMWARE_DIR "/asix-sigma-200.fw",
+       /* Synchronous clock from pin */
+       FIRMWARE_DIR "/asix-sigma-50sync.fw",
+       /* Frequency counter */
+       FIRMWARE_DIR "/asix-sigma-phasor.fw",
 };
 
 static int sigma_read(void *buf, size_t size, struct dev_context *devc)
@@ -537,7 +542,7 @@ static int upload_firmware(int firmware_idx, struct dev_context *devc)
        unsigned char pins;
        size_t buf_size;
        unsigned char result[32];
-       char firmware_path[128];
+       const char *firmware = sigma_firmware_files[firmware_idx];
 
        /* Make sure it's an ASIX SIGMA. */
        if ((ret = ftdi_usb_open_desc(&devc->ftdic,
@@ -566,17 +571,14 @@ static int upload_firmware(int firmware_idx, struct dev_context *devc)
                return ret;
 
        /* Prepare firmware. */
-       snprintf(firmware_path, sizeof(firmware_path), "%s/%s", FIRMWARE_DIR,
-                firmware_files[firmware_idx]);
-
-       if ((ret = bin2bitbang(firmware_path, &buf, &buf_size)) != SR_OK) {
+       if ((ret = bin2bitbang(firmware, &buf, &buf_size)) != SR_OK) {
                sr_err("An error occured while reading the firmware: %s",
-                      firmware_path);
+                      firmware);
                return ret;
        }
 
        /* Upload firmare. */
-       sr_info("Uploading firmware file '%s'.", firmware_files[firmware_idx]);
+       sr_info("Uploading firmware file '%s'.", firmware);
        sigma_write(buf, buf_size, devc);
 
        g_free(buf);