blob: 873bf17f3db632183cabe8eea8d557f54b2a8f38 [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
Adriana Kobylak56ec62e2021-01-20 10:57:18 -06005#include "utils.hpp"
6
Gunnar Millsb0ce9962018-09-07 13:39:10 -05007#include <phosphor-logging/log.hpp>
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -06008#include <sdbusplus/exception.hpp>
Gunnar Millsb0ce9962018-09-07 13:39:10 -05009
Lei YU56aaf452018-06-21 16:09:44 +080010namespace phosphor
11{
12namespace software
13{
14namespace updater
15{
16
17using namespace phosphor::logging;
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -060018using sdbusplus::exception::SdBusError;
Adriana Kobylakbbcb7be2018-07-17 15:47:34 -050019
20void Helper::setEntry(const std::string& entryId, uint8_t value)
21{
22 std::string serviceFile = "obmc-flash-bmc-setenv@" + entryId + "\\x3d" +
23 std::to_string(value) + ".service";
24 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
25 SYSTEMD_INTERFACE, "StartUnit");
26 method.append(serviceFile, "replace");
27 bus.call_noreply(method);
28}
29
Lei YU56aaf452018-06-21 16:09:44 +080030void Helper::clearEntry(const std::string& entryId)
31{
32 // Remove the priority environment variable.
33 auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service";
34 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
35 SYSTEMD_INTERFACE, "StartUnit");
36 method.append(serviceFile, "replace");
37 bus.call_noreply(method);
38}
39
40void Helper::cleanup()
41{
42 // Remove any volumes that do not match current versions.
43 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
44 SYSTEMD_INTERFACE, "StartUnit");
45 method.append("obmc-flash-bmc-cleanup.service", "replace");
46 bus.call_noreply(method);
47}
48
49void Helper::factoryReset()
50{
51 // Mark the read-write partition for recreation upon reboot.
Adriana Kobylak56ec62e2021-01-20 10:57:18 -060052 utils::execute("/sbin/fw_setenv", "rwreset", "true");
Lei YU56aaf452018-06-21 16:09:44 +080053}
54
55void Helper::removeVersion(const std::string& versionId)
56{
57 auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + versionId + ".service";
58
59 // Remove the read-only partitions.
60 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
61 SYSTEMD_INTERFACE, "StartUnit");
62 method.append(serviceFile, "replace");
63 bus.call_noreply(method);
64}
65
66void Helper::updateUbootVersionId(const std::string& versionId)
67{
68 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
69 SYSTEMD_INTERFACE, "StartUnit");
70 auto updateEnvVarsFile =
71 "obmc-flash-bmc-updateubootvars@" + versionId + ".service";
72 method.append(updateEnvVarsFile, "replace");
Lei YU56aaf452018-06-21 16:09:44 +080073
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -060074 try
75 {
76 bus.call_noreply(method);
77 }
78 catch (const SdBusError& e)
Lei YU56aaf452018-06-21 16:09:44 +080079 {
80 log<level::ERR>("Failed to update u-boot env variables",
81 entry("VERSIONID=%s", versionId.c_str()));
82 }
83}
84
Lei YU56aaf452018-06-21 16:09:44 +080085void Helper::mirrorAlt()
86{
87 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
88 SYSTEMD_INTERFACE, "StartUnit");
89 auto mirrorUbootFile = "obmc-flash-bmc-mirroruboot.service";
90 method.append(mirrorUbootFile, "replace");
Lei YU56aaf452018-06-21 16:09:44 +080091
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -060092 try
93 {
94 bus.call_noreply(method);
95 }
96 catch (const SdBusError& e)
Lei YU56aaf452018-06-21 16:09:44 +080097 {
98 log<level::ERR>("Failed to copy U-Boot to alternate chip");
99 }
100}
101
102} // namespace updater
103} // namespace software
104} // namespace phosphor