From d87aceae2d5e5cb66201af5f897b06fa1471d90e Mon Sep 17 00:00:00 2001 From: Stephen Cprek Date: Mon, 20 Mar 2017 13:07:42 -0500 Subject: 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 Tested-by: Jenkins Server Tested-by: FSP CI Jenkins Tested-by: Jenkins OP Build CI Reviewed-by: Michael Baiocchi Reviewed-by: Nicholas E. Bofferding Reviewed-by: William G. Hoffa --- src/usr/errl/parser/genErrlParsers.pl | 5 ++ src/usr/pnor/pnor_common.C | 9 +-- src/usr/pnor/pnor_utils.C | 121 +++++++++++++++++++++++----------- src/usr/pnor/pnor_utils.H | 16 ++++- src/usr/pnor/pnorrp.C | 10 +-- src/usr/pnor/runtime/rt_pnor.C | 11 +--- src/usr/pnor/test/pnorutilsTest.H | 4 +- src/usr/testcore/rtloader/loader.H | 4 +- src/usr/testcore/rtloader/makefile | 6 +- 9 files changed, 120 insertions(+), 66 deletions(-) (limited to 'src/usr') diff --git a/src/usr/errl/parser/genErrlParsers.pl b/src/usr/errl/parser/genErrlParsers.pl index c24df2f34..0316db383 100755 --- a/src/usr/errl/parser/genErrlParsers.pl +++ b/src/usr/errl/parser/genErrlParsers.pl @@ -76,6 +76,8 @@ while( $ARGV = shift ) my $compIdFile = $base."/src/include/usr/hbotcompid.H"; my $compPath = $base."/src/usr"; my $compIncPath = $base."/src/include/usr"; +my $compBlPath = $base."/src/bootloader"; +my $compBlIncPath = $base."/src/include/bootloader"; my $genFilesPath = $base."/obj/genfiles"; my $hbfwTermRcFile = $genFilesPath."/hbfw_term_rc.H"; my $srcFileName = $genFilesPath."/srcListing"; @@ -91,9 +93,12 @@ my @reasonCodeFiles; my @filesToParse; my @pluginDirsToParse; getReasonCodeFiles($compIncPath); +getReasonCodeFiles($compBlIncPath); getFilesToParse($compPath); getFilesToParse($compIncPath); getFilesToParse($genFilesPath); +getFilesToParse($compBlPath); +getFilesToParse($compBlIncPath); getPluginDirsToParse($compPath); #Add kernel/lib files for TI SRC descriptions diff --git a/src/usr/pnor/pnor_common.C b/src/usr/pnor/pnor_common.C index 93978c277..f766e3937 100644 --- a/src/usr/pnor/pnor_common.C +++ b/src/usr/pnor/pnor_common.C @@ -46,11 +46,6 @@ TRAC_INIT(&g_trac_pnor, PNOR_COMP_NAME, 4*KILOBYTE, TRACE::BUFFER_SLOW); //4K //#define TRACUCOMP(args...) TRACFCOMP(args) #define TRACUCOMP(args...) -/** - * Eyecatcher strings for PNOR TOC entries - */ -extern const char* cv_EYECATCHER[]; - /* * @brief determine the physical offset of the ffs entry @@ -319,7 +314,7 @@ errlHndl_t PNOR::parseTOC( uint8_t* i_tocBuffer,SectionData_t * o_TOC) addr -= headerSize; l_errhdl = PNOR::extendHash(addr, headerSize, - cv_EYECATCHER[l_secId]); + PNOR::SectionIdToString(l_secId)); if (l_errhdl) { break; @@ -333,7 +328,7 @@ errlHndl_t PNOR::parseTOC( uint8_t* i_tocBuffer,SectionData_t * o_TOC) tmpId ++ ) { TRACFCOMP(g_trac_pnor, "%s: size=0x%.8X flash=0x%.8X ", - cv_EYECATCHER[tmpId], o_TOC[tmpId].size, + PNOR::SectionIdToString(tmpId), o_TOC[tmpId].size, o_TOC[tmpId].flashAddr); } 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 -#if !defined(__BOOT_LOADER_H) +#ifndef BOOTLOADER #include +#include 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 +#include +#include #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 -/** - * 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", /**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. + */ + 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::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]; +} + diff --git a/src/usr/pnor/pnor_utils.H b/src/usr/pnor/pnor_utils.H index 75d85d77b..8bb4504f1 100644 --- a/src/usr/pnor/pnor_utils.H +++ b/src/usr/pnor/pnor_utils.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2011,2016 */ +/* Contributors Listed Below - COPYRIGHT 2011,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -229,6 +229,20 @@ void parseEntries (ffs_hdr* i_ffs_hdr, */ bool isSecureSection(const uint32_t i_section); +/** + * @brief Returns string representation of a PNOR SectionId. + * If id requested is out of range of known string array + * - Hostboot asserts + * - Bootloader terminates + * + * @param[in] i_secIdIndex PNOR section id which also represents the index + * into the string array. + * + * @return const char* - String associated with Section ID + * +*/ +const char * SectionIdToString( uint32_t i_secIdIndex ); + } // End namespace PNOR diff --git a/src/usr/pnor/pnorrp.C b/src/usr/pnor/pnorrp.C index b3f394e51..329e3cac9 100644 --- a/src/usr/pnor/pnorrp.C +++ b/src/usr/pnor/pnorrp.C @@ -66,10 +66,6 @@ extern trace_desc_t* g_trac_pnor; using namespace PNOR; -/** - * Eyecatcher strings for PNOR TOC entries - */ -extern const char* cv_EYECATCHER[]; /** * @brief set up _start() task entry procedure for PNOR daemon @@ -528,7 +524,7 @@ errlHndl_t PnorRP::getSectionInfo( PNOR::SectionId i_section, // copy my data into the external format o_info.id = iv_TOC[id].id; - o_info.name = cv_EYECATCHER[id]; + o_info.name = SectionIdToString(id); #ifdef CONFIG_SECUREBOOT o_info.secureProtectedPayloadSize = 0; // for non secure sections @@ -1737,7 +1733,7 @@ errlHndl_t PnorRP::setVirtAddrs(void) if (rc) { TRACFCOMP(g_trac_pnor, "E>PnorRP::readTOC: Failed to set block permissions to WRITABLE for section %s.", - cv_EYECATCHER[i]); + SectionIdToString(i)); /*@ * @errortype * @moduleid PNOR::MOD_PNORRP_READTOC @@ -1770,7 +1766,7 @@ errlHndl_t PnorRP::setVirtAddrs(void) if (rc) { TRACFCOMP(g_trac_pnor, "E>PnorRP::readTOC: Failed to set block permissions to WRITABLE/WRITE_TRACKED for section %s.", - cv_EYECATCHER[i]); + SectionIdToString(i)); /*@ * @errortype * @moduleid PNOR::MOD_PNORRP_READTOC diff --git a/src/usr/pnor/runtime/rt_pnor.C b/src/usr/pnor/runtime/rt_pnor.C index dc5adb7f7..484d47e7d 100644 --- a/src/usr/pnor/runtime/rt_pnor.C +++ b/src/usr/pnor/runtime/rt_pnor.C @@ -42,11 +42,6 @@ // Trace definition extern trace_desc_t* g_trac_pnor; -/** - * Eyecatcher strings for PNOR TOC entries - */ -extern const char* cv_EYECATCHER[]; - /** * @brief set up _start() task entry procedure for PNOR daemon */ @@ -214,7 +209,7 @@ errlHndl_t RtPnor::getSectionInfo(PNOR::SectionId i_section, } //return the data in the struct o_info.id = i_section; - o_info.name = cv_EYECATCHER[i_section]; + o_info.name = SectionIdToString(i_section); o_info.vaddr = (uint64_t)l_pWorking; o_info.flashAddr = iv_TOC[i_section].flashAddr; o_info.size = l_sizeBytes; @@ -365,7 +360,7 @@ errlHndl_t RtPnor::readFromDevice (uint64_t i_procId, do { - const char* l_partitionName = cv_EYECATCHER[i_section]; + const char* l_partitionName = SectionIdToString(i_section); void* l_dataToRead = o_data; size_t l_readSize = i_size; size_t l_readSizePlusECC = (i_size * 9)/8; @@ -581,7 +576,7 @@ errlHndl_t RtPnor::writeToDevice( uint64_t i_procId, l_offset = (i_offset * 9)/8; } - const char* l_partitionName = cv_EYECATCHER[i_section]; + const char* l_partitionName = SectionIdToString(i_section); if (g_hostInterfaces && g_hostInterfaces->pnor_write) { //make call into opal to write the data diff --git a/src/usr/pnor/test/pnorutilsTest.H b/src/usr/pnor/test/pnorutilsTest.H index c71f90e54..a2258c622 100644 --- a/src/usr/pnor/test/pnorutilsTest.H +++ b/src/usr/pnor/test/pnorutilsTest.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2014,2016 */ +/* Contributors Listed Below - COPYRIGHT 2014,2017 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -39,7 +39,7 @@ * * @brief unit tests for pnor utils */ -extern const char* cv_EYECATCHER[]; + extern trace_desc_t* g_trac_pnor; class pnorutilsTest : public CxxTest::TestSuite { diff --git a/src/usr/testcore/rtloader/loader.H b/src/usr/testcore/rtloader/loader.H index 417009992..f131d9a7e 100644 --- a/src/usr/testcore/rtloader/loader.H +++ b/src/usr/testcore/rtloader/loader.H @@ -42,10 +42,10 @@ #include #include #include +#include trace_desc_t* g_trac_hbrt = NULL; TRAC_INIT(&g_trac_hbrt, "HBRT_TEST", 2*KILOBYTE); -extern const char* cv_EYECATCHER[]; class RuntimeLoaderTest : public CxxTest::TestSuite { @@ -347,7 +347,7 @@ class RuntimeLoaderTest : public CxxTest::TestSuite for (size_t i=PNOR::FIRST_SECTION; i<=PNOR::NUM_SECTIONS; ++i) { - if (0 == strcmp(cv_EYECATCHER[i], i_partitionName)) + if (0 == strcmp(PNOR::SectionIdToString(i), i_partitionName)) { l_id = (PNOR::SectionId)i; break; diff --git a/src/usr/testcore/rtloader/makefile b/src/usr/testcore/rtloader/makefile index c75e71933..d253d3f06 100644 --- a/src/usr/testcore/rtloader/makefile +++ b/src/usr/testcore/rtloader/makefile @@ -5,7 +5,9 @@ # # OpenPOWER HostBoot Project # -# COPYRIGHT International Business Machines Corp. 2011,2014 +# Contributors Listed Below - COPYRIGHT 2011,2017 +# [+] International Business Machines Corp. +# # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -22,6 +24,8 @@ # IBM_PROLOG_END_TAG ROOTPATH = ../../../.. +EXTRAINCDIR += ${ROOTPATH}/src/usr/pnor/ + MODULE = testrtloader TESTS = *.H -- cgit v1.2.1