c - Hello World ,裸机 Beagleboard

标签 c arm beagleboard omap

我正在尝试让“hello world”类型的程序在我的 Beagleboard-xm 版本上运行。 C,通过从程序集调用 C puts 函数。

到目前为止,我一直将其用作引用:http://wiki.osdev.org/ARM_Beagleboard

这是我到目前为止的内容,但没有输出。

你好.c

volatile unsigned int * const UART3DR = (unsigned int *)0x49020000;

void puts(const char *s) {
  while(*s != '\0') { 
    *UART3DR = (unsigned int)(*s); 
    s++; 
  }
}

void hello() {
  puts("Hello, Beagleboard!\n");
}

boot.asm

.global start
start:
   ldr sp, =stack_bottom
   bl hello
   b .

linker.ld

ENTRY(start)

MEMORY
{
    ram : ORIGIN = 0x80200000, LENGTH = 0x10000
}

SECTIONS
{
    .hello : { hello.o(.text) } > ram
    .text : { *(.text) } > ram
    .data : { *(.data) } > ram
    .bss : { *(.bss) } > ram
     . = . + 0x5000; /* 4kB of stack memory */
    stack_bottom = .;

}

生成文件

ARMGNU = arm-linux-gnueabi

AOPS = --warn --fatal-warnings
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding

boot.bin: boot.asm
   $(ARMGNU)-as boot.asm -o boot.o
   $(ARMGNU)-gcc-4.6 -c $(COPS) hello.c -o hello.o
   $(ARMGNU)-ld -T linker.ld hello.o boot.o -o boot.elf
   $(ARMGNU)-objdump -D boot.elf > boot.list
   $(ARMGNU)-objcopy boot.elf -O srec boot.srec
   $(ARMGNU)-objcopy boot.elf -O binary boot.bin

像这样只使用 asm 文件就可以了。

.equ UART3.BASE,        0x49020000
start:
   ldr r0,=UART3.BASE
   mov r1,#'c'

这里有一些 Beagleboard/minicom 相关信息:http://paste.ubuntu.com/829072/

有什么指点吗? :)


我也试过

void hello() {
  *UART3DR = 'c';
}

我正在使用 minicom 并通过 ymodem 发送文件,然后我尝试运行它:

go 0x80200000

minicom 中的硬件和软件控制流已关闭。

最佳答案

这应该对你有用。这是我从很久以前挖出的一些代码,今晚没有在 beagleboard 上尝试它只是确保它编译了,它曾经工作过......

启动.s:

    .code 32

.globl _start
_start:

    bl main
hang: b hang

.globl PUT32
PUT32:
    str r1,[r0]
    bx lr

.globl GET32
GET32:
    ldr r0,[r0]
    bx lr

你好.c:

extern void PUT32 ( unsigned int, unsigned int );
extern unsigned int GET32 ( unsigned int );
void uart_send ( unsigned char x )
{
    while((GET32(0x49020014)&0x20)==0x00) continue;
    PUT32(0x49020000,x);
}
void hexstring ( unsigned int d )
{
    //unsigned int ra;
    unsigned int rb;
    unsigned int rc;

    rb=32;
    while(1)
    {
        rb-=4;
        rc=(d>>rb)&0xF;
        if(rc>9) rc+=0x37; else rc+=0x30;
        uart_send(rc);
        if(rb==0) break;
    }
    uart_send(0x0D);
    uart_send(0x0A);
}
int main ( void )
{
    hexstring(0x12345678);
    return(0);
}

memmap(链接描述文件):

MEMORY
{
    ram : ORIGIN = 0x82000000, LENGTH = 256K
}

SECTIONS
{
    ROM : { startup.o } > ram
}

生成文件:

CROSS_COMPILE = arm-none-eabi

AOPS = --warn --fatal-warnings 
COPS = -Wall -Werror -O2 -nostdlib -nostartfiles -ffreestanding 

all : hello.bin

hello.bin : startup.o hello.o memmap
    $(CROSS_COMPILE)-ld startup.o hello.o -T memmap -o hello.elf  
    $(CROSS_COMPILE)-objdump -D hello.elf > hello.list
    $(CROSS_COMPILE)-objcopy hello.elf -O binary hello.bin

startup.o : startup.s
    $(CROSS_COMPILE)-as $(AOPS) startup.s -o startup.o

hello.o : hello.c 
    $(CROSS_COMPILE)-gcc -c $(COPS) hello.c -o hello.o

clean :
    rm -f *.o
    rm -f *.elf
    rm -f *.bin
    rm -f *.list

看起来我只是将堆栈指针留在了引导加载程序所在的位置。同样,与您一样,假设引导加载程序已初始化串行端口。

我假设你有串行端口访问工作,你看到 uboot 并且你能够键入命令以将此程序(xmodem,或其他)下载到板 ram 中?如果你不能这样做,那么可能是你没有正确连接到串口。 beagleboards 的串行端口很麻烦,可能需要自己制作电缆。

关于c - Hello World ,裸机 Beagleboard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9142951/

相关文章:

c - 将元素指针压入堆栈

python - 将 SciPy 编译为 Android - 是否已完成,关于如何将 FORTRAN 代码编译为 Android Arm 的任何帮助

python - OpenCV 中的自适应阈值(版本 1 - swig 版本)

c - 如何判断单词的开头和结尾读法是否相同?

c - C中转义字符的大小

memory-management - 在ARMv8中,如果全局页表项在不同进程之间发生冲突会发生什么?

android - 在我的触摸屏上交换 X 和 Y

android - Android 中的 USB Dongle 识别 - Beaglebone

c - 如何检查之前是否已定义结构类型?

c - GDB 停留在 “Configuring GDB Aborting configuring GDB”