blob: 3bd67fa77025b1471d299282a88ec2837884bfe7 [file] [log] [blame]
Adriana Kobylak70f5bc02020-05-13 14:08:14 -05001#include "config.h"
2
Adriana Kobylak86013f32020-05-13 12:12:38 -05003#include "flash.hpp"
4
5#include "activation.hpp"
6
7namespace phosphor
8{
9namespace software
10{
11namespace updater
12{
13
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050014namespace softwareServer = sdbusplus::xyz::openbmc_project::Software::server;
15
Adriana Kobylak86013f32020-05-13 12:12:38 -050016void Activation::flashWrite()
17{
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050018 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
19 SYSTEMD_INTERFACE, "StartUnit");
20 auto serviceFile = "obmc-flash-mmc@" + versionId + ".service";
21 method.append(serviceFile, "replace");
22 bus.call_noreply(method);
Adriana Kobylak86013f32020-05-13 12:12:38 -050023}
24
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050025void Activation::onStateChanges(sdbusplus::message::message& msg)
Adriana Kobylak86013f32020-05-13 12:12:38 -050026{
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050027 uint32_t newStateID{};
28 sdbusplus::message::object_path newStateObjPath;
29 std::string newStateUnit{};
30 std::string newStateResult{};
31
32 // Read the msg and populate each variable
33 msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
34
35 auto mmcServiceFile = "obmc-flash-mmc@" + versionId + ".service";
Adriana Kobylak34124352020-05-22 09:40:40 -050036 auto mmcSetPrimary = "obmc-flash-mmc-setprimary@" + versionId + ".service";
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050037
38 if (newStateUnit == mmcServiceFile && newStateResult == "done")
39 {
40 roVolumeCreated = true;
41 activationProgress->progress(activationProgress->progress() + 1);
42 }
43
Adriana Kobylak34124352020-05-22 09:40:40 -050044 if (newStateUnit == mmcSetPrimary && newStateResult == "done")
45 {
46 ubootEnvVarsUpdated = true;
47 }
48
49 if (newStateUnit == mmcServiceFile || newStateUnit == mmcSetPrimary)
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050050 {
51 if (newStateResult == "failed" || newStateResult == "dependency")
52 {
53 Activation::activation(
54 softwareServer::Activation::Activations::Failed);
55 }
56 else if (roVolumeCreated)
57 {
Adriana Kobylak34124352020-05-22 09:40:40 -050058 if (!ubootEnvVarsUpdated)
59 {
60 activationProgress->progress(90);
61
62 // Set the priority which triggers the service that updates the
63 // environment variables.
64 if (!Activation::redundancyPriority)
65 {
66 Activation::redundancyPriority =
67 std::make_unique<RedundancyPriority>(bus, path, *this,
68 0);
69 }
70 }
71 else // Environment variables were updated
72 {
73 Activation::onFlashWriteSuccess();
74 }
Adriana Kobylak70f5bc02020-05-13 14:08:14 -050075 }
76 }
77
78 return;
Adriana Kobylak86013f32020-05-13 12:12:38 -050079}
80
81} // namespace updater
82} // namespace software
83} // namespace phosphor