blob: 9f67553f79bf25149d93e24502c8c85f9793054d [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
Sampa Misraaea5dde2020-08-31 08:33:47 -05009namespace pldm
10{
11namespace responder
12{
13
14static constexpr uint8_t pSideNum = 1;
15static constexpr uint8_t tSideNum = 2;
16static constexpr auto Pside = "P";
17static constexpr auto Tside = "T";
18
19static constexpr auto redundancyIntf =
20 "xyz.openbmc_project.Software.RedundancyPriority";
21
22/** @class CodeUpdate
23 *
24 * @brief This class performs the necessary operation in pldm for
25 * inband code update. That includes taking actions on the
26 * setStateEffecterStates calls from Host and also sending
27 * notification to phosphor-software-manager app
28 */
29class CodeUpdate
30{
31 public:
32 /** @brief Constructor to create an inband codeupdate object
33 * @param[in] dBusIntf - D-Bus handler pointer
34 */
35 CodeUpdate(const pldm::utils::DBusHandler* dBusIntf) : dBusIntf(dBusIntf)
36 {
37 currBootSide = Tside;
38 nextBootSide = Tside;
Sampa Misra3a0e3b92020-10-21 05:58:00 -050039 markerLidSensorId = PLDM_INVALID_EFFECTER_ID;
40 firmwareUpdateSensorId = PLDM_INVALID_EFFECTER_ID;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -060041 imageActivationMatch = nullptr;
Sampa Misraaea5dde2020-08-31 08:33:47 -050042 }
43
44 /* @brief Method to return the current boot side
45 */
46 std::string fetchCurrentBootSide();
47
48 /* @brief Method to return the next boot side
49 */
50 std::string fetchNextBootSide();
51
52 /* @brief Method to set the current boot side or
53 * perform a rename operation on current boot side
54 * @param[in] currSide - current side to be set to
55 * @return PLDM_SUCCESS codes
56 */
57 int setCurrentBootSide(const std::string& currSide);
58
59 /* @brief Method to set the next boot side
60 * @param[in] nextSide - next boot side to be set to
61 * @return PLDM_SUCCESS codes
62 */
63 int setNextBootSide(const std::string& nextSide);
64
65 /* @brief Method to set the running and non-running
66 * images
67 */
68 virtual void setVersions();
69
70 /* @brief Method to return the newly upoaded image id in
71 * /tmp
72 */
73 std::string fetchnewImageId()
74 {
75 return newImageId;
76 }
77
78 /* @brief Method to set the oem platform handler in CodeUpdate class */
79 void setOemPlatformHandler(pldm::responder::oem_platform::Handler* handler);
80
Sampa Misra69508502020-09-08 00:08:21 -050081 /* @brief Method to check whether code update is
82 * going on
83 * @return - bool
84 */
85 bool isCodeUpdateInProgress()
86 {
87 return codeUpdateInProgress;
88 }
89
90 /* @brief Method to indicate whether code update
91 * is going on
92 * @param[in] progress - yes/no
93 */
94 void setCodeUpdateProgress(bool progress)
95 {
96 codeUpdateInProgress = progress;
97 }
98
Varsha Kaverappa3ca29df2020-09-27 12:39:22 -050099 /** @brief Method to clear contents the LID staging directory that contains
100 * images such as host firmware and BMC.
101 * @param[in] dirPath - directory system path that has to be cleared
102 * @return none
103 */
104 void clearDirPath(const std::string& dirPath);
105
Sagar Srinivascfdbca72020-09-22 10:03:35 -0500106 /* @brief Method to set the RequestApplyTime D-Bus property
107 * on start update to OnReset
108 * @return - Completion codes
109 */
110 int setRequestedApplyTime();
111
112 /* @brief Method to set the RequestedActivation D-Bus property
113 * on end update to Active by fetching the newImageID and
114 * clearning it once RequestedActivation is set or on error
115 * @param[in] codeUpdate - codeUpdate pointer
116 * @return - Completion codes
117 */
118 int setRequestedActivation();
119
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500120 /* @brief Method to fetch the sensor id for marker lid
121 * validation PDR
122 * @return - sensor id
123 */
124 uint16_t getMarkerLidSensor()
125 {
126 return markerLidSensorId;
127 }
128
129 /* @brief Method to set the sensor id for marker lid
130 * validation
131 * @param[in] sensorId - sensor id for marker lid validation
132 */
133 void setMarkerLidSensor(uint16_t sensorId)
134 {
135 markerLidSensorId = sensorId;
136 }
137
138 /* @brief Method to set the sensor id for firmware update state
139 * @param[in] sensorId - sensor id for firmware update state
140 */
141 void setFirmwareUpdateSensor(uint16_t sensorId)
142 {
143 firmwareUpdateSensorId = sensorId;
144 }
145
146 /* @brief Method to fetch the sensor id for firmware update state
147 * @return - sensor id
148 */
149 uint16_t getFirmwareUpdateSensor()
150 {
151 return firmwareUpdateSensorId;
152 }
153
Archana Kakanic23b6142025-02-19 04:04:20 -0600154 /* @brief Method to set the sensor id for boot side rename state
155 * @param[in] sensorId - sensor id for boot side rename update
156 * state
157 */
158 void setBootSideRenameStateSensor(uint16_t sensorId)
159 {
160 bootSideRenameStateSensorId = sensorId;
161 }
162
163 /* @brief Method to fetch the sensor id for boot side rename state
164 * @return - sensor id
165 */
166 uint16_t getBootSideRenameStateSensor()
167 {
168 return bootSideRenameStateSensorId;
169 }
170
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500171 /* @brief Method to send a state sensor event to Host from CodeUpdate class
172 * @param[in] sensorId - sensor id for the event
173 * @param[in] sensorEventClass - sensor event class wrt DSP0248
174 * @param[in] sensorOffset - sensor offset
175 * @param[in] eventState - new event state
176 * @param[in] prevEventState - previous state
177 */
178 void sendStateSensorEvent(uint16_t sensorId,
179 enum sensor_event_class_states sensorEventClass,
180 uint8_t sensorOffset, uint8_t eventState,
181 uint8_t prevEventState);
182
183 /* @brief Method to delete the image from non running side prior to
184 * an inband code update
185 */
186 void deleteImage();
187
Adriana Kobylak9296f242021-09-22 15:52:00 +0000188 /** @brief Method to assemble the code update tarball and trigger the
189 * phosphor software manager to create a version interface
190 * @return - PLDM_SUCCESS codes
191 */
192 int assembleCodeUpdateImage();
193
Archana Kakanic23b6142025-02-19 04:04:20 -0600194 /* @brief Method to process the bootside rename event, sends a boot side
195 * rename event notification to host when code update is initiated*/
196 void processRenameEvent();
197
Patrick Williams6da4f912023-05-10 07:50:53 -0500198 virtual ~CodeUpdate() {}
Sampa Misraaea5dde2020-08-31 08:33:47 -0500199
200 private:
201 std::string currBootSide; //!< current boot side
202 std::string nextBootSide; //!< next boot side
203 std::string runningVersion; //!< currently running image
204 std::string nonRunningVersion; //!< alternate image
205 std::string newImageId; //!< new image id
206 bool codeUpdateInProgress =
Patrick Williams6da4f912023-05-10 07:50:53 -0500207 false; //!< indicates whether codeupdate is going on
Sampa Misraaea5dde2020-08-31 08:33:47 -0500208 const pldm::utils::DBusHandler* dBusIntf; //!< D-Bus handler
Patrick Williams84b790c2022-07-22 19:26:56 -0500209 std::vector<std::unique_ptr<sdbusplus::bus::match_t>>
Sampa Misraaea5dde2020-08-31 08:33:47 -0500210 captureNextBootSideChange; //!< vector to catch the D-Bus property
211 //!< change for next boot side
Patrick Williams84b790c2022-07-22 19:26:56 -0500212 std::vector<std::unique_ptr<sdbusplus::bus::match_t>>
Sampa Misraaea5dde2020-08-31 08:33:47 -0500213 fwUpdateMatcher; //!< pointer to capture the interface added signal for
214 //!< new image
215 pldm::responder::oem_platform::Handler*
216 oemPlatformHandler; //!< oem platform handler
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500217 uint16_t markerLidSensorId;
218 uint16_t firmwareUpdateSensorId;
Archana Kakanic23b6142025-02-19 04:04:20 -0600219 uint16_t bootSideRenameStateSensorId;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600220 /** @brief D-Bus property changed signal match for image activation */
Patrick Williams84b790c2022-07-22 19:26:56 -0500221 std::unique_ptr<sdbusplus::bus::match_t> imageActivationMatch;
Sagar Srinivas9a64b4a2021-02-09 07:55:38 -0600222
Sampa Misraaea5dde2020-08-31 08:33:47 -0500223 /* @brief Method to take action when the subscribed D-Bus property is
224 * changed
225 * @param[in] chProperties - list of properties which have changed
226 * @return - none
227 */
Brad Bishop5079ac42021-08-19 18:35:06 -0400228 void processPriorityChangeNotification(
229 const pldm::utils::DbusChangedProps& chProperties);
Sampa Misraaea5dde2020-08-31 08:33:47 -0500230};
231
232/* @brief Method to fetch current or next boot side
233 * @param[in] entityInstance - entity instance for the sensor
234 * @param[in] codeUpdate - pointer to the CodeUpdate object
235 *
236 * @return - boot side
237 */
238uint8_t fetchBootSide(uint16_t entityInstance, CodeUpdate* codeUpdate);
239
240/* @brief Method to set current or next boot side
241 * @param[in] entityInstance - entity instance for the effecter
242 * @param[in] currState - state to be set
243 * @param[in] stateField - state field set as sent by Host
244 * @return - PLDM_SUCCESS codes
245 */
246int setBootSide(uint16_t entityInstance, uint8_t currState,
247 const std::vector<set_effecter_state_field>& stateField,
248 CodeUpdate* codeUpdate);
249
Adriana Kobylak727f7382020-09-01 14:38:25 -0500250/* @brief Method to process LIDs during inband update, such as verifying and
251 * removing the header to get them ready to be written to flash
252 * @param[in] filePath - Path to the LID file
253 * @return - PLDM_SUCCESS codes
254 */
255int processCodeUpdateLid(const std::string& filePath);
Adriana Kobylak837fb472020-10-16 16:53:42 -0500256
Sampa Misraaea5dde2020-08-31 08:33:47 -0500257} // namespace responder
258} // namespace pldm