blob: 31a58bd2c85104a1533157192b840693da27734f [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{
31void initializeService(sdbusplus::bus::bus& bus)
32{
Brad Bishop4dcf55d2020-12-16 12:20:42 -050033 static sdbusplus::server::manager::manager objManager(bus,
34 SOFTWARE_OBJPATH);
Brad Bishop1ee90952020-11-09 11:57:32 -050035#ifdef UBIFS_LAYOUT
36 static ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH);
37 static Watch watch(
38 bus.get_event(),
39 std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation),
40 &updater, std::placeholders::_1));
41#elif defined MMC_LAYOUT
42 static ItemUpdaterMMC updater(bus, SOFTWARE_OBJPATH);
43#else
44 static ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH);
45#endif
46 bus.request_name(BUSNAME_UPDATER);
47}
48} // namespace updater
49} // namespace software
50} // namespace openpower
51
Brad Bishop099543e2020-11-09 15:37:58 -050052int main(int argc, char* argv[])
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050053{
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050054 using namespace openpower::software::updater;
55 using namespace phosphor::logging;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050056 auto bus = sdbusplus::bus::new_default();
Brad Bishop0283f7c2020-11-09 10:09:26 -050057 auto loop = sdeventplus::Event::get_default();
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050058
Brad Bishop1ee90952020-11-09 11:57:32 -050059 bus.attach_event(loop.get(), SD_EVENT_PRIORITY_NORMAL);
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050060
Brad Bishop099543e2020-11-09 15:37:58 -050061 CLI::App app{"OpenPOWER host firmware manager"};
62
63 // subcommandContext allows program subcommand callbacks to add loop event
64 // callbacks (e.g. reception of a dbus signal) and then return to main,
65 // without the loop event callback being destroyed until the loop event
66 // callback has a chance to run and instruct the loop to exit.
67 std::shared_ptr<void> subcommandContext;
68 static_cast<void>(
69 app.add_subcommand("process-host-firmware",
70 "Point the host firmware at its data.")
71 ->callback([&bus, &loop, &subcommandContext]() {
72 using namespace std::string_literals;
73 std::map<std::string, std::vector<std::string>> extensionMap{{
74 {"ibm,rainier-2u"s, {".RAINIER_2U_XML"s, ".P10"s}},
75 {"ibm,rainier-4u"s, {".RAINIER_4U_XML"s, ".P10"s}},
76 }};
77 auto hostFirmwareDirectory = "/media/hostfw/running"s;
78 auto logCallback = [](const auto& path, auto& ec) {
79 std::cerr << path << ": " << ec.message() << "\n";
80 };
81 subcommandContext =
82 functions::process_hostfirmware::processHostFirmware(
83 bus, std::move(extensionMap),
84 std::move(hostFirmwareDirectory),
85 std::move(logCallback), loop);
86 }));
87 CLI11_PARSE(app, argc, argv);
88
89 if (app.get_subcommands().size() == 0)
90 {
91 initializeService(bus);
92 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050093
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050094 try
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050095 {
Brad Bishop0283f7c2020-11-09 10:09:26 -050096 auto rc = loop.loop();
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050097 if (rc < 0)
98 {
99 log<level::ERR>("Error occurred during the sd_event_loop",
100 entry("RC=%d", rc));
101 return -1;
102 }
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500103 }
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -0500104 catch (const std::system_error& e)
105 {
106 log<level::ERR>(e.what());
107 return -1;
108 }
109
Adriana Kobylak2d8fa222017-03-15 12:34:32 -0500110 return 0;
111}