blob: 28c7c9c8b4f2ee336587530a7cf7e696cde37264 [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
Sampa Misraaea5dde2020-08-31 08:33:47 -0500104 virtual ~CodeUpdate()
105 {}
106
107 private:
108 std::string currBootSide; //!< current boot side
109 std::string nextBootSide; //!< next boot side
110 std::string runningVersion; //!< currently running image
111 std::string nonRunningVersion; //!< alternate image
112 std::string newImageId; //!< new image id
113 bool codeUpdateInProgress =
114 false; //!< indicates whether codeupdate is going on
115 const pldm::utils::DBusHandler* dBusIntf; //!< D-Bus handler
116 std::vector<std::unique_ptr<sdbusplus::bus::match::match>>
117 captureNextBootSideChange; //!< vector to catch the D-Bus property
118 //!< change for next boot side
119 std::unique_ptr<sdbusplus::bus::match::match>
120 fwUpdateMatcher; //!< pointer to capture the interface added signal for
121 //!< new image
122 pldm::responder::oem_platform::Handler*
123 oemPlatformHandler; //!< oem platform handler
124
125 /* @brief Method to take action when the subscribed D-Bus property is
126 * changed
127 * @param[in] chProperties - list of properties which have changed
128 * @return - none
129 */
130
131 void
132 processPriorityChangeNotification(const DbusChangedProps& chProperties);
133};
134
135/* @brief Method to fetch current or next boot side
136 * @param[in] entityInstance - entity instance for the sensor
137 * @param[in] codeUpdate - pointer to the CodeUpdate object
138 *
139 * @return - boot side
140 */
141uint8_t fetchBootSide(uint16_t entityInstance, CodeUpdate* codeUpdate);
142
143/* @brief Method to set current or next boot side
144 * @param[in] entityInstance - entity instance for the effecter
145 * @param[in] currState - state to be set
146 * @param[in] stateField - state field set as sent by Host
147 * @return - PLDM_SUCCESS codes
148 */
149int setBootSide(uint16_t entityInstance, uint8_t currState,
150 const std::vector<set_effecter_state_field>& stateField,
151 CodeUpdate* codeUpdate);
152
Adriana Kobylak727f7382020-09-01 14:38:25 -0500153/* @brief Method to process LIDs during inband update, such as verifying and
154 * removing the header to get them ready to be written to flash
155 * @param[in] filePath - Path to the LID file
156 * @return - PLDM_SUCCESS codes
157 */
158int processCodeUpdateLid(const std::string& filePath);
Adriana Kobylak837fb472020-10-16 16:53:42 -0500159
160/** @brief Method to assemble the code update tarball and trigger the
161 * phosphor software manager to create a version interface
162 * @return - PLDM_SUCCESS codes
163 */
164int assembleCodeUpdateImage();
165
Sampa Misraaea5dde2020-08-31 08:33:47 -0500166} // namespace responder
167} // namespace pldm