blob: 458f651f21ab34afe698bc5b89ddafefbbf1ecad [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 <sdbusplus/bus.hpp>
Brandon Wymand1bc4ce2019-12-13 14:20:34 -060021
22#include <filesystem>
Lei YUd19df252019-10-25 17:31:52 +080023#include <string>
24
Lei YU7c2fbbb2019-11-06 14:56:02 +080025class TestUpdater;
26
Lei YUd19df252019-10-25 17:31:52 +080027namespace updater
28{
29
Lei YU9ab6d752019-10-28 17:03:20 +080030namespace fs = std::filesystem;
31
Lei YUd19df252019-10-25 17:31:52 +080032/**
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 */
40bool update(const std::string& psuInventoryPath, const std::string& imageDir);
41
Lei YU9ab6d752019-10-28 17:03:20 +080042class Updater
43{
44 public:
Lei YU7c2fbbb2019-11-06 14:56:02 +080045 friend TestUpdater;
Lei YU9ab6d752019-10-28 17:03:20 +080046 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 YU575ed132019-10-29 17:22:16 +080063 ~Updater() = default;
Lei YU9ab6d752019-10-28 17:03:20 +080064
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 YU575ed132019-10-29 17:22:16 +080077 /** @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 YU9ab6d752019-10-28 17:03:20 +080083 /** @brief Do the PSU update
84 *
85 * @return 0 if success, otherwise non-zero
86 */
87 int doUpdate();
88
Lei YU7c2fbbb2019-11-06 14:56:02 +080089 /** @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 YU9ab6d752019-10-28 17:03:20 +080096 private:
97 /** @brief The sdbusplus DBus bus connection */
Patrick Williams7354ce62022-07-22 19:26:56 -050098 sdbusplus::bus_t bus;
Lei YU9ab6d752019-10-28 17:03:20 +080099
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 YU7c2fbbb2019-11-06 14:56:02 +0800126
127 /** @brief The i2c device interface */
128 std::unique_ptr<i2c::I2CInterface> i2c;
Lei YU9ab6d752019-10-28 17:03:20 +0800129};
130
Lei YUd19df252019-10-25 17:31:52 +0800131} // namespace updater