Beagleboard裸机编程 [英] Beagleboard bare metal programming

查看:186
本文介绍了Beagleboard裸机编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚得到了我的BeagleBoard-Xm,我想知道有没有详细的一步一步的教程如何获得在硬件上运行的非常简单的裸机软件?



我想要深入了解硬件架构如何工作,从Bootloader,接口,中断,异常,MMU等方面的一切。我认为最好的方法是获得一个简单的hello世界程序来执行beagleboard xm没有操作系统。没有什么先进的,只需启动板,并在屏幕上获得一个你好世界的输出。而已!



下一步将是运行一个小型操作系统,可以安排一些非常简单的任务。无需文件系统,只需了解操作系统的基础知识。



任何帮助赞赏!



最好的问候



Gigu先生

解决方案

绝对没有问题...



首先得到串口运行,我有一个较旧/较早的beagleboards和记住串行端口,只是关于I / O的一切都是痛苦的,但是在它上面有一个串行端口,所以你可以看到它启动。



它启动uboot我想,你可以按一个键或esc或类似的东西来中断正常启动(进入linux)。从uboot提示符可以很容易的加载你的第一个简单的程序。



我现在有一些beagleboard代码方便,但没有我的beagleboard本身方便的尝试。因此,请 http://sam7stuff.blogspot.com/ 了解如何混合一些启动用于无OS嵌入式程序的汇编程序和C代码(对于arm来说,我有许多示例可用于其他thumb / cortex-m3平台,但是这些启动有点不同)。



sam7端口的东西和内存地址空间是完全不同于beagleboard / omap。以上是您可以更改或重新创建的框架。



您将需要ti.com的OMAP 35x技术参考手册。在他们的网站OMAP3530上搜索omap部分。



还有beagleboard文档。例如这个说法:



BeagleBoard上提供了一个RS232端口,可以访问UART3的TX和
RX线路



所以在trm中搜索UART3的omap显示它的基地址是0x49020000。 (通常很难找出整个地址,因为手册通常在这里有一部分存储器映射,另一部分在这里,在寄存器描述附近,只有地址的较低位被调用。) / p>

查看uart寄存器THR_REG是你要写出要发送出去的字节的地方,请注意它是一个16位寄存器。



知道这一点,我们可以做第一个程序:

  .globl _start 
_start:
ldr r0,= 0x49020000
mov r1,#0x55
strh r1,[r0]
strh r1,[r0]
strh r1,[r0]
strh r1,[r0]
strh r1,[r0]
hang:b hang

这是一个makefile:

  ARMGNU = arm-none-linux-gnueabi 

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

uarttest.bin:uarttest.s
$( ARMGNU)-as $(AOPS)uarttest.s -o uart test.o
$(ARMGNU)-ld -T rammap uarttest.o -o uarttest.elf
$(ARMGNU)-objdump -D uarttest.elf> uarttest.list
$(ARMGNU)-objcopy uarttest.elf -O srec uarttest.srec
$(ARMGNU)-objcopy uarttest.elf -O binary uarttest.bin

使用的链接描述文件:

  / * rammap * / 
MEMORY
{
ram:ORIGIN = 0x80300000,LENGTH = 0x10000
}

SECTIONS
{
.text:{*(。text *)}> ram
}

请注意,来自codesourcery的linux版本被调出,您不需要版本的gnu交叉编译器,实际上这个代码是asm只需要一个汇编器和链接器(binutils的东西)。 arm-none-eabi -...类型交叉编译器也可以正常工作(假设你从codeourcery获取了精简工具)。



一旦你有一个.bin文件看看uboot上的帮助,我不记得确切的命令,但它可能是一个l 0x80300000或load_xmodem或一些这样的事情。基本上你想要将x或y或z调制解调器的.bin文件通过串行端口插入处理器的内存空间,然后使用go或者任何命令告诉uboot分支到你的程序。



运行时,您会看到少数U字符(0x55为'U')出来串行端口。



您的主要目标是获得一个简单的串口例程,以便您可以打印出来的东西进行调试,否则看看您的程序正在做什么。后来你可以进入图形等等,但首先使用串行端口。



有一些作弊行为。由于uboot出来并初始化了串行端口,所以我们没有必要,只是把字节推入thr。但是很快你会溢出thr的存储并丢失字节,所以你需要读取omap的trm,并找到一些指示发送器是空的位,它已经传输了所有的东西,然后创建一个uart_send类型的函数来轮询发送机空,然后发送一个字节。



还要忘记printf(),你需要创建自己的打印一个数字(八进制或十六进制是最简单的),也许打印字符串。我一整天都在做这样的工作,99%的时间我使用的是一个小例程,打印出uart的32位十六进制数字。从数字我可以调试并看到程序的状态。



所以采取sam7模型或类似的东西(注意编译器和链接器命令行选项是重要的是链接命令行上的文件顺序,如果要使.bin文件中的第一个指令/单词成为您的入口点,则第一个文件必须是您的入口点,这通常是道路上的一个好主意你想知道如何控制这个从ROM启动)。



如果你开始看看,你可能会做一些没有删除或替换uboot的对于uboot,您将看到基于linux的引导命令,您将看到它正在将一个.bin文件从flash或某处复制到ram中的一个位置,然后分支到它。现在分支到linux,esp arm linux涉及一些arm表,并可能设置一些寄存器,您的程序不需要或需要。基本上无论你想要使用什么命令,在你将程序​​复制到ram之后,你将如何在启动脚本中为uboot创建脚本,如果你选择让板子启动并像linux那样运行。



说你可以使用jtag,而不是依靠uboot工作,当你走这条路,虽然可能有一定数量的事情你需要做的开机,以获得芯片,运行,特别是配置uart可能是某处的几个时钟分频器,时钟使能,I / O使能,各种各样的东西。这就是为什么sam7的例子从眨眼的事情开始,而不是一个uart的东西。 amotek jtag-tiny是一个很好的jtag摆动器,我一直很高兴,每天在工作中使用这些。 beagleboard可能使用TI引脚,而不是标准的ARM引脚分配,因此您可能需要更改布线。而且我不知道OMAP是否可以直接访问手臂开关控制器,或者您必须做某些特定的功能。你最好暂时去uboot路由。



一旦你有一个框架,你有一小部分的asm设置堆栈和分支到你的entrypoint C代码,您可以开始将该C代码转换为操作系统或做任何你想要的。如果您查看chibios或prex或类似的其他人,您会发现他们有小的asm启动代码,让他们进入他们的系统。同样地,还有uart调试和非调试例程。许多角色将要使用中断,而不是轮询为空。



如果这篇文章没有让你和你的好友一起运行(让你做一些工作),让我知道,我会挖出我的beagleboard并创建一个完整的例子。我的董事会并不完全符合你的要求,但就你的世界而言,它应该足够接近。


I just got my BeagleBoard-Xm and I'm wondering if there is any detailed step by step tutorials on how to get a very simple bare metal software running on the hardware?

The reason I ask is I want to deeply understand how the hardware architecture works, everything from the bootloader, linkers, interrupts, exceptions, MMU etc. I figured the best way is to get a simple hello world program to execute on the beagleboard xm without an OS. Nothing advanced, just start up the board and get a "hello world" output on the screen. thats it!

The next step would be getting an tiny OS to run, that can schedule some very simple tasks. No filesystem needed, just to understand the basics of the OS.

Any help appreciated!

Best Regards

Mr Gigu

解决方案

Absolutely no problem...

First off get the serial port up and running, I have one of the older/earlier beagleboards and remember the serial port and just about everything about the I/O being painful, nevertheless get a serial port on it so you can see it boot.

It boots uboot I think and you can press a key or esc or something like that to interrupt the normal boot (into linux). From the uboot prompt it is easy to load your first simple programs.

I have some beagleboard code handy at the moment but dont have my beagleboard itself handy to try them. So go to http://sam7stuff.blogspot.com/ to get an idea of how to mix some startup assembler and C code for OSless embedded programs (for arm, I have a number of examples out there for other thumb/cortex-m3 platforms, but those boot a little differently).

The sam7 ports for things and memory address space is totally different from the beagleboard/omap. The above is a framework that you can change or re-invent.

You will need the OMAP 35x techincal reference manual from ti.com. Search for the omap part on their site OMAP3530.

Also the beagleboard documentation. For example this statement:

A single RS232 port is provided on the BeagleBoard and provides access to the TX and RX lines of UART3

So in the trm for the omap searching for UART3 shows that it is at a base address of 0x49020000. (often it is very difficult to figure out the entire address for something as the manuals usually have part of the memory map here, and another part there, and near the register descriptions only the lower few bits of the address are called out.)

Looking at the uart registers THR_REG is where you write bytes to be sent out the uart, note that it is a 16 bit register.

Knowing this we can make the first program:

.globl _start
_start:
    ldr r0,=0x49020000
    mov r1,#0x55
    strh r1,[r0]
    strh r1,[r0]
    strh r1,[r0]
    strh r1,[r0]
    strh r1,[r0]
hang: b hang

Here is a makefile for it:

ARMGNU = arm-none-linux-gnueabi

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

uarttest.bin : uarttest.s
    $(ARMGNU)-as $(AOPS) uarttest.s -o uarttest.o
    $(ARMGNU)-ld -T rammap uarttest.o -o uarttest.elf
    $(ARMGNU)-objdump -D uarttest.elf > uarttest.list
    $(ARMGNU)-objcopy uarttest.elf -O srec uarttest.srec
    $(ARMGNU)-objcopy uarttest.elf -O binary uarttest.bin

And the linker script that is used:

/* rammap */
MEMORY
{
    ram : ORIGIN = 0x80300000, LENGTH = 0x10000
}

SECTIONS
{
    .text : { *(.text*) } > ram
}

Note the linux version from codesourcery is called out, you do not need that version of a gnu cross compiler, in fact this code being asm only needs an assembler and linker (binutils stuff). The arm-none-eabi-... type cross compiler will work as well (assuming you get the lite tools from codesourcery).

Once you have a .bin file look at the help on uboot, I dont remember the exact command but it is probably an l 0x80300000 or load_xmodem or some such thing. Basically you want to x, or y or z modem the .bin file over the serial port into memory space for the processor, then using a go or whatever the command is tell uboot to branch to your program.

You should see a handful of U characters (0x55 is 'U') come out the serial port when run.

Your main goal up front is to get a simple serial port routine up so you can print stuff out to debug and otherwise see what your programs are doing. Later you can get into graphics, etc. but first use the serial port.

There was some cheating going on. Since uboot came up and initialized the serial port we didnt have to, just shove bytes into the thr. but quickly you will overflow the thr's storage and lose bytes, so you then need to read the trm for the omap and find some sort of bit that indicates the transmitter is empty, it has transmitted everything, then create a uart_send type function that polls for transmitter empty then sends the one byte out.

also forget about printf(), you need to create your own print a number (octal or hex are the easiest) and perhaps print string. I do this sort of work all day and all night and 99% of the time all I use is a small routine that prints 32 bit hex numbers out the uart. from the numbers I can debug and see the status of the programs.

So take the sam7 model or something like it (note the compiler and linker command line options are important as is the order of files on the link command line, the first file has to be your entry point if you want to have the first instruction/word in the .bin file be your entry point, which is usually a good idea as down the road you want to know how to control this for booting from a rom).

You can probably do quite a bit without removing or replacing uboot, if you start to look at the linux based boot commands for uboot you will see that it is copying what is pretty much a .bin file from flash or somewhere into a spot in ram, then branching to it. Now branching to linux, esp arm linux involves some arm tables and possible setting up some registers, where your programs wont want or need that. basically whatever command you figure out to use, after you have copied your program to ram, is what you will script in a boot script for uboot should you choose to have the board boot and run like it does with linux.

Saying that you can use jtag and not rely on uboot to work, when you go that path though there are likely a certain number of things you have to do on boot to get the chip up and running, in particular configuring the uart is likely a few clock dividers somewhere, clock enables, I/O enables, various things like that. Which is why the sam7 example starts with a blink the led thing instead of a uart thing. The amotek jtag-tiny is a good jtag wiggler, I have been quite pleased, use these all day long every day at work. The beagleboard probably uses a TI pinout and not the standard ARM pinout so you will likely need to change the cabling. And I dont know if the OMAP gives you direct access to the arm tap controller or if you have to do something ti specific. You are better off just going the uboot route for the time being.

Once you have a framework where you have a small amount of asm to setup the stack and branch to your entrypoint C code, you can start to turn that C code into an OS or do whatever you want. If you look at chibios or prex or others like it you will find they have small asm boot code that gets them into their system. Likewise there are uart debug and non-debug routines in there. Many rtoses are going to want to use interrupts and not poll for thr to be empty.

If this post doesnt get you up and running with your hello world (letting you do some of the work), let me know and i will dig out my beagleboard and create a complete example. My board doesnt exactly match yours but as far as hello world goes it should be close enough.

这篇关于Beagleboard裸机编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