gboot.lds
如下:
OUTPUT_ARCH(arm)
ENTRY(_start)SECTIONS {. = 0x30000000;. = ALIGN(4);.text : {start.o (.text)*(.text)}. = ALIGN(4);.data : {*(.data)}. = ALIGN(4);bss_start = .;.bss : {*(.bss)}bss_end = .;
}
main.c
如下:
#define GPBCON ( volatile unsigned long * ) 0x56000010
#define GPBDAT ( volatile unsigned long * ) 0x56000014int gboot_main() {* ( GPBCON ) = 0x400;* ( GPBDAT ) = 0x0;return 0;
}
start.S
如下:
.text
.global _start
_start:b resetldr pc, _undifined_instructionldr pc, _software_interruptldr pc, _prefetch_abortldr pc, _data_abortldr pc, _not_usedldr pc, _irqldr pc, _fiq_undifined_instruction: .word undifined_instruction
_software_interrupt: .word software_interrupt
_prefetch_abort: .word prefetch_abort
_data_abort: .word data_abort
_not_used: .word not_used
_irq: .word irq
_fiq: .word resetundifined_instruction:nopsoftware_interrupt:nopprefetch_abort:nopdata_abort:nopnot_used:nopirq:nopfiq:nopreset:bl set_svcbl disable_watchdogbl disable_interruptbl disable_mmubl init_clockbl init_sdrambl copy_to_rambl init_stackbl clean_bssldr pc, =gboot_main
@ bl light_ledset_svc:mrs r0, cpsrbic r0, r0, #0x1forr r0, r0, #0xd3msr cpsr, r0mov pc, lr#define pWTCON 0x53000000
disable_watchdog:ldr r0, =pWTCONmov r1, #0x0str r1, [r0]mov pc, lrdisable_interrupt:mvn r1, #0x0ldr r0, =0x4a000008str r1, [r0]mov pc, lrdisable_mmu:mcr p15, 0, r0, c7, c7, 0mrc p15, 0, r0, c1, c0, 0bic r0, r0, #0x00000007mcr p15, 0, r0, c1, c0, 0mov pc, lr#define CLKDIVN 0x4c000014
#define MPLLCON 0x4c000008
#define MPLL_405MHZ ((127<<12)|(2<<4)|(1<<0))init_clock:ldr r0, &#61;CLKDIVNmov r1, #0x5str r1, [r0]mcr p15, 0, r0, c1, c0, 0orr r0, r0, #0xc0000000mcr p15, 0, r0, c1, c0, 0ldr r0, &#61;MPLLCONldr r1, &#61;MPLL_405MHZstr r1, [r0]mov pc, lr#define mem_contrl 0x48000000
init_sdram:ldr r0, &#61;mem_contrladd r3, r0, #4*13adrl r1, mem_data0:ldr r2, [r1], #4str r2, [r0], #4cmp r0, r3bne 0bmov pc, lrcopy_to_ram:ldr r0, &#61;0x0ldr r1, &#61;0x30008000add r3, r0, #1024*4copy_loop:ldr r2, [r0], #4str r2, [r1], #4cmp r0, r3bne copy_loopmov pc, lrinit_stack:ldr sp, &#61;0x34000000mov pc, lrclean_bss:ldr r0, &#61;bss_startldr r1, &#61;bss_endcmp r0, r1moveq pc, lrclean_loop:mov r2, #0str r2, [r0], #4cmp r0, r1bne clean_loopmov pc, lrmem_data:.long 0x22000000.long 0x00000700.long 0x00000700.long 0x00000700.long 0x00000700.long 0x00000700.long 0x00000700.long 0x00018001.long 0x00018001.long 0x008c04f5.long 0x000000b1.long 0x00000030.long 0x00000030#define GPBCON 0x56000010
#define GPBDAT 0x56000014light_led:ldr r0, &#61;GPBCONmov r1, #0x400str r1, [r0]ldr r0, &#61;GPBDATmov r1, #0x0str r1, [r0]mov pc, lr
Makefile
如下&#xff1a;
all: start.o main.oarm-linux-ld -Tgboot.lds -o gboot.elf $^arm-linux-objcopy -O binary gboot.elf gboot.bin%.o: %.Sarm-linux-gcc -g -c $^%.o: %.carm-linux-gcc -g -c $^.PHONY: clean
clean:rm *.o *.elf *.bin