asix-sigma: Fix firmware path construction

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 <marex@denx.de>
This commit is contained in:
Marek Vasut 2014-04-20 17:49:29 +02:00 committed by Bert Vermeulen
parent d5fa188ac9
commit 499b17e9c0
1 changed files with 15 additions and 13 deletions

View File

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