blob: 0089d015ca80cb362d698c5fbc9e6949fddb5d32 [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"
Adriana Kobylak25773a72022-01-21 15:24:48 +00004#include "item_updater.hpp"
Gunnar Millsb0ce9962018-09-07 13:39:10 -05005
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -05006namespace phosphor
7{
8namespace software
9{
10namespace updater
11{
12
Adriana Kobylak3ce563a2018-06-06 16:41:15 -050013namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
14
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -050015void Activation::flashWrite()
16{
17 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
18 SYSTEMD_INTERFACE, "StartUnit");
19 method.append("obmc-flash-bmc-ubirw.service", "replace");
20 bus.call_noreply(method);
21
22 auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service";
23 method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
24 SYSTEMD_INTERFACE, "StartUnit");
25 method.append(roServiceFile, "replace");
26 bus.call_noreply(method);
27
28 return;
29}
30
Adriana Kobylak3ce563a2018-06-06 16:41:15 -050031void Activation::onStateChanges(sdbusplus::message::message& msg)
32{
33 uint32_t newStateID{};
34 sdbusplus::message::object_path newStateObjPath;
35 std::string newStateUnit{};
36 std::string newStateResult{};
37
38 // Read the msg and populate each variable
39 msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
40
41 auto rwServiceFile = "obmc-flash-bmc-ubirw.service";
42 auto roServiceFile = "obmc-flash-bmc-ubiro@" + versionId + ".service";
Adriana Kobylak25773a72022-01-21 15:24:48 +000043 auto flashId = parent.versions.find(versionId)->second->path();
Adriana Kobylak3ce563a2018-06-06 16:41:15 -050044 auto ubootVarsServiceFile =
Adriana Kobylak25773a72022-01-21 15:24:48 +000045 "obmc-flash-bmc-updateubootvars@" + flashId + ".service";
Adriana Kobylak3ce563a2018-06-06 16:41:15 -050046
47 if (newStateUnit == rwServiceFile && newStateResult == "done")
48 {
49 rwVolumeCreated = true;
50 activationProgress->progress(activationProgress->progress() + 20);
51 }
52
53 if (newStateUnit == roServiceFile && newStateResult == "done")
54 {
55 roVolumeCreated = true;
56 activationProgress->progress(activationProgress->progress() + 50);
57 }
58
59 if (newStateUnit == ubootVarsServiceFile && newStateResult == "done")
60 {
61 ubootEnvVarsUpdated = true;
62 }
63
64 if (newStateUnit == rwServiceFile || newStateUnit == roServiceFile ||
65 newStateUnit == ubootVarsServiceFile)
66 {
67 if (newStateResult == "failed" || newStateResult == "dependency")
68 {
69 Activation::activation(
70 softwareServer::Activation::Activations::Failed);
71 }
Adriana Kobylakb824b2f2020-05-14 14:57:53 -050072 else if (rwVolumeCreated && roVolumeCreated) // Volumes were created
Adriana Kobylak3ce563a2018-06-06 16:41:15 -050073 {
Adriana Kobylakb824b2f2020-05-14 14:57:53 -050074 if (!ubootEnvVarsUpdated)
75 {
76 activationProgress->progress(90);
77
78 // Set the priority which triggers the service that updates the
79 // environment variables.
80 if (!Activation::redundancyPriority)
81 {
82 Activation::redundancyPriority =
83 std::make_unique<RedundancyPriority>(bus, path, *this,
84 0);
85 }
86 }
87 else // Environment variables were updated
88 {
89 Activation::onFlashWriteSuccess();
90 }
Adriana Kobylak3ce563a2018-06-06 16:41:15 -050091 }
92 }
93
94 return;
95}
96
Adriana Kobylak9f89e2e2018-05-30 13:16:20 -050097} // namespace updater
98} // namespace software
Gunnar Millsfa34e022018-09-04 10:05:45 -050099} // namespace phosphor