power-utils: Initially add --update option

This option is used to update the PSU firmware, usage:

 psutils --update <psu-inventory-path> <image-dir>

Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: I3958e360f04bb0ace9eea41d9f81e4533432701c
diff --git a/tools/power-utils/main.cpp b/tools/power-utils/main.cpp
index 19d0395..3142bc6 100644
--- a/tools/power-utils/main.cpp
+++ b/tools/power-utils/main.cpp
@@ -13,9 +13,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "updater.hpp"
 #include "version.hpp"
 
 #include <CLI/CLI.hpp>
+#include <cassert>
 #include <phosphor-logging/log.hpp>
 
 using namespace phosphor::logging;
@@ -26,6 +28,7 @@
     std::string psuPath;
     std::vector<std::string> versions;
     bool rawOutput = false;
+    std::vector<std::string> updateArguments;
 
     CLI::App app{"PSU utils app for OpenBMC"};
     auto action = app.add_option_group("Action");
@@ -33,6 +36,11 @@
                        "Get PSU version from inventory path");
     action->add_option("-c,--compare", versions,
                        "Compare and get the latest version");
+    action
+        ->add_option("-u,--update", updateArguments,
+                     "Update PSU firmware, expecting two arguments: "
+                     "<PSU inventory path> <image-dir>")
+        ->expected(2);
     action->require_option(1); // Only one option is supported
     app.add_flag("--raw", rawOutput, "Output raw text without linefeed");
     CLI11_PARSE(app, argc, argv);
@@ -47,6 +55,14 @@
     {
         ret = version::getLatest(versions);
     }
+    if (!updateArguments.empty())
+    {
+        assert(updateArguments.size() == 2);
+        if (updater::update(updateArguments[0], updateArguments[1]))
+        {
+            ret = "Update successful";
+        }
+    }
 
     printf("%s", ret.c_str());
     if (!rawOutput)
diff --git a/tools/power-utils/meson.build b/tools/power-utils/meson.build
index 4f0d53f..f4b8d45 100644
--- a/tools/power-utils/meson.build
+++ b/tools/power-utils/meson.build
@@ -1,6 +1,7 @@
 psutils = executable(
     'psutils',
     'version.cpp',
+    'updater.cpp',
     'main.cpp',
     dependencies: [
         phosphor_dbus_interfaces,
diff --git a/tools/power-utils/updater.cpp b/tools/power-utils/updater.cpp
new file mode 100644
index 0000000..6b9468c
--- /dev/null
+++ b/tools/power-utils/updater.cpp
@@ -0,0 +1,31 @@
+/**
+ * Copyright © 2019 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "config.h"
+
+#include "updater.hpp"
+
+namespace updater
+{
+
+bool update(const std::string& psuInventoryPath, const std::string& imageDir)
+{
+    // TODO
+    fprintf(stderr, "psu: %s, image: %s\n", psuInventoryPath.c_str(),
+            imageDir.c_str());
+    return true;
+}
+
+} // namespace updater
diff --git a/tools/power-utils/updater.hpp b/tools/power-utils/updater.hpp
new file mode 100644
index 0000000..9efa713
--- /dev/null
+++ b/tools/power-utils/updater.hpp
@@ -0,0 +1,33 @@
+/**
+ * Copyright © 2019 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#pragma once
+
+#include <string>
+
+namespace updater
+{
+
+/**
+ * Update PSU firmware
+ *
+ * @param[in] psuInventoryPath - The inventory path of the PSU
+ * @param[in] imageDir - The directory containing the PSU image
+ *
+ * @return true if successful, otherwise false
+ */
+bool update(const std::string& psuInventoryPath, const std::string& imageDir);
+
+} // namespace updater