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> |
Adriana Kobylak | 3b6a4cd | 2018-12-10 13:45:09 -0600 | [diff] [blame] | 6 | #include <sdbusplus/exception.hpp> |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 7 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 8 | namespace phosphor |
| 9 | { |
| 10 | namespace software |
| 11 | { |
| 12 | namespace updater |
| 13 | { |
| 14 | |
| 15 | using namespace phosphor::logging; |
Adriana Kobylak | 3b6a4cd | 2018-12-10 13:45:09 -0600 | [diff] [blame] | 16 | using sdbusplus::exception::SdBusError; |
Adriana Kobylak | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 17 | |
| 18 | void Helper::setEntry(const std::string& entryId, uint8_t value) |
| 19 | { |
| 20 | std::string serviceFile = "obmc-flash-bmc-setenv@" + entryId + "\\x3d" + |
| 21 | std::to_string(value) + ".service"; |
| 22 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 23 | SYSTEMD_INTERFACE, "StartUnit"); |
| 24 | method.append(serviceFile, "replace"); |
| 25 | bus.call_noreply(method); |
| 26 | } |
| 27 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 28 | void Helper::clearEntry(const std::string& entryId) |
| 29 | { |
| 30 | // Remove the priority environment variable. |
| 31 | auto serviceFile = "obmc-flash-bmc-setenv@" + entryId + ".service"; |
| 32 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 33 | SYSTEMD_INTERFACE, "StartUnit"); |
| 34 | method.append(serviceFile, "replace"); |
| 35 | bus.call_noreply(method); |
| 36 | } |
| 37 | |
| 38 | void Helper::cleanup() |
| 39 | { |
| 40 | // Remove any volumes that do not match current versions. |
| 41 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 42 | SYSTEMD_INTERFACE, "StartUnit"); |
| 43 | method.append("obmc-flash-bmc-cleanup.service", "replace"); |
| 44 | bus.call_noreply(method); |
| 45 | } |
| 46 | |
| 47 | void Helper::factoryReset() |
| 48 | { |
| 49 | // Mark the read-write partition for recreation upon reboot. |
| 50 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 51 | SYSTEMD_INTERFACE, "StartUnit"); |
| 52 | method.append("obmc-flash-bmc-setenv@rwreset\\x3dtrue.service", "replace"); |
| 53 | bus.call_noreply(method); |
| 54 | } |
| 55 | |
| 56 | void Helper::removeVersion(const std::string& versionId) |
| 57 | { |
| 58 | auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + versionId + ".service"; |
| 59 | |
| 60 | // Remove the read-only partitions. |
| 61 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 62 | SYSTEMD_INTERFACE, "StartUnit"); |
| 63 | method.append(serviceFile, "replace"); |
| 64 | bus.call_noreply(method); |
| 65 | } |
| 66 | |
| 67 | void Helper::updateUbootVersionId(const std::string& versionId) |
| 68 | { |
| 69 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 70 | SYSTEMD_INTERFACE, "StartUnit"); |
| 71 | auto updateEnvVarsFile = |
| 72 | "obmc-flash-bmc-updateubootvars@" + versionId + ".service"; |
| 73 | method.append(updateEnvVarsFile, "replace"); |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 74 | |
Adriana Kobylak | 3b6a4cd | 2018-12-10 13:45:09 -0600 | [diff] [blame] | 75 | try |
| 76 | { |
| 77 | bus.call_noreply(method); |
| 78 | } |
| 79 | catch (const SdBusError& e) |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 80 | { |
| 81 | log<level::ERR>("Failed to update u-boot env variables", |
| 82 | entry("VERSIONID=%s", versionId.c_str())); |
| 83 | } |
| 84 | } |
| 85 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 86 | void Helper::mirrorAlt() |
| 87 | { |
| 88 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 89 | SYSTEMD_INTERFACE, "StartUnit"); |
| 90 | auto mirrorUbootFile = "obmc-flash-bmc-mirroruboot.service"; |
| 91 | method.append(mirrorUbootFile, "replace"); |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 92 | |
Adriana Kobylak | 3b6a4cd | 2018-12-10 13:45:09 -0600 | [diff] [blame] | 93 | try |
| 94 | { |
| 95 | bus.call_noreply(method); |
| 96 | } |
| 97 | catch (const SdBusError& e) |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 98 | { |
| 99 | log<level::ERR>("Failed to copy U-Boot to alternate chip"); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | } // namespace updater |
| 104 | } // namespace software |
| 105 | } // namespace phosphor |