我是用的是6410的板子(128MBDDR,256MBnand)。
里面有我的一些注释,希望大家一起学习交流学习。
编译通过的话,烧写到要从nand的0地址开始,这与6410板子的启动有关系,具体自己看一些书籍查询。
/*Makefile*/
CC := arm-linux-gcc
AS := arm-linux-as
LD := arm-linux-ld
OBJCOPY := arm-linux-objcopy
BIN := arm.bin
ELF := arm
OBJS := start.o main.o
all:$(ELF)
$(OBJCOPY) $< -O binary /tftpboot/$(BIN)
#-Ttext指定程序的人口地址是在nand地址的0
$(ELF):$(OBJS)
$(LD) $^ -o $@ -Ttext 0
%.o:%.c
$(CC) $< -c -o $@
%.o:%.s
$(AS) $< -o $@
.PHONY:clean
clean:
rm -rf $(OBJS) $(ELF)
/*start_led.s*/
.align 2
.global _start,start,loop,delay1
.text
_start:
mov r0,#0x70000000 @外围寄存器的基地址
orr r0,#0x13 @外围寄存器的大小size=0x13 = 256M
mcr p15,0,r0,c15,c2,4 @告诉处理器访问外围存储器的大小(MMU)
ldr r0,=0x7e004000 @门狗定时器控制寄存器,关闭。
ldr r1,[r0]
bic r1,#(1 << 5)
str r1,[r0]
@mov sp,#0x2000 @初始化栈指针,(6410板子内置DROM = 8K)
ldr r0,=0x7f008820 @GPMCON
ldr r2,[r0] @read the value
ldr r1,=(~0xffff) @r1 = ~0xffff
and r2,r1 @clear the 16bits(4 leds)
ldr r1,=0x1111 @enable the GPMCON(16bits) as output
orr r2,r1
str r2,[r0] @write in the GPMCON
ldr r0,=0x7f008824 @GPMDAT
ldr r2,[r0] @read the GPMDAT old value
mov r1,#0xf
orr r2,r1 @off the leds
str r2,[r0] @write new value in the GPMDAT
start: @after led on 4 leds,init r5 to the first led
mov r5,#0 @r5 is about which leds is on
loop:
cmp r5,#4
beq start
mov r1,#1
ldr r0,=0x7f008824 @the r5 led on
ldr r2,[r0]
bic r2,r1,lsl r5
str r2,[r0]
mov r3,#0
bl delay1
ldr r2,[r0] @the r5 led off,then the led right move
orr r2,r1,lsl r5
str r2,[r0]
add r5,#1;
b loop
delay1:
nop;
add r3,#1
ldr r4,=0xffff
cmp r3,r4
moveq pc,lr
b delay1