Tag Archives: emulation

Raspberry Pi Emulator on Ubuntu 12.04 LTS

You have two options:

  1. Use a Ubuntu Desktop version with Gnome environment already preinstalled (do you really need all that crap?!)
  2. Install a brand new Ubuntu server 12.04 x64 LTS, basic, without Gnome or any super fancy packages… just a basic installation with SSH (suggested but not required). And after, just follow the post here to install a “Minimal X server”.If you want to change a bit the look of the login screen, you can have a look to this post.
    This is what I’ve done 🙂

Please note that a graphic environment is REQUIRED for this emulator to work.

Compile and install QEMU

Packages:

sudo apt-get install git zlib1g-dev libsdl1.2-dev libpixman-1-dev

Working directory:

mkdir ~/raspidev && cd ~/raspidev/
git clone git://git.qemu-project.org/qemu.git

It will take a while

Once done:

cd qemu
./configure --help

Read the output carefully (options of interest highlighted):

Usage: configure [options]
Options: [defaults in brackets after descriptions]

Standard options:
--help                   print this message
<span style="color: #0000ff;">--prefix=PREFIX          install in PREFIX [/usr/local]</span>
--interp-prefix=PREFIX   where to find shared libraries, etc.
use %M for cpu name [/usr/gnemul/qemu-%M]
<span style="color: #0000ff;">--target-list=LIST       set target list (default: build everything)</span>
Available targets: i386-softmmu x86_64-softmmu
<span style="color: #0000ff;">arm-softmmu</span> cris-softmmu lm32-softmmu m68k-softmmu
microblaze-softmmu microblazeel-softmmu mips-softmmu
mipsel-softmmu mips64-softmmu mips64el-softmmu
ppc-softmmu ppcemb-softmmu ppc64-softmmu sh4-softmmu
sh4eb-softmmu sparc-softmmu sparc64-softmmu
s390x-softmmu i386-linux-user x86_64-linux-user
alpha-linux-user <span style="color: #0000ff;">arm-linux-user</span> armeb-linux-user
cris-linux-user m68k-linux-user
microblaze-linux-user microblazeel-linux-user
mips-linux-user mipsel-linux-user ppc-linux-user
ppc64-linux-user ppc64abi32-linux-user
sh4-linux-user sh4eb-linux-user sparc-linux-user
sparc64-linux-user sparc32plus-linux-user
unicore32-linux-user s390x-linux-user

Advanced options (experts only):
--source-path=PATH       path of source code [/home/shift/openembedded/qemu]
--cross-prefix=PREFIX    use PREFIX for compile tools []
--cc=CC                  use C compiler CC [gcc]
--host-cc=CC             use C compiler CC [gcc] for code run at
build time
--extra-cflags=CFLAGS    append extra C compiler flags QEMU_CFLAGS
--extra-ldflags=LDFLAGS  append extra linker flags LDFLAGS
--make=MAKE              use specified make [make]
--install=INSTALL        use specified install [install]
--python=PYTHON          use specified python [python]
--static                 enable static build [no]
--mandir=PATH            install man pages in PATH
--datadir=PATH           install firmware in PATH
--docdir=PATH            install documentation in PATH
--bindir=PATH            install binaries in PATH
--sysconfdir=PATH        install config in PATH/qemu
--enable-debug-tcg       enable TCG debugging
--disable-debug-tcg      disable TCG debugging (default)
--enable-debug           enable common debug build options
--enable-sparse          enable sparse checker
--disable-sparse         disable sparse checker (default)
--disable-strip          disable stripping binaries
--disable-werror         disable compilation abort on warning
--disable-sdl            disable SDL
<span style="color: #0000ff;">--enable-sdl             enable SDL</span>
--disable-vnc            disable VNC
--enable-vnc             enable VNC
--enable-cocoa           enable COCOA (Mac OS X only)
--audio-drv-list=LIST    set audio drivers list:
Available drivers: oss alsa sdl esd pa fmod
--audio-card-list=LIST   set list of emulated audio cards [ac97 es1370 sb16 hda]
Available cards: ac97 es1370 sb16 cs4231a adlib gus hda
--block-drv-whitelist=L  set block driver whitelist
(affects only QEMU, not qemu-img)
--enable-mixemu          enable mixer emulation
--disable-xen            disable xen backend driver support
--enable-xen             enable xen backend driver support
--disable-brlapi         disable BrlAPI
--enable-brlapi          enable BrlAPI
--disable-vnc-tls        disable TLS encryption for VNC server
--enable-vnc-tls         enable TLS encryption for VNC server
--disable-vnc-sasl       disable SASL encryption for VNC server
--enable-vnc-sasl        enable SASL encryption for VNC server
--disable-vnc-jpeg       disable JPEG lossy compression for VNC server
--enable-vnc-jpeg        enable JPEG lossy compression for VNC server
--disable-vnc-png        disable PNG compression for VNC server (default)
--enable-vnc-png         enable PNG compression for VNC server
--disable-vnc-thread     disable threaded VNC server
--enable-vnc-thread      enable threaded VNC server
--disable-curses         disable curses output
--enable-curses          enable curses output
--disable-curl           disable curl connectivity
--enable-curl            enable curl connectivity
--disable-fdt            disable fdt device tree
--enable-fdt             enable fdt device tree
--disable-check-utests   disable check unit-tests
--enable-check-utests    enable check unit-tests
--disable-bluez          disable bluez stack connectivity
--enable-bluez           enable bluez stack connectivity
--disable-slirp          disable SLIRP userspace network connectivity
--disable-kvm            disable KVM acceleration support
--enable-kvm             enable KVM acceleration support
--disable-nptl           disable usermode NPTL support
--enable-nptl            enable usermode NPTL support
--enable-system          enable all system emulation targets
--disable-system         disable all system emulation targets
--enable-user            enable supported user emulation targets
--disable-user           disable all user emulation targets
--enable-linux-user      enable all linux usermode emulation targets
--disable-linux-user     disable all linux usermode emulation targets
--enable-darwin-user     enable all darwin usermode emulation targets
--disable-darwin-user    disable all darwin usermode emulation targets
--enable-bsd-user        enable all BSD usermode emulation targets
--disable-bsd-user       disable all BSD usermode emulation targets
--enable-guest-base      enable GUEST_BASE support for usermode
emulation targets
--disable-guest-base     disable GUEST_BASE support
--enable-user-pie        build usermode emulation targets as PIE
--disable-user-pie       do not build usermode emulation targets as PIE
--fmod-lib               path to FMOD library
--fmod-inc               path to FMOD includes
--oss-lib                path to OSS library
--enable-uname-release=R Return R for uname -r in usermode emulation
--sparc_cpu=V            Build qemu for Sparc architecture v7, v8, v8plus, v8plusa, v9
--disable-uuid           disable uuid support
--enable-uuid            enable uuid support
--disable-vde            disable support for vde network
--enable-vde             enable support for vde network
--disable-linux-aio      disable Linux AIO support
--enable-linux-aio       enable Linux AIO support
--disable-attr           disables attr and xattr support
--enable-attr            enable attr and xattr support
--enable-io-thread       enable IO thread
--disable-blobs          disable installing provided firmware blobs
--enable-docs            enable documentation build
--disable-docs           disable documentation build
--disable-vhost-net      disable vhost-net acceleration support
--enable-vhost-net       enable vhost-net acceleration support
--enable-trace-backend=B Set trace backend
Available backends: nop simple stderr ust dtrace
--with-trace-file=NAME   Full PATH,NAME of file to store traces
Default:trace-<pid>
--disable-spice          disable spice
--enable-spice           enable spice
--enable-rbd             enable building the rados block device (rbd)
--disable-smartcard      disable smartcard support
--enable-smartcard       enable smartcard support
--disable-smartcard-nss  disable smartcard nss support
--enable-smartcard-nss   enable smartcard nss support
--disable-usb-redir      disable usb network redirection support
--enable-usb-redir       enable usb network redirection support
--disable-guest-agent    disable building of the QEMU Guest Agent
--enable-guest-agent     enable building of the QEMU Guest Agent

