build: add option --enable-host-bios

Add option to enable building in support for the host bios.

Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I324fc071f07cd364fd39c7df1ccfd9f0fd509a46
diff --git a/bmc/Makefile.am b/bmc/Makefile.am
index 6378ffb..8ada86b 100644
--- a/bmc/Makefile.am
+++ b/bmc/Makefile.am
@@ -5,6 +5,12 @@
 	phosphor-ipmi-flash-bmc-prepare.target \
 	phosphor-ipmi-flash-bmc-verify.target \
 	phosphor-ipmi-flash-bmc-update.target
+if ENABLE_HOST_BIOS
+systemdsystemunit_DATA += \
+	phosphor-ipmi-flash-bios-prepare.target \
+	phosphor-ipmi-flash-bios-verify.target \
+	phosphor-ipmi-flash-bios-update.target
+endif
 endif
 
 noinst_LTLIBRARIES = libfirmwareblob_common.la
diff --git a/bmc/main.cpp b/bmc/main.cpp
index d89369c..9f1088a 100644
--- a/bmc/main.cpp
+++ b/bmc/main.cpp
@@ -49,6 +49,9 @@
 #ifdef ENABLE_TARBALL_UBI
 FileHandler ubitarballHandler(TARBALL_STAGED_NAME);
 #endif
+#ifdef ENABLE_HOST_BIOS
+FileHandler biosHandler(BIOS_STAGED_NAME);
+#endif
 
 /* The maximum external buffer size we expect is 64KB. */
 static constexpr std::size_t memoryRegionSize = 64 * 1024UL;
@@ -81,6 +84,9 @@
 #ifdef ENABLE_TARBALL_UBI
     {ubiTarballBlobId, &ubitarballHandler},
 #endif
+#ifdef ENABLE_HOST_BIOS
+    {biosBlobId, &biosHandler},
+#endif
 };
 
 std::vector<DataHandlerPack> supportedTransports = {
@@ -102,6 +108,8 @@
 
 std::unique_ptr<blobs::GenericBlobInterface> createHandler()
 {
+    ipmi_flash::ActionMap actionPacks = {};
+
 #ifdef ENABLE_REBOOT_UPDATE
     static constexpr auto rebootTarget = "reboot.target";
     static constexpr auto rebootMode = "replace-irreversibly";
@@ -120,8 +128,6 @@
         sdbusplus::bus::new_default(), VERIFY_STATUS_FILENAME,
         VERIFY_DBUS_SERVICE);
 
-    ipmi_flash::ActionMap actionPacks = {};
-
     /* TODO: for bios should the name be, bios or /flash/bios?, these are
      * /flash/... and it simplifies a few other things later (open/etc)
      */
@@ -139,6 +145,27 @@
     bmcPack->update = std::move(updater);
     actionPacks[bmcName] = std::move(bmcPack);
 
+#ifdef ENABLE_HOST_BIOS
+    {
+        auto biosPack = std::make_unique<ipmi_flash::ActionPack>();
+
+        biosPack->preparation =
+            ipmi_flash::SystemdPreparation::CreatePreparation(
+                sdbusplus::bus::new_default(), PREPARATION_BIOS_TARGET);
+
+        biosPack->verification =
+            ipmi_flash::SystemdVerification::CreateVerification(
+                sdbusplus::bus::new_default(), BIOS_VERIFY_STATUS_FILENAME,
+                VERIFY_BIOS_TARGET);
+
+        biosPack->update =
+            ipmi_flash::SystemdUpdateMechanism::CreateSystemdUpdate(
+                sdbusplus::bus::new_default(), UPDATE_BIOS_TARGET);
+
+        actionPacks[ipmi_flash::biosBlobId] = std::move(biosPack);
+    }
+#endif
+
     auto handler = ipmi_flash::FirmwareBlobHandler::CreateFirmwareBlobHandler(
         ipmi_flash::supportedFirmware, ipmi_flash::supportedTransports,
         std::move(actionPacks));
diff --git a/bmc/phosphor-ipmi-flash-bios-prepare.target.in b/bmc/phosphor-ipmi-flash-bios-prepare.target.in
new file mode 100644
index 0000000..b50e644
--- /dev/null
+++ b/bmc/phosphor-ipmi-flash-bios-prepare.target.in
@@ -0,0 +1,2 @@
+[Unit]
+Description=Phosphor-ipmi-flash Prepare BIOS to receive update
diff --git a/bmc/phosphor-ipmi-flash-bios-update.target.in b/bmc/phosphor-ipmi-flash-bios-update.target.in
new file mode 100644
index 0000000..46759ed
--- /dev/null
+++ b/bmc/phosphor-ipmi-flash-bios-update.target.in
@@ -0,0 +1,2 @@
+[Unit]
+Description=Phosphor-ipmi-flash update the BIOS image
diff --git a/bmc/phosphor-ipmi-flash-bios-verify.target.in b/bmc/phosphor-ipmi-flash-bios-verify.target.in
new file mode 100644
index 0000000..d45da94
--- /dev/null
+++ b/bmc/phosphor-ipmi-flash-bios-verify.target.in
@@ -0,0 +1,2 @@
+[Unit]
+Description=Phosphor-ipmi-flash verify the image contents
diff --git a/bmc/test/firmware_multiplebundle_unittest.cpp b/bmc/test/firmware_multiplebundle_unittest.cpp
index b8d738d..2c450f4 100644
--- a/bmc/test/firmware_multiplebundle_unittest.cpp
+++ b/bmc/test/firmware_multiplebundle_unittest.cpp
@@ -33,7 +33,7 @@
         blobs = {
             {hashBlobId, &hashImageMock},
             {staticLayoutBlobId, &staticImageMock},
-            {biosId, &biosImageMock},
+            {biosBlobId, &biosImageMock},
         };
 
         std::unique_ptr<TriggerableActionInterface> bmcPrepareMock =
@@ -77,7 +77,7 @@
         biosPack->update = std::move(biosUpdateMock);
 
         packs[staticLayoutBlobId] = std::move(bmcPack);
-        packs[biosId] = std::move(biosPack);
+        packs[biosBlobId] = std::move(biosPack);
 
         handler = FirmwareBlobHandler::CreateFirmwareBlobHandler(
             blobs, data, std::move(packs));
@@ -103,8 +103,6 @@
     std::uint16_t session = 1;
     std::uint16_t flags =
         blobs::OpenFlags::write | FirmwareFlags::UpdateFlags::ipmi;
-
-    const std::string biosId = "/flash/bios";
 };
 
 TEST_F(IpmiOnlyTwoFirmwaresTest, OpeningBiosAfterBlobFails)
@@ -124,8 +122,8 @@
 
     expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
 
-    EXPECT_CALL(biosImageMock, open(biosId)).Times(0);
-    EXPECT_FALSE(handler->open(session, flags, biosId));
+    EXPECT_CALL(biosImageMock, open(biosBlobId)).Times(0);
+    EXPECT_FALSE(handler->open(session, flags, biosBlobId));
 }
 
 TEST_F(IpmiOnlyTwoFirmwaresTest, OpeningHashBeforeBiosSucceeds)
@@ -142,8 +140,8 @@
     expectedState(FirmwareBlobHandler::UpdateState::verificationPending);
     ASSERT_FALSE(handler->canHandleBlob(verifyBlobId));
 
-    EXPECT_CALL(biosImageMock, open(biosId)).WillOnce(Return(true));
-    EXPECT_TRUE(handler->open(session, flags, biosId));
+    EXPECT_CALL(biosImageMock, open(biosBlobId)).WillOnce(Return(true));
+    EXPECT_TRUE(handler->open(session, flags, biosBlobId));
 
     expectedState(FirmwareBlobHandler::UpdateState::uploadInProgress);