The first No OS program (Mini2440)

In Mini2440:

First we need a Assembly program to call C program.

crt0.S 

@switch to C program
.text
.global _start
_start:
    ldr r0,=0x53000000
    mov r1,#0x0
    str r1,[r0]
    ldr sp,=1024*4

    bl main       @using C main
halt_loop:
    b halt_loop

Next  the main().

led_on_c.c

#define GPBCON (*(volatile unsigned long *)0x56000010)
#define GPBDAT (*(volatile unsigned long *)0x56000014)
#define LED1   (1<<(10))    //LED1-GPB5
int main()
{
    GPBCON = LED1;
    GPBDAT &= ~(1<<5);     //LED1 ON
    return 0;
}

Next the Makefile.

Makefile

led_on_c.bin: crt0.S led_on_c.c
    arm-linux-gcc -g -c -o crt0.o crt0.S
    arm-linux-gcc -g -c -o led_on_c.o led_on_c.c
    arm-linux-ld -Ttext 0x0000000 -g crt0.o led_on_c.o -o led_on_c_elf
    arm-linux-objcopy -O binary -S led_on_c_elf led_on_c.bin
    arm-linux-objdump -D -m arm led_on_c_elf > led_on_c.dis
clean:
    rm -f led_on_c.dis led_on_c.bin led_on_c_elf *.o

Finally,we just need to execute the make command.And the bin are created.

原文地址:https://www.cnblogs.com/ht-beyond/p/4187926.html