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 | bbcb7be | 2018-07-17 15:47:34 -0500 | [diff] [blame] | 18 | |
| 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 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 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 | |
| 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 | |
| 48 | void Helper::factoryReset() |
| 49 | { |
| 50 | // Mark the read-write partition for recreation upon reboot. |
Adriana Kobylak | 56ec62e | 2021-01-20 10:57:18 -0600 | [diff] [blame] | 51 | utils::execute("/sbin/fw_setenv", "rwreset", "true"); |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 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"); |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 72 | |
Adriana Kobylak | 3b6a4cd | 2018-12-10 13:45:09 -0600 | [diff] [blame] | 73 | try |
| 74 | { |
| 75 | bus.call_noreply(method); |
| 76 | } |
Patrick Williams | 4ce901c | 2021-09-02 09:34:45 -0500 | [diff] [blame] | 77 | catch (const sdbusplus::exception::exception& e) |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 78 | { |
Adriana Kobylak | 2af0fdf | 2021-09-01 19:36:46 +0000 | [diff] [blame] | 79 | error("Failed to update u-boot env variables", "VERSIONID", versionId); |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 80 | } |
| 81 | } |
| 82 | |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 83 | void Helper::mirrorAlt() |
| 84 | { |
| 85 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 86 | SYSTEMD_INTERFACE, "StartUnit"); |
| 87 | auto mirrorUbootFile = "obmc-flash-bmc-mirroruboot.service"; |
| 88 | method.append(mirrorUbootFile, "replace"); |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 89 | |
Adriana Kobylak | 3b6a4cd | 2018-12-10 13:45:09 -0600 | [diff] [blame] | 90 | try |
| 91 | { |
| 92 | bus.call_noreply(method); |
| 93 | } |
Patrick Williams | 4ce901c | 2021-09-02 09:34:45 -0500 | [diff] [blame] | 94 | catch (const sdbusplus::exception::exception& e) |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 95 | { |
Patrick Williams | c9bb642 | 2021-08-27 06:18:35 -0500 | [diff] [blame] | 96 | error("Failed to copy U-Boot to alternate chip: {ERROR}", "ERROR", e); |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
| 100 | } // namespace updater |
| 101 | } // namespace software |
| 102 | } // namespace phosphor |