Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
| 3 | #include "flash.hpp" |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 4 | |
| 5 | #include "activation.hpp" |
Lei YU | 1be8d50 | 2018-06-20 11:48:36 +0800 | [diff] [blame] | 6 | #include "images.hpp" |
Bright Cheng | 8e9ccfe | 2019-11-18 16:18:44 +0800 | [diff] [blame] | 7 | #include "item_updater.hpp" |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 8 | |
Lei YU | d8c9eea | 2021-12-16 16:08:30 +0800 | [diff] [blame] | 9 | #include <phosphor-logging/lg2.hpp> |
| 10 | |
Adriana Kobylak | c98d912 | 2020-05-05 10:36:01 -0500 | [diff] [blame] | 11 | #include <filesystem> |
George Liu | 44b9fef | 2023-02-07 14:31:32 +0800 | [diff] [blame] | 12 | #include <system_error> |
Gunnar Mills | b0ce996 | 2018-09-07 13:39:10 -0500 | [diff] [blame] | 13 | |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 14 | namespace |
| 15 | { |
| 16 | constexpr auto PATH_INITRAMFS = "/run/initramfs"; |
Lei YU | d8c9eea | 2021-12-16 16:08:30 +0800 | [diff] [blame] | 17 | constexpr auto FLASH_ALT_SERVICE_TMPL = "obmc-flash-bmc-alt@"; |
Gunnar Mills | fa34e02 | 2018-09-04 10:05:45 -0500 | [diff] [blame] | 18 | } // namespace |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 19 | |
| 20 | namespace phosphor |
| 21 | { |
| 22 | namespace software |
| 23 | { |
| 24 | namespace updater |
| 25 | { |
| 26 | |
Lei YU | d8c9eea | 2021-12-16 16:08:30 +0800 | [diff] [blame] | 27 | PHOSPHOR_LOG2_USING; |
| 28 | |
Adriana Kobylak | c98d912 | 2020-05-05 10:36:01 -0500 | [diff] [blame] | 29 | namespace fs = std::filesystem; |
Bright Cheng | 8e9ccfe | 2019-11-18 16:18:44 +0800 | [diff] [blame] | 30 | using namespace phosphor::software::image; |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 31 | |
| 32 | void Activation::flashWrite() |
| 33 | { |
Lei YU | d8c9eea | 2021-12-16 16:08:30 +0800 | [diff] [blame] | 34 | #ifdef BMC_STATIC_DUAL_IMAGE |
| 35 | if (parent.runningImageSlot != 0) |
| 36 | { |
| 37 | // It's running on the secondary chip, update the primary one |
| 38 | info("Flashing primary flash from secondary, id: {ID}", "ID", |
| 39 | versionId); |
| 40 | auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH, |
| 41 | SYSTEMD_INTERFACE, "StartUnit"); |
| 42 | auto serviceFile = FLASH_ALT_SERVICE_TMPL + versionId + ".service"; |
| 43 | method.append(serviceFile, "replace"); |
| 44 | bus.call_noreply(method); |
| 45 | return; |
| 46 | } |
| 47 | #endif |
Lei YU | dd69157 | 2018-07-17 17:04:34 +0800 | [diff] [blame] | 48 | // For static layout code update, just put images in /run/initramfs. |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 49 | // It expects user to trigger a reboot and an updater script will program |
| 50 | // the image to flash during reboot. |
| 51 | fs::path uploadDir(IMG_UPLOAD_DIR); |
| 52 | fs::path toPath(PATH_INITRAMFS); |
Bright Cheng | 8e9ccfe | 2019-11-18 16:18:44 +0800 | [diff] [blame] | 53 | |
| 54 | for (const auto& bmcImage : parent.imageUpdateList) |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 55 | { |
George Liu | 44b9fef | 2023-02-07 14:31:32 +0800 | [diff] [blame] | 56 | std::error_code ec; |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 57 | fs::copy_file(uploadDir / versionId / bmcImage, toPath / bmcImage, |
George Liu | 44b9fef | 2023-02-07 14:31:32 +0800 | [diff] [blame] | 58 | fs::copy_options::overwrite_existing, ec); |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
Patrick Williams | bf2bb2b | 2022-07-22 19:26:52 -0500 | [diff] [blame] | 62 | void Activation::onStateChanges([[maybe_unused]] sdbusplus::message_t& msg) |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 63 | { |
Lei YU | d8c9eea | 2021-12-16 16:08:30 +0800 | [diff] [blame] | 64 | #ifdef BMC_STATIC_DUAL_IMAGE |
| 65 | uint32_t newStateID; |
| 66 | auto serviceFile = FLASH_ALT_SERVICE_TMPL + versionId + ".service"; |
| 67 | sdbusplus::message::object_path newStateObjPath; |
| 68 | std::string newStateUnit{}; |
| 69 | std::string newStateResult{}; |
| 70 | msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult); |
| 71 | |
| 72 | if (newStateUnit != serviceFile) |
| 73 | { |
| 74 | return; |
| 75 | } |
| 76 | if (newStateResult == "done") |
| 77 | { |
| 78 | activationProgress->progress(90); |
| 79 | onFlashWriteSuccess(); |
| 80 | } |
| 81 | else |
| 82 | { |
Patrick Williams | 1e9a5f1 | 2023-08-23 16:53:06 -0500 | [diff] [blame] | 83 | Activation::activation(sdbusplus::server::xyz::openbmc_project:: |
| 84 | software::Activation::Activations::Failed); |
Lei YU | d8c9eea | 2021-12-16 16:08:30 +0800 | [diff] [blame] | 85 | } |
| 86 | #endif |
Lei YU | a7853ee | 2018-05-23 11:13:12 +0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | } // namespace updater |
| 90 | } // namespace software |
Gunnar Mills | fa34e02 | 2018-09-04 10:05:45 -0500 | [diff] [blame] | 91 | } // namespace phosphor |