bmc: enable configuration of all verification
Enable verification configuration beyond the result file check. This
patchset allows a developer to provide their own verification mechanisms
by implementing an interface and adding configuration to enable using
their custom version.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: Iba5d4be75bb49d9c4ab84be8578f0306c15b5be9
diff --git a/firmware_handler.cpp b/firmware_handler.cpp
index 6e02024..c2e935a 100644
--- a/firmware_handler.cpp
+++ b/firmware_handler.cpp
@@ -32,55 +32,12 @@
namespace blobs
{
-// systemd service to kick start a target.
-static constexpr auto systemdService = "org.freedesktop.systemd1";
-static constexpr auto systemdRoot = "/org/freedesktop/systemd1";
-static constexpr auto systemdInterface = "org.freedesktop.systemd1.Manager";
-static constexpr auto verifyTarget = "verify_image.service";
-
-namespace
-{
-
-FirmwareBlobHandler::VerifyCheckResponses
- checkVerificationState(const std::string& path)
-{
- FirmwareBlobHandler::VerifyCheckResponses result =
- FirmwareBlobHandler::VerifyCheckResponses::other;
-
- std::ifstream ifs;
- ifs.open(path);
- if (ifs.good())
- {
- /*
- * Check for the contents of the file, accepting:
- * running, success, or failed.
- */
- std::string status;
- ifs >> status;
- if (status == "running")
- {
- result = FirmwareBlobHandler::VerifyCheckResponses::running;
- }
- else if (status == "success")
- {
- result = FirmwareBlobHandler::VerifyCheckResponses::success;
- }
- else if (status == "failed")
- {
- result = FirmwareBlobHandler::VerifyCheckResponses::failed;
- }
- }
-
- return result;
-}
-
-} // namespace
std::unique_ptr<GenericBlobInterface>
FirmwareBlobHandler::CreateFirmwareBlobHandler(
- sdbusplus::bus::bus&& bus, const std::vector<HandlerPack>& firmwares,
+ const std::vector<HandlerPack>& firmwares,
const std::vector<DataHandlerPack>& transports,
- const std::string& verificationPath)
+ std::unique_ptr<VerificationInterface> verification)
{
/* There must be at least one. */
if (!firmwares.size())
@@ -112,9 +69,8 @@
bitmask |= item.bitmask;
}
- return std::make_unique<FirmwareBlobHandler>(std::move(bus), firmwares,
- blobs, transports, bitmask,
- verificationPath);
+ return std::make_unique<FirmwareBlobHandler>(
+ firmwares, blobs, transports, bitmask, std::move(verification));
}
/* Check if the path is in our supported list (or active list). */
@@ -257,7 +213,7 @@
*/
if (item->second->activePath == verifyBlobId)
{
- auto value = checkVerificationState(verificationPath);
+ auto value = verification->checkVerificationState();
meta->metadata.push_back(static_cast<std::uint8_t>(value));
@@ -700,25 +656,13 @@
bool FirmwareBlobHandler::triggerVerification()
{
- auto method = bus.new_method_call(systemdService, systemdRoot,
- systemdInterface, "StartUnit");
- method.append(verifyTarget);
- method.append("replace");
-
- try
+ bool result = verification->triggerVerification();
+ if (result)
{
- bus.call_noreply(method);
state = UpdateState::verificationStarted;
}
- catch (const sdbusplus::exception::SdBusError& ex)
- {
- /* TODO: Once logging supports unit-tests, add a log message to test
- * this failure.
- */
- return false;
- }
- return true;
+ return result;
}
} // namespace blobs