DFU: fix detect -> bypass bitstream
This commit is contained in:
parent
e278b87a64
commit
e21a251af3
74
src/dfu.cpp
74
src/dfu.cpp
|
|
@ -46,8 +46,8 @@ enum dfu_cmd {
|
||||||
* - index as jtag chain (fix issue when more than one device connected)
|
* - index as jtag chain (fix issue when more than one device connected)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DFU::DFU(const string &filename, uint16_t vid, uint16_t pid,
|
DFU::DFU(const string &filename, bool bypass_bitstream,
|
||||||
int16_t altsetting,
|
uint16_t vid, uint16_t pid, int16_t altsetting,
|
||||||
int verbose_lvl):_verbose(verbose_lvl > 0), _debug(verbose_lvl > 1),
|
int verbose_lvl):_verbose(verbose_lvl > 0), _debug(verbose_lvl > 1),
|
||||||
_quiet(verbose_lvl < 0), dev_idx(0), _vid(0), _pid(0),
|
_quiet(verbose_lvl < 0), dev_idx(0), _vid(0), _pid(0),
|
||||||
_altsetting(altsetting),
|
_altsetting(altsetting),
|
||||||
|
|
@ -57,36 +57,41 @@ DFU::DFU(const string &filename, uint16_t vid, uint16_t pid,
|
||||||
struct dfu_status status;
|
struct dfu_status status;
|
||||||
int dfu_vid = 0, dfu_pid = 0;
|
int dfu_vid = 0, dfu_pid = 0;
|
||||||
|
|
||||||
printInfo("Open file ", false);
|
printInfo("Open file : ", false);
|
||||||
|
|
||||||
try {
|
if (bypass_bitstream) {
|
||||||
_bit = new DFUFileParser(filename, _verbose > 0);
|
_bit = nullptr;
|
||||||
printSuccess("DONE");
|
printInfo("bypassed");
|
||||||
} catch (std::exception &e) {
|
} else {
|
||||||
printError("FAIL");
|
try {
|
||||||
throw runtime_error("Error: Fail to open file");
|
_bit = new DFUFileParser(filename, _verbose > 0);
|
||||||
}
|
printSuccess("DONE");
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
printError("FAIL");
|
||||||
|
throw runtime_error("Error: Fail to open file");
|
||||||
|
}
|
||||||
|
|
||||||
printInfo("Parse file ", false);
|
printInfo("Parse file ", false);
|
||||||
try {
|
try {
|
||||||
_bit->parse();
|
_bit->parse();
|
||||||
printSuccess("DONE");
|
printSuccess("DONE");
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
printError("FAIL");
|
printError("FAIL");
|
||||||
delete _bit;
|
delete _bit;
|
||||||
throw runtime_error("Error: Fail to parse file");
|
throw runtime_error("Error: Fail to parse file");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_verbose > 0)
|
if (_verbose > 0)
|
||||||
_bit->displayHeader();
|
_bit->displayHeader();
|
||||||
|
|
||||||
/* get VID and PID from dfu file */
|
/* get VID and PID from dfu file */
|
||||||
try {
|
try {
|
||||||
dfu_vid = std::stoi(_bit->getHeaderVal("idVendor"), 0, 16);
|
dfu_vid = std::stoi(_bit->getHeaderVal("idVendor"), 0, 16);
|
||||||
dfu_pid = std::stoi(_bit->getHeaderVal("idProduct"), 0, 16);
|
dfu_pid = std::stoi(_bit->getHeaderVal("idProduct"), 0, 16);
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
if (_verbose)
|
if (_verbose)
|
||||||
printWarn(e.what());
|
printWarn(e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (libusb_init(&usb_ctx) < 0) {
|
if (libusb_init(&usb_ctx) < 0) {
|
||||||
|
|
@ -128,12 +133,16 @@ DFU::DFU(const string &filename, uint16_t vid, uint16_t pid,
|
||||||
displayDFU();
|
displayDFU();
|
||||||
|
|
||||||
/* don't try device without vid/pid */
|
/* don't try device without vid/pid */
|
||||||
if (_vid == 0 || _pid == 0) {
|
if ((_vid == 0 || _pid == 0) && _bit) {
|
||||||
libusb_exit(usb_ctx);
|
libusb_exit(usb_ctx);
|
||||||
delete _bit;
|
delete _bit;
|
||||||
throw std::runtime_error("Can't open device vid/pid == 0");
|
throw std::runtime_error("Can't open device vid/pid == 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* the If bitstream has been bypassed -> it's the end */
|
||||||
|
if (!_bit)
|
||||||
|
return;
|
||||||
|
|
||||||
/* open the first */
|
/* open the first */
|
||||||
if (open_DFU(0) == EXIT_FAILURE) {
|
if (open_DFU(0) == EXIT_FAILURE) {
|
||||||
libusb_exit(usb_ctx);
|
libusb_exit(usb_ctx);
|
||||||
|
|
@ -154,7 +163,8 @@ DFU::~DFU()
|
||||||
{
|
{
|
||||||
close_DFU();
|
close_DFU();
|
||||||
libusb_exit(usb_ctx);
|
libusb_exit(usb_ctx);
|
||||||
delete _bit;
|
if (_bit)
|
||||||
|
delete _bit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open the device using VID and PID
|
/* open the device using VID and PID
|
||||||
|
|
@ -666,6 +676,10 @@ int DFU::download()
|
||||||
printError("Error: No device. Can't download file");
|
printError("Error: No device. Can't download file");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (!_bit) {
|
||||||
|
printError("Error: No bitstream. Stop");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
int ret, ret_val = EXIT_SUCCESS;
|
int ret, ret_val = EXIT_SUCCESS;
|
||||||
uint8_t *buffer, *ptr;
|
uint8_t *buffer, *ptr;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,8 @@ class DFU {
|
||||||
* \param[in] altsetting: device altsetting to use
|
* \param[in] altsetting: device altsetting to use
|
||||||
* \param[in] verbose_lvl: verbose level 0 normal, -1 quiet, 1 verbose
|
* \param[in] verbose_lvl: verbose level 0 normal, -1 quiet, 1 verbose
|
||||||
*/
|
*/
|
||||||
DFU(const std::string &filename, uint16_t vid, uint16_t pid,
|
DFU(const std::string &filename, bool bypass_bitstream,
|
||||||
|
uint16_t vid, uint16_t pid,
|
||||||
int16_t altsetting, int verbose_lvl);
|
int16_t altsetting, int verbose_lvl);
|
||||||
|
|
||||||
~DFU();
|
~DFU();
|
||||||
|
|
|
||||||
|
|
@ -346,7 +346,8 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dfu = new DFU(args.bit_file, vid, pid, altsetting, args.verbose);
|
dfu = new DFU(args.bit_file, args.detect, vid, pid, altsetting,
|
||||||
|
args.verbose);
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
printError("DFU init failed with: " + string(e.what()));
|
printError("DFU init failed with: " + string(e.what()));
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue