05_prekernelboot.pdf
DESCRIPTION
Tornado BSPTraining WorkshopTRANSCRIPT
![Page 1: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/1.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-1
Chapter
5
Pre-KernelInitialization - Boot
Specific Code
![Page 2: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/2.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-2
Pre-Kernel Initialization - BootSpecific Code
5.1 Boot Specific vs. Generic Code
romInit.s : romInit()
PIC and VxWorks
bootInit.c : romStart()
sysALib.s : sysInit()
![Page 3: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/3.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-3
VxWorks Image Types and GenericCode
• Details of pre-kernel initialization depend on VxWorks
image type characteristics:
● ROM image - Boot or “end-user” image.
a. compressed
b. uncompressed
● ROM-resident image - Boot or “end-user” image.● Loadable image - “End-user” image.
• Generic pre-kernel code common to all image types is
usrInit() and the routines it calls. These will be
discussed in the next chapter.
![Page 4: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/4.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-4
Boot Specific Pre-kernelInitialization Code
• VxWorks image type specific code:
● romInit()● romStart()● sysInit()
• romInit() and romStart() execute for all images
“burned” into ROM.
• sysInit() only executes for all loadable VxWorks images.
• romInit() and sysInit() are similar routines except
romInit() initializes memory and sysInit() does not (this
is done by romInit() in the boot image).
![Page 5: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/5.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-5
Choice of First Image
• Which type of image is developed first depends on
download path:
● Download to RAM - Use vxWorks.● Download to ROM - Use vxWorks_rom or
vxWorks.res_rom_nosym.
• The initial image should not be compressed or contain a
symbol table. These features can be added later.
• The first image for a download path to ROM:
● vxWorks_rom - Allows software breakpoints forcode which executes in RAM.
● vxWorks.res_rom_nosym - Provides a smaller RAMfootprint (and possibly reduced start-up time).
● Note, if the first image is vxWorks, RAM will need to be initializedprior to the download.
![Page 6: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/6.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-6
Pre-Kernel Initialization - BootSpecific Code
Boot Specific vs. Generic Code
5.2 romInit.s : romInit()
PIC and VxWorks
bootInit.c : romStart()
sysALib.s : sysInit()
![Page 7: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/7.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-7
romInit() Basics
• First code to execute on power-up. Entry point for all
VxWorks ROM images.
• Performs minimum required setup to execute
romStart(). The remainder of hardware initialization is
performed by generic pre-kernel code.
• Routine must:
● Mask processor interrupts and reset processor.● Initialize the memory system.● Initialize stack pointer and other registers to begin
executing romStart() and passing the boot type.
• Routine is written is assembly language and resides in
file romInit.s.
![Page 8: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/8.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-8
Architecture vs. BSP Specific Issues
• Much of what romInit() needs to do is processor specific
and can be copied from the reference BSP:
● Masking processor interrupts.● Initializing on-processor caches.● Initializing the stack pointer.
• Non-processor specific initialization involves DRAM
and will be specific to the hardware environment.
● Wait states.● Refresh rates.● Chip selects (bridge/bus/memory controllers, etc.)● Disabling of L2 caches (if necessary).
• Usually on-processor caches are disabled except when the instruction
cache is turned on for faster Flash/ROM boots.
![Page 9: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/9.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-9
Cold vs. Warm Boots
• Two boot types:
● Cold boot - Power-up of hardware environment.● Warm boot - Call to reboot(), ^X, or exception at
interrupt level. The routine which passes control tothe ROM monitor is sysToMonitor() in sysLib.c.
• Where romInit() begins execution is a function of the
boot type:
● Cold boot - Execution begins at the entry pointromInit(). Boot type is forced to be BOOT_COLD.
● Warm boot - Execution begins at romInit() plus asmall offset (usually 4 bytes). Boot type is saved.
• Boot type (cold/warm) is stored in an architecture
specific register and passed to romStart().
• The first instruction executed by romInit() is a branch to a label (cold:
or warm: ) where the instruction to store the appropriate boot type is.
The branch to cold is the first executable instruction in romInit(), the
branch to warm follows this instruction and is where romInit() begins
execution for a warm boot.
• reboot() services ^X.
![Page 10: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/10.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-10
Stack Pointer Initialization
• Macro which configures beginning of stack is
STACK_ADRS in configAll.h.
• For ROM-resident images the stack will begin:
● In RAM at the start of the VxWorks data segment forstacks which grow down.
● In RAM at the start of the VxWorks data segment lessthe size of the stack for stacks which grow up.
• For non-ROM-resident images the stack will begin:
● In RAM at the start of the text segment of theVxWorks image for stacks which grow down.
● In RAM at the start of the text segment of theVxWorks image less the size of the stack for stackswhich grow up.
![Page 11: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/11.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-11
romInit() - PIC
• romInit(), which runs in ROM/Flash, must be written
as Position Independent Code (PIC) to support the
various boot strategies for VxWorks images.
• PIC code is program counter (PC) relative.
• If a ROM address cannot be made program counter
relative then it must be recomputed by:
● Subtracting _romInit (The entry point for romInit().)● Adding ROM_TEXT_ADRS (Boot ROM/Flash
entry address. Where ROM code is “burned”.)
• This algorithm ensures that a ROM address is expressed
relative to the PC value for romInit() regardless of the
address assigned to romInit() by the compiler/linker.
• Address recalculations are usually done with a macro:
#define ROM_OFFSET(x) ((x) - _romInit+ ROM_TEXT_ADRS)
• Because romInit() is statically linked into a VxWorks image, the address
assigned to romInit() by the linker will be a ROM address for a ROM-
resident image and a RAM address for a non-ROM-resident ROM
image. This will be discussed in more detail in the next section.
![Page 12: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/12.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-12
romInit() - Some do’s and don’ts
• Perform minimum necessary initialization. Leave most
hardware initialization to generic routine sysHwInit().
• Do not call out to other modules or routines:
● May cause linking problems for compressed images.● Call outs to C routines may use absolute not PC
relative addressing.
• Make sure romInit() is the first routine in romInit.s.
• Start with romInit() from reference BSP.
• Make sure macros in Makefile and config.h are correct:
● ROM_TEXT_ADRS● ROM_SIZE
• After romInit() initializes memory, but before branching to romStart(),run memory diagnostic code:
● Often supplied by board vendor.● Will test for replication of maps (e.g. SIM1 maps to SIM2), missing
memory, refreshes, etc.● Remove code when test is complete.
![Page 13: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/13.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-13
Pre-Kernel Initialization - BootSpecific Code
Boot Specific vs. Generic Code
romInit.s : romInit()
5.3 PIC and VxWorks
bootInit.c : romStart()
sysALib.s : sysInit()
![Page 14: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/14.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-14
PIC and VxWorks Builds
• romInit() which executes in ROM needs to be PIC to
support various VxWorks image types.
• This is because romInit() is linked into all non-loadable
VxWorks images, all of which do not execute in ROM.
• To understand how romInit() (as well as other routines)
are linked into VxWorks images the build rules in ../h/make/rules.bsp must be examined.
• Examine the link instructions for vxWorks_rom:
● Uncompressed rommable binary image.● Begins execution in ROM.● Transfers execution to RAM in romStart().
![Page 15: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/15.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-15
vxWorks_rom Build
• The link instructions for the target vxWorks_rom are:
vxWorks_rom : ........
$(LD) $(LDFLAGS) $(LD_PARTIAL_FLAGS) \ -o ctmp.o usrConfig.o \ $(MACH_DEP) version.o $(LIBS)
....
$(LD) $(LDFLAGS) -e $(ROM_ENTRY) $(LD_LOW_FLAGS) \ -o $@ romInit.o bootInit_uncmp.o dataSegPad.o \ ctmp.o ctdt.o
....
• Dots, “....” indicate missing code. Missing code consists
of compilation and file management instructions.
![Page 16: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/16.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-16
vxWorks_rom Build Link Flags
• The first link builds most of the image and places it in
the relocatable module ctmp.o.
• The second link builds the final fully linked relocatable
image vxWorks_rom (this is target name for “$@”).
• The link flags are:
● LD = ldppc ( make.$(CPU)$(TOOL) )● LDFLAGS = -X -N ( defs.bsp)● LD_PARTIAL_FLAGS = -X -r (defs.bsp)
• Note, it is the “-r ” flag which produces a partially
linked relocatable module (ctmp.o) for the first link, but
not for the second which produces vxWorks_rom.
• The -X flag deletes all temporary local symbols.
• The -N flag sets the text and data segments as readable and writable,
and does not page-align the data segment.
• See the “GNU ToolKit User’s Guide” for information on compiler and
linker flags.
![Page 17: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/17.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-17
vxWorks_rom Build - ctmp.o
• The temporary relocatable module ctmp.o uses the
macro expansions (defs.bsp):
● MACH_DEP = sysALib.o sysLib.o ..● LIBS = ../lib/lib$(CPU)$(TOOL)vx.a
• Pre-kernel initialization code in ctmp.o:
● sysInit() - in sysALib.o● sysHwInit() - in sysLib.o● usrInit() - in usrConfig.o
• Remainder of the ctmp.o contains modules from the
appropriate VxWorks library archive and version.o.
• The remainder of the pre-kernel initialization code is
included in the second link.
• configAll.h and config.h control which VxWorks modules in archived
files are linked. Archived files reside in the directory ../lib/obj$(CPU)$(TOOL)vx.
• ctmp.o is deleted after the build is completed.
• The complete macro definitions are:
MACH_DEP = sysALib.o sysLib.o $(MACH_EXTRA) $(ADDED_MODULES)LIBS = $(LIB_EXTRA) $(TGT_DIR)/lib/lib$(CPU)$(TOOL)vx.a
• Additional machine dependent modules added by the BSP developer
(MACH_EXTRA), application specific modules added by users
(ADDED_MODULES), and library archives (perhaps containing third
party drivers) are also linked into ctmp.o.
![Page 18: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/18.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-18
vxWorks_rom Image
• The final link includes the remainder of the kernel
initialization code:
● romInit() - in romInit.o● romStart() - in bootInit_unmcp.o
• The final vxWorks_rom image uses the macro
expansions (defs.bsp):
● ROM_ENTRY = _romInit● LD_LOW_FLAGS = -Ttext $(RAM_LOW_ADRS)
• The ROM_ENTRY macro for the “-e ” flag insures that
romInit() will be the execution entry point.
• The LD_LOW_FLAGS produces text addresses starting in
RAM not ROM!
• Note, that this final link also includes:
● dataSegPad.o - For VxVMI page alignment of data segment.● ctdt.o - C++ constructors/destructors produced by munch.
• The rules for building the module bootInit_uncmp.o (from bootInit.c)
are in rules.bsp:
bootInit_uncmp.o : depend.$(BSP_NAME) $(BOOTINIT) bootInit.o - @ $(RM) $@ $(CP) $(BOOTINIT) bootInit_uncmp.c $(CC) -c $(CFLAGS) -DUNCOMPRESS bootInit_uncmp.c - @ $(RM) bootInit_uncmp.c
• The bootInit.c (BOOTINIT) file is simply copied to a file
bootInit_uncmp.c and compiled.
• RAM_LOW_ADRS is the load point of this image in RAM.
![Page 19: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/19.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-19
vxWorks_rom Image and PIC
• The vxWorks_rom image is “burned” into ROM (or
Flash) at the address ROM_TEXT_ADRS (Makefile). This
is how ROM_ENTRY = ROM_TEXT_ADRS.
• Execution will begin in ROM even though the linker
has assigned RAM addresses to the text for romInit().
• This is the reason why romInit() must be PIC code for
this image.
• For addresses which are not program counter relative,
address recalculations are usually done with a macro:
#define ROM_OFFSET(x)((x) - _romInit+ROM_TEXT_ADRS)
• Note, for some environments ROM_TEXT_ADRS may not be at the
beginning of the ROM area if this area is used to store a reset vector.
• The portion of romStart() which executes in ROM for this image will
also need to be PIC.
![Page 20: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/20.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-20
vxWorks.res_rom_nosym
• Next consider a ROM-resident image:
vxWorks.res_rom_nosym: ....
$(LD) -o $@ $(LDFLAGS) $(ROM_LDFLAGS) \ -e $(ROM_ENTRY) $(RES_LOW_FLAGS) \ romInit_res.o bootInit_res.o \ ctmp.o ctdt.o
• The linker flag RES_LOW_FLAGS expands to:
-Ttext $(ROM_TEXT_ADRS) -Tdata $(RAM_LOW_ADRS)
● Text is assigned ROM addresses.● Data is assigned RAM addresses.
• romInit() does not need to be PIC for this image, or any
ROM-resident image.
• For flexibility with respect to VxWorks builds it is suggested that
VxWorks code which executes in ROM be PIC.
• ROM_LDFLAGS is an optional macro which allows link instructions to be
passed to ROM-resident images. It may be defined in Makefile.
• The rules for building romInit_res.o (from romInit.s) and
bootInit_res.o (from bootInit.c) are in rules.bsp:
romInit_res.o: depend.$(BSP_NAME) romInit.s romInit.o - @ $(RM) $@ $(CC) $(CFLAGS_AS) -DROM_RESIDENT -c -o $@ romInit.s
bootInit_res.o : depend.$(BSP_NAME) $(BOOTINIT) bootInit.o - @ $(RM) $@ $(CP) $(BOOTINIT) bootInit_res.c $(CC) -c $(CFLAGS) -DROM_RESIDENT bootInit_res.c - @ $(RM) bootInit_res.c
• See discussion of romInit() for example BSP in Appendix A
![Page 21: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/21.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-21
Pre-Kernel Initialization - BootSpecific Code
Boot Specific vs. Generic Code
romInit.s : romInit()
PIC and VxWorks
5.4 bootInit.c : romStart()
sysALib.s : sysInit()
![Page 22: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/22.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-22
romStart() Basics
• Jumped to by romInit() which places the start type on
the stack for romStart().
• Performs necessary code relocation, uncompression,
and RAM initialization for ROM images:
● Copies appropriate ROM image segments to RAM.● Clears portions of RAM not being used (cold boot).● Performs uncompression if required.● Passes control to generic pre-kernel code (usrInit()).
• Code is written in C and resides in ../all/bootInit.c.
Portion which executes in ROM should be PIC.
• Do not modify code. Functionality is controlled by
configuration macros.
• For i960 processors romStart() transfers control to sysInitAlt() which
transfers control to usrInit(). sysInitAlt() re-installs the processor tables
for the i960.
• Code modification during development will be discussed later in this
section.
![Page 23: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/23.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-23
Code Relocation
• Which image segments are relocated by romStart():
● ROM images - Text and data.● ROM-resident images - Data.
• Final RAM destination for ROM image segments:
● Uncompressed VxWorks boot - RAM_HIGH_ADRS● Compressed VxWorks boot - RAM_HIGH_ADRS● Uncompressed VxWorks - RAM_LOW_ADRS● Compressed VxWorks - RAM_LOW_ADRS● ROM-resident VxWorks boot - RAM_HIGH_ADRS● ROM-resident VxWorks - RAM_LOW_ADRS
• For uncompressed ROM images there is only one
relocation from ROM to the final RAM destination.
![Page 24: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/24.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-24
Compressed Image Relocations
• Compressed ROM images contain an uncompressed
component and a compressed component.
• romInit.s, and bootInit.c code is in the uncompressed
component. Remainder of image is compressed.
• There are two relocations for these images:
● First relocation moves uncompressed componentfrom ROM to RAM.
● Second relocation occurs when compressedcomponent of image is uncompressed and relocatedfrom ROM to final destination in RAM.
• Second relocation is performed by romStart() in RAM.
romStart() is moved into RAM during first relocation.
• For compressed images, if the second relocation is to
RAM_LOW[HIGH]_ADRS the first relocation will be to
RAM_HIGH[LOW]_ADRS.
● Final (second) relocation addresses for various images are listed onthe previous page.
![Page 25: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/25.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-25
Compressed Binary Images
• Compressed VxWorks boot images:
● Relocate uncompressed component of ROM image toRAM location RAM_LOW_ADRS.
● Uncompression code executes in RAMuncompressing and relocating VxWorks boot imagefrom ROM to RAM location RAM_HIGH_ADRS.
● Execution jumps to usrInit().
• Compressed VxWorks application images:
● Relocate uncompressed component of ROM image toRAM location RAM_HIGH_ADRS.
● Uncompression code executes in RAMuncompressing and relocating VxWorks image fromROM to RAM location RAM_LOW_ADRS.
● Execution jumps to usrInit().
• Uncompression uses standard routine inflate() which is based on the
public domain zlib code. For more information on inflate()/deflate() see:
● http://www.cdrom.com/pub/infozip/zlib/
• Compression of VxWorks object modules typically achieves over 55%
compression. Overhead is additional delay of a few seconds at boot
time.
![Page 26: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/26.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-26
Clearing Memory For Cold Boots
• For cold boots RAM is re-initialized.
• Mitigates parity error generation for some hardware
(usually activated by read access without initialization).
• After romStart() relocates ROM image to RAM (but
prior to uncompression if necessary) it clears all
memory not filled with text and data.
• Memory is re-initialized to zero a long at a time.
• Additional memory which is not re-initialized:
● Reserved using USR_RESERVED_MEM (config.h).● Reserved using RESERVED (configAll.h).● Reserved using STACK_SAVE (configAll.h).
• The macros USR_RESERVED_MEM, RESERVED, and STACK_SAVE will be
discussed later in this section.
• For a warm boot memory is not cleared.
![Page 27: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/27.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-27
romStart() Stack
• Stack pointer for romStart() start initialized to
STACK_ADRS by romInit().
• romStart() does not return. It’s stack is used until kernel
is activated.
• The VxWorks kernel is activated by kernelInit() which
spawns a task (with its own stack) to complete system
configuration and start user application (usually by
spawning another task).
• Memory for romStart() stack is not re-initialized on
cold boot.
![Page 28: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/28.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-28
Checking Initialization
• After final relocation of image, there may still be
problems:
● RAM access not working properly.● For ROM-resident images data segment may not
have been relocated to correct address in RAM.● Download environment problems not solved.● Code problems.
• Verify RAM access by writing to an un-initialized
global:
int dummyVar; /* BSS segment variable */.... dummyVar = 13; if (dummyVar != 13) somethingWrongWithRAM();
• If download environment problems have not been solved, re-examine
development environment issues discussed earlier.
• Check for code problems using the first pre-Tornado debug procedures
discussed earlier.
![Page 29: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/29.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-29
ROM-resident Data Segment
• For ROM-resident images verify that the data segment
has been correctly initialized after the final relocation:
static int testVal = 13; /* data segment variable */.... if (testVal != 13) somethingWrongWithData();
• If there are problems and RAM access works, check
relocation of data segment to RAM.
• For ROM-resident images romStart() copies the data
segment to an architecture specific RAM address
computed as an offset from the end of text in ROM.
• Check offset, particularly if WRS tools were not used to
make ROM-resident image.
• The portion of romStart() which copies the data segment to RAM for
ROM-resident images is:
....
#if (CPU_FAMILY == SPARC) copyLongs ((UINT *)(etext + 8), (UINT *) RESIDENT_DATA,#elif ((CPU_FAMILY == MIPS) || (CPU_FAMILY == PPC)) copyLongs ((UINT *)(etext + 0), (UINT *) RESIDENT_DATA,#else copyLongs ((UINT *)(etext + 4), (UINT *) RESIDENT_DATA,#endif ((UINT) edata - (UINT) RESIDENT_DATA) / sizeof(long));....
• Note the architecture specific offset added to the ROM address etext.
(Linker assigns ROM addresses to text and RAM addresses to data).
• RESIDENT_DATA is defined as RAM_HIGH_ADRS.
![Page 30: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/30.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-30
Modifying romStart()
• During BSP development debug code may need to be
placed into bootInit.c.
• Do not modify ../config/all/bootInit.c. Make a copy of
this file in the BSP directory, and modify the copied file.
• To link the copy and not the original file, add the
following line to Makefile after the macro HEX_FLAGS:
BOOTINIT = bootInit.c
• Macro BOOTINIT is used to access bootInit.c during
VxWorks builds in rules.bsp.
• Default value for this macro is defined in
defs.$(WIND_HOST_TYPE) as ../config/all/bootInit.c.
![Page 31: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/31.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-31
romStart() Configuration Macros
• Configuration macros control behavior of romStart().These macros are defined in config.h, Makefile,
configAll.h, and bootInit.c.
• BSP developers are responsible for the configuration
macros in config.h, <bsp>.h, and Makefile.
• bootInit.c should not be modified. Macros in this file
are:
● BSP (or architecture) dependent. - Controlled fromconfig.h, Makefile, and configAll.h.
● Image type specific. - Controlled at compile time inrules.bsp. BSP developer does not need to modify.
● Specific to code in bootInit.c.
![Page 32: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/32.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-32
romStart() Configuration Macros -continued
• romStart() configuration macros defined in config.h:
● LOCAL_MEM_LOCAL_ADRS - Start of RAM.● LOCAL_MEM_SIZE - Size of RAM.● USER_RESERVED_MEM - Number of reserved bytes.
Memory reserved from top of RAM and will not becleared on cold boot or used by VxWorks.
● RAM_HIGH_ADRS - RAM load address for non-ROM-resident VxWorks boot images.
● RAM_LOW_ADRS - RAM load address for non-ROM-resident VxWorks application images.
● ROM_TEXT_ADRS - Boot ROM entry address.● ROM_SIZE - Size of ROM.● ROM_BASE_ADRS - Base address of ROM.
![Page 33: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/33.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-33
romStart() Configuration Macros -continued
• romStart() configuration macros defined in Makefile:
● RAM_HIGH_ADRS - Must agree with config.h● RAM_LOW_ADRS - Must agree with config.h● ROM_TEXT_ADRS - Must agree with config.h● ROM_SIZE - Must agree with config.h
• romStart() configuration macros defined in configAll.h:
● RESERVED - Number of reserved bytes. Memoryreserved from bottom of RAM, and will not becleared on cold boot.
● STACK_SAVE - Maximum stack size for romStart().Architecture specific. Not cleared on cold reboot.
![Page 34: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/34.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-34
romStart() Configuration Macros -continued
• romStart() configuration macros defined in bootInit.c:
● USER_RESERVED_MEM- Will be defined as zero ifnot defined in config.h.
● SYS_MEM_BOTTOM - For cold boot, memory will becleared starting at this address. It expands to:LOCAL_MEM_LOCAL_ADRS + RESERVED.
● SYS_MEM_TOP - For cold boot, memory will becleared up to (but not including) this address. Itexpands to: LOCAL_MEM_LOCAL_ADRS +LOCAL_MEM_SIZE - USR_RESERVED_MEM.
● UNCMP_RTN - Name (address) of uncompressionroutine.
● ROM_OFFSET - Macro to re-compute absoluteaddresses which are not PIC compatible.
![Page 35: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/35.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-35
romStart() Configuration Macros -continued
● RAM_DST_ADRS - Final relocation address forcompressed image. Default value isRAM_HIGH_ADRS, redefined when necessary atcompile time in rules.bsp.
● RESIDENT_DATA - Architecture specific. Defined asRAM_DST_ADRS for MIPS and PowerPC. Defined asthe start of the data segment otherwise.
● ROM_COPY_SIZE - For uncompressed and ROM-resident images size of image to relocate.
● ROM_BASE_ADRS - Defined in config.h. Redefined asromInit if BOOTCODE_IN_RAM is defined.
● binArrayStart - Start of compressed binaryimage.
● binArrayEnd - End of compressed binary image.
• BOOTCODE_IN_RAM is an optional configuration macro discussed in
what follows (x86 architecture only).
![Page 36: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/36.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-36
romStart() Configuration Macros -continued
• Optionally defined configuration macros for romStart():
● BOOTCODE_IN_RAM - Used to not clear RAM on coldboot. If RAM is already initialized this macro allowsBSP developer to avoid RAM initialization on coldboot. Must be defined in config.h (x86 architectureonly).
● UNCOMPRESS - Defined at compile time in rules.bspfor uncompressed image. Does not need to beredefined.
● ROM_RESIDENT - Defined at compile time inrules.bsp for ROM-resident image. Does not need tobe redefined.
![Page 37: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/37.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-37
ROM Layout
+ROM_BASE_ADRS
ROM_SIZE
ROM_BASE_ADRS
ROM_TEXT_ADRS
UncompressedImage Segment
binArrayStart
binArrayEnd
CompressedImage Segment
• Figure not to scale.
• The compressed image segment is only relevant for compressed ROM
images.
![Page 38: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/38.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-38
RAM Layout
LOCAL_MEM_LOCAL_ADRS
RAM_DST_ADRS
RESERVED
RelocatedROM Image
zero filledon cold boot
zero filledon cold boot
sysPhysMemTop()
STACK_SAVE
SYS_MEM_BOTTOM
SYS_MEM_TOP
User reserved
• Figure not to scale.
• Figure represents RAM state after final relocation of ROM image.
• RAM_DST_ADRS will be:
● RAM_HIGH_ADRS for VxWorks boot images.● RAM_LOW_ADRS for application VxWorks images.
• Image segments relocated to RAM_DST_ADRS:
● Text and data for ROM images.● Data for ROM-resident images.
• sysPhysMemTop() is function which returns the address of the top of
physical memory. The routine is in sysLib.c and its return value is:
LOCAL_MEM_LOCAL_ADRS + LOCAL_MEM_SIZE
![Page 39: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/39.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-39
romStart() - Some do’s and don’ts
• Do not modify code. Functionality is controlled by
modifying configuration macros.
• Code is written in C. Portion which executes in ROM
should be PIC and should use a macro to compute PC
relative addresses when necessary.
• Sequence of execution:
● Copies appropriate ROM image segments to RAM.● Clears portions of RAM not being used (cold boot).● Performs uncompression if required.● Passes control to generic pre-kernel code (usrInit()).
• usrInit() stack begins at final relocation address and
grows away from relocated image.
• romStart() code in Appendix C.
![Page 40: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/40.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-40
Pre-Kernel Initialization - BootSpecific Code
Boot Specific vs. Generic Code
romInit.s : romInit()
PIC and VxWorks
bootInit.c : romStart()
5.5 sysALib.s : sysInit()
![Page 41: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/41.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-41
sysInit() Basics
• Entry point for loadable VxWorks images. Processor is
jumped to sysInit() after image is loaded into RAM.
• sysInit() resides at the load address for loadable
VxWorks images RAM_LOW_ADRS.
• Performs minimum required setup to execute usrInit().The remainder of hardware initialization is performed
by generic pre-kernel code.
• Performs all the functions of romInit() except for
memory system initialization.
• Routine is written in assembly language and resides in
file sysALib.s.
• For loadable images it is assumed that the memory system has been
initialized prior to loading VxWorks.
• Memory used by the VxWorks boot image is reclaimed by the loaded
image and incorporated into the system memory pool later in the
initialization sequence of the loaded image.
![Page 42: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/42.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-42
sysInit() Code
• Routine must:
● Mask processor interrupts and reset processor.● Initialize stack pointer and other registers to begin
executing usrInit() and passing the boot type.
• Hardware initialization completed in sysHwInit().
• Once romInit() code has been written, it will only need
to be modified to create sysInit():
● Memory initialization code removed.● Upon completion jump to usrInit() not romstart().● Code executes in RAM, does not need to be PIC.
• Linked into all VxWorks image types but only executed
for loadable images.
• sysInit() is linked into all VxWorks images through the macro
MACH_DEP which also links code from sysLib.c which is required for all
VxWorks image types.
• The final link rule for the default (loadable) image is:
$(LD) $(LDFLAGS) -e $(SYS_ENTRY) $(LD_LOW_FLAGS) \ -o vxWorks dataSegPad.o vxWorks.tmp ctdt.o
• SYS_ENTRY is defined as _sysInit in defs.bsp.
• sysALib.s and sysLib.c code is linked into vxWorks.tmp using
MACH_DEP.
![Page 43: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/43.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-43
Stack Initialized by sysInit()
• Stack for usrInit() set up by sysInit() grows away from
VxWorks image to lower addresses in memory.
• Must be accounted for when determining load address
for VxWorks image.
• Memory between RAM_LOW_ADRS and
LOCAL_MEM_LOCAL_ADRS contains parameters which
should not be over-written by the stack for usrInit()(which never returns). Some of these parameters are
target environment specific others are generic:
● Exception description message.● Shared memory anchor address.● Boot line.
• The routine usrInit() does not return. It’s stack is used until the kernel is
activated.
![Page 44: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/44.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-44
RAM Layout
LOCAL_MEM_LOCAL_ADRS
RAM_LOW_ADRS
VxWorks
Initial Stack
sysPhysMemTop()
• Figure not to scale.
• Figure represents RAM layout after loadable image has been relocated.
![Page 45: 05_preKernelBoot.pdf](https://reader033.vdocuments.us/reader033/viewer/2022051820/552a9df355034698428b469a/html5/thumbnails/45.jpg)
Wind River SystemsTornado BSP Training Workshop © Copyright Wind River Systems 5-45
Summary
• Details of pre-kernel initialization depend on VxWorks
image type.
• VxWorks image type specific code:
● romInit()● romStart()● sysInit()
• romInit() and romStart() execute for all images
“burned” into ROM.
• sysInit() only executes for loadable VxWorks images.
• Next stage of pre-kernel initialization (following
romStart() or sysInit()) is the generic routine usrInit().