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