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 reads the position gpio pin and updates the bmc position. In 204 * case of any error, default value of bmc position passed as parameter is 205 * retained. 206 * 207 * @param[out] o_bmcPosition - BMC position. 208 */ 209 void checkAndUpdateBmcPosition(size_t& o_bmcPosition) const noexcept; 210 211 /** 212 * @brief API to check sysconfig json symlink. 213 */ 214 void isSymlinkPresent() noexcept; 215 216 /** @brief API to set symbolic link for system config JSON. 217 * 218 * Once correct device tree is set, symbolic link to the correct sytsem 219 * config JSON is set to be used in subsequent BMC boot. 220 * 221 * @throws std::runtime_error 222 * 223 * @param[in] i_systemJson - system config JSON. 224 */ 225 void setJsonSymbolicLink(const std::string& i_systemJson); 226 227 /** 228 * @brief API to initialize worker object. 229 * 230 * @throws std::runtime_error. 231 */ 232 void initWorker(); 233 234 /** 235 * @brief API to set environment variable and reboot the BMC 236 * 237 * @param[in] i_key - Name of the environment variable 238 * @param[in] i_value - Value of the environment variable 239 * 240 * @throw std::runtime_error 241 */ 242 void setEnvAndReboot(const std::string& i_key, const std::string& i_value); 243 244 /** 245 * @brief API to read the fitconfig environment variable 246 * 247 * @return On success, returns the value of the fitconfig environment 248 * variable, otherwise returns empty string 249 */ 250 std::string readFitConfigValue(); 251 252 /** 253 * @brief API to initialize back up and restore class. 254 */ 255 void initBackupAndRestore() noexcept; 256 257 /** 258 * @brief API to register listener objects. 259 */ 260 void initEventListeners() noexcept; 261 262 /** 263 * @brief API to set BMC position. 264 * 265 * The API sets BMC position under system inventory path. In case of any 266 * error, default value will be set as BMC position. 267 */ 268 void setBmcPosition(); 269 270 /** 271 * @brief API to write the BMC position to a file. 272 * 273 * Writes the BMC position value to /run/openbmc/bmc_position file, 274 * creating the directory if it doesn't exist. 275 * 276 * @param[in] i_bmcPosition - BMC position value to write. 277 */ 278 void writeBmcPositionToFile(const size_t i_bmcPosition); 279 280 // Parsed system config json object. 281 nlohmann::json m_sysCfgJsonObj{}; 282 283 // Shared pointer to worker class 284 std::shared_ptr<Worker>& m_worker; 285 286 // Shared pointer to backup and restore object. 287 std::shared_ptr<BackupAndRestore>& m_backupAndRestoreObj; 288 289 // Shared pointer to GpioMonitor object. 290 std::shared_ptr<GpioMonitor> m_gpioMonitor; 291 292 // Shared pointer to Dbus interface class. 293 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface; 294 295 // Shared pointer to Dbus collection progress interface class. 296 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_progressInterface; 297 298 // Shared pointer to asio context object. 299 const std::shared_ptr<boost::asio::io_context>& m_ioContext; 300 301 // Shared pointer to bus connection. 302 const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection; 303 304 // Shared pointer to Listener object. 305 std::shared_ptr<Listener> m_eventListener; 306 307 // Shared pointer to Logger object. 308 std::shared_ptr<Logger> m_logger; 309 310 // vpd collection mode 311 const types::VpdCollectionMode m_vpdCollectionMode; 312 313 // Holds if sysmlink to config JSON is present or not. 314 bool m_isSymlinkPresent = false; 315 316 // Holds path to the config JSON being used. 317 std::string m_configJsonPath{INVENTORY_JSON_DEFAULT}; 318 319 // To distinguish the factory reset path. 320 bool m_isFactoryResetDone = false; 321 }; 322 } // namespace vpd 323