1 #include "usb_manager.hpp" 2 3 #include <CLI/CLI.hpp> 4 #include <phosphor-logging/lg2.hpp> 5 #include <sdeventplus/event.hpp> 6 7 int main(int argc, char** argv) 8 { 9 namespace fs = std::filesystem; 10 11 std::string deviceName{}; 12 13 CLI::App app{"Update the firmware of OpenBMC via USB app"}; 14 app.add_option("-d,--device", deviceName, 15 "Get the name of the USB device name, eg: sda1, sdb1"); 16 17 CLI11_PARSE(app, argc, argv); 18 19 // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) 20 if (deviceName.empty()) 21 { 22 lg2::error("The file name passed in is empty."); 23 return -1; 24 } 25 26 fs::path devicePath = fs::path{"/dev"} / deviceName; 27 fs::path usbPath = fs::path{"/run/media/usb"} / deviceName; 28 29 #ifdef START_UPDATE_DBUS_INTEFACE 30 31 sdbusplus::async::context ctx; 32 phosphor::usb::USBManager manager(ctx, devicePath, usbPath); 33 ctx.run(); 34 35 #else 36 37 // Dbus constructs 38 auto bus = sdbusplus::bus::new_default(); 39 40 // Get a default event loop 41 auto event = sdeventplus::Event::get_default(); 42 43 phosphor::usb::USBManager manager(bus, event, devicePath, usbPath); 44 45 // Attach the bus to sd_event to service user requests 46 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); 47 event.loop(); 48 49 #endif // START_UPDATE_DBUS_INTEFACE 50 51 return 0; 52 } 53