1、Makefile及Bootloader源代码结构vBootloader源代码结构vMakefile-mapcs-32:生成可以运行在具有32位程序计数器的处理器上的目标文件,并且遵循APCS-32函数调用标准。-mcpu=strongarm110:目标处理器是strongarm110MakefileCC=/usr/local/hybus-arm-linux-R1.1/bin/arm-linux-gccOBJCOPY=/usr/local/hybus-arm-linux-R1.1/bin/arm-linux-objcopyINCLUDE=-I./includeCFLAGS=-O2-nostdin
2、c-mcpu=strongarm110-mapcs-32-fomit-frame-pointer-fPIC$(INCLUDE)-Wall$(CFLAGSII)OCFLAGS=-O binary-R.note-R.comment SLDFLAGS=-static nostdlibELF32_LDFLAGS=-Wl,-T ld-xscaleCOMPILE=$(CC)$(CFLAGS)CFILES=$(wildcard*.c)SFILES=$(wildcard*.S)OBJ_FILES=$(SFILES:%.S=%.o)$(CFILES:%.c=%.o)BIN_FILE=x-boot255all:$
3、(OBJ_FILES)$(CC)$(LDFLAGS)-o$(BIN_FILE)-elf32$(ELF32_LDFLAGS)$(OBJ_FILES)lgcc$(OBJCOPY)$(OCFLAGS)$(BIN_FILE)-elf32$(BIN_FILE)ELF文件格式vELF Executable&Linkable Formatv三种类型可重定位目标文件(relocatable object):保存着代码和适当的数据,用来和其他目标文件一起创建一个可执行文件或目标文件可执行文件(executable):保存着代码和适当的数据,是一个可执行的程序;exec用来它创建进程映像共享目标文件(shared
4、 object):保存着代码和适当的数据。相当于Windows的DLL。从不同角度观察ELF文件格式几个重要的sectionvAn object file written by as has at least three sections,any of which may be empty.These are named text,data and bss sections.text-程序的“text”或可执行指令,相当于RO。.data-程序的初始化数据,相当于RW。.bss-未初始化数据。该section不占文件空间,相当于ZI。当程序运行时,系统初始化这些数据为0。vWithin the
5、 object file,the text section starts at address 0,the data section follows,and the bss section follows the data section.rodata段v.rodata 保存着只读数据,在进程映像中构造不可写的段。系统自动生成v生成最终的可执行文件时,仅连接.text,.rodata,.data,.bss段。一般.rodata连接到.text段中。用readelf查看文件格式vreadelf a main.o用objdump查看ELF文件格式vobjdump h main.old连接工具和连接
6、脚本vThe main purpose of the linker script is to describe how the sections in the input files should be mapped into the output file,and to control the memory layout of the output file.vOUTPUT_ARCH(arch)Specify a particular output machine architecture.vENTRY(symbol)定义程序入口点vSECTIONS The SECTIONS command
7、 tells the linker how to map input sections into output sections,and how to place the output sections in memory.v一个连接脚本文件-ldxscale:ENTRY(_start)OUTPUT_FORMAT(elf32-littlearm,elf32-littlearm,elf32-littlearm)OUTPUT_ARCH(arm)SECTIONSldxscale文件SECTIONS .=ALIGN(4);.text 0 xA4000000-0 x80000:_ld_text_star
8、t=.;*(.text)*(.got)*(.got.pld)*(.rodata)_ld_text_end=.;_ld_text_size=SIZEOF(.text);.=ALIGN(4);.data _ld_text_end:AT(ADDR(.text)+SIZEOF(.text)_ld_data_start=.;*(.data)_ld_data_end=.;_ld_data_size=SIZEOF(.data);_ld_text_and_data_size=SIZEOF(.text)+SIZEOF(.data);.=ALIGN(4);.bss:_ld_bss_start=.;*(.bss)*(COMMON)_ld_bss_end=.;_ld_bss_size=SIZEOF(.bss);_ld_stack_address=_ld_text_start+0 x80000;用objdump查看最终的文件vobjdump h x-boot255