power-utils: Initially add Updater class
The Updater class is used to do PSU code update, initially add it that
does unbind/bind driver and set PSU present to false/true during the
update.
Tested: Manually verify on Witherspoon that the driver is unbind/bind,
and the PSU present property is set to false/true during the PSU
update:
psutils --update \
/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0 \
/tmp/images/xxxxxxxx
Signed-off-by: Lei YU <mine260309@gmail.com>
Change-Id: Ic0a9df7687303caeb9a7f21ba00dc33ee76482db
diff --git a/tools/power-utils/updater.hpp b/tools/power-utils/updater.hpp
index 9efa713..0d69c0b 100644
--- a/tools/power-utils/updater.hpp
+++ b/tools/power-utils/updater.hpp
@@ -15,11 +15,15 @@
*/
#pragma once
+#include <filesystem>
+#include <sdbusplus/bus.hpp>
#include <string>
namespace updater
{
+namespace fs = std::filesystem;
+
/**
* Update PSU firmware
*
@@ -30,4 +34,76 @@
*/
bool update(const std::string& psuInventoryPath, const std::string& imageDir);
+class Updater
+{
+ public:
+ Updater() = delete;
+ Updater(const Updater&) = delete;
+ Updater& operator=(const Updater&) = delete;
+ Updater(Updater&&) = default;
+ Updater& operator=(Updater&&) = default;
+
+ /**
+ * @brief Constructor
+ *
+ * @param psuInventoryPath - The PSU inventory path
+ * @param devPath - The PSU device path
+ * @param imageDir - The update image directory
+ */
+ Updater(const std::string& psuInventoryPath, const std::string& devPath,
+ const std::string& imageDir);
+
+ /** @brief Destructor */
+ ~Updater();
+
+ /** @brief Bind or unbind the driver
+ *
+ * @param doBind - indicate if it's going to bind or unbind the driver
+ */
+ void bindUnbind(bool doBind);
+
+ /** @brief Set the PSU inventory present property
+ *
+ * @param present - The present state to set
+ */
+ void setPresent(bool present);
+
+ /** @brief Do the PSU update
+ *
+ * @return 0 if success, otherwise non-zero
+ */
+ int doUpdate();
+
+ private:
+ /** @brief The sdbusplus DBus bus connection */
+ sdbusplus::bus::bus bus;
+
+ /** @brief The PSU inventory path */
+ std::string psuInventoryPath;
+
+ /** @brief The PSU device path
+ *
+ * Usually it is a device in i2c subsystem, e.g.
+ * /sys/bus/i2c/devices/3-0068
+ */
+ std::string devPath;
+
+ /** @brief The PSU device name
+ *
+ * Usually it is a i2c device name, e.g.
+ * 3-0068
+ */
+ std::string devName;
+
+ /** @brief The PSU image directory */
+ std::string imageDir;
+
+ /** @brief The PSU device driver's path
+ *
+ * Usually it is the PSU driver, e.g.
+ * /sys/bus/i2c/drivers/ibm-cffps
+ */
+ fs::path driverPath;
+};
+
} // namespace updater