Skip to content

Commit d64618b

Browse files
Stephen CprekNick Bofferding
Stephen Cprek
authored and
Nick Bofferding
committed
Add SecureROM version info and Change SBE update to use max HBBL size
The HBBL also contains the securerom code and hw keys' hash for verification purposes. So looking for the end of the HBBL code leaves out those sections Change-Id: I73a1b5c50e3a5b3f642ca569b90e79dbe4c4ba1e Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/35979 Tested-by: Jenkins Server <[email protected]> Tested-by: FSP CI Jenkins <[email protected]> Tested-by: Jenkins OP Build CI <[email protected]> Reviewed-by: Martin Gloff <[email protected]> Reviewed-by: Nicholas E. Bofferding <[email protected]> Reviewed-by: Daniel M. Crowell <[email protected]>
1 parent 8091b11 commit d64618b

File tree

20 files changed

+240
-285
lines changed

20 files changed

+240
-285
lines changed

src/bootloader/bl_start.S

-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
.set SBE_HB_PNORSIZEMB, sbe_hb_structures+6 ;// uint16_t
3232
.set SBE_HB_BLLOADSIZE, sbe_hb_structures+8 ;// uint64_t
3333
.set HBBL_BASE_ADDRESS, base_load_address
34-
.set HBBL_END_EYECATCHER, 0x4842424C656E6400 ;// 'HBBLend.'
3534
.set HBBL_END_ADDRESS, end_load_address
3635
.set HBBL_system_reset, 0x100
3736
.set HBBL_machine_check, 0x200
@@ -423,11 +422,6 @@ bootloader_hbbSection:
423422
hbi_ImageId:
424423
.space 128
425424

426-
.balign 16
427-
.global bootloader_end_eyecatcher
428-
bootloader_end_eyecatcher:
429-
.quad HBBL_END_EYECATCHER
430-
431425
.global bootloader_end_address
432426
bootloader_end_address:
433427
.quad HBBL_END_ADDRESS

src/bootloader/bootloader.C

+48-29
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ namespace Bootloader{
6969
sizeof(sha2_hash_t));
7070
}
7171

