blob: 0e4a35b6af7173485e6441d77fff84b5dd52169e [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
Gunnar Millsf6ed5892018-09-07 17:08:02 -050011
12#include <phosphor-logging/log.hpp>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050013#include <sdbusplus/bus.hpp>
14#include <sdbusplus/server/manager.hpp>
Brad Bishop0283f7c2020-11-09 10:09:26 -050015#include <sdeventplus/event.hpp>
Brad Bishop8facccf2020-11-04 09:44:58 -050016
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050017#include <system_error>
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050018
Brad Bishopc8f22502020-11-06 14:42:09 -050019int main(int, char*[])
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050020{
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050021 using namespace openpower::software::updater;
22 using namespace phosphor::logging;
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050023 auto bus = sdbusplus::bus::new_default();
Brad Bishop0283f7c2020-11-09 10:09:26 -050024 auto loop = sdeventplus::Event::get_default();
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050025
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050026 // Add sdbusplus ObjectManager.
27 sdbusplus::server::manager::manager objManager(bus, SOFTWARE_OBJPATH);
28
Lei YUf3ce4332019-02-21 14:09:49 +080029#ifdef UBIFS_LAYOUT
30 ItemUpdaterUbi updater(bus, SOFTWARE_OBJPATH);
Adriana Kobylak8bc2ab42020-07-15 09:16:27 -050031#elif defined MMC_LAYOUT
32 ItemUpdaterMMC updater(bus, SOFTWARE_OBJPATH);
Lei YU322f3f42019-02-21 16:10:41 +080033#else
34 ItemUpdaterStatic updater(bus, SOFTWARE_OBJPATH);
Lei YUf3ce4332019-02-21 14:09:49 +080035#endif
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050036
37 bus.request_name(BUSNAME_UPDATER);
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050038 try
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050039 {
Lei YUda6ab6c2019-02-22 14:21:22 +080040#ifdef UBIFS_LAYOUT
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050041 openpower::software::updater::Watch watch(
Brad Bishop0283f7c2020-11-09 10:09:26 -050042 loop.get(),
Adriana Kobylak70dcb632018-02-27 15:46:52 -060043 std::bind(std::mem_fn(&ItemUpdater::updateFunctionalAssociation),
44 &updater, std::placeholders::_1));
Lei YUda6ab6c2019-02-22 14:21:22 +080045#endif
Brad Bishop0283f7c2020-11-09 10:09:26 -050046 bus.attach_event(loop.get(), SD_EVENT_PRIORITY_NORMAL);
47 auto rc = loop.loop();
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050048 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 Kobylak2d8fa222017-03-15 12:34:32 -050054 }
Gunnar Mills6bd6d7b2017-09-18 09:22:36 -050055 catch (const std::system_error& e)
56 {
57 log<level::ERR>(e.what());
58 return -1;
59 }
60
Adriana Kobylak2d8fa222017-03-15 12:34:32 -050061 return 0;
62}