mirror of
https://github.com/trabucayre/openFPGALoader.git
synced 2026-08-31 02:07:14 +02:00
all/everything/world: removed using namespace std to be able to compile in c++17 with windows
This commit is contained in:
+81
-82
@@ -69,23 +69,22 @@
|
||||
|
||||
#define DEFAULT_FREQ 6000000
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct arguments {
|
||||
int8_t verbose;
|
||||
bool force_terminal_mode;
|
||||
bool reset, detect, detect_flash, verify, scan_usb;
|
||||
unsigned int offset;
|
||||
string bit_file;
|
||||
string secondary_bit_file;
|
||||
string device;
|
||||
string cable;
|
||||
string ftdi_serial;
|
||||
std::string bit_file;
|
||||
std::string secondary_bit_file;
|
||||
std::string device;
|
||||
std::string cable;
|
||||
std::string ftdi_serial;
|
||||
int ftdi_channel;
|
||||
int status_pin;
|
||||
uint32_t freq;
|
||||
bool invert_read_edge;
|
||||
string board;
|
||||
std::string board;
|
||||
bool pin_config;
|
||||
bool list_cables;
|
||||
bool list_boards;
|
||||
@@ -94,13 +93,13 @@ struct arguments {
|
||||
bool is_list_command;
|
||||
bool spi;
|
||||
bool dfu;
|
||||
string file_type;
|
||||
string fpga_part;
|
||||
string bridge_path;
|
||||
string probe_firmware;
|
||||
std::string file_type;
|
||||
std::string fpga_part;
|
||||
std::string bridge_path;
|
||||
std::string probe_firmware;
|
||||
int index_chain;
|
||||
unsigned int file_size;
|
||||
string target_flash;
|
||||
std::string target_flash;
|
||||
bool external_flash;
|
||||
bool spi_flash_type;
|
||||
int16_t altsetting;
|
||||
@@ -109,26 +108,26 @@ struct arguments {
|
||||
int16_t cable_index;
|
||||
uint8_t bus_addr;
|
||||
uint8_t device_addr;
|
||||
string ip_adr;
|
||||
std::string ip_adr;
|
||||
uint32_t protect_flash;
|
||||
bool unprotect_flash;
|
||||
bool enable_quad;
|
||||
bool disable_quad;
|
||||
bool bulk_erase_flash;
|
||||
string flash_sector;
|
||||
std::string flash_sector;
|
||||
bool skip_load_bridge;
|
||||
bool skip_reset;
|
||||
/* xvc server */
|
||||
bool xvc;
|
||||
int port;
|
||||
string interface;
|
||||
string mcufw;
|
||||
std::string interface;
|
||||
std::string mcufw;
|
||||
bool conmcu;
|
||||
std::map<uint32_t, misc_device> user_misc_devs;
|
||||
bool read_dna;
|
||||
bool read_xadc;
|
||||
string read_register;
|
||||
string user_flash;
|
||||
std::string read_register;
|
||||
std::string user_flash;
|
||||
};
|
||||
|
||||
int run_xvc_server(const struct arguments &args, const cable_t &cable,
|
||||
@@ -185,9 +184,9 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (args.prg_type == Device::WR_SRAM)
|
||||
cout << "write to ram" << endl;
|
||||
std::cout << "write to ram" << std::endl;
|
||||
if (args.prg_type == Device::WR_FLASH)
|
||||
cout << "write to flash" << endl;
|
||||
std::cout << "write to flash" << std::endl;
|
||||
|
||||
if (args.board[0] != '-') {
|
||||
if (board_list.find(args.board) != board_list.end()) {
|
||||
@@ -215,7 +214,7 @@ int main(int argc, char **argv)
|
||||
if (args.cable[0] == '-') { // no user selection
|
||||
args.cable = (*t).first; // use board default cable
|
||||
} else {
|
||||
cout << "Board default cable overridden with " << args.cable << endl;
|
||||
std::cout << "Board default cable overridden with " << args.cable << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +341,7 @@ int main(int argc, char **argv)
|
||||
dfu = new DFU(args.bit_file, args.detect, vid, pid, altsetting,
|
||||
args.verbose);
|
||||
} catch (std::exception &e) {
|
||||
printError("DFU init failed with: " + string(e.what()));
|
||||
printError("DFU init failed with: " + std::string(e.what()));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/* if verbose or detect: display device */
|
||||
@@ -356,7 +355,7 @@ int main(int argc, char **argv)
|
||||
try {
|
||||
dfu->download();
|
||||
} catch (std::exception &e) {
|
||||
printError("DFU download failed with: " + string(e.what()));
|
||||
printError("DFU download failed with: " + std::string(e.what()));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -394,18 +393,18 @@ int main(int argc, char **argv)
|
||||
args.invert_read_edge, args.probe_firmware,
|
||||
args.user_misc_devs);
|
||||
} catch (std::exception &e) {
|
||||
printError("JTAG init failed with: " + string(e.what()));
|
||||
printError("JTAG init failed with: " + std::string(e.what()));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
/* chain detection */
|
||||
vector<uint32_t> listDev = jtag->get_devices_list();
|
||||
std::vector<uint32_t> listDev = jtag->get_devices_list();
|
||||
size_t found = listDev.size();
|
||||
int idcode = -1;
|
||||
size_t index = 0;
|
||||
|
||||
if (args.verbose > 0)
|
||||
cout << "found " << std::to_string(found) << " devices" << endl;
|
||||
std::cout << "found " << std::to_string(found) << " devices" << std::endl;
|
||||
|
||||
/* in verbose mode or when detect
|
||||
* display full chain with details
|
||||
@@ -475,7 +474,7 @@ int main(int argc, char **argv)
|
||||
|
||||
/* detect svf file and program the device */
|
||||
if (!args.file_type.compare("svf") ||
|
||||
args.bit_file.find(".svf") != string::npos) {
|
||||
args.bit_file.find(".svf") != std::string::npos) {
|
||||
#ifdef ENABLE_SVF_JTAG
|
||||
SVF_jtag *svf = new SVF_jtag(jtag, args.verbose);
|
||||
try {
|
||||
@@ -495,12 +494,12 @@ int main(int argc, char **argv)
|
||||
* mainly used in conjunction with --index-chain
|
||||
*/
|
||||
if (fpga_list.find(idcode) == fpga_list.end()) {
|
||||
cerr << "Error: device " << hex << idcode << " not supported" << endl;
|
||||
std::cerr << "Error: device " << std::hex << idcode << " not supported" << std::endl;
|
||||
delete(jtag);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
string fab = fpga_list[idcode].manufacturer;
|
||||
std::string fab = fpga_list[idcode].manufacturer;
|
||||
|
||||
|
||||
Device *fpga;
|
||||
@@ -578,7 +577,7 @@ int main(int argc, char **argv)
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} catch (std::exception &e) {
|
||||
printError("Error: Failed to claim FPGA device: " + string(e.what()));
|
||||
printError("Error: Failed to claim FPGA device: " + std::string(e.what()));
|
||||
delete(jtag);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -590,7 +589,7 @@ int main(int argc, char **argv)
|
||||
try {
|
||||
fpga->program(args.offset, args.unprotect_flash);
|
||||
} catch (std::exception &e) {
|
||||
printError("Error: Failed to program FPGA: " + string(e.what()));
|
||||
printError("Error: Failed to program FPGA: " + std::string(e.what()));
|
||||
delete(fpga);
|
||||
delete(jtag);
|
||||
return EXIT_FAILURE;
|
||||
@@ -677,7 +676,7 @@ int run_xvc_server(const struct arguments &args, const cable_t &cable,
|
||||
xvc->close_connection();
|
||||
delete xvc;
|
||||
} catch (std::exception &e) {
|
||||
printError("XVC_server failed with " + string(e.what()));
|
||||
printError("XVC_server failed with " + std::string(e.what()));
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printInfo("Xilinx Virtual Cable Stopped! ");
|
||||
@@ -821,7 +820,7 @@ int spi_comm(struct arguments args, const cable_t &cable,
|
||||
try {
|
||||
flash.erase_and_prog(args.offset, bit->getData(), bit->getLength()/8);
|
||||
} catch (std::exception &e) {
|
||||
printError("FAIL: " + string(e.what()));
|
||||
printError("FAIL: " + std::string(e.what()));
|
||||
}
|
||||
|
||||
if (args.verify)
|
||||
@@ -857,7 +856,7 @@ int spi_comm(struct arguments args, const cable_t &cable,
|
||||
|
||||
// parse double from string in engineering notation
|
||||
// can deal with postfixes k and m, add more when required
|
||||
static int parse_eng(string arg, double *dst) {
|
||||
static int parse_eng(std::string arg, double *dst) {
|
||||
try {
|
||||
size_t end;
|
||||
double base = stod(arg, &end);
|
||||
@@ -879,7 +878,7 @@ static int parse_eng(string arg, double *dst) {
|
||||
return EINVAL;
|
||||
}
|
||||
} catch (...) {
|
||||
cerr << "error : speed: invalid format" << endl;
|
||||
std::cerr << "error : speed: invalid format" << std::endl;
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
@@ -888,8 +887,8 @@ static int parse_eng(string arg, double *dst) {
|
||||
int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
jtag_pins_conf_t *pins_config)
|
||||
{
|
||||
string freqo;
|
||||
vector<string> pins, bus_dev_num;
|
||||
std::string freqo;
|
||||
std::vector<std::string> pins, bus_dev_num;
|
||||
bool verbose = false, quiet = false;
|
||||
int8_t verbose_level = -2;
|
||||
try {
|
||||
@@ -909,11 +908,11 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
" UltraScale boards)",
|
||||
cxxopts::value<std::string>(args->secondary_bit_file))
|
||||
("b,board", "board name, may be used instead of cable",
|
||||
cxxopts::value<string>(args->board))
|
||||
cxxopts::value<std::string>(args->board))
|
||||
("B,bridge", "disable spiOverJtag model detection by providing "
|
||||
"bitstream(intel/xilinx)",
|
||||
cxxopts::value<string>(args->bridge_path))
|
||||
("c,cable", "jtag interface", cxxopts::value<string>(args->cable))
|
||||
cxxopts::value<std::string>(args->bridge_path))
|
||||
("c,cable", "jtag interface", cxxopts::value<std::string>(args->cable))
|
||||
("status-pin",
|
||||
"JTAG mode / FTDI: GPIO pin number to use as a status indicator (active low)",
|
||||
cxxopts::value<int>(args->status_pin))
|
||||
@@ -926,15 +925,15 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
cxxopts::value<int16_t>(args->cable_index))
|
||||
("busdev-num",
|
||||
"select a probe by it bus and device number (bus_num:device_addr)",
|
||||
cxxopts::value<vector<string>>(bus_dev_num))
|
||||
cxxopts::value<std::vector<std::string>>(bus_dev_num))
|
||||
("ftdi-serial", "FTDI chip serial number",
|
||||
cxxopts::value<string>(args->ftdi_serial))
|
||||
cxxopts::value<std::string>(args->ftdi_serial))
|
||||
("ftdi-channel",
|
||||
"FTDI chip channel number (channels 0-3 map to A-D)",
|
||||
cxxopts::value<int>(args->ftdi_channel))
|
||||
#if defined(USE_DEVICE_ARG)
|
||||
("d,device", "device to use (/dev/ttyUSBx)",
|
||||
cxxopts::value<string>(args->device))
|
||||
cxxopts::value<std::string>(args->device))
|
||||
#endif
|
||||
("detect", "detect FPGA, add -f to show connected flash",
|
||||
cxxopts::value<bool>(args->detect))
|
||||
@@ -949,7 +948,7 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
("target-flash",
|
||||
"for boards with multiple flash chips (some Xilinx UltraScale"
|
||||
" boards), select the target flash: primary (default), secondary or both",
|
||||
cxxopts::value<string>(args->target_flash))
|
||||
cxxopts::value<std::string>(args->target_flash))
|
||||
("external-flash",
|
||||
"select ext flash for device with internal and external storage",
|
||||
cxxopts::value<bool>(args->external_flash))
|
||||
@@ -958,20 +957,20 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
cxxopts::value<unsigned int>(args->file_size))
|
||||
("file-type",
|
||||
"provides file type instead of let's deduced by using extension",
|
||||
cxxopts::value<string>(args->file_type))
|
||||
cxxopts::value<std::string>(args->file_type))
|
||||
("flash-sector", "flash sector (Lattice and Altera MAX10 parts only)",
|
||||
cxxopts::value<string>(args->flash_sector))
|
||||
cxxopts::value<std::string>(args->flash_sector))
|
||||
("fpga-part", "fpga model flavor + package",
|
||||
cxxopts::value<string>(args->fpga_part))
|
||||
("freq", "jtag frequency (Hz)", cxxopts::value<string>(freqo))
|
||||
cxxopts::value<std::string>(args->fpga_part))
|
||||
("freq", "jtag frequency (Hz)", cxxopts::value<std::string>(freqo))
|
||||
("f,write-flash",
|
||||
"write bitstream in flash (default: false)")
|
||||
("index-chain", "device index in JTAG-chain",
|
||||
cxxopts::value<int>(args->index_chain))
|
||||
("misc-device", "add JTAG non-FPGA devices <idcode,irlen,name>",
|
||||
cxxopts::value<vector<string>>())
|
||||
cxxopts::value<std::vector<std::string>>())
|
||||
("ip", "IP address (XVC and remote bitbang client)",
|
||||
cxxopts::value<string>(args->ip_adr))
|
||||
cxxopts::value<std::string>(args->ip_adr))
|
||||
("list-boards", "list all supported boards",
|
||||
cxxopts::value<bool>(args->list_boards))
|
||||
("list-cables", "list all supported cables",
|
||||
@@ -983,9 +982,9 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
("o,offset", "Start address (in bytes) for read/write into non volatile memory (default: 0)",
|
||||
cxxopts::value<unsigned int>(args->offset))
|
||||
("pins", "pin config TDI:TDO:TCK:TMS or MOSI:MISO:SCK:CS[:HOLDN:WPN]",
|
||||
cxxopts::value<vector<string>>(pins))
|
||||
cxxopts::value<std::vector<std::string>>(pins))
|
||||
("probe-firmware", "firmware for JTAG probe (usbBlasterII)",
|
||||
cxxopts::value<string>(args->probe_firmware))
|
||||
cxxopts::value<std::string>(args->probe_firmware))
|
||||
("protect-flash", "protect SPI flash area",
|
||||
cxxopts::value<uint32_t>(args->protect_flash))
|
||||
("quiet", "Produce quiet output (no progress bar)",
|
||||
@@ -1026,16 +1025,16 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
("X,read-xadc", "Read XADC (Xilinx FPGA only)",
|
||||
cxxopts::value<bool>(args->read_xadc))
|
||||
("read-register", "Read Status Register(Xilinx FPGA only)",
|
||||
cxxopts::value<string>(args->read_register))
|
||||
cxxopts::value<std::string>(args->read_register))
|
||||
("user-flash", "User flash file (Gowin LittleBee FPGA only)",
|
||||
cxxopts::value<string>(args->user_flash))
|
||||
cxxopts::value<std::string>(args->user_flash))
|
||||
("V,Version", "Print program version");
|
||||
|
||||
options.parse_positional({"bitstream"});
|
||||
auto result = options.parse(argc, argv);
|
||||
|
||||
if (result.count("help")) {
|
||||
cout << options.help() << endl;
|
||||
std::cout << options.help() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1058,7 +1057,7 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
}
|
||||
|
||||
if (result.count("Version")) {
|
||||
cout << "openFPGALoader " << VERSION << endl;
|
||||
std::cout << "openFPGALoader " << VERSION << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1202,7 +1201,7 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
!args->detect
|
||||
) {
|
||||
printError("Error: secondary bitfile not specified");
|
||||
cout << options.help() << endl;
|
||||
std::cout << options.help() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -1235,7 +1234,7 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
!args->read_xadc &&
|
||||
args->read_register.empty()) {
|
||||
printError("Error: bitfile not specified");
|
||||
cout << options.help() << endl;
|
||||
std::cout << options.help() << std::endl;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1247,7 +1246,7 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
args->detect_flash = true;
|
||||
}
|
||||
} catch (const cxxopts::OptionException& e) {
|
||||
printError("Error parsing options: " + string(e.what()));
|
||||
printError("Error parsing options: " + std::string(e.what()));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1258,27 +1257,27 @@ int parse_opt(int argc, char **argv, struct arguments *args,
|
||||
void displaySupported(const struct arguments &args)
|
||||
{
|
||||
if (args.list_cables == true) {
|
||||
stringstream t;
|
||||
t << setw(25) << left << "cable name" << "vid:pid";
|
||||
std::stringstream t;
|
||||
t << std::setw(25) << std::left << "cable name" << "vid:pid";
|
||||
printSuccess(t.str());
|
||||
for (auto b = cable_list.begin(); b != cable_list.end(); b++) {
|
||||
cable_t c = (*b).second;
|
||||
stringstream ss;
|
||||
ss << setw(25) << left << (*b).first;
|
||||
ss << "0x" << hex << right << setw(4) << setfill('0') << c.vid
|
||||
<< ":" << setw(4) << c.pid;
|
||||
std::stringstream ss;
|
||||
ss << std::setw(25) << std::left << (*b).first;
|
||||
ss << "0x" << std::hex << std::right << std::setw(4) << std::setfill('0') << c.vid
|
||||
<< ":" << std::setw(4) << c.pid;
|
||||
printInfo(ss.str());
|
||||
}
|
||||
cout << endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
if (args.list_boards) {
|
||||
stringstream t;
|
||||
t << setw(27) << left << "board name" << setw(19) << "cable_name";
|
||||
t << setw(25) << "fpga_part";
|
||||
std::stringstream t;
|
||||
t << std::setw(27) << std::left << "board name" << std::setw(19) << "cable_name";
|
||||
t << std::setw(25) << "fpga_part";
|
||||
printSuccess(t.str());
|
||||
for (auto b = board_list.begin(); b != board_list.end(); b++) {
|
||||
stringstream ss;
|
||||
std::stringstream ss;
|
||||
target_board_t c = (*b).second;
|
||||
std::string cable_name = c.cable_name;
|
||||
std::string fpga_part = c.fpga_part;
|
||||
@@ -1286,28 +1285,28 @@ void displaySupported(const struct arguments &args)
|
||||
cable_name = "Undefined";
|
||||
if (fpga_part.size() == 0)
|
||||
fpga_part = "Undefined";
|
||||
ss << setw(27) << left << (*b).first << setw(19) << cable_name;
|
||||
ss << setw(25)<< fpga_part;
|
||||
ss << std::setw(27) << std::left << (*b).first << std::setw(19) << cable_name;
|
||||
ss << std::setw(25)<< fpga_part;
|
||||
printInfo(ss.str());
|
||||
}
|
||||
cout << endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
if (args.list_fpga) {
|
||||
stringstream t;
|
||||
t << setw(12) << left << "IDCode" << setw(14) << "manufacturer";
|
||||
t << setw(16) << "family" << setw(20) << "model";
|
||||
std::stringstream t;
|
||||
t << std::setw(12) << std::left << "IDCode" << std::setw(14) << "manufacturer";
|
||||
t << std::setw(16) << "family" << std::setw(20) << "model";
|
||||
printSuccess(t.str());
|
||||
for (auto b = fpga_list.begin(); b != fpga_list.end(); b++) {
|
||||
fpga_model fpga = (*b).second;
|
||||
stringstream ss, idCode;
|
||||
idCode << "0x" << hex << setw(8) << setfill('0') << (*b).first;
|
||||
ss << setw(12) << left << idCode.str();
|
||||
ss << setw(14) << fpga.manufacturer << setw(16) << fpga.family;
|
||||
ss << setw(20) << fpga.model;
|
||||
std::stringstream ss, idCode;
|
||||
idCode << "0x" << std::hex << std::setw(8) << std::setfill('0') << (*b).first;
|
||||
ss << std::setw(12) << std::left << idCode.str();
|
||||
ss << std::setw(14) << fpga.manufacturer << std::setw(16) << fpga.family;
|
||||
ss << std::setw(20) << fpga.model;
|
||||
printInfo(ss.str());
|
||||
}
|
||||
cout << endl;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
#ifdef ENABLE_USB_SCAN
|
||||
|
||||
Reference in New Issue
Block a user