Skip to content

Commit

Permalink
SMF: NVRAM Reading and Mem Distribution end-to-end Changes
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Jenkins OP Build CI <[email protected]>
Tested-by: FSP CI Jenkins <[email protected]>
Reviewed-by: Nicholas E. Bofferding <[email protected]>
Tested-by: Jenkins OP HW <[email protected]>
Reviewed-by: Daniel M. Crowell <[email protected]>
  • Loading branch information
Ilya Smirnov authored and dcrowell77 committed Jan 10, 2019
1 parent 1ba78c4 commit 21f75b9
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/include/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/include/usr/nvram/nvram_interface.H
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
40 changes: 39 additions & 1 deletion src/lib/stdlib.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2010,2018 */
/* Contributors Listed Below - COPYRIGHT 2010,2019 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -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;
}
40 changes: 39 additions & 1 deletion src/usr/isteps/istep07/call_mss_eff_config.C
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2015,2018 */
/* Contributors Listed Below - COPYRIGHT 2015,2019 */
/* [+] International Business Machines Corp. */
/* */
/* */
Expand Down Expand Up @@ -62,6 +62,10 @@

#include <hbotcompid.H>

#include <nvram/nvram_interface.H>
#include <secureboot/smf.H>
#include <stdlib.h>

namespace ISTEP_07
{

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/usr/nvram/nvram_interface.C
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/usr/secureboot/smf/smf.C
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 21f75b9

Please sign in to comment.