blob: 748a6cf31bf648f20c31aee35dc15e8fb56789d3 [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>
Gunnar Millsb0ce9962018-09-07 13:39:10 -050012
Lei YUa7853ee2018-05-23 11:13:12 +080013namespace
14{
15constexpr auto PATH_INITRAMFS = "/run/initramfs";
Lei YUd8c9eea2021-12-16 16:08:30 +080016constexpr auto FLASH_ALT_SERVICE_TMPL = "obmc-flash-bmc-alt@";
Gunnar Millsfa34e022018-09-04 10:05:45 -050017} // namespace
Lei YUa7853ee2018-05-23 11:13:12 +080018
19namespace phosphor
20{
21namespace software
22{
23namespace updater
24{
25
Lei YUd8c9eea2021-12-16 16:08:30 +080026PHOSPHOR_LOG2_USING;
27
Adriana Kobylakc98d9122020-05-05 10:36:01 -050028namespace fs = std::filesystem;
Bright Cheng8e9ccfe2019-11-18 16:18:44 +080029using namespace phosphor::software::image;
Lei YUa7853ee2018-05-23 11:13:12 +080030
31void Activation::flashWrite()
32{
Lei YUd8c9eea2021-12-16 16:08:30 +080033#ifdef BMC_STATIC_DUAL_IMAGE
34 if (parent.runningImageSlot != 0)
35 {
36 // It's running on the secondary chip, update the primary one
37 info("Flashing primary flash from secondary, id: {ID}", "ID",
38 versionId);
39 auto method = bus.new_method_call(SYSTEMD_BUSNAME, SYSTEMD_PATH,
40 SYSTEMD_INTERFACE, "StartUnit");
41 auto serviceFile = FLASH_ALT_SERVICE_TMPL + versionId + ".service";
42 method.append(serviceFile, "replace");
43 bus.call_noreply(method);
44 return;
45 }
46#endif
Lei YUdd691572018-07-17 17:04:34 +080047 // For static layout code update, just put images in /run/initramfs.
Lei YUa7853ee2018-05-23 11:13:12 +080048 // It expects user to trigger a reboot and an updater script will program
49 // the image to flash during reboot.
50 fs::path uploadDir(IMG_UPLOAD_DIR);
51 fs::path toPath(PATH_INITRAMFS);
Bright Cheng8e9ccfe2019-11-18 16:18:44 +080052
53 for (const auto& bmcImage : parent.imageUpdateList)
Lei YUa7853ee2018-05-23 11:13:12 +080054 {
55 fs::copy_file(uploadDir / versionId / bmcImage, toPath / bmcImage,
56 fs::copy_options::overwrite_existing);
57 }
58}
59
Lei YUd8c9eea2021-12-16 16:08:30 +080060void Activation::onStateChanges(
61 [[maybe_unused]] sdbusplus::message::message& msg)
Lei YUa7853ee2018-05-23 11:13:12 +080062{
Lei YUd8c9eea2021-12-16 16:08:30 +080063#ifdef BMC_STATIC_DUAL_IMAGE
64 uint32_t newStateID;
65 auto serviceFile = FLASH_ALT_SERVICE_TMPL + versionId + ".service";
66 sdbusplus::message::object_path newStateObjPath;
67 std::string newStateUnit{};
68 std::string newStateResult{};
69 msg.read(newStateID, newStateObjPath, newStateUnit, newStateResult);
70
71 if (newStateUnit != serviceFile)
72 {
73 return;
74 }
75 if (newStateResult == "done")
76 {
77 activationProgress->progress(90);
78 onFlashWriteSuccess();
79 }
80 else
81 {
82 namespace softwareServer =
83 sdbusplus::xyz::openbmc_project::Software::server;
84 Activation::activation(softwareServer::Activation::Activations::Failed);
85 }
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