summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIlya Smirnov <ismirno@us.ibm.com>2018-10-08 15:27:28 -0500
committerDaniel M. Crowell <dcrowell@us.ibm.com>2018-11-07 20:36:51 -0600
commit22134d69a2016dd1ea6d9de858f4e68f732289ae (patch)
tree3e6996dc775e869d6643e748f83d728187add2c3
parentbeca51100d6ba74914391b2a0baec830f427ec99 (diff)
downloadtalos-hostboot-22134d69a2016dd1ea6d9de858f4e68f732289ae.tar.gz
talos-hostboot-22134d69a2016dd1ea6d9de858f4e68f732289ae.zip
SMF: Port NVRAM Reading Logic From Skiboot
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>
-rw-r--r--src/include/usr/hbotcompid.H8
-rw-r--r--src/include/usr/isteps/istep07list.H3
-rw-r--r--src/include/usr/nvram/import/nvram.h42
-rw-r--r--src/include/usr/nvram/import/skiboot.h103
-rw-r--r--src/include/usr/nvram/nvram_interface.H61
-rw-r--r--src/include/usr/nvram/nvram_reasoncodes.H45
-rw-r--r--src/makefile1
-rw-r--r--src/usr/makefile1
-rw-r--r--src/usr/nvram/import/nvram-format.C232
-rw-r--r--src/usr/nvram/makefile37
-rw-r--r--src/usr/nvram/nvram_interface.C119
-rw-r--r--src/usr/sbeio/common/sbe_attn.C2
12 files changed, 653 insertions, 1 deletions
diff --git a/src/include/usr/hbotcompid.H b/src/include/usr/hbotcompid.H
index d9faaaf5f..6405d0a89 100644
--- a/src/include/usr/hbotcompid.H
+++ b/src/include/usr/hbotcompid.H
@@ -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
diff --git a/src/include/usr/isteps/istep07list.H b/src/include/usr/isteps/istep07list.H
index a0c591679..e9c03b082 100644
--- a/src/include/usr/isteps/istep07list.H
+++ b/src/include/usr/isteps/istep07list.H
@@ -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
}
};
diff --git a/src/include/usr/nvram/import/nvram.h b/src/include/usr/nvram/import/nvram.h
new file mode 100644
index 000000000..e335b0f4b
--- /dev/null
+++ b/src/include/usr/nvram/import/nvram.h
@@ -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 */
diff --git a/src/include/usr/nvram/import/skiboot.h b/src/include/usr/nvram/import/skiboot.h
new file mode 100644
index 000000000..689eef541
--- /dev/null
+++ b/src/include/usr/nvram/import/skiboot.h
@@ -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
diff --git a/src/include/usr/nvram/nvram_interface.H b/src/include/usr/nvram/nvram_interface.H
new file mode 100644
index 000000000..d5730e86b
--- /dev/null
+++ b/src/include/usr/nvram/nvram_interface.H
@@ -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
diff --git a/src/include/usr/nvram/nvram_reasoncodes.H b/src/include/usr/nvram/nvram_reasoncodes.H
new file mode 100644
index 000000000..985bab349
--- /dev/null
+++ b/src/include/usr/nvram/nvram_reasoncodes.H
@@ -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
diff --git a/src/makefile b/src/makefile
index d7b0bf045..60a62feb7 100644
--- a/src/makefile
+++ b/src/makefile
@@ -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
diff --git a/src/usr/makefile b/src/usr/makefile
index ca4f9d512..6d9ccd9c6 100644
--- a/src/usr/makefile
+++ b/src/usr/makefile
@@ -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
diff --git a/src/usr/nvram/import/nvram-format.C b/src/usr/nvram/import/nvram-format.C
new file mode 100644
index 000000000..d57f9ab51
--- /dev/null
+++ b/src/usr/nvram/import/nvram-format.C
@@ -0,0 +1,232 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/usr/nvram/import/nvram-format.C $ */
+/* */
+/* 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 */
+#include <skiboot.h>
+#include <nvram.h>
+
+struct chrp_nvram_hdr {
+ uint8_t sig;
+ uint8_t cksum;
+ be16 len;
+ char name[12];
+};
+
+static struct chrp_nvram_hdr *skiboot_part_hdr;
+
+static uint8_t chrp_nv_cksum(struct chrp_nvram_hdr *hdr)
+{
+ struct chrp_nvram_hdr h_copy = *hdr;
+ uint8_t b_data, i_sum, c_sum;
+ uint8_t *p = (uint8_t *)&h_copy;
+ unsigned int nbytes = sizeof(h_copy);
+
+ h_copy.cksum = 0;
+ for (c_sum = 0; nbytes; nbytes--) {
+ b_data = *(p++);
+ i_sum = c_sum + b_data;
+ if (i_sum < c_sum)
+ i_sum++;
+ c_sum = i_sum;
+ }
+ return c_sum;
+}
+
+#define NVRAM_SIG_FW_PRIV 0x51
+#define NVRAM_SIG_SYSTEM 0x70
+#define NVRAM_NAME_COMMON "common"
+#define NVRAM_NAME_FW_PRIV "ibm,skiboot"
+#define NVRAM_SIZE_FW_PRIV 0x1000
+
+static const char *find_next_key(const char *start, const char *end)
+{
+ /*
+ * Unused parts of the partition are set to NUL. If we hit two
+ * NULs in a row then we assume that we have hit the end of the
+ * partition.
+ */
+ if (*start == 0)
+ return NULL;
+
+ while (start < end) {
+ if (*start == 0)
+ return start + 1;
+
+ start++;
+ }
+
+ return NULL;
+}
+
+/*
+ * Check that the nvram partition layout is sane and that it
+ * contains our required partitions. If not, we re-format the
+ * lot of it
+ */
+int nvram_check(void *nvram_image, const uint32_t nvram_size)
+{
+ unsigned int offset = 0;
+ bool found_common = false;
+
+ skiboot_part_hdr = NULL;
+
+ while (offset + sizeof(struct chrp_nvram_hdr) < nvram_size) {
+#ifdef __HOSTBOOT_MODULE
+ struct chrp_nvram_hdr *h = reinterpret_cast<chrp_nvram_hdr*>(
+ reinterpret_cast<uint8_t*>(nvram_image)
+ + offset);
+#else
+ struct chrp_nvram_hdr *h = nvram_image + offset;
+#endif
+
+ if (chrp_nv_cksum(h) != h->cksum) {
+ prerror("NVRAM: Partition at offset 0x%x"
+ " has bad checksum: 0x%02x vs 0x%02x\n",
+ offset, h->cksum, chrp_nv_cksum(h));
+ goto failed;
+ }
+ if (be16_to_cpu(h->len) < 1) {
+ prerror("NVRAM: Partition at offset 0x%x"
+ " has incorrect 0 length\n", offset);
+ goto failed;
+ }
+
+ if (h->sig == NVRAM_SIG_SYSTEM &&
+ strcmp(h->name, NVRAM_NAME_COMMON) == 0)
+ found_common = true;
+
+ if (h->sig == NVRAM_SIG_FW_PRIV &&
+ strcmp(h->name, NVRAM_NAME_FW_PRIV) == 0)
+ skiboot_part_hdr = h;
+
+ offset += be16_to_cpu(h->len) << 4;
+ if (offset > nvram_size) {
+ prerror("NVRAM: Partition at offset 0x%x"
+ " extends beyond end of nvram !\n", offset);
+ goto failed;
+ }
+ }
+ if (!found_common) {
+ prlog_once(PR_ERR, "NVRAM: Common partition not found !\n");
+ goto failed;
+ }
+
+ if (!skiboot_part_hdr) {
+ prlog_once(PR_ERR, "NVRAM: Skiboot private partition not found !\n");
+ goto failed;
+ } else {
+ /*
+ * The OF NVRAM format requires config strings to be NUL
+ * terminated and unused memory to be set to zero. Well behaved
+ * software should ensure this is done for us, but we should
+ * always check.
+ */
+ const char *last_byte = (const char *) skiboot_part_hdr +
+ be16_to_cpu(skiboot_part_hdr->len) * 16 - 1;
+
+ if (*last_byte != 0) {
+ prerror("NVRAM: Skiboot private partition is not NUL terminated");
+ goto failed;
+ }
+ }
+
+ prlog(PR_INFO, "NVRAM: Layout appears sane\n");
+ assert(skiboot_part_hdr);
+ return 0;
+ failed:
+ return -1;
+}
+
+/*
+ * nvram_query() - Searches skiboot NVRAM partition for a key=value pair.
+ *
+ * Returns a pointer to a NUL terminated string that contains the value
+ * associated with the given key.
+ */
+const char *nvram_query(const char *key)
+{
+ const char *part_end, *start;
+ int key_len = strlen(key);
+
+ assert(key);
+
+ if (!nvram_has_loaded()) {
+ prlog(PR_DEBUG,
+ "NVRAM: Query for '%s' must wait for NVRAM to load\n",
+ key);
+ if (!nvram_wait_for_load()) {
+ prlog(PR_CRIT, "NVRAM: Failed to load\n");
+ return NULL;
+ }
+ }
+
+ /*
+ * The running OS can modify the NVRAM as it pleases so we need to be
+ * a little paranoid and check that it's ok before we try parse it.
+ *
+ * NB: nvram_validate() can update skiboot_part_hdr
+ */
+ if (!nvram_validate())
+ return NULL;
+
+ assert(skiboot_part_hdr);
+
+ part_end = (const char *) skiboot_part_hdr
+ + be16_to_cpu(skiboot_part_hdr->len) * 16 - 1;
+
+ start = (const char *) skiboot_part_hdr
+ + sizeof(*skiboot_part_hdr);
+
+ if (!key_len) {
+ prlog(PR_WARNING, "NVRAM: search key is empty!\n");
+ return NULL;
+ }
+
+ if (key_len > 32)
+ prlog(PR_WARNING, "NVRAM: search key '%s' is longer than 32 chars\n", key);
+
+ while (start) {
+ int remaining = part_end - start;
+
+ prlog(PR_TRACE, "NVRAM: '%s' (%lu)\n",
+ start, strlen(start));
+
+ if (key_len + 1 > remaining)
+ return NULL;
+
+ if (!strncmp(key, start, key_len) && start[key_len] == '=') {
+ const char *value = &start[key_len + 1];
+
+ prlog(PR_DEBUG, "NVRAM: Searched for '%s' found '%s'\n",
+ key, value);
+
+ return value;
+ }
+
+ start = find_next_key(start, part_end);
+ }
+
+ prlog(PR_DEBUG, "NVRAM: '%s' not found\n", key);
+
+ return NULL;
+}
diff --git a/src/usr/nvram/makefile b/src/usr/nvram/makefile
new file mode 100644
index 000000000..672e85529
--- /dev/null
+++ b/src/usr/nvram/makefile
@@ -0,0 +1,37 @@
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: src/usr/nvram/makefile $
+#
+# 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
+ROOTPATH = ../../..
+
+MODULE = nvram
+
+EXTRAINCDIR += ${ROOTPATH}/src/include/usr
+EXTRAINCDIR += ${ROOTPATH}/src/include/usr/nvram/import
+
+OBJS += nvram_interface.o
+OBJS += nvram-format.o
+
+VPATH += import
+
+include ${ROOTPATH}/config.mk
diff --git a/src/usr/nvram/nvram_interface.C b/src/usr/nvram/nvram_interface.C
new file mode 100644
index 000000000..e4bb95796
--- /dev/null
+++ b/src/usr/nvram/nvram_interface.C
@@ -0,0 +1,119 @@
+/* IBM_PROLOG_BEGIN_TAG */
+/* This is an automatically generated prolog. */
+/* */
+/* $Source: src/usr/nvram/nvram_interface.C $ */
+/* */
+/* 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 */
+#include <nvram/nvram_interface.H>
+#include <nvram/import/nvram.h>
+#include <nvram/nvram_reasoncodes.H>
+#include <pnor/pnorif.H>
+
+static bool g_is_nvram_checked = false;
+
+namespace NVRAM_TRACE
+{
+ trace_desc_t * g_trac_nvram = nullptr;
+ // NVRAM won't be read too often in hostboot, so 1KB should be enough.
+ TRAC_INIT(&g_trac_nvram, NVRAM_COMP_NAME, KILOBYTE);
+}
+
+namespace NVRAM
+{
+
+/*
+ * @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
+ * it's formatted incorrectly.
+ */
+errlHndl_t nvramRead(const char* const i_key, const char*& o_val)
+{
+ errlHndl_t l_errl = nullptr;
+
+ do {
+
+ if(i_key == nullptr)
+ {
+ /*@ errorlog
+ * @errortype ERRL_SEV_UNRECOVERABLE
+ * @moduleid NVRAM::MOD_NVRAM_READ
+ * @reasoncode NVRAM::RC_NVRAM_READ_NULL_KEY
+ * @devdesc A nullptr was passed for i_key to nvramRead
+ * @custdesc Error occurred during system boot.
+ */
+ l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_UNRECOVERABLE,
+ NVRAM::MOD_NVRAM_READ,
+ NVRAM::RC_NVRAM_READ_NULL_KEY,
+ 0,
+ 0);
+ break;
+ }
+
+ if(!g_is_nvram_checked)
+ {
+ PNOR::SectionInfo_t l_nvramSectionInfo;
+ l_errl = PNOR::getSectionInfo(PNOR::NVRAM, l_nvramSectionInfo);
+ if(l_errl)
+ {
+ break;
+ }
+
+ // Skiboot function to check NVRAM for integrity.
+ // This function will also populate the inner skiboot_part_hdr
+ // pointer to point to the start of the NVRAM. nvram_query will
+ // then attempt to index into skiboot_part_hdr to find the K/V
+ // pairs.
+ int l_rc = nvram_check(
+ reinterpret_cast<uint8_t*>(l_nvramSectionInfo.vaddr),
+ l_nvramSectionInfo.size);
+ if(l_rc)
+ {
+ /*@ errorlog
+ * @errortype ERRL_SEV_INFORMATIONAL
+ * @moduleid NVRAM::MOD_NVRAM_READ
+ * @reasoncode NVRAM::RC_NVRAM_CHECK_FAILED
+ * @userdata1 rc from nvram_check
+ * @userdata2 NVRAM virtual address
+ * @devdesc nvram_check failed during an attempt to read the
+ * NVRAM PNOR partition.
+ * @custdesc Error occurred during system boot.
+ */
+ l_errl = new ERRORLOG::ErrlEntry(ERRORLOG::ERRL_SEV_INFORMATIONAL,
+ NVRAM::MOD_NVRAM_READ,
+ NVRAM::RC_NVRAM_CHECK_FAILED,
+ l_rc,
+ l_nvramSectionInfo.vaddr);
+ l_errl->collectTrace(NVRAM_COMP_NAME);
+ l_errl->collectTrace(PNOR_COMP_NAME);
+ break;
+ }
+
+ g_is_nvram_checked = true;
+ }
+
+ o_val = nvram_query(i_key);
+
+ }while(0);
+
+ return l_errl;
+}
+
+} // namespace NVRAM
diff --git a/src/usr/sbeio/common/sbe_attn.C b/src/usr/sbeio/common/sbe_attn.C
index fb146ed11..f09439344 100644
--- a/src/usr/sbeio/common/sbe_attn.C
+++ b/src/usr/sbeio/common/sbe_attn.C
@@ -199,4 +199,4 @@ namespace SBEIO
return l_err;
}
-}; \ No newline at end of file
+};
OpenPOWER on IntegriCloud