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