Raspbian Emulation Using QEMU
Raspbian Emulation Using QEMU
Raspbian Emulation Using QEMU
QEMU
ELECTGON
www.electgon.com
ma_ext@gmx.net
15.04.2018
Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 QEMU Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
3 Running QEMU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
4 QEMU for ARM Development Boards . . . . . . . . . . . . . . . . . . . . . . . . . 3
5 Get Hardware Speci ications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
6 Get Running Operating System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
6.1 Image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
6.2 Kernel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
7 Start the Emulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2
Abstract
This tutorial was set as an illustration about how to use QEMU for emulation of ARM development
boards, namely Raspberry pi board. It will start with quick demonstration about how using
QEMU for virtualization. Then detailed guide will be shown to learn how to build emulation
environment for Raspberry in QEMU.
QEMU Tutorial 1. Introduction
1 Introduction
Developing a project for an ARM board requires testing of your project performance on this
target board. In case of target board is not available to work with, you can rely on emulation
techniques to run your environment. QEMU can be used for that purpose. Generally QEMU
is used for virtualization and Emulation. In the following lines, needed procedure for setting
and running QEMU as emulation for ARM development board will be discussed.
2 QEMU Installation
You can install QEMU directly by typing
$sudo apt-get install qemu
or by getting source code from
$git clone git://git.qemu-project.org/qemu.git
then con igure and install. It is preferred to use latest method, in order to con igure the
installation.
Before start installation, some packages should be installed on your machine irst,
$sudo apt-get install zlib1g_dev
$sudo apt-get install libglib2.0-dev
$sudo apt-get install libpixman-1-dev
$sudo apt-get install libfdt
$sudo apt-get install gvncviewer
$sudo apt-get install libsdl1.2-dev
Now you can start QEMU installation using the following steps:
1
QEMU Tutorial 3. Running QEMU
3 Running QEMU
In general to run QEMU you need to provide the operating system that will run and disk space
for running it. You can imagine any qemu command should have
$qemu [Running System Image] [Disk Image]
Some other attributes are needed sometimes, but this will be discussed later.
You need then to have an image of your disk “Hardware part” and an ISO image of the
operating system that you need to virtualize “Software part”. Now lets see how to work with
QEMU as a virtualizer to get familiar with QEMU important instructions. Then we can see
how to work with QEMU as ARM board emulator.
To get a running system image, In this tutorial I downloaded Ubuntu iso ile from Ubuntu
website, my downloaded version is “ubuntu‐14.04.2‐desktop‐amd64”.
We need now to create disk image that will host this operating system. lets work in
WORKING_DIR
$cd path/to/WORKING_DIR
$qemu-img create -f qcow tutorial_disk.img 3G
$qemu-system-x86_64 -cdrom ubuntu-14.04.2-desktop-amd64.iso -hda \
tutorial_disk.img -m 1024 -boot d
In the command “qemu‐img create ‐f qcow tutorial_disk.img 3G” we created an image of
the harddisk with size 3G.
In the last command “‐cdrom” is used to indicate for qemu as this iso ile is running as
from cdrom. “‐hda” to direct qemu that this system will run on a harddisk “tutorial_disk.img”.
“‐m” is used to indicate what the RAM speed which is in our example 1024 M.
your operating system should run then. Note, if you found this message at the start “Failed
to access perfctr msr” this is not error message, it says that the CPU doesn’t support performance
counters. You should have your system as shown in igure 1. You can continue with setup of
your operating system.
2
QEMU Tutorial 4. QEMU for ARM Development Boards
Since we target to work with development board, we need to make sure also that QEMU
is supporting emulation of these boards. You can check that by typing
$qemu-system-arm -M ?
M denotes for machine, as development boards are de ined as machines. You will get like
igure 3.
It worth mentioning here that, to work with Raspberry board versatilepb board is used
instead.
3
QEMU Tutorial 5. Get Hardware Speci ications
If previous checks are met, everything shall be ready then for emulation. In this tutorial
we will go through Raspberry Pi board emulation.
For Raspberry pi, you can ind ready builds “operating systems” that are designed to work
with this board. You can ind online these builds at the following link
http://www.raspberrypi.org/downloads/
4
QEMU Tutorial 6. Get Running Operating System
Currently we will work with Raspbian, so download this image. This image is downloaded
with size ~ 700 M. The emulation can’t run on this space, so we have to append more disk
space for this image. You can do that using qemu with the following command
$qemu-img resize 2015-02-16-raspbian-wheezy.img +2G
Image size will be around 2.7 G after this operation.
6.2 Kernel
Downloaded image “Raspbian” can’t work standalone, you need to provide the kernel on
which this image will run. Any Linux kernel should be suitable for running. So download
any Linux kernel.
Operating System that you need to run should be also supporting working on ARM processors.
To know that open the directory of your Linux version (directory of the Linux that you will
run on the board) > > arch > > arm. You will ind there folders with each supported machine.
Since we target to emulate Raspberry, the Versatile machine should be supported. So in arm
directory open folder “mach‐versatile”. Open “Kcon ig” to know which models of the machine
are supported.
Now step back up to arm directory then open folder “mm” then open ile “Kcon ig”. You
will ind there all supported processors architecture by this Linux version. Make sure that
your architecture is covered by the machine we will work with.
For example, In latest version downloaded from Linux kernel, ARMv6 wasn’t covered by
versatilepb machine. But our emulation needs it. So I added machine name “ARCH_VERSATILE_PB”
in Kcon ig ile as shown in the following igure.
If your kernel is supporting the versatile machine, you can continue now with compilation
steps. In the following steps we will show how to prepare a kernel for raspberry emulation.
As any kernel, it should be compiled for the target platform. Compile means to convert
system ile (normally in C) to the suitable instruction set. That is why we have to make sure
that the kernel is supporting target architecture. We need then a tool that compiles the system
iles to the target machine language. This tool is the cross compiler.
For Linux, you can work with a tool called codesourcery or linearo. In this tutorial we will
work with codesourcery. You can download it from the link
https://sourcery.mentor.com/sgpp/lite/arm/portal/kbentry62
a ile called “arm‐2010.09‐50‐arm‐none‐linux‐gnueabi” shall be downloaded, install it
5
QEMU Tutorial 6. Get Running Operating System
$chmod +x arm-2010.09-50-arm-none-linux-gnueabi.bin
$./arm-2010.09-50-arm-none-linux-gnueabi.bin
Usually, you will get an error message tells that dash shell is not supported.
6
QEMU Tutorial 6. Get Running Operating System
7
QEMU Tutorial 6. Get Running Operating System
Also in “General Setup” de ine the name of the cross compiler in “Cross‐compiler tool
pre ix” option as “Arm‐none‐linux‐gnueabi‐” and don’t forget the last dash ‐. this is the name
of codesourcery that we just installed. You can igure out this name from the bin directory of
the installation directory.
8
QEMU Tutorial 7. Start the Emulation
After this con iguration step, your kernel is ready for compilation.
$make ARCH=arm
$make ARCH=arm INSTALL_MOD_PATH=../modules modules_install
To here you have compiled successfully a kernel for emulation usage. You can ind an
image created for this kernel in the directory arch/arm/boot, there you can ind zImage of
the kernel. We will use this image to run the emulation, so take a copy.
9
QEMU Tutorial 7. Start the Emulation
KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n",
Don’t forget the last comma. Then press Ctrl+O <ENTER> to write the ile and then Ctrl+X
to exit the editor.
Up to here all ixes needed for the image to run on qemu has been applied. We can now
start running the system on Qemu. Close current Qemu window and write back in Terminal
window the following
$qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -append
"root=/dev/sda2 panic=1" -hda 2015-02-16-wheezy-raspbian.img
It will boot to raspi‐con ig as shown in igure 9. Click Finish
10
QEMU Tutorial 7. Start the Emulation
11
QEMU Tutorial 7. Start the Emulation
Select Finish
12
QEMU Tutorial 7. Start the Emulation
We need to do some ixes for the emulation display, write the following command
$sudo nano /etc/X11/xorg.config
13
QEMU Tutorial 7. Start the Emulation
14
QEMU Tutorial 7. Start the Emulation
Enter
15
Bibliography
[1] http://xecdesign.com/qemu‐emulating‐raspberry‐pi‐the‐easy‐way/
[2] http://xecdesign.com/compiling‐a‐kernel/
[3] http://www.elinux.org/Virtual_Development_Board
[4] https://balau82.wordpress.com/arm‐emulation/
[5] https://sourcery.mentor.com/sgpp/lite/arm/portal/kbentry62
[6] https://www.cs.umd.edu/~meesh/cmsc411/website/proj01/arm/
[7] https://darrenjw2.wordpress.com/2015/02/07/getting‐started‐with‐snappy‐
ubuntu‐core‐on‐the‐ raspberry‐pi‐2/
[8] http://www.pezzino.ch/sourcery‐codebench‐lite/
[9] https://gist.github.com/bdsatish/7476239
[10] http://www.slideshare.net/sherif_mosa/building‐embedded‐linux‐full‐tutorial‐for‐
arm
16