72-
// @TODO RTC:167740 remove magic number check once fsp/op signs HBB
7372
/**
7473
* @brief Memcmp a vaddr to the known secureboot magic number
7574
*
@@ -97,24 +96,48 @@ namespace Bootloader{
9796
const sha2_hash_t* i_hwKeyHash)
9897
{
9998
#ifdef CONFIG_SECUREBOOT
100-
// @TODO RTC:167740 remove magic number check once fsp/op signs HBB
101-
if (cmpSecurebootMagicNumber(reinterpret_cast<const uint8_t*>
102-
(i_pContainer)))
99+
BOOTLOADER_TRACE(BTLDR_TRC_MAIN_VERIFY_START);
100+
101+
uint64_t l_rc = 0;
102+
103+
// @TODO RTC:166848 Move find/get secure rom logic out of ROM verify
104+
// Find secure ROM addr
105+
// Get starting address of ROM size and code which is the next 8 byte
106+
// aligned address after the bootloader end.
107+
// [hbbl][pad:8:if-applicable][securerom-size:8][securerom]
108+
const void* l_pBootloaderEnd = &bootloader_end_address;
109+
uint64_t l_bootloaderSize = 0;
110+
memcpy (&l_bootloaderSize, l_pBootloaderEnd, sizeof(l_bootloaderSize));
111+
uint64_t l_rom_startAddr = getHRMOR() + ALIGN_8(l_bootloaderSize);
112+
// Get Rom Size
113+
// @TODO RTC:166848 Store size so hb can use
114+
uint64_t l_secureRomSize = 0;
115+
memcpy (&l_secureRomSize, reinterpret_cast<void*>(l_rom_startAddr),
116+
sizeof(l_secureRomSize));
117+
l_rom_startAddr += sizeof(l_secureRomSize);
118+
119+
// Beginning of SecureROM has a info structure
120+
// Get Secure ROM info
121+
const auto l_pSecRomInfo = reinterpret_cast<SecureRomInfo*>(
122+
l_rom_startAddr);
123+
124+
// # @TODO RTC:170136 terminate in this case
125+
// Ensure SecureRom is actually present
126+
if ( !secureRomInfoValid(l_pSecRomInfo) )
127+
{
128+
BOOTLOADER_TRACE(BTLDR_TRC_MAIN_VERIFY_NO_EYECATCH);
129+
}
130+
// # @TODO RTC:170136 terminate in this case
131+
else if ( !cmpSecurebootMagicNumber(reinterpret_cast<const uint8_t*>
132+
(i_pContainer)))
133+
{
134+
BOOTLOADER_TRACE(BTLDR_TRC_MAIN_VERIFY_NO_MAGIC_NUM);
135+
}
136+
else
103137
{
104-
BOOTLOADER_TRACE(BTLDR_TRC_MAIN_VERIFY_HBB_START);
105-
106-
uint64_t l_rc = 0;
107-
108-
const void * l_pBootloaderEnd = &bootloader_end_address;
109-
110-
// Get starting address of ROM code which is the next 8 byte aligned
111-
// address after the bootloader end.
112-
uint64_t l_size = 0;
113-
memcpy (&l_size, l_pBootloaderEnd, sizeof(l_size));
114-
uint64_t l_rom_startAddr = getHRMOR() + ALIGN_8(l_size);
115-
116138
// Set startAddr to ROM_verify() function at an offset of Secure ROM
117139
uint64_t l_rom_verify_startAddr = l_rom_startAddr
140+
+ l_pSecRomInfo->branchtableOffset
118141
+ ROM_VERIFY_FUNCTION_OFFSET;
119142

120143
// Declare local input struct
@@ -128,18 +151,17 @@ namespace Bootloader{
128151
// Use current hw hash key
129152
memcpy (&l_hw_parms.hw_key_hash, i_hwKeyHash, sizeof(sha2_hash_t));
130153

131-
const ROM_container_raw* l_container =
132-
reinterpret_cast<const ROM_container_raw*>(i_pContainer);
154+
const auto l_container = reinterpret_cast<const ROM_container_raw*>
155+
(i_pContainer);
133156

134157
l_rc = call_rom_verify(reinterpret_cast<void*>
135158
(l_rom_verify_startAddr),
136159
l_container,
137160
&l_hw_parms);
138-
139161
if (l_rc != 0)
140162
{
141163
// Verification of Container failed.
142-
BOOTLOADER_TRACE(BTLDR_TRC_MAIN_VERIFY_HBB_FAIL);
164+
BOOTLOADER_TRACE(BTLDR_TRC_MAIN_VERIFY_FAIL);
143165
/*@
144166
* @errortype
145167
* @moduleid MOD_BOOTLOADER_VERIFY
@@ -156,11 +178,7 @@ namespace Bootloader{
156178

157179
}
158180

159-
BOOTLOADER_TRACE(BTLDR_TRC_MAIN_VERIFY_HBB_SUCCESS);
160-
}
161-
else
162-
{
163-
BOOTLOADER_TRACE(BTLDR_TRC_MAIN_VERIFY_HBB_SKIP);
181+
BOOTLOADER_TRACE(BTLDR_TRC_MAIN_VERIFY_SUCCESS);
164182
}
165183
#endif
166184
}
@@ -260,10 +278,11 @@ namespace Bootloader{
260278
verifyContainer(l_src_addr, &l_hwKeyHash);
261279

262280
// Increment past secure header
263-
#ifdef CONFIG_SECUREBOOT
264-
l_src_addr += PAGE_SIZE/sizeof(uint64_t);
265-
l_hbbLength -= PAGE_SIZE;
266-
#endif
281+
if (isSecureSection(PNOR::HB_BASE_CODE))
282+
{
283+
l_src_addr += PAGE_SIZE/sizeof(uint64_t);
284+
l_hbbLength -= PAGE_SIZE;
285+
}
267286

268287
// Copy HBB image into address where it executes
269288
for(uint32_t i = 0;

src/bootloader/makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66
# OpenPOWER HostBoot Project
77
#
8-
# Contributors Listed Below - COPYRIGHT 2015,2016
8+
# Contributors Listed Below - COPYRIGHT 2015,2017
99
# [+] International Business Machines Corp.
1010
#
1111
#
@@ -30,6 +30,8 @@ EXTRAINCDIR += ${ROOTPATH}/src/include/usr/
3030
EXTRAINCDIR += ${ROOTPATH}/src/include/usr/pnor/
3131
EXTRAINCDIR += ${ROOTPATH}/src/include/usr/lpc/
3232

33+
COMMONFLAGS += -DBOOTLOADER
34+
3335
OBJS += bl_start.o
3436
OBJS += bootloader.o
3537
OBJS += bl_pnorAccess.o

src/build/debug/Hostboot/BlTrace.pm

+5-4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ my %traceText = (
3434
"11" => "Main getHBBSection returned",
3535
"12" => "Main handleMMIO to working location returned",
3636
"13" => "Main removeECC returned",
37+
"14" => "Main verify started",
38+
"15" => "Main verify succeeded",
39+
"16" => "Main copy HBB to running location done",
40+
"17" => "Main verify skip verification - no eyecatch ",
3741
# @TODO RTC:167740 remove magic number check once fsp/op signs HBB
38-
"14" => "main verifyBaseImage skip verification - no magic number ",
39-
"15" => "main verifyBaseImage started",
40-
"16" => "main verifyBaseImage succeeded",
41-
"17" => "Main copy HBB to running location done",
42+
"18" => "Main verify skip verification - no magic number ",
4243
"20" => "HandleMMIO started",
4344
"21" => "HandleMMIO started using BYTESIZE",
4445
"24" => "HandleMMIO started using WORDSIZE",

src/build/mkrules/hbfw/img/makefile

+6-4
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ FINAL_OUTPUT_IMAGES = ${HBBL_FINAL_IMG} ${HBB_FINAL_IMG} ${HBI_FINAL_IMG} \
9595
${PAYLOAD_FINAL_IMG} ${RINGOVD_FINAL_IMG} ${SBKT_FINAL_IMG} \
9696
${WOFDATA_FINAL_IMG}
9797

98-
# Temp images
99-
HB_TEMP_IMG = hb_temp.bin
100-
10198
# Aggregate
10299
ALL_DEFAULT_IMAGES = ${DEFAULT_INPUT_IMAGES} ${FINAL_OUTPUT_IMAGES}
103100

@@ -138,10 +135,15 @@ gen_default_images: cp_hbfiles
138135
# Remove offset from start of Bootloader image for HBBL partition
139136
# Actual code is offset from HRMOR by 12k = 12 1k-blocks (space
140137
# reserved for exception vectors)
138+
# Note: ibs=8 conv=sync to ensure this ends at an 8byte boundary for the
139+
# securerom code to start at.
141140
dd if=${BOOTLDR_IMG} of=${HBBL_IMG} ibs=8 skip=1536 conv=sync
142141

143-
# Append Hostboot securerom code to the HBBL section
142+
# Append Hostboot securerom code size to HBBL
143+
du -b ${HB_SECROM_IMG} | cut -f1 | xargs printf "%016x" | sed 's/.\{2\}/\\\\x&/g' | xargs echo -n -e >> ${HBBL_IMG}
144+
# Append Hostboot securerom code after its size
144145
cat ${HB_SECROM_IMG} >> ${HBBL_IMG}
146+
# result [hbbl][pad:8:if-applicable][securerom-size:8][securerom]
145147

146148
# Call script to generate final bin files for default images
147149
${GEN_PNOR_IMAGE_SCRIPT} ${DEFAULT_PARAMS}

src/include/array

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/* */
66
/* OpenPOWER HostBoot Project */
77
/* */
8-
/* Contributors Listed Below - COPYRIGHT 2016 */
8+
/* Contributors Listed Below - COPYRIGHT 2016,2017 */
99
/* [+] International Business Machines Corp. */
1010
/* */
1111
/* */
@@ -36,6 +36,7 @@
3636
#define __STDC_LIMIT_MACROS
3737
#endif
3838
#include <stdint.h>
39+
#include <algorithm>
3940

