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