Skip to content

Commit 2cf51b9

Browse files
committed
Exposed fw version and device id and added checksum check capability when flashing
1 parent 245fb57 commit 2cf51b9

File tree

4 files changed

+29
-21
lines changed

4 files changed

+29
-21
lines changed

cmake/Depthai/DepthaiDeviceSideConfig.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot")
33

44
# "full commit hash of device side binary"
5-
set(DEPTHAI_DEVICE_SIDE_COMMIT "31be3c3f138f11050b6a3d6ab6ad7f686f86e18f")
5+
set(DEPTHAI_DEVICE_SIDE_COMMIT "2d804ddd22b8f22f4067ce22772c930417aec6c1")
66

77
# "version if applicable"
88
set(DEPTHAI_DEVICE_SIDE_VERSION "")

examples/Script/script_json_communication.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ int main() {
2929
# Change initial dictionary a bit
3030
dict['one'] += 1
3131
dict['foo'] = "baz"
32+
dict['fw_version'] = __version__
33+
dict['device_id'] = __device_id__
3234
33-
b = Buffer(30)
35+
b = Buffer(256)
3436
b.setData(json.dumps(dict).encode('utf-8'))
3537
node.io['out'].send(b)
3638
)");

include/depthai/device/DeviceBootloader.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class DeviceBootloader {
155155
static std::vector<uint8_t> createDepthaiApplicationPackage(const Pipeline& pipeline,
156156
const dai::Path& pathToCmd = {},
157157
bool compress = false,
158-
std::string applicationName = "");
158+
std::string applicationName = "", bool checkChecksum = false);
159159

160160
/**
161161
* Creates application package which can be flashed to depthai device.
@@ -164,7 +164,7 @@ class DeviceBootloader {
164164
* @param applicationName Name the application that is flashed
165165
* @returns Depthai application package
166166
*/
167-
static std::vector<uint8_t> createDepthaiApplicationPackage(const Pipeline& pipeline, bool compress, std::string applicationName = "");
167+
static std::vector<uint8_t> createDepthaiApplicationPackage(const Pipeline& pipeline, bool compress, std::string applicationName = "", bool checkChecksum = false);
168168

169169
/**
170170
* Saves application package to a file which can be flashed to depthai device.
@@ -175,7 +175,7 @@ class DeviceBootloader {
175175
* @param applicationName Optional name the application that is flashed
176176
*/
177177
static void saveDepthaiApplicationPackage(
178-
const dai::Path& path, const Pipeline& pipeline, const dai::Path& pathToCmd = {}, bool compress = false, std::string applicationName = "");
178+
const dai::Path& path, const Pipeline& pipeline, const dai::Path& pathToCmd = {}, bool compress = false, std::string applicationName = "", bool checkChecksum = false);
179179

180180
/**
181181
* Saves application package to a file which can be flashed to depthai device.
@@ -184,7 +184,7 @@ class DeviceBootloader {
184184
* @param compress Specifies if contents should be compressed
185185
* @param applicationName Optional name the application that is flashed
186186
*/
187-
static void saveDepthaiApplicationPackage(const dai::Path& path, const Pipeline& pipeline, bool compress, std::string applicationName = "");
187+
static void saveDepthaiApplicationPackage(const dai::Path& path, const Pipeline& pipeline, bool compress, std::string applicationName = "", bool checkChecksum = false);
188188

189189
/**
190190
* @returns Embedded bootloader version
@@ -246,15 +246,16 @@ class DeviceBootloader {
246246
const Pipeline& pipeline,
247247
bool compress = false,
248248
std::string applicationName = "",
249-
Memory memory = Memory::AUTO);
249+
Memory memory = Memory::AUTO,
250+
bool checkChecksum = false);
250251

251252
/**
252253
* Flashes a given pipeline to the device.
253254
* @param pipeline Pipeline to flash to the board
254255
* @param compress Compresses application to reduce needed memory size
255256
* @param applicationName Optional name the application that is flashed
256257
*/
257-
std::tuple<bool, std::string> flash(const Pipeline& pipeline, bool compress = false, std::string applicationName = "", Memory memory = Memory::AUTO);
258+
std::tuple<bool, std::string> flash(const Pipeline& pipeline, bool compress = false, std::string applicationName = "", Memory memory = Memory::AUTO, bool checkChecksum = false);
258259

