blob: 77ada56c376c2a1a5c2f19fc1c0c2d2fccf08a4e [file] [log] [blame]
Sampa Misraaea5dde2020-08-31 08:33:47 -05001#pragma once
2
3#include "common/utils.hpp"
Sagar Srinivas78a225a2020-08-27 00:52:20 -05004#include "libpldmresponder/pdr_utils.hpp"
Sampa Misraaea5dde2020-08-31 08:33:47 -05005#include "libpldmresponder/platform.hpp"
6
7#include <string>
8
9using namespace pldm::utils;
10namespace pldm
11{
12namespace responder
13{
14
15static constexpr uint8_t pSideNum = 1;
16static constexpr uint8_t tSideNum = 2;
17static constexpr auto Pside = "P";
18static constexpr auto Tside = "T";
19
20static constexpr auto redundancyIntf =
21 "xyz.openbmc_project.Software.RedundancyPriority";
22
23/** @class CodeUpdate
24 *
25 * @brief This class performs the necessary operation in pldm for
26 * inband code update. That includes taking actions on the
27 * setStateEffecterStates calls from Host and also sending
28 * notification to phosphor-software-manager app
29 */
30class CodeUpdate
31{
32 public:
33 /** @brief Constructor to create an inband codeupdate object
34 * @param[in] dBusIntf - D-Bus handler pointer
35 */
36 CodeUpdate(const pldm::utils::DBusHandler* dBusIntf) : dBusIntf(dBusIntf)
37 {
38 currBootSide = Tside;
39 nextBootSide = Tside;
40 }
41
42 /* @brief Method to return the current boot side
43 */
44 std::string fetchCurrentBootSide();
45
46 /* @brief Method to return the next boot side
47 */
48 std::string fetchNextBootSide();
49
50 /* @brief Method to set the current boot side or
51 * perform a rename operation on current boot side
52 * @param[in] currSide - current side to be set to
53 * @return PLDM_SUCCESS codes
54 */
55 int setCurrentBootSide(const std::string& currSide);
56
57 /* @brief Method to set the next boot side
58 * @param[in] nextSide - next boot side to be set to
59 * @return PLDM_SUCCESS codes
60 */
61 int setNextBootSide(const std::string& nextSide);
62
63 /* @brief Method to set the running and non-running
64 * images
65 */
66 virtual void setVersions();
67
68 /* @brief Method to return the newly upoaded image id in
69 * /tmp
70 */
71 std::string fetchnewImageId()
72 {
73 return newImageId;
74 }
75
76 /* @brief Method to set the oem platform handler in CodeUpdate class */
77 void setOemPlatformHandler(pldm::responder::oem_platform::Handler* handler);
78
Sampa Misra69508502020-09-08 00:08:21 -050079 /* @brief Method to check whether code update is
80 * going on
81 * @return - bool
82 */
83 bool isCodeUpdateInProgress()
84 {
85 return codeUpdateInProgress;
86 }
87
88 /* @brief Method to indicate whether code update
89 * is going on
90 * @param[in] progress - yes/no
91 */
92 void setCodeUpdateProgress(bool progress)
93 {
94 codeUpdateInProgress = progress;
95 }
96
Varsha Kaverappa3ca29df2020-09-27 12:39:22 -050097 /** @brief Method to clear contents the LID staging directory that contains
98 * images such as host firmware and BMC.
99 * @param[in] dirPath - directory system path that has to be cleared
100 * @return none
101 */
102 void clearDirPath(const std::string& dirPath);
103
Sagar Srinivascfdbca72020-09-22 10:03:35 -0500104 /* @brief Method to set the RequestApplyTime D-Bus property
105 * on start update to OnReset
106 * @return - Completion codes
107 */
108 int setRequestedApplyTime();
109
110 /* @brief Method to set the RequestedActivation D-Bus property
111 * on end update to Active by fetching the newImageID and
112 * clearning it once RequestedActivation is set or on error
113 * @param[in] codeUpdate - codeUpdate pointer
114 * @return - Completion codes
115 */
116 int setRequestedActivation();
117
Sampa Misraaea5dde2020-08-31 08:33:47 -0500118 virtual ~CodeUpdate()
119 {}
120
121 private:
122 std::string currBootSide; //!< current boot side
123 std::string nextBootSide; //!< next boot side
124 std::string runningVersion; //!< currently running image
125 std::string nonRunningVersion; //!< alternate image
126 std::string newImageId; //!< new image id
127 bool codeUpdateInProgress =
128 false; //!< indicates whether codeupdate is going on
129 const pldm::utils::DBusHandler* dBusIntf; //!< D-Bus handler
130 std::vector<std::unique_ptr<sdbusplus::bus::match::match>>
131 captureNextBootSideChange; //!< vector to catch the D-Bus property
132 //!< change for next boot side
133 std::unique_ptr<sdbusplus::bus::match::match>
134 fwUpdateMatcher; //!< pointer to capture the interface added signal for
135 //!< new image
136 pldm::responder::oem_platform::Handler*
137 oemPlatformHandler; //!< oem platform handler
138
139 /* @brief Method to take action when the subscribed D-Bus property is
140 * changed
141 * @param[in] chProperties - list of properties which have changed
142 * @return - none
143 */
144
145 void
146 processPriorityChangeNotification(const DbusChangedProps& chProperties);
147};
148
149/* @brief Method to fetch current or next boot side
150 * @param[in] entityInstance - entity instance for the sensor
151 * @param[in] codeUpdate - pointer to the CodeUpdate object
152 *
153 * @return - boot side
154 */
155uint8_t fetchBootSide(uint16_t entityInstance, CodeUpdate* codeUpdate);
156
157/* @brief Method to set current or next boot side
158 * @param[in] entityInstance - entity instance for the effecter
159 * @param[in] currState - state to be set
160 * @param[in] stateField - state field set as sent by Host
161 * @return - PLDM_SUCCESS codes
162 */
163int setBootSide(uint16_t entityInstance, uint8_t currState,
164 const std::vector<set_effecter_state_field>& stateField,
165 CodeUpdate* codeUpdate);
166
Adriana Kobylak727f7382020-09-01 14:38:25 -0500167/* @brief Method to process LIDs during inband update, such as verifying and
168 * removing the header to get them ready to be written to flash
169 * @param[in] filePath - Path to the LID file
170 * @return - PLDM_SUCCESS codes
171 */
172int processCodeUpdateLid(const std::string& filePath);
Adriana Kobylak837fb472020-10-16 16:53:42 -0500173
174/** @brief Method to assemble the code update tarball and trigger the
175 * phosphor software manager to create a version interface
176 * @return - PLDM_SUCCESS codes
177 */
178int assembleCodeUpdateImage();
179
Sampa Misraaea5dde2020-08-31 08:33:47 -0500180} // namespace responder
181} // namespace pldm