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 |
Gunnar Mills | f6ed589 | 2018-09-07 17:08:02 -0500 | [diff] [blame] | 11 | |
| 12 | #include <phosphor-logging/log.hpp> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 13 | #include <sdbusplus/bus.hpp> |
| 14 | #include <sdbusplus/server/manager.hpp> |
Brad Bishop | 0283f7c | 2020-11-09 10:09:26 -0500 | [diff] [blame^] | 15 | #include <sdeventplus/event.hpp> |
Brad Bishop | 8facccf | 2020-11-04 09:44:58 -0500 | [diff] [blame] | 16 | |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 17 | #include <system_error> |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 18 | |
Brad Bishop | c8f2250 | 2020-11-06 14:42:09 -0500 | [diff] [blame] | 19 | int main(int, char*[]) |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 20 | { |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 21 | using namespace openpower::software::updater; |
| 22 | using namespace phosphor::logging; |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 23 | auto bus = sdbusplus::bus::new_default(); |
Brad Bishop | 0283f7c | 2020-11-09 10:09:26 -0500 | [diff] [blame^] | 24 | auto loop = sdeventplus::Event::get_default(); |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 25 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 26 | // Add sdbusplus ObjectManager. |
| 27 | sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH); |
| 28 | |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 29 | #ifdef UBIFS_LAYOUT |
| 30 | ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH); |
Adriana Kobylak | 8bc2ab4 | 2020-07-15 09:16:27 -0500 | [diff] [blame] | 31 | #elif defined MMC_LAYOUT |
| 32 | ItemUpdaterMMC updater(bus, SOFTWARE_OBJPATH); |
Lei YU | 322f3f4 | 2019-02-21 16:10:41 +0800 | [diff] [blame] | 33 | #else |
| 34 | ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH); |
Lei YU | f3ce433 | 2019-02-21 14:09:49 +0800 | [diff] [blame] | 35 | #endif |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 36 | |
| 37 | bus.request_name(BUSNAME_UPDATER); |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 38 | try |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 39 | { |
Lei YU | da6ab6c | 2019-02-22 14:21:22 +0800 | [diff] [blame] | 40 | #ifdef UBIFS_LAYOUT |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 41 | openpower::software::updater::Watch watch( |
Brad Bishop | 0283f7c | 2020-11-09 10:09:26 -0500 | [diff] [blame^] | 42 | loop.get(), |
Adriana Kobylak | 70dcb63 | 2018-02-27 15:46:52 -0600 | [diff] [blame] | 43 | std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation), |
| 44 | &updater, std::placeholders::_1)); |
Lei YU | da6ab6c | 2019-02-22 14:21:22 +0800 | [diff] [blame] | 45 | #endif |
Brad Bishop | 0283f7c | 2020-11-09 10:09:26 -0500 | [diff] [blame^] | 46 | bus.attach_event(loop.get(), SD_EVENT_PRIORITY_NORMAL); |
| 47 | auto rc = loop.loop(); |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 48 | if (rc < 0) |
| 49 | { |
| 50 | log<level::ERR>("Error occurred during the sd_event_loop", |
| 51 | entry("RC=%d", rc)); |
| 52 | return -1; |
| 53 | } |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 54 | } |
Gunnar Mills | 6bd6d7b | 2017-09-18 09:22:36 -0500 | [diff] [blame] | 55 | catch (const std::system_error& e) |
| 56 | { |
| 57 | log<level::ERR>(e.what()); |
| 58 | return -1; |
| 59 | } |
| 60 | |
Adriana Kobylak | 2d8fa22 | 2017-03-15 12:34:32 -0500 | [diff] [blame] | 61 | return 0; |
| 62 | } |