blob: a478644b527975b91e65f139752319a6692bca07 [file] [log] [blame]
Gunnar Millsb0ce9962018-09-07 13:39:10 -05001#include "config.h"
2
3#include "flash.hpp"
Lei YUa7853ee2018-05-23 11:13:12 +08004
5#include "activation.hpp"
Lei YU1be8d502018-06-20 11:48:36 +08006#include "images.hpp"
Bright Cheng8e9ccfe2019-11-18 16:18:44 +08007#include "item_updater.hpp"
Lei YUa7853ee2018-05-23 11:13:12 +08008
Lei YUd8c9eea2021-12-16 16:08:30 +08009#include <phosphor-logging/lg2.hpp>
10
Adriana Kobylakc98d9122020-05-05 10:36:01 -050011#include <filesystem>
George Liu44b9fef2023-02-07 14:31:32 +080012#include <system_error>
Gunnar Millsb0ce9962018-09-07 13:39:10 -050013
Lei YUa7853ee2018-05-23 11:13:12 +080014namespace
15{
16constexpr auto PATH_INITRAMFS = "/run/initramfs";
Lei YUd8c9eea2021-12-16 16:08:30 +080017constexpr auto FLASH_ALT_SERVICE_TMPL = "obmc-flash-bmc-alt@";
Gunnar Millsfa34e022018-09-04 10:05:45 -050018} // namespace
Lei YUa7853ee2018-05-23 11:13:12 +080019
20namespace phosphor
21{
22namespace software
23{
24namespace updater
25{
26
Lei YUd8c9eea2021-12-16 16:08:30 +080027PHOSPHOR_LOG2_USING;
28
Adriana Kobylakc98d9122020-05-05 10:36:01 -050029namespace fs = std::filesystem;
Bright Cheng8e9ccfe2019-11-18 16:18:44 +080030using namespace phosphor::software::image;
Lei YUa7853ee2018-05-23 11:13:12 +080031
32void Activation::flashWrite()
33{
Lei YUd8c9eea2021-12-16 16:08:30 +080034#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 YUdd691572018-07-17 17:04:34 +080048 // For static layout code update, just put images in /run/initramfs.
Lei YUa7853ee2018-05-23 11:13:12 +080049 // 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 Cheng8e9ccfe2019-11-18 16:18:44 +080053
54 for (const auto& bmcImage : parent.imageUpdateList)
Lei YUa7853ee2018-05-23 11:13:12 +080055 {
George Liu44b9fef2023-02-07 14:31:32 +080056 std::error_code ec;
Lei YUa7853ee2018-05-23 11:13:12 +080057 fs::copy_file(uploadDir / versionId / bmcImage, toPath / bmcImage,
George Liu44b9fef2023-02-07 14:31:32 +080058 fs::copy_options::overwrite_existing, ec);
Lei YUa7853ee2018-05-23 11:13:12 +080059 }
60}
61
Patrick Williamsbf2bb2b2022-07-22 19:26:52 -050062void Activation::onStateChanges([[maybe_unused]] sdbusplus::message_t& msg)
Lei YUa7853ee2018-05-23 11:13:12 +080063{
Lei YUd8c9eea2021-12-16 16:08:30 +080064#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 Williams1e9a5f12023-08-23 16:53:06 -050083 Activation::activation(sdbusplus::server::xyz::openbmc_project::
84 software::Activation::Activations::Failed);
Lei YUd8c9eea2021-12-16 16:08:30 +080085 }
86#endif
Lei YUa7853ee2018-05-23 11:13:12 +080087}
88
89} // namespace updater
90} // namespace software
Gunnar Millsfa34e022018-09-04 10:05:45 -050091} // namespace phosphor