1 #include "config.h"
2
3 #include "item_updater_helper.hpp"
4
5 #include "utils.hpp"
6
7 #include <phosphor-logging/lg2.hpp>
8 #include <sdbusplus/exception.hpp>
9
10 namespace phosphor
11 {
12 namespace software
13 {
14 namespace updater
15 {
16
17 PHOSPHOR_LOG2_USING;
18
setEntry(const std::string & entryId,uint8_t value)19 void 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
clearEntry(const std::string & entryId)29 void 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
cleanup()39 void 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
factoryReset()48 void Helper::factoryReset()
49 {
50 // Mark the read-write partition for recreation upon reboot.
51 utils::execute("/sbin/fw_setenv", "rwreset", "true");
52 }
53
removeVersion(const std::string & flashId)54 void Helper::removeVersion(const std::string& flashId)
55 {
56 auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + flashId + ".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
updateUbootVersionId(const std::string & flashId)65 void Helper::updateUbootVersionId(const std::string& flashId)
66 {
67 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
68 SYSTEMD_INTERFACE, "StartUnit");
69 auto updateEnvVarsFile =
70 "obmc-flash-bmc-updateubootvars@" + flashId + ".service";
71 method.append(updateEnvVarsFile, "replace");
72
73 try
74 {
75 bus.call_noreply(method);
76 }
77 catch (const sdbusplus::exception_t& e)
78 {
79 error("Failed to update u-boot env variables: {FLASHID}", "FLASHID",
80 flashId);
81 }
82 }
83
mirrorAlt()84 void 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");
90
91 try
92 {
93 bus.call_noreply(method);
94 }
95 catch (const sdbusplus::exception_t& e)
96 {
97 error("Failed to copy U-Boot to alternate chip: {ERROR}", "ERROR", e);
98 }
99 }
100
101 } // namespace updater
102 } // namespace software
103 } // namespace phosphor
104