psutils: Add new functions to AEI Updater class
The following functions handle the critical stages of firmware update,
including validation, reading, preparation, and reboot verification.
Error handling and logging are incorporated to isolate issues during the
update.
getFirmwarePath()
Retrieves the firmware file path from the image directory. Uses
getFWFilenamePath to fetch the path. Logs an error if the firmware path
is not found and returns an empty string otherwise returns firmware
path.
isFirmwareFileValid()
Validates the firmware file at the given path using validateFWFile.
Ensure the firmware file exists and meets requirements before proceeding
with the update. Logs an error if validation fails.
openFirmwareFile()
Opens the firmware file at the specified path for reading in binary
mode. Logs an error if the file cannot be opened.
readFirmwareBlock()
Reads a block of data from the firmware file.Uses readFirmwareBytes to
read the specified number of bytes.
prepareCommandBlock()
Prepares a command block for writing firmware data to the PSU. Adds
metadata, data, and a CRC8 checksum. Packages firmware data in a format
suitable for I2C transmission.
ispReboot()
Sends a reboot command to the status register to apply new firmware.
ispReadRebootStatus()
Reads the reboot status from ISP, returns true for success otherwise
false.
Tested:
- Validated that the firmware path retrieves the correct file.
- A validation error is logged when the file is empty or path is
incorrect.
- Removed read permission on the firmware file and verified that an
error was logged.
- Verify the block of data read as specified in the specification.
- Printed the command block and verified that the command and data are
ready to be sent to the PSU via I2C.
- Downloaded the firmware and verified that the command block, ISP
reboot and reboot status are working as expected.
Change-Id: I097b4aeefc0967d5591b8fb6aefb3c600c9f77f8
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 1b872b6..de5ca5c 100644
--- a/tools/power-utils/aei_updater.hpp
+++ b/tools/power-utils/aei_updater.hpp
@@ -53,7 +53,7 @@
/**
* @brief Initiates the firmware update process.
*
- * @return int Status code 0 for success or 1 for failure.
+ * @return Status code 0 for success or 1 for failure.
*/
int doUpdate() override;
@@ -61,25 +61,82 @@
/**
* @brief Writes an ISP (In-System Programming) key to initiate the update.
*
- * @return bool True if successful, false otherwise.
+ * @return True if successful, false otherwise.
*/
bool writeIspKey();
/**
* @brief Writes the mode required for ISP to start firmware programming.
*
- * @return bool True if successful, false otherwise.
+ * @return True if successful, false otherwise.
*/
bool writeIspMode();
/**
* @brief Resets the ISP status to prepare for a firmware update.
*
- * @return bool True if successful, false otherwise.
+ * @return True if successful, false otherwise.
*/
bool writeIspStatusReset();
/**
+ * @brief Retrieves the path to the firmware file.
+ *
+ * @return The file path of the firmware.
+ */
+ std::string getFirmwarePath();
+
+ /**
+ * @brief Validates the firmware file.
+ *
+ * @param fspath The file path to validate.
+ * @return True if the file is valid, false otherwise.
+ */
+ bool isFirmwareFileValid(const std::string& fspath);
+
+ /**
+ * @brief Opens a firmware file in binary mode.
+ *
+ * @param fspath The path to the firmware file.
+ * @return A file stream to read the firmware
+ * file.
+ */
+ std::unique_ptr<std::ifstream> openFirmwareFile(const std::string& fspath);
+
+ /**
+ * @brief Reads a block of firmware data from the file.
+ *
+ * @param file The input file stream from which to read data.
+ * @param bytesToRead The number of bytes to read.
+ * @return A vector containing the firmware block.
+ */
+ std::vector<uint8_t> readFirmwareBlock(std::ifstream& file,
+ const size_t& bytesToRead);
+
+ /**
+ * @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);
+
+ /**
+ * @brief Initiates a reboot of the ISP to apply new firmware.
+ */
+ void ispReboot();
+
+ /**
+ * @brief Reads the reboot status from the ISP.
+ *
+ * @return True if the reboot status indicates success, false
+ * otherwise.
+ */
+ bool ispReadRebootStatus();
+
+ /**
* @brief Pointer to the I2C interface for communication
*
* This pointer is not owned by the class. The caller is responsible for