blob: 5cb10e01c152a5a4be4da3ebadbc66c5ff0ff85a [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
Patrick Williamsc9bb6422021-08-27 06:18:35 -05007#include <phosphor-logging/lg2.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
Patrick Williamsc9bb6422021-08-27 06:18:35 -050017PHOSPHOR_LOG2_USING;
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 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -050080 error("Failed to update u-boot env variables", "VERSIONID", versionid);
Lei YU56aaf452018-06-21 16:09:44 +080081 }
82}
83
Lei YU56aaf452018-06-21 16:09:44 +080084void Helper::mirrorAlt()
85{
86 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
87 SYSTEMD_INTERFACE, "StartUnit");
88 auto mirrorUbootFile = "obmc-flash-bmc-mirroruboot.service";
89 method.append(mirrorUbootFile, "replace");
Lei YU56aaf452018-06-21 16:09:44 +080090
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -060091 try
92 {
93 bus.call_noreply(method);
94 }
95 catch (const SdBusError& e)
Lei YU56aaf452018-06-21 16:09:44 +080096 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -050097 error("Failed to copy U-Boot to alternate chip: {ERROR}", "ERROR", e);
Lei YU56aaf452018-06-21 16:09:44 +080098 }
99}
100
101} // namespace updater
102} // namespace software
103} // namespace phosphor