PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 1 | #include "vpd_tool_impl.hpp" |
| 2 | |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 3 | #include "vpd_exceptions.hpp" |
| 4 | |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 5 | #include <cstdlib> |
| 6 | #include <filesystem> |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 7 | #include <iostream> |
| 8 | #include <sdbusplus/bus.hpp> |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 9 | #include <variant> |
| 10 | #include <vector> |
| 11 | |
| 12 | using namespace std; |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 13 | using namespace openpower::vpd; |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 14 | using namespace inventory; |
| 15 | using namespace openpower::vpd::manager::editor; |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 16 | namespace fs = std::filesystem; |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 17 | using json = nlohmann::json; |
| 18 | using namespace openpower::vpd::exceptions; |
| 19 | |
| 20 | Binary VpdTool::toBinary(const std::string& value) |
| 21 | { |
| 22 | Binary val{}; |
| 23 | if (value.find("0x") == string::npos) |
| 24 | { |
| 25 | val.assign(value.begin(), value.end()); |
| 26 | } |
| 27 | else if (value.find("0x") != string::npos) |
| 28 | { |
| 29 | stringstream ss; |
| 30 | ss.str(value.substr(2)); |
| 31 | string byteStr{}; |
| 32 | |
Priyanga Ramasamy | ec912e6 | 2021-12-15 22:47:51 -0600 | [diff] [blame^] | 33 | if (value.length() % 2 != 0) |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 34 | { |
Priyanga Ramasamy | ec912e6 | 2021-12-15 22:47:51 -0600 | [diff] [blame^] | 35 | throw runtime_error( |
| 36 | "VPD-TOOL write option accepts 2 digit hex numbers. (Eg. 0x1 " |
| 37 | "should be given as 0x01). Aborting the write operation."); |
| 38 | } |
| 39 | |
| 40 | if (value.find_first_not_of("0123456789abcdefABCDEF", 2) != |
| 41 | std::string::npos) |
| 42 | { |
| 43 | throw runtime_error("Provide a valid hexadecimal input."); |
| 44 | } |
| 45 | |
| 46 | while (ss >> setw(2) >> byteStr) |
| 47 | { |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 48 | uint8_t byte = strtoul(byteStr.c_str(), nullptr, 16); |
| 49 | |
| 50 | val.push_back(byte); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | else |
| 55 | { |
| 56 | throw runtime_error("The value to be updated should be either in ascii " |
| 57 | "or in hex. Refer --help option"); |
| 58 | } |
| 59 | return val; |
| 60 | } |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 61 | |
PriyangaRamasamy | 6ee637a | 2021-02-12 04:49:02 -0600 | [diff] [blame] | 62 | void VpdTool::printReturnCode(int returnCode) |
| 63 | { |
| 64 | if (returnCode) |
| 65 | { |
| 66 | cout << "\n Command failed with the return code " << returnCode |
| 67 | << ". Continuing the execution. " << endl; |
| 68 | } |
| 69 | } |
| 70 | |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 71 | void VpdTool::eraseInventoryPath(string& fru) |
| 72 | { |
| 73 | // Power supply frupath comes with INVENTORY_PATH appended in prefix. |
| 74 | // Stripping it off inorder to avoid INVENTORY_PATH duplication |
| 75 | // during getVINIProperties() execution. |
| 76 | fru.erase(0, sizeof(INVENTORY_PATH) - 1); |
| 77 | } |
| 78 | |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 79 | void VpdTool::debugger(json output) |
| 80 | { |
| 81 | cout << output.dump(4) << '\n'; |
| 82 | } |
| 83 | |
| 84 | auto VpdTool::makeDBusCall(const string& objectName, const string& interface, |
| 85 | const string& kw) |
| 86 | { |
| 87 | auto bus = sdbusplus::bus::new_default(); |
| 88 | auto properties = |
| 89 | bus.new_method_call(INVENTORY_MANAGER_SERVICE, objectName.c_str(), |
| 90 | "org.freedesktop.DBus.Properties", "Get"); |
| 91 | properties.append(interface); |
| 92 | properties.append(kw); |
| 93 | auto result = bus.call(properties); |
| 94 | |
| 95 | if (result.is_method_error()) |
| 96 | { |
| 97 | throw runtime_error("Get api failed"); |
| 98 | } |
| 99 | return result; |
| 100 | } |
| 101 | |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 102 | json VpdTool::getVINIProperties(string invPath) |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 103 | { |
| 104 | variant<Binary> response; |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 105 | json kwVal = json::object({}); |
| 106 | |
| 107 | vector<string> keyword{"CC", "SN", "PN", "FN", "DR"}; |
| 108 | string interface = "com.ibm.ipzvpd.VINI"; |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 109 | string objectName = {}; |
| 110 | |
| 111 | if (invPath.find(INVENTORY_PATH) != string::npos) |
| 112 | { |
| 113 | objectName = invPath; |
| 114 | eraseInventoryPath(invPath); |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | objectName = INVENTORY_PATH + invPath; |
| 119 | } |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 120 | for (string kw : keyword) |
| 121 | { |
| 122 | try |
| 123 | { |
| 124 | makeDBusCall(objectName, interface, kw).read(response); |
| 125 | |
| 126 | if (auto vec = get_if<Binary>(&response)) |
| 127 | { |
PriyangaRamasamy | 887a42a | 2020-09-03 00:33:57 +0530 | [diff] [blame] | 128 | string printableVal = getPrintableValue(*vec); |
| 129 | kwVal.emplace(kw, printableVal); |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 130 | } |
| 131 | } |
Patrick Williams | 8be4334 | 2021-09-02 09:33:36 -0500 | [diff] [blame] | 132 | catch (const sdbusplus::exception::exception& e) |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 133 | { |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 134 | if (string(e.name()) == |
| 135 | string("org.freedesktop.DBus.Error.UnknownObject")) |
| 136 | { |
| 137 | kwVal.emplace(invPath, json::object({})); |
| 138 | objFound = false; |
| 139 | break; |
| 140 | } |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 144 | return kwVal; |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 145 | } |
| 146 | |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 147 | void VpdTool::getExtraInterfaceProperties(const string& invPath, |
| 148 | const string& extraInterface, |
| 149 | const json& prop, json& output) |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 150 | { |
| 151 | variant<string> response; |
| 152 | |
| 153 | string objectName = INVENTORY_PATH + invPath; |
| 154 | |
| 155 | for (const auto& itProp : prop.items()) |
| 156 | { |
| 157 | string kw = itProp.key(); |
| 158 | try |
| 159 | { |
| 160 | makeDBusCall(objectName, extraInterface, kw).read(response); |
| 161 | |
| 162 | if (auto str = get_if<string>(&response)) |
| 163 | { |
| 164 | output.emplace(kw, *str); |
| 165 | } |
| 166 | } |
Patrick Williams | 8be4334 | 2021-09-02 09:33:36 -0500 | [diff] [blame] | 167 | catch (const sdbusplus::exception::exception& e) |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 168 | { |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 169 | if (std::string(e.name()) == |
| 170 | std::string("org.freedesktop.DBus.Error.UnknownObject")) |
| 171 | { |
| 172 | objFound = false; |
| 173 | break; |
| 174 | } |
| 175 | else if (std::string(e.name()) == |
| 176 | std::string("org.freedesktop.DBus.Error.UnknownProperty")) |
| 177 | { |
| 178 | output.emplace(kw, ""); |
| 179 | } |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 180 | } |
| 181 | } |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | json VpdTool::interfaceDecider(json& itemEEPROM) |
| 185 | { |
| 186 | if (itemEEPROM.find("inventoryPath") == itemEEPROM.end()) |
| 187 | { |
| 188 | throw runtime_error("Inventory Path not found"); |
| 189 | } |
| 190 | |
| 191 | if (itemEEPROM.find("extraInterfaces") == itemEEPROM.end()) |
| 192 | { |
| 193 | throw runtime_error("Extra Interfaces not found"); |
| 194 | } |
| 195 | |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 196 | json output = json::object({}); |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 197 | json subOutput = json::object({}); |
Alpana Kumari | b6965f1 | 2020-06-01 00:32:21 -0500 | [diff] [blame] | 198 | fruType = "FRU"; |
| 199 | |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 200 | json j; |
| 201 | objFound = true; |
| 202 | string invPath = itemEEPROM.at("inventoryPath"); |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 203 | |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 204 | j = getVINIProperties(invPath); |
| 205 | |
| 206 | if (objFound) |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 207 | { |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 208 | subOutput.insert(j.begin(), j.end()); |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 209 | json js; |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 210 | if (itemEEPROM.find("type") != itemEEPROM.end()) |
| 211 | { |
| 212 | fruType = itemEEPROM.at("type"); |
| 213 | } |
| 214 | js.emplace("TYPE", fruType); |
| 215 | |
| 216 | if (invPath.find("powersupply") != string::npos) |
| 217 | { |
| 218 | js.emplace("type", POWER_SUPPLY_TYPE_INTERFACE); |
| 219 | } |
| 220 | else if (invPath.find("fan") != string::npos) |
| 221 | { |
| 222 | js.emplace("type", FAN_INTERFACE); |
| 223 | } |
| 224 | |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 225 | for (const auto& ex : itemEEPROM["extraInterfaces"].items()) |
| 226 | { |
| 227 | if (!(ex.value().is_null())) |
| 228 | { |
Priyanga Ramasamy | dacaa47 | 2021-10-07 12:22:41 -0500 | [diff] [blame] | 229 | // TODO: Remove this if condition check once inventory json is |
| 230 | // updated with xyz location code interface. |
| 231 | if (ex.key() == "com.ibm.ipzvpd.Location") |
| 232 | { |
| 233 | getExtraInterfaceProperties( |
| 234 | invPath, |
| 235 | "xyz.openbmc_project.Inventory.Decorator.LocationCode", |
| 236 | ex.value(), js); |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | getExtraInterfaceProperties(invPath, ex.key(), ex.value(), |
| 241 | js); |
| 242 | } |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 243 | } |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 244 | if ((ex.key().find("Item") != string::npos) && |
| 245 | (ex.value().is_null())) |
| 246 | { |
| 247 | js.emplace("type", ex.key()); |
| 248 | } |
| 249 | subOutput.insert(js.begin(), js.end()); |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 250 | } |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 251 | } |
PriyangaRamasamy | 8cc5b15 | 2021-06-03 13:05:17 -0500 | [diff] [blame] | 252 | output.emplace(invPath, subOutput); |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 253 | return output; |
| 254 | } |
| 255 | |
| 256 | json VpdTool::parseInvJson(const json& jsObject, char flag, string fruPath) |
| 257 | { |
| 258 | json output = json::object({}); |
| 259 | bool validObject = false; |
| 260 | |
| 261 | if (jsObject.find("frus") == jsObject.end()) |
| 262 | { |
| 263 | throw runtime_error("Frus missing in Inventory json"); |
| 264 | } |
| 265 | else |
| 266 | { |
| 267 | for (const auto& itemFRUS : jsObject["frus"].items()) |
| 268 | { |
| 269 | for (auto itemEEPROM : itemFRUS.value()) |
| 270 | { |
| 271 | try |
| 272 | { |
| 273 | if (flag == 'O') |
| 274 | { |
| 275 | if (itemEEPROM.find("inventoryPath") == |
| 276 | itemEEPROM.end()) |
| 277 | { |
| 278 | throw runtime_error("Inventory Path not found"); |
| 279 | } |
| 280 | |
| 281 | else if (itemEEPROM.at("inventoryPath") == fruPath) |
| 282 | { |
| 283 | validObject = true; |
| 284 | json j = interfaceDecider(itemEEPROM); |
| 285 | output.insert(j.begin(), j.end()); |
| 286 | return output; |
| 287 | } |
| 288 | } |
| 289 | else |
| 290 | { |
| 291 | json j = interfaceDecider(itemEEPROM); |
| 292 | output.insert(j.begin(), j.end()); |
| 293 | } |
| 294 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 295 | catch (const exception& e) |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 296 | { |
| 297 | cerr << e.what(); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | if ((flag == 'O') && (!validObject)) |
| 302 | { |
| 303 | throw runtime_error( |
| 304 | "Invalid object path. Refer --dumpInventory/-i option."); |
| 305 | } |
| 306 | } |
| 307 | return output; |
| 308 | } |
| 309 | |
| 310 | void VpdTool::dumpInventory(const nlohmann::basic_json<>& jsObject) |
| 311 | { |
| 312 | char flag = 'I'; |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 313 | json output = json::array({}); |
| 314 | output.emplace_back(parseInvJson(jsObject, flag, "")); |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 315 | debugger(output); |
| 316 | } |
| 317 | |
| 318 | void VpdTool::dumpObject(const nlohmann::basic_json<>& jsObject) |
| 319 | { |
| 320 | char flag = 'O'; |
PriyangaRamasamy | cdf943c | 2020-03-18 02:25:30 +0530 | [diff] [blame] | 321 | json output = json::array({}); |
Santosh Puranik | d5d52bb | 2020-07-28 15:08:10 +0530 | [diff] [blame] | 322 | output.emplace_back(parseInvJson(jsObject, flag, fruPath)); |
PriyangaRamasamy | 1f0b1e6 | 2020-02-20 20:48:25 +0530 | [diff] [blame] | 323 | debugger(output); |
| 324 | } |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 325 | |
| 326 | void VpdTool::readKeyword() |
| 327 | { |
| 328 | string interface = "com.ibm.ipzvpd."; |
| 329 | variant<Binary> response; |
| 330 | |
| 331 | try |
| 332 | { |
| 333 | json output = json::object({}); |
| 334 | json kwVal = json::object({}); |
| 335 | makeDBusCall(INVENTORY_PATH + fruPath, interface + recordName, keyword) |
| 336 | .read(response); |
| 337 | |
PriyangaRamasamy | 887a42a | 2020-09-03 00:33:57 +0530 | [diff] [blame] | 338 | string printableVal{}; |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 339 | if (auto vec = get_if<Binary>(&response)) |
| 340 | { |
PriyangaRamasamy | 887a42a | 2020-09-03 00:33:57 +0530 | [diff] [blame] | 341 | printableVal = getPrintableValue(*vec); |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 342 | } |
PriyangaRamasamy | 887a42a | 2020-09-03 00:33:57 +0530 | [diff] [blame] | 343 | kwVal.emplace(keyword, printableVal); |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 344 | |
| 345 | output.emplace(fruPath, kwVal); |
| 346 | |
| 347 | debugger(output); |
| 348 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 349 | catch (const json::exception& e) |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 350 | { |
| 351 | json output = json::object({}); |
| 352 | json kwVal = json::object({}); |
PriyangaRamasamy | 02d4d4e | 2020-02-24 14:54:45 +0530 | [diff] [blame] | 353 | } |
| 354 | } |
PriyangaRamasamy | d09d2ec | 2020-03-12 14:11:50 +0530 | [diff] [blame] | 355 | |
| 356 | int VpdTool::updateKeyword() |
| 357 | { |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 358 | Binary val = toBinary(value); |
PriyangaRamasamy | d09d2ec | 2020-03-12 14:11:50 +0530 | [diff] [blame] | 359 | auto bus = sdbusplus::bus::new_default(); |
| 360 | auto properties = |
| 361 | bus.new_method_call(BUSNAME, OBJPATH, IFACE, "WriteKeyword"); |
| 362 | properties.append(static_cast<sdbusplus::message::object_path>(fruPath)); |
| 363 | properties.append(recordName); |
| 364 | properties.append(keyword); |
| 365 | properties.append(val); |
| 366 | auto result = bus.call(properties); |
| 367 | |
| 368 | if (result.is_method_error()) |
| 369 | { |
| 370 | throw runtime_error("Get api failed"); |
| 371 | } |
| 372 | return 0; |
| 373 | } |
PriyangaRamasamy | 0407b17 | 2020-03-31 13:57:18 +0530 | [diff] [blame] | 374 | |
| 375 | void VpdTool::forceReset(const nlohmann::basic_json<>& jsObject) |
| 376 | { |
| 377 | for (const auto& itemFRUS : jsObject["frus"].items()) |
| 378 | { |
| 379 | for (const auto& itemEEPROM : itemFRUS.value().items()) |
| 380 | { |
| 381 | string fru = itemEEPROM.value().at("inventoryPath"); |
| 382 | |
| 383 | fs::path fruCachePath = INVENTORY_MANAGER_CACHE; |
| 384 | fruCachePath += INVENTORY_PATH; |
| 385 | fruCachePath += fru; |
| 386 | |
| 387 | try |
| 388 | { |
| 389 | for (const auto& it : fs::directory_iterator(fruCachePath)) |
| 390 | { |
| 391 | if (fs::is_regular_file(it.status())) |
| 392 | { |
| 393 | fs::remove(it); |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | catch (const fs::filesystem_error& e) |
| 398 | { |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
PriyangaRamasamy | 6ee637a | 2021-02-12 04:49:02 -0600 | [diff] [blame] | 403 | cout.flush(); |
PriyangaRamasamy | 0407b17 | 2020-03-31 13:57:18 +0530 | [diff] [blame] | 404 | string udevRemove = "udevadm trigger -c remove -s \"*nvmem*\" -v"; |
PriyangaRamasamy | 6ee637a | 2021-02-12 04:49:02 -0600 | [diff] [blame] | 405 | int returnCode = system(udevRemove.c_str()); |
| 406 | printReturnCode(returnCode); |
PriyangaRamasamy | 0407b17 | 2020-03-31 13:57:18 +0530 | [diff] [blame] | 407 | |
| 408 | string invManagerRestart = |
| 409 | "systemctl restart xyz.openbmc_project.Inventory.Manager.service"; |
PriyangaRamasamy | 6ee637a | 2021-02-12 04:49:02 -0600 | [diff] [blame] | 410 | returnCode = system(invManagerRestart.c_str()); |
| 411 | printReturnCode(returnCode); |
PriyangaRamasamy | 0407b17 | 2020-03-31 13:57:18 +0530 | [diff] [blame] | 412 | |
| 413 | string sysVpdStop = "systemctl stop system-vpd.service"; |
PriyangaRamasamy | 6ee637a | 2021-02-12 04:49:02 -0600 | [diff] [blame] | 414 | returnCode = system(sysVpdStop.c_str()); |
| 415 | printReturnCode(returnCode); |
PriyangaRamasamy | 0407b17 | 2020-03-31 13:57:18 +0530 | [diff] [blame] | 416 | |
| 417 | string udevAdd = "udevadm trigger -c add -s \"*nvmem*\" -v"; |
PriyangaRamasamy | 6ee637a | 2021-02-12 04:49:02 -0600 | [diff] [blame] | 418 | returnCode = system(udevAdd.c_str()); |
| 419 | printReturnCode(returnCode); |
PriyangaRamasamy | 0407b17 | 2020-03-31 13:57:18 +0530 | [diff] [blame] | 420 | } |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 421 | |
| 422 | int VpdTool::updateHardware() |
| 423 | { |
| 424 | int rc = 0; |
| 425 | bool updCache = true; |
| 426 | const Binary& val = static_cast<const Binary&>(toBinary(value)); |
| 427 | ifstream inventoryJson(INVENTORY_JSON_SYM_LINK); |
| 428 | try |
| 429 | { |
| 430 | auto json = nlohmann::json::parse(inventoryJson); |
| 431 | EditorImpl edit(fruPath, json, recordName, keyword); |
| 432 | if (!((isPathInJson(fruPath)) && |
| 433 | (isRecKwInDbusJson(recordName, keyword)))) |
| 434 | { |
| 435 | updCache = false; |
| 436 | } |
| 437 | edit.updateKeyword(val, updCache); |
| 438 | } |
Patrick Williams | 8e15b93 | 2021-10-06 13:04:22 -0500 | [diff] [blame] | 439 | catch (const json::parse_error& ex) |
PriyangaRamasamy | c0a534f | 2020-08-24 21:29:18 +0530 | [diff] [blame] | 440 | { |
| 441 | throw(VpdJsonException("Json Parsing failed", INVENTORY_JSON_SYM_LINK)); |
| 442 | } |
| 443 | return rc; |
| 444 | } |