Device: Allow skipping of device state refreshing on call to open

This commit is contained in:
Max Brombach
2026-11-03 11:20:04 -05:00
committed by Kyle Schwarz
parent dffb0bcefb
commit 645549193d
21 changed files with 124 additions and 166 deletions
@@ -15,20 +15,33 @@ namespace icsneo {
namespace Bootloader {
using Logger = icsneo::Device::OpenStatusHandler;
enum class StatusType {
Progress,
Failed
};
/**
* @brief Alias of callback function for progress of a bootloader pipeline task
*
* The progress value passed into the callback function indicates the following:
* 1) If the value is std::nullopt, this implies the status message is for an asynchronous task or a task in which the current progress is unknown.
* 2) If the value is between 0 and 1 (i.e., 0 <= progress <= 1), this implies the actual progress of the current task as a percentage.
* 3) Values not between 0 and 1 (i.e., progress < 0 or progress > 1) are undefined.
*/
using StatusHandler = std::function<void(StatusType type, const std::string& status, std::optional<double> progress)>;
bool requiresUpdate(icsneo::Device& device, const FWRepo& fw);
bool update(
icsneo::Device& device,
const FWRepo& fw,
Logger logger = [](icsneo::Device::OpenStatusType, const std::string&, std::optional<double>) { return icsneo::Device::OpenDirective::Continue; },
StatusHandler statusHandler = [](StatusType, const std::string&, std::optional<double>) {},
bool alreadyInBootloader = false,
bool forceFlash = false
);
bool enterBootloader(icsneo::Device& device);
bool exitBootloader(icsneo::Device& device, Logger logger, bool updatedChips);
bool verifyConnection(icsneo::Device& device, Logger logger);
bool exitBootloader(icsneo::Device& device, StatusHandler statusHandler, bool updatedChips);
bool verifyConnection(icsneo::Device& device, StatusHandler statusHandler);
bool isSFPChip(const icsneo::Bootloader::Chip& chip);
bool isSFPIEF(const icsneo::Bootloader::IEF& ief);
@@ -31,7 +31,7 @@ public:
return true;
}
bool finalize() override;
bool flash(const FWRepo& repo, const icsneo::Device::OpenStatusHandler& handler) override;
bool flash(const FWRepo& repo, const StatusHandler& handler) override;
bool open() override {
return true;
@@ -42,8 +42,8 @@ public:
}
bool authenticate();
bool sendSoftware(const std::vector<uint8_t>& bin, const icsneo::Device::OpenStatusHandler& handler);
bool sendSoftware(const std::vector<IEF::Sector>& sectors, uint32_t blockSize, const icsneo::Device::OpenStatusHandler& handler);
bool sendSoftware(const std::vector<uint8_t>& bin, const StatusHandler& handler);
bool sendSoftware(const std::vector<IEF::Sector>& sectors, uint32_t blockSize, const StatusHandler& handler);
bool validateFirmware(const DeviceAppVersion& chipSrcVer);
bool validateComponent();
@@ -74,12 +74,12 @@ private:
const bool doAuthChecks;
const bool encrypted;
using StatusHandler = std::function<void(double progress)>;
bool sendCommand(Update command, const StatusHandler& handler, uint32_t offset = 0,
using CommandStatusHandler = std::function<void(double progress)>;
bool sendCommand(Update command, const CommandStatusHandler& handler, uint32_t offset = 0,
const std::vector<uint8_t>& args = {}, std::chrono::milliseconds timeout = std::chrono::milliseconds(3000)) {
return sendCommand(command, offset, static_cast<uint32_t>(args.size()), handler, timeout, args);
}
bool sendCommand(Update command, uint32_t offset, uint32_t length, const StatusHandler& handler,
bool sendCommand(Update command, uint32_t offset, uint32_t length, const CommandStatusHandler& handler,
std::chrono::milliseconds timeout = std::chrono::milliseconds(3000), std::vector<uint8_t> args = {});
};
@@ -5,6 +5,7 @@
#include "icsneo/device/extensions/bootloader/chip.h"
#include "icsneo/device/device.h"
#include "icsneo/device/extensions/bootloader/api.h"
#include <cstdint>
@@ -29,7 +30,7 @@ public:
virtual bool enterApplication() = 0;
virtual bool hasFinalizationStep() const = 0;
virtual bool finalize() = 0;
virtual bool flash(const FWRepo& repo, const icsneo::Device::OpenStatusHandler& handler) = 0;
virtual bool flash(const FWRepo& repo, const StatusHandler& handler) = 0;
virtual bool open() = 0;
virtual bool close() = 0;
@@ -69,7 +69,7 @@ protected:
Response& sendRequest(const Request& request, std::chrono::milliseconds timeout = std::chrono::milliseconds(2000));
bool sendRequestNoResponse();
icsneo::Device::OpenStatusHandler logger; // Progress updates, set in flash()
StatusHandler statusHandler; // Progress updates, set in flash()
Response lastResponse; // Last response received from sendRequest
bool supportsZynqBinaryFlasher = false; // Dictates how messages are formatted, this gets set in initialize()
@@ -92,7 +92,7 @@ public:
bool enterApplication() override;
bool finalize() override;
bool flash(const FWRepo& fw, const icsneo::Device::OpenStatusHandler& handler) override;
bool flash(const FWRepo& fw, const StatusHandler& handler) override;
bool open() override;
bool close() override;
@@ -22,7 +22,7 @@ private:
public:
RADMultiChipCommunication(icsneo::Device& dev, const ChipInfo& chipToFlash, bool auth, uint8_t slot = UINT8_MAX);
bool flash(const FWRepo& fw, const icsneo::Device::OpenStatusHandler& handler) override;
bool flash(const FWRepo& fw, const StatusHandler& handler) override;
bool open() override;
bool close() override;
bool enterApplication() override;
@@ -79,7 +79,7 @@ public:
RADPeriphCommunication(icsneo::Device& dev, const ChipInfo& chipToFlash);
~RADPeriphCommunication();
bool flash(const FWRepo& fw, const icsneo::Device::OpenStatusHandler& handler) override;
bool flash(const FWRepo& fw, const StatusHandler& handler) override;
bool open() override;
bool close() override;
bool enterApplication() override;
@@ -23,7 +23,7 @@ class REDCommunication : public REDCommunicationBase {
public:
REDCommunication(icsneo::Device& dev, const ChipInfo& chip, bool auth, bool encryptWithDeviceKey = true);
bool enterApplication() override { return sendCommand(uint8_t(Command::EnterApplication)); }
bool flash(const FWRepo& fw, const icsneo::Device::OpenStatusHandler& handler) override;
bool flash(const FWRepo& fw, const StatusHandler& handler) override;
bool open() override;
private:
@@ -27,7 +27,7 @@ public:
using REDCommunicationBase::REDCommunicationBase;
bool enterApplication() override { return false; }
bool flash(const FWRepo& fw, const icsneo::Device::OpenStatusHandler& handler) override;
bool flash(const FWRepo& fw, const StatusHandler& handler) override;
private:
/**
* Core flasher commands are tunneled through a RED request using CoreFlasherCommand,
@@ -16,12 +16,6 @@ public:
virtual ~DeviceExtension() = default;
virtual const char* getName() const = 0;
// Return false to block opening
virtual bool onDeviceOpen(Device::OpenFlags, const Device::OpenStatusHandler&) { return true; }
// Return true to indicate that communication should now be back
virtual bool onDeviceCommunicationDead(Device::OpenFlags, const Device::OpenStatusHandler&) { return false; }
virtual void onGoOnline() {}
virtual void onGoOffline() {}
virtual void onDeviceClose() {}