目的:学习linxu编程,用bootloader跳转实现系统的运行。
skyeye:1.2.6版本
1.下载HelloWorld on Skyeye 源码
http://download.pudn.com/downloads75/sourcecode/unix_linux/119128673Hello4Skyeye.rar
2.修改代码
2.1 修改hello.c
[root@localhost Hello4Skyeye]# cat hello.c
/*
* hello.c
* just a function used to output "helloworld" to uart
*
* author: SU Hang
* date: 2004-08-28
*/
void hello(void)
{
int i;
char * hellostr="helloworld";
long* paddr=(long*)0x50000020; //这里的0x50000020 为2440 UTXH0端口地址
for(i=0;i<10;i++)
{
* paddr=hellostr[i];
}
return;
}
2.2修改hello.lds
[root@localhost Hello4Skyeye]# cat hello.lds
/*
* hello.lds
* ld script for helloforSkyeye
*
* author: SU Hang
* Date: 2004-08-28
*/
OUTPUT_ARCH(arm)
ENTRY(begin)
SECTIONS
{
. = 0x31000000; //修改程序的起始地址,这里设置成0x31000000
.text :
{
*(.text)
*(.rodata)
}
. = ALIGN(8192);
.data : {*(.data)}
.bss : {*(.bss)}
/* Stabs debugging sections. */
.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) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_info 0 : { *(.debug_info) }
.debug_line 0 : { *(.debug_line) }
.debug_pubnames 0 : { *(.debug_pubnames) }
.debug_aranges 0 : { *(.debug_aranges) }
}
2.3 修改makefile
[root@localhost Hello4Skyeye]# vi makefile
#
#makefile for helloforSkyeye
#
#author: SU Hang
#Date: 2004-08-28
#begin
CC=arm-linux-gcc
LD=arm-linux-ld
CFLAGS= -c -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -pipe -g -mapcs-32 -march=armv4 -mtune=arm7tdmi -mshort-load-bytes
LDFLAGS= -p -X -Thello.lds
LIB=
all: hello.bin //结果需求bin文件
arm-linux-objcopy --gap-fill=0xff -O binary hello hello.bin //新增 生成bin文件
hello.bin: hello
hello: start.o hello.o
$(LD) $(LDFLAGS) start.o hello.o -o hello
start.o:start.S
$(CC) $(CFLAGS) start.S
hello.o:hello.c
$(CC) $(CFLAGS) hello.c
clean:
rm -rf *.o *.elf *.gdb hello *.r *.n *.s hello.bin
3.编译
[root@localhost Hello4Skyeye]# make clean
[root@localhost Hello4Skyeye]# make
生成hello.bin文件
4.编辑skyeye.conf文件
cpu: arm920t
mach: s3c2440
#physical memory
mem_bank: map=M, type=RW, addr=0x31000000, size=0x04000000,file=hello.bin,boot=yes
mem_bank: map=M, type=RW, addr=0x00000000, size=0x04000000
#all peripherals I/O mapping area
mem_bank: map=I, type=RW, addr=0x48000000, size=0x20000000
mem_bank: map=I, type=RW, addr=0x19000300, size=0x00000020
#net: state=on, type=cs8900a,mac=08:00:3e:26:0a:5b, ethmod=tuntap, hostip=10.0.0.1
#net: type=cs8900a, base=0x19000300, size=0x20,int=9, mac=0:4:3:2:1:f, ethmod=tuntap, hostip=10.0.0.1
#lcd:type=s3c2410x,mod=gtk
#dbct:state=on
hello.bin和skyeye.conf放到同一个文件夹下面;
执行:[root@localhost s3c2440]# skyeye
出现如下结果:
**************************** WARNING **********************************
If you want to run ELF image, you should use -e option to indicate
your elf-format image filename. Or you only want to run binary image,
you need to set the filename of the image and its entry in skyeye.conf.
***********************************************************************
big_endian is false.
arch: arm
cpu info: armv4, arm920t, 41009200, ff00fff0, 2
mach info: name s3c2440, mach_init addr 0x8081b0c
uart_mod:0, desc_in:, desc_out:, converter:
SKYEYE: use arm920t mmu ops
Loaded RAM hello.bin
start addr is set to 0x31000000 by exec file.
helloworldhelloworldhelloworldhelloworldhell
证明hello已经在skyeye虚拟的s3c2440上跑起来了。
5. 使用vivi引导hello.bin
修改skyeye.conf
cpu: arm920t
mach: s3c2440
#physical memory
mem_bank: map=M, type=RW, addr=0x31000000, size=0x04000000,file=hello.bin
mem_bank: map=M, type=RW, addr=0x00000000, size=0x04000000,file=vivi-elf.bin,boot=yes
#all peripherals I/O mapping area
mem_bank: map=I, type=RW, addr=0x48000000, size=0x20000000
mem_bank: map=I, type=RW, addr=0x19000300, size=0x00000020
#net: state=on, type=cs8900a,mac=08:00:3e:26:0a:5b, ethmod=tuntap, hostip=10.0.0.1
#net: type=cs8900a, base=0x19000300, size=0x20,int=9, mac=0:4:3:2:1:f, ethmod=tuntap, hostip=10.0.0.1
#lcd:type=s3c2410x,mod=gtk
#dbct:state=on
执行:[root@localhost s3c2440]# skyeye
[root@localhost s3c2440]# skyeye
**************************** WARNING **********************************
If you want to run ELF image, you should use -e option to indicate
your elf-format image filename. Or you only want to run binary image,
you need to set the filename of the image and its entry in skyeye.conf.
***********************************************************************
big_endian is false.
arch: arm
cpu info: armv4, arm920t, 41009200, ff00fff0, 2
mach info: name s3c2440, mach_init addr 0x8081b0c
uart_mod:0, desc_in:, desc_out:, converter:
SKYEYE: use arm920t mmu ops
Loaded RAM hello.bin
Loaded RAM vivi-elf.bin
VIVI version 0.1.4 (root@localhost.localdomain) (gcc version 2.95.3 20010315 (release)) #0.1.4 Wed Aug 26 23:34:04 CST 2009
Evacuating 1MB of Flash to DRAM at 0x33F00000
MMU table base address = 0x33DFC000
Map flash virtual section to DRAM at 0x33F00000
Succeed memory mapping.
S3C2440 flash: probing 16-bit flash bus
Found default vivi parameters
Press Return to start the LINUX now, any other key for vivi
type "help" for help.
FriendlyARM>
在FriendlyARM下输入
FriendlyARM> go 0x31000000
又看到熟悉的helloworld
FriendlyARM> go 0x31000000
go to 0x31000000
argument 0 = 0x00000000
argument 1 = 0x00000000
argument 2 = 0x00000000
argument 3 = 0x00000000
helloworldhelloworldhelloworldhellow