blob: 771b4cddba7498db0c0a2deb6eeea86d5366881c [file] [log] [blame]
George Liu073a6532021-10-25 14:40:03 +08001#include "usb_manager.hpp"
2
George Liucc742332021-10-20 16:25:55 +08003#include <CLI/CLI.hpp>
George Liu073a6532021-10-25 14:40:03 +08004#include <phosphor-logging/lg2.hpp>
George Liu5107c452021-11-09 20:06:31 +08005#include <sdeventplus/event.hpp>
George Liucc742332021-10-20 16:25:55 +08006
7int main(int argc, char** argv)
8{
George Liu073a6532021-10-25 14:40:03 +08009 namespace fs = std::filesystem;
George Liu5107c452021-11-09 20:06:31 +080010 // Dbus constructs
11 auto bus = sdbusplus::bus::new_default();
12
13 // Get a default event loop
14 auto event = sdeventplus::Event::get_default();
George Liu073a6532021-10-25 14:40:03 +080015
George Liu6d775e62021-10-26 10:44:30 +080016 std::string deviceName{};
George Liucc742332021-10-20 16:25:55 +080017
18 CLI::App app{"Update the firmware of OpenBMC via USB app"};
George Liu6d775e62021-10-26 10:44:30 +080019 app.add_option("-d,--device", deviceName,
20 "Get the name of the USB device name, eg: sda1, sdb1");
George Liucc742332021-10-20 16:25:55 +080021
22 CLI11_PARSE(app, argc, argv);
23
George Liu6d775e62021-10-26 10:44:30 +080024 if (deviceName.empty())
George Liu073a6532021-10-25 14:40:03 +080025 {
26 lg2::error("The file name passed in is empty.");
27 return -1;
28 }
29
George Liu6d775e62021-10-26 10:44:30 +080030 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 Liu073a6532021-10-25 14:40:03 +080033
George Liu5107c452021-11-09 20:06:31 +080034 // Attach the bus to sd_event to service user requests
35 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
36 event.loop();
George Liu073a6532021-10-25 14:40:03 +080037
George Liucc742332021-10-20 16:25:55 +080038 return 0;
39}