259260
/**
260261
* Reads information about flashed application in specified memory from device

src/device/DeviceBootloader.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ std::vector<DeviceInfo> DeviceBootloader::getAllAvailableDevices() {
7070
std::vector<uint8_t> DeviceBootloader::createDepthaiApplicationPackage(const Pipeline& pipeline,
7171
const dai::Path& pathToCmd,
7272
bool compress,
73-
std::string applicationName) {
73+
std::string applicationName, bool checkChecksum) {
7474
// Serialize the pipeline
7575
PipelineSchema schema;
7676
Assets assets;
@@ -158,8 +158,13 @@ std::vector<uint8_t> DeviceBootloader::createDepthaiApplicationPackage(const Pip
158158
sbr_section_set_size(fwSection, static_cast<uint32_t>(deviceFirmware.size()));
159159
sbr_section_set_checksum(fwSection, sbr_compute_checksum(deviceFirmware.data(), static_cast<uint32_t>(deviceFirmware.size())));
160160
sbr_section_set_offset(fwSection, SBR_RAW_SIZE);
161-
// Ignore checksum to allow faster booting (images are verified after flashing, low risk)
162-
sbr_section_set_ignore_checksum(fwSection, true);
161+
if(checkChecksum) {
162+
// Don't ignore checksum, use it when booting
163+
sbr_section_set_ignore_checksum(fwSection, false);
164+
} else {
165+
// Ignore checksum to allow faster booting (images are verified after flashing, low risk)
166+
sbr_section_set_ignore_checksum(fwSection, true);
167+
}
163168
// Set compression flags
164169
if(compress) {
165170
sbr_section_set_compression(fwSection, SBR_COMPRESSION_ZLIB);
@@ -226,19 +231,19 @@ std::vector<uint8_t> DeviceBootloader::createDepthaiApplicationPackage(const Pip
226231
return fwPackage;
227232
}
228233

229-
std::vector<uint8_t> DeviceBootloader::createDepthaiApplicationPackage(const Pipeline& pipeline, bool compress, std::string applicationName) {
230-
return createDepthaiApplicationPackage(pipeline, "", compress, applicationName);
234+
std::vector<uint8_t> DeviceBootloader::createDepthaiApplicationPackage(const Pipeline& pipeline, bool compress, std::string applicationName, bool checkChecksum) {
235+
return createDepthaiApplicationPackage(pipeline, "", compress, applicationName, checkChecksum);
231236
}
232237

233238
void DeviceBootloader::saveDepthaiApplicationPackage(
234-
const dai::Path& path, const Pipeline& pipeline, const dai::Path& pathToCmd, bool compress, std::string applicationName) {
235-
auto dap = createDepthaiApplicationPackage(pipeline, pathToCmd, compress, applicationName);
239+
const dai::Path& path, const Pipeline& pipeline, const dai::Path& pathToCmd, bool compress, std::string applicationName, bool checkChecksum) {
240+
auto dap = createDepthaiApplicationPackage(pipeline, pathToCmd, compress, applicationName, checkChecksum);
236241
std::ofstream outfile(path, std::ios::binary);
237242
outfile.write(reinterpret_cast<const char*>(dap.data()), dap.size());
238243
}
239244

240-
void DeviceBootloader::saveDepthaiApplicationPackage(const dai::Path& path, const Pipeline& pipeline, bool compress, std::string applicationName) {
241-
auto dap = createDepthaiApplicationPackage(pipeline, compress, applicationName);
245+
void DeviceBootloader::saveDepthaiApplicationPackage(const dai::Path& path, const Pipeline& pipeline, bool compress, std::string applicationName, bool checkChecksum) {
246+
auto dap = createDepthaiApplicationPackage(pipeline, compress, applicationName, checkChecksum);
242247
std::ofstream outfile(path, std::ios::binary);
243248
outfile.write(reinterpret_cast<const char*>(dap.data()), dap.size());
244249
}
@@ -560,12 +565,12 @@ bool DeviceBootloader::isAllowedFlashingBootloader() const {
560565
}
561566

562567
std::tuple<bool, std::string> DeviceBootloader::flash(
563-
std::function<void(float)> progressCb, const Pipeline& pipeline, bool compress, std::string applicationName, Memory memory) {
564-
return flashDepthaiApplicationPackage(progressCb, createDepthaiApplicationPackage(pipeline, compress, applicationName), memory);
568+
std::function<void(float)> progressCb, const Pipeline& pipeline, bool compress, std::string applicationName, Memory memory, bool checkCheksum) {
569+
return flashDepthaiApplicationPackage(progressCb, createDepthaiApplicationPackage(pipeline, compress, applicationName, checkCheksum), memory);
565570
}
566571

567-
std::tuple<bool, std::string> DeviceBootloader::flash(const Pipeline& pipeline, bool compress, std::string applicationName, Memory memory) {
568-
return flashDepthaiApplicationPackage(createDepthaiApplicationPackage(pipeline, compress, applicationName), memory);
572+
std::tuple<bool, std::string> DeviceBootloader::flash(const Pipeline& pipeline, bool compress, std::string applicationName, Memory memory, bool checkCheksum) {
573+
return flashDepthaiApplicationPackage(createDepthaiApplicationPackage(pipeline, compress, applicationName, checkCheksum), memory);
569574
}
570575

571576
DeviceBootloader::ApplicationInfo DeviceBootloader::readApplicationInfo(Memory mem) {

0 commit comments

Comments
 (0)