RSS

How to Cross-Compile U-Boot and work it on QEMU

15 Dec

Download the latest release of U-boot source from ftp://ftp.denx.de/pub/u-boot/

Extract the compressed folder.

Now we need to make a small change in the versatile.h file to make U-Boot work in QEMU. Note we’re gonna configure U-Boot for versatilepb board.

Open u-boot-2012.10/include/configs/versatile.h file

I prefer gedit for editing purposes though everyone claims vi is a very powerful tool.

$ gedit versatile.h

Now we in the first line after the comments you will see the expressions

#ifndef __CONFIG_H

#define __CONFIG_H

Just add the next line right below them.

#define CONFIG_ARCH_VERSATILE_QEMU

Otherwise it won’t work in QEMU environment. You will probably see the error message below when you try to work it in QEMU:

qemu: fatal: Trying to execute code outside RAM or ROM at 0x33f801f4

R00=00000000 R01=33fb9880 R02=00049868 R03=00000000
R04=00000000 R05=00000000 R06=00000000 R07=00000000
R08=00000000 R09=00000000 R10=00000000 R11=00000000
R12=000100fc R13=00000000 R14=000100fc R15=33f801f4
PSR=800001d3 N— A svc32
Aborted

AlayinaIsyan 

Let’s continue

In order to cross-compile the U-Boot source I used CodeSourcery toolchain. Visit the website http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/   Under the ARM Processors section click on “Download the EABI Release”. You have to type your name and e-mail adress. You will receive an e-mail containing the download link. Just download the lite version. I used Sourcery CodeBench Lite 2012.09-63 for ARM EABI.

You can take a look at the How to install code sourcery section for more detailed info.

Let me explain the reason I chose the EABI version and not the GNU/Linux release. We are going to work U-Boot as the first thing in QEMU, I mean it won’t work under linux. It’s just going to load the kernel and voila. Therefore we don’t need to cross-compile it with a GNU/Linux compiler.

After the installation add the compilers directory to the PATH variable. You can add it to bashrc file in order to avoid repeatedly typing the same command every time you open a new shell.

$ gedit ~/.bashrc

To the end of the file just add the following line which, in my case, is:

export PATH=/home/egenc/CodeSourcery/arm-2012.09/bin:$PATH

Save the file and type

$ source ~/.bashrc

to execute the command. Every you open the console (shell) this command executes your PATH variable is set.

Keep in mind that this command executes in normal user mode only. For the root user it won’t take effect.

You can also edit /etc/profile file for the root user

$ gedit /etc/profile

Less talk, more action. Let’s go on.

Now go to u-boot source folder.

First of all we need clean all the precompiled files, if any, prior to cross-compiling.

$ make CROSS_COMPILE=arm-none-eabi- clean

Now configure for versatilepb board.

$ make versatilepb_config ARCH=arm CROSS_COMPILE=arm-none-eabi-

And let the cross-compile begin!

$ make all ARCH=arm CROSS_COMPILE=arm-none-eabi-

When the process is completed we will have u-boot.bin file in the u-boot source directory and mkimage executable in tools folder.

Just copy mkimage to /usr/local/bin for future purposes.

$ sudo cp tools/mkimage /usr/local/bin

Now let’s use our binary u-boot file in QEMU.

I have used QEMU emulator version 0.15.1 at the time.

You can check how to install QEMU from this link.

Let’s get it done lads.

$ qemu-system-arm -M versatilepb -m 128M -nographic -kernel u-boot.bin

Voila

You must see an output like:

U-Boot 2012.10 (Dec 14 2012 – 02:10:06)

 

DRAM:  128 MiB

WARNING: Caches not enabled

Using default environment

In:    serial

Out:   serial

Err:   serial

Net:   SMC91111-0

Warning: SMC91111-0 using MAC address from net device

 

AlayinaIsyan #

You can change the command prompt from the versatile.h file by modifying the line

# define CONFIG_SYS_PROMPT              “VersatilePB # “

And then compile it again from scratch.

You can type help on U-Boot prompt to see the available commands.

Many of you will wonder why I used the “-nographic” option.

To put it straight QEMU directs the output to graphics display. Hence one cannot see the serial channel output on the display. By adding the aforementioned option we direct the serial channel output to the console.

You can exit the u-boot by using the key combination “CTRL+A+X”

That’s all folks.

About these ads
 
1 Comment

Posted by on December 15, 2012 in Linux

 

Tags: , ,

One response to “How to Cross-Compile U-Boot and work it on QEMU

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

%d bloggers like this: