使用GNUbinutils制作二进制文件.doc_第1页
使用GNUbinutils制作二进制文件.doc_第2页
使用GNUbinutils制作二进制文件.doc_第3页
使用GNUbinutils制作二进制文件.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

使用GNU binutils制作二进制文件2008-02-18 21:51因为自己制作的IXP425的板子能够跑uboot却不能引导Linux内核,连Uncompressing的字样也没有打出来。于是在内核head.S中初始化串口以后加入打印出简单字符的debug语句,也未见打印。为了确认跳转是否成功,于是想直接编写简单的程序,制作成二进制文件进行测试。二进制程序文件,是cpu可以直接执行的文件,就像bootloader一样,如果将它存放到系统加点自动执行指令的地址,cpu就能执行文件。一般编译器完成编译链接以后生成的都是某种可执行文件格式,如linux下的ELF,a.out等,windows下则是PE(Portable Executibal)格式。本程序在redboot和IXDPG425上测试通过。Redboot load -r -v -b 000800000 test.binRedboot go 000800000Hello world 0123!1、编写代码测试代码来源于u-boot,利用u-boot中的printf函数,打印出hello world字样。将printf函数所有相关的函数,头文件等全部取出放到自己新建的源文件中。例如我新建了printf.c文件,存放了所有从u-boot源代码里拷贝过来的c语言代码,并添加了一个简短的调用过程:int _main(void)int i = 0123;printf(“Hello World 0x%xn”, i);return 1;编写一个简单的head.S,跳转入_main.section “.start”, #alloc, #execinstr.alignstart:.type start,#functionb _main2、链接脚本test.lds修改自linux2.4.x/arch/arm/boot/compressed/vmlinux.ldsOUTPUT_FORMAT(”elf32-bigarm”, “elf32-bigarm”, “elf32-bigarm”)OUTPUT_ARCH(arm)/*ENTRY(_start)*/SECTIONS. = 0800000;.text : *(.start)*(.text)*(.fixup)*(.gnu.warning)*(.rodata)*(.rodata.*)*(.glue_7)*(.glue_7t). = ALIGN(4);_etext = .;_got_start = .;.got : *(.got) _got_end = .;.got.plt : *(.got.plt) .data : *(.data) _edata = .;. = ALIGN(4);_bss_start = .;.bss : *(.bss) _end = .;.stack (NOLOAD) : *(.stack) .stab 0 : *(.stab) .stabstr 0 : *(.stabstr) .stab.excl 0 : *(.stab.excl) .stab.exclstr 0 : *(.stab.exclstr) .stab.index 0 : *(.stab.index) .stab.indexstr 0 : *(.stab.indexstr) .comment 0 : *(.comment) . = 000800000指定了程序被加载的地址,如果将其指定为0,则可以像bootloader一样,将其烧到flash的0地址,上电后cpu自动执行。3、编译链接参照u-boot和linux的编译printf.c:arm-linux-gcc -g -Os -fno-strict-aliasing -fno-common -ffixed-r8 -mshort-load-bytes -msoft-float -mbig-endian -D_KERNEL_ -DTEXT_BASE=000f80000 -I./ -I/home/tony/intel/uboot/u-boot-1.1.2/include -fno-builtin -ffreestanding -nostdinc -isystem /usr/local/lib/gcc-lib/arm-linux/3.2.1/include -pipe -DCONFIG_ARM -D_ARM_ -mbig-endian -mapcs-32 -march=armv4 -mtune=strongarm1100 -Wall -Wstrict-prototypes -c -o printf.o printf.chead.S:arm-linux-gcc -mbig-endian -D_ASSEMBLY_ -D_KERNEL_ -I/home/tony/intel/snapgear/snapgear/linux-2.4.x/include -mapcs-32 -D_LINUX_ARM_ARCH_=5 -mcpu=xscale -msoft-float -traditional -c -o head.o head.S下面几个文件也是上述代码所依赖的,在作除法运算是需要用到div0.carm-linux-gcc -g -Os -fno-strict-aliasing -fno-common -ffixed-r8 -mshort-load-bytes -msoft-float -mbig-endian -D_KERNEL_ -DTEXT_BASE=000f80000 -I./ -I/home/tony/intel/uboot/u-boot-1.1.2/include -fno-builtin -ffreestanding -nostdinc -isystem /usr/local/lib/gcc-lib/arm-linux/3.2.1/include -pipe -DCONFIG_ARM -D_ARM_ -mbig-endian -mapcs-32 -march=armv4 -mtune=strongarm1100 -Wall -Wstrict-prototypes -c -o div0.o div0.c_udivsi3.S:arm-linux-gcc -Wa,-gstabs -D_ASSEMBLY_ -g -Os -fno-strict-aliasing -fno-common -ffixed-r8 -mshort-load-bytes -msoft-float -mbig-endian -D_KERNEL_ -DTEXT_BASE=000f80000 -I/home/tony/intel/uboot/u-boot-1.1.2/include -fno-builtin -ffreestanding -nostdinc -isystem /usr/local/lib/gcc-lib/arm-linux/3.2.1/include -pipe -DCONFIG_ARM -D_ARM_ -mbig-endian -mapcs-32 -march=armv4 -mtune=strongarm1100 -c -o _udivsi3.o _udivsi3.S_umodsi3.S:arm-linux-gcc -Wa,-gstabs -D_ASSEMBLY_ -g -Os -fno-strict-aliasing -fno-common -ffixed-r8 -mshort-load-bytes -msoft-float -mbig-endian -D_KERNEL_ -DTEXT_BASE=000f80000 -I/home/tony/intel/uboot/u-boot-1.1.2/include -fno-builtin -ffreestanding -nostdinc -isystem /usr/local/lib/gcc-lib/arm-linux/3.2.1/include -pipe -DCONFIG_ARM -D_ARM_ -mbig-endian -mapcs-32 -march=armv4 -mtune=strongarm1100 -c -o _umodsi3.o _umodsi3.S链接:arm-linux-ld -p -X -T test.lds h

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论