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