firmware: add global state for the process
Add global state for tracking the firmware update progress. A firmware
update goes through a simple state machine, for the most part.
Change-Id: Iab797b0d175fa343fa9ec675746a96ff72818f75
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/firmware_handler.hpp b/firmware_handler.hpp
index 4dcbfb8..8cb42cf 100644
--- a/firmware_handler.hpp
+++ b/firmware_handler.hpp
@@ -48,6 +48,21 @@
lpc = (1 << 10), /* Expect to send contents over LPC bridge. */
};
+ /** The state of the firmware update process. */
+ enum UpdateState
+ {
+ /** The initial state. */
+ notYetStarted = 0,
+ /**
+ * The upload process has started, but verification has not started.
+ */
+ uploadInProgress = 1,
+ /** The verification process has started, no more writes allowed. */
+ verificationStarted = 2,
+ /** The verification process has completed. */
+ verificationCompleted = 3,
+ };
+
/**
* Create a FirmwareBlobHandler.
*
@@ -72,7 +87,7 @@
std::uint16_t bitmask) :
handlers(firmwares),
blobIDs(blobs), transports(transports), bitmask(bitmask), activeImage(),
- activeHash(), lookup()
+ activeHash(), lookup(), state(UpdateState::notYetStarted)
{
}
~FirmwareBlobHandler() = default;
@@ -102,6 +117,12 @@
static const std::string activeImageBlobID;
static const std::string activeHashBlobID;
+ /** Allow grabbing the current state. */
+ UpdateState getCurrentState() const
+ {
+ return state;
+ };
+
private:
/** List of handlers by type. */
std::vector<HandlerPack> handlers;
@@ -124,6 +145,9 @@
/** A quick method for looking up a session's mechanisms and details. */
std::map<std::uint16_t, Session*> lookup;
+ /** The firmware update state. */
+ UpdateState state;
+
/** Temporary variable to track whether a blob is open. */
bool fileOpen = false;
};