blob: 68162cbcedc17fd33878501d9966885fc2c1c7cd [file] [log] [blame]
Lei YU56aaf452018-06-21 16:09:44 +08001#include "config.h"
Gunnar Millsb0ce9962018-09-07 13:39:10 -05002
Lei YU56aaf452018-06-21 16:09:44 +08003#include "item_updater_helper.hpp"
4
Gunnar Millsb0ce9962018-09-07 13:39:10 -05005#include <phosphor-logging/log.hpp>
6
Lei YU56aaf452018-06-21 16:09:44 +08007namespace phosphor
8{
9namespace software
10{
11namespace updater
12{
13
14using namespace phosphor::logging;
Adriana Kobylakbbcb7be2018-07-17 15:47:34 -050015
16void Helper::setEntry(const std::string& entryId, uint8_t value)
17{
18 std::string serviceFile = "obmc-flash-bmc-setenv@" + entryId + "\\x3d" +
19 std::to_string(value) + ".service";
20 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
21 SYSTEMD_INTERFACE, "StartUnit");
22 method.append(serviceFile, "replace");
23 bus.call_noreply(method);
24}
25
Lei YU56aaf452018-06-21 16:09:44 +080026void Helper::clearEntry(const std::string& entryId)
27{
28 // Remove the priority environment variable.
29 auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service";
30 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
31 SYSTEMD_INTERFACE, "StartUnit");
32 method.append(serviceFile, "replace");
33 bus.call_noreply(method);
34}
35
36void Helper::cleanup()
37{
38 // Remove any volumes that do not match current versions.
39 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
40 SYSTEMD_INTERFACE, "StartUnit");
41 method.append("obmc-flash-bmc-cleanup.service", "replace");
42 bus.call_noreply(method);
43}
44
45void Helper::factoryReset()
46{
47 // Mark the read-write partition for recreation upon reboot.
48 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
49 SYSTEMD_INTERFACE, "StartUnit");
50 method.append("obmc-flash-bmc-setenv@rwreset\\x3dtrue.service", "replace");
51 bus.call_noreply(method);
52}
53
54void Helper::removeVersion(const std::string& versionId)
55{
56 auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + versionId + ".service";
57
58 // Remove the read-only partitions.
59 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
60 SYSTEMD_INTERFACE, "StartUnit");
61 method.append(serviceFile, "replace");
62 bus.call_noreply(method);
63}
64
65void Helper::updateUbootVersionId(const std::string& versionId)
66{
67 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
68 SYSTEMD_INTERFACE, "StartUnit");
69 auto updateEnvVarsFile =
70 "obmc-flash-bmc-updateubootvars@" + versionId + ".service";
71 method.append(updateEnvVarsFile, "replace");
72 auto result = bus.call(method);
73
74 // Check that the bus call didn't result in an error
75 if (result.is_method_error())
76 {
77 log<level::ERR>("Failed to update u-boot env variables",
78 entry("VERSIONID=%s", versionId.c_str()));
79 }
80}
81
82void Helper::enableFieldMode()
83{
84 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
85 SYSTEMD_INTERFACE, "StartUnit");
86 method.append("obmc-flash-bmc-setenv@fieldmode\\x3dtrue.service",
87 "replace");
88 bus.call_noreply(method);
89
90 method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
91 SYSTEMD_INTERFACE, "StopUnit");
92 method.append("usr-local.mount", "replace");
93 bus.call_noreply(method);
94
95 std::vector<std::string> usrLocal = {"usr-local.mount"};
96
97 method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
98 SYSTEMD_INTERFACE, "MaskUnitFiles");
99 method.append(usrLocal, false, true);
100 bus.call_noreply(method);
101}
102void Helper::mirrorAlt()
103{
104 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
105 SYSTEMD_INTERFACE, "StartUnit");
106 auto mirrorUbootFile = "obmc-flash-bmc-mirroruboot.service";
107 method.append(mirrorUbootFile, "replace");
108 auto result = bus.call(method);
109
110 // Check that the bus call didn't result in an error
111 if (result.is_method_error())
112 {
113 log<level::ERR>("Failed to copy U-Boot to alternate chip");
114 }
115}
116
117} // namespace updater
118} // namespace software
119} // namespace phosphor