blob: 1b872b6293d89ca38ed99e36c12e60c3b47c79e1 [file] [log] [blame]
Faisal Awada5a582d32024-11-15 14:11:44 -06001/**
2 * Copyright © 2024 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#pragma once
17
18#include "updater.hpp"
19
20namespace aeiUpdater
21{
22/**
23 * @class AeiUpdater
24 * @brief A class to handle firmware updates for the AEI PSUs.
25 *
26 * This class provides methods to update firmware by writing ISP keys,
27 * validating firmware files, and performing I2C communications. It includes
28 * functions to manage the update process, including downloading firmware blocks
29 * and verifying the update status.
30 */
31class AeiUpdater : public updater::Updater
32{
33 public:
34 AeiUpdater() = delete;
35 AeiUpdater(const AeiUpdater&) = delete;
36 AeiUpdater(AeiUpdater&&) = delete;
37 AeiUpdater& operator=(const AeiUpdater&) = delete;
38 AeiUpdater& operator=(AeiUpdater&&) = delete;
39 ~AeiUpdater() = default;
40
41 /**
42 * @brief Constructor for the AeiUpdater class.
43 *
44 * @param psuInventoryPath The path to the PSU's inventory in the system.
45 * @param devPath The device path for the PSU.
46 * @param imageDir The directory containing the firmware image files.
47 */
48 AeiUpdater(const std::string& psuInventoryPath, const std::string& devPath,
49 const std::string& imageDir) :
50 Updater(psuInventoryPath, devPath, imageDir)
51 {}
52
53 /**
54 * @brief Initiates the firmware update process.
55 *
56 * @return int Status code 0 for success or 1 for failure.
57 */
58 int doUpdate() override;
59
60 private:
61 /**
62 * @brief Writes an ISP (In-System Programming) key to initiate the update.
63 *
64 * @return bool True if successful, false otherwise.
65 */
66 bool writeIspKey();
67
68 /**
69 * @brief Writes the mode required for ISP to start firmware programming.
70 *
71 * @return bool True if successful, false otherwise.
72 */
73 bool writeIspMode();
74
75 /**
76 * @brief Resets the ISP status to prepare for a firmware update.
77 *
78 * @return bool True if successful, false otherwise.
79 */
80 bool writeIspStatusReset();
81
82 /**
83 * @brief Pointer to the I2C interface for communication
84 *
85 * This pointer is not owned by the class. The caller is responsible for
86 * ensuring that 'i2cInterface' remains valid for the lifetime of this
87 * object. Ensure to check this pointer for null before use.
88 */
89 i2c::I2CInterface* i2cInterface;
90
91 /**
92 * @brief Stores byte-swapped indices for command processing
93 */
94 std::vector<uint8_t> byteSwappedIndex;
95};
96} // namespace aeiUpdater