02 - VxWorks-BSP & Boot Sequcence
02 - VxWorks-BSP & Boot Sequcence
Session Speaker
B.N.Shobha
M.S Ramaiah School of Advanced Studies - Bangalore 1
Session Objectives
PEMP ESD531
To discuss general principles involved in booting a system and in VxWorks To motivate and clarify the transfer of control from hardware, to firmware, to software during system boot. To discuss Board Support Package concept in VxWorks To understand memory management and cross development in VxWorks
Session Topics
General Boot Sequence Memory Layout in VxWorks Tornado directory Structure BSP organization VxWorks Images Booting process in VxWorks Cross-development
PEMP ESD531
Boot Process
PEMP ESD531
BIOS reads the boot sector of the boot disk (floppy, hard disk, , according to the BIOS parameter setting) Floppy: the first sector Hard disk: the first sector is the master boot record (MBR) stored the information about how a hard disk has been partitioned. boot sector ends with 0xAA55 Load the boot sector (512 bytes), which will contain program code for loading the operating system kernel
0x000 JMP 0x03E 0x003 Disk parameters 0x03E Program code loading the OS kernel 0x1FE 0xAA55 Boot Sector (Floppy)
4
MBR
PEMP ESD531
A small program that reads the partition table Checks which partition is active (i.e. bootable) Reads the boot sector of active partition (boot sector-contains another small program that reads the first part of the OS stored on that partition) jump into the boot sector at offset 0 The original partitioning scheme for PC hard disk allowed only four primary partitions (too little in real-life) only 4 partition entries. Each entry is 16 bytes
Code for loading the boot sector of the active partition 0x1BE 0x010 Partition 1 0x1CE 0x010 Partition 2 0x000 0x1BE 0x1DE 0x010 0x1EE 0x010 0x1FE 0x002 Partition 3 Partition 4 0xAA55
5
MBR
PEMP ESD531
Solution = Extended partition (EP) : allows partitioning a primary partition into sub-partitions Sub-partitions are logical partitions and behave like primary partitions but are created differently The first sector of extended partition is same as MBR The first partition entry is for the first logical drive, yhe second partition entry points to the next logical drive The first sector of each PP or EP contains a boot sector
MBR Boot Sector Data area of PP-1 EP Boot Sector Data area of PP-3 Boot Sector Data area of PP-4
M.S Ramaiah School of Advanced Studies - Bangalore 6
Boot Sector Unused Boot Sector Data area of LP-1 Unused Boot Sector Data area of LP-2
PEMP ESD531
System code: 0x83 Linux, 0x82: swap, 0x05: extend End: head number CYL End: sector and cylinder number of boot sector high byte high byte Relative sector number of start sector Number of sectors in the partition
Booting is carried out from the active partition which is determined by the boot flag
M.S Ramaiah School of Advanced Studies - Bangalore 7
Booting a Computer
PEMP ESD531
Switch on. It will check disk drive (floppy or hard disk) Boot sector contains an initial program (bootstrap program) which is run to initialize all aspects of the system - CPU registers, device controllers, memory contents. The bootstrap program locates the OS kernel and loads it into memory. The OS then starts executing the first process and waits for some event to occur. The occurrence of an event is usually signaled by an interrupt from either the hardware or the software. Hardware may trigger an interrupt by sending a signal to the CPU via the system bus. Software may trigger an interrupt by executing a special operation called a system call.
M.S Ramaiah School of Advanced Studies - Bangalore 8
PEMP ESD531
VxWorks is a modular design which isolates all hardwarespecific functionality into a set of libraries called the Board Support Package(BSP). BSP for short, it is a software-only layer (hardware dependent) These libraries provide an identical software interface to the hardware of all boards. A Board + its BSP = standard platform for an O/S (hardware independent) They include facilities for hardware initialization, interrupt handling, hardware clock and timer control, mapping of local and bus memory, memory sizing.
Power On Reset
PEMP ESD531
CPU Self initialization Addressing Control Random Access Memory C code setup Initialize Interrupt System
Start device
Start Application
10
PEMP ESD531
BSP - Equivalent of a lower O/S layer. It provides a standard set of capabilities for the main higher O/S to run on eg. memory, communications, and other device interfaces It provides a controlled startup sequence from power-on / reset (the bootstrapping process) includes the pre-kernel initialization and starting up the kernel itself Provides a set of switches to turn on/off different capabilities of and to the O/S. All the switches together represent the standard platform and its allowed variants The ON switches represent capabilities on the board and O/S
M.S Ramaiah School of Advanced Studies - Bangalore 11
PEMP ESD531
It provides a controlled startup sequence from power-on / reset for the devices to be initialized, and started up as usable devices to the O/S and application It provides a framework for each of the devices driver code to be included It uses the corresponding device drivers code for this process The controlled start-up sequence ensures a sane environment which is progressively built up to full capability of the board
12
PEMP ESD531
host /usr/wind
share Shared XDR code target VxWorks OS. Board Support Package
13
PEMP ESD531
host
GUI, Tcl and Help supports files Standard Tcl distribution UNIX man pages on Tornado tools Source for VxColor demo.
14
PEMP ESD531
target
config Files to configure and build VxWorks all Generic configuration files. bsp-name Board Support Package (BSP) h VxWorks header files lib Libraries provided by VxWorks man UNIX man pages src Partial VxWorks source code. unsupportedTools, drivers
15
Libraries
PEMP ESD531
VxWorks routines are grouped into libraries. Each library has corresponding include file(s). Examples: Library Routine Include file(s) ------------------------------------taskLib taskSpawn taskLib.h memPartLib malloc stdLib.h semLib semTake semLib.h lstLib lstGet lstLib.h sockLib send types.h, socket.h sockLib.h
16
PEMP ESD531
17
PEMP ESD531
We are porting VxWorks to a new target board VxWorks and the Tornado debugger are already available for the target processor / architecture Tornado and VxWorks development capability is already available for the host Reference BSP on same processor / architecture Device driver code for devices on board BSP template for processor architecture
18
PEMP ESD531
Primary BSP files: - Source files. - Include files. - Make files. Source files: - Generic code is written in C. Architecture specific and - performance optimized code is assembly. Include files: - All includes and definitions specific to a CPU board are localized in two files. Make file: - Controls building of all images
19
PEMP ESD531
target/config/all/configAll.h specifies default, or base configuration which applies to all boards. Modifying this file is discouraged. target/config/bsp/config.h extends or overrides the defaults specified in configAll.h for the particular board BSP. Modify this file to change the VxWorks image for this board. target/config/bsp/<bspname>.h is a BSP specific header of static constructs
20
Booting
PEMP ESD531
Hardware must first be configured: VxWorks Boot ROMs replace board manufacturers ROMs. Jumpers (etc.) set as described in target\config\bsp\target.txt. VxWorks Boot ROMs enable: Setting boot parameters via a serial connection. Downloading & executing VxWorks image. Booting scenarios: ethernet serial BOOTP / TFTP shared memory network local disk
M.S Ramaiah School of Advanced Studies - Bangalore 21
PEMP ESD531
sysInit
romStart bootInit.c
C code setup
usrInit usrConfig.c
Initialize Interrupt System sysLib.c Calls for rest of the sequence Application
22
PEMP ESD531
2. romStart(): File -> bootInit.c a. copy text and data segment from ROM to RAM b. clear memory c. decompress image d. if (i960) invoke sysInitAlt() else usrInit()
M.S Ramaiah School of Advanced Studies - Bangalore 23
PEMP ESD531
3. usrInit(): File -> usrConfig.c a. if (SPARC) initialize register window management b. if (MIPS) sysGpInit() to initialize global pointer: File -> bootInit.c c. zero bss (uninitialized data) File -> usrConfig.c d. save bootType in sysStartType e. intVecBaseSet() to set vector base table: f. excVecInit() to initialize all system and default interrupt vectors g. excShowInit() to initialize exception show utility h. sysHwInit() to initialize board dependent hardware: File -> sysLib.c I. usrKernelInit() to initialize the wind kernel: File -> target/src/config/usrKernel.c j. Enable instruction/data cache if applicable k. kernelInit()
24
PEMP ESD531
5 usrRoot(): File -> bootConfig.c {initialize I/O sub-system; install drivers; create devices; setup network as necessary for the particular configuration; may also create the system symbol table if one is to be included; Spawn the boot command loop task a.memInit(): initialize memory pool b.sysClkConnect(): set up system timer :File -> sysLib.c c.sysClkRateSet() d.sysClkEnable() e.sysProcNumSet(): set unique processor number for the board f. iosInit(): Initialize I/O system.
25
PEMP ESD531
ROM
0xFF8x xxxx =
Bootstrap data Bootstrap text
binArrayStart
1 MB Board
USER_RESERVED_ME M
ROM IMAGE
0x0009 0000
0
= RAM_HIGH_ADRS
STACK SAVE
RAM
= FREE_RAM_ADRS
0x0000 1000
0 RESERVED
0x0000 0000
= LOCAL_MEM_LOCAL_ADRS
26
Memory Layout
PEMP ESD531
The data segment of a ROM-resident standalone VxWorks system is loaded at low address to minimize fragmentation. The data segment of the ROM-resident boot ROMs is loaded at high address so that loading VxWorks does not overwrite the resident boot ROMs.
Types of VxWorks VxWorks Boot Program Images Tornado Standalone ROMable _ vxWorks.st_rom bootrom compressed ROMable vxWorks_rom _ bootrom_uncmp uncompressed ROM vxWorks.res_rom_nosym vxWorks.res_rom bootrom_res resident Downloadable vxWorks vxWorks.st _ uncompressed
M.S Ramaiah School of Advanced Studies - Bangalore 27
Memory Layout
PEMP ESD531
LOCAL_MEM_LOCAL_AD RS RAM_LOW-ADRS
VxWorks
FREE_RAM_ADRS WDB_POOL_SIZE SYSTEM MEMORY POOL sysMemTop( ) USER_RESERVED_MEM sysPhysMemTop( )
28
PEMP ESD531
A pool of memory on the target reserved for use by the Tornado tools : Dynamic loading of object modules. Spawning task from WindSh or CrossWind. Creation of variables from WindSh. The initial size of the target server memory pool is configured by WDB_POOL_SIZE. The default is 1 / 16 of sysMemTop( ) - FREE_RAM_ADRS. Additional memory is silently allocated from the system memory pool, if needed.
29
PEMP ESD531
Initialized at system startup. Can modify USER_RESERVED_MEM to reserve memory for application-specific use. May need to modify sysPhysMemTop( ) (or just LOCAL_MEM_SIZE) when adding memory to your board. To add off board memory : void memAddToPool (pPool, poolSize) pPool must be the local address of the memory.
M.S Ramaiah School of Advanced Studies - Bangalore 30
PEMP ESD531
To dynamically allocate memory : void *malloc (nBytes) Returns a pointer to the newly allocated memory or NULL on error. Uses first-fit algorithm. Free memory is stored in a linked list. Some (small) overhead for each malloc( ). To release allocated memory : void free (ptr) Adjacent blocks are coalesced.
M.S Ramaiah School of Advanced Studies - Bangalore 31
Debugging Options
PEMP ESD531
Default malloc( ) debugging : If request too large, log an error message. Default free( ) debugging : Check block for consistency If corrupted: suspend task, log error message. Can change default debugging options with : void memOptionsSet (options) Options can be : + MEM_ALLOC_ERROR_LOG_FLAG - MEM_ALLOC_ERROR_SUSPEND_FLAG + MEM_BLOCK_CHECK + MEM_BLOCK_ERROR_LOG_FLAG + MEM_BLOCK_ERROR_SUSPEND_FLAG
32
Examining Memory
PEMP ESD531
Use the browser. Enter the memory partition ID in the Show box.
mv152-external@mekong: Total bytes Allocated blocks bytes Free blocks bytes Cummulative blocks bytes Free List 0 addr size 1 addr size Mempart Ox
= = = = = = = = = = =
Free List
PEMP ESD531
void *calloc(nElems, size ) Allocate zeroed memory for an array. void *realloc(ptr,newSize) int memFindMax( ) Resize an allocated block. The block may be moved. Returns the size of the largest free block in system memory.
High level routines like malloc( ) and free( ) call lower level routines, specifying the system memory pool.
M.S Ramaiah School of Advanced Studies - Bangalore 34
PEMP ESD531
PART_ID memPartCreate (pPool, size) pPool size Pointer to memory for this partition Size of memory partition in bytes. Returns a partition id (PART_ID) or NULL or error. The memory for this partition (pPool) may be taken from : A separate memory board. A block allocated from the system memory partition. The top of the CPU boards RAM.
35
PEMP ESD531
System partition management routines call routines listed below, specifying the PART_ID as memSysPartId.
Generic memPartAlloc( ) memPartFree( ) memPartShow( ) memPartAddToPool( ) memPartOptionsSet( ) memPartRealloc( ) memPartFindMax( ) System Memory Pool malloc( ) free( ) memShow( ) memAddToPool( ) memOptionsSet( ) realloc( ) memFindMax( )
36
PEMP ESD531
37
PEMP ESD531
Not all BSPs will support all of these images. Some BSPs support additional images. Standalone VxWorks has a target shell and built-in symbol table. Network support is included but not initialized. The file target\h\make\rules. BSP has the make rules for building these images.
38
PEMP ESD531
The project facility can build the following VxWorks image in a bootable project: Downloadable image: vxWorks: does not contain within it the bootstrap code to copy itself out of ROM into RAM. ROMable image: vxWorks_rom : uncompressed copies VxWorks, from ROM to RAM vxWorks.st_rom:(Compress): ROM is less vxWorks.res_rom:(Resident): When RAM less - text in ROM rest in RAM Boot ROM image: executes in ROM
39
PEMP ESD531
The configuration of the VxWorks images you build is governed by information from three sources: target\config\all\configAll.h default base configuration target\config\bsp\config.h board specific configuration The Project tool, if used.
M.S Ramaiah School of Advanced Studies - Bangalore 40
PEMP ESD531
Cross-Development
41
WindSh
Interactive C-expression interpreter allows : Accessing all VxWorks facilities. Invoking any subroutine in memory. Creating and examining variables. Automating interactions with target. Defining user commands Interactive Tcl interpreter allows : For UNIX hosts, invoke from the Launcher.(UNIX Hosts) For PC host, invoke from the Tornado development environment Tools menu or the launch toolbar.(PC Host)
M.S Ramaiah School of Advanced Studies - Bangalore
PEMP ESD531
42
PEMP ESD531
WindSh uses the target servers system symbol table and the following rules to interpret an expression : retVal = printf (Foo is %d\n, foo) i (tWdbTask) 1. Look for symbol in the symbol table. 2. Look for _symbol in the symbol table. 3. Create symbol if it is to the left of a = and does not exist in the symbol table. 4. Convert a task name to a task ID. 5. If you do not specify one of the arguments to a function, the Shell will pass a zero. Some common commands are WindSh built-ins and not functions.
M.S Ramaiah School of Advanced Studies - Bangalore 43
WindSh as a C Interpreter
Shell command syntax is generally the same as the C programming language. -> x = (8 * 6) / 4 x=0x20ff378: value = 12 = 0xc
PEMP ESD531
-> name = Nelson new symbol name added to symbol table. name = 0x23fe798: value = 37742504 = 0x23fe7a8 = name + 0x10 -> printf (Hello %s, number is %d.\n, name, 0x20) value = 29 = 0x1d -> x x = 0x20ff378: value = 12 = 0xc
M.S Ramaiah School of Advanced Studies - Bangalore
44
PEMP ESD531
History mechanism like UNIX Korn Shell. Type h to see previous commands. Press esc to toggle from input to edit mode. Leave edit mode by pressing esc or return. Editing mode uses vi - like commands , including : h j k l
45
PEMP ESD531
Reboot VxWorks (trap to the boot ROMs). Temporarily suspend terminal output. Resume terminal output. Toggle between regular input mode and K-shell edit mode.
46
PEMP ESD531
WindSh provides common commands needed for development: sp Create a task with default options. td Delete a task. ts / tr Suspend / resume a task. b Set or display break point. s Step a task. c Continue a task. tt Trace a tasks stack. i / ti Give (detailed) task information. ld/unld Load / unload a module. browse Display object information in Browser. show Display object information in WindSh.
47
Shell Redirection
PEMP ESD531
Shell input can be redirected to come from a file. -> < script Shell output can be redirected to a file. -> h( ) > hFile Caveat: I/O can only be redirected to devices accessible to the WindSh process running on the development host, not local devices on the target !
48
WindSh Debugging
Can debug target resident tasks from WindSh: Set and remove breakpoints b, bd, bdall Single step s, so Disassemble code l Trace a tasks stack tt Resume execution c
PEMP ESD531
Debugging is done at the assembly code level. Use remote debugger for source-level debugging. See the windsh appendix to the Tornado Users Guide for information on these (and other) windsh primitives.
M.S Ramaiah School of Advanced Studies - Bangalore 49
Debugging Example
Example:
PEMP ESD531
-> b (printf) -> sp (stuff) task spawned: id = 0x23e0a3c, name = t3 value = 37620284 = 0x23e0a3c Break at 0x2005f78: _printf Task: 0x23e0a3c (t3) -> tt( ) 20461b8 _vxTaskEntry+10: _stuff (0, 0, 0, 0, 0, 0, 0, 0, 0, 0) 23feb4a _stuff +12: func1 (1) 23febf2 _func1 +18: _printf (23fec39, 23fec2e) value = 0 = 0x0 If a task halts unexpectedly, tt( ) can be used to find out what routine failed.
M.S Ramaiah School of Advanced Studies - Bangalore 50
Summary
PEMP ESD531
Boot sector of bootable device will load the kernel image in the main memory VxWorks is a modular design which isolates all hardwarespecific functionality into a set of libraries called the Board Support Package(BSP). The data segment of a ROM-resident standalone VxWorks system is loaded at low address to minimize fragmentation WindSh provides common commands needed for development Shell command syntax is generally the same as the C programming language A pool of memory on the target reserved for use by the Tornado tools
51