Skip to content

Commit

Permalink
SMF: Port NVRAM Reading Logic From Skiboot
Browse files Browse the repository at this point in the history
As part of SMF secure memory distribution, we need to be able
to read the size of secure memory from NVRAM PNOR partition
(for OpenPOWER). The functionality to read (index into) NVRAM
already exists in skiboot. This commits ports the bare minimum
functionality required to read NVRAM from skiboot to hb.

Change-Id: I17b9014ec3df590bcd8745ae70e0f96e36580117
RTC: 192411
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/67414
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: Dean Sanner <dsanner@us.ibm.com>
Reviewed-by: Roland Veloz <rveloz@us.ibm.com>
Reviewed-by: Nicholas E. Bofferding <bofferdn@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
  • Loading branch information
Ilya Smirnov authored and dcrowell77 committed Nov 8, 2018
1 parent beca511 commit 22134d6
Show file tree
Hide file tree
Showing 12 changed files with 653 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/include/usr/hbotcompid.H
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ const compId_t NVDIMM_COMP_ID = 0x3500;
const char NVDIMM_COMP_NAME[] = "nvdimm";
//@}

/** @name NVRAM
* NVRAM Support component
*/
//@{
const compId_t NVRAM_COMP_ID = 0x3900;
const char NVRAM_COMP_NAME[] = "nvram";
//@}

/** @name HDAT
* HDAT component
* @Note HDAT_COMP_ID=0x9000 matches with what
Expand Down
3 changes: 3 additions & 0 deletions src/include/usr/isteps/istep07list.H
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ const DepModInfo g_istep07Dependancies = {
DEP_LIB(libsbe.so),
DEP_LIB(libimageprocs.so),
DEP_LIB(libcen.so),
#ifndef CONFIG_FSP_BUILD
DEP_LIB(libnvram.so),
#endif
NULL
}
};
Expand Down
42 changes: 42 additions & 0 deletions src/include/usr/nvram/import/nvram.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/include/usr/nvram/import/nvram.h $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2018 */
/* [+] 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 __NVRAM_H
#define __NVRAM_H

#include <stdint.h>

extern "C"
{
int nvram_format(void *nvram_image, uint32_t nvram_size);
int nvram_check(void *nvram_image, uint32_t nvram_size);
void nvram_reinit(void);
bool nvram_validate(void);
bool nvram_has_loaded(void);
bool nvram_wait_for_load(void);

const char *nvram_query(const char *name);
bool nvram_query_eq(const char *key, const char *value);
}
#endif /* __NVRAM_H */
103 changes: 103 additions & 0 deletions src/include/usr/nvram/import/skiboot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/include/usr/nvram/import/skiboot.h $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2018 */
/* [+] 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 __SKIBOOT_H
#define __SKIBOOT_H

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <tracinterface.H>
#include <trace/trace.H>
#include <nvram/nvram_interface.H>

typedef uint16_t beint16_t;
typedef beint16_t be16;

#define BE16_TO_CPU(le_val) ((uint16_t)(le_val))

static inline uint16_t be16_to_cpu(beint16_t be_val)
{
return BE16_TO_CPU(be_val);
}

// For console logging
#define PR_EMERG 0
#define PR_ALERT 1
#define PR_CRIT 2
#define PR_ERR 3
#define PR_WARNING 4
#define PR_NOTICE 5
#define PR_PRINTF PR_NOTICE
#define PR_INFO 6
#define PR_DEBUG 7
#define PR_TRACE 8
#define PR_INSANE 9

// Skiboot-specific trace plug-in
#define prlog(l, f, args...) \
do { \
if(l == PR_TRACE || \
l <= PR_ERR) \
{ \
TRACFCOMP(NVRAM_TRACE::g_trac_nvram, f, ##args); \
} \
else \
{ \
TRACDCOMP(NVRAM_TRACE::g_trac_nvram, f, ##args); \
} \
} while(0)

#define prerror(fmt...) do { prlog(PR_ERR, fmt); } while(0)

#define prlog_once(arg, ...) \
({ \
static bool __prlog_once = false; \
if (!__prlog_once) { \
__prlog_once = true; \
prlog(arg, ##__VA_ARGS__); \
} \
})

extern "C"
{
// Various stubs for NVRAM checking/manipulation. Note that on hostboot
// side we rely on getSectionInfo to carry out most of these tasks.
bool nvram_has_loaded(void)
{
return true;
}

bool nvram_wait_for_load(void)
{
return true;
}

bool nvram_validate(void)
{
return true;
}
}

#endif
61 changes: 61 additions & 0 deletions src/include/usr/nvram/nvram_interface.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/include/usr/nvram/nvram_interface.H $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2018 */
/* [+] 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 __NVRAM_INTERFACE_H
#define __NVRAM_INTERFACE_H

#include <errl/errlentry.H>

namespace NVRAM_TRACE
{
extern trace_desc_t * g_trac_nvram;
}

namespace NVRAM
{

const char TEST_KEY[] = "test";

/**
* @brief Utility function to read the i_key from the NVRAM PNOR partition.
* The value of the i_key, if any, will reside in o_val after the
* function returns. The function attempts to readSectionInfo for
* the NVRAM partition and will error if it's unable to read the
* section info. o_val will be nullptr if the key is not found in
* NVRAM.
*
* @param[in] i_key: the key of the key/value pair representing the data
* that needs to be read from NVRAM.
* @pre The key should be a null-terminated string and must not be
* nullptr. The function will assert if i_key is nullptr.
*
* @param[out] o_val: The pointer to the location in NVRAM where the i_key
* is located or nullptr if the key is not found.
*
* @return error handle: nullptr - success; non-nullptr - an error occurred
*/
errlHndl_t nvramRead(const char* i_key, const char*& o_val);

}
#endif
45 changes: 45 additions & 0 deletions src/include/usr/nvram/nvram_reasoncodes.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/include/usr/nvram/nvram_reasoncodes.H $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2018 */
/* [+] 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 __NVRAM_REASONCODES_H
#define __NVRAM_REASONCODES_H

#include <hbotcompid.H>

namespace NVRAM
{
enum NVRAMModuleId
{
MOD_NVRAM_READ = 0x01,
};

enum NVRAMReasonCode
{
RC_NVRAM_CHECK_FAILED = NVRAM_COMP_ID | 0x01,
RC_NVRAM_READ_NULL_KEY = NVRAM_COMP_ID | 0x02,
};

} // namespace NVRAM

#endif
1 change: 1 addition & 0 deletions src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ EXTENDED_MODULES += isteps_nest
EXTENDED_MODULES += isteps_io
EXTENDED_MODULES += node_comm
EXTENDED_MODULES += $(if $(CONFIG_NVDIMM),nvdimm)
EXTENDED_MODULES += $(if $(CONFIG_FSP_BUILD),,nvram)

#***************************************
# Working test modules
Expand Down
1 change: 1 addition & 0 deletions src/usr/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ SUBDIRS += diag.d
SUBDIRS += xz.d
SUBDIRS += hwplibs.d
SUBDIRS += $(if $(CONFIG_ENABLE_HDAT_IN_HOSTBOOT),hdat.d,)
SUBDIRS += $(if $(CONFIG_FSP_BUILD),,nvram.d)

#errldisplay relies on some generated files from PRD.
#Enforce that it goes after
Expand Down

0 comments on commit 22134d6

Please sign in to comment.