updater: Cleanup Active blob to support multiple stages
Without the change, the update will fail due to existing active blob.
```
./burn_my_bmc --command update --interface ipmipci \
--image test.txt --sig test.txt --type bios
Sending over the firmware image.
sendFile with /flash/bios and test.txt
Opening the cleanup blob
Committing to the cleanup blob
Closing cleanup blob
Exception received: blob exception received: Received IPMI_CC: 255
```
With the Change, it will delete the active blob to continue the update.
```
./burn_my_bmc --command update --interface ipmipci \
--image test.txt --sig test.txt --type bios
Found an active blob, deleting /flash/active/image
Opening the cleanup blob
Committing to the cleanup blob
Closing cleanup blob
Committing to the cleanup blob
Closing cleanup blob
Sending over the firmware image.
sendFile with /flash/bios and test.txt
000Find [0x1050 0x750]
bar0[0x90100000]
Progress: 100.00%
001Sending over the hash file.
sendFile with /flash/hash and test.txt
000Find [0x1050 0x750]
bar0[0x90100000]
Progress: 100.00%
001Opening the verification file
Committing to /flash/verify to trigger service
Calling stat on /flash/verify session to check status
running
running
failed
Returned non-success (could still be running (unlikely))
failed
Opening the cleanup blob
Committing to the cleanup blob
Closing cleanup blob
Exception received: Verification failed
```
Signed-off-by: Willy Tu <wltu@google.com>
Change-Id: I46a802c7faece60a9b5354db47860e796af99107
diff --git a/tools/updater.cpp b/tools/updater.cpp
index 87962b9..4963103 100644
--- a/tools/updater.cpp
+++ b/tools/updater.cpp
@@ -35,8 +35,8 @@
namespace host_tool
{
-void updaterMain(UpdateHandlerInterface* updater, const std::string& imagePath,
- const std::string& signaturePath,
+void updaterMain(UpdateHandlerInterface* updater, ipmiblob::BlobInterface* blob,
+ const std::string& imagePath, const std::string& signaturePath,
const std::string& layoutType, bool ignoreUpdate)
{
/* TODO: validate the layoutType isn't a special value such as: 'update',
@@ -50,6 +50,23 @@
throw ToolException("Goal firmware not supported");
}
+ // Clean all active blobs to support multiple stages
+ // Check for any active blobs and delete the first one found to reset the
+ // BMC's phosphor-ipmi-flash state machine then clean any leftover artifacts
+ const auto blobList = blob->getBlobList();
+ for (const auto& activeBlob : blobList)
+ {
+ // Prefix is /flash/active/
+ if (activeBlob.find("/flash/active/", 0) == 0)
+ {
+ std::fprintf(stderr, "Found an active blob, deleting %s\n",
+ activeBlob.c_str());
+ blob->deleteBlob(activeBlob);
+ updater->cleanArtifacts();
+ break;
+ }
+ }
+
/* Yay, our layout type is supported. */
try
{