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
|
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/bootloader/bl_pnorAccess.C $ */
/* */
/* 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 */
#include <bootloader/bl_pnorAccess.H>
#include <bootloader/bootloader_trace.H>
#include <util/singleton.H>
#include <bootloader/bootloader.H>
#ifdef PNORUTILSTEST_H
#define BOOTLOADER_TRACE(args) TRACFCOMP(g_trac_pnor,"##args")
#define BOOTLOADER_TRACE_W_BRK(args) TRACFCOMP(g_trac_pnor,"##args")
#endif
extern const char* cv_EYECATCHER[];
/**
* @brief Takes in a buffer containing a ToC, as well as a base address
Returns out a boolean whether or not this toc was valid
also returns a SectionData_t struct if the toc was valid
*/
void bl_pnorAccess::readTOC(uint8_t i_tocBuffer[PNOR::TOC_SIZE],
uint32_t& o_errCode,
PNOR::SectionData_t * o_TOC,
uint64_t& o_pnorStart,
uint64_t i_pnorEnd)
{
do
{
o_errCode = PNOR::NO_ERROR;
ffs_hdr* l_ffs_hdr = NULL;
//zero out the section data for each section
PNOR::initializeSections(o_TOC);
BOOTLOADER_TRACE(BTLDR_TRC_PA_READTOC_ZEROSECTION_RTN);
//make sure that the buffer is not null
PNOR::checkForNullBuffer(i_tocBuffer, o_errCode, l_ffs_hdr);
//Subtract the size of the pnor from the end address to find the start
o_pnorStart = i_pnorEnd -
(l_ffs_hdr->block_size * l_ffs_hdr->block_count) + 1;
if(o_errCode != PNOR::NO_ERROR)
{
BOOTLOADER_TRACE_W_BRK(BTLDR_TRC_PA_READTOC_CHKNULLBUFFER_NULL);
break;
}
BOOTLOADER_TRACE(BTLDR_TRC_PA_READTOC_CHECKNULLBUFFER_RTN);
//Do a checksum on the header
if(PNOR::pnor_ffs_checksum(l_ffs_hdr, FFS_HDR_SIZE) != 0)
{
o_errCode |= PNOR::CHECKSUM_ERR;
}
if(o_errCode != PNOR::NO_ERROR)
{
BOOTLOADER_TRACE_W_BRK(BTLDR_TRC_PA_READTOC_HDRCHECKSUM_ERR);
break;
}
BOOTLOADER_TRACE(BTLDR_TRC_PA_READTOC_HDRCHECKSUM_RTN);
//Check out the header to make sure its all valid
PNOR::checkHeader(l_ffs_hdr, o_errCode);
if(o_errCode != PNOR::NO_ERROR)
{
BOOTLOADER_TRACE_W_BRK(BTLDR_TRC_PA_READTOC_CHECKHEADER_ERR);
break;
}
BOOTLOADER_TRACE(BTLDR_TRC_PA_READTOC_CHECKHEADER_RTN);
//if an error is found with an entry we use this variable to hold
//the value of the entry. That way we can record which entry is causing
//an issue.
ffs_entry* l_err_entry = NULL;
//parse through the entries and check for any errors
PNOR::parseEntries(l_ffs_hdr, o_errCode, o_TOC, l_err_entry);
if(o_errCode != PNOR::NO_ERROR)
{
BOOTLOADER_TRACE_W_BRK(BTLDR_TRC_PA_READTOC_PARSEENTRIES_ERR);
break;
}
BOOTLOADER_TRACE(BTLDR_TRC_PA_READTOC_PARSEENTRIES_RTN);
} while(0);
}
void bl_pnorAccess::findTOC(uint64_t i_pnorEnd, PNOR::SectionData_t * o_TOC,
uint32_t& o_errCode, uint8_t& o_tocUsed,
uint64_t& o_pnorStart)
{
uint8_t *l_tocBuffer = Bootloader::g_blScratchSpace;
do
{
//@TODO RTC:138268 Set up multiple side of PNOR for bootloader
o_errCode = 0;
o_tocUsed = 0;
//Copy Table of Contents from PNOR flash to a local buffer
//The first TOC is 2 TOC sizes back from the end of the flash (+ 1)
Bootloader::handleMMIO(i_pnorEnd - PNOR::TOC_OFFSET_FROM_TOP_OF_FLASH,
reinterpret_cast<uint64_t>(l_tocBuffer),
(PNOR::TOC_SIZE),
Bootloader::WORDSIZE);
BOOTLOADER_TRACE(BTLDR_TRC_PA_FINDTOC_TOC1_HANDLEMMIO_RTN);
readTOC(l_tocBuffer, o_errCode, o_TOC, o_pnorStart, i_pnorEnd);
if(o_errCode == PNOR::NO_ERROR)
{
BOOTLOADER_TRACE(BTLDR_TRC_PA_FINDTOC_TOC1_READTOC_RTN);
o_tocUsed = 0;
break;
}
else
{
//If the first toc was invalid, look for the backup in the start
Bootloader::handleMMIO(o_pnorStart,
reinterpret_cast<uint64_t>(l_tocBuffer),
(PNOR::TOC_SIZE),
Bootloader::WORDSIZE);
o_errCode = 0;
readTOC(l_tocBuffer, o_errCode, o_TOC, o_pnorStart, i_pnorEnd);
if(o_errCode == PNOR::NO_ERROR)
{
o_tocUsed = 1;
break;
}
BOOTLOADER_TRACE_W_BRK(BTLDR_TRC_PA_FINDTOC_READTOC_ERR);
}
break;
}while(0);
}
/**
* @brief Get the hostboot base image
*/
void bl_pnorAccess::getHBBSection(uint64_t i_pnorEnd,
PNOR::SectionData_t& o_hbbSection,
uint32_t& o_errCode,
uint8_t& o_tocUsed,
uint64_t& o_pnorStart)
{
BOOTLOADER_TRACE(BTLDR_TRC_PA_GETHBBSECTION_START);
do
{
PNOR::SectionData_t l_TOC[PNOR::NUM_SECTIONS];
findTOC(i_pnorEnd, l_TOC, o_errCode, o_tocUsed, o_pnorStart);
if(o_errCode != PNOR::NO_ERROR)
{
BOOTLOADER_TRACE_W_BRK(BTLDR_TRC_PA_GETHBBSECTION_FINDTOC_ERR);
break;
}
o_hbbSection = l_TOC[PNOR::HB_BASE_CODE];
if(o_hbbSection.flashAddr == PNOR::INVALID_FLASH_OFFSET)
{
o_errCode = PNOR::NO_HBB_SECTION;
BOOTLOADER_TRACE_W_BRK(BTLDR_TRC_PA_GETHBBSECTION_FINDTOC_NOHBB);
break;
}
} while(0);
BOOTLOADER_TRACE(BTLDR_TRC_PA_GETHBBSECTION_FINDTOC_RTN);
}
|