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