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 18 #include <filesystem> 19 #include <sdbusplus/bus.hpp> 20 #include <string> 21 22 namespace updater 23 { 24 25 namespace fs = std::filesystem; 26 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 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 */ 57 ~Updater(); 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 71 /** @brief Do the PSU update 72 * 73 * @return 0 if success, otherwise non-zero 74 */ 75 int doUpdate(); 76 77 private: 78 /** @brief The sdbusplus DBus bus connection */ 79 sdbusplus::bus::bus bus; 80 81 /** @brief The PSU inventory path */ 82 std::string psuInventoryPath; 83 84 /** @brief The PSU device path 85 * 86 * Usually it is a device in i2c subsystem, e.g. 87 * /sys/bus/i2c/devices/3-0068 88 */ 89 std::string devPath; 90 91 /** @brief The PSU device name 92 * 93 * Usually it is a i2c device name, e.g. 94 * 3-0068 95 */ 96 std::string devName; 97 98 /** @brief The PSU image directory */ 99 std::string imageDir; 100 101 /** @brief The PSU device driver's path 102 * 103 * Usually it is the PSU driver, e.g. 104 * /sys/bus/i2c/drivers/ibm-cffps 105 */ 106 fs::path driverPath; 107 }; 108 109 } // namespace updater 110