flash_boot_header.cpp
Go to the documentation of this file.
1 #include <algorithm>
2 #include <cstdint>
3 #include <cstdio>
4 #include <fstream>
5 #include <string>
6 
7 #include "depthai/depthai.hpp"
8 
9 int main(int argc, char** argv) {
10  if(argc < 2) {
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;
17  return 0;
18  }
19  std::string mode{argv[1]};
20  std::transform(mode.begin(), mode.end(), mode.begin(), ::tolower);
21  std::function<std::tuple<bool, std::string>(dai::DeviceBootloader&)> flash = nullptr;
22 
23  if(mode == "gpio_mode") {
24  // gpio mode header
25  if(argc < 3) {
26  std::cout << "Usage: " << argv[0] << " GPIO_MODE gpioModeNum" << std::endl;
27  return 0;
28  }
29  int gpioMode = std::stoi(std::string(argv[2]));
30 
31  flash = [gpioMode](dai::DeviceBootloader& bl) { return bl.flashGpioModeBootHeader(dai::DeviceBootloader::Memory::FLASH, gpioMode); };
32  } else if(mode == "usb_recovery") {
33  // usb recovery header
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;
39  return 0;
40  }
41  int64_t offset = -1;
42  int64_t location = -1;
43  int32_t dummyCycles = -1;
44  int32_t frequency = -1;
45  if(argc > 3) {
46  if(argc >= 3) {
47  offset = std::stoi(std::string(argv[2]));
48  }
49  if(argc >= 4) {
50  location = std::stoi(std::string(argv[3]));
51  }
52  if(argc >= 5) {
53  dummyCycles = std::stoi(std::string(argv[4]));
54  }
55  if(argc >= 6) {
56  frequency = std::stoi(std::string(argv[5]));
57  }
58  } else if(argc == 3) {
59  frequency = std::stoi(std::string(argv[2]));
60  }
61 
62  if(mode == "normal") {
63  flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) {
64  return bl.flashBootHeader(dai::DeviceBootloader::Memory::FLASH, frequency, location, dummyCycles, offset);
65  };
66  } else if(mode == "fast") {
67  flash = [offset, location, dummyCycles, frequency](dai::DeviceBootloader& bl) {
68  return bl.flashFastBootHeader(dai::DeviceBootloader::Memory::FLASH, frequency, location, dummyCycles, offset);
69  };
70  }
71  }
72 
73  // Find device and flash specified boot header
74  bool res = false;
77 
78  if(res) {
79  std::cout << "Found device with name: " << info.name << std::endl;
81  // Flash the specified boot header
82  if(flash) {
83  bool success;
84  std::string errorMsg;
85  std::tie(success, errorMsg) = flash(bl);
86  if(success) {
87  std::cout << "Successfully flashed boot header!" << std::endl;
88  } else {
89  std::cout << "Couldn't flash boot header: " << errorMsg << std::endl;
90  }
91  } else {
92  std::cout << "Invalid boot option header specified" << std::endl;
93  }
94  } else {
95  std::cout << "No devices found" << std::endl;
96  }
97 
98  return 0;
99 }
dai::DeviceBootloader
Definition: DeviceBootloader.hpp:29
dai::DeviceInfo
Definition: XLinkConnection.hpp:27
dai::logger::info
void info(const FormatString &fmt, Args &&...args)
Definition: Logging.hpp:78
depthai.hpp
transform
static void transform(uint32_t digest[], uint32_t block[BLOCK_INTS], uint64_t &transforms)
Definition: sha1.hpp:129
dai::DeviceBootloader::getFirstAvailableDevice
static std::tuple< bool, DeviceInfo > getFirstAvailableDevice()
Definition: DeviceBootloader.cpp:48
main
int main(int argc, char **argv)
Definition: flash_boot_header.cpp:9


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19