item_updater: sort ubi specific code
Add item_updater_helper and implement it in ubi and static layouts.
Tested: Build this repo on both Romulus and Witherspoon OK;
Tested on Romulus and Witherspoon that code update works fine.
Change-Id: I706cfe63900f89bb41672dcc745b3483e06838c7
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/item_updater_helper.hpp b/item_updater_helper.hpp
new file mode 100644
index 0000000..33b3cdb
--- /dev/null
+++ b/item_updater_helper.hpp
@@ -0,0 +1,68 @@
+#pragma once
+
+#include <string>
+#include <sdbusplus/bus.hpp>
+
+namespace phosphor
+{
+namespace software
+{
+namespace updater
+{
+
+class Helper
+{
+ public:
+ Helper() = delete;
+ Helper(const Helper&) = delete;
+ Helper& operator=(const Helper&) = delete;
+ Helper(Helper&&) = default;
+ Helper& operator=(Helper&&) = default;
+
+ /** @brief Constructor
+ *
+ * @param[in] bus - sdbusplus D-Bus bus connection
+ */
+ Helper(sdbusplus::bus::bus& bus) : bus(bus)
+ {
+ // Empty
+ }
+
+ /** @brief Clear an image with the entry id
+ *
+ * @param[in] entryId - The image entry id
+ */
+ void clearEntry(const std::string& entryId);
+
+ /** @brief Clean up all the unused images */
+ void cleanup();
+
+ /** @brief Do factory reset */
+ void factoryReset();
+
+ /** @brief Remove the image with the version id
+ *
+ * @param[in] versionId - The version id of the image
+ */
+ void removeVersion(const std::string& versionId);
+
+ /** @brief Update version id in uboot env
+ *
+ * @param[in] versionId - The version id of the image
+ */
+ void updateUbootVersionId(const std::string& versionId);
+
+ /** @brief Enable field mode */
+ void enableFieldMode();
+
+ /** @brief Mirror Uboot to the alt uboot partition */
+ void mirrorAlt();
+
+ private:
+ /** @brief Persistent sdbusplus D-Bus bus connection. */
+ sdbusplus::bus::bus& bus;
+};
+
+} // namespace updater
+} // namespace software
+} // namespace phosphor