Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 1 | #include "config.h" |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 2 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 3 | #include "item_updater_helper.hpp" |
| 4 | |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/log.hpp> |
| 6 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 7 | namespace phosphor |
| 8 | { |
| 9 | namespace software |
| 10 | { |
| 11 | namespace updater |
| 12 | { |
| 13 | |
| 14 | using namespace phosphor::logging; |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 15 | |
| 16 | void Helper::setEntry(const std::string& entryId, uint8_t value) |
| 17 | { |
| 18 | std::string serviceFile = "obmc-flash-bmc-setenv@" + entryId + "\\x3d" + |
| 19 | std::to_string(value) + ".service"; |
| 20 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 21 | SYSTEMD_INTERFACE, "StartUnit"); |
| 22 | method.append(serviceFile, "replace"); |
| 23 | bus.call_noreply(method); |
| 24 | } |
| 25 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 26 | void Helper::clearEntry(const std::string& entryId) |
| 27 | { |
| 28 | // Remove the priority environment variable. |
| 29 | auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service"; |
| 30 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 31 | SYSTEMD_INTERFACE, "StartUnit"); |
| 32 | method.append(serviceFile, "replace"); |
| 33 | bus.call_noreply(method); |
| 34 | } |
| 35 | |
| 36 | void Helper::cleanup() |
| 37 | { |
| 38 | // Remove any volumes that do not match current versions. |
| 39 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 40 | SYSTEMD_INTERFACE, "StartUnit"); |
| 41 | method.append("obmc-flash-bmc-cleanup.service", "replace"); |
| 42 | bus.call_noreply(method); |
| 43 | } |
| 44 | |
| 45 | void Helper::factoryReset() |
| 46 | { |
| 47 | // Mark the read-write partition for recreation upon reboot. |
| 48 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 49 | SYSTEMD_INTERFACE, "StartUnit"); |
| 50 | method.append("obmc-flash-bmc-setenv@rwreset\\x3dtrue.service", "replace"); |
| 51 | bus.call_noreply(method); |
| 52 | } |
| 53 | |
| 54 | void 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 | |
| 65 | void 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"); |
| 72 | auto result = bus.call(method); |
| 73 | |
| 74 | // Check that the bus call didn't result in an error |
| 75 | if (result.is_method_error()) |
| 76 | { |
| 77 | log<level::ERR>("Failed to update u-boot env variables", |
| 78 | entry("VERSIONID=%s", versionId.c_str())); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | void Helper::enableFieldMode() |
| 83 | { |
| 84 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 85 | SYSTEMD_INTERFACE, "StartUnit"); |
| 86 | method.append("obmc-flash-bmc-setenv@fieldmode\\x3dtrue.service", |
| 87 | "replace"); |
| 88 | bus.call_noreply(method); |
| 89 | |
| 90 | method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 91 | SYSTEMD_INTERFACE, "StopUnit"); |
| 92 | method.append("usr-local.mount", "replace"); |
| 93 | bus.call_noreply(method); |
| 94 | |
| 95 | std::vector<std::string> usrLocal = {"usr-local.mount"}; |
| 96 | |
| 97 | method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 98 | SYSTEMD_INTERFACE, "MaskUnitFiles"); |
| 99 | method.append(usrLocal, false, true); |
| 100 | bus.call_noreply(method); |
| 101 | } |
| 102 | void Helper::mirrorAlt() |
| 103 | { |
| 104 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 105 | SYSTEMD_INTERFACE, "StartUnit"); |
| 106 | auto mirrorUbootFile = "obmc-flash-bmc-mirroruboot.service"; |
| 107 | method.append(mirrorUbootFile, "replace"); |
| 108 | auto result = bus.call(method); |
| 109 | |
| 110 | // Check that the bus call didn't result in an error |
| 111 | if (result.is_method_error()) |
| 112 | { |
| 113 | log<level::ERR>("Failed to copy U-Boot to alternate chip"); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | } // namespace updater |
| 118 | } // namespace software |
| 119 | } // namespace phosphor |