ARM-uboot介紹以及基於uboot編程
1. uboot介紹
是製作bootloader的源碼集合,在arm的板子上所有的bootloader都是由uboot做出來的。
2. uboot的作用
引導和加載操作系統內核,本身不屬於操作系統,是在操作運行之前執行的一小段代碼,爲操作系統的運行提供硬件環境。
3. 基於uboot編寫helloworld程序
#define printf(...) (((int (*) (const char *, ...))0x43e11a2c)(__VA_ARGS__))
int _start(void)
{
printf("hello world\n");
return 0;
}
- 編譯命令:
/*只編譯不鏈接 */
arm-linux-gcc -c hello.c -o hello.o
/*手動鏈接,指令定程序入口地址 */
arm-linux-ld -Ttext=0x40008000 hello.o -o hello
/*生成純淨的二進制 */
arm-linux-objcopy -O binary hello hello.bin - 編譯完成後將hello.bin程序下載到開發板內存40008000的內存地址
執行程序:go 40008000
4. 基於uboot編寫的彙編流水燈程序
.global _start
.align 2
.text
_start:
push {r0-r12,lr}
ldr r0, =0x110002e0
ldr r1, =0x1111
str r1, [r0]
mov r3, #0x0
for:
ldr r0, =0x110002e4
mov r1, #0xe
str r1, [r0]
bl delay
mov r1, #0xd
str r1, [r0]
bl delay
mov r1, #0xb
str r1, [r0]
bl delay
mov r1, #0x7
str r1, [r0]
bl delay
cmp r3, #0xff
beq last
addne r3, #0x1
bne for
delay:
mov r2, #0x0
ldr r4, =0xfffffff
loop:
cmp r2, r4
beq end
addne r2, #0x1
bne loop
end:
mov pc, lr
last:
pop {r0-r12,pc}
.end
編譯命令:
arm-linux-gcc -c led.S -o led.o
arm-linux-ld -Ttext=0x40008000 led.o -o led
arm-linux-objcopy -O binary led led.bin
下載執行即可。
讓我們一起來欣賞優美的流水燈~~~~