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; |
George Liu | 5107c45 | 2021-11-09 20:06:31 +0800 | [diff] [blame] | 10 | // Dbus constructs |
| 11 | auto bus = sdbusplus::bus::new_default(); |
| 12 | |
| 13 | // Get a default event loop |
| 14 | auto event = sdeventplus::Event::get_default(); |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 15 | |
George Liu | 6d775e6 | 2021-10-26 10:44:30 +0800 | [diff] [blame] | 16 | std::string deviceName{}; |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 17 | |
| 18 | CLI::App app{"Update the firmware of OpenBMC via USB app"}; |
George Liu | 6d775e6 | 2021-10-26 10:44:30 +0800 | [diff] [blame] | 19 | app.add_option("-d,--device", deviceName, |
| 20 | "Get the name of the USB device name, eg: sda1, sdb1"); |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 21 | |
| 22 | CLI11_PARSE(app, argc, argv); |
| 23 | |
George Liu | 6d775e6 | 2021-10-26 10:44:30 +0800 | [diff] [blame] | 24 | if (deviceName.empty()) |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 25 | { |
| 26 | lg2::error("The file name passed in is empty."); |
| 27 | return -1; |
| 28 | } |
| 29 | |
George Liu | 6d775e6 | 2021-10-26 10:44:30 +0800 | [diff] [blame] | 30 | fs::path devicePath = fs::path{"/dev"} / deviceName; |
| 31 | fs::path usbPath = fs::path{"/run/media/usb"} / deviceName; |
| 32 | phosphor::usb::USBManager manager(bus, event, devicePath, usbPath); |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 33 | |
George Liu | 5107c45 | 2021-11-09 20:06:31 +0800 | [diff] [blame] | 34 | // Attach the bus to sd_event to service user requests |
| 35 | bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL); |
| 36 | event.loop(); |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 37 | |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 38 | return 0; |
| 39 | } |