Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 1 | #include "config.h" |
| 2 | |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 3 | #ifdef UBIFS_LAYOUT |
| 4 | #include "ubi/item_updater_ubi.hpp" |
Lei YU | da6ab6c | 2019-02-22 14:21:22 +0800 | [diff] [blame] | 5 | #include "ubi/watch.hpp" |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 6 | #elif defined MMC_LAYOUT |
| 7 | #include "mmc/item_updater_mmc.hpp" |
Lei YU | 322f3f4 | 2019-02-21 16:10:41 +0800 | [diff] [blame] | 8 | #else |
| 9 | #include "static/item_updater_static.hpp" |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 10 | #endif |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 11 | #include "functions.hpp" |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 12 | |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 13 | #include <CLI/CLI.hpp> |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 14 | #include <phosphor-logging/log.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 15 | #include <sdbusplus/bus.hpp> |
| 16 | #include <sdbusplus/server/manager.hpp> |
Brad Bishop | 0283f7c | 2020-11-09 10:09:26 -0500 | [diff] [blame] | 17 | #include <sdeventplus/event.hpp> |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 18 | |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 19 | #include <map> |
| 20 | #include <memory> |
| 21 | #include <string> |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 22 | #include <system_error> |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 23 | #include <vector> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 24 | |
Brad Bishop | 1ee9095 | 2020-11-09 11:57:32 -0500 | [diff] [blame] | 25 | namespace openpower |
| 26 | { |
| 27 | namespace software |
| 28 | { |
| 29 | namespace updater |
| 30 | { |
| 31 | void initializeService(sdbusplus::bus::bus& bus) |
| 32 | { |
Brad Bishop | 4dcf55d | 2020-12-16 12:20:42 -0500 | [diff] [blame] | 33 | static sdbusplus::server::manager::manager objManager(bus, |
| 34 | SOFTWARE_OBJPATH); |
Brad Bishop | 1ee9095 | 2020-11-09 11:57:32 -0500 | [diff] [blame] | 35 | #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 Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 52 | int main(int argc, char* argv[]) |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 53 | { |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 54 | using namespace openpower::software::updater; |
| 55 | using namespace phosphor::logging; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 56 | auto bus = sdbusplus::bus::new_default(); |
Brad Bishop | 0283f7c | 2020-11-09 10:09:26 -0500 | [diff] [blame] | 57 | auto loop = sdeventplus::Event::get_default(); |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 58 | |
Brad Bishop | 1ee9095 | 2020-11-09 11:57:32 -0500 | [diff] [blame] | 59 | bus.attach_event(loop.get(), SD_EVENT_PRIORITY_NORMAL); |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 60 | |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 61 | CLI::App app{"OpenPOWER host firmware manager"}; |
| 62 | |
Adriana Kobylak | 53a2739 | 2021-06-14 17:42:40 +0000 | [diff] [blame^] | 63 | using namespace std::string_literals; |
| 64 | std::map<std::string, std::vector<std::string>> extensionMap{{ |
| 65 | {"ibm,everest"s, {".EVEREST_XML"s, ".P10"s}}, |
| 66 | {"ibm,rainier-2u"s, {".RAINIER_2U_XML"s, ".P10"s}}, |
| 67 | {"ibm,rainier-4u"s, {".RAINIER_4U_XML"s, ".P10"s}}, |
| 68 | {"ibm,rainier-1s4u"s, {".RAINIER_4U_XML"s, ".P10"s}}, |
| 69 | }}; |
| 70 | |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 71 | // subcommandContext allows program subcommand callbacks to add loop event |
| 72 | // callbacks (e.g. reception of a dbus signal) and then return to main, |
| 73 | // without the loop event callback being destroyed until the loop event |
| 74 | // callback has a chance to run and instruct the loop to exit. |
Adriana Kobylak | 53a2739 | 2021-06-14 17:42:40 +0000 | [diff] [blame^] | 75 | std::vector<std::shared_ptr<void>> subcommandContext; |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 76 | static_cast<void>( |
| 77 | app.add_subcommand("process-host-firmware", |
| 78 | "Point the host firmware at its data.") |
Adriana Kobylak | 53a2739 | 2021-06-14 17:42:40 +0000 | [diff] [blame^] | 79 | ->callback([&bus, &loop, &subcommandContext, extensionMap]() { |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 80 | auto hostFirmwareDirectory = "/media/hostfw/running"s; |
| 81 | auto logCallback = [](const auto& path, auto& ec) { |
| 82 | std::cerr << path << ": " << ec.message() << "\n"; |
| 83 | }; |
Adriana Kobylak | 53a2739 | 2021-06-14 17:42:40 +0000 | [diff] [blame^] | 84 | subcommandContext.push_back( |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 85 | functions::process_hostfirmware::processHostFirmware( |
Adriana Kobylak | 53a2739 | 2021-06-14 17:42:40 +0000 | [diff] [blame^] | 86 | bus, extensionMap, std::move(hostFirmwareDirectory), |
| 87 | std::move(logCallback), loop)); |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 88 | })); |
Adriana Kobylak | 53a2739 | 2021-06-14 17:42:40 +0000 | [diff] [blame^] | 89 | static_cast<void>( |
| 90 | app.add_subcommand("update-bios-attr-table", |
| 91 | "Update the bios attribute table with the host " |
| 92 | "firmware data details.") |
| 93 | ->callback([&bus, &loop, &subcommandContext, extensionMap]() { |
| 94 | subcommandContext.push_back( |
| 95 | functions::process_hostfirmware::updateBiosAttrTable( |
| 96 | bus, extensionMap, loop)); |
| 97 | })); |
| 98 | |
Brad Bishop | 099543e | 2020-11-09 15:37:58 -0500 | [diff] [blame] | 99 | CLI11_PARSE(app, argc, argv); |
| 100 | |
| 101 | if (app.get_subcommands().size() == 0) |
| 102 | { |
| 103 | initializeService(bus); |
| 104 | } |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 105 | |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 106 | try |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 107 | { |
Brad Bishop | 0283f7c | 2020-11-09 10:09:26 -0500 | [diff] [blame] | 108 | auto rc = loop.loop(); |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 109 | if (rc < 0) |
| 110 | { |
| 111 | log<level::ERR>("Error occurred during the sd_event_loop", |
| 112 | entry("RC=%d", rc)); |
| 113 | return -1; |
| 114 | } |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 115 | } |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 116 | catch (const std::system_error& e) |
| 117 | { |
| 118 | log<level::ERR>(e.what()); |
| 119 | return -1; |
| 120 | } |
| 121 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 122 | return 0; |
| 123 | } |