Raspberry Pi Emulator in Ubuntu with Qemu

The Raspberry Pi board is a low cost board based on Broadcom BCM2835 media processor SoC with an ARM1176JZF-S core clocked at 700MHz. This board is currently under development and should be ready by end of November, beginning of December and will be sold for 25 USD (128MB RAM – no Ethernet) and 35 USD (256MB RAM – Ethernet).

While we are waiting for the board, we can still test software using qemu to emulate a board based on an ARM1176 core with 128MB or 256 MB memory.

I’ve tried to create a rootfs based on Ubuntu with rootstock but this only support processors with ARM cortex A8 and greater, so it would not work with ARM11. I’ll be using Debian Squeeze instead.

Prerequisites

My host computer is running Ubuntu 10.04.3 LTS, but any recent Ubuntu or Debian installation should work with these instructions. [Update: You won’t be able to install qemu-linaro in Debian.  [Update in update: Apparently in the latest version of Debian Squeeze, you can just install the default qemu image: apt-get install qemu-system. The build instructions below are for reference in case you use a distro with an older qemu]

You need to cross-compile qemu as follows:


This also seems much faster than Linaro Qemu.]

I’m using qemu-linaro, here’s how to install it:


Here’s the version I use for reference:

Building the kernel for ARM11

I will basically follow the very clear instructions given at http://raspi.springnote.com/pages/8234994 with some slight modifications. I’ll skip some explanations so refer to the link above to understand exactly what you are doing.

First create a working direcory:


Download the latest  Sourcery G++ Lite IA32 GNU/Linux TAR package for EABI to your working directory and extract it:


Download, extract and patch the kernel for ARMv6 support:


Configure the kernel:


Specify the cross-compiler:


In my case I entered “/home/jaufranc/edev/raspberry-pi/arm-2011.03/bin/arm-none-eabi-“.

Select the right CPU options:


Enable ARM EABI:


Enable qemu’s disk support:


Enable devtmpfs:


Enable tmpfs:


Enable the event interface:


Exit and save the configuration.

Now compile the kernel:

Generating ARMEL Debian Squeeze Rootfs

The kernel build will take a while, so in the meantine you can open another terminal window and prepare the rootfs.

Create an empty rootfs directory and retrieve an armel rootfs for Debian Squeeze:


Once the kernel above is built and debootsrap has completed install the kernel modules in the rootfs:


The first stage of the rootfs is complete. You’ll notice some important script (e.g. inittab) are missing at this point, but this is normal.

Now let’s create an empty ext2 rootfs (3GB) and copy the rootfs we’ve just created to it:


To complete the rootfs, we’ll need to copy the kernel image the working directory and run qemu as follows:


Once you have access to the command line, mount the proc filesystem and complete the bootstrapping process:


The final steps are to enable the network, give a hostname and create a temporary root password:


That’s it your system is now ready.

You can stop qemu and restart it as follows:


Login as root with your temporary password and you should be asked to change it. After you have access to the command line and can check the CPU details with cat /proc/cpuinfo

Raspberry Pi Emulator Window

You can compile your own program using the cross-toolchain installed above

For those who want to skip the steps to build the kernel and generate the rootfs and just want to run qemu, I’ve uploaded the binary files:

After you download rootfs.ext2.gz you’ll need to unzip it first:


The root password is raspberry for the rootfs above.

If you want to install armel binaries using apt-get like you would do on a PC distribution, edit /etc/apt/sources.list as follows:


and run:


Sources:

Leave a Reply

54 Comments on "Raspberry Pi Emulator in Ubuntu with Qemu"

avatar
  Subscribe  
newest oldest most voted
Notify of
Gee Bartlett
Guest

Really great tutorial, great fun compliling linux for the first time, be warned their are a few spelling mistakes and the rootfs loads better if you use. sudo qemu-system-arm -M versatilepb -cpu arm1176 -hda YOURROOTFSFILE -kernel YOURKERNELFILE -append “root=/dev/sda”. but real good fun playing with the software before the board is available

Gee Bartlett
Guest

@cnxsoft
Still using the files that you provided can’t get the rootfs to mount for love or toffee. Might have to start again. but so far (with a dist-upgrade) got an lxde desktop running. hehe not bad when it is emulating on an old sempron 3000. very much liking qemu as a multi cpu test platform

Mark Johnson
Guest

Having some trouble with the compile on a Linux Mint 11 (i386) system.

The first problem was resulted in these errors:

cc1: error: unrecognized command line option “-mlittle-endian”
cc1: error: unrecognized command line option “-mapcs”
cc1: error: unrecognized command line option “-mno-sched-prolog”

