TRIMUI SMART >> Assembly

LED


參考資訊:
1. pdf

紅色LED連接到PG10


GPIO位址


PG_CFG1


PG_DATA


main.s

    .global _start
        
    .equ GPIO_BASE, 0x01c20800
    .equ PG_CFG1,   (GPIO_BASE + (0x24 * 6) + 0x04)
    .equ PG_DATA,   (GPIO_BASE + (0x24 * 6) + 0x10)
         
    .arm
    .text
_start:
    .long 0xea000016
    .byte 'e', 'G', 'O', 'N', '.', 'B', 'T', '0'
    .long 0, __spl_size
    .byte 'S', 'P', 'L', 2
    .long 0, 0
    .long 0, 0, 0, 0, 0, 0, 0, 0
    .long 0, 0, 0, 0, 0, 0, 0, 0
         
_vector:
    b reset
    b .
    b .
    b .
    b .
    b .
    b .
    b .
         
reset:
    ldr r0, =PG_CFG1
    ldr r1, =0x11111111
    str r1, [r0]
    
    ldr r0, =PG_DATA
    ldr r2, =0xffff
    str r2, [r0]
     
    ldr r0, =PG_DATA
    ldr r1, =(1 << 10)
0:
    eor r2, r1
    str r2, [r0]
    ldr r3, =500000
1:
    subs r3, #1
    bne 1b
    b 0b
    .end

main.ld

OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)

MEMORY {
    RAM : ORIGIN = 0x00000000, LENGTH = 128M
}

SECTIONS {
    .text :
    {
        PROVIDE(__spl_start = .);
        *(.text*)
        PROVIDE(__spl_end = .);
        *(.init.text)
        *(.exit.text)
        *(.glue*)
        *(.note.gnu.build-id)
    } > RAM
    PROVIDE(__spl_size = __spl_end - __spl_start);

    .rodata ALIGN(8) :
    {
        PROVIDE(__rodata_start = .);
        *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*)))
        PROVIDE(__rodata_end = .);
    } > RAM

    .data ALIGN(8) :
    {
        PROVIDE(__data_start = .);    
        *(.data*)
        . = ALIGN(8);
            PROVIDE(__data_end = .);
        PROVIDE(__image_end = .);
    } > RAM

    .bss ALIGN(8) (NOLOAD) :
    {
        PROVIDE(__bss_start = .);
        *(.bss*)
        *(.sbss*)
        *(COMMON)
        . = ALIGN(8);
        PROVIDE(__bss_end = .);
    } > RAM

    .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) }
}

Makefile

all:
	arm-linux-gnueabihf-as -mcpu=cortex-a7 -o main.o main.s
	arm-linux-gnueabihf-ld -T main.ld -o main.elf main.o
	arm-linux-gnueabihf-objcopy -O binary main.elf main.bin
	gcc mksunxi.c -o mksunxi
	./mksunxi main.bin

clean:
	rm -rf main.bin main.o main.elf

編譯

$ make
    arm-linux-gnueabihf-as -mcpu=cortex-a7 -o main.o main.s
    arm-linux-gnueabihf-ld -T main.ld -o main.elf main.o
    arm-linux-gnueabihf-objcopy -O binary main.elf main.bin
    gcc mksunxi.c -o mksunxi
    ./mksunxi main.bin
    The bootloader head has been fixed, spl size is 512 bytes.

燒錄到MicroSD

$ sudo dd if=main.bin of=/dev/sdX bs=1024 seek=8 conv=notrunc

P.S. /dev/sdX是使用者的MicroSD位置

插入MicroSD並且開機


返回上一頁