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 | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 5 | |
| 6 | int main(int argc, char** argv) |
| 7 | { |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 8 | namespace fs = std::filesystem; |
| 9 | |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 10 | std::string fileName{}; |
| 11 | |
| 12 | CLI::App app{"Update the firmware of OpenBMC via USB app"}; |
| 13 | app.add_option("-f,--fileName", fileName, |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 14 | "Get the name of the USB mount folder, eg: sda1, sdb1"); |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 15 | |
| 16 | CLI11_PARSE(app, argc, argv); |
| 17 | |
George Liu | 073a653 | 2021-10-25 14:40:03 +0800 | [diff] [blame] | 18 | if (fileName.empty()) |
| 19 | { |
| 20 | lg2::error("The file name passed in is empty."); |
| 21 | return -1; |
| 22 | } |
| 23 | |
| 24 | fs::path usbPath = fs::path{"/run/media/usb"} / fileName; |
| 25 | phosphor::usb::USBManager manager(usbPath); |
| 26 | |
| 27 | if (!manager.run()) |
| 28 | { |
| 29 | lg2::error("Failed to FW Update via USB, usbPath:{USBPATH}", "USBPATH", |
| 30 | usbPath); |
| 31 | return -1; |
| 32 | } |
| 33 | |
George Liu | cc74233 | 2021-10-20 16:25:55 +0800 | [diff] [blame] | 34 | return 0; |
| 35 | } |