QEMU based virtual image.
- QEMU contains definitions/implementations for various machines that are also supported by linux kernel, we will use the Versatile Express one (vexpress).
- It is possible to create and boot a full image the same way as with real hardware: have u-boot started on boot and use that to boot linux. However, qemu can also boot a linux kernel directly and we will use that here.
QEMU
- Install system qemu:
apt-get install qemu
-
Compile qemu from source:
wget http://wiki.qemu-project.org/download/qemu-2.5.0-rc2.tar.bz2 tar xf qemu-2.5.0-rc2.tar.bz2 cd qemu-2.5.0-rc2 ./configure --target-list=arm-softmmu,arm-linux-user --prefix=$(HOME)/embeddedlinux/usr make -j5 make install
Toolchain
As we will be using (emulating) an "older" machine, the cortex A9 toolchains we used in the
other case will not work for us. We will use an older Codesourcery arm toolchain (note that
it's prefix is arm-none-linux-gnueabi-
).:
wget http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi/arm-2014.05-29-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 tar xf arm-2014.05-29-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 export PATH=$PWD/arm-2014.05/bin:$PATH
Kernel
We will use a vanilla kernel with the versatile-quemu
defconfig.
and
versatile-pb
DTB.
wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.2.3.tar.xz tar xf linux-4.2.3.tar.xz cd linux-4.2.3/ export ARCH=arm export CROSS_COMPILE=arm-none-linux-gnueabi- # defconfig make versatile_qemu_defconfig # for faster build (we don't need modules right now): make -j5 zImage dtbs time ionice -c3 nice -n10 make -j5 # insert sdcard, mount... cp arch/arm/boot/zImage /run/media/$USER/boot/
Booting
export PATH=$(HOME)/embeddedlinux/usr/bin/:$PATH qemu-system-arm \ -M versatilepb \ -nographic \ -kernel linux-4.2.3/arch/arm/boot/zImage \ -dtb linux-4.2.3/arch/arm/boot/dts/versatile-pb.dtb \ -append console=ttyAMA0
USB
QEMU emulates USB hardware. If you add support for OHCI (usb 1.1) and USB mass storage in the kernel, you can mount "usb disks" inside QEMU. The simplest way is to mount a file containing a filesystem image:
- in QEMU, switch to the command mode ("ctrl-A C"),
- execute
usb_add disk:FILE
, where FILE is a file containing a filesystem image, the contents will show up directly as/dev/sdX
.
You can also connect an existing usb device from your host to the QEMU system, look in qemu
documentation for the syntax of the usb_add
command. Note that the device must not
be used by the host system.