blob: f22f663a1dd340221b87d13b94cc277ea77d46a9 [file] [log] [blame]
Lei YUd19df252019-10-25 17:31:52 +08001/**
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 YU7c2fbbb2019-11-06 14:56:02 +080018#include "i2c_interface.hpp"
19
Lei YU9ab6d752019-10-28 17:03:20 +080020#include <filesystem>
21#include <sdbusplus/bus.hpp>
Lei YUd19df252019-10-25 17:31:52 +080022#include <string>
23
Lei YU7c2fbbb2019-11-06 14:56:02 +080024class TestUpdater;
25
Lei YUd19df252019-10-25 17:31:52 +080026namespace updater
27{
28
Lei YU9ab6d752019-10-28 17:03:20 +080029namespace fs = std::filesystem;
30
Lei YUd19df252019-10-25 17:31:52 +080031/**
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 */
39bool update(const std::string& psuInventoryPath, const std::string& imageDir);
40
Lei YU9ab6d752019-10-28 17:03:20 +080041class Updater
42{
43 public:
Lei YU7c2fbbb2019-11-06 14:56:02 +080044 friend TestUpdater;
Lei YU9ab6d752019-10-28 17:03:20 +080045 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 YU575ed132019-10-29 17:22:16 +080062 ~Updater() = default;
Lei YU9ab6d752019-10-28 17:03:20 +080063
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 YU575ed132019-10-29 17:22:16 +080076 /** @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 YU9ab6d752019-10-28 17:03:20 +080082 /** @brief Do the PSU update
83 *
84 * @return 0 if success, otherwise non-zero
85 */
86 int doUpdate();
87
Lei YU7c2fbbb2019-11-06 14:56:02 +080088 /** @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 YU9ab6d752019-10-28 17:03:20 +080095 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 YU7c2fbbb2019-11-06 14:56:02 +0800125
126 /** @brief The i2c device interface */
127 std::unique_ptr<i2c::I2CInterface> i2c;
Lei YU9ab6d752019-10-28 17:03:20 +0800128};
129
Lei YUd19df252019-10-25 17:31:52 +0800130} // namespace updater