summaryrefslogtreecommitdiffstats
path: root/src/usr/nvram/nvram_interface.C
blob: 0c20498269416b7381fe74cd5f6153d246e1d7a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* 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
{

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
 *        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
OpenPOWER on IntegriCloud