4041
namespace std
4142
{

src/include/bootloader/bootloader.H

+2-5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <common/ffs_hb.H>
3939
#include <kernel/terminate.H>
4040
#include <kernel/hbterminatetypes.H>
41+
#include <bootloader/bootloaderif.H>
4142

4243
extern "C" void task_end_stub();
4344
extern "C" void enterHBB(uint64_t i_hbb_hrmor, uint64_t i_hbb_offset);
@@ -166,15 +167,11 @@ namespace Bootloader{
166167
* HBB is copied to its running location and its execution is started.
167168
*/
168169

169-
/** Max size of HBBL without ECC. Must match PNOR layout for eyeCatch HBBL*/
170-
#define MAX_HBBL_SIZE (20 * KILOBYTE)
171-
/** Size of exception vector reserved space at start of the HBBL section*/
172-
#define HBBL_EXCEPTION_VECTOR_SIZE (12 * KILOBYTE)
173170
/** HW Keys hash is placed in the last 64 bytes of the HBBL */
174171
#define HW_KEYS_HASH_ADDR (getHRMOR() + HBBL_EXCEPTION_VECTOR_SIZE \
175172
+ MAX_HBBL_SIZE - 64)
176173
/** Location of working copy of HBB with ECC */
177-
#define HBB_ECC_WORKING_ADDR (getHRMOR() - ( 1*MEGABYTE))
174+
#define HBB_ECC_WORKING_ADDR (getHRMOR() + ( 1*MEGABYTE))
178175

179176
/** Location of working copy of HBB without ECC */
180177
#define HBB_WORKING_ADDR (getHRMOR() - ( 1*MEGABYTE))

src/include/bootloader/bootloader_trace.H

+14-11
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,21 @@ enum BootloaderTraces
6060
/** Bootloader main removeECC returned */
6161
BTLDR_TRC_MAIN_REMOVEECC_RTN = 0x13,
6262

63-
// @TODO RTC:167740 remove magic number check once fsp/op signs HBB
64-
/** Bootloader main verifyBaseImage skip verification - no magic number */
65-
BTLDR_TRC_MAIN_VERIFY_HBB_SKIP = 0x14,
66-
67-
/** Bootloader main verifyBaseImage started */
68-
BTLDR_TRC_MAIN_VERIFY_HBB_START = 0x15,
63+
/** Bootloader main verifyContainer started */
64+
BTLDR_TRC_MAIN_VERIFY_START = 0x14,
6965

70-
/** Bootloader main verifyBaseImage succeeded */
71-
BTLDR_TRC_MAIN_VERIFY_HBB_SUCCESS = 0x16,
66+
/** Bootloader main verifyContainer succeeded */
67+
BTLDR_TRC_MAIN_VERIFY_SUCCESS = 0x15,
7268

7369
/** Bootloader main copy HBB to running location done */
74-
BTLDR_TRC_MAIN_COPY_HBB_DONE = 0x17,
70+
BTLDR_TRC_MAIN_COPY_HBB_DONE = 0x16,
71+
72+
/** Bootloader main verifyContainer skip verification - no eyecatch */
73+
BTLDR_TRC_MAIN_VERIFY_NO_EYECATCH = 0x17,
74+
75+
// @TODO RTC:167740 remove magic number check once fsp/op signs HBB
76+
/** Bootloader main verifyContainer skip verification - no magic number */
77+
BTLDR_TRC_MAIN_VERIFY_NO_MAGIC_NUM = 0x18,
7578

7679
/** Bootloader handleMMIO started */
7780
BTLDR_TRC_HANDLEMMIO_START = 0x20,
@@ -169,8 +172,8 @@ enum BootloaderTraces
169172
/** Bootloader PNOR Access getHBBSection findTOC no HBB section */
170173
BTLDR_TRC_PA_GETHBBSECTION_FINDTOC_NOHBB = 0xFA,
171174

172-
/** Bootloader main verifyBaseImage failed */
173-
BTLDR_TRC_MAIN_VERIFY_HBB_FAIL = 0xFB,
175+
/** Bootloader main verifyContainer failed */
176+
BTLDR_TRC_MAIN_VERIFY_FAIL = 0xFB,
174177
};
175178

