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 | |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame^] | 7 | #include <phosphor-logging/lg2.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 | |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame^] | 17 | PHOSPHOR_LOG2_USING; |
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 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame^] | 80 | error("Failed to update u-boot env variables", "VERSIONID", versionid); |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 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"); |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 90 | |
Adriana Kobylak | 3b6a4cd | 2018-12-10 13:45:09 -0600 | [diff] [blame] | 91 | try |
| 92 | { |
| 93 | bus.call_noreply(method); |
| 94 | } |
| 95 | catch (const SdBusError& e) |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 96 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame^] | 97 | error("Failed to copy U-Boot to alternate chip: {ERROR}", "ERROR", e); |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
| 101 | } // namespace updater |
| 102 | } // namespace software |
| 103 | } // namespace phosphor |