1 #pragma once 2 3 #include "backup_restore.hpp" 4 #include "gpio_monitor.hpp" 5 #include "listener.hpp" 6 #include "logger.hpp" 7 #include "worker.hpp" 8 9 #include <sdbusplus/asio/object_server.hpp> 10 11 #include <memory> 12 13 namespace vpd 14 { 15 /** 16 * @brief Class to handle OEM specific use case. 17 * 18 * Few pre-requisites needs to be taken case specifically, which will be 19 * encapsulated by this class. 20 */ 21 class IbmHandler 22 { 23 public: 24 /** 25 * List of deleted methods. 26 */ 27 IbmHandler(const IbmHandler&) = delete; 28 IbmHandler& operator=(const IbmHandler&) = delete; 29 IbmHandler(IbmHandler&&) = delete; 30 31 /** 32 * @brief Constructor. 33 * 34 * @param[in] o_worker - Reference to worker class object. 35 * @param[in] o_backupAndRestoreObj - Ref to back up and restore class 36 * object. 37 * @param[in] i_iFace - interface to implement. 38 * @param[in] i_progressiFace - Interface to track collection progress. 39 * @param[in] i_ioCon - IO context. 40 * @param[in] i_asioConnection - Dbus Connection. 41 * @param[in] i_vpdCollectionMode - VPD collection mode. 42 */ 43 IbmHandler( 44 std::shared_ptr<Worker>& o_worker, 45 std::shared_ptr<BackupAndRestore>& o_backupAndRestoreObj, 46 const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_iFace, 47 const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_progressiFace, 48 const std::shared_ptr<boost::asio::io_context>& i_ioCon, 49 const std::shared_ptr<sdbusplus::asio::connection>& i_asioConnection, 50 const types::VpdCollectionMode& i_vpdCollectionMode); 51 52 /** 53 * @brief API to collect all FRUs VPD. 54 * 55 * This api will call worker API to perform VPD collection for all FRUs 56 * present in the system config JSON and publish it on DBus. Also updates 57 * the Dbus VPD collection status property hosted under vpd-manager. 58 * 59 * Note: 60 * System VPD collection will always be skipped. 61 * If host is in power on state, FRUs marked as 'powerOffOnly' in the 62 * system config JSON will be skipped. 63 * 64 * @throw JsonException, runtime_error 65 */ 66 void collectAllFruVpd(); 67 68 private: 69 /** 70 * @brief API tocollect system VPD and set appropriate device tree and JSON. 71 * 72 * This API based on system chooses corresponding device tree and JSON. 73 * If device tree change is required, it updates the "fitconfig" and reboots 74 * the system. Else it is NOOP. 75 * 76 * @throw std::exception 77 * 78 * @param[out] o_parsedSystemVpdMap - Parsed system VPD map. 79 */ 80 void setDeviceTreeAndJson(types::VPDMapVariant& o_parsedSystemVpdMap); 81 82 /** 83 * @brief API to detect if system vpd is backed up in cache. 84 * 85 * System vpd can be cached either in cache or some other location. The 86 * information is extracted from system config json. 87 * 88 * @return True if the location is cache, fale otherwise. 89 */ 90 bool isBackupOnCache(); 91 92 /** 93 * @brief API to select system specific JSON. 94 * 95 * The API based on the IM value of VPD, will select appropriate JSON for 96 * the system. In case no system is found corresponding to the extracted IM 97 * value, error will be logged. 98 * 99 * @throw DataException, std::exception 100 * 101 * @param[out] o_systemJson - System JSON name. 102 * @param[in] i_parsedVpdMap - Parsed VPD map. 103 */ 104 void getSystemJson(std::string& o_systemJson, 105 const types::VPDMapVariant& i_parsedVpdMap); 106 107 /** 108 * @brief An API to perform backup or restore of VPD. 109 * 110 * @param[in,out] io_srcVpdMap - Source VPD map. 111 */ 112 void performBackupAndRestore(types::VPDMapVariant& io_srcVpdMap); 113 114 /** 115 * @brief An API to parse and publish system VPD on D-Bus. 116 * 117 * @throw DataException, std::runtime_error 118 * 119 * @param[in] parsedVpdMap - Parsed VPD as a map. 120 */ 121 void publishSystemVPD(const types::VPDMapVariant& i_parsedVpdMap); 122 123 /** 124 * @brief API to form asset tag string for the system. 125 * 126 * @param[in] i_parsedVpdMap - Parsed VPD map. 127 * 128 * @throw std::runtime_error 129 * 130 * @return - Formed asset tag string. 131 */ 132 std::string createAssetTagString( 133 const types::VPDMapVariant& i_parsedVpdMap); 134 135 /** 136 * @brief Set timer to detect and set VPD collection status for the system. 137 * 138 * Collection of FRU VPD is triggered in a separate thread. Resulting in 139 * multiple threads at a given time. The API creates a timer which on 140 * regular interval will check if all the threads were collected back and 141 * sets the status of the VPD collection for the system accordingly. 142 * 143 * @throw std::runtime_error 144 */ 145 void SetTimerToDetectVpdCollectionStatus(); 146 147 /** 148 * @brief API to process VPD collection thread failed EEPROMs. 149 */ 150 void processFailedEeproms(); 151 152 /** 153 * @brief API to check and update PowerVS VPD. 154 * 155 * The API will read the existing data from the DBus and if found 156 * different than what has been read from JSON, it will update the VPD with 157 * JSON data on hardware and DBus both. 158 * 159 * @param[in] i_powerVsJsonObj - PowerVS JSON object. 160 * @param[out] o_failedPathList - List of path failed to update. 161 */ 162 void checkAndUpdatePowerVsVpd(const nlohmann::json& i_powerVsJsonObj, 163 std::vector<std::string>& o_failedPathList); 164 /** 165 * @brief API to handle configuration w.r.t. PowerVS systems. 166 * 167 * Some FRUs VPD is specific to powerVS system. The API detects the 168 * powerVS configuration and updates the VPD accordingly. 169 */ 170 void ConfigurePowerVsSystem(); 171 172 /** 173 * @brief API to perform initial setup before manager claims Bus name. 174 * 175 * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for 176 * corret device tree, inventory JSON w.r.t system should be linked and 177 * system VPD should be on DBus. 178 */ 179 void performInitialSetup(); 180 181 /** 182 * @brief Function to enable and bring MUX out of idle state. 183 * 184 * This finds all the MUX defined in the system json and enables them by 185 * setting the holdidle parameter to 0. 186 * 187 * @throw std::runtime_error 188 */ 189 void enableMuxChips(); 190 191 /** 192 * @brief Checks whether the system is an RBMC prototype. 193 * 194 * @param[out] o_errCode - To set error code in case of error. 195 * 196 * @return true for RBMC prototype system, false otherwise. 197 */ 198 bool isRbmcPrototypeSystem(uint16_t& o_errCode) const noexcept; 199 200 /** 201 * @brief Checks and updates BMC position. 202 * 203 * This API updates BMC position for the RBMC prototype 204 * system based on whether the motherboard EEPROM is accessible. 205 * 206 * @param[out] o_bmcPosition - BMC position. 207 */ 208 void checkAndUpdateBmcPosition(size_t& o_bmcPosition) const noexcept; 209 210 /** 211 * @brief API to check sysconfig json symlink. 212 */ 213 void isSymlinkPresent() noexcept; 214 215 /** @brief API to set symbolic link for system config JSON. 216 * 217 * Once correct device tree is set, symbolic link to the correct sytsem 218 * config JSON is set to be used in subsequent BMC boot. 219 * 220 * @throws std::runtime_error 221 * 222 * @param[in] i_systemJson - system config JSON. 223 */ 224 void setJsonSymbolicLink(const std::string& i_systemJson); 225 226 /** 227 * @brief API to initialize worker object. 228 * 229 * @throws std::runtime_error. 230 */ 231 void initWorker(); 232 233 /** 234 * @brief API to set environment variable and reboot the BMC 235 * 236 * @param[in] i_key - Name of the environment variable 237 * @param[in] i_value - Value of the environment variable 238 * 239 * @throw std::runtime_error 240 */ 241 void setEnvAndReboot(const std::string& i_key, const std::string& i_value); 242 243 /** 244 * @brief API to read the fitconfig environment variable 245 * 246 * @return On success, returns the value of the fitconfig environment 247 * variable, otherwise returns empty string 248 */ 249 std::string readFitConfigValue(); 250 251 /** 252 * @brief API to initialize back up and restore class. 253 */ 254 void initBackupAndRestore() noexcept; 255 256 /** 257 * @brief API to register listener objects. 258 */ 259 void initEventListeners() noexcept; 260 261 /** 262 * @brief API to set BMC position. 263 * 264 * The API sets BMC position under system inventory path. In case of any 265 * error, default value will be set as BMC position. 266 */ 267 void setBmcPosition(); 268 269 // Parsed system config json object. 270 nlohmann::json m_sysCfgJsonObj{}; 271 272 // Shared pointer to worker class 273 std::shared_ptr<Worker>& m_worker; 274 275 // Shared pointer to backup and restore object. 276 std::shared_ptr<BackupAndRestore>& m_backupAndRestoreObj; 277 278 // Shared pointer to GpioMonitor object. 279 std::shared_ptr<GpioMonitor> m_gpioMonitor; 280 281 // Shared pointer to Dbus interface class. 282 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface; 283 284 // Shared pointer to Dbus collection progress interface class. 285 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_progressInterface; 286 287 // Shared pointer to asio context object. 288 const std::shared_ptr<boost::asio::io_context>& m_ioContext; 289 290 // Shared pointer to bus connection. 291 const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection; 292 293 // Shared pointer to Listener object. 294 std::shared_ptr<Listener> m_eventListener; 295 296 // Shared pointer to Logger object. 297 std::shared_ptr<Logger> m_logger; 298 299 // vpd collection mode 300 const types::VpdCollectionMode m_vpdCollectionMode; 301 302 // Holds if sysmlink to config JSON is present or not. 303 bool m_isSymlinkPresent = false; 304 305 // Holds path to the config JSON being used. 306 std::string m_configJsonPath{INVENTORY_JSON_DEFAULT}; 307 308 // To distinguish the factory reset path. 309 bool m_isFactoryResetDone = false; 310 }; 311 } // namespace vpd 312