blob: 1076068b2980191e85a3b6ea46c488a750fd582c [file] [log] [blame]
Gunnar Millsf6ed5892018-09-07 17:08:02 -05001#include "config.h"
2
Lei YUf3ce4332019-02-21 14:09:49 +08003#ifdef UBIFS_LAYOUT
4#include "ubi/item_updater_ubi.hpp"
Lei YUda6ab6c2019-02-22 14:21:22 +08005#include "ubi/watch.hpp"
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -05006#elif defined MMC_LAYOUT
7#include "mmc/item_updater_mmc.hpp"
Lei YU322f3f42019-02-21 16:10:41 +08008#else
9#include "static/item_updater_static.hpp"
Lei YUf3ce4332019-02-21 14:09:49 +080010#endif
Brad Bishop099543e2020-11-09 15:37:58 -050011#include "functions.hpp"
Gunnar Millsf6ed5892018-09-07 17:08:02 -050012
Brad Bishop099543e2020-11-09 15:37:58 -050013#include <CLI/CLI.hpp>
Gunnar Millsf6ed5892018-09-07 17:08:02 -050014#include <phosphor-logging/log.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050015#include <sdbusplus/bus.hpp>
16#include <sdbusplus/server/manager.hpp>
Brad Bishop0283f7c2020-11-09 10:09:26 -050017#include <sdeventplus/event.hpp>
Brad Bishop8facccf2020-11-04 09:44:58 -050018
Brad Bishop099543e2020-11-09 15:37:58 -050019#include <map>
20#include <memory>
21#include <string>
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050022#include <system_error>
Brad Bishop099543e2020-11-09 15:37:58 -050023#include <vector>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050024
Brad Bishop1ee90952020-11-09 11:57:32 -050025namespace openpower
26{
27namespace software
28{
29namespace updater
30{
Patrick Williams0dea1992022-07-22 19:26:52 -050031void initializeService(sdbusplus::bus_t& bus)
Brad Bishop1ee90952020-11-09 11:57:32 -050032{
Patrick Williams0dea1992022-07-22 19:26:52 -050033 static sdbusplus::server::manager_t objManager(bus, SOFTWARE_OBJPATH);
Brad Bishop1ee90952020-11-09 11:57:32 -050034#ifdef UBIFS_LAYOUT
35 static ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH);
36 static Watch watch(
37 bus.get_event(),
38 std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation),
39 &updater, std::placeholders::_1));
40#elif defined MMC_LAYOUT
41 static ItemUpdaterMMC updater(bus, SOFTWARE_OBJPATH);
42#else
43 static ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH);
44#endif
45 bus.request_name(BUSNAME_UPDATER);
46}
47} // namespace updater
48} // namespace software
49} // namespace openpower
50
Brad Bishop099543e2020-11-09 15:37:58 -050051int main(int argc, char* argv[])
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050052{
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050053 using namespace openpower::software::updater;
54 using namespace phosphor::logging;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050055 auto bus = sdbusplus::bus::new_default();
Brad Bishop0283f7c2020-11-09 10:09:26 -050056 auto loop = sdeventplus::Event::get_default();
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050057
Brad Bishop1ee90952020-11-09 11:57:32 -050058 bus.attach_event(loop.get(), SD_EVENT_PRIORITY_NORMAL);
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050059
Brad Bishop099543e2020-11-09 15:37:58 -050060 CLI::App app{"OpenPOWER host firmware manager"};
61
Adriana Kobylak53a27392021-06-14 17:42:40 +000062 using namespace std::string_literals;
63 std::map<std::string, std::vector<std::string>> extensionMap{{
Adriana Kobylak749bdcc2024-01-17 12:56:00 -060064 {"com.ibm.Hardware.Chassis.Model.Bonnell"s, {".BONNELL_XML"s, ".P10"s}},
65 {"com.ibm.Hardware.Chassis.Model.Everest"s, {".EVEREST_XML"s, ".P10"s}},
66 {"com.ibm.Hardware.Chassis.Model.Rainier2U"s,
67 {".RAINIER_2U_XML"s, ".P10"s}},
68 {"com.ibm.Hardware.Chassis.Model.Rainier4U"s,
69 {".RAINIER_4U_XML"s, ".P10"s}},
70 {"com.ibm.Hardware.Chassis.Model.Rainier1S4U"s,
71 {".RAINIER_4U_XML"s, ".P10"s}},
Adriana Kobylak53a27392021-06-14 17:42:40 +000072 }};
73
Brad Bishop099543e2020-11-09 15:37:58 -050074 // subcommandContext allows program subcommand callbacks to add loop event
75 // callbacks (e.g. reception of a dbus signal) and then return to main,
76 // without the loop event callback being destroyed until the loop event
77 // callback has a chance to run and instruct the loop to exit.
Adriana Kobylak53a27392021-06-14 17:42:40 +000078 std::vector<std::shared_ptr<void>> subcommandContext;
Brad Bishop099543e2020-11-09 15:37:58 -050079 static_cast<void>(
80 app.add_subcommand("process-host-firmware",
81 "Point the host firmware at its data.")
Adriana Kobylak53a27392021-06-14 17:42:40 +000082 ->callback([&bus, &loop, &subcommandContext, extensionMap]() {
Patrick Williamsaf29f722023-10-20 11:18:27 -050083 auto hostFirmwareDirectory = "/media/hostfw/running"s;
84 auto logCallback = [](const auto& path, auto& ec) {
85 std::cerr << path << ": " << ec.message() << "\n";
86 };
87 subcommandContext.push_back(
88 functions::process_hostfirmware::processHostFirmware(
89 bus, extensionMap, std::move(hostFirmwareDirectory),
90 std::move(logCallback), loop));
91 }));
Adriana Kobylak53a27392021-06-14 17:42:40 +000092 static_cast<void>(
93 app.add_subcommand("update-bios-attr-table",
94 "Update the bios attribute table with the host "
95 "firmware data details.")
Patrick Williamsaf29f722023-10-20 11:18:27 -050096 ->callback([&bus, &loop, &subcommandContext, extensionMap]() {
Patrick Williams7fb6c342023-05-10 07:50:18 -050097 auto elementsJsonFilePath = "/usr/share/hostfw/elements.json"s;
98 auto subcommands = functions::process_hostfirmware::updateBiosAttrTable(
99 bus, extensionMap, std::move(elementsJsonFilePath), loop);
100 for (const auto& subcommand : subcommands)
101 {
102 subcommandContext.push_back(subcommand);
103 }
Patrick Williamsaf29f722023-10-20 11:18:27 -0500104 }));
Adriana Kobylak53a27392021-06-14 17:42:40 +0000105
Brad Bishop099543e2020-11-09 15:37:58 -0500106 CLI11_PARSE(app, argc, argv);
107
108 if (app.get_subcommands().size() == 0)
109 {
110 initializeService(bus);
111 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500112
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -0500113 try
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500114 {
Brad Bishop0283f7c2020-11-09 10:09:26 -0500115 auto rc = loop.loop();
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -0500116 if (rc < 0)
117 {
118 log<level::ERR>("Error occurred during the sd_event_loop",
119 entry("RC=%d", rc));
120 return -1;
121 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500122 }
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -0500123 catch (const std::system_error& e)
124 {
125 log<level::ERR>(e.what());
126 return -1;
127 }
128
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500129 return 0;
130}