NOTE: The object files are built at the place where configure is launched

Easiest way:

./configure --help | egrep -i "PREFIX|everything|arm-softmmu|arm-linux-user|SDL"

Then, compile and install:

make
sudo make install

Check that all is fine:

qemu-system-arm -cpu ?

The output should contain ‘arm1176‘. If all is good, go to the next steps. 😉

 

Create the emulation environment

cd ~
mkdir raspemu && cd raspemu

Get the linux kernel:

wget http://xecdesign.com/downloads/linux-qemu/kernel-qemu

Download a raw image of Raspberry Pi from here and save in the same folder

wget http://downloads.raspberrypi.org/raspbian_latest

If you want to play a bit with it, you might need to pre-expand the file size, in order to have some extra space (by default you have only 200 Mb free on the current image).
For this, you can use the following commands, to add 2GB to the image:

dd if=/dev/zero bs=1M count=2048 >> path/your_image.img

Then, launch your qemu, and inside the console, try to useraspi-config script to automatically expand the filesystem.
Otherwise, try the following to do it manually (not tested):

PART_START=$(parted /dev/sda -ms unit s p |grep “^2? | cut -f 2 -d:)
echo $PART_START # (to be sure that it’s not empty).
fdisk /dev/sda <<EOF
p
d
2
n
p
2
$PART_START
p
w
EOF

Then reboot and launch resize2fs /dev/root
Now, you’re ready for the first boot.
Create a script called first_boot.sh with the following:

qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -hda <strong>$1</strong>

Remember to setchmod +xto this file and do not try to use more than 256 MB of RAM, the value is hard-coded in and QEMU will not work correctly.

After you can easily use this syntax to start your image:

./first_boot.sh path/your_image.img

Comment the line/usr/lib/arm-linux-gnueabihf/libcofi_rpi.soin the file/etc/ld.so.preloadand reboot.
Alternatively create a file/etc/udev/rules.d/90-qemu.ruleswith the following content:

KERNEL=="sda", SYMLINK+="mmcblk0"
KERNEL=="sda?", SYMLINK+="mmcblk0p%n"
KERNEL=="sda2", SYMLINK+="root"

The kernel sees the disk as /dev/sda, while a real pi sees /dev/mmcblk0. This will create symlinks to be more consistent with the real pi.

Once done, you can create a new script called start.sh with the following content:

qemu-system-arm -kernel kernel-qemu -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw" -hda <strong>$1</strong>

And now, finally, we can run our image of Raspberry Pi running:

./start.sh path/your_image.img

NOTE: use first_boot.sh script ONLY with a brand new image. If you’re using a copy of your Pi, maybe made using dd command, just use start.sh script.

Sources:

http://xecdesign.com/compiling-qemu/
http://xecdesign.com/qemu-emulating-raspberry-pi-the-easy-way/