blob: befa4fba1d834d166617a88d0c69a55f878185cd [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 YU9ab6d752019-10-28 17:03:20 +080018#include <filesystem>
19#include <sdbusplus/bus.hpp>
Lei YUd19df252019-10-25 17:31:52 +080020#include <string>
21
22namespace updater
23{
24
Lei YU9ab6d752019-10-28 17:03:20 +080025namespace fs = std::filesystem;
26
Lei YUd19df252019-10-25 17:31:52 +080027/**
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 */
35bool update(const std::string& psuInventoryPath, const std::string& imageDir);
36
Lei YU9ab6d752019-10-28 17:03:20 +080037class 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 YU575ed132019-10-29 17:22:16 +080057 ~Updater() = default;
Lei YU9ab6d752019-10-28 17:03:20 +080058
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 YU575ed132019-10-29 17:22:16 +080071 /** @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 YU9ab6d752019-10-28 17:03:20 +080077 /** @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 YUd19df252019-10-25 17:31:52 +0800115} // namespace updater