blob: 4cc83c4d64f28ab3a3a1954ca60735b1d3de2b1a [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>
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -06006#include <sdbusplus/exception.hpp>
Gunnar Millsb0ce9962018-09-07 13:39:10 -05007
Lei YU56aaf452018-06-21 16:09:44 +08008namespace phosphor
9{
10namespace software
11{
12namespace updater
13{
14
15using namespace phosphor::logging;
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -060016using sdbusplus::exception::SdBusError;
Adriana Kobylakbbcb7be2018-07-17 15:47:34 -050017
18void Helper::setEntry(const std::string& entryId, uint8_t value)
19{
20 std::string serviceFile = "obmc-flash-bmc-setenv@" + entryId + "\\x3d" +
21 std::to_string(value) + ".service";
22 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
23 SYSTEMD_INTERFACE, "StartUnit");
24 method.append(serviceFile, "replace");
25 bus.call_noreply(method);
26}
27
Lei YU56aaf452018-06-21 16:09:44 +080028void Helper::clearEntry(const std::string& entryId)
29{
30 // Remove the priority environment variable.
31 auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service";
32 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
33 SYSTEMD_INTERFACE, "StartUnit");
34 method.append(serviceFile, "replace");
35 bus.call_noreply(method);
36}
37
38void Helper::cleanup()
39{
40 // Remove any volumes that do not match current versions.
41 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
42 SYSTEMD_INTERFACE, "StartUnit");
43 method.append("obmc-flash-bmc-cleanup.service", "replace");
44 bus.call_noreply(method);
45}
46
47void Helper::factoryReset()
48{
49 // Mark the read-write partition for recreation upon reboot.
50 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
51 SYSTEMD_INTERFACE, "StartUnit");
52 method.append("obmc-flash-bmc-setenv@rwreset\\x3dtrue.service", "replace");
53 bus.call_noreply(method);
54}
55
56void Helper::removeVersion(const std::string& versionId)
57{
58 auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + versionId + ".service";
59
60 // Remove the read-only partitions.
61 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
62 SYSTEMD_INTERFACE, "StartUnit");
63 method.append(serviceFile, "replace");
64 bus.call_noreply(method);
65}
66
67void Helper::updateUbootVersionId(const std::string& versionId)
68{
69 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
70 SYSTEMD_INTERFACE, "StartUnit");
71 auto updateEnvVarsFile =
72 "obmc-flash-bmc-updateubootvars@" + versionId + ".service";
73 method.append(updateEnvVarsFile, "replace");
Lei YU56aaf452018-06-21 16:09:44 +080074
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -060075 try
76 {
77 bus.call_noreply(method);
78 }
79 catch (const SdBusError& e)
Lei YU56aaf452018-06-21 16:09:44 +080080 {
81 log<level::ERR>("Failed to update u-boot env variables",
82 entry("VERSIONID=%s", versionId.c_str()));
83 }
84}
85
Lei YU56aaf452018-06-21 16:09:44 +080086void Helper::mirrorAlt()
87{
88 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
89 SYSTEMD_INTERFACE, "StartUnit");
90 auto mirrorUbootFile = "obmc-flash-bmc-mirroruboot.service";
91 method.append(mirrorUbootFile, "replace");
Lei YU56aaf452018-06-21 16:09:44 +080092
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -060093 try
94 {
95 bus.call_noreply(method);
96 }
97 catch (const SdBusError& e)
Lei YU56aaf452018-06-21 16:09:44 +080098 {
99 log<level::ERR>("Failed to copy U-Boot to alternate chip");
100 }
101}
102
103} // namespace updater
104} // namespace software
105} // namespace phosphor