blob: ae00ea525681038d940b06bd83af582e08945026 [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
Adriana Kobylak25773a72022-01-21 15:24:48 +000054void Helper::removeVersion(const std::string& flashId)
Lei YU56aaf452018-06-21 16:09:44 +080055{
Adriana Kobylak25773a72022-01-21 15:24:48 +000056 auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + flashId + ".service";
Lei YU56aaf452018-06-21 16:09:44 +080057
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
Adriana Kobylak25773a72022-01-21 15:24:48 +000065void Helper::updateUbootVersionId(const std::string& flashId)
Lei YU56aaf452018-06-21 16:09:44 +080066{
67 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
68 SYSTEMD_INTERFACE, "StartUnit");
Patrick Williamsfc33ba82024-08-16 15:19:54 -040069 auto updateEnvVarsFile =
70 "obmc-flash-bmc-updateubootvars@" + flashId + ".service";
Lei YU56aaf452018-06-21 16:09:44 +080071 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 Williamsbf2bb2b2022-07-22 19:26:52 -050077 catch (const sdbusplus::exception_t& e)
Lei YU56aaf452018-06-21 16:09:44 +080078 {
Adriana Kobylak25773a72022-01-21 15:24:48 +000079 error("Failed to update u-boot env variables: {FLASHID}", "FLASHID",
80 flashId);
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 }
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050095 catch (const sdbusplus::exception_t& 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