blob: 3f0e5f5b9104bc0f35b454b4702080abb95af769 [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;
10
George Liu6d775e62021-10-26 10:44:30 +080011 std::string deviceName{};
George Liucc742332021-10-20 16:25:55 +080012
13 CLI::App app{"Update the firmware of OpenBMC via USB app"};
George Liu6d775e62021-10-26 10:44:30 +080014 app.add_option("-d,--device", deviceName,
15 "Get the name of the USB device name, eg: sda1, sdb1");
George Liucc742332021-10-20 16:25:55 +080016
17 CLI11_PARSE(app, argc, argv);
18
Jagpal Singh Gill6fbb54c2024-08-03 16:39:24 -070019 // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
George Liu6d775e62021-10-26 10:44:30 +080020 if (deviceName.empty())
George Liu073a6532021-10-25 14:40:03 +080021 {
22 lg2::error("The file name passed in is empty.");
23 return -1;
24 }
25
George Liu6d775e62021-10-26 10:44:30 +080026 fs::path devicePath = fs::path{"/dev"} / deviceName;
27 fs::path usbPath = fs::path{"/run/media/usb"} / deviceName;
Jagpal Singh Gill6fbb54c2024-08-03 16:39:24 -070028
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 Liu6d775e62021-10-26 10:44:30 +080043 phosphor::usb::USBManager manager(bus, event, devicePath, usbPath);
George Liu073a6532021-10-25 14:40:03 +080044
George Liu5107c452021-11-09 20:06:31 +080045 // Attach the bus to sd_event to service user requests
46 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
47 event.loop();
George Liu073a6532021-10-25 14:40:03 +080048
Jagpal Singh Gill6fbb54c2024-08-03 16:39:24 -070049#endif // START_UPDATE_DBUS_INTEFACE
50
George Liucc742332021-10-20 16:25:55 +080051 return 0;
52}