Lei YU | d19df25 | 2019-10-25 17:31:52 +0800 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 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 | |
Lei YU | 7c2fbbb | 2019-11-06 14:56:02 +0800 | [diff] [blame] | 18 | #include "i2c_interface.hpp" |
| 19 | |
Lei YU | 9ab6d75 | 2019-10-28 17:03:20 +0800 | [diff] [blame] | 20 | #include <sdbusplus/bus.hpp> |
Brandon Wyman | d1bc4ce | 2019-12-13 14:20:34 -0600 | [diff] [blame] | 21 | |
| 22 | #include <filesystem> |
Lei YU | d19df25 | 2019-10-25 17:31:52 +0800 | [diff] [blame] | 23 | #include <string> |
| 24 | |
Lei YU | 7c2fbbb | 2019-11-06 14:56:02 +0800 | [diff] [blame] | 25 | class TestUpdater; |
| 26 | |
Lei YU | d19df25 | 2019-10-25 17:31:52 +0800 | [diff] [blame] | 27 | namespace updater |
| 28 | { |
| 29 | |
Lei YU | 9ab6d75 | 2019-10-28 17:03:20 +0800 | [diff] [blame] | 30 | namespace fs = std::filesystem; |
| 31 | |
Lei YU | d19df25 | 2019-10-25 17:31:52 +0800 | [diff] [blame] | 32 | /** |
| 33 | * Update PSU firmware |
| 34 | * |
| 35 | * @param[in] psuInventoryPath - The inventory path of the PSU |
| 36 | * @param[in] imageDir - The directory containing the PSU image |
| 37 | * |
| 38 | * @return true if successful, otherwise false |
| 39 | */ |
| 40 | bool update(const std::string& psuInventoryPath, const std::string& imageDir); |
| 41 | |
Lei YU | 9ab6d75 | 2019-10-28 17:03:20 +0800 | [diff] [blame] | 42 | class Updater |
| 43 | { |
| 44 | public: |
Lei YU | 7c2fbbb | 2019-11-06 14:56:02 +0800 | [diff] [blame] | 45 | friend TestUpdater; |
Lei YU | 9ab6d75 | 2019-10-28 17:03:20 +0800 | [diff] [blame] | 46 | Updater() = delete; |
| 47 | Updater(const Updater&) = delete; |
| 48 | Updater& operator=(const Updater&) = delete; |
| 49 | Updater(Updater&&) = default; |
| 50 | Updater& operator=(Updater&&) = default; |
| 51 | |
| 52 | /** |
| 53 | * @brief Constructor |
| 54 | * |
| 55 | * @param psuInventoryPath - The PSU inventory path |
| 56 | * @param devPath - The PSU device path |
| 57 | * @param imageDir - The update image directory |
| 58 | */ |
| 59 | Updater(const std::string& psuInventoryPath, const std::string& devPath, |
| 60 | const std::string& imageDir); |
| 61 | |
| 62 | /** @brief Destructor */ |
Lei YU | 575ed13 | 2019-10-29 17:22:16 +0800 | [diff] [blame] | 63 | ~Updater() = default; |
Lei YU | 9ab6d75 | 2019-10-28 17:03:20 +0800 | [diff] [blame] | 64 | |
| 65 | /** @brief Bind or unbind the driver |
| 66 | * |
| 67 | * @param doBind - indicate if it's going to bind or unbind the driver |
| 68 | */ |
| 69 | void bindUnbind(bool doBind); |
| 70 | |
| 71 | /** @brief Set the PSU inventory present property |
| 72 | * |
| 73 | * @param present - The present state to set |
| 74 | */ |
| 75 | void setPresent(bool present); |
| 76 | |
Lei YU | 575ed13 | 2019-10-29 17:22:16 +0800 | [diff] [blame] | 77 | /** @brief Check if it's ready to update the PSU |
| 78 | * |
| 79 | * @return true if it's ready, otherwise false |
| 80 | */ |
| 81 | bool isReadyToUpdate(); |
| 82 | |
Lei YU | 9ab6d75 | 2019-10-28 17:03:20 +0800 | [diff] [blame] | 83 | /** @brief Do the PSU update |
| 84 | * |
| 85 | * @return 0 if success, otherwise non-zero |
| 86 | */ |
| 87 | int doUpdate(); |
| 88 | |
Lei YU | 7c2fbbb | 2019-11-06 14:56:02 +0800 | [diff] [blame] | 89 | /** @brief Create I2C device |
| 90 | * |
| 91 | * Creates the I2C device based on the device name. |
| 92 | * e.g. It opens busId 3, address 0x68 for "3-0068" |
| 93 | */ |
| 94 | void createI2CDevice(); |
| 95 | |
Lei YU | 9ab6d75 | 2019-10-28 17:03:20 +0800 | [diff] [blame] | 96 | private: |
| 97 | /** @brief The sdbusplus DBus bus connection */ |
Patrick Williams | 7354ce6 | 2022-07-22 19:26:56 -0500 | [diff] [blame] | 98 | sdbusplus::bus_t bus; |
Lei YU | 9ab6d75 | 2019-10-28 17:03:20 +0800 | [diff] [blame] | 99 | |
| 100 | /** @brief The PSU inventory path */ |
| 101 | std::string psuInventoryPath; |
| 102 | |
| 103 | /** @brief The PSU device path |
| 104 | * |
| 105 | * Usually it is a device in i2c subsystem, e.g. |
| 106 | * /sys/bus/i2c/devices/3-0068 |
| 107 | */ |
| 108 | std::string devPath; |
| 109 | |
| 110 | /** @brief The PSU device name |
| 111 | * |
| 112 | * Usually it is a i2c device name, e.g. |
| 113 | * 3-0068 |
| 114 | */ |
| 115 | std::string devName; |
| 116 | |
| 117 | /** @brief The PSU image directory */ |
| 118 | std::string imageDir; |
| 119 | |
| 120 | /** @brief The PSU device driver's path |
| 121 | * |
| 122 | * Usually it is the PSU driver, e.g. |
| 123 | * /sys/bus/i2c/drivers/ibm-cffps |
| 124 | */ |
| 125 | fs::path driverPath; |
Lei YU | 7c2fbbb | 2019-11-06 14:56:02 +0800 | [diff] [blame] | 126 | |
| 127 | /** @brief The i2c device interface */ |
| 128 | std::unique_ptr<i2c::I2CInterface> i2c; |
Lei YU | 9ab6d75 | 2019-10-28 17:03:20 +0800 | [diff] [blame] | 129 | }; |
| 130 | |
Lei YU | d19df25 | 2019-10-25 17:31:52 +0800 | [diff] [blame] | 131 | } // namespace updater |