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