summaryrefslogtreecommitdiffstats
path: root/src/usr/sbe/sbe_resolve_sides.H
blob: 3400b6a1aa3691591416468263a9ea3e6a7142cf (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/sbe/sbe_resolve_sides.H $                             */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2016                        */
/* [+] 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 __SBE_SBE_RESOLVE_SIDES_H
#define __SBE_SBE_RESOLVE_SIDES_H


#include <stdint.h>
#include <builtins.h>
#include <errl/errlentry.H>
#include <pnor/pnorif.H>
#include <util/align.H>
#include <vmmconst.h>
#include <targeting/common/targetservice.H>
#include <i2c/eepromif.H>
#include "sbe_update.H"

namespace SBE
{
    /******************************************/
    /*  Constants                             */
    /******************************************/

    // This seeprom is a candidate to be READ_ONLY (ie, not updated)
    const sbeSeepromSide_t READ_ONLY_SEEPROM = SBE_SEEPROM1;

    // Used to keep SBE Seeproms in sync with EEPROM::eeprom_chip_types_t
    const EEPROM::eeprom_chip_types_t sbe_side_sync[2] =
                                      { EEPROM::SBE_PRIMARY,
                                        EEPROM::SBE_BACKUP };

    // @todo RTC 124679 - Remove Once BMC Monitors Shutdown Attention
    // Set Watchdog Timer To 15 seconds before calling doShutdown()
    const uint16_t SET_WD_TIMER_IN_SECS = 15;

    /******************************************/
    /*  Enums                                 */
    /******************************************/

    // Actions can be combined
    enum
    {
        NO_ACTIONS             = 0x00000000,
        REIPL                  = 0x00000001,

        // Use PNOR::ALTERNATE SideId for HBB Address info
        USE_PNOR_ALT_SIDE      = 0x00000002,

        // NOTE: These next 2 values are mutually exclusive
        CHECK_WORKING_HBB         = 0x00000010,
        COPY_READ_ONLY_TO_WORKING = 0x00000020,
    };

    /******************************************/
    /*  Structs                               */
    /******************************************/
    struct sbeResolveState_t
    {

        // Target Information
        TARGETING::Target*       tgt;

        sbeSeepromSide_t   cur_side;    // aka 'booted' side
        sbeSeepromSide_t   alt_side;    // non-booted/non-cur side
        sbeSeepromSide_t   update_side; // side to be updated

        // Info from PNOR
        PNOR::SideId pnor_sideId;
        char pnor_side;          /**< name of the side either A or B */
        bool pnor_isGolden;      /**< True if side is golden */
        bool pnor_hasOtherSide;  /**< True if a valid alternate side exists*/

        uint32_t actions;

        // Constructor to default certain values
        sbeResolveState_t() :
          tgt(NULL), cur_side(SBE_SEEPROM_INVALID),
          alt_side(SBE_SEEPROM_INVALID),
          update_side(SBE_SEEPROM_INVALID),
          pnor_sideId(PNOR::WORKING),
          pnor_side(NULL),
          pnor_isGolden(false), pnor_hasOtherSide(false),
          actions(NO_ACTIONS)
        {}

    };


    /******************************************/
    /*  Functions -- High Level Functions     */
    /******************************************/

    /**
     * @brief Collects SBE Side Information for a specifc target
     *
     * @param[io/out] io_sideState   Struct containing SBE State of the target
     *
     * @return errlHndl_t    Error log handle on failure.
     */
    errlHndl_t getSideState(sbeResolveState_t& io_sideState);

    /**
     * @brief Analyze and Determine Update Actions for a specific target
     *
     * @param[io/out] io_sideState   Struct containing SBE State of the target
     *
     * @return errlHndl_t    Error log handle on failure.
     */
    errlHndl_t getSideActions(sbeResolveState_t& io_sideState);

    /**
     * @brief Performs the Update Actions for a specific target
     *
     * @param[io/out] io_sideState   Struct containing SBE State of the target
     *
     * @return errlHndl_t    Error log handle on failure.
     */
    errlHndl_t performSideActions(sbeResolveState_t& io_sideState);



    /******************************************/
    /*  Functions -- System Access            */
    /******************************************/


    /**
     * @brief Read SBE Image from SBE Seeprom
     *
     * @param[in] i_target   Target processor
     *
     * @param[out] o_imgPtr    Pointer to SBE image in memory
     *                         Memory for this pointer is expected to be
     *                         pre-alloacted
     *                         NOTE:  ECC is handled internally in this
     *                         function. io_imgPtr points to non-ECC image
     *
     * @param[in] i_side          Seeprom Side to access
     *
     * @param[in] o_image_size    The size of the image (non-ECC)
     *                            NOTE: o_image_size will be 8 byte aligned.
     *
     * @param[in] o_version       SBE Version struct from seeprom (non-ECC)
     *
     * @return errlHndl_t    Error log handle on failure.
     */
    errlHndl_t readSbeImage(TARGETING::Target* i_target,
                              void* o_imgPtr,
                              sbeSeepromSide_t i_side,
                              size_t& o_image_size,
                              sbeSeepromVersionInfo_t& o_version);

    /**
     * @brief Write SBE Image from SBE Seeprom
     *
     * @param[in] i_target   Target processor
     *
     * @param[in] i_imgPtr    Pointer to SBE image in memory
     *                        Memory for this pointer is expected to be
     *                        pre-alloacted
     *                        NOTE:  ECC is handled internally in this function,
     *                        i_imgPtr points to non-ECC image
     *
     * @param[in] i_side        Seeprom Side to access
     *
     * @param[in] i_image_size  Size of image to write (non-ECC)
     *                          NOTE: must be 8 byte aligned
     *
     * @param[in] io_version    SBE Version struct to write (non-ECC)
     *                          NOTE: data_crc updated in this function
     *
     * @return errlHndl_t    Error log handle on failure.
     */
    errlHndl_t writeSbeImage(TARGETING::Target* i_target,
                             void* i_imgPtr,
                             sbeSeepromSide_t i_side,
                             size_t i_image_size,
                             sbeSeepromVersionInfo_t& io_version);

    /**
     * @brief Read SBE Image Header from SBE Seeprom and gets the
     *        Image size from the heaser
     *
     * @param[in] i_target   Target processor
     *
     * @param[in] i_imgPtr     Pointer to pre-allocated memory to be used
     *                         for different operations
     *
     * @param[in] i_side          Seeprom Side to access
     *
     * @param[in] o_image_size    The size of the image (non-ECC)
     *
     * @return errlHndl_t    Error log handle on failure.
     */
    errlHndl_t getSbeImageSize(TARGETING::Target* i_target,
                               void* i_imgPtr,
                               sbeSeepromSide_t i_side,
                               size_t& o_image_size);




    /******************************************/
    /*  Functions -- Helper Functions         */
    /******************************************/

#ifdef CONFIG_BMC_IPMI
    /**
     * @brief Performs any necessary IPMI calls before reboot the system
     *
     * @return errlHndl_t    Error log handle on failure.
     */
    errlHndl_t sbePreRebootIpmiCalls( void );
#endif

} //end namespace SBE
#endif
OpenPOWER on IntegriCloud