blob: 92c8e84504a1862bc6c3d71bee3ba26d1a9b5a9e [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 Kobylakbbcb7be2018-07-17 15:47:34 -050018
19void Helper::setEntry(const std::string& entryId, uint8_t value)
20{
21 std::string serviceFile = "obmc-flash-bmc-setenv@" + entryId + "\\x3d" +
22 std::to_string(value) + ".service";
23 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
24 SYSTEMD_INTERFACE, "StartUnit");
25 method.append(serviceFile, "replace");
26 bus.call_noreply(method);
27}
28
Lei YU56aaf452018-06-21 16:09:44 +080029void Helper::clearEntry(const std::string& entryId)
30{
31 // Remove the priority environment variable.
32 auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service";
33 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
34 SYSTEMD_INTERFACE, "StartUnit");
35 method.append(serviceFile, "replace");
36 bus.call_noreply(method);
37}
38
39void Helper::cleanup()
40{
41 // Remove any volumes that do not match current versions.
42 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
43 SYSTEMD_INTERFACE, "StartUnit");
44 method.append("obmc-flash-bmc-cleanup.service", "replace");
45 bus.call_noreply(method);
46}
47
48void Helper::factoryReset()
49{
50 // Mark the read-write partition for recreation upon reboot.
Adriana Kobylak56ec62e2021-01-20 10:57:18 -060051 utils::execute("/sbin/fw_setenv", "rwreset", "true");
Lei YU56aaf452018-06-21 16:09:44 +080052}
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");
Lei YU56aaf452018-06-21 16:09:44 +080072
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -060073 try
74 {
75 bus.call_noreply(method);
76 }
Patrick Williams4ce901c2021-09-02 09:34:45 -050077 catch (const sdbusplus::exception::exception& e)
Lei YU56aaf452018-06-21 16:09:44 +080078 {
Adriana Kobylak2af0fdf2021-09-01 19:36:46 +000079 error("Failed to update u-boot env variables", "VERSIONID", versionId);
Lei YU56aaf452018-06-21 16:09:44 +080080 }
81}
82
Lei YU56aaf452018-06-21 16:09:44 +080083void Helper::mirrorAlt()
84{
85 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
86 SYSTEMD_INTERFACE, "StartUnit");
87 auto mirrorUbootFile = "obmc-flash-bmc-mirroruboot.service";
88 method.append(mirrorUbootFile, "replace");
Lei YU56aaf452018-06-21 16:09:44 +080089
Adriana Kobylak3b6a4cd2018-12-10 13:45:09 -060090 try
91 {
92 bus.call_noreply(method);
93 }
Patrick Williams4ce901c2021-09-02 09:34:45 -050094 catch (const sdbusplus::exception::exception& e)
Lei YU56aaf452018-06-21 16:09:44 +080095 {
Patrick Williamsc9bb6422021-08-27 06:18:35 -050096 error("Failed to copy U-Boot to alternate chip: {ERROR}", "ERROR", e);
Lei YU56aaf452018-06-21 16:09:44 +080097 }
98}
99
100} // namespace updater
101} // namespace software
102} // namespace phosphor