Emulating a 32-bit Raspberry Pi ARM 7 on CentOS Linux with Qemu

Overview

Emulate an ARM processor on Intel using CentOS 7 and Qemu.

Conventions

Commands run as root will appear on a black background:

Commands run as your regular user will appear on a blue background:

Prerequisite Packages

Qemu

Cross-compilation

Acquire Resources

Create a working directory in your unprivileged user home directory and clone the raspbian kernel source:

Also get the Raspbian toolchain:

Download a current version of Raspbian from downloads.raspberrypi.org and unpack. This example uses Raspbian Lite 2020-02-14:

Inspect the Raspbian Image

The output will show two partitions. When we emulate, this img file will be handed off as hda, so these two partitions will be seen by the emulator as sda1 and sda2.

Configure and Cross-Compile Kernel

Executing $ file ${HOME}/git/raspbian/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-gcc reveals that the Linaro ARM cross-compiler in the Raspbian toolchain is dynamically linked; necessitating the i686 glibc, libstdc++, and zlib packages installed (above).

The kernel will be configured to support a minimal number of features, architectures, and filesystems:

ARM/Raspberry Pi Emulation

Command breakdown (please see man qemu-system-arm for further detail):

ParameterDescription
export QEMU_AUDIO_DRV=noneDisable audio
qemu-system-armQEMU binary that emulates ARM processors
-kernel linux/vmlinuxPath to the kernel (built above)
-cpu arm1176Specific ARM processor to emulate
-m 256MMemory in MB
-machine versatilepbMachine type to emulate. Additional types can be enumerated with qemu-system-arm -machine help
-no-reboot
-serial stdioDirects serial output to stdio (linux only)
-append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash"Options to pass to the kernel to describe filesystem details and initial processes
-drive file=2020-02-13-raspbian-buster-lite.img,format=raw,index=0,media=diskDisk image containing the filesystem(s)