1 #include "config.h"
2
3 #include "flash.hpp"
4
5 #include "activation.hpp"
6 #include "item_updater.hpp"
7
8 namespace phosphor
9 {
10 namespace software
11 {
12 namespace updater
13 {
14
15 namespace softwareServer = sdbusplus::server::xyz::openbmc_project::software;
16
flashWrite()17 void Activation::flashWrite()
18 {
19 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);
24 }
25
onStateChanges(sdbusplus::message_t & msg)26 void Activation::onStateChanges(sdbusplus::message_t& msg)
27 {
28 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";
37 auto flashId = parent.versions.find(versionId)->second->path();
38 auto mmcSetPrimary = "obmc-flash-mmc-setprimary@" + flashId + ".service";
39
40 if (newStateUnit == mmcServiceFile && newStateResult == "done")
41 {
42 roVolumeCreated = true;
43 activationProgress->progress(activationProgress->progress() + 1);
44 }
45
46 if (newStateUnit == mmcSetPrimary && newStateResult == "done")
47 {
48 ubootEnvVarsUpdated = true;
49 }
50
51 if (newStateUnit == mmcServiceFile || newStateUnit == mmcSetPrimary)
52 {
53 if (newStateResult == "failed" || newStateResult == "dependency")
54 {
55 Activation::activation(
56 softwareServer::Activation::Activations::Failed);
57 }
58 else if (roVolumeCreated)
59 {
60 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 }
77 }
78 }
79
80 return;
81 }
82
83 } // namespace updater
84 } // namespace software
85 } // namespace phosphor
86