diff --git a/cmake/Depthai/DepthaiBootloaderConfig.cmake b/cmake/Depthai/DepthaiBootloaderConfig.cmake index 633e6a4a33..4cae578f49 100644 --- a/cmake/Depthai/DepthaiBootloaderConfig.cmake +++ b/cmake/Depthai/DepthaiBootloaderConfig.cmake @@ -1,5 +1,5 @@ # Maturity level "snapshot" / "release" -set(DEPTHAI_BOOTLOADER_MATURITY "release") +set(DEPTHAI_BOOTLOADER_MATURITY "snapshot") # "version if applicable" -set(DEPTHAI_BOOTLOADER_VERSION "0.0.11") +set(DEPTHAI_BOOTLOADER_VERSION "eb6701e5b053da5609f2c23a915969247603bc6b") diff --git a/cmake/Depthai/DepthaiDeviceSideConfig.cmake b/cmake/Depthai/DepthaiDeviceSideConfig.cmake index 11ef954348..cd06f0bd57 100644 --- a/cmake/Depthai/DepthaiDeviceSideConfig.cmake +++ b/cmake/Depthai/DepthaiDeviceSideConfig.cmake @@ -2,7 +2,7 @@ set(DEPTHAI_DEVICE_SIDE_MATURITY "snapshot") # "full commit hash of device side binary" -set(DEPTHAI_DEVICE_SIDE_COMMIT "b71584129b101b30e4632678c19d33b020c04c36") +set(DEPTHAI_DEVICE_SIDE_COMMIT "7417ecc8b275931ce2eb8635e854ded05a9c3c6d") # "version if applicable" set(DEPTHAI_DEVICE_SIDE_VERSION "") diff --git a/include/depthai/device/DeviceBootloader.hpp b/include/depthai/device/DeviceBootloader.hpp index f4e5d04b42..ecc3871fa5 100644 --- a/include/depthai/device/DeviceBootloader.hpp +++ b/include/depthai/device/DeviceBootloader.hpp @@ -123,6 +123,17 @@ class DeviceBootloader { */ std::tuple flashBootloader(std::function progressCallback, std::string path = ""); + /** + * Flashes a boot header that does USB boot (as if setting the boot switches to 0x16). Currently this overwrites the bootloader + * @param progressCallback Callback that sends back a value between 0..1 which signifies current flashing progress + */ + std::tuple flashUsbBoot(std::function progressCallback); + + /** + * Sends a command to switch to USB boot. Cleared by a hard-reset/power-cycle + */ + std::tuple switchToUsbBoot(); + /** * @returns Version of current running bootloader */ diff --git a/shared/depthai-bootloader-shared b/shared/depthai-bootloader-shared index c8779ca581..2f38e221c1 160000 --- a/shared/depthai-bootloader-shared +++ b/shared/depthai-bootloader-shared @@ -1 +1 @@ -Subproject commit c8779ca581659803b6f3e465cc2bde7b22203be0 +Subproject commit 2f38e221c161d23c2451788eca7dce9992f137ad diff --git a/src/device/DeviceBootloader.cpp b/src/device/DeviceBootloader.cpp index c07ebc56c7..3a2cc906aa 100644 --- a/src/device/DeviceBootloader.cpp +++ b/src/device/DeviceBootloader.cpp @@ -367,6 +367,65 @@ std::tuple DeviceBootloader::flashBootloader(std::function DeviceBootloader::flashUsbBoot(std::function progressCb) { + // get streamId + streamId_t streamId = stream->getStreamId(); + + // send request to flash BOOT_HEADER with USB boot + dai::bootloader::request::UpdateFlash updateFlash; + updateFlash.storage = dai::bootloader::request::UpdateFlash::BOOT_HEADER; + updateFlash.bootHeader = dai::bootloader::request::UpdateFlash::BootHeader::USB; + updateFlash.totalSize = 0; + updateFlash.numPackets = 0; + if(!sendBootloaderRequest(streamId, updateFlash)) return {false, "Couldn't send bootloader flash request"}; + + // Then wait for response by bootloader + // Wait till FLASH_COMPLETE response + dai::bootloader::response::FlashComplete result; + do { + std::vector data; + if(!receiveBootloaderResponseData(streamId, data)) return {false, "Couldn't receive bootloader response"}; + + dai::bootloader::response::FlashStatusUpdate update; + if(parseBootloaderResponse(data, update)) { + // if progress callback is set + if(progressCb != nullptr) { + progressCb(update.progress); + } + // if flash complete response arrived, break from while loop + } else if(parseBootloaderResponse(data, result)) { + break; + } else { + // Unknown response, shouldn't happen + return {false, "Unknown response from bootloader while flashing"}; + } + + } while(true); + + // Return if flashing was successful + return {result.success, result.errorMsg}; +} + +std::tuple DeviceBootloader::switchToUsbBoot() { + // get streamId + streamId_t streamId = stream->getStreamId(); + + // send request to switch to USB boot, and don't let app reset again to bootloader + dai::bootloader::request::UsbRomBoot usbBootRequest; + usbBootRequest.keepUsbBootAfterAppRestart = true; + + if(!sendBootloaderRequest(streamId, usbBootRequest)) { + return {false, "Couldn't send bootloader USB boot request"}; + } + + // Dummy read, until link falls down and it returns an error + streamPacketDesc_t* pPacket; + XLinkReadData(streamId, &pPacket); + + return {true, ""}; +} + bool DeviceBootloader::isEmbeddedVersion() { return isEmbedded; }