usb: Copy image file to /tmp/images via USB
Traverse the USB mount directory, and copy the first file with
a `.tar` extension under the directory to the `/tmp/images`
directory.
Tested: Manually call the fs::copy_file app locally, test passed.
Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: I8e03b9c3305f5e9d9a1535dd176ecd40dbea8903
diff --git a/usb/usb_manager_main.cpp b/usb/usb_manager_main.cpp
index b5a538d..143125d 100644
--- a/usb/usb_manager_main.cpp
+++ b/usb/usb_manager_main.cpp
@@ -1,14 +1,35 @@
+#include "usb_manager.hpp"
+
#include <CLI/CLI.hpp>
+#include <phosphor-logging/lg2.hpp>
int main(int argc, char** argv)
{
+ namespace fs = std::filesystem;
+
std::string fileName{};
CLI::App app{"Update the firmware of OpenBMC via USB app"};
app.add_option("-f,--fileName", fileName,
- "Get the name of the USB mount folder");
+ "Get the name of the USB mount folder, eg: sda1, sdb1");
CLI11_PARSE(app, argc, argv);
+ if (fileName.empty())
+ {
+ lg2::error("The file name passed in is empty.");
+ return -1;
+ }
+
+ fs::path usbPath = fs::path{"/run/media/usb"} / fileName;
+ phosphor::usb::USBManager manager(usbPath);
+
+ if (!manager.run())
+ {
+ lg2::error("Failed to FW Update via USB, usbPath:{USBPATH}", "USBPATH",
+ usbPath);
+ return -1;
+ }
+
return 0;
}