diff options
| author | Dan Crowell <dcrowell@us.ibm.com> | 2018-06-18 23:05:31 -0500 |
|---|---|---|
| committer | William G. Hoffa <wghoffa@us.ibm.com> | 2018-07-03 09:18:52 -0400 |
| commit | e5dfc3ab0ec51ee63205c7064b7b4a4c4b8ba46f (patch) | |
| tree | 76ccf82718d46c0bb7bbb5cbcf451d2bbd03aaf6 /src/usr/vpd | |
| parent | 691894a135de3e81f4318a5498c4a964fdebb8ae (diff) | |
| download | blackbird-hostboot-e5dfc3ab0ec51ee63205c7064b7b4a4c4b8ba46f.tar.gz blackbird-hostboot-e5dfc3ab0ec51ee63205c7064b7b4a4c4b8ba46f.zip | |
Allow SPDX override as part of FW load
Memory VPD contents have changed since the cards have been
built so we need to provide a method to override the data
as part of a FW build. We have done the same thing
previously for the MEMD record on the Nimbus machines
so will use the same design here for SPDX.
As part of this change, the previous MEMD support was
refactored to be completely generic so a single code path
can be used for any arbitrary record.
Change-Id: I5af5e965429c881be3de0d18c82b1d7918ac9c22
CQ: SW430659
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/61190
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-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>
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/60980
Diffstat (limited to 'src/usr/vpd')
| -rw-r--r-- | src/usr/vpd/cvpd.C | 148 | ||||
| -rw-r--r-- | src/usr/vpd/cvpd.H | 32 | ||||
| -rw-r--r-- | src/usr/vpd/dvpd.C | 164 | ||||
| -rw-r--r-- | src/usr/vpd/dvpd.H | 32 | ||||
| -rw-r--r-- | src/usr/vpd/ipvpd.C | 458 | ||||
| -rw-r--r-- | src/usr/vpd/ipvpd.H | 125 | ||||
| -rw-r--r-- | src/usr/vpd/memd_vpd.C | 228 | ||||
| -rw-r--r-- | src/usr/vpd/memd_vpd.H | 227 | ||||
| -rwxr-xr-x | src/usr/vpd/test/dvpdtest.H | 54 | ||||
| -rwxr-xr-x | src/usr/vpd/vpd.C | 26 | ||||
| -rw-r--r-- | src/usr/vpd/vpd.H | 34 | ||||
| -rw-r--r-- | src/usr/vpd/vpd.mk | 3 | ||||
| -rw-r--r-- | src/usr/vpd/vpd_common.C | 8 |
13 files changed, 968 insertions, 571 deletions
diff --git a/src/usr/vpd/cvpd.C b/src/usr/vpd/cvpd.C index 7576009eb..fe203dd50 100644 --- a/src/usr/vpd/cvpd.C +++ b/src/usr/vpd/cvpd.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2013,2017 */ +/* Contributors Listed Below - COPYRIGHT 2013,2018 */ /* [+] Google Inc. */ /* [+] International Business Machines Corp. */ /* */ @@ -115,10 +115,38 @@ namespace CVPD TRACSSCOMP( g_trac_vpd, ENTER_MRK"cvpdRead()" ); - err = Singleton<CvpdFacade>::instance().read(i_target, - io_buffer, - io_buflen, - args); +#ifdef CONFIG_SECUREBOOT + // Load the secure section just in case if we're using it + bool l_didload = false; + err = Singleton<CvpdFacade>::instance(). + loadUnloadSecureSection( args, i_target, true, l_didload ); +#endif + + if( !err ) + { + err = Singleton<CvpdFacade>::instance().read(i_target, + io_buffer, + io_buflen, + args); + } + +#ifdef CONFIG_SECUREBOOT + if( l_didload ) + { + errlHndl_t err2 = Singleton<CvpdFacade>::instance(). + loadUnloadSecureSection( args, i_target, false, l_didload ); + if( err2 && !err ) + { + err = err2; + err2 = nullptr; + } + else if( err2 ) + { + err2->plid(err->plid()); + errlCommit( err2, VPD_COMP_ID ); + } + } +#endif return err; } @@ -288,3 +316,113 @@ void CvpdFacade::getRecordLists( #endif } +/** + * @brief Callback function to check for a record override and + * set iv_overridePtr appropriately + */ +errlHndl_t CvpdFacade::checkForRecordOverride( const char* i_record, + TARGETING::Target* i_target, + uint8_t*& o_ptr ) +{ + TRACFCOMP(g_trac_vpd,ENTER_MRK"CvpdFacade::checkForRecordOverride( %s, 0x%.8X )", + i_record, get_huid(i_target)); + errlHndl_t l_errl = nullptr; + o_ptr = nullptr; + + assert( i_record != nullptr, "CvpdFacade::checkForRecordOverride() i_record is null" ); + assert( i_target != nullptr, "CvpdFacade::checkForRecordOverride() i_target is null" ); + + VPD::RecordTargetPair_t l_recTarg = + VPD::makeRecordTargetPair(i_record,i_target); + + do + { + // We only support overriding SPDX + if( strcmp( i_record, "SPDX" ) ) + { + TRACFCOMP(g_trac_vpd,"Record %s has no override", i_record); + iv_overridePtr[l_recTarg] = nullptr; + break; + } + + // Compare the 5th nibble + constexpr uint32_t l_vmMask = 0x00000F00; + input_args_t l_args = { CVPD::SPDX, CVPD::VM, VPD::AUTOSELECT }; + l_errl = getMEMDFromPNOR( l_args, + i_target, + l_vmMask ); + if( l_errl ) + { + TRACFCOMP(g_trac_vpd,ERR_MRK"ERROR from getMEMDFromPNOR."); + break; + } + + } while(0); + + // For any error, we should reset the override map so that we'll + // attempt everything again the next time we want VPD + if( l_errl ) + { + iv_overridePtr.erase(l_recTarg); + } + else + { + o_ptr = iv_overridePtr[l_recTarg]; + } + + return l_errl; +} + +#ifdef CONFIG_SECUREBOOT +/** + * @brief Load/unload the appropriate secure section for + * an overriden PNOR section + */ +errlHndl_t CvpdFacade::loadUnloadSecureSection( input_args_t i_args, + TARGETING::Target* i_target, + bool i_load, + bool& o_loaded ) +{ + errlHndl_t l_err = nullptr; + o_loaded = false; + +#ifndef __HOSTBOOT_RUNTIME + // Only relevant for SPDX + if( i_args.record != CVPD::SPDX ) + { + return nullptr; + } + + const char* l_record = nullptr; + l_err = translateRecord( i_args.record, l_record ); + if( l_err ) + { + return l_err; + } + + // Jump out if we don't have an override + VPD::RecordTargetPair_t l_recTarg = + VPD::makeRecordTargetPair(l_record,i_target); + VPD::OverrideMap_t::iterator l_overItr = iv_overridePtr.find(l_recTarg); + if( l_overItr == iv_overridePtr.end() ) + { + return nullptr; + } + + if( i_load ) + { + l_err = loadSecureSection(PNOR::MEMD); + if( !l_err ) + { + o_loaded = true; + } + } + else + { + l_err = unloadSecureSection(PNOR::MEMD); + } +#endif + + return l_err; +} +#endif diff --git a/src/usr/vpd/cvpd.H b/src/usr/vpd/cvpd.H index 73c54128d..31f89b29f 100644 --- a/src/usr/vpd/cvpd.H +++ b/src/usr/vpd/cvpd.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2013,2017 */ +/* Contributors Listed Below - COPYRIGHT 2013,2018 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -176,6 +176,22 @@ class CvpdFacade: public IpVpdFacade */ CvpdFacade( ); +#ifdef CONFIG_SECUREBOOT + /** + * @brief Load/unload the appropriate secure section for + * an overriden PNOR section + * @param[in] i_args Record/keyword + * @param[in] i_target Target pointer + * @param[in] i_load true=load, false=unload + * @param[out] o_loaded true=section loaded, false=section not loaded + * @return Error log + */ + virtual errlHndl_t loadUnloadSecureSection( input_args_t i_args, + TARGETING::Target* i_target, + bool i_load, + bool& o_loaded ); +#endif + private: /** @@ -197,5 +213,19 @@ class CvpdFacade: public IpVpdFacade const recordInfo* & o_altVpdRecords, uint64_t & o_altRecSize); + protected: + /** + * @brief Callback function to check for a record override and + * set iv_overridePtr appropriately + * @param[in] i_record Record name + * @param[in] i_target Target pointer + * @param[out] o_ptr Pointer to location of record in PNOR, + * ==nullptr if there is no override + * @return Error log + */ + virtual errlHndl_t checkForRecordOverride( const char* i_record, + TARGETING::Target* i_target, + uint8_t*& o_ptr ); + }; #endif // __CVPD_H diff --git a/src/usr/vpd/dvpd.C b/src/usr/vpd/dvpd.C index 8adf670f7..9e5e7fbf4 100644 --- a/src/usr/vpd/dvpd.C +++ b/src/usr/vpd/dvpd.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2013,2017 */ +/* Contributors Listed Below - COPYRIGHT 2013,2018 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -113,12 +113,44 @@ namespace DVPD args.location = ((VPD::vpdCmdTarget)va_arg( i_args, uint64_t )); TRACSSCOMP( g_trac_vpd, - ENTER_MRK"dvpdRead()" ); + ENTER_MRK"dvpdRead(0x%.8X):rec=%d,kw=%d,loc=%d", + TARGETING::get_huid(i_target), + args.record, + args.keyword, + args.location); + +#ifdef CONFIG_SECUREBOOT + // Load the secure section just in case if we're using it + bool l_didload = false; + err = Singleton<DvpdFacade>::instance(). + loadUnloadSecureSection( args, i_target, true, l_didload ); +#endif - err = Singleton<DvpdFacade>::instance().read(i_target, - io_buffer, - io_buflen, - args); + if( !err ) + { + err = Singleton<DvpdFacade>::instance().read(i_target, + io_buffer, + io_buflen, + args); + } + +#ifdef CONFIG_SECUREBOOT + if( l_didload ) + { + errlHndl_t err2 = Singleton<DvpdFacade>::instance(). + loadUnloadSecureSection( args, i_target, false, l_didload ); + if( err2 && !err ) + { + err = err2; + err2 = nullptr; + } + else if( err2 ) + { + err2->plid(err->plid()); + errlCommit( err2, VPD_COMP_ID ); + } + } +#endif return err; } @@ -166,7 +198,11 @@ namespace DVPD args.location = ((VPD::vpdCmdTarget)va_arg( i_args, uint64_t )); TRACSSCOMP( g_trac_vpd, - ENTER_MRK"dvpdWrite()" ); + ENTER_MRK"dvpdWrite(0x%.8X):rec=%d,kw=%d,loc=%d", + TARGETING::get_huid(i_target), + args.record, + args.keyword, + args.location); err = Singleton<DvpdFacade>::instance().write(i_target, @@ -337,9 +373,8 @@ IpVpdFacade(DVPD::dvpdRecords, iv_configInfo.vpdWriteHW = false; #endif -iv_vpdSectionSize = DVPD::SECTION_SIZE; -iv_vpdMaxSections = DVPD::MAX_SECTIONS; - + iv_vpdSectionSize = DVPD::SECTION_SIZE; + iv_vpdMaxSections = DVPD::MAX_SECTIONS; } // Retrun lists of records that should be copied to pnor. void DvpdFacade::getRecordLists( @@ -367,3 +402,112 @@ void DvpdFacade::getRecordLists( #endif } +/** + * @brief Callback function to check for a record override + */ +errlHndl_t DvpdFacade::checkForRecordOverride( const char* i_record, + TARGETING::Target* i_target, + uint8_t*& o_ptr ) +{ + TRACFCOMP(g_trac_vpd,ENTER_MRK"DvpdFacade::checkForRecordOverride( %s, 0x%.8X )", + i_record, get_huid(i_target)); + errlHndl_t l_errl = nullptr; + o_ptr = nullptr; + + assert( i_record != nullptr, "DvpdFacade::checkForRecordOverride() i_record is null" ); + assert( i_target != nullptr, "DvpdFacade::checkForRecordOverride() i_target is null" ); + + VPD::RecordTargetPair_t l_recTarg = + VPD::makeRecordTargetPair(i_record,i_target); + + do + { + // We only support overriding MEMD + if( strcmp( i_record, "MEMD" ) ) + { + TRACFCOMP(g_trac_vpd,"Record %s has no override", i_record); + iv_overridePtr[l_recTarg] = nullptr; + break; + } + + // Compare the last nibble + constexpr uint32_t l_vmMask = 0x0000000F; + input_args_t l_args = { DVPD::MEMD, DVPD::VM, VPD::AUTOSELECT }; + l_errl = getMEMDFromPNOR( l_args, + i_target, + l_vmMask ); + if( l_errl ) + { + TRACFCOMP(g_trac_vpd,ERR_MRK"ERROR from getMEMDFromPNOR."); + break; + } + + } while(0); + + // For any error, we should reset the override map so that we'll + // attempt everything again the next time we want VPD + if( l_errl ) + { + iv_overridePtr.erase(l_recTarg); + } + else + { + o_ptr = iv_overridePtr[l_recTarg]; + } + + return l_errl; +} + +#ifdef CONFIG_SECUREBOOT +/** + * @brief Load/unload the appropriate secure section for + * an overriden PNOR section + */ +errlHndl_t DvpdFacade::loadUnloadSecureSection( input_args_t i_args, + TARGETING::Target* i_target, + bool i_load, + bool& o_loaded ) +{ + errlHndl_t l_err = nullptr; + o_loaded = false; + +#ifndef __HOSTBOOT_RUNTIME + // Only relevant for MEMD + if( i_args.record != DVPD::MEMD ) + { + return nullptr; + } + + const char* l_record = nullptr; + l_err = translateRecord( i_args.record, l_record ); + if( l_err ) + { + return l_err; + } + + // Jump out if we don't have an override + VPD::RecordTargetPair_t l_recTarg = + VPD::makeRecordTargetPair(l_record,i_target); + VPD::OverrideMap_t::iterator l_overItr = iv_overridePtr.find(l_recTarg); + if( l_overItr == iv_overridePtr.end() ) + { + return nullptr; + } + + if( i_load ) + { + l_err = loadSecureSection(PNOR::MEMD); + if( !l_err ) + { + o_loaded = true; + } + } + else + { + l_err = unloadSecureSection(PNOR::MEMD); + } +#endif + + return l_err; +} +#endif diff --git a/src/usr/vpd/dvpd.H b/src/usr/vpd/dvpd.H index 73279e844..92985aebe 100644 --- a/src/usr/vpd/dvpd.H +++ b/src/usr/vpd/dvpd.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2013,2016 */ +/* Contributors Listed Below - COPYRIGHT 2013,2018 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -225,6 +225,22 @@ class DvpdFacade: public IpVpdFacade */ DvpdFacade( ); +#ifdef CONFIG_SECUREBOOT + /** + * @brief Load/unload the appropriate secure section for + * an overriden PNOR section + * @param[in] i_args Record/keyword + * @param[in] i_target Target pointer + * @param[in] i_load true=load, false=unload + * @param[out] o_loaded true=section loaded, false=section not loaded + * @return Error log + */ + virtual errlHndl_t loadUnloadSecureSection( input_args_t i_args, + TARGETING::Target* i_target, + bool i_load, + bool& o_loaded ); +#endif + private: /** @@ -246,5 +262,19 @@ class DvpdFacade: public IpVpdFacade const recordInfo* & o_altVpdRecords, uint64_t & o_altRecSize); + protected: + /** + * @brief Callback function to check for a record override and + * set iv_overridePtr appropriately + * @param[in] i_record Record name + * @param[in] i_target Target pointer + * @param[out] o_ptr Pointer to location of record in PNOR, + * ==nullptr if there is no override + * @return Error log + */ + virtual errlHndl_t checkForRecordOverride( const char* i_record, + TARGETING::Target* i_target, + uint8_t*& o_ptr ); + }; #endif // __DVPD_H diff --git a/src/usr/vpd/ipvpd.C b/src/usr/vpd/ipvpd.C index c62c8355f..25b7970f2 100644 --- a/src/usr/vpd/ipvpd.C +++ b/src/usr/vpd/ipvpd.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2013,2017 */ +/* Contributors Listed Below - COPYRIGHT 2013,2018 */ /* [+] Google Inc. */ /* [+] International Business Machines Corp. */ /* */ @@ -41,7 +41,8 @@ #include <vpd/vpd_if.H> #include <config.h> #include <vpd/ipvpdenums.H> -#include <vpd/memd_vpdenums.H> +#include <util/utilrsvdmem.H> +#include <util/runtime/util_rt.H> #include "vpd.H" #include "cvpd.H" @@ -68,7 +69,6 @@ extern trace_desc_t* g_trac_vpd; static const uint64_t IPVPD_TOC_SIZE = 0x100; //256 static const uint64_t IPVPD_TOC_ENTRY_SIZE = 8; static const uint64_t IPVPD_TOC_INVALID_DATA = 0xFFFFFFFFFFFFFFFF; -uint64_t MEMD_HEADER_SIZE = sizeof(MemdHeader_t); /** * @brief Constructor @@ -88,7 +88,6 @@ IpVpdFacade::IpVpdFacade(const recordInfo* i_vpdRecords, ,iv_mutex(i_mutex) ,iv_cachePnorAddr(0x0) ,iv_vpdMsgType(i_vpdMsgType) -,iv_memdAccessed(false) { iv_configInfo.vpdReadPNOR = false; iv_configInfo.vpdReadHW = false; @@ -243,11 +242,9 @@ errlHndl_t IpVpdFacade::write ( TARGETING::Target * i_target, // write() recursively for each location if ( iv_configInfo.vpdWritePNOR && iv_configInfo.vpdWriteHW && - i_args.location == VPD::AUTOSELECT ) + ((i_args.location & VPD::LOCATION_MASK) == VPD::AUTOSELECT) ) { - input_args_t l_args; - l_args.record = i_args.record; - l_args.keyword = i_args.keyword; + input_args_t l_args = i_args; l_args.location = VPD::SEEPROM; err = write( i_target, @@ -615,7 +612,8 @@ errlHndl_t IpVpdFacade::loadPnor ( TARGETING::Target * i_target ) sRecLength, pRecPtr, i_target, - sRecArgs.location ); + sRecArgs.location, + (*it).record_name ); if( err ) { TRACFCOMP(g_trac_vpd,"IpVpdFacade::loadPnor() Error reading record %s",(*it).record_name); @@ -858,6 +856,43 @@ errlHndl_t IpVpdFacade::findRecordOffset ( const char * i_record, { errlHndl_t err = NULL; + // Look for a record override in our image unless explicitly told not to + if( (i_args.location & VPD::OVERRIDE_MASK) != VPD::USEVPD ) + { + uint8_t* l_overridePtr = nullptr; + VPD::RecordTargetPair_t l_recTarg = + VPD::makeRecordTargetPair(i_record,i_target); + + // Check if we already figured out where to get this record from + VPD::OverrideMap_t::iterator l_overItr = iv_overridePtr.find(l_recTarg); + if( l_overItr != iv_overridePtr.end() ) + { + l_overridePtr = l_overItr->second; + } + else + { + // Now go see if we should be using the override and if so + // where we find the right copy + err = checkForRecordOverride(i_record,i_target,l_overridePtr); + if( err ) + { + TRACFCOMP( g_trac_vpd, ERR_MRK"findRecordOffset> failure calling checkForRecordOverride for %s on %.8X", + i_record, get_huid(i_target) ); + return err; + } + + TRACFCOMP( g_trac_vpd, INFO_MRK" Record %s for target 0x%.8X exists at %p in PNOR", + i_record, get_huid(i_target), l_overridePtr ); + } + + // If we have an override, the record is already pointed at directly + if( l_overridePtr != nullptr ) + { + o_offset = 0; + return nullptr; + } + } + // Determine the VPD source (PNOR/SEEPROM) VPD::vpdCmdTarget vpdSource = VPD::AUTOSELECT; bool configError = false; @@ -940,17 +975,17 @@ bool IpVpdFacade::hasVpdPresent( TARGETING::Target * i_target, uint16_t recordOffset = 0x0; input_args_t i_args; bool vpdPresent = false; - const char * recordName = NULL; - const char * keywordName = NULL; + const char * l_recordName = NULL; + const char * l_keywordName = NULL; i_args.record = i_record; i_args.keyword = i_keyword; do { - //get the Recod/Keyword names + //get the Record/Keyword names err = translateRecord( i_args.record, - recordName ); + l_recordName ); if( err ) { @@ -960,7 +995,7 @@ bool IpVpdFacade::hasVpdPresent( TARGETING::Target * i_target, } err = translateKeyword( i_args.keyword, - keywordName ); + l_keywordName ); if( err ) { @@ -969,10 +1004,10 @@ bool IpVpdFacade::hasVpdPresent( TARGETING::Target * i_target, break; } - vpdPresent = recordPresent( recordName, + vpdPresent = recordPresent( l_recordName, recordOffset, i_target, - VPD::AUTOSELECT ); + VPD::USEVPD ); }while( 0 ); @@ -996,7 +1031,7 @@ bool IpVpdFacade::recordPresent( const char * i_record, { errlHndl_t err = NULL; uint64_t tmpOffset = 0x0; - char record[RECORD_BYTE_SIZE] = { '\0' }; + char l_record[RECORD_BYTE_SIZE] = { '\0' }; bool matchFound = false; do @@ -1018,9 +1053,10 @@ bool IpVpdFacade::recordPresent( const char * i_record, //Read Record Name err = fetchData( tmpOffset, RECORD_BYTE_SIZE, - record, + l_record, i_target, - i_location ); + i_location, + i_record ); tmpOffset += RECORD_BYTE_SIZE; if( err ) @@ -1028,7 +1064,7 @@ bool IpVpdFacade::recordPresent( const char * i_record, break; } - if( !(memcmp(record, i_record, RECORD_BYTE_SIZE )) ) + if( !(memcmp(l_record, i_record, RECORD_BYTE_SIZE )) ) { matchFound = true; @@ -1037,7 +1073,8 @@ bool IpVpdFacade::recordPresent( const char * i_record, RECORD_ADDR_BYTE_SIZE, &o_offset, i_target, - i_location ); + i_location, + i_record ); if( err ) { break; @@ -1485,7 +1522,8 @@ errlHndl_t IpVpdFacade::retrieveKeyword ( const char * i_keywordName, keywordSize, io_buffer, i_target, - i_args.location ); + i_args.location, + i_recordName ); if( err ) { break; @@ -1525,7 +1563,8 @@ errlHndl_t IpVpdFacade::retrieveRecord( const char * i_recordName, sizeof(l_size), &l_size, i_target, - i_args.location ); + i_args.location, + i_recordName ); if( err ) { @@ -1557,7 +1596,8 @@ errlHndl_t IpVpdFacade::retrieveRecord( const char * i_recordName, l_size, io_buffer, i_target, - i_args.location ); + i_args.location, + i_recordName ); if( err ) { break; @@ -1581,7 +1621,8 @@ errlHndl_t IpVpdFacade::fetchData ( uint64_t i_byteAddr, size_t i_numBytes, void * o_data, TARGETING::Target * i_target, - VPD::vpdCmdTarget i_location ) + VPD::vpdCmdTarget i_location, + const char* i_record ) { errlHndl_t err = NULL; @@ -1594,12 +1635,58 @@ errlHndl_t IpVpdFacade::fetchData ( uint64_t i_byteAddr, i_location, vpdSource ); + // Look for a record override in our image unless explicitly told not to + bool l_foundOverride = false; + if( (i_location & VPD::OVERRIDE_MASK) != VPD::USEVPD ) + { + uint8_t* l_overridePtr = nullptr; + VPD::RecordTargetPair_t l_recTarg = + VPD::makeRecordTargetPair(i_record,i_target); + + // At this point we can assume that the pointer is set into our + // map if we need it + VPD::OverrideMap_t::iterator l_overItr = iv_overridePtr.find(l_recTarg); + if( l_overItr != iv_overridePtr.end() ) + { + l_overridePtr = l_overItr->second; + + // Just do a simple memcpy + if( l_overridePtr != nullptr ) + { + memcpy( o_data, l_overridePtr+i_byteAddr, i_numBytes ); + l_foundOverride = true; + } + } + // Automatically populate a bunch of infrastructure records that + // we would never override (makes the error checks pass cleaner) + else if( (0 == memcmp( i_record, "VHDR", 4 )) + || (0 == memcmp( i_record, "VTOC", 4 )) ) + { + iv_overridePtr[l_recTarg] = nullptr; + } + else + { + TRACFCOMP( g_trac_vpd, ERR_MRK"IpVpdFacade::fetchData: " + "iv_overridePtr is not set as expected for %s on %.8X", + i_record, TARGETING::get_huid(i_target) ); + for( auto l_over : iv_overridePtr ) + { + TRACFCOMP( g_trac_vpd, "%.8X : %.8X = %p", + TARGETING::get_huid((l_over.first).second), + (l_over.first).first, + l_over.second ); + } + assert( false, + "iv_overridePtr is not set inside IpVpdFacade::fetchData" ); + } + } + // Get the data - if ( vpdSource == VPD::PNOR ) + if ( (vpdSource == VPD::PNOR) && !l_foundOverride ) { err = fetchDataFromPnor( i_byteAddr, i_numBytes, o_data, i_target ); } - else if ( vpdSource == VPD::SEEPROM ) + else if ( (vpdSource == VPD::SEEPROM) && !l_foundOverride ) { err = fetchDataFromEeprom( i_byteAddr, i_numBytes, o_data, i_target ); } @@ -1608,7 +1695,7 @@ errlHndl_t IpVpdFacade::fetchData ( uint64_t i_byteAddr, configError = true; } - if( configError ) + if( configError && !l_foundOverride ) { TRACFCOMP( g_trac_vpd, ERR_MRK"IpVpdFacade::fetchData: " "Error resolving VPD source (PNOR/SEEPROM)"); @@ -1738,9 +1825,12 @@ errlHndl_t IpVpdFacade::findKeywordAddr ( const char * i_keywordName, int matchesFound = 0; TRACSSCOMP( g_trac_vpd, - ENTER_MRK"IpVpdFacade::findKeywordAddr(%s, %s, . . .)", + ENTER_MRK"IpVpdFacade::findKeywordAddr(%s, %s, %d, %d, %.8X )", i_keywordName, - i_recordName ); + i_recordName, + i_offset, + i_index, + TARGETING::get_huid(i_target) ); do { @@ -1749,31 +1839,14 @@ errlHndl_t IpVpdFacade::findKeywordAddr ( const char * i_keywordName, RECORD_ADDR_BYTE_SIZE, &recordSize, i_target, - i_args.location ); + i_args.location, + i_recordName ); offset += RECORD_ADDR_BYTE_SIZE; if( err ) { break; } - if((iv_pnorSection == PNOR::MEMD)) - { - static uint64_t l_basePnorAddr = 0;//getPnorAddr(*this); - uint64_t l_cache_address = 0; - - if((iv_cachePnorAddr !=0) && !(iv_memdAccessed)) - { - l_basePnorAddr = getPnorAddr(*this); - iv_memdAccessed = true; - } - - TARGETING::ATTR_MEMD_OFFSET_type l_memd_offset = - i_target->getAttr<TARGETING::ATTR_MEMD_OFFSET>(); - l_cache_address = l_basePnorAddr + - MEMD_HEADER_SIZE + l_memd_offset; - setPnorAddr(l_cache_address); - } - // Byte Swap recordSize = le16toh( recordSize ); @@ -1784,7 +1857,8 @@ errlHndl_t IpVpdFacade::findKeywordAddr ( const char * i_keywordName, RECORD_BYTE_SIZE, record, i_target, - i_args.location ); + i_args.location, + i_recordName ); // If we were looking for the Record Type (RT) keyword, we are done. if (memcmp( i_keywordName, "RT", KEYWORD_BYTE_SIZE ) == 0) { @@ -1809,10 +1883,11 @@ errlHndl_t IpVpdFacade::findKeywordAddr ( const char * i_keywordName, if( memcmp( record, i_recordName, RECORD_BYTE_SIZE ) ) { TRACFCOMP( g_trac_vpd, ERR_MRK"IpVpdFacade::findKeywordAddr: " - "Record(%s) for offset (0x%04x) did not match " + "Record(%s) for offset (0x%04x->0x%04x) did not match " "expected record(%s)!", record, i_offset, + offset, i_recordName ); /*@ @@ -1866,7 +1941,8 @@ errlHndl_t IpVpdFacade::findKeywordAddr ( const char * i_keywordName, KEYWORD_BYTE_SIZE, keyword, i_target, - i_args.location ); + i_args.location, + i_recordName ); offset += KEYWORD_BYTE_SIZE; if( err ) @@ -1894,7 +1970,8 @@ errlHndl_t IpVpdFacade::findKeywordAddr ( const char * i_keywordName, keywordLength, &keywordSize, i_target, - i_args.location ); + i_args.location, + i_recordName ); offset += keywordLength; if( err ) @@ -2055,6 +2132,52 @@ errlHndl_t IpVpdFacade::writeKeyword ( const char * i_keywordName, i_args.location, vpdDest ); + // Look for a record override in our image unless explicitly told not to + if( (i_args.location & VPD::OVERRIDE_MASK) != VPD::USEVPD ) + { + uint8_t* l_overridePtr = nullptr; + VPD::RecordTargetPair_t l_recTarg + = VPD::makeRecordTargetPair(i_recordName,i_target); + + // At this point we can assume that the pointer is set into our + // map if we need it + VPD::OverrideMap_t::iterator l_overItr = iv_overridePtr.find(l_recTarg); + if( l_overItr != iv_overridePtr.end() ) + { + // If we are using an override, we can't write to it + if( l_overridePtr != nullptr ) + { + uint32_t l_kw = 0; + memcpy( &l_kw, i_keywordName, KEYWORD_BYTE_SIZE ); + /*@ + * @errortype + * @reasoncode VPD::VPD_CANNOT_WRITE_OVERRIDDEN_VPD + * @moduleid VPD::VPD_IPVPD_WRITE_KEYWORD + * @userdata1[0:31] Target HUID + * @userdata1[32:63] <unused> + * @userdata2[0:31] VPD Record (ASCII) + * @userdata2[32:63] VPD Keyword (ASCII) + * @devdesc Attempting to write to a VPD record + * that has been overridden by firmware + * @custdesc Firmware error writing VPD + */ + err = new ERRORLOG::ErrlEntry( + ERRORLOG::ERRL_SEV_UNRECOVERABLE, + VPD::VPD_IPVPD_WRITE_KEYWORD, + VPD::VPD_WRITE_DEST_UNRESOLVED, + TWO_UINT32_TO_UINT64( + TARGETING::get_huid(i_target), + 0 ), + TWO_UINT32_TO_UINT64( + l_recTarg.first, + l_kw), + ERRORLOG::ErrlEntry::ADD_SW_CALLOUT ); + err->collectTrace( "VPD", 256 ); + break; + } + } + } + // Write the data if ( vpdDest == VPD::PNOR ) { @@ -2119,7 +2242,7 @@ errlHndl_t IpVpdFacade::writeKeyword ( const char * i_keywordName, if( configError ) { - TRACFCOMP( g_trac_vpd, ERR_MRK"IpVpdFacade::fetchData: " + TRACFCOMP( g_trac_vpd, ERR_MRK"IpVpdFacade::writeKeyword: " "Error resolving VPD source (PNOR/SEEPROM)"); /*@ @@ -2270,3 +2393,230 @@ void IpVpdFacade::getRecordLists( o_altRecSize = 0; } +/** + * @brief Callback function to check for a record override + */ +errlHndl_t IpVpdFacade::checkForRecordOverride( const char* i_record, + TARGETING::Target* i_target, + uint8_t*& o_ptr ) +{ + // by default there is not an override + o_ptr = nullptr; + TRACDCOMP( g_trac_vpd, "No override for %s on %.8X", i_record, TARGETING::get_huid(i_target) ); + VPD::RecordTargetPair_t l_recTarg = + VPD::makeRecordTargetPair(i_record,i_target); + iv_overridePtr[l_recTarg] = nullptr; + return nullptr; +} + +/** + * @brief Retrieves the MEMD record from PNOR, finds a matching + * set of data, and sets up sets up the override pointer. + */ +errlHndl_t IpVpdFacade::getMEMDFromPNOR( input_args_t i_recKw, + TARGETING::Target* i_target, + uint32_t i_vmMask ) +{ + TRACFCOMP(g_trac_vpd,ENTER_MRK"IpVpdFacade::getMEMDFromPNOR( %d, %.8X )", + i_recKw.record, get_huid(i_target)); + errlHndl_t l_errl = nullptr; + + /** + * @brief Define the set of information included at the beginning of the + * MEMD PNOR section + */ + struct MemdHeader_t + { + uint32_t eyecatch; /* Eyecatch to determine validity. "OKOK" */ + uint32_t header_version; /* What version of the header this is in */ + uint32_t memd_version; /* What version of the MEMD this includes */ + uint32_t expected_size_k; /* Size in thousands (not KB) of each MEMD instance */ + uint16_t expected_num; /* Number of MEMD instances in this section */ + uint8_t padding[14]; /* Padding for future changes */ + }__attribute__((packed)); + + enum MEMD_valid_constants + { + MEMD_VALID_HEADER = 0x4f4b4f4b, // "OKOK" + MEMD_VALID_HEADER_VERSION = 0x30312e30, // "01.0"; + }; + + do + { + // Get the Record/keyword names + const char* l_record = nullptr; + l_errl = translateRecord( i_recKw.record, + l_record ); + if( l_errl ) + { + break; + } + + const char* l_keyword = nullptr; + l_errl = translateKeyword( i_recKw.keyword, + l_keyword ); + if( l_errl ) + { + break; + } + + VPD::RecordTargetPair_t l_recTarg = + VPD::makeRecordTargetPair(l_record,i_target); + + // MEMD Processing +#ifdef __HOSTBOOT_RUNTIME + uint64_t l_memdSize = 0; + uint64_t l_memd_addr = hb_get_rt_rsvd_mem( + Util::HBRT_MEM_LABEL_VPD_MEMD, + 0, + l_memdSize ); + if( (l_memd_addr == 0) || (l_memdSize == 0) ) + { + TRACFCOMP(g_trac_vpd,"Optional MEMD section not found in reserved mem."); + break; + } + + uint8_t* l_memd_vaddr + = reinterpret_cast<uint8_t *>(l_memd_addr); +#else + PNOR::SectionInfo_t l_memd_info; + l_errl = PNOR::getSectionInfo(PNOR::MEMD,l_memd_info); + if( l_errl ) + { + TRACFCOMP(g_trac_vpd,"Optional MEMD section not found in PNOR."); + delete l_errl; + l_errl = nullptr; + iv_overridePtr[l_recTarg] = nullptr; + break; + } + + uint8_t* l_memd_vaddr + = reinterpret_cast<uint8_t *>(l_memd_info.vaddr); +#endif + + TRACFCOMP(g_trac_vpd,"MEMD is at %p", l_memd_vaddr); + + // Get and process the header + MemdHeader_t l_header; + memcpy(&l_header, l_memd_vaddr, sizeof(l_header)); + TRACFBIN(g_trac_vpd,"MEMD Header", &l_header, sizeof(l_header)); + + // See if we have any valid override records + bool l_valid_memd = ((l_header.eyecatch == MEMD_VALID_HEADER) & + (l_header.header_version == MEMD_VALID_HEADER_VERSION) & + ( (l_header.memd_version == l_recTarg.first) + // also handle old version to avoid coreqs + || (l_header.memd_version == MEMD_VALID_HEADER_VERSION) )); + if( !l_valid_memd ) + { + TRACFCOMP(g_trac_vpd,"MEMD is not valid, ignoring it"); + iv_overridePtr[l_recTarg] = nullptr; + break; + } + + // Get the VM keyword size from the real VPD + size_t l_vm_size = 0; + input_args_t l_vm_args = i_recKw; + l_vm_args.location = VPD::USEVPD; + l_errl = read( i_target, nullptr, l_vm_size, l_vm_args ); + if( l_errl ) + { + TRACFCOMP(g_trac_vpd,"ERROR getting MEMD VM size"); + break; + } + + // VM should be exactly 4 bytes long + uint32_t l_vm_kw = 0; + assert( l_vm_size == sizeof(l_vm_kw) ); + + // Get the VM keyword from the real VPD + l_errl = read( i_target, &l_vm_kw, l_vm_size, l_vm_args ); + if( l_errl ) + { + TRACFCOMP(g_trac_vpd,"ERROR getting DVPD VM keyword"); + break; + } + TRACFCOMP(g_trac_vpd,"VPD VM = %.8X", l_vm_kw); + + // Offset past the header to start with + uint16_t l_memd_offset = sizeof(MemdHeader_t); + bool l_found_match = false; + + // Loop through each possible instance until we find a match or run out + for( auto l_inst = 0; l_inst < l_header.expected_num; ++l_inst ) + { + // Get the VM keyword from the copy in PNOR + TRACFCOMP(g_trac_vpd,"Attempting to read MEMD VM keyword from override"); + input_args_t l_pnor_args = i_recKw; + l_pnor_args.location = VPD::USEOVERRIDE; + + // Set the ptr in the map to allow the lookups inside + // IpVpdFacade to work + iv_overridePtr[l_recTarg] = l_memd_vaddr + l_memd_offset; + + uint32_t l_memd_vm = 0; + l_errl = retrieveKeyword( l_keyword, l_record, + 0, 0, + i_target, + &l_memd_vm, l_vm_size, + l_pnor_args ); + if(l_errl) + { + TRACFCOMP(g_trac_vpd,"getMEMDFromPNOR: ERROR getting %s:%s keyword in slot %d", l_record, l_keyword, l_inst); + // if we got this using the legacy header version then it is + // because we are looking at a bunch of the wrong record + // type, so just move on + if( l_header.memd_version == MEMD_VALID_HEADER_VERSION ) + { + delete l_errl; + l_errl = nullptr; + } + break; + } + + // Compare the appropriate portion of VM + if( (l_memd_vm != 0) && + ((l_vm_kw & i_vmMask) == (l_memd_vm & i_vmMask)) ) + { + TRACFCOMP(g_trac_vpd,"Matching data was found in PNOR at %.llX. VM: PNOR=%.8X, VPD=%.8X", + l_memd_offset, + l_memd_vm, + l_vm_kw); + l_found_match = true; + break; + } + + // VM's don't match, we need to keep looking + TRACFCOMP(g_trac_vpd,"No match. VM: PNOR=%.8X, VPD=%.8X", + l_memd_vm, + l_vm_kw ); + l_memd_offset += (l_header.expected_size_k * 1000); + } + if( l_errl ) { break; } + + // If we did not find a match, set our map back to a nullptr + if( !l_found_match ) + { + iv_overridePtr[l_recTarg] = nullptr; + } + } while(0); + + TRACFCOMP(g_trac_vpd,EXIT_MRK"getMEMDFromPNOR()"); + return l_errl; +} + +#ifdef CONFIG_SECUREBOOT +/** + * @brief Load/unload the appropriate secure section for + * an overriden PNOR section + */ +errlHndl_t IpVpdFacade::loadUnloadSecureSection( input_args_t i_args, + TARGETING::Target* i_target, + bool i_load, + bool& o_loaded ) +{ + // nothing to do by default + o_loaded = false; + return nullptr; +} +#endif diff --git a/src/usr/vpd/ipvpd.H b/src/usr/vpd/ipvpd.H index 4797cb317..597c6e256 100644 --- a/src/usr/vpd/ipvpd.H +++ b/src/usr/vpd/ipvpd.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2013,2017 */ +/* Contributors Listed Below - COPYRIGHT 2013,2018 */ /* [+] Google Inc. */ /* [+] International Business Machines Corp. */ /* */ @@ -28,10 +28,13 @@ #include <list> +#include <map> #include <pnor/pnorif.H> #include <devicefw/driverif.H> +#include <config.h> #include "vpd.H" + /** @file ipvpd.H * @brief Provides base support for i/p-Series style IBM VPD */ @@ -84,8 +87,7 @@ class IpVpdFacade } input_args_t; /** - * @brief Structure of information needed to access requested - * record/keyword combinations. + * @brief Mapping from keyword enum into 4 character string */ typedef struct { @@ -94,6 +96,7 @@ class IpVpdFacade } recordInfo; /** + * @brief Mapping from keyword enum into 2 character string */ typedef struct { @@ -102,6 +105,16 @@ class IpVpdFacade } keywordInfo; /** + * @brief Mapping from record enum into PNOR section + * where override might be + */ + typedef struct + { + VPD::vpdRecord record; + PNOR::SectionId section; + } recordOverrideInfo_t; + + /** * @brief Structure defining where to read/write VPD data */ typedef struct @@ -138,7 +151,7 @@ class IpVpdFacade * * @param[in] i_vpdKeywords - Pointer to array of VPD Keywords to use * - * @param[in] i_keyCount - size of i_vpdKeywords array + * @param[in] i_keySize - size of i_vpdKeywords array * * @param[in] i_pnorSection - PNOR Section containing VPD for current * chip @@ -293,6 +306,23 @@ class IpVpdFacade */ void setConfigFlagsHW ( ); +#ifdef CONFIG_SECUREBOOT + /** + * @brief Load/unload the appropriate secure section for + * an overriden PNOR section + * @param[in] i_args Record/keyword + * @param[in] i_target Target pointer + * @param[in] i_load true=load, false=unload + * @param[out] o_loaded true=section loaded, false=section not loaded + * @return Error log + */ + virtual errlHndl_t loadUnloadSecureSection( input_args_t i_args, + TARGETING::Target* i_target, + bool i_load, + bool& o_loaded ); +#endif + + protected: /** @@ -578,6 +608,8 @@ class IpVpdFacade * * @param[in] i_location - VPD location to fetch data from (PNOR/SEEPROM) * + * @param[in] i_record - String representation of the record. + * * @return errHndl_t - NULL if successful, otherwise a pointer to the * error log. */ @@ -585,7 +617,8 @@ class IpVpdFacade size_t i_numBytes, void * o_data, TARGETING::Target * i_target, - VPD::vpdCmdTarget i_location ); + VPD::vpdCmdTarget i_location, + const char* i_record ); /** * @brief This function actually reads the data from PNOR @@ -625,8 +658,7 @@ class IpVpdFacade void * o_data, TARGETING::Target * i_target ); - - /** + /** * @brief This function compares 2 ipvpd record values. Used for binary * search to find a match. * @@ -688,6 +720,51 @@ class IpVpdFacade const recordInfo* & o_altVpdRecords, uint64_t & o_altRecSize); + /** + * @brief Returns the cached pnor address + * + */ + inline static uint64_t getPnorAddr(const IpVpdFacade& x) + { + return x.iv_cachePnorAddr; + }; + + /** + * @brief Set the cached pnor address to the given value + * + */ + inline void setPnorAddr(uint64_t i_pnorAddr) + { + this->iv_cachePnorAddr = i_pnorAddr; + }; + + + /** + * @brief Retrieves the MEMD record from PNOR, finds a matching + * set of data, and sets up sets up the override pointer. + * @param[in] i_recKw Record/Keyword values + * @param[in] i_target Relevant Target + * @param[in] i_vmMask Specific bits to compare with EEPROM + * @return Error log + */ + errlHndl_t getMEMDFromPNOR( input_args_t i_recKw, + TARGETING::Target* i_target, + uint32_t i_vmMask ); + + /** + * @brief Callback function to check for a record override and + * set iv_overridePtr appropriately + * @param[in] i_record Record name + * @param[in] i_target Target pointer + * @param[out] o_ptr Pointer to location of record in PNOR, + * ==nullptr if there is no override + * @return Error log + */ + virtual errlHndl_t checkForRecordOverride( const char* i_record, + TARGETING::Target* i_target, + uint8_t*& o_ptr ); + + protected: // Variables /** @@ -702,8 +779,7 @@ class IpVpdFacade */ uint64_t iv_vpdMaxSections; - - public: // Variables + public: //Used by static function /** * @brief Pointer to array of VPD Record information * @@ -711,30 +787,12 @@ class IpVpdFacade const recordInfo* iv_vpdRecords; /** - * @brief Returns the cached pnor address - * - */ - inline static uint64_t getPnorAddr(const IpVpdFacade& x) - { - return x.iv_cachePnorAddr; - } - - /** - * @brief Set the cached pnor address to the given value - * - */ - inline void setPnorAddr(uint64_t i_pnorAddr) - { - this->iv_cachePnorAddr = i_pnorAddr; - } - - /** * @brief Number of VPD Records for current chip * */ - uint64_t iv_recSize; + const uint64_t iv_recSize; - protected: // Variables + protected: /** * @brief Pointer to array of VPD Keyword information * @@ -745,7 +803,7 @@ class IpVpdFacade * @brief Number of VPD Keywords for current chip * */ - uint64_t iv_keySize; + const uint64_t iv_keySize; /** * @brief PNOR section enum for vpd type @@ -778,10 +836,11 @@ class IpVpdFacade configInfo iv_configInfo; /** - * @brief Boolean variable to denote if the pnor section was - * accessed for the MEMD section + * @brief Used to denote if a record is being + * fetched from a copy in our code image versus the + * real VPD EEPROM (or cache) */ - bool iv_memdAccessed; + VPD::OverrideMap_t iv_overridePtr; }; diff --git a/src/usr/vpd/memd_vpd.C b/src/usr/vpd/memd_vpd.C deleted file mode 100644 index 08f122d03..000000000 --- a/src/usr/vpd/memd_vpd.C +++ /dev/null @@ -1,228 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: src/usr/vpd/memd_vpd.C $ */ -/* */ -/* OpenPOWER HostBoot Project */ -/* */ -/* Contributors Listed Below - COPYRIGHT 2013,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. */ -/* You may obtain a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ -/* implied. See the License for the specific language governing */ -/* permissions and limitations under the License. */ -/* */ -/* IBM_PROLOG_END_TAG */ -// ---------------------------------------------- -// Includes -// ---------------------------------------------- -#include <string.h> -#include <endian.h> -#include <trace/interface.H> -#include <errl/errlentry.H> -#include <errl/errlmanager.H> -#include <targeting/common/targetservice.H> -#include <targeting/common/util.H> -#include <targeting/common/utilFilter.H> -#include <devicefw/driverif.H> -#include <vfs/vfs.H> -#include <vpd/vpdreasoncodes.H> -#include <vpd/memd_vpdenums.H> -#include <vpd/vpd_if.H> -#include <i2c/eepromif.H> -#include <config.h> -#include "memd_vpd.H" -#include "cvpd.H" -#include "vpd.H" -#include "pvpd.H" -#include <initservice/initserviceif.H> - -// ---------------------------------------------- -// Trace definitions -// ---------------------------------------------- -extern trace_desc_t* g_trac_vpd; - - -// ------------------------ -// Macros for unit testing -//#define TRACUCOMP(args...) TRACFCOMP(args) -#define TRACUCOMP(args...) -//#define TRACSSCOMP(args...) TRACFCOMP(args) -#define TRACSSCOMP(args...) - -namespace MEMD_VPD -{ - // ---------------------------------------------- - // Globals - // ---------------------------------------------- - mutex_t g_mutex = MUTEX_INITIALIZER; - - - /** - * @brief This function will perform the steps required to do a read from - * the Hostboot MEMD_VPD data. - * - * @param[in] i_opType - Operation Type - See DeviceFW::OperationType in - * driververif.H - * - * @param[in] i_target - Processor Target device - * - * @param [in/out] io_buffer - Pointer to the data that was read from - * the target device. This parameter, when set to NULL, will return - * the keyword size value in io_buflen. - * - * @param [in/out] io_buflen - Length of the buffer to be read or written - * to/from the target. This value should indicate the size of the - * io_buffer parameter that has been allocated. Being returned it - * will indicate the number of valid bytes in the buffer being - * returned. This parameter will contain the size of a keyword when - * the io_buffer parameter is passed in NULL. - * - * @param [in] i_accessType - Access Type - See DeviceFW::AccessType in - * usrif.H - * - * @param [in] i_args - This is an argument list for the device driver - * framework. - * - * @return errlHndl_t - NULL if successful, otherwise a pointer to the - * error log. - */ - errlHndl_t MEMD_VPDRead ( DeviceFW::OperationType i_opType, - TARGETING::Target * i_target, - void * io_buffer, - size_t & io_buflen, - int64_t i_accessType, - va_list i_args ) - { - errlHndl_t err = NULL; - IpVpdFacade::input_args_t args; - args.record = ((MEMD_VPDRecord)va_arg( i_args, uint64_t )); - args.keyword = ((MEMD_VPDKeyword)va_arg( i_args, uint64_t )); - args.location = ((VPD::vpdCmdTarget)va_arg( i_args, uint64_t )); - - TRACSSCOMP( g_trac_vpd, - ENTER_MRK"MEMD_VPDRead()" ); - - err = Singleton<MEMD_VpdFacade>::instance().read(i_target, - io_buffer, - io_buflen, - args); - - return err; - } - - - /** - * @brief This function will perform the steps required to do a write to - * the Hostboot MEMD_VPD data. - * - * @param[in] i_opType - Operation Type - See DeviceFW::OperationType in - * driververif.H - * - * @param[in] i_target - Processor Target device - * - * @param [in/out] io_buffer - Pointer to the data that was read from - * the target device. It will also be used to contain data to - * be written to the device. - * - * @param [in/out] io_buflen - Length of the buffer to be read or written - * to/from the target. This value should indicate the size of the - * io_buffer parameter that has been allocated. Being returned it - * will indicate the number of valid bytes in the buffer being - * returned. - * - * @param [in] i_accessType - Access Type - See DeviceFW::AccessType in - * usrif.H - * - * @param [in] i_args - This is an argument list for the device driver - * framework. - * - * @return errlHndl_t - NULL if successful, otherwise a pointer to the - * error log. - */ - errlHndl_t MEMD_VPDWrite ( DeviceFW::OperationType i_opType, - TARGETING::Target * i_target, - void * io_buffer, - size_t & io_buflen, - int64_t i_accessType, - va_list i_args ) - { - errlHndl_t err = NULL; - IpVpdFacade::input_args_t args; - args.record = ((MEMD_VPDRecord)va_arg( i_args, uint64_t )); - args.keyword = ((MEMD_VPDKeyword)va_arg( i_args, uint64_t )); - args.location = ((VPD::vpdCmdTarget)va_arg( i_args, uint64_t )); - - TRACSSCOMP( g_trac_vpd, - ENTER_MRK"MEMD_VPDWrite()" ); - - - err = Singleton<MEMD_VpdFacade>::instance().write(i_target, - io_buffer, - io_buflen, - args); - - return err; - } - - // Register with the routing code - DEVICE_REGISTER_ROUTE( DeviceFW::READ, - DeviceFW::MEMD_VPD, - TARGETING::TYPE_MCS, - MEMD_VPDRead ); - DEVICE_REGISTER_ROUTE( DeviceFW::WRITE, - DeviceFW::MEMD_VPD, - TARGETING::TYPE_MCS, - MEMD_VPDWrite ); - -}; // end namespace MEMD_VPD - - -//MEMD_VpdFacade Class Functions -/** - * @brief Constructor - * Planar VPD is included in the Centaur PNOR section. - * Including with Centaur vpd minimizes the number of PNOR sections. - */ -MEMD_VpdFacade::MEMD_VpdFacade() : -IpVpdFacade(MEMD_VPD::MEMD_VPDRecords, - (sizeof(MEMD_VPD::MEMD_VPDRecords)/sizeof( - MEMD_VPD::MEMD_VPDRecords[0])), - MEMD_VPD::MEMD_VPDKeywords, - (sizeof(MEMD_VPD::MEMD_VPDKeywords)/sizeof( - MEMD_VPD::MEMD_VPDKeywords[0])), - PNOR::MEMD, // note use of MEMD - MEMD_VPD::g_mutex, - VPD::VPD_INVALID) // Direct access memory -{ - TRACUCOMP(g_trac_vpd, "MEMD_VpdFacade::MEMD_VpdFacade> " ); - - iv_configInfo.vpdReadPNOR = true; - iv_configInfo.vpdReadHW = false; - iv_configInfo.vpdWritePNOR = false; - iv_configInfo.vpdWriteHW = false; - iv_vpdSectionSize = MEMD_VPD::SECTION_SIZE; - iv_vpdMaxSections = MEMD_VPD::MAX_SECTIONS; -} - -/** - * @brief returns true if the record is present in this facade. - * this will always return true in this function - */ -bool MEMD_VpdFacade::recordPresent( const char * i_record, - uint16_t & offset, - TARGETING::Target * i_target, - VPD::vpdCmdTarget i_location ) -{ - offset = 0; - return true; -} diff --git a/src/usr/vpd/memd_vpd.H b/src/usr/vpd/memd_vpd.H deleted file mode 100644 index d94532b4a..000000000 --- a/src/usr/vpd/memd_vpd.H +++ /dev/null @@ -1,227 +0,0 @@ -/* IBM_PROLOG_BEGIN_TAG */ -/* This is an automatically generated prolog. */ -/* */ -/* $Source: src/usr/vpd/memd_vpd.H $ */ -/* */ -/* OpenPOWER HostBoot Project */ -/* */ -/* Contributors Listed Below - COPYRIGHT 2013,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. */ -/* You may obtain a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */ -/* implied. See the License for the specific language governing */ -/* permissions and limitations under the License. */ -/* */ -/* IBM_PROLOG_END_TAG */ -#ifndef __MEMD_VPD_H -#define __MEMD_VPD_H - - -/** - * @file MEMD_VPD.H - * - * @brief Provides the interfaces for the MEMD_VPD device driver - * - */ - -// ---------------------------------------------- -// Includes -// ---------------------------------------------- -#include <errl/errlentry.H> -#include <vpd/memd_vpdenums.H> - -#include "ipvpd.H" -#include <config.h> - -namespace MEMD_VPD -{ - - enum - { - MAX_SECTIONS = 1, - SECTION_SIZE = 0x6000, - }; - - - /** - * @brief Conversion of MEMD_VPD Records to corresponding character - * representation. - */ - const IpVpdFacade::recordInfo MEMD_VPDRecords[] = - { - // ------------------------------------------------------------------- - // NOTE: This list must remain an ordered list! There is a - // testcase that checks this. When adding new entries to the - // list, be sure that the keyword in each entry (value 0) - // are in ascending order. - // ------------------------------------------------------------------- - { MEMD, "MEMD" }, - - // ------------------------------------------------------------------- - // DO NOT USE!! This is for test purposes ONLY! - { MEMD_VPD_TEST_RECORD, "TEST" }, - // ------------------------------------------------------------------- - }; - - /** - * @brief Conversion of MEMD_VPD Keywords to corresponding character - * representation. - */ - const IpVpdFacade::keywordInfo MEMD_VPDKeywords[] = - { - // ------------------------------------------------------------------- - // NOTE: This list must remain an ordered list! There is a - // testcase that checks this. When adding new entries to - // the list, be sure that the keyword in each entry (value 0) - // are in ascending order. - // ------------------------------------------------------------------- - { B3, "B3" }, - { B4, "B4" }, - { B7, "B7" }, - { CC, "CC" }, - { CE, "CE" }, - { CT, "CT" }, - { DR, "DR" }, - { FC, "FC" }, - { FN, "FN" }, - { HE, "HE" }, - { HW, "HW" }, - { I2, "I2" }, - { IN, "IN" }, - { J0, "J0" }, - { J1, "J1" }, - { J2, "J2" }, - { J3, "J3" }, - { J4, "J4" }, - { J5, "J5" }, - { J6, "J6" }, - { J7, "J7" }, - { J8, "J8" }, - { J9, "J9" }, - { JA, "JA" }, - { JB, "JB" }, - { JC, "JC" }, - { JD, "JD" }, - { JE, "JE" }, - { JF, "JF" }, - { JG, "JG" }, - { JH, "JH" }, - { JI, "JI" }, - { JJ, "JJ" }, - { JK, "JK" }, - { JL, "JL" }, - { JM, "JM" }, - { JN, "JN" }, - { JO, "JO" }, - { JP, "JP" }, - { JQ, "JQ" }, - { JR, "JR" }, - { JS, "JS" }, - { JT, "JT" }, - { JU, "JU" }, - { JV, "JV" }, - { JW, "JW" }, - { JX, "JX" }, - { JY, "JY" }, - { JZ, "JZ" }, - { LX, "LX" }, - { MR, "MR" }, - { MT, "MT" }, - { PF, "PF" }, - { PN, "PN" }, - { PR, "PR" }, - { RB, "RB" }, - { RG, "RG" }, - { RT, "RT" }, - { SE, "SE" }, - { SN, "SN" }, - { SO, "SO" }, - { TM, "TM" }, - { VM, "VM" }, - { VZ, "VZ" }, - { X0, "X0" }, - { X1, "X1" }, - { X2, "X2" }, - { X3, "X3" }, - { X4, "X4" }, - { X5, "X5" }, - { X6, "X6" }, - { X7, "X7" }, - { X8, "X8" }, - { X9, "X9" }, - { XA, "XA" }, - { XB, "XB" }, - { XC, "XC" }, - { XD, "XD" }, - { XE, "XE" }, - { XF, "XF" }, - { XG, "XG" }, - { XH, "XH" }, - { XI, "XI" }, - { XJ, "XJ" }, - { XK, "XK" }, - { XL, "XL" }, - { XM, "XM" }, - { XN, "XN" }, - { XO, "XO" }, - { XP, "XP" }, - { XQ, "XQ" }, - { XR, "XR" }, - { XS, "XS" }, - { XT, "XT" }, - { XU, "XU" }, - { XV, "XV" }, - { XW, "XW" }, - { XX, "XX" }, - { XY, "XY" }, - { XZ, "XZ" }, - { Q0, "Q0" }, - { Q1, "Q1" }, - { Q2, "Q2" }, - { Q3, "Q3" }, - { Q4, "Q4" }, - { Q5, "Q5" }, - { Q6, "Q6" }, - { Q7, "Q7" }, - { Q8, "Q8" }, - { CK, "CK" }, - - // ------------------------------------------------------------------- - // DO NOT USE!! This is for test purposes ONLY! - { MEMD_VPD_TEST_KEYWORD, "ZZ" }, - // ------------------------------------------------------------------- - - //Common ipvpd - { FULL_RECORD, "FL"}, - }; - -}; // end MEMD_VPD namespace - -class MEMD_VpdFacade: public IpVpdFacade -{ - public: - - /** - * @brief Constructor - */ - MEMD_VpdFacade( ); - - - protected: - virtual bool recordPresent( const char * i_record, - uint16_t & offset, - TARGETING::Target * i_target, - VPD::vpdCmdTarget i_location ); - - -}; -#endif // __MEMD_VPD_H diff --git a/src/usr/vpd/test/dvpdtest.H b/src/usr/vpd/test/dvpdtest.H index e7c61cdd2..b0d62a062 100755 --- a/src/usr/vpd/test/dvpdtest.H +++ b/src/usr/vpd/test/dvpdtest.H @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2013,2016 */ +/* Contributors Listed Below - COPYRIGHT 2013,2018 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -37,6 +37,7 @@ #include <errl/errlentry.H> #include <devicefw/driverif.H> #include <targeting/common/predicates/predicatectm.H> +#include <config.h> #include <vpd/dvpdenums.H> #include <vpd/vpdreasoncodes.H> @@ -204,6 +205,7 @@ class DVPDTest: public CxxTest::TestSuite /** * @brief This function will test DVPD writes. + * Note: this forces the path to not use the FW override */ void testDvpdWrite ( void ) { @@ -234,7 +236,9 @@ class DVPDTest: public CxxTest::TestSuite err = deviceRead( theTarget, testData, theSize, - DEVICE_DVPD_ADDRESS(DVPD::MEMD,TSTKEYWD) ); + DEVICE_DVPD_FORCE_ADDRESS(DVPD::MEMD, + TSTKEYWD, + VPD::USEVPD) ); if( err ) { fails++; @@ -254,7 +258,9 @@ class DVPDTest: public CxxTest::TestSuite err = deviceRead( theTarget, origData, theSize, - DEVICE_DVPD_ADDRESS(DVPD::MEMD,TSTKEYWD) ); + DEVICE_DVPD_FORCE_ADDRESS(DVPD::MEMD, + TSTKEYWD, + VPD::USEVPD) ); if( err ) { fails++; @@ -282,7 +288,9 @@ class DVPDTest: public CxxTest::TestSuite err = deviceWrite( theTarget, testData, theSize, - DEVICE_DVPD_ADDRESS(DVPD::MEMD,TSTKEYWD) ); + DEVICE_DVPD_FORCE_ADDRESS(DVPD::MEMD, + TSTKEYWD, + VPD::USEVPD) ); if( err ) { fails++; @@ -302,7 +310,9 @@ class DVPDTest: public CxxTest::TestSuite err = deviceRead( theTarget, verifyData, theSize, - DEVICE_DVPD_ADDRESS(DVPD::MEMD,TSTKEYWD) ); + DEVICE_DVPD_FORCE_ADDRESS(DVPD::MEMD, + TSTKEYWD, + VPD::USEVPD) ); if( err ) { fails++; @@ -334,7 +344,9 @@ class DVPDTest: public CxxTest::TestSuite err = deviceWrite( theTarget, origData, theSize, - DEVICE_DVPD_ADDRESS(DVPD::MEMD,TSTKEYWD) ); + DEVICE_DVPD_FORCE_ADDRESS(DVPD::MEMD, + TSTKEYWD, + VPD::USEVPD) ); if( err ) { fails++; @@ -716,6 +728,36 @@ class DVPDTest: public CxxTest::TestSuite "testDvpdCheckStructOrder - %d fails", fails ); } + + DVPDTest() : CxxTest::TestSuite() + { + TRACFCOMP( g_trac_vpd, "Starting DVPDTest" ); +#ifdef CONFIG_SECUREBOOT +#ifndef __HOSTBOOT_RUNTIME + errlHndl_t l_err = loadSecureSection(PNOR::MEMD); + if(l_err) + { + TS_FAIL( "DVPDTest : loadSecureSection" ); + delete l_err; + } +#endif +#endif + } + + ~DVPDTest() + { +#ifdef CONFIG_SECUREBOOT +#ifndef __HOSTBOOT_RUNTIME + errlHndl_t l_err = unloadSecureSection(PNOR::MEMD); + TRACFCOMP( g_trac_vpd, "Ending DVPDTest" ); + if(l_err) + { + TS_FAIL( "DVPDTest : unloadSecureSection" ); + delete l_err; + } +#endif +#endif + } }; #endif diff --git a/src/usr/vpd/vpd.C b/src/usr/vpd/vpd.C index 585c168fa..a9bc590b5 100755 --- a/src/usr/vpd/vpd.C +++ b/src/usr/vpd/vpd.C @@ -1106,4 +1106,30 @@ errlHndl_t validateSharedPnorCache() return errl; } +/** + * @brief Get a list of all overridden sections + */ +void getListOfOverrideSections( OverrideRsvMemMap_t& o_overrides ) +{ + // Note - any new sections need to be added here + + PNOR::SectionInfo_t l_memd_info; + errlHndl_t l_elog = PNOR::getSectionInfo(PNOR::MEMD,l_memd_info); + if( l_elog ) + { + TRACFCOMP( g_trac_vpd, + "getListOfOverrideSections> failed getSectionInfo call" ); + delete l_elog; + return; + } + + // Add MEMD section + OverrideSpecifier_t l_memd = { + PNOR::MEMD, + l_memd_info.size + }; + + o_overrides[0x4D454D44/*MEMD*/] = l_memd; +} + }; //end VPD namespace diff --git a/src/usr/vpd/vpd.H b/src/usr/vpd/vpd.H index 2753a476d..7446dc491 100644 --- a/src/usr/vpd/vpd.H +++ b/src/usr/vpd/vpd.H @@ -27,6 +27,7 @@ #include <pnor/pnorif.H> #include <vpd/vpd_if.H> +#include <map> namespace VPD { @@ -83,6 +84,35 @@ union VpdWriteMsg_t } PACKED; }; +/** + * first = 4-character record name as a 4-byte uint + * second = Target pointer + */ +typedef std::pair<uint32_t, TARGETING::Target*> RecordTargetPair_t; + +/** + * @brief Helper function to convert record string to uint + * @param[in] 4-character record string + * @param[in] Target pointer + * @return Fully formed RecordTargetPair_t + */ +inline RecordTargetPair_t makeRecordTargetPair( const char* i_rec, + TARGETING::Target* i_targ ) +{ + uint32_t l_rec = 0; + memcpy( &l_rec, i_rec, sizeof(l_rec) ); + return std::make_pair(l_rec,i_targ); +}; + + +/** + * Indexed by RecordTargetPair_t + * Returns a pointer to this record within the override section + * if it is being used, or nullptr if not. + */ +typedef std::map<RecordTargetPair_t,uint8_t*> OverrideMap_t; + + /** * @brief This function is used to query the attribute code to get the VPD @@ -258,6 +288,10 @@ errlHndl_t getPnAndSnRecordAndKeywords( TARGETING::Target * i_target, vpdKeyword & io_partKeyword, vpdKeyword & io_serialKeyword); +/** + * @brief Read data from the BMC to update the system serial number + * @param[in] i_target - node target to update vpd of + */ void updateSerialNumberFromBMC( TARGETING::Target * i_nodetarget ); }; //end VPD namespace diff --git a/src/usr/vpd/vpd.mk b/src/usr/vpd/vpd.mk index d07a2bbea..b8337b989 100644 --- a/src/usr/vpd/vpd.mk +++ b/src/usr/vpd/vpd.mk @@ -5,7 +5,7 @@ # # OpenPOWER HostBoot Project # -# Contributors Listed Below - COPYRIGHT 2013,2017 +# Contributors Listed Below - COPYRIGHT 2013,2018 # [+] International Business Machines Corp. # # @@ -29,6 +29,5 @@ OBJS += mvpd.o OBJS += cvpd.o OBJS += pvpd.o OBJS += dvpd.o -OBJS += memd_vpd.o OBJS += spd.o OBJS += errlud_vpd.o diff --git a/src/usr/vpd/vpd_common.C b/src/usr/vpd/vpd_common.C index d11dc8743..3c657acb5 100644 --- a/src/usr/vpd/vpd_common.C +++ b/src/usr/vpd/vpd_common.C @@ -1,11 +1,11 @@ /* IBM_PROLOG_BEGIN_TAG */ /* This is an automatically generated prolog. */ /* */ -/* $Source: src/usr/vpd/vpd.C $ */ +/* $Source: src/usr/vpd/vpd_common.C $ */ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2013,2015 */ +/* Contributors Listed Below - COPYRIGHT 2013,2018 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -77,7 +77,7 @@ bool resolveVpdSource( TARGETING::Target * i_target, bool badConfig = false; o_vpdSource = VPD::INVALID_LOCATION; - if( i_vpdCmdTarget == VPD::PNOR ) + if( (i_vpdCmdTarget & VPD::LOCATION_MASK) == VPD::PNOR ) { if( i_rwPnorEnabled ) { @@ -89,7 +89,7 @@ bool resolveVpdSource( TARGETING::Target * i_target, TRACFCOMP(g_trac_vpd,"resolveVpdSource: VpdCmdTarget=PNOR but READ/WRITE PNOR CONFIG is disabled"); } } - else if( i_vpdCmdTarget == VPD::SEEPROM ) + else if( (i_vpdCmdTarget & VPD::LOCATION_MASK) == VPD::SEEPROM ) { if( i_rwHwEnabled ) { |

