blob: e1c5e9cb5a43292db96a9a45414a72e136d0cd89 [file] [log] [blame]
Adriana Kobylak70f5bc02020-05-13 14:08:14 -05001#include "config.h"
2
Adriana Kobylak86013f32020-05-13 12:12:38 -05003#include "flash.hpp"
4
5#include "activation.hpp"
Adriana Kobylak25773a72022-01-21 15:24:48 +00006#include "item_updater.hpp"
Adriana Kobylak86013f32020-05-13 12:12:38 -05007
8namespace phosphor
9{
10namespace software
11{
12namespace updater
13{
14
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050015namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
16
Adriana Kobylak86013f32020-05-13 12:12:38 -050017void Activation::flashWrite()
18{
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050019 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
20 SYSTEMD_INTERFACE, "StartUnit");
21 auto serviceFile = "obmc-flash-mmc@" + versionId + ".service";
22 method.append(serviceFile, "replace");
23 bus.call_noreply(method);
Adriana Kobylak86013f32020-05-13 12:12:38 -050024}
25
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050026void Activation::onStateChanges(sdbusplus::message::message& msg)
Adriana Kobylak86013f32020-05-13 12:12:38 -050027{
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050028 uint32_t newStateID{};
29 sdbusplus::message::object_path newStateObjPath;
30 std::string newStateUnit{};
31 std::string newStateResult{};
32
33 // Read the msg and populate each variable
34 msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
35
36 auto mmcServiceFile = "obmc-flash-mmc@" + versionId + ".service";
Adriana Kobylak25773a72022-01-21 15:24:48 +000037 auto flashId = parent.versions.find(versionId)->second->path();
38 auto mmcSetPrimary = "obmc-flash-mmc-setprimary@" + flashId + ".service";
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050039
40 if (newStateUnit == mmcServiceFile && newStateResult == "done")
41 {
42 roVolumeCreated = true;
43 activationProgress->progress(activationProgress->progress() + 1);
44 }
45
Adriana Kobylak34124352020-05-22 09:40:40 -050046 if (newStateUnit == mmcSetPrimary && newStateResult == "done")
47 {
48 ubootEnvVarsUpdated = true;
49 }
50
51 if (newStateUnit == mmcServiceFile || newStateUnit == mmcSetPrimary)
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050052 {
53 if (newStateResult == "failed" || newStateResult == "dependency")
54 {
55 Activation::activation(
56 softwareServer::Activation::Activations::Failed);
57 }
58 else if (roVolumeCreated)
59 {
Adriana Kobylak34124352020-05-22 09:40:40 -050060 if (!ubootEnvVarsUpdated)
61 {
62 activationProgress->progress(90);
63
64 // Set the priority which triggers the service that updates the
65 // environment variables.
66 if (!Activation::redundancyPriority)
67 {
68 Activation::redundancyPriority =
69 std::make_unique<RedundancyPriority>(bus, path, *this,
70 0);
71 }
72 }
73 else // Environment variables were updated
74 {
75 Activation::onFlashWriteSuccess();
76 }
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050077 }
78 }
79
80 return;
Adriana Kobylak86013f32020-05-13 12:12:38 -050081}
82
83} // namespace updater
84} // namespace software
85} // namespace phosphor