9 int main(
int argc,
char** argv) {
11 std::cout <<
"Usage: " << argv[0] <<
" [GPIO_MODE/USB_RECOVERY/NORMAL/FAST] [params]" << std::endl;
12 std::cout <<
"\tOptions:\n";
13 std::cout <<
"\t\t" << argv[0] <<
" GPIO_MODE gpioModeNum" << std::endl;
14 std::cout <<
"\t\t" << argv[0] <<
" USB_RECOVERY" << std::endl;
15 std::cout <<
"\t\t" << argv[0] <<
" NORMAL [frequency] [location] [dummyCycles] [offset]" << std::endl;
16 std::cout <<
"\t\t" << argv[0] <<
" FAST [frequency] [location] [dummyCycles] [offset]" << std::endl;
19 std::string mode{argv[1]};
23 if(mode ==
"gpio_mode") {
26 std::cout <<
"Usage: " << argv[0] <<
" GPIO_MODE gpioModeNum" << std::endl;
29 int gpioMode = std::stoi(std::string(argv[2]));
31 flash = [gpioMode](
dai::DeviceBootloader& bl) {
return bl.flashGpioModeBootHeader(dai::DeviceBootloader::Memory::FLASH, gpioMode); };
32 }
else if(mode ==
"usb_recovery") {
34 flash = [](
dai::DeviceBootloader& bl) {
return bl.flashUsbRecoveryBootHeader(dai::DeviceBootloader::Memory::FLASH); };
35 }
else if(mode ==
"normal" || mode ==
"fast") {
36 if(argc != 2 && argc != 3 && argc <= 3) {
37 std::cout <<
"Usage: " << argv[0] <<
" NORMAL/FAST [frequency] [location] [dummyCycles] [offset]" << std::endl;
38 std::cout <<
"Usage: " << argv[0] <<
" NORMAL/FAST [frequency]" << std::endl;
42 int64_t location = -1;
43 int32_t dummyCycles = -1;
44 int32_t frequency = -1;
47 offset = std::stoi(std::string(argv[2]));
50 location = std::stoi(std::string(argv[3]));
53 dummyCycles = std::stoi(std::string(argv[4]));
56 frequency = std::stoi(std::string(argv[5]));
58 }
else if(argc == 3) {
59 frequency = std::stoi(std::string(argv[2]));
62 if(mode ==
"normal") {
64 return bl.flashBootHeader(dai::DeviceBootloader::Memory::FLASH, frequency, location, dummyCycles, offset);
66 }
else if(mode ==
"fast") {
68 return bl.flashFastBootHeader(dai::DeviceBootloader::Memory::FLASH, frequency, location, dummyCycles, offset);
79 std::cout <<
"Found device with name: " <<
info.name << std::endl;
85 std::tie(success, errorMsg) = flash(bl);
87 std::cout <<
"Successfully flashed boot header!" << std::endl;
89 std::cout <<
"Couldn't flash boot header: " << errorMsg << std::endl;
92 std::cout <<
"Invalid boot option header specified" << std::endl;
95 std::cout <<
"No devices found" << std::endl;