176179
#ifndef BOOTLOADER_TRACE

src/include/bootloader/bootloaderif.H

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* IBM_PROLOG_BEGIN_TAG */
2+
/* This is an automatically generated prolog. */
3+
/* */
4+
/* $Source: src/include/bootloader/bootloaderif.H $ */
5+
/* */
6+
/* OpenPOWER HostBoot Project */
7+
/* */
8+
/* Contributors Listed Below - COPYRIGHT 2017 */
9+
/* [+] International Business Machines Corp. */
10+
/* */
11+
/* */
12+
/* Licensed under the Apache License, Version 2.0 (the "License"); */
13+
/* you may not use this file except in compliance with the License. */
14+
/* You may obtain a copy of the License at */
15+
/* */
16+
/* http://www.apache.org/licenses/LICENSE-2.0 */
17+
/* */
18+
/* Unless required by applicable law or agreed to in writing, software */
19+
/* distributed under the License is distributed on an "AS IS" BASIS, */
20+
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
21+
/* implied. See the License for the specific language governing */
22+
/* permissions and limitations under the License. */
23+
/* */
24+
/* IBM_PROLOG_END_TAG */
25+
#ifndef __BOOT_LOADERIF_H
26+
#define __BOOT_LOADERIF_H
27+
28+
// Max size of HBBL without ECC. Must match PNOR layout for eyeCatch HBBL
29+
// Must be aligned CACHELINE_SIZE of 128 bytes
30+
#define MAX_HBBL_SIZE (20 * KILOBYTE)
31+
32+
// Size of exception vector reserved space at start of the HBBL section
33+
#define HBBL_EXCEPTION_VECTOR_SIZE (12 * KILOBYTE)
34+
35+
#endif

0 commit comments

Comments
 (0)