diff options
author | Stephen Cprek <smcprek@us.ibm.com> | 2017-03-20 13:07:42 -0500 |
---|---|---|
committer | William G. Hoffa <wghoffa@us.ibm.com> | 2017-03-23 10:05:07 -0400 |
commit | d87aceae2d5e5cb66201af5f897b06fa1471d90e (patch) | |
tree | 8ca50bf550c1b460d9dc686aed5839901ba5d3e8 /src/usr/pnor/pnor_utils.C | |
parent | 98de8e60e8395033bf1deed9ede0929ecb796841 (diff) | |
download | talos-hostboot-d87aceae2d5e5cb66201af5f897b06fa1471d90e.tar.gz talos-hostboot-d87aceae2d5e5cb66201af5f897b06fa1471d90e.zip |
Add PNOR SectionIdToString to replace direct access to cv_EYECATCHER
This catches if the const array size does not match the number of
pnor sections and out of range index errors
Also it adds genErrlParsing for bootloader files
Change-Id: I0a90816a7620022dec16bc7358a68ffbdade0083
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/38159
Reviewed-by: Martin Gloff <mgloff@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Reviewed-by: Michael Baiocchi <mbaiocch@us.ibm.com>
Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com>
Reviewed-by: William G. Hoffa <wghoffa@us.ibm.com>
Diffstat (limited to 'src/usr/pnor/pnor_utils.C')
-rw-r--r-- | src/usr/pnor/pnor_utils.C | 121 |
1 files changed, 83 insertions, 38 deletions
diff --git a/src/usr/pnor/pnor_utils.C b/src/usr/pnor/pnor_utils.C index 5af2993cb..c7e77cbb7 100644 --- a/src/usr/pnor/pnor_utils.C +++ b/src/usr/pnor/pnor_utils.C @@ -34,13 +34,16 @@ #include "pnor_utils.H" #include <pnor/pnor_const.H> -#if !defined(__BOOT_LOADER_H) +#ifndef BOOTLOADER #include <errl/errlmanager.H> +#include <assert.h> extern trace_desc_t* g_trac_pnor; #define PNOR_UTIL_TRACE(arg0, args...) TRACFCOMP(g_trac_pnor, args) #define PNOR_UTIL_TRACE_W_BRK(arg0, args...) TRACFCOMP(g_trac_pnor, args) #else #include <bootloader/bootloader_trace.H> +#include <bootloader/bootloader.H> +#include <bootloader/hbblreasoncodes.H> #define PNOR_UTIL_TRACE(arg0, args...) BOOTLOADER_TRACE(arg0) #define PNOR_UTIL_TRACE_W_BRK(arg0, args...) BOOTLOADER_TRACE_W_BRK(arg0) #endif @@ -49,42 +52,7 @@ extern trace_desc_t* g_trac_pnor; #include "common/ffs_hb.H" #include <util/align.H> -/** - * Eyecatcher strings for PNOR TOC entries - */ -const char* cv_EYECATCHER[] = { - "part", /**< PNOR::TOC : Table of Contents */ - "HBI", /**< PNOR::HB_EXT_CODE : Hostboot Extended Image */ - "GLOBAL", /**< PNOR::GLOBAL_DATA : Global Data */ - "HBB", /**< PNOR::HB_BASE_CODE : Hostboot Base Image */ - "SBEC", /**< PNOR::CENTAUR_SBE : Centaur Self-Boot Engine image */ - "SBE", /**< PNOR::SBE_IPL : Self-Boot Enginer IPL image */ - "HCODE", /**< PNOR::HCODE : HCODE Reference image */ - "PAYLOAD", /**< PNOR::PAYLOAD : HAL/OPAL */ - "HBRT", /**< PNOR::HB_RUNTIME : Hostboot Runtime(for Sapphire)*/ - "HBD", /**< PNOR::HB_DATA : Hostboot Data */ - "GUARD", /**< PNOR::GUARD_DATA : Hostboot Data */ - "HBEL", /**< PNOR::HB_ERRLOGS : Hostboot Error log Repository */ - "DJVPD", /**< PNOR::DIMM_JEDEC_VPD : Dimm JEDEC VPD */ - "MVPD", /**< PNOR::MODULE_VPD : Module VPD */ - "CVPD", /**< PNOR::CENTAUR_VPD : Centaur VPD */ - "NVRAM", /**< PNOR::NVRAM : OPAL Storage */ - "OCC", /**< PNOR::OCC : OCC LID */ - "FIRDATA", /**< PNOR::FIRDATA : FIRs for checkstop analysis */ - "ATTR_TMP", /**< PNOR::ATTR_TMP : Temporary Attribute Overrides */ - "ATTR_PERM", /**< PNOR::ATTR_PERM : Permanent Attribute Overrides */ - "CAPP", /**< PNOR::CAPP : CAPP LID */ - "VERSION", /**< PNOR::VERSION : PNOR Version string */ - "HBBL", /**<PNOR::HB_BOOTLOADER : Hostboot Bootloader image */ - "TEST", /**< PNOR::TEST : Test space for PNOR*/ - "TESTRO", /**< PNOR::TESTRO : ReadOnly Test space for PNOR */ - "BACKUP_PART", /**PNOR::BACKUP_PART : Backup of PART*/ - "POWERVM", /**< PNOR::POWERVM : Power VM data */ - "RINGOVD", /**< PNOR::RINGOVD : Ring overrides */ - "WOFDATA", /**< PNOR::WOFDATA : VFRT data tables for WOF */ -}; - -/** +/* * @brief calculates the checksum on data(ffs header/entry) and will return * 0 if the checksums match */ @@ -248,7 +216,7 @@ void PNOR::getSectionEnum (ffs_entry* i_entry, for(uint32_t eyeIndex=PNOR::TOC;eyeIndex<PNOR::NUM_SECTIONS; eyeIndex++) { - if(strcmp(cv_EYECATCHER[eyeIndex],i_entry->name) == 0) + if(strcmp(PNOR::SectionIdToString(eyeIndex),i_entry->name) == 0) { *o_secId = eyeIndex; break; @@ -382,3 +350,80 @@ bool PNOR::isSecureSection(const uint32_t i_section) #endif } +const char * PNOR::SectionIdToString( uint32_t i_secIdIndex ) +{ + /** + * Eyecatcher strings for PNOR TOC entries + * Use an array vs switch statement for O(1) lookup + * Not using std::array so we can check the actual size filled in vs N + * in std:array<const char*, N>. + */ + static const char* SectionIdToStringArr[] = + { + "part", /**< PNOR::TOC : Table of Contents */ + "HBI", /**< PNOR::HB_EXT_CODE : Hostboot Extended Image */ + "GLOBAL", /**< PNOR::GLOBAL_DATA : Global Data */ + "HBB", /**< PNOR::HB_BASE_CODE : Hostboot Base Image */ + "SBEC", /**< PNOR::CENTAUR_SBE : Centaur Self-Boot Engine image */ + "SBE", /**< PNOR::SBE_IPL : Self-Boot Enginer IPL image */ + "HCODE", /**< PNOR::HCODE : HCODE Reference image */ + "PAYLOAD", /**< PNOR::PAYLOAD : HAL/OPAL */ + "HBRT", /**< PNOR::HB_RUNTIME : Hostboot Runtime(for Sapphire)*/ + "HBD", /**< PNOR::HB_DATA : Hostboot Data */ + "GUARD", /**< PNOR::GUARD_DATA : Hostboot Data */ + "HBEL", /**< PNOR::HB_ERRLOGS : Hostboot Error log Repository */ + "DJVPD", /**< PNOR::DIMM_JEDEC_VPD : Dimm JEDEC VPD */ + "MVPD", /**< PNOR::MODULE_VPD : Module VPD */ + "CVPD", /**< PNOR::CENTAUR_VPD : Centaur VPD */ + "NVRAM", /**< PNOR::NVRAM : OPAL Storage */ + "OCC", /**< PNOR::OCC : OCC LID */ + "FIRDATA", /**< PNOR::FIRDATA : FIRs for checkstop analysis */ + "ATTR_TMP", /**< PNOR::ATTR_TMP : Temporary Attribute Overrides */ + "ATTR_PERM", /**< PNOR::ATTR_PERM : Permanent Attribute Overrides */ + "CAPP", /**< PNOR::CAPP : CAPP LID */ + "VERSION", /**< PNOR::VERSION : PNOR Version string */ + "HBBL", /**<PNOR::HB_BOOTLOADER : Hostboot Bootloader image */ + "TEST", /**< PNOR::TEST : Test space for PNOR*/ + "TESTRO", /**< PNOR::TESTRO : ReadOnly Test space for PNOR */ + "BACKUP_PART", /**PNOR::BACKUP_PART : Backup of PART*/ + "POWERVM", /**< PNOR::POWERVM : Power VM data */ + "RINGOVD", /**< PNOR::RINGOVD : Ring overrides */ + "WOFDATA", /**< PNOR::WOFDATA : VFRT data tables for WOF */ + "SBKT", /**< PNOR::SBKT : SecureBoot Key Transition */ + }; + + // Get actual number of entries of array. + const size_t numEntries = sizeof(SectionIdToStringArr)/sizeof(char*); + + // Assert that the number of entries equals PNOR::NUM_SECTIONS + static_assert (numEntries == (PNOR::NUM_SECTIONS), + "Mismatch between number of SectionIds and correlating strings"); + + // Bootloader does not support asserts +#ifdef BOOTLOADER + if(i_secIdIndex >= (PNOR::NUM_SECTIONS)) + { + PNOR_UTIL_TRACE(BTLDR_TRC_UTILS_PARSE_PNOR_SECID_OUT_OF_RANGE); + /*@ + * @errortype + * @moduleid Bootloader::MOD_BOOTLOADER_PNOR_SECID_TO_STR + * @reasoncode Bootloader::RC_PNOR_SECID_OUT_OF_RANGE + * @userdata1 Section ID requested + * @userdata2 Max index of Section id to string array + * @devdesc No String associated with PNOR section ID + * @custdesc A problem occurred while running processor + * boot code. + */ + bl_terminate(Bootloader::MOD_BOOTLOADER_PNOR_SECID_TO_STR, + Bootloader::RC_PNOR_SECID_OUT_OF_RANGE, + i_secIdIndex, + numEntries); + } +#else + // Assert if accessing index out of array. + assert(i_secIdIndex < (PNOR::NUM_SECTIONS), "SectionIdToString PNOR section id out of range"); +#endif + + return SectionIdToStringArr[i_secIdIndex]; +} + |