diff options
author | Ilya Smirnov <ismirno@us.ibm.com> | 2018-12-12 11:33:38 -0600 |
---|---|---|
committer | Daniel M. Crowell <dcrowell@us.ibm.com> | 2019-01-10 14:52:34 -0600 |
commit | 21f75b9e4475b92665e4dd8ca182108dab53045f (patch) | |
tree | 5534008afd3766285c4da672f3082a03d056fb88 /src | |
parent | 1ba78c4580b6067882d62909c2ce2941ad36008d (diff) | |
download | talos-hostboot-21f75b9e4475b92665e4dd8ca182108dab53045f.tar.gz talos-hostboot-21f75b9e4475b92665e4dd8ca182108dab53045f.zip |
SMF: NVRAM Reading and Mem Distribution end-to-end Changes
This commit introduces the changes to read out the SMF secure
memory amount value from NVRAM and to distribute the secure
memory amount based on the value read. strtou64 was copied
from runtime code to convert the value read from NVRAM (as a
string) to uint64_t.
Change-Id: I83e41f0aaff9b4035d20a517cf866f348acedd59
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/69728
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/include/stdlib.h | 15 | ||||
-rw-r--r-- | src/include/usr/nvram/nvram_interface.H | 3 | ||||
-rw-r--r-- | src/lib/stdlib.C | 40 | ||||
-rw-r--r-- | src/usr/isteps/istep07/call_mss_eff_config.C | 40 | ||||
-rw-r--r-- | src/usr/nvram/nvram_interface.C | 3 | ||||
-rw-r--r-- | src/usr/secureboot/smf/smf.C | 6 |
6 files changed, 100 insertions, 7 deletions
diff --git a/src/include/stdlib.h b/src/include/stdlib.h index e0a8fcf6b..ed46d1bef 100644 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -5,7 +5,9 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* COPYRIGHT International Business Machines Corp. 2010,2014 */ +/* Contributors Listed Below - COPYRIGHT 2010,2019 */ +/* [+] 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. */ @@ -35,6 +37,17 @@ void free(void*); void* realloc(void*, size_t); void* calloc(size_t, size_t) __attribute__((malloc)); +/** + * @brief converts a given char string to uint64_t + * + * @param[in] nptr input string in the form of pointer to char + * @param[in] endptr UNUSED + * @param[in] base UNUSED (always base 16) + * @return the uint64_t representation of the input string or 0 + * if the function failed to convert + */ +uint64_t strtoul(const char *nptr, char **endptr, int base); + #ifdef __cplusplus }; #endif diff --git a/src/include/usr/nvram/nvram_interface.H b/src/include/usr/nvram/nvram_interface.H index d5730e86b..1df96b412 100644 --- a/src/include/usr/nvram/nvram_interface.H +++ b/src/include/usr/nvram/nvram_interface.H @@ -35,7 +35,8 @@ namespace NVRAM_TRACE namespace NVRAM { -const char TEST_KEY[] = "test"; +extern const char TEST_KEY[]; +extern const char SMF_MEM_AMT_KEY[]; /** * @brief Utility function to read the i_key from the NVRAM PNOR partition. diff --git a/src/lib/stdlib.C b/src/lib/stdlib.C index a7c694f9d..2688959bd 100644 --- a/src/lib/stdlib.C +++ b/src/lib/stdlib.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2010,2018 */ +/* Contributors Listed Below - COPYRIGHT 2010,2019 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -161,3 +161,41 @@ void* calloc(size_t num, size_t size) return mem; } +uint64_t strtoul(const char *nptr, char **endptr, int base) +{ + uint64_t l_data = 0; + size_t i = 0; + while( nptr[i] != '\0' ) + { + uint64_t l_nib = 0; + switch(nptr[i]) + { + // handle leading '0x' or 'x' + case('x'): case('X'): + l_data = 0; + break; + case('0'): l_nib = 0; break; + case('1'): l_nib = 1; break; + case('2'): l_nib = 2; break; + case('3'): l_nib = 3; break; + case('4'): l_nib = 4; break; + case('5'): l_nib = 5; break; + case('6'): l_nib = 6; break; + case('7'): l_nib = 7; break; + case('8'): l_nib = 8; break; + case('9'): l_nib = 9; break; + case('A'): case('a'): l_nib = 0xA; break; + case('B'): case('b'): l_nib = 0xB; break; + case('C'): case('c'): l_nib = 0xC; break; + case('D'): case('d'): l_nib = 0xD; break; + case('E'): case('e'): l_nib = 0xE; break; + case('F'): case('f'): l_nib = 0xF; break; + default: + return 0ULL; + } + l_data <<= 4; + l_data |= l_nib; + i++; + } + return l_data; +} diff --git a/src/usr/isteps/istep07/call_mss_eff_config.C b/src/usr/isteps/istep07/call_mss_eff_config.C index 8573a0a5f..b6aebf5cb 100644 --- a/src/usr/isteps/istep07/call_mss_eff_config.C +++ b/src/usr/isteps/istep07/call_mss_eff_config.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2015,2018 */ +/* Contributors Listed Below - COPYRIGHT 2015,2019 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -62,6 +62,10 @@ #include <hbotcompid.H> +#include <nvram/nvram_interface.H> +#include <secureboot/smf.H> +#include <stdlib.h> + namespace ISTEP_07 { @@ -435,6 +439,40 @@ void* call_mss_eff_config( void *io_pArgs ) } } +#ifndef CONFIG_FSP_BUILD + if(l_StepError.isNull()) + { + const char* l_smfMemAmtStr = nullptr; + l_err = NVRAM::nvramRead(NVRAM::SMF_MEM_AMT_KEY, l_smfMemAmtStr); + if(l_err) + { + TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace, INFO_MRK"NVRAM read failed. Will not attempt to distribute any SMF memory."); + // Do not propagate the error - we don't care if NVRAM read fails + delete l_err; + l_err = nullptr; + break; + } + + // l_smfMemAmtStr will be nullptr if the SMF_MEM_AMT_KEY doesn't exist + if(l_smfMemAmtStr) + { + uint64_t l_smfMemAmt = strtoul(l_smfMemAmtStr, nullptr, 16); + TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace, INFO_MRK"Distributing 0x%.16llx SMF memory among the procs on the system", l_smfMemAmt); + l_err = SECUREBOOT::SMF::distributeSmfMem(l_smfMemAmt); + if(l_err) + { + // Do not propagate or break on error - distributeSmfMem will + // not return unrecoverable errors. + errlCommit(l_err, HWPF_COMP_ID); + } + } + else + { + TRACFCOMP(ISTEPS_TRACE::g_trac_isteps_trace, INFO_MRK"SMF_MEM_AMT_KEY was not found in NVRAM; no SMF memory was distributed."); + } + } +#endif + } while (0); #ifdef CONFIG_SECUREBOOT diff --git a/src/usr/nvram/nvram_interface.C b/src/usr/nvram/nvram_interface.C index e4bb95796..0c2049826 100644 --- a/src/usr/nvram/nvram_interface.C +++ b/src/usr/nvram/nvram_interface.C @@ -39,6 +39,9 @@ namespace NVRAM_TRACE namespace NVRAM { +const char TEST_KEY[] = "test"; +const char SMF_MEM_AMT_KEY[] = "smf_mem_amt"; + /* * @brief Searches NVRAM partition for the i_key and puts the value in * o_val. An error is returned if NVRAM can't be loaded or if diff --git a/src/usr/secureboot/smf/smf.C b/src/usr/secureboot/smf/smf.C index 6793f0fa6..a743163d6 100644 --- a/src/usr/secureboot/smf/smf.C +++ b/src/usr/secureboot/smf/smf.C @@ -168,7 +168,7 @@ errlHndl_t distributeSmfMem(uint64_t i_requestedSmfMemAmtInBytes) l_procToMemVec.push_back(l_pToM); } - TRACFCOMP(SMF_TRACE::g_trac_smf, "distributeSmfMem: distributing 0x%x requested memory.", i_requestedSmfMemAmtInBytes); + TRACFCOMP(SMF_TRACE::g_trac_smf, "distributeSmfMem: distributing 0x%.16llx requested memory.", i_requestedSmfMemAmtInBytes); int64_t l_remainingAmtToAllocate = i_requestedSmfMemAmtInBytes; uint64_t l_currChunkSize = MIN_SMF_MEMORY_AMT; @@ -270,7 +270,7 @@ errlHndl_t distributeSmfMem(uint64_t i_requestedSmfMemAmtInBytes) uint64_t l_totMemOnSystem = 0; // For error handling below for(const auto l_proc : l_procList) { - TRACFCOMP(SMF_TRACE::g_trac_smf, "distributeSmfMem: proc 0x%x SMF_BAR_SIZE = 0x%x", + TRACFCOMP(SMF_TRACE::g_trac_smf, "distributeSmfMem: proc 0x%x SMF_BAR_SIZE = 0x%.16llx", TARGETING::get_huid(l_proc), l_proc->getAttr<TARGETING::ATTR_PROC_SMF_BAR_SIZE>()); l_totMemOnSystem += getTotalProcMemSize(l_proc); @@ -311,7 +311,7 @@ errlHndl_t distributeSmfMem(uint64_t i_requestedSmfMemAmtInBytes) // that could be allocated. if(i_requestedSmfMemAmtInBytes != l_totalAllocated) { - TRACFCOMP(SMF_TRACE::g_trac_smf, "distributeSmfMem: could not allocate exactly 0x%x SMF mem, allocated 0x%x instead.", i_requestedSmfMemAmtInBytes, l_totalAllocated); + TRACFCOMP(SMF_TRACE::g_trac_smf, "distributeSmfMem: could not allocate exactly 0x%.16llx SMF mem, allocated 0x%.16llx instead.", i_requestedSmfMemAmtInBytes, l_totalAllocated); /*@ * @reasoncode SECUREBOOT::RC_ALLOCATED_NE_REQUESTED * @moduleid SECUREBOOT::MOD_SMF_SPLIT_SMF_MEM |