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 | |
Adriana Kobylak | 25773a7 | 2022-01-21 15:24:48 +0000 | [diff] [blame] | 54 | void Helper::removeVersion(const std::string& flashId) |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 55 | { |
Adriana Kobylak | 25773a7 | 2022-01-21 15:24:48 +0000 | [diff] [blame] | 56 | auto serviceFile = "obmc-flash-bmc-ubiro-remove@" + flashId + ".service"; |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 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 | |
Adriana Kobylak | 25773a7 | 2022-01-21 15:24:48 +0000 | [diff] [blame] | 65 | void Helper::updateUbootVersionId(const std::string& flashId) |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 66 | { |
| 67 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 68 | SYSTEMD_INTERFACE, "StartUnit"); |
Patrick Williams | fc33ba8 | 2024-08-16 15:19:54 -0400 | [diff] [blame^] | 69 | auto updateEnvVarsFile = |
| 70 | "obmc-flash-bmc-updateubootvars@" + flashId + ".service"; |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 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 | bf2bb2b | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 77 | catch (const sdbusplus::exception_t& e) |
Lei YU | 56aaf45 | 2018-06-21 16:09:44 +0800 | [diff] [blame] | 78 | { |
Adriana Kobylak | 25773a7 | 2022-01-21 15:24:48 +0000 | [diff] [blame] | 79 | error("Failed to update u-boot env variables: {FLASHID}", "FLASHID", |
| 80 | flashId); |
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 | } |
Patrick Williams | bf2bb2b | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 95 | catch (const sdbusplus::exception_t& 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 |