From b742fd9b5b3c07129abfa3c099655346f6b1e6a6 Mon Sep 17 00:00:00 2001 From: Marty Gloff Date: Thu, 17 Dec 2015 10:10:47 -0600 Subject: Hostboot Bootloader Infrastructure New and changed code to provide bootloader infrastructure. Changes to build bootloader and create the image file. Change-Id: Ie400f0ca6954b86e275fd68c9462f8d18eeec98a RTC:127211 Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/22856 Tested-by: Jenkins Server Reviewed-by: Daniel M. Crowell --- src/bootloader.ld | 92 +++++++++++++++ src/bootloader/bl_builtins.C | 34 ++++++ src/bootloader/bl_pnor_ecc.C | 37 ++++++ src/bootloader/bl_start.S | 182 +++++++++++++++++++++++++++++ src/bootloader/bootloader.C | 84 ++++++++++++++ src/bootloader/makefile | 33 ++++++ src/build/mkrules/dist.targets.mk | 3 +- src/build/mkrules/hbfw/img/makefile | 9 +- src/build/mkrules/images.rules.mk | 7 +- src/build/tools/addimgid | 8 +- src/include/bootloader/bootloader.H | 93 +++++++++++++++ src/include/bootloader/bootloader_trace.H | 183 ++++++++++++++++++++++++++++++ src/libc++/builtins.C | 7 +- src/makefile | 17 +++ src/usr/pnor/ecc.C | 8 +- 15 files changed, 785 insertions(+), 12 deletions(-) create mode 100644 src/bootloader.ld create mode 100644 src/bootloader/bl_builtins.C create mode 100644 src/bootloader/bl_pnor_ecc.C create mode 100644 src/bootloader/bl_start.S create mode 100644 src/bootloader/bootloader.C create mode 100644 src/bootloader/makefile create mode 100644 src/include/bootloader/bootloader.H create mode 100644 src/include/bootloader/bootloader_trace.H (limited to 'src') diff --git a/src/bootloader.ld b/src/bootloader.ld new file mode 100644 index 000000000..0e2feae9f --- /dev/null +++ b/src/bootloader.ld @@ -0,0 +1,92 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/bootloader.ld $ */ +/* */ +/* OpenPOWER HostBoot Project */ +/* */ +/* Contributors Listed Below - COPYRIGHT 2015,2016 */ +/* [+] Google Inc. */ +/* [+] 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 */ +base_load_address = 0x00000000; +text_load_address = 0x00000020; + +SECTIONS +{ + . = base_load_address; + + . = text_load_address; + .text ALIGN(0x0020): { + *(.text.intvects) + *(.text.bootloaderasm) + *(.text) + *(.text._*) + *(.text.*) + } + + .rodata ALIGN(0x8): { + __minimum_data_start_addr = ALIGN(0x1000); + ctor_start_address = .; + *(.ctors) + *(.ctors.*) + ctor_end_address = .; + *(.rodata) + *(.rodata.*) + . = ALIGN(8); + toc_load_address = .; + *(.toc) + *(.opd) + *(.got) + *(.plt) + *(.data.rel.ro.*) + *(.data.*traceData_codeInfo*) + + . = __minimum_data_start_addr > . ? __minimum_data_start_addr : .; + } + + .data ALIGN(0x8): { + data_load_address = .; + *(.data) + *(.data.*) + + *(.bss) + *(.bss.*) + + } + + end_load_address = .; + + .rela : { + *(.rela.*) + } + + .dynsym : { *(.dynsym) } + .dynstr : { *(.dynstr) } + .hash : { *(.hash) } + .gnu.hash : { *(.gnu.hash) } + .eh_frame : { *(.eh_frame) } + + /DISCARD/ : { + *(.comment) + *(.gnu.attributes) + *(.dtors) + *(.interp) + } +} + + diff --git a/src/bootloader/bl_builtins.C b/src/bootloader/bl_builtins.C new file mode 100644 index 000000000..2e89c55b7 --- /dev/null +++ b/src/bootloader/bl_builtins.C @@ -0,0 +1,34 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/bootloader/bl_builtins.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 + +#define bl_builtins_C + +#include + +#include <../libc++/builtins.C> + +#undef bl_builtins_C + diff --git a/src/bootloader/bl_pnor_ecc.C b/src/bootloader/bl_pnor_ecc.C new file mode 100644 index 000000000..df7e9d6ee --- /dev/null +++ b/src/bootloader/bl_pnor_ecc.C @@ -0,0 +1,37 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/bootloader/bl_pnor_ecc.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 + +#define bl_pnor_ecc_C + +#include +#include + +#include + +#include <../usr/pnor/ecc.C> + +#undef bl_pnor_ecc_C + diff --git a/src/bootloader/bl_start.S b/src/bootloader/bl_start.S new file mode 100644 index 000000000..9f190b11f --- /dev/null +++ b/src/bootloader/bl_start.S @@ -0,0 +1,182 @@ +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/bootloader/bl_start.S $ +# +# 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 "kernel/ppcconsts.S" + +.section .text.bootloaderasm + +.global _start +_start: + ;// Set thread priority high. + or 2,2,2 + + ;// Clear MSR[TA] (bit 1) and enable MSR[ME] (bit 51). + mfmsr r2 + rldicl r2,r2,1,1 ;// Clear bit 1 - result [1-63,0] + rotrdi r2,r2,1 ;// Rotate right 1 - result [0,63] + ori r2,r2,4096 ;// Set bit 51 + ;// Set up SRR0 / SRR1 to enable new MSR. + mtsrr1 r2 + li r2, _start_postmsr@l + mtsrr0 r2 + b _start_postmsr + +_start_postmsr: + + ;// Determine if this is the first thread. + li r4, 2 + ;// Read spinlock value. + lis r2, kernel_other_thread_spinlock@h + ori r2, r2, kernel_other_thread_spinlock@l + lwsync +1: + ldarx r3, 0, r2 + cmpwi r3, 0 ;// Non-zero means this thread wasn't first. + bnel cr0, _other_thread_error ;// Handle having multiple threads started + stdcx. r4, 0, r2 ;// Attempt to store 2. + bne 1b ;// Loop until sucessful at stwcx. + isync + + b _main + + +/* @TODO RTC:133821 might not be needed + ;// Relocate code + bl pre_relocate ;// fill LR with address +pre_relocate: + mflr r2 + lis r1,0x0010 + cmpl cr0,r2,r1 ;// Check LR is less than 1MB + blt finished_relocate ;// No need to relocate if less than 1MB + + ;// Get addresses for relocation. + ;// Write address in r5 + ;// Read address in r1 + li r5,0 + lis r1, -1 ;// fill r1 with ffff..ff0000 + + and r1,r1,r2 ;// and with pre_relocate's address from r2 to get start of + ;// rom section. + + ;// Update LR to low address. + clrldi r2,r2,48 ;// Equiv to ~(0x0FFFF) + mtlr 2 + + ;// Moving 1MB , so load r2 with (1MB / 8 bytes per word) + lis r2, 0x2 + mtctr r2 +relocate_loop: + ;// The dcbst/sync/icbi/isync sequence comes from PowerISA + ld r4, 0(r1) + std r4, 0(r5) + dcbst 0,r5 + sync + icbi 0,r5 + isync + addi r1,r1,8 + addi r5,r5,8 + bdnz+ relocate_loop + + ;// Now that we've relocated, erase exception prefix. + mfmsr r11 + + rldicl r11,r11,57,1 ;// Erase bit 6 ( equiv to r11 & ~(0x40)) + rotldi r11,r11,7 + + mtmsr r11 + + ;// Jump to low address. + blr + +finished_relocate: + ;// Jump to main. + b _main +@TODO RTC:133821 might not be needed */ + + +;// _main: +;// Set up stack and TOC and call kernel's main. +_main: + ;// Set up initial TOC Base + lis r2, main@h + ori r2, r2, main@l + ld r2,8(r2) + + ;// Set up initial stack, space for 8 double-words + lis r1, kernel_stack@h + ori r1, r1, kernel_stack@l + addi r1, r1, 16320 + + ;// Call main. + bl main +_main_loop: + b _main_loop + + +;// @fn _other_thread_error: +;// Used for threads other than first to handle this unexpected condition. +_other_thread_error: + ;// Read spinlock value. + lis r2, kernel_other_thread_spinlock@h + ori r2, r2, kernel_other_thread_spinlock@l +1: + ld r3, 0(r2) + ;// Loop until value is 1... + cmpi cr0, r3, 1 + beq task_end_stub ;// End the multiple threads + or 1,1,1 ;// Lower thread priority. + b 1b + + + ;// @fn task_end_stub + ;// Stub to call a TASK_END syscall in the event that a task 'returns' from + ;// its entry point. We cannot call task_end() directly because profiling + ;// inserts garbage code into the task_end C function. +.global task_end_stub +task_end_stub: + mr r4, r3 ;// Move current rc (r3) to status value (r4) + li r3, 2 ;// TASK_END -> r3 (syscall number) + sc + + +.section .data + + .balign 1024 +kernel_stack: + .space 4*1024 + + .balign 8 +.global data_sandbox +data_sandbox: + .space 64 + +.global kernel_other_thread_spinlock +kernel_other_thread_spinlock: + .space 8 + +.global g_blScratchSpace +g_blScratchSpace: + .space 8 + diff --git a/src/bootloader/bootloader.C b/src/bootloader/bootloader.C new file mode 100644 index 000000000..462217d76 --- /dev/null +++ b/src/bootloader/bootloader.C @@ -0,0 +1,84 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/bootloader/bootloader.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 +#include +#include +#include + +#include // @TODO RTC:133821 might not be needed long-term + +#include + +#include + +extern uint64_t kernel_other_thread_spinlock; +extern uint32_t data_sandbox[16]; // @TODO RTC:133821 temporary bringup + +namespace Bootloader{ + extern "C" + int main() + { + // cppBootstrap(); @TODO RTC:133821 might not be needed long-term + // cv_blScratchSpace = ??? @TODO RTC:133821 + + // @TODO RTC:134064 Get location of HB base code in PNOR from TOC + + // @TODO RTC:133821 Copy HB base code from PNOR to 0x200000 + + // Remove ECC from HB base code at 0x200000 and store result at 0x300000 + PNOR::ECC::eccStatus rc = PNOR::ECC::CLEAN; +// PNOR::ECC::removeECC(reinterpret_cast(0x200000), +// reinterpret_cast(0x300000), +// 0x100000); // @TODO RTC:133821 determine size + + if (rc != PNOR::ECC::UNCORRECTABLE) + { +// memcpy(reinterpret_cast(0x300000), +// reinterpret_cast(0), +// 0x100000); // @TODO RTC:133821 determine size // replace with asm cache inhibited instructions + } + + // Ready to let the other CPUs go. @TODO RTC:133821 actually need to start relocated HB base code + lwsync(); + kernel_other_thread_spinlock = 1; + + data_sandbox[8] = 0x12345678; // @TODO RTC:133821 temporary bringup + + MAGIC_INSTRUCTION(MAGIC_BREAK); // @TODO RTC:133821 temporary bringup + + while(1); // @TODO + task_end_stub(); // @TODO + return 0; + } + + void handleMMIO(uint64_t i_srcAddr, + uint64_t i_destAddr, + uint32_t i_size, + MMIOLoadStoreSizes i_ld_st_size) + { + // @TODO RTC:133821 + } +} // end namespace Bootloader + diff --git a/src/bootloader/makefile b/src/bootloader/makefile new file mode 100644 index 000000000..cf5fe04a6 --- /dev/null +++ b/src/bootloader/makefile @@ -0,0 +1,33 @@ +# IBM_PROLOG_BEGIN_TAG +# This is an automatically generated prolog. +# +# $Source: src/bootloader/makefile $ +# +# 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 +ROOTPATH = ../.. + +OBJS += bl_start.o +OBJS += bootloader.o +OBJS += bl_pnor_ecc.o +OBJS += bl_builtins.o + +include ${ROOTPATH}/config.mk + diff --git a/src/build/mkrules/dist.targets.mk b/src/build/mkrules/dist.targets.mk index f11a93f17..2edbf1652 100644 --- a/src/build/mkrules/dist.targets.mk +++ b/src/build/mkrules/dist.targets.mk @@ -5,7 +5,7 @@ # # OpenPOWER HostBoot Project # -# Contributors Listed Below - COPYRIGHT 2013,2015 +# Contributors Listed Below - COPYRIGHT 2013,2016 # [+] International Business Machines Corp. # # @@ -98,6 +98,7 @@ COPY_RENAME_FILES = \ makefile:src/build/mkrules/hbfw/makefile:fsp\ img/makefile:src/build/mkrules/hbfw/img/makefile:fsp \ hbicore.bin:img/hbicore$(UNDERSCORE_TEST).bin:vpo \ + img/bootloader.bin:img/bootloader.bin:fsp,openpower \ img/hostboot.bin:img/hbicore$(UNDERSCORE_TEST).bin:fsp,openpower \ img/hostboot_extended.bin:img/hbicore$(UNDERSCORE_TEST)_extended.bin:fsp,openpower \ img/hostboot_runtime.bin:img/hbirt$(UNDERSCORE_TEST).bin:fsp,openpower \ diff --git a/src/build/mkrules/hbfw/img/makefile b/src/build/mkrules/hbfw/img/makefile index 1f29c09cb..79bebf7ee 100755 --- a/src/build/mkrules/hbfw/img/makefile +++ b/src/build/mkrules/hbfw/img/makefile @@ -5,7 +5,7 @@ # # OpenPOWER HostBoot Project # -# Contributors Listed Below - COPYRIGHT 2012,2015 +# Contributors Listed Below - COPYRIGHT 2012,2016 # [+] International Business Machines Corp. # # @@ -51,6 +51,7 @@ ENGD_OBJPATH = ${HBFW_OBJPATH:S/hbfw\/img/engd\/href/g} # Having external users acquire from OBJ dir as there are packaging # changes expected in the future which will require using OBJ version. ################################################# +BOOTLDR_IMAGE = bootloader.bin BASE_IMAGE = hostboot.bin EXT_IMAGE = hostboot_extended.bin EXT_FAKE_IMAGE = hostboot_extended.bin.fake @@ -58,7 +59,7 @@ HBRT_IMAGE = hostboot_runtime.bin HBRT_SHA_IMAGE = hostboot_runtime.sha.bin HBRT_HEADER_IMAGE = hostboot_runtime.header.bin HBRT_ECC_HEADER_IMAGE = hostboot_runtime.header.bin.ecc -BASE_IMAGES = ${BASE_IMAGE} ${EXT_IMAGE} ${HBRT_IMAGE} +BASE_IMAGES = ${BASE_IMAGE} ${EXT_IMAGE} ${HBRT_IMAGE} ${BOOTLDR_IMAGE} BASE_W_HEADER_IMAGE = hostboot.header.bin BASE_W_HEADER_ECC_IMAGE = hostboot.header.bin.ecc BASE_ECC_IMAGE = hostboot.bin.ecc @@ -397,12 +398,12 @@ clobber_build_pnor_images: #Special target to copy images to flash dir for simics ################################################# FLASH_DEST = $(MAKETOP)$(OBJECTDIRTOP)../images/$(CONTEXT)/lab/flash -FLASH_IMG = ${BASE_IMAGE} ${BASE_ECC_IMAGE} +FLASH_IMG = ${BASE_IMAGE} ${BASE_ECC_IMAGE} ${BOOTLDR_IMAGE} FAKE_PNOR = fake6m.pnor update_images_for_sandbox: inject_ecc build_sbe_partitions build_pnor_images mkdir -p ${FLASH_DEST} - #Copy hostboot base image to flash dir + #Copy hostboot base image and bootloader image to flash dir ${FLASH_IMG:@image@${baseimg:!cd ${FLASH_DEST}; cp -f ${.PATH:F${image}} ${image};!e}@} #Truncate fake pnor image down to 6MB and copy to flash dir ${FAKE_PNOR_IMG_INFO:@image@${pnorimg:!dd if=${image:s/:/ /g:xs/ .*//} of=${FAKE_PNOR} bs=6M count=1; \ diff --git a/src/build/mkrules/images.rules.mk b/src/build/mkrules/images.rules.mk index d486baa4d..92722dba2 100644 --- a/src/build/mkrules/images.rules.mk +++ b/src/build/mkrules/images.rules.mk @@ -5,7 +5,7 @@ # # OpenPOWER HostBoot Project # -# Contributors Listed Below - COPYRIGHT 2013,2014 +# Contributors Listed Below - COPYRIGHT 2013,2016 # [+] International Business Machines Corp. # # @@ -37,11 +37,12 @@ CLEAN_TARGETS += $(addsuffix .lnkout.bz2, $(addprefix $(IMGDIR)/., $(IMGS))) define ELF_template $$(IMGDIR)/$(1).elf: $$(addprefix $$(OBJDIR)/, $$($(1)_OBJECTS)) \ - $$(ROOTPATH)/src/kernel.ld + $$(ROOTPATH)/src/$$($(1)_LDFILE) $$(C2) " LD $$(notdir $$@)" $$(C1)$$(LD) -static $$(LDFLAGS) $$($$*_LDFLAGS) \ $$(addprefix $$(OBJDIR)/, $$($(1)_OBJECTS)) \ - $$($(1)_LDFLAGS) -T $$(ROOTPATH)/src/kernel.ld -o $$@ + $$($(1)_LDFLAGS) -T $$(ROOTPATH)/src/$$($(1)_LDFILE) \ + -o $$@ endef $(foreach img,$(IMGS),$(eval $(call ELF_template,$(img)))) diff --git a/src/build/tools/addimgid b/src/build/tools/addimgid index 34d633ea6..abd8e7de6 100755 --- a/src/build/tools/addimgid +++ b/src/build/tools/addimgid @@ -6,7 +6,7 @@ # # OpenPOWER HostBoot Project # -# Contributors Listed Below - COPYRIGHT 2011,2015 +# Contributors Listed Below - COPYRIGHT 2011,2016 # [+] International Business Machines Corp. # # @@ -31,6 +31,12 @@ my $imageIdSym = "hbi_ImageId"; my $img = shift; my $src = shift; +if(($img =~ /.*bootloader.*/) || ($src =~ /.*bootloader.*/)) +{ + # @TODO RTC:135747 Add version/id tag to binary + exit $? +} + my $imgBase = $img; $imgBase =~ s/.*\///; diff --git a/src/include/bootloader/bootloader.H b/src/include/bootloader/bootloader.H new file mode 100644 index 000000000..89b4bd761 --- /dev/null +++ b/src/include/bootloader/bootloader.H @@ -0,0 +1,93 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/include/bootloader/bootloader.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 __BOOT_LOADER_H +#define __BOOT_LOADER_H + +/** + * @file bootloader.H + * + * TaskInfo structs for each task that will run. + */ + +#include +#include + +extern "C" void task_end_stub(); + +#define assert(expr) \ +{\ + if (unlikely(!(expr)))\ + {\ + MAGIC_INSTRUCTION(MAGIC_BREAK); /* @TODO RTC:133821 temp bringup */ \ + task_end_stub();\ + }\ +} + +#define printk(format...) + +namespace Bootloader{ + /** @enum MMIOLoadStoreSizes + * @brief List of MMIO Load and Store Sizes. + * + * These are the sizes (in bytes) for the load and store commands used + * to read and write data when handling an MMIO. + */ + enum MMIOLoadStoreSizes + { + /** BYTESIZE */ + BYTESIZE = 1, + /** WORDSIZE */ + WORDSIZE = 4, + /** DBLWORDSIZE */ + DBLWORDSIZE = 8 + }; + + /** + * @brief Handle MMIO to copy code/data from one location to another + * + * @param[in] i_srcAddr MMIO address to copy from + * @param[in] i_destAddr address to copy to + * @param[in] i_size number of bytes to copy + * @param[in] i_ld_st_size size of data in ld and st instructions + * BYTESIZE => copy 1 byte at a time + * WORDSIZE => copy 4 bytes at a time + * DBLWORDSIZE => copy 8 bytes at a time + */ + extern void handleMMIO(uint64_t i_srcAddr, + uint64_t i_destAddr, + uint32_t i_size, + MMIOLoadStoreSizes i_ld_st_size); + + /** + * @brief Pointer to bootloader scratch space + * + * Pointer to location in main storage which bootloader uses as + * scratch space + */ + extern uint8_t *g_blScratchSpace; +} // end namespace Bootloader + +#endif diff --git a/src/include/bootloader/bootloader_trace.H b/src/include/bootloader/bootloader_trace.H new file mode 100644 index 000000000..234bb782c --- /dev/null +++ b/src/include/bootloader/bootloader_trace.H @@ -0,0 +1,183 @@ +/* IBM_PROLOG_BEGIN_TAG */ +/* This is an automatically generated prolog. */ +/* */ +/* $Source: src/include/bootloader/bootloader_trace.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 __BOOT_LOADER_TRACE_H +#define __BOOT_LOADER_TRACE_H + +#include + +/** + * @file bootloader_trace.H + * + * TaskInfo structs for each task that will run. + */ + +#ifndef BOOTLOADER_TRACE_SIZE +#define BOOTLOADER_TRACE_SIZE 64 +#endif + +extern uint8_t bootloader_trace_index; +extern uint8_t bootloader_trace[BOOTLOADER_TRACE_SIZE]; + +/** @enum BootloaderTraces + * @brief List of Hostboot Bootloader Trace values. + * + * These are used as trace values for the Hostboot Bootloader code. + */ +enum BootloaderTraces +{ + /** Bootloader main started */ + BTLDR_TRC_MAIN_START = 0x10, + + /** Bootloader main getHBBSection returned */ + BTLDR_TRC_MAIN_GETHBBSECTION_RTN = 0x11, + + /** Bootloader main handleMMIO to working location returned */ + BTLDR_TRC_MAIN_WORKING_HANDLEMMIO_RTN = 0x12, + + /** Bootloader main removeECC returned */ + BTLDR_TRC_MAIN_REMOVEECC_RTN = 0x13, + + /** Bootloader main applySecureSignatureValidation returned */ + BTLDR_TRC_MAIN_APPLYSECSIGVAL_RTN = 0x14, + + /** Bootloader main copy HBB to running location done */ + BTLDR_TRC_MAIN_COPY_HBB_DONE = 0x15, + + /** Bootloader handleMMIO started */ + BTLDR_TRC_HANDLEMMIO_START = 0x20, + + /** Bootloader PNOR Access getHBBSection started */ + BTLDR_TRC_PA_GETHBBSECTION_START = 0x30, + + /** Bootloader PNOR Access findTOC handleMMIO to copy TOC ONE returned */ + BTLDR_TRC_PA_FINDTOC_TOC1_HANDLEMMIO_RTN = 0x31, + + /** Bootloader PNOR Access findTOC readTOC for TOC ONE returned */ + BTLDR_TRC_PA_FINDTOC_TOC1_READTOC_RTN = 0x32, + + /** Bootloader PNOR Access findTOC handleMMIO to copy TOC TWO returned */ + BTLDR_TRC_PA_FINDTOC_TOC2_HANDLEMMIO_RTN = 0x33, + + /** Bootloader PNOR Access findTOC readTOC for TOC TWO returned */ + BTLDR_TRC_PA_FINDTOC_TOC2_READTOC_RTN = 0x34, + + /** Bootloader PNOR Access getHBBSection findTOC returned */ + BTLDR_TRC_PA_GETHBBSECTION_FINDTOC_RTN = 0x35, + + /** Bootloader PNOR Access readTOC zeroSection returned */ + BTLDR_TRC_PA_READTOC_ZEROSECTION_RTN = 0x41, + + /** Bootloader PNOR Access readTOC checkForNullBuffer returned */ + BTLDR_TRC_PA_READTOC_CHECKNULLBUFFER_RTN = 0x42, + + /** Bootloader PNOR Access readTOC performHdrChecksum returned */ + BTLDR_TRC_PA_READTOC_HDRCHECKSUM_RTN = 0x43, + + /** Bootloader PNOR Access readTOC checkHeader returned */ + BTLDR_TRC_PA_READTOC_CHECKHEADER_RTN = 0x44, + + /** Bootloader PNOR Access readTOC parseEntries returned */ + BTLDR_TRC_PA_READTOC_PARSEENTRIES_RTN = 0x45, + + /** Bootloader main removeECC returned corrected ECC rc */ + BTLDR_TRC_MAIN_REMOVEECC_CORRECTED = 0xD0, + + /** Bootloader Utils checkHeader magic invalid */ + BTLDR_TRC_UTILS_CHECKHEADER_MAGIC = 0xE0, + + /** Bootloader Utils checkHeader version invalid */ + BTLDR_TRC_UTILS_CHECKHEADER_VERSION = 0xE1, + + /** Bootloader Utils checkHeader entry size invalid */ + BTLDR_TRC_UTILS_CHECKHEADER_ENTRYSIZE = 0xE2, + + /** Bootloader Utils checkHeader entry count invalid */ + BTLDR_TRC_UTILS_CHECKHEADER_ENTRYCNT = 0xE3, + + /** Bootloader Utils checkHeader block size invalid */ + BTLDR_TRC_UTILS_CHECKHEADER_BLOCKSIZE = 0xE4, + + /** Bootloader Utils checkHeader block count invalid */ + BTLDR_TRC_UTILS_CHECKHEADER_BLOCKCNT = 0xE5, + + /** Bootloader Utils checkHeader header size invalid */ + BTLDR_TRC_UTILS_CHECKHEADER_HDRSIZE = 0xE6, + + /** Bootloader Utils parseEntries invalid section */ + BTLDR_TRC_UTILS_PARSE_INVALID_SECTION = 0xE7, + + /** Bootloader main getHBBSection returned */ + BTLDR_TRC_MAIN_GETHBBSECTION_FAIL = 0xF0, + + /** Bootloader main removeECC returned */ + BTLDR_TRC_MAIN_REMOVEECC_FAIL = 0xF1, + + /** Bootloader PNOR Access readTOC checkForNullBuffer null buffer */ + BTLDR_TRC_PA_READTOC_CHKNULLBUFFER_NULL = 0xF2, + + /** Bootloader PNOR Access readTOC performHdrChecksum checksum error */ + BTLDR_TRC_PA_READTOC_HDRCHECKSUM_ERR = 0xF3, + + /** Bootloader PNOR Access readTOC checkHeader header error */ + BTLDR_TRC_PA_READTOC_CHECKHEADER_ERR = 0xF4, + + /** Bootloader PNOR Access readTOC parseEntries entry error */ + BTLDR_TRC_PA_READTOC_PARSEENTRIES_ERR = 0xF5, + + /** Bootloader PNOR Access findTOC readTOC errors */ + BTLDR_TRC_PA_FINDTOC_READTOC_ERR = 0xF6, + + /** Bootloader Utils parseEntries checksum error */ + BTLDR_TRC_UTILS_PARSE_CHECKSUM_ERROR = 0xF7, + + /** Bootloader Utils parseEntries size extends beyond Flash */ + BTLDR_TRC_UTILS_PARSE_EXCEEDS_FLASH = 0xF8, + + /** Bootloader PNOR Access getHBBSection findTOC error */ + BTLDR_TRC_PA_GETHBBSECTION_FINDTOC_ERR = 0xF9, + + /** Bootloader PNOR Access getHBBSection findTOC no HBB section */ + BTLDR_TRC_PA_GETHBBSECTION_FINDTOC_NOHBB = 0xFA, +}; + +#ifndef BOOTLOADER_TRACE +#define BOOTLOADER_TRACE(trace_value) \ +{ \ + bootloader_trace[bootloader_trace_index++] = trace_value; \ + bootloader_trace_index %= BOOTLOADER_TRACE_SIZE; \ + lwsync(); \ +} +#endif + +#ifndef BOOTLOADER_TRACE_W_BRK +#define BOOTLOADER_TRACE_W_BRK(trace_value) \ +{ \ + BOOTLOADER_TRACE(trace_value); \ + /* MAGIC_INSTRUCTION(MAGIC_BREAK); */ \ +} +#endif + +#endif diff --git a/src/libc++/builtins.C b/src/libc++/builtins.C index f8dc97aad..d66e81ec3 100755 --- a/src/libc++/builtins.C +++ b/src/libc++/builtins.C @@ -5,7 +5,7 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* Contributors Listed Below - COPYRIGHT 2010,2015 */ +/* Contributors Listed Below - COPYRIGHT 2010,2016 */ /* [+] International Business Machines Corp. */ /* */ /* */ @@ -22,6 +22,7 @@ /* permissions and limitations under the License. */ /* */ /* IBM_PROLOG_END_TAG */ +#ifndef bl_builtins_C #include #include @@ -58,6 +59,7 @@ void operator delete[](void* p) { return free(p); }; +#endif // bl_builtins_C extern "C" int __cxa_guard_acquire(volatile uint64_t* gv) { @@ -91,6 +93,7 @@ extern "C" void __cxa_guard_release(volatile uint64_t* gv) return; } +#ifndef bl_builtins_C extern "C" void __cxa_pure_virtual() { // TODO: Add better code for invalid pure virtual call. @@ -162,6 +165,6 @@ extern "C" int __cxa_atexit(void (*i_dtor)(void*), } return 0; } - +#endif // bl_builtins_C diff --git a/src/makefile b/src/makefile index 285f453b2..d271d0432 100644 --- a/src/makefile +++ b/src/makefile @@ -26,6 +26,7 @@ ROOTPATH = .. +SUBDIRS += bootloader.d SUBDIRS += kernel.d SUBDIRS += lib.d SUBDIRS += libc++.d @@ -36,6 +37,7 @@ SUBDIRS += runtime.d # Reducing HB extended img size for VPO by disabling certain libs using # CONFIG_VPO_COMPILE option +IMGS += bootloader IMGS += hbicore IMGS += hbicore_test IMGS += hbirt @@ -57,6 +59,13 @@ BASE_OBJECTS += tls.o ifdef HOSTBOOT_PROFILE BASE_OBJECTS += gcov.o endif + +BL_BASE_OBJECTS += bl_builtins.o + +BOOTLDR_OBJECTS += bl_start.o +BOOTLDR_OBJECTS += bootloader.o +BOOTLDR_OBJECTS += bl_pnor_ecc.o + DIRECT_BOOT_OBJECTS += start.o DIRECT_BOOT_OBJECTS += kernel.o DIRECT_BOOT_OBJECTS += taskmgr.o @@ -270,10 +279,15 @@ RUNTIME_TESTCASE_MODULES += testpnor_rt RELOCATABLE_IMAGE_LDFLAGS = -pie --export-dynamic +bootloader_OBJECTS += ${BL_BASE_OBJECTS} +bootloader_OBJECTS += ${BOOTLDR_OBJECTS} +bootloader_LDFILE = bootloader.ld + hbicore_OBJECTS += ${BASE_OBJECTS} hbicore_OBJECTS += ${DIRECT_BOOT_OBJECTS} hbicore_MODULES += ${BASE_MODULES} hbicore_EXTENDED_MODULES += ${EXTENDED_MODULES} +hbicore_LDFILE = kernel.ld # for PRDR_RULE_TABLE_TARGETS include ${ROOTPATH}/src/usr/diag/prdf/common/framework/rule/prdf_rule.mk @@ -286,6 +300,7 @@ hbicore_test_DATA_MODULES += testdata ifndef SKIP_BINARY_FILES hbicore_test_DATA_MODULES += test_signed_container endif +hbicore_test_LDFILE = kernel.ld hbirt_OBJECTS += ${RUNTIME_OBJECTS} hbirt_OBJECTS += ${BASE_OBJECTS} @@ -293,12 +308,14 @@ hbirt_MODULES += ${RUNTIME_MODULES} hbirt_DATA_MODULES += ${RUNTIME_DATA_MODULES} hbirt_DATA_MODULES += $(if $(CONFIG_HBRT_PRD),$(prd_rule_prf_targets)) hbirt_LDFLAGS = ${RELOCATABLE_IMAGE_LDFLAGS} +hbirt_LDFILE = kernel.ld hbirt_test_OBJECTS += ${hbirt_OBJECTS} hbirt_test_MODULES += ${hbirt_MODULES} hbirt_test_MODULES += ${RUNTIME_TESTCASE_MODULES} hbirt_test_DATA_MODULES += ${hbirt_DATA_MODULES} hbirt_test_LDFLAGS = ${RELOCATABLE_IMAGE_LDFLAGS} +hbirt_test_LDFILE = kernel.ld IMAGE_PASS_POST += buildpnor IMAGE_PASS_POST += imgsizecheck diff --git a/src/usr/pnor/ecc.C b/src/usr/pnor/ecc.C index fb03c0be6..7ccab7b69 100644 --- a/src/usr/pnor/ecc.C +++ b/src/usr/pnor/ecc.C @@ -5,7 +5,9 @@ /* */ /* OpenPOWER HostBoot Project */ /* */ -/* COPYRIGHT International Business Machines Corp. 2013,2014 */ +/* Contributors Listed Below - COPYRIGHT 2013,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. */ @@ -20,11 +22,13 @@ /* permissions and limitations under the License. */ /* */ /* IBM_PROLOG_END_TAG */ +#ifndef bl_pnor_ecc_C #include #include #include #include +#endif namespace PNOR { @@ -168,6 +172,7 @@ namespace ECC return badBit; } +#ifndef bl_pnor_ecc_C void injectECC(const uint8_t* i_src, size_t i_srcSz, uint8_t* o_dst) { @@ -187,6 +192,7 @@ namespace ECC o_dst[o + sizeof(uint64_t)] = ecc; } } +#endif eccStatus removeECC(uint8_t* io_src, uint8_t* o_dst, size_t i_dstSz) -- cgit v1.2.1