From d5e696b5c33d9946d42a3bd56f6851728ccbb932 Mon Sep 17 00:00:00 2001 From: Gwenhael Goavec-Merou Date: Sat, 22 Feb 2020 20:55:51 +0100 Subject: [PATCH] add --detect option to display wich FPGA --- README.md | 1 + src/main.cpp | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 73ab0e9..068b36a 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ openFPGALoader -- a program to flash cyclone10 LP FPGA -b, --board=BOARD board name, may be used instead of cable -c, --cable=CABLE jtag interface -d, --device=DEVICE device to use (/dev/ttyUSBx) + --detect detect FPGA -f, --write-flash write bitstream in flash (default: false, only for Gowin devices) --list-boards list all supported boards diff --git a/src/main.cpp b/src/main.cpp index f24680f..4a35abb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -38,7 +38,7 @@ using namespace std; struct arguments { - bool verbose, reset; + bool verbose, reset, detect; unsigned int offset; string bit_file; string device; @@ -55,6 +55,7 @@ struct arguments { #define LIST_CABLE 1 #define LIST_BOARD 2 #define LIST_FPGA 3 +#define DETECT 4 const char *argp_program_version = "openFPGALoader 1.0"; const char *argp_program_bug_address = ""; @@ -68,6 +69,7 @@ static struct argp_option options[] = { {"list-boards", LIST_BOARD, 0, 0, "list all supported boards"}, {"device", 'd', "DEVICE", 0, "device to use (/dev/ttyUSBx)"}, {"list-fpga", LIST_FPGA, 0, 0, "list all supported FPGA"}, + {"detect", DETECT, 0, 0, "detect FPGA"}, {"write-flash", 'f', 0, 0, "write bitstream in flash (default: false, only for Gowin devices)"}, {"write-sram", 'm', 0, 0, @@ -86,7 +88,7 @@ int main(int argc, char **argv) FTDIpp_MPSSE::mpsse_bit_config cable; /* command line args. */ - struct arguments args = {false, false, 0, "", "-", "-", "-", + struct arguments args = {false, false, false, 0, "", "-", "-", "-", false, false, false, false, true, false}; /* parse arguments */ argp_parse(&argp, argc, argv, 0, 0, &args); @@ -145,13 +147,19 @@ int main(int argc, char **argv) if (fpga_list.find(idcode) == fpga_list.end()) { cerr << "Error: device " << hex << idcode << " not supported" << endl; return 1; - } else if (args.verbose) { + } else if (args.verbose || args.detect) { printf("idcode 0x%x\nmanufacturer %s\nmodel %s\nfamily %s\n", idcode, fpga_list[idcode].manufacturer.c_str(), fpga_list[idcode].model.c_str(), fpga_list[idcode].family.c_str()); } + + if (args.detect == true) { + delete jtag; + return EXIT_SUCCESS; + } + string fab = fpga_list[idcode].manufacturer; Device *fpga; @@ -224,6 +232,7 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) case ARGP_KEY_END: if (arguments->bit_file.empty() && !arguments->is_list_command && + !arguments->detect && !arguments->reset) { cout << "Error: bitfile not specified" << endl; argp_usage(state); @@ -241,6 +250,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) arguments->list_fpga = true; arguments->is_list_command = true; break; + case DETECT: + arguments->detect = true; + break; default: return ARGP_ERR_UNKNOWN; }