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

@ -167,14 +167,17 @@ openFPGALoader -- a program to flash FPGA
-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
A-D)
-d, --device arg device to use (/dev/ttyUSBx) -d, --device arg device to use (/dev/ttyUSBx)
--detect detect FPGA --detect detect FPGA
--file-type arg provides file type instead of let's deduced by --file-type arg provides file type instead of let's deduced by
using extension using extension
--fpga-part arg fpga model flavor + package
--freq arg jtag frequency (Hz) --freq arg jtag frequency (Hz)
-f, --write-flash write bitstream in flash (default: false, only for -f, --write-flash write bitstream in flash (default: false, only
Gowin and ECP5 devices) for Gowin and ECP5 devices)
--index-chain arg device index in JTAG-chain
--list-boards list all supported boards --list-boards list all supported boards
--list-cables list all supported cables --list-cables list all supported cables
--list-fpga list all supported FPGA --list-fpga list all supported FPGA
@ -182,6 +185,7 @@ openFPGALoader -- a program to flash FPGA
Gowin and ECP5 devices) Gowin and ECP5 devices)
-o, --offset arg start offset in EEPROM -o, --offset arg start offset in EEPROM
--pins arg pin config (only for ft232R) TDI:TDO:TCK:TMS --pins arg pin config (only for ft232R) TDI:TDO:TCK:TMS
--probe-firmware arg firmware for JTAG probe (usbBlasterII)
--quiet Produce quiet output (no progress bar) --quiet Produce quiet output (no progress bar)
-r, --reset reset FPGA after operations -r, --reset reset FPGA after operations
--spi SPI mode (only for FTDI in serial mode) --spi SPI mode (only for FTDI in serial mode)

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,11 +275,13 @@ int main(int argc, char **argv)
} }
if (found != 0) { if (found != 0) {
if (args.index_chain == -1) {
for (int i = 0; i < found; i++) { for (int i = 0; i < found; i++) {
if (fpga_list.find(listDev[i]) != fpga_list.end()) { if (fpga_list.find(listDev[i]) != fpga_list.end()) {
index = i; index = i;
if (idcode != -1) { if (idcode != -1) {
printError("Error: currently only one device is supported"); printError("Error: more than one FPGA found");
printError("Use --index-chain to force selection");
for (int i = 0; i < found; i++) for (int i = 0; i < found; i++)
printf("0x%08x\n", listDev[i]); printf("0x%08x\n", listDev[i]);
delete(jtag); delete(jtag);
@ -288,6 +291,15 @@ int main(int argc, char **argv)
} }
} }
} }
} 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");
delete(jtag); delete(jtag);
@ -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",