1 #include "config.h"
2 
3 #include "activation.hpp"
4 
5 namespace phosphor
6 {
7 namespace software
8 {
9 namespace updater
10 {
11 
12 namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
13 
14 void 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 
30 void 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         }
70         else if (rwVolumeCreated && roVolumeCreated) // Volumes were created
71         {
72             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             }
89         }
90     }
91 
92     return;
93 }
94 
95 } // namespace updater
96 } // namespace software
97 } // namespace phosphor
98