George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 1 | #include "usb_manager.hpp" |
| 2 | |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 3 | #include <CLI/CLI.hpp> |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 4 | #include <phosphor-logging/lg2.hpp> |
George Liu | 5107c45 | 2021-11-09 20:06:31 +0800 | [diff] [blame] | 5 | #include <sdeventplus/event.hpp> |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 6 | |
| 7 | int main(int argc, char** argv) |
| 8 | { |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 9 | namespace fs = std::filesystem; |
| 10 | |
George Liu | 6d775e6 | 2021-10-26 10:44:30 +0800 | [diff] [blame] | 11 | std::string deviceName{}; |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 12 | |
| 13 | CLI::App app{"Update the firmware of OpenBMC via USB app"}; |
George Liu | 6d775e6 | 2021-10-26 10:44:30 +0800 | [diff] [blame] | 14 | app.add_option("-d,--device", deviceName, |
| 15 | "Get the name of the USB device name, eg: sda1, sdb1"); |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 16 | |
| 17 | CLI11_PARSE(app, argc, argv); |
| 18 | |
Jagpal Singh Gill | 6fbb54c | 2024-08-03 16:39:24 -0700 | [diff] [blame] | 19 | // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn) |
George Liu | 6d775e6 | 2021-10-26 10:44:30 +0800 | [diff] [blame] | 20 | if (deviceName.empty()) |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 21 | { |
| 22 | lg2::error("The file name passed in is empty."); |
| 23 | return -1; |
| 24 | } |
| 25 | |
George Liu | 6d775e6 | 2021-10-26 10:44:30 +0800 | [diff] [blame] | 26 | fs::path devicePath = fs::path{"/dev"} / deviceName; |
| 27 | fs::path usbPath = fs::path{"/run/media/usb"} / deviceName; |
Jagpal Singh Gill | 6fbb54c | 2024-08-03 16:39:24 -0700 | [diff] [blame] | 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 | |
George Liu | 6d775e6 | 2021-10-26 10:44:30 +0800 | [diff] [blame] | 43 | phosphor::usb::USBManager manager(bus, event, devicePath, usbPath); |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 44 | |
George Liu | 5107c45 | 2021-11-09 20:06:31 +0800 | [diff] [blame] | 45 | // Attach the bus to sd_event to service user requests |
| 46 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 47 | event.loop(); |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 48 | |
Jagpal Singh Gill | 6fbb54c | 2024-08-03 16:39:24 -0700 | [diff] [blame] | 49 | #endif // START_UPDATE_DBUS_INTEFACE |
| 50 | |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 51 | return 0; |
| 52 | } |