1 extern "C" 2 { 3 #include <libpdbg.h> 4 } 5 6 #include "create_pel.hpp" 7 #include "dump_utils.hpp" 8 #include "extensions/phal/common_utils.hpp" 9 #include "phal_error.hpp" 10 11 #include <attributes_info.H> 12 #include <fmt/format.h> 13 #include <libekb.H> 14 #include <libphal.H> 15 16 #include <nlohmann/json.hpp> 17 #include <phosphor-logging/elog.hpp> 18 19 #include <algorithm> 20 #include <cstdlib> 21 #include <cstring> 22 #include <iomanip> 23 #include <list> 24 #include <map> 25 #include <sstream> 26 #include <string> 27 28 namespace openpower 29 { 30 namespace phal 31 { 32 using namespace phosphor::logging; 33 using namespace openpower::phal::exception; 34 35 /** 36 * Used to pass buffer to pdbg callback api to get required target 37 * data (attributes) based on given data (attribute). 38 */ 39 struct TargetInfo 40 { 41 ATTR_PHYS_BIN_PATH_Type physBinPath; 42 ATTR_LOCATION_CODE_Type locationCode; 43 ATTR_PHYS_DEV_PATH_Type physDevPath; 44 ATTR_MRU_ID_Type mruId; 45 46 bool deconfigure; 47 48 TargetInfo() 49 { 50 memset(&physBinPath, '\0', sizeof(physBinPath)); 51 memset(&locationCode, '\0', sizeof(locationCode)); 52 memset(&physDevPath, '\0', sizeof(physDevPath)); 53 mruId = 0; 54 deconfigure = false; 55 } 56 }; 57 58 /** 59 * Used to return in callback function which are used to get 60 * physical path value and it binary format value. 61 * 62 * The value for constexpr defined based on pdbg_target_traverse function usage. 63 */ 64 constexpr int continueTgtTraversal = 0; 65 constexpr int requireAttrFound = 1; 66 constexpr int requireAttrNotFound = 2; 67 68 /** 69 * @brief Used to get target location code from phal device tree 70 * 71 * @param[in] target current device tree target 72 * @param[out] appPrivData used for accessing|storing from|to application 73 * 74 * @return 0 to continue traverse, non-zero to stop traverse 75 */ 76 int pdbgCallbackToGetTgtReqAttrsVal(struct pdbg_target* target, 77 void* appPrivData) 78 { 79 using namespace openpower::phal::pdbg; 80 81 TargetInfo* targetInfo = static_cast<TargetInfo*>(appPrivData); 82 83 ATTR_PHYS_BIN_PATH_Type physBinPath; 84 /** 85 * TODO: Issue: phal/pdata#16 86 * Should not use direct pdbg api to read attribute. Need to use DT_GET_PROP 87 * macro for bmc app's and this will call libdt-api api but, it will print 88 * "pdbg_target_get_attribute failed" trace if attribute is not found and 89 * this callback will call recursively by using pdbg_target_traverse() until 90 * find expected attribute based on return code from this callback. Because, 91 * need to do target iteration to get actual attribute (ATTR_PHYS_BIN_PATH) 92 * value when device tree target info doesn't know to read attribute from 93 * device tree. So, Due to this error trace user will get confusion while 94 * looking traces. Hence using pdbg api to avoid trace until libdt-api 95 * provides log level setup. 96 */ 97 if (!pdbg_target_get_attribute( 98 target, "ATTR_PHYS_BIN_PATH", 99 std::stoi(dtAttr::fapi2::ATTR_PHYS_BIN_PATH_Spec), 100 dtAttr::fapi2::ATTR_PHYS_BIN_PATH_ElementCount, physBinPath)) 101 { 102 return continueTgtTraversal; 103 } 104 105 if (std::memcmp(physBinPath, targetInfo->physBinPath, 106 sizeof(physBinPath)) != 0) 107 { 108 return continueTgtTraversal; 109 } 110 111 // Found Target, now collect the required attributes associated to the 112 // target. Incase of any attribute read failure, initialize the data with 113 // default value. 114 try 115 { 116 // Get location code information 117 openpower::phal::pdbg::getLocationCode(target, 118 targetInfo->locationCode); 119 } 120 catch (const std::exception& e) 121 { 122 log<level::ERR>(fmt::format("getLocationCode({}): Exception({})", 123 pdbg_target_path(target), e.what()) 124 .c_str()); 125 } 126 127 if (DT_GET_PROP(ATTR_PHYS_DEV_PATH, target, targetInfo->physDevPath)) 128 { 129 log<level::ERR>( 130 fmt::format("Could not read({}) PHYS_DEV_PATH attribute", 131 pdbg_target_path(target)) 132 .c_str()); 133 } 134 135 if (DT_GET_PROP(ATTR_MRU_ID, target, targetInfo->mruId)) 136 { 137 log<level::ERR>(fmt::format("Could not read({}) ATTR_MRU_ID attribute", 138 pdbg_target_path(target)) 139 .c_str()); 140 } 141 142 return requireAttrFound; 143 } 144 145 /** 146 * @brief Used to get target info (attributes data) 147 * 148 * To get target required attributes value using another attribute value 149 * ("PHYS_BIN_PATH" which is present in same target attributes list) by using 150 * "ipdbg_target_traverse" api because, here we have attribute value only and 151 * doesn't have respective device tree target info to get required attributes 152 * values from it attributes list. 153 * 154 * @param[in] physBinPath to pass PHYS_BIN_PATH value 155 * @param[out] targetInfo to pas buufer to fill with required attributes 156 * 157 * @return true on success otherwise false 158 */ 159 bool getTgtReqAttrsVal(const std::vector<uint8_t>& physBinPath, 160 TargetInfo& targetInfo) 161 { 162 std::memcpy(&targetInfo.physBinPath, physBinPath.data(), 163 sizeof(targetInfo.physBinPath)); 164 165 int ret = pdbg_target_traverse(NULL, pdbgCallbackToGetTgtReqAttrsVal, 166 &targetInfo); 167 if (ret == 0) 168 { 169 log<level::ERR>(fmt::format("Given ATTR_PHYS_BIN_PATH value({}) " 170 "not found in phal device tree", 171 targetInfo.physBinPath) 172 .c_str()); 173 return false; 174 } 175 else if (ret == requireAttrNotFound) 176 { 177 return false; 178 } 179 180 return true; 181 } 182 } // namespace phal 183 184 namespace pel 185 { 186 using namespace phosphor::logging; 187 188 namespace detail 189 { 190 using json = nlohmann::json; 191 192 // keys need to be unique so using counter value to generate unique key 193 static int counter = 0; 194 195 // list of debug traces 196 static std::vector<std::pair<std::string, std::string>> traceLog; 197 198 /** 199 * @brief Process platform realted boot failure 200 * 201 * @param[in] errInfo - error details 202 */ 203 static void processPlatBootError(const ipl_error_info& errInfo); 204 205 void processLogTraceCallback(void*, const char* fmt, va_list ap) 206 { 207 va_list vap; 208 va_copy(vap, ap); 209 std::vector<char> logData(1 + std::vsnprintf(nullptr, 0, fmt, ap)); 210 std::vsnprintf(logData.data(), logData.size(), fmt, vap); 211 va_end(vap); 212 std::string logstr(logData.begin(), logData.end()); 213 214 log<level::INFO>(logstr.c_str()); 215 216 char timeBuf[80]; 217 time_t t = time(0); 218 tm myTm{}; 219 gmtime_r(&t, &myTm); 220 strftime(timeBuf, 80, "%Y-%m-%d %H:%M:%S", &myTm); 221 222 // key values need to be unique for PEL 223 // TODO #openbmc/dev/issues/1563 224 // If written to Json no need to worry about unique KEY 225 std::stringstream str; 226 str << std::setfill('0'); 227 str << "LOG" << std::setw(3) << counter; 228 str << " " << timeBuf; 229 traceLog.emplace_back(std::make_pair(str.str(), std::move(logstr))); 230 counter++; 231 } 232 233 /** 234 * @brief GET PEL priority from pHAL priority 235 * 236 * The pHAL callout priority is in different format than PEL format 237 * so, this api is used to return current phal supported priority into 238 * PEL expected format. 239 * 240 * @param[in] phalPriority used to pass phal priority format string 241 * 242 * @return pel priority format string else empty if failure 243 * 244 * @note For "NONE" returning "L" (LOW) 245 */ 246 static std::string getPelPriority(const std::string& phalPriority) 247 { 248 const std::map<std::string, std::string> priorityMap = { 249 {"HIGH", "H"}, {"MEDIUM", "M"}, {"LOW", "L"}, {"NONE", "L"}}; 250 251 auto it = priorityMap.find(phalPriority); 252 if (it == priorityMap.end()) 253 { 254 log<level::ERR>(fmt::format("Unsupported phal priority({}) is given " 255 "to get pel priority format", 256 phalPriority) 257 .c_str()); 258 return "H"; 259 } 260 261 return it->second; 262 } 263 264 void processIplErrorCallback(const ipl_error_info& errInfo) 265 { 266 log<level::INFO>( 267 fmt::format("processIplErrorCallback: Error type({})", errInfo.type) 268 .c_str()); 269 270 switch (errInfo.type) 271 { 272 case IPL_ERR_OK: 273 // reset trace log and exit 274 reset(); 275 break; 276 case IPL_ERR_SBE_BOOT: 277 case IPL_ERR_SBE_CHIPOP: 278 // handle SBE related failures. 279 processSbeBootError(); 280 break; 281 case IPL_ERR_HWP: 282 // Handle hwp failure 283 processBootError(false); 284 break; 285 case IPL_ERR_PLAT: 286 processPlatBootError(errInfo); 287 break; 288 default: 289 createPEL("org.open_power.PHAL.Error.Boot"); 290 // reset trace log and exit 291 reset(); 292 break; 293 } 294 } 295 296 /** 297 * @brief addPlanarCallout 298 * 299 * This function will add a json for planar callout in the input json list. 300 * The caller can pass this json list into createErrorPEL to apply the callout. 301 * 302 * @param[in,out] jsonCalloutDataList - json list where callout json will be 303 * emplaced 304 * @param[in] priority - string indicating priority. 305 */ 306 static void addPlanarCallout(json& jsonCalloutDataList, 307 const std::string& priority) 308 { 309 json jsonCalloutData; 310 311 // Inventory path for planar 312 jsonCalloutData["InventoryPath"] = 313 "/xyz/openbmc_project/inventory/system/chassis/motherboard"; 314 jsonCalloutData["Deconfigured"] = false; 315 jsonCalloutData["Guarded"] = false; 316 jsonCalloutData["Priority"] = priority; 317 318 jsonCalloutDataList.emplace_back(jsonCalloutData); 319 } 320 321 void processBootErrorHelper(FFDC* ffdc, const std::string& ffdc_prefix) 322 { 323 log<level::INFO>("processBootErrorHelper "); 324 try 325 { 326 log<level::INFO>( 327 fmt::format("PHAL FFDC: Return Message[{}]", ffdc->message) 328 .c_str()); 329 330 // To store callouts details in json format as per pel expectation. 331 json jsonCalloutDataList; 332 jsonCalloutDataList = json::array(); 333 334 // To store phal trace and other additional data about ffdc. 335 FFDCData pelAdditionalData; 336 337 if (ffdc->ffdc_type == FFDC_TYPE_HWP) 338 { 339 std::string keyWithPrefix(ffdc_prefix + "RC"); 340 // Adding hardware procedures return code details 341 pelAdditionalData.emplace_back(keyWithPrefix, 342 ffdc->hwp_errorinfo.rc); 343 keyWithPrefix = ffdc_prefix + "RC_DESC"; 344 pelAdditionalData.emplace_back(keyWithPrefix, 345 ffdc->hwp_errorinfo.rc_desc); 346 347 // Adding hardware procedures required ffdc data for debug 348 for_each(ffdc->hwp_errorinfo.ffdcs_data.begin(), 349 ffdc->hwp_errorinfo.ffdcs_data.end(), 350 [&pelAdditionalData, &ffdc_prefix]( 351 std::pair<std::string, std::string>& ele) -> void { 352 std::string keyWithPrefix(ffdc_prefix + "FFDC_"); 353 keyWithPrefix.append(ele.first); 354 355 pelAdditionalData.emplace_back(keyWithPrefix, 356 ele.second); 357 }); 358 359 // Adding hardware callout details 360 int calloutCount = 0; 361 for_each( 362 ffdc->hwp_errorinfo.hwcallouts.begin(), 363 ffdc->hwp_errorinfo.hwcallouts.end(), 364 [&pelAdditionalData, &calloutCount, &jsonCalloutDataList, 365 &ffdc_prefix](const HWCallout& hwCallout) -> void { 366 calloutCount++; 367 std::stringstream keyPrefix; 368 keyPrefix << ffdc_prefix << "HW_CO_" << std::setfill('0') 369 << std::setw(2) << calloutCount << "_"; 370 371 pelAdditionalData.emplace_back( 372 std::string(keyPrefix.str()).append("HW_ID"), 373 hwCallout.hwid); 374 375 pelAdditionalData.emplace_back( 376 std::string(keyPrefix.str()).append("PRIORITY"), 377 hwCallout.callout_priority); 378 379 // Log target details only if entity path is 380 // available. For example target entity path will not 381 // be available for non-hwp clock failure. 382 if (!hwCallout.target_entity_path.empty()) 383 { 384 phal::TargetInfo targetInfo; 385 phal::getTgtReqAttrsVal(hwCallout.target_entity_path, 386 targetInfo); 387 388 std::string locationCode = 389 std::string(targetInfo.locationCode); 390 pelAdditionalData.emplace_back( 391 std::string(keyPrefix.str()).append("LOC_CODE"), 392 locationCode); 393 394 std::string physPath = 395 std::string(targetInfo.physDevPath); 396 pelAdditionalData.emplace_back( 397 std::string(keyPrefix.str()).append("PHYS_PATH"), 398 physPath); 399 } 400 401 pelAdditionalData.emplace_back( 402 std::string(keyPrefix.str()).append("CLK_POS"), 403 std::to_string(hwCallout.clkPos)); 404 405 pelAdditionalData.emplace_back( 406 std::string(keyPrefix.str()).append("CALLOUT_PLANAR"), 407 (hwCallout.isPlanarCallout == true ? "true" : "false")); 408 409 std::string pelPriority = 410 getPelPriority(hwCallout.callout_priority); 411 412 if (hwCallout.isPlanarCallout) 413 { 414 addPlanarCallout(jsonCalloutDataList, pelPriority); 415 } 416 }); 417 418 // Adding CDG (callout, deconfigure and guard) targets details 419 calloutCount = 0; 420 for_each( 421 ffdc->hwp_errorinfo.cdg_targets.begin(), 422 ffdc->hwp_errorinfo.cdg_targets.end(), 423 [&pelAdditionalData, &calloutCount, &jsonCalloutDataList, 424 &ffdc_prefix](const CDG_Target& cdg_tgt) -> void { 425 calloutCount++; 426 std::stringstream keyPrefix; 427 keyPrefix << ffdc_prefix << "CDG_TGT_" << std::setfill('0') 428 << std::setw(2) << calloutCount << "_"; 429 430 phal::TargetInfo targetInfo; 431 targetInfo.deconfigure = cdg_tgt.deconfigure; 432 433 phal::getTgtReqAttrsVal(cdg_tgt.target_entity_path, 434 targetInfo); 435 436 std::string locationCode = 437 std::string(targetInfo.locationCode); 438 pelAdditionalData.emplace_back( 439 std::string(keyPrefix.str()).append("LOC_CODE"), 440 locationCode); 441 std::string physPath = std::string(targetInfo.physDevPath); 442 pelAdditionalData.emplace_back( 443 std::string(keyPrefix.str()).append("PHYS_PATH"), 444 physPath); 445 446 pelAdditionalData.emplace_back( 447 std::string(keyPrefix.str()).append("CO_REQ"), 448 (cdg_tgt.callout == true ? "true" : "false")); 449 450 pelAdditionalData.emplace_back( 451 std::string(keyPrefix.str()).append("CO_PRIORITY"), 452 cdg_tgt.callout_priority); 453 454 pelAdditionalData.emplace_back( 455 std::string(keyPrefix.str()).append("DECONF_REQ"), 456 (cdg_tgt.deconfigure == true ? "true" : "false")); 457 458 pelAdditionalData.emplace_back( 459 std::string(keyPrefix.str()).append("GUARD_REQ"), 460 (cdg_tgt.guard == true ? "true" : "false")); 461 462 pelAdditionalData.emplace_back( 463 std::string(keyPrefix.str()).append("GUARD_TYPE"), 464 cdg_tgt.guard_type); 465 466 json jsonCalloutData; 467 jsonCalloutData["LocationCode"] = locationCode; 468 std::string pelPriority = 469 getPelPriority(cdg_tgt.callout_priority); 470 jsonCalloutData["Priority"] = pelPriority; 471 472 if (targetInfo.mruId != 0) 473 { 474 jsonCalloutData["MRUs"] = json::array({ 475 {{"ID", targetInfo.mruId}, 476 {"Priority", pelPriority}}, 477 }); 478 } 479 jsonCalloutData["Deconfigured"] = cdg_tgt.deconfigure; 480 jsonCalloutData["Guarded"] = cdg_tgt.guard; 481 jsonCalloutData["GuardType"] = cdg_tgt.guard_type; 482 jsonCalloutData["EntityPath"] = cdg_tgt.target_entity_path; 483 484 jsonCalloutDataList.emplace_back(jsonCalloutData); 485 }); 486 // Adding procedure callout 487 calloutCount = 0; 488 for_each( 489 ffdc->hwp_errorinfo.procedures_callout.begin(), 490 ffdc->hwp_errorinfo.procedures_callout.end(), 491 [&pelAdditionalData, &calloutCount, &jsonCalloutDataList, 492 &ffdc_prefix](const ProcedureCallout& procCallout) -> void { 493 calloutCount++; 494 std::stringstream keyPrefix; 495 keyPrefix << ffdc_prefix << "PROC_CO_" << std::setfill('0') 496 << std::setw(2) << calloutCount << "_"; 497 498 pelAdditionalData.emplace_back( 499 std::string(keyPrefix.str()).append("PRIORITY"), 500 procCallout.callout_priority); 501 502 pelAdditionalData.emplace_back( 503 std::string(keyPrefix.str()).append("MAINT_PROCEDURE"), 504 procCallout.proc_callout); 505 506 json jsonCalloutData; 507 jsonCalloutData["Procedure"] = procCallout.proc_callout; 508 std::string pelPriority = 509 getPelPriority(procCallout.callout_priority); 510 jsonCalloutData["Priority"] = pelPriority; 511 jsonCalloutDataList.emplace_back(jsonCalloutData); 512 }); 513 } 514 else if ((ffdc->ffdc_type != FFDC_TYPE_NONE) && 515 (ffdc->ffdc_type != FFDC_TYPE_UNSUPPORTED)) 516 { 517 log<level::ERR>( 518 fmt::format("Unsupported phal FFDC type to create PEL. " 519 "MSG: {}", 520 ffdc->message) 521 .c_str()); 522 } 523 524 // Adding collected phal logs into PEL additional data 525 for_each(traceLog.begin(), traceLog.end(), 526 [&pelAdditionalData]( 527 std::pair<std::string, std::string>& ele) -> void { 528 pelAdditionalData.emplace_back(ele.first, ele.second); 529 }); 530 531 // TODO: #ibm-openbmc/dev/issues/2595 : Once enabled this support, 532 // callout details is not required to sort in H,M and L orders which 533 // are expected by pel because, pel will take care for sorting callouts 534 // based on priority so, now adding support to send callout in order 535 // i.e High -> Medium -> Low. 536 std::sort( 537 jsonCalloutDataList.begin(), jsonCalloutDataList.end(), 538 [](const json& aEle, const json& bEle) -> bool { 539 // Considering b element having higher priority than a element 540 // or Both element will be same priorty (to keep same order 541 // which are given by phal when two callouts are having same 542 // priority) 543 if (((aEle["Priority"] == "M") && (bEle["Priority"] == "H")) || 544 ((aEle["Priority"] == "L") && 545 ((bEle["Priority"] == "H") || 546 (bEle["Priority"] == "M"))) || 547 (aEle["Priority"] == bEle["Priority"])) 548 { 549 return false; 550 } 551 552 // Considering a element having higher priority than b element 553 return true; 554 }); 555 openpower::pel::createErrorPEL("org.open_power.PHAL.Error.Boot", 556 jsonCalloutDataList, pelAdditionalData); 557 } 558 catch (const std::exception& ex) 559 { 560 reset(); 561 throw ex; 562 } 563 reset(); 564 } 565 566 void processPlatBootError(const ipl_error_info& errInfo) 567 { 568 log<level::INFO>("processPlatBootError "); 569 570 // Collecting ffdc details from phal 571 FFDC* ffdc = reinterpret_cast<FFDC*>(errInfo.private_data); 572 try 573 { 574 processBootErrorHelper(ffdc, "PLAT_"); 575 } 576 catch (const std::exception& ex) 577 { 578 log<level::ERR>( 579 fmt::format("processPlatBootError: exception({})", ex.what()) 580 .c_str()); 581 throw ex; 582 } 583 } 584 585 void processBootError(bool status) 586 { 587 log<level::INFO>( 588 fmt::format("processBootError: status({})", status).c_str()); 589 590 try 591 { 592 // return If no failure during hwp execution 593 if (status) 594 return; 595 596 // Collecting ffdc details from phal 597 FFDC ffdc; 598 libekb_get_ffdc(ffdc); 599 600 processBootErrorHelper(&ffdc, "HWP_"); 601 } 602 catch (const std::exception& ex) 603 { 604 log<level::ERR>( 605 fmt::format("processBootError: exception({})", ex.what()).c_str()); 606 throw ex; 607 } 608 } 609 610 void processSbeBootError() 611 { 612 log<level::INFO>("processSbeBootError : Entered "); 613 614 using namespace openpower::phal::sbe; 615 616 // To store phal trace and other additional data about ffdc. 617 FFDCData pelAdditionalData; 618 619 // Adding collected phal logs into PEL additional data 620 for_each( 621 traceLog.begin(), traceLog.end(), 622 [&pelAdditionalData](std::pair<std::string, std::string>& ele) -> void { 623 pelAdditionalData.emplace_back(ele.first, ele.second); 624 }); 625 626 // reset the trace log and counter 627 reset(); 628 629 // get primary processor to collect FFDC/Dump information. 630 struct pdbg_target* procTarget; 631 pdbg_for_each_class_target("proc", procTarget) 632 { 633 if (openpower::phal::isPrimaryProc(procTarget)) 634 break; 635 procTarget = nullptr; 636 } 637 // check valid primary processor is available 638 if (procTarget == nullptr) 639 { 640 log<level::ERR>("processSbeBootError: fail to get primary processor"); 641 // Add BMC code callout and create PEL 642 json jsonCalloutDataList; 643 jsonCalloutDataList = json::array(); 644 json jsonCalloutData; 645 jsonCalloutData["Procedure"] = "BMC0001"; 646 jsonCalloutData["Priority"] = "H"; 647 jsonCalloutDataList.emplace_back(jsonCalloutData); 648 openpower::pel::createErrorPEL( 649 "org.open_power.Processor.Error.SbeBootFailure", 650 jsonCalloutDataList); 651 return; 652 } 653 // SBE error object. 654 sbeError_t sbeError; 655 bool dumpIsRequired = false; 656 657 try 658 { 659 // Capture FFDC information on primary processor 660 sbeError = captureFFDC(procTarget); 661 } 662 catch (const phalError_t& phalError) 663 { 664 // Fail to collect FFDC information , trigger Dump 665 log<level::ERR>( 666 fmt::format("captureFFDC: Exception({})", phalError.what()) 667 .c_str()); 668 dumpIsRequired = true; 669 } 670 671 std::string event; 672 673 if ((sbeError.errType() == SBE_FFDC_NO_DATA) || 674 (sbeError.errType() == SBE_CMD_TIMEOUT) || (dumpIsRequired)) 675 { 676 event = "org.open_power.Processor.Error.SbeBootTimeout"; 677 dumpIsRequired = true; 678 } 679 else 680 { 681 event = "org.open_power.Processor.Error.SbeBootFailure"; 682 } 683 // SRC6 : [0:15] chip position 684 uint32_t index = pdbg_target_index(procTarget); 685 pelAdditionalData.emplace_back("SRC6", std::to_string(index << 16)); 686 // Create SBE Error with FFDC data. 687 auto logId = createSbeErrorPEL(event, sbeError, pelAdditionalData); 688 689 if (dumpIsRequired) 690 { 691 using namespace openpower::phal::dump; 692 DumpParameters dumpParameters = {logId, index, SBE_DUMP_TIMEOUT, 693 DumpType::SBE}; 694 try 695 { 696 requestDump(dumpParameters); 697 } 698 catch (const std::runtime_error& e) 699 { 700 // Allowing call back to handle the error gracefully. 701 log<level::ERR>("Dump collection failed"); 702 // TODO revist error handling. 703 } 704 } 705 } 706 707 void reset() 708 { 709 // reset the trace log and counter 710 traceLog.clear(); 711 counter = 0; 712 } 713 714 void pDBGLogTraceCallbackHelper(int, const char* fmt, va_list ap) 715 { 716 processLogTraceCallback(NULL, fmt, ap); 717 } 718 } // namespace detail 719 720 static inline uint8_t getLogLevelFromEnv(const char* env, const uint8_t dValue) 721 { 722 auto logLevel = dValue; 723 try 724 { 725 if (const char* env_p = std::getenv(env)) 726 { 727 logLevel = std::stoi(env_p); 728 } 729 } 730 catch (const std::exception& e) 731 { 732 log<level::ERR>(("Conversion Failure"), entry("ENVIRONMENT=%s", env), 733 entry("EXCEPTION=%s", e.what())); 734 } 735 return logLevel; 736 } 737 738 void addBootErrorCallbacks() 739 { 740 // Get individual phal repos log level from environment variable 741 // and update the log level. 742 pdbg_set_loglevel(getLogLevelFromEnv("PDBG_LOG", PDBG_INFO)); 743 libekb_set_loglevel(getLogLevelFromEnv("LIBEKB_LOG", LIBEKB_LOG_IMP)); 744 ipl_set_loglevel(getLogLevelFromEnv("IPL_LOG", IPL_INFO)); 745 746 // add callback for debug traces 747 pdbg_set_logfunc(detail::pDBGLogTraceCallbackHelper); 748 libekb_set_logfunc(detail::processLogTraceCallback, NULL); 749 ipl_set_logfunc(detail::processLogTraceCallback, NULL); 750 751 // add callback for ipl failures 752 ipl_set_error_callback_func(detail::processIplErrorCallback); 753 } 754 755 } // namespace pel 756 } // namespace openpower 757