mmc: Set updated version to primary
Once the update is successful, mark the version as primary so that
it boots from the updated version upon BMC reboot.
Add a sleep to wait for the service file to complete setting the
primary version. Otherwise, the BMC could mark a Delete or
Priority value change as complete and the service is not done yet,
and if the BMC is rebooted it could try to boot from a non-existent
version.
As backgroung, reference issue openbmc/openbmc#2857 that attempted
to create a 'wait for service' function but was not successful.
This could be investigated further at a later time, which would
benefit other functions like Factory Reset that are also using
sleep as a workaround to wait for systemd service files.
Tested: Verified the version was set to primary during code update
and delete, and that 3s passed (service file finished in
about 1s) before the delete/update continued.
Change-Id: I4f9afdb020d8cc7c18cfdafe468dbff2dc8046c1
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/mmc/item_updater_helper.cpp b/mmc/item_updater_helper.cpp
index 0eb910e..29b4e58 100644
--- a/mmc/item_updater_helper.cpp
+++ b/mmc/item_updater_helper.cpp
@@ -2,6 +2,8 @@
#include "item_updater_helper.hpp"
+#include <thread>
+
namespace phosphor
{
namespace software
@@ -38,9 +40,18 @@
bus.call_noreply(method);
}
-void Helper::updateUbootVersionId(const std::string& /* versionId */)
+void Helper::updateUbootVersionId(const std::string& versionId)
{
- // Empty
+ auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
+ SYSTEMD_INTERFACE, "StartUnit");
+ auto serviceFile = "obmc-flash-mmc-setprimary@" + versionId + ".service";
+ method.append(serviceFile, "replace");
+ bus.call_noreply(method);
+
+ // Wait a few seconds for the service file to finish, otherwise the BMC may
+ // be rebooted while pointing to a non-existent version.
+ constexpr auto setPrimaryWait = std::chrono::seconds(3);
+ std::this_thread::sleep_for(setPrimaryWait);
}
void Helper::mirrorAlt()