ARM Beagleboard: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
fixed package name.
m Bot: Replace deprecated source tag with syntaxhighlight
 
(16 intermediate revisions by 4 users not shown)
Line 6:
 
==Intro==
This is a tutorial on bare-metal [OS] development on the Texas Instruments BeagleboardBeagleBoard. This tutorial is written specifically for the BeagleboardBeagleBoard-xM Rev C because the author has no other hardware to test on.
 
Experience in Linux/nix ('''very''' important) and at least one assembly language ('''incredibly''' important, or at least extensive C knowledge) is assumed and required. Please make sure you can figure out how to get a basic x86 OS (no copypaste!) to the booting stage before attempting this guide. No need to make much more than a '"Hello World'", since what you know about x86 won't really apply here.
 
=== Materials ===
You will need a:
* '''BeagleboardBeagleBoard-xM Rev C''', or perhaps an older board, ''with a serial port''.
* An '''RS-232''' serial port. This is the kind of serial port on the back of your x86 PC, and on the BeagleboardBeagleBoard-xM. using TTL (5v) or lower voltage serial will damage something.
* A serial cable that comes to '''DB-9 Male''' on at least one side (to connect to the BeagleboardBeagleBoard)
* '''Debian, or other *nix with arm-binutils''' [guide will document installation for Debian]
* '''Power supply''' for your BeagleboardBeagleBoard ''(5v, at least 1A but I recommend/use 3A)''
* '''A copy of the ARM ARM (ARM Architecture Reference Manual) (download a PDF, make sure it's the new one, with ARMv7 stuff)'''
* '''A copy of the OMAP35x/DM37x TRM (Technical Reference Manual)''' <-- ^ ''THESE ARE INCREDIBLY IMPORTANT!''
:* '''Optional:''' Various peripherals for the BeagleboardBeagleBoard. Be aware that ''you'' will need to write drivers for them. Welcome to OS Development ^_^.
 
==Getting Started==
Line 27:
First things first, you're going to want to make sure all your hardware works. Set up your serial port, however yours works, and open up minicom. Make sure you have flow control turned off.
Now jumper '''PIN 2 (RX)''' to '''PIN 3 (TX)''' on the DB-9 side. Just type some characters into minicom, and they should be echoed back.
Ensure you can run at 115200 baud, 8N1, which is what you will use to connect to the BeagleboardBeagleBoard.
 
If you get 'Permission Denied' '''do NOT become root!''' This is unnecessary. Instead do:
<sourcesyntaxhighlight lang="asm">
sudo adduser <user> dialout
</syntaxhighlight>
</source>
This will let your user use serial ports without needing root.
 
Or do ls -l /dev/ttyS* to find out the group that own the device, then add you into that group under /etc/group (normally the group is uucp)
 
===Testing the BeagleboardBeagleBoard===
 
Follow the guide here http://elinux.org/BeagleBoardDebian#Debian_armhf_port to install the Debian armhf image to a microSD card. We don't really need to boot Debian from it, but it's a nice simple <small>ghetto/lazy</small> way to get u-boot set up and working.
 
Connect the BeagleboardBeagleBoard up via serial, and make sure minicomMinicom is running (on your PC). Put the microSD card in the BeagleboardBeagleBoard. Connect the BeagleboardBeagleBoard to its power supply. You should see some output on the serial port. If not, googleGoogle around to figure out why not. If a few bytes of garbage appear in Minicom only, make sure the MicroSDmicroSD card is inserted and VALID. Also make sure you didn't press the 'user button'.
 
You should get some meaningful output. Unplug your BeagleboardBeagleBoard when you are done with it.
 
===Getting an assembler===
Line 50:
 
Append:
<sourcesyntaxhighlight lang="asm">
deb http://www.emdebian.org/debian/ squeeze main
</syntaxhighlight>
</source>
to your /etc/apt/sources.list, changing 'squeeze' for your version of Debian - I'm running wheezy, for example.
 
now run:
<sourcesyntaxhighlight lang="asm">
sudo aptitude update
sudo aptitude install gcc-4.4-arm-linux-gnueabi # check this! it might be an older version for non-wheezy...
</syntaxhighlight>
</source>
 
That will install a C compiler, and also install binutilsBinutils, which for this tutorial is really all we need, but you may later wish to write your code in C, since writing it all in ASM is apparently frowned upon (;)).
 
==Writing some CODE!==
 
Now that we have all the crapstuff we need, let's get to writing some code. Before we write an ASM source file, we should make a linker script and a Makefile.
 
===Linker Script===
Line 75:
Take note of what it does. It's pretty simple. Refer to docs if necessary.
 
<sourcesyntaxhighlight lang="asm">
/* rammap */
MEMORY
Line 86:
.text : { *(.text*) } > ram
}
</syntaxhighlight>
</source>
 
===Makefile===
 
This is the basic makefile I use. It's similar to the one on the stackoverflow link. Spot the difference.
 
<sourcesyntaxhighlight lang="asm">
ARMGNU = arm-linux-gnueabi
 
Line 104:
$(ARMGNU)-objcopy boot.elf -O srec boot.srec
$(ARMGNU)-objcopy boot.elf -O binary boot.bin
</syntaxhighlight>
</source>
 
===Assembly!===
 
YAY! We can write some code now!
YAY! We can write some code now! ARM Assembly is a VERY beautiful and powerful language, and should not be feared. There are indeed reasons NOT to use assembly, namely that it is nonportable and hard to maintain. However, I personally wouldn't want to miss out on playing with this beautiful architecture.
 
You are free to branch to C code after following this tutorial, but remember, you will need to write some things in ASM, just like on x86. Except now ASM is more fun.
Afterall, arguably the best OS developer here, Solar, wrote his operating system, Solar_OS [http://www.oby.ro/os/index.html] is written fully in Assembly, so why can't you ;).
 
You are free to branch to C code after following this tutorial, but remember, you will need to write some things in ASM, just like on x86. Except now ASM is more fun.
 
====boot.asm====
 
<tt><sourcesyntaxhighlight lang="asm">
#UART base locations from the TRM
.equ UART1.BASE, 0x4806A000
.equ UART2.BASE, 0x4806C000
#According to the Beagleboard-xM System Reference Manual, UART3 is connected to the serial port.
# vv USE ME USE ME HARD vv
.equ UART3.BASE, 0x49020000
# ^^ USE ME USE ME HARD ^^
.equ UART4.BASE, 0x49042000
 
Line 145 ⟶ 141:
# (branch (jump, JMP) to _hang)
# b _hang
</sourcesyntaxhighlight></tt>
 
==='Compiling' it===
Line 153 ⟶ 149:
==Executing code on the device==
 
Remember that minicomMinicom window we almost forgot about? It's time to use it ;).
 
===Introduction to u-boot===
 
Reset your BeagleboardBeagleBoard (hit the reset button).
 
You should see:
 
<sourcesyntaxhighlight lang="asm">
U-Boot 2011.03-rc1-00000-g9a3cc57-dirty (Apr 04 2011 - 12:36:16)
Line 179 ⟶ 175:
Die ID #2e7000029ff80000016842c813020023
Hit any key to stop autoboot: 3
</syntaxhighlight>
</source>
 
Hit a key. Before Linux loads.
 
<sourcesyntaxhighlight lang="asm">
OMAP3 beagleboard.org #
</syntaxhighlight>
</source>
 
Whee, a u-boot prompt.
Line 191 ⟶ 187:
===Loading code===
 
Now it's time to load our code into RAM. To do this, we will use 'loady' and the y-modem protocol. We can do all this from minicomMinicom - that's why we needed Minicom and not GNU Screen. Hopefully you did what I asked ;).
 
Just type 'loady'. Don't worry about being fast on your first go, you'll miss it anyway.
 
<sourcesyntaxhighlight lang="asm">
OMAP3 beagleboard.org # loady
## Ready for binary (ymodem) download to 0x80200000 at 115200 bps...
</syntaxhighlight>
</source>
 
Now hit Ctrl+A. A bar will appear at the bottom.
Line 214 ⟶ 210:
Ctrl+C out of the ymodem transfer window if nothing happens.
 
Reset your BeagleboardBeagleBoard and try again - now that the file is already selected, you can just hit enter twice in the file prompt window, preventing timeouts.
 
Be patient, ymodem can take a few seconds to 'sync'.
 
After the file is loaded into RAM,
<sourcesyntaxhighlight lang="asm">
READY: Press any key.
</syntaxhighlight>
</source>
and
<sourcesyntaxhighlight lang="asm">
Cm - CRC mode, 9(SOH)/0(STX)/0(CAN) packets, 3 retries
## Total Size = 0x00000350 = 848 Bytes
OMAP3 beagleboard.org #
</syntaxhighlight>
</source>
is printed (my file is bigger... don't worry about that), we just have to execute the code in memory!
 
Line 233 ⟶ 229:
 
Execution is started from an address with 'go'. Our _start address is 0x80200000. So, we type:
<sourcesyntaxhighlight lang="asm">
OMAP3 beagleboard.org # go 0x80200000
</syntaxhighlight>
</source>
 
and we should get:
 
<sourcesyntaxhighlight lang="asm">
## Starting application at 0x80200000 ...
!
</syntaxhighlight>
</source>
 
If you get that, congratulations! You've just written an 'Operating' System (;)) for the BeagleboardBeagleBoard! The process will seem long winded at first, but it's not really at all.
 
==What to do now==
 
Read the ARM ARM.
Read the ARM ARM. All 2080 pages. And then read it again. (Ok, I haven't done this ^_^)
 
Read the TRM.
Read the TRM. All 3652 pages. And then read it again. (I probably _have_ done this ^_^. But I need to read it again :<)
 
<code>01:26 < doublebeta> embrace the TRM. Hold it close to your heart, and tell it you love it.</code>
 
Find out how to do push/pop and how to return from functions (and how to return using a pop) from example code and the ARM.
 
Write routines to print integers and strings. (I've done this, It's a good coding exercise, so I will NOT post example code)
 
Set up virtual memory.
 
Enable interrupts
Enable interrupts (I'm working on this, I'll hopefully make tutorials once I'm done).
 
Write some device drivers.
Line 278 ⟶ 272:
</code>
But I quite honestly haven't tried ^_^.
 
==WIP==
 
<big> This section contains '''crap'''. Please don't read it unless you are used to swimming in a river of '''crap'''. </big>
 
I'm probing addresses looking for where to store interrupt vectors, so I can handle exceptions as soon as possible, so I can answer 'why the hell did I hang?'.
 
I can't probe 0x0, apparently it throws an exception, since I hang trying to read. Expected as much, since there shouldn't be any memory device there.
 
I probed 0xFFFF0000, which is virtual address space - I haven't set up the MMU yet. Result: http://paste2.org/p/1681798
 
Looks like a whole lot of nothing. Looks like I must program the MMU before I can have interrupts, which is rather a pain in the ass.
 
Out of curiosity, I probed 0x78787878. This is also MMU virtual address space. It contains meaningful data! Or, possibly not, but data at least! http://paste2.org/p/1681826
So what does this mean... discusssssss...
 
==Help==
 
For help, you can try joining #Beagle (note the capital B!) on irc.freenode.net. Speak to doublebeta, if he's not online, pm him. Of course you will be expected to 'pull your own weight' and you will NOT be 'spoon-fed'.
 
Also, drop in for a chat, eh? Or one of doublebeta's 'discussions' ;).
 
Vote for a Beagle-specific subforum on forum.osdev.org ;).
 
== See also ==