One post for another environment suggested that CROSS_COMPILE was incorrect.

I updated the Makefile with this line:

CROSS_COMPILE = ~/edev/arm-2011.03/bin/arm-none-eabi-

This attempt got further but there were several of these warnings:

warning: “__LINUX_ARM_ARCH__” is not defined

followed by

linux-3.0.4/arch/arm/include/asm/glue-df.h:107:2: error: #error Unknown data abort handler type
In file included from arch/arm/kernel/asm-offsets.c:18:0:
linux-3.0.4/arch/arm/include/asm/glue-pf.h:54:2: error: #error Unknown prefetch abort handler type
make[1]: *** [arch/arm/kernel/asm-offsets.s] Error 1

Repeating the entire process from scratch had the same results.

Can you explain what I am doing wrong?

Thank you

Mark Johnson
Guest

I checked the Bash history and my menuconfig matches the instructions: make ARCH=arm menuconfig

I have successfully built kernels before with menuconfig having started out with Slackware.

Mark Johnson
Guest

@cnxsoft
Thank you, I would appreciate that. wget http://mjohnson.sixbit.org/RaspberryPi.config

Mark Johnson
Guest

@cnxsoft

Thanks for the suggestions.

I chased down CONFIG_ARM_PATCH_PHYS_VIRT to the very first line in the menuconfig screen: [] Patch physical to virtual translations at runtime (EXPERIMENTAL)

Enabling it (which is not in the instructions) resulted in the .config containing CONFIG_ARM_PATCH_PHYS_VIRT=y but it did not help.

Attempting to make after that results in warnings for __LINUX_ARM_ARCH__ being undefined. Of course, that can be defined, but regardless, there is an error due to CPU_PABORT_HANDLER being undefined.

I’m about ready to throw in the towel. Once the hardware comes out, there should be a stable build environment.

Arne
Guest

Thanks for the great guide!
Works perfectly.

I just spotted one small typo:
Instead of “mount /proc /proc -t /proc” it should be “mount /proc /proc -t proc”

Tony
Guest

apt-get install qemu-system works for debian, too. No need to muck around with compiling.

If like me you want to run this on a remote box with no monitor, the command changes to:

qemu-system-arm -M versatilepb -cpu arm1176 -m 256 -hda rootfs.ext2 -kernel zImage -append “root=/dev/sda console=ttyAMA00” -nographic

To enable the serial console you need to add the line:

T0:23:respawn:/sbin/getty -L ttyAMA0 9600 vt100

To /etc/inittab

Also add

ttyAMA0

To /etc/securetty

I’m impressed how speedy it is, even running on a Microserver it’s perfectly usable. CPU emulation has come a long way..

Benny
Guest

Great tutorial, thank you very much.

Do you have an idea how to make the RTC (real time clock) work?

Whenever I launch QEMU, system time is set to January 1st, 1970. Calling “hwclock” leads to the error “Cannot access the Hardware Clock via any known method”.

Any help is appreciated.

Benny
Guest

I cannot access any USB devices I provide to the virtual machine. Is the kernel correctly configured for Qemu’s USB controller? If yes, I may be missing something in my Debian installation …

Benny
Guest

@ cnxsoft
I managed to enable USB by making some more adjustments to the kernel config from above:

Device Drivers ->
[*] USB support ->
Support for Host-side USB
OHCI HCD support
USB Mass Storage support

Without this, Qemu’s USB controller will not work (“-usb -usbdevice …” parameters not having any effect). Please note that this is only a minimum USB config, allowing standard USB drives to be accessed. There are many more potential USB options for the kernel …

For FAT-formatted USB drives, I also had to enable an additional codepage (otherwise mounting such devices will fail):

File systems ->
{M} Native language support ->
Codepage 437 (United States, Canada)

trackback

[…] 3.1.9, so we need to compile an ARM11 kernel 3.1.9 for qemu by following the instructions given at http://www.cnx-software.com/2011/10/18/raspberry-pi-emulator-in-ubuntu-with-qemu/, replacing kernel 3.0.4 by 3.1.9 AND enabling ext-4 with make menuconfig.Once the build is complete […]

trackback

[…] 3.1.9, so we need to compile an ARM11 kernel 3.1.9 for qemu by following the instructions given at http://www.cnx-software.com/2011/10/18/raspberry-pi-emulator-in-ubuntu-with-qemu/, replacing kernel 3.0.4 by 3.1.9 AND enabling ext-4 with make menuconfig.Once the build is complete […]

Chbribs
Guest

I’m having trouble getting past the “sudo debootstrap –foreign –arch armel squeeze debian_armel_squeeze http://ftp.debian.org/debian” step on Ubuntu 11.10. It brings up a “sudo: debootstrap: command not found” error, and unless there was some typo that I’m not aware of, I dunno what’s wrong with it. This is my first time trying anything like this, so I’m a wee bit clueless compared to the rest of you folk.

Rmm200
Guest

One point you did not address is how to route network traffic through QEMU.
My Raspberry machine has a healthy IP address of 10.0.2.15, but QEMU does not route that anywhere.
What do I need to do so apt-get will work within the Raspberry machine?
Thanks!

Rmm200
Guest

Full configuration is running Ubuntu 11.10 under VMWare. Firefox – and apt-get – work fine to the Internet on Ubuntu. I am running qemu in a terminal window on the Ubuntu machine. From the qemu client, I can ping 10.0.2.2 successfully (the net is up and working), but ping to 192.168.1.1 (my router) never gets a response back. My Ubuntu machine uses bridged ethernet to the host. I have not set up any routing tables on the Ubuntu machine. Surprisingly, ping yahoo.com responds with: PING yahoo.com (98.139.183.24) as if DNS was working, but never gets a response from Yahoo.
Ring any bells?

Rmm200
Guest

Bah – apt-get update works great. I used apt-get install ntp, which is what I really wanted, and it worked great. I have network time. No idea why ping’s don’t work, and I don’t care right now… Everything I need is working.

Thanks for putting up with me!

Robert

trackback

[…] cpu within QEMU full system emulation running on Ubuntu for the foreseeable future (see here or here for excellent info on setting a system like this up). The saving of western civilization will just […]

trackback

[…] the instructions given in the section “Generating ARMEL Debian Squeeze Rootfs” of that post. Since Ethernet does not work and WiFi is then required for internet connectivity, you also need to […]

John Rose
Guest

make (of qemu) gave:
In file included from /home/john/Software/RaspberryPi/qemu-1.0/linux-user/syscall.c:3325:
/home/john/Software/RaspberryPi/qemu-1.0/linux-user/ioctls.h:187: error: ‘SNDCTL_DSP_MAPINBUF’ undeclared here (not in a function)
/home/john/Software/RaspberryPi/qemu-1.0/linux-user/ioctls.h:188: error: ‘SNDCTL_DSP_MAPOUTBUF’ undeclared here (not in a function)
/home/john/Software/RaspberryPi/qemu-1.0/linux-user/ioctls.h:243: error: ‘SOUND_MIXER_ACCESS’ undeclared here (not in a function)
make[1]: *** [syscall.o] Error 1
make: *** [subdir-arm-linux-user] Error 2

John Rose
Guest

libc6-dev is already the newest version

but E: Couldn’t find package gcc-arm-linux-gnueabi

Where is it?

In new instructions, make -j 2 gave same problem.

John Rose
Guest

@ cnxsoft
Ubuntu Lucid (i.e. 10.04.4 updated fully) Desktop 64 bit.

John Rose
Guest

@ cnxsoft
Thanks for help. I installed qemu-system as per your instructions. I also did sudo apt-get upgrade and it upgraded python-debian & some qemu packages (e.g. qemu-user). I’m now lost as to what to do next. Currently, I have Qemulator 0.5 & Qemu Launcher 1.7.4 GUI apps available. Do I use them them or do I start somewhere else in your instructions?

John Rose
Guest

I checked on qemu-system-arm:
[email protected]:~$ qemu-system-arm –version
QEMU emulator version 1.0.50 (Debian 1.0.50-2012.03-0ubuntu1~ppa10.04.1), Copyright (c) 2003-2008 Fabrice Bellard

I’ve tried running Qemulator 0.5 using a debian .img (in Terminal mode). It gives “Flash image must be given with the ‘pflash’ parameter” in qemu-system-arm window.

Any ideas please?

John Rose
Guest

I’d prefer to use a Debian Armel with lxde/xfce 6.0.4 for which I have the .iso. Is it possible to use that with QEMU?

John Rose
Guest

It’s not straightforward with getting, say, Debian Armel installed. I don’t fully understand why but it’s to with the initial boot of the installer. I’ve found out how to install Debian Armel Standard & Desktop and that’s explained very well (together with the necessary downloads) at
http://people.debian.org/~aurel32/qemu/armel/

trackback

[…] kernel is a ugly hack based on CNXSoft‘s notes. […]

trackback

[…] there are precompiled images available, and you can use the one from here (direct […]

iLem0n
Guest

The dropbox link don’t works 🙁

fhff
Guest

file not found, any images cant dowlnoads ;(