psutils: Add necessary firmware update functions

doUpdate: Adds the main logic for orchestrating the PSU firmware update
process, including ISP setup, firmware download, and verification.

performI2cWriteReadWithRetries: Introduces functionality to perform I2C
write-read operations with configurable retries, and error handling for
robustness.

performI2cReadWrite: Provides the implementation for direct I2C
write-read operations with a customizable delay to ensure timing
requirements are met.

downloadPsuFirmware: Implements the functionality to read and process
PSU firmware in blocks, ensuring data integrity during transfer.

verifyDownloadFwStatus: Adds a mechanism to validate the success of
firmware downloads by checking the PSU's checksum status register.

getClassInstance: Add logic to dynamically instantiate updater class
based on PSU model.

Test:
 Placed latest firmware and MANIFEST files in "/usr/share/obmc/51E9"
 then retrieved the current PSU FW level. Ran "psutils" on the command
 line as follow:
 /usr/bin/psutils --update
  /xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply1
  /usr/share/obmc/51E9

 Retrieved the FW level and verified the PSU FW was updated as
 expected.

    Signed-off-by: Faisal Awada <faisal@us.ibm.com>
Change-Id: I65d0c015eab0322110e85b954a38590332aaa67a
Signed-off-by: Faisal Awada <faisal@us.ibm.com>
diff --git a/tools/power-utils/aei_updater.hpp b/tools/power-utils/aei_updater.hpp
index de5ca5c..99127fd 100644
--- a/tools/power-utils/aei_updater.hpp
+++ b/tools/power-utils/aei_updater.hpp
@@ -114,14 +114,61 @@
                                            const size_t& bytesToRead);
 
     /**
-     * @brief Prepares an ISP_MEMORY  command block by processing the firmware
+     * @brief Prepares an ISP_MEMORY command block by processing the firmware
      * data block.
      *
      * @param dataBlockRead The firmware data block read from the file.
-     * @return The prepared command block.
      */
-    std::vector<uint8_t>
-        prepareCommandBlock(const std::vector<uint8_t>& dataBlockRead);
+    void prepareCommandBlock(const std::vector<uint8_t>& dataBlockRead);
+
+    /**
+     * @brief Performs firmware update for the power supply unit (PSU)
+     *
+     * This function retrieves the firmware file from appropriate path,
+     * validate existence of the file and initiate the update process.
+     * The process includes processing the data into blocks, and writes
+     * these blocks to the PSU.
+     *
+     * @return True if firmware download was successful, false otherwise.
+     */
+    bool downloadPsuFirmware();
+
+    /**
+     * @brief Performs an I2C write and read with retry logic.
+     *
+     * This function attempts to write a command block to PSU register
+     * and read next block sequence and CML write status. If the block
+     * sequence number the same as written block, then retry to write
+     * same block again.
+     *
+     * @param regAddr The register address to write to.
+     * @param expectedReadSize The size of data read from i2c device.
+     * @param readData The buffer to store read data.
+     * @param retries The number of retry attempts allowed.
+     * @param delayTime The delay time between retries.
+     * @return True if the operation is successful, false otherwise.
+     */
+    bool performI2cWriteReadWithRetries(
+        uint8_t regAddr, const uint8_t expectedReadSize, uint8_t* readData,
+        const int retries, const int delayTime);
+
+    /**
+     * @brief Performs a single I2C write and read without retry logic.
+     *
+     * @param regAddr The register address to write to.
+     * @param readReplySize The size of data read from i2c device.
+     * @param readData The buffer to store read data.
+     * @param delayTime The delay time between write and read operations.
+     */
+    void performI2cWriteRead(uint8_t regAddr, uint8_t& readReplySize,
+                             uint8_t* readData, const int& delayTime);
+    /**
+     * @brief Verifies the status of the firmware download.
+     *
+     * @return True if the download status is verified as successful, false
+     * otherwise.
+     */
+    bool verifyDownloadFWStatus();
 
     /**
      * @brief Initiates a reboot of the ISP to apply new firmware.
@@ -149,5 +196,10 @@
      * @brief Stores byte-swapped indices for command processing
      */
     std::vector<uint8_t> byteSwappedIndex;
+
+    /**
+     * @brief Command block used for writing data to the device
+     */
+    std::vector<uint8_t> cmdBlockWrite;
 };
 } // namespace aeiUpdater