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