/*
*************************************************************************
*
* Jump vector table as in table 3.1 in [1]
*
*************************************************************************
*/
.globl _start
_start: b start_code
_TEXT_BASE:
.word TEXT_BASE
.globl _armboot_start
_armboot_start:
.word _start
/*
* These are defined in the board-specific linker script.
*/
.globl _bss_start
_bss_start:
.word __bss_start
.globl _bss_end
_bss_end:
.word _end
start_code:
/* Set up the stack */
stack_setup:
ldr r0, =TEXT_BASE /* upper 128 KiB: relocated uboot */
sub r0, r0, #CONFIG_SYS_MALLOC_LEN /* malloc area */
sub sp, r0, #12 /* leave 3 words for abort-stack */
bic sp, sp, #7 /* 8-byte alignment for ABI compliance */
clear_bss:
ldr r0, _bss_start /* find start of bss segment */
ldr r1, _bss_end /* stop here */
mov r2, #0x00000000 /* clear */
clbss_l:str r2, [r0] /* clear loop... */
add r0, r0, #4
cmp r0, r1
ble clbss_l
bl bootstrap_main
堆栈段初始化
其中TEXT_BASE和#CONFIG_SYS_MALLOC_LEN变量是在makefile文件中定义的,如下:
# Set the stack top base address here
TEXT_BASE=0x31000000
STACK_BASE=0x31010000
MALLOC_SIZE=0x100000
CFLAGS+=-DTEXT_BASE=$(TEXT_BASE) -DSTACK_BASE=${STACK_BASE} -DCONFIG_SYS_MALLOC_LEN=${MALLOC_SIZE}
上面的CFLAGS一行中的-D的意思类似于#define,,例如-DTEXT_BASE=$(TEXT_BASE) 等于#define TEXT_BASE 0X31000000。.
BSS段初始化
Bss段初始化代码其中的_bss_start ---> __bss_start是在makefile文件中
APP_NAME=bootstrap
LDFLAGS=-Bstatic -T$(APP_NAME).lds -Ttext $(TEXT_BASE)
参数LDFLAGS依赖于文件bootstrap.lds文件,如下
/********************************************************************************************
* File: bootstrap.lds
* Version: 1.0.0
* Copyright: 2011 (c) Guo Wenxue <guowenxue@gmail.com>
* Description: This is the LD linker configure script for bootstrap
* ChangeLog: 1, Release initial version on "Tue Jul 12 16:43:18 CST 2011"
*
*******************************************************************************************/
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS{
. = ALIGN(4);
.text :
{
start.o (.text)
*(.text)
}
. = ALIGN(4);
.rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }
. = ALIGN(4);
.rodata : { *(.rodata) }
. = ALIGN(4);
.data : { *(.data) }
. = ALIGN(4);
__bss_start = .;
.bss : { *(.bss) }
_end = .;
}
然后是跳转到c函数中的bootstarp_main()函数中去,bootstarp_main()函数如下:
位置:yaffs2/bootstrap.c
int bootstrap_main(void)
{
char *ptr = NULL;
int rv = -1;
console_serial_init();
printf("\b\n");
printf("\bBootstrap nandflash yaffs2 test Version 0.0.1\n");