1 #include "config.h"
2 
3 #include "activation.hpp"
4 #include "item_updater.hpp"
5 
6 namespace phosphor
7 {
8 namespace software
9 {
10 namespace updater
11 {
12 
13 namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
14 
15 void 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 
31 void Activation::onStateChanges(sdbusplus::message_t& 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";
43     auto flashId = parent.versions.find(versionId)->second->path();
44     auto ubootVarsServiceFile =
45         "obmc-flash-bmc-updateubootvars@" + flashId + ".service";
46 
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         }
72         else if (rwVolumeCreated && roVolumeCreated) // Volumes were created
73         {
74             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             }
91         }
92     }
93 
94     return;
95 }
96 
97 } // namespace updater
98 } // namespace software
99 } // namespace phosphor
100