blob: c58eefc4ec481d1155bac38a9c4ce80fa21d45bf [file] [log] [blame]
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -05001#include "config.h"
2
Gunnar Millsb0ce9962018-09-07 13:39:10 -05003#include "activation.hpp"
4
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -05005namespace phosphor
6{
7namespace software
8{
9namespace updater
10{
11
Adriana Kobylak3ce563a2018-06-06 16:41:15 -050012namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
13
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -050014void Activation::flashWrite()
15{
16 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
17 SYSTEMD_INTERFACE, "StartUnit");
18 method.append("obmc-flash-bmc-ubirw.service", "replace");
19 bus.call_noreply(method);
20
21 auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service";
22 method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
23 SYSTEMD_INTERFACE, "StartUnit");
24 method.append(roServiceFile, "replace");
25 bus.call_noreply(method);
26
27 return;
28}
29
Adriana Kobylak3ce563a2018-06-06 16:41:15 -050030void Activation::onStateChanges(sdbusplus::message::message& msg)
31{
32 uint32_t newStateID{};
33 sdbusplus::message::object_path newStateObjPath;
34 std::string newStateUnit{};
35 std::string newStateResult{};
36
37 // Read the msg and populate each variable
38 msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
39
40 auto rwServiceFile = "obmc-flash-bmc-ubirw.service";
41 auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service";
42 auto ubootVarsServiceFile =
43 "obmc-flash-bmc-updateubootvars@" + versionId + ".service";
44
45 if (newStateUnit == rwServiceFile && newStateResult == "done")
46 {
47 rwVolumeCreated = true;
48 activationProgress->progress(activationProgress->progress() + 20);
49 }
50
51 if (newStateUnit == roServiceFile && newStateResult == "done")
52 {
53 roVolumeCreated = true;
54 activationProgress->progress(activationProgress->progress() + 50);
55 }
56
57 if (newStateUnit == ubootVarsServiceFile && newStateResult == "done")
58 {
59 ubootEnvVarsUpdated = true;
60 }
61
62 if (newStateUnit == rwServiceFile || newStateUnit == roServiceFile ||
63 newStateUnit == ubootVarsServiceFile)
64 {
65 if (newStateResult == "failed" || newStateResult == "dependency")
66 {
67 Activation::activation(
68 softwareServer::Activation::Activations::Failed);
69 }
Adriana Kobylakb824b2f2020-05-14 14:57:53 -050070 else if (rwVolumeCreated && roVolumeCreated) // Volumes were created
Adriana Kobylak3ce563a2018-06-06 16:41:15 -050071 {
Adriana Kobylakb824b2f2020-05-14 14:57:53 -050072 if (!ubootEnvVarsUpdated)
73 {
74 activationProgress->progress(90);
75
76 // Set the priority which triggers the service that updates the
77 // environment variables.
78 if (!Activation::redundancyPriority)
79 {
80 Activation::redundancyPriority =
81 std::make_unique<RedundancyPriority>(bus, path, *this,
82 0);
83 }
84 }
85 else // Environment variables were updated
86 {
87 Activation::onFlashWriteSuccess();
88 }
Adriana Kobylak3ce563a2018-06-06 16:41:15 -050089 }
90 }
91
92 return;
93}
94
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -050095} // namespace updater
96} // namespace software
Gunnar Millsfa34e022018-09-04 10:05:45 -050097} // namespace phosphor