main: add option to specify device index

This commit is contained in:
Gwenhael Goavec-Merou 2021-05-15 15:26:09 +02:00
parent acf4ab270c
commit 27af85dc19
2 changed files with 58 additions and 37 deletions

View File

@ -163,31 +163,35 @@ openFPGALoader --help
Usage: openFPGALoader [OPTION...] BIT_FILE Usage: openFPGALoader [OPTION...] BIT_FILE
openFPGALoader -- a program to flash FPGA openFPGALoader -- a program to flash FPGA
--bitstream arg bitstream --bitstream arg bitstream
-b, --board arg board name, may be used instead of cable -b, --board arg board name, may be used instead of cable
-c, --cable arg jtag interface -c, --cable arg jtag interface
--ftdi-serial arg FTDI chip serial number --ftdi-serial arg FTDI chip serial number
--ftdi-channel arg FTDI chip channel number (channels 0-3 map to A-D) --ftdi-channel arg FTDI chip channel number (channels 0-3 map to
-d, --device arg device to use (/dev/ttyUSBx) A-D)
--detect detect FPGA -d, --device arg device to use (/dev/ttyUSBx)
--file-type arg provides file type instead of let's deduced by --detect detect FPGA
using extension --file-type arg provides file type instead of let's deduced by
--freq arg jtag frequency (Hz) using extension
-f, --write-flash write bitstream in flash (default: false, only for --fpga-part arg fpga model flavor + package
Gowin and ECP5 devices) --freq arg jtag frequency (Hz)
--list-boards list all supported boards -f, --write-flash write bitstream in flash (default: false, only
--list-cables list all supported cables for Gowin and ECP5 devices)
--list-fpga list all supported FPGA --index-chain arg device index in JTAG-chain
-m, --write-sram write bitstream in SRAM (default: true, only for --list-boards list all supported boards
Gowin and ECP5 devices) --list-cables list all supported cables
-o, --offset arg start offset in EEPROM --list-fpga list all supported FPGA
--pins arg pin config (only for ft232R) TDI:TDO:TCK:TMS -m, --write-sram write bitstream in SRAM (default: true, only for
--quiet Produce quiet output (no progress bar) Gowin and ECP5 devices)
-r, --reset reset FPGA after operations -o, --offset arg start offset in EEPROM
--spi SPI mode (only for FTDI in serial mode) --pins arg pin config (only for ft232R) TDI:TDO:TCK:TMS
-v, --verbose Produce verbose output --probe-firmware arg firmware for JTAG probe (usbBlasterII)
-h, --help Give this help list --quiet Produce quiet output (no progress bar)
-V, --Version Print program version -r, --reset reset FPGA after operations
--spi SPI mode (only for FTDI in serial mode)
-v, --verbose Produce verbose output
-h, --help Give this help list
-V, --Version Print program version
Mandatory or optional arguments to long options are also mandatory or optional Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options. for any corresponding short options.

View File

@ -64,6 +64,7 @@ struct arguments {
string file_type; string file_type;
string fpga_part; string fpga_part;
string probe_firmware; string probe_firmware;
int index_chain;
}; };
int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *pins_config); int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *pins_config);
@ -79,7 +80,7 @@ int main(int argc, char **argv)
/* command line args. */ /* command line args. */
struct arguments args = {0, false, false, 0, "", "", "-", "", -1, 6000000, "-", struct arguments args = {0, false, false, 0, "", "", "-", "", -1, 6000000, "-",
false, false, false, false, Device::WR_SRAM, false, false, "", false, false, false, false, Device::WR_SRAM, false, false, "",
"", ""}; "", "", 0};
/* parse arguments */ /* parse arguments */
try { try {
if (parse_opt(argc, argv, &args, &pins_config)) if (parse_opt(argc, argv, &args, &pins_config))
@ -274,19 +275,30 @@ int main(int argc, char **argv)
} }
if (found != 0) { if (found != 0) {
for (int i = 0; i < found; i++) { if (args.index_chain == -1) {
if (fpga_list.find(listDev[i]) != fpga_list.end()) { for (int i = 0; i < found; i++) {
index = i; if (fpga_list.find(listDev[i]) != fpga_list.end()) {
if (idcode != -1) { index = i;
printError("Error: currently only one device is supported"); if (idcode != -1) {
for (int i = 0; i < found; i++) printError("Error: more than one FPGA found");
printf("0x%08x\n", listDev[i]); printError("Use --index-chain to force selection");
delete(jtag); for (int i = 0; i < found; i++)
return EXIT_FAILURE; printf("0x%08x\n", listDev[i]);
} else { delete(jtag);
idcode = listDev[i]; return EXIT_FAILURE;
} else {
idcode = listDev[i];
}
} }
} }
} else {
index = args.index_chain;
if (index > found || index < 0) {
printError("wrong index for device in JTAG chain");
delete(jtag);
return EXIT_FAILURE;
}
idcode = listDev[index];
} }
} else { } else {
printError("Error: no device found"); printError("Error: no device found");
@ -296,6 +308,9 @@ int main(int argc, char **argv)
jtag->device_select(index); jtag->device_select(index);
/* check if selected device is supported
* mainly used in conjunction with --index-chain
*/
if (fpga_list.find(idcode) == fpga_list.end()) { if (fpga_list.find(idcode) == fpga_list.end()) {
cerr << "Error: device " << hex << idcode << " not supported" << endl; cerr << "Error: device " << hex << idcode << " not supported" << endl;
delete(jtag); delete(jtag);
@ -413,6 +428,8 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p
("freq", "jtag frequency (Hz)", cxxopts::value<string>(freqo)) ("freq", "jtag frequency (Hz)", cxxopts::value<string>(freqo))
("f,write-flash", ("f,write-flash",
"write bitstream in flash (default: false, only for Gowin and ECP5 devices)") "write bitstream in flash (default: false, only for Gowin and ECP5 devices)")
("index-chain", "device index in JTAG-chain",
cxxopts::value<int>(args->index_chain))
("list-boards", "list all supported boards", ("list-boards", "list all supported boards",
cxxopts::value<bool>(args->list_boards)) cxxopts::value<bool>(args->list_boards))
("list-cables", "list all supported cables", ("list-cables", "list all supported cables",