Using Qemu to Simulate ARM

How to use qemu to build an ARM simulator?

Download the source code of qemu from github:

1
2
$ git clone git://github.com/Xilinx/qemu.git    
$ cd qemu

The command above will by default clone the master branch of QEMU. This generally is ahead of the version of QEMU released with PetaLinux. This means it has improvements and new features compared to the released version, but is also is less thoroughly tested and could have unknown bugs. If you want to build the source that was used for the released version of QEMU, please checkout the appropriate tag instead of the master branch.
As of QEMU released with 2016.2 all tags created by Xilinx will be signed and verified by a valid PGP signature.

Install Qemu Linux Dependencies

1
$ sudo apt install libglib2.0-dev libgcrypt20-dev zlib1g-dev autoconf automake libtool bison flex

QEMU also includes sub modules that will need to be checked out. Use the follow command to checkout the appropriate sub modules.

1
$ git submodule update --init dtc

Configuring QEMU

QEMU must be configured to build on the Linux host. This can be accomplished using the following command line.

1
$ ./configure --target-list="aarch64-softmmu,microblazeel-softmmu" --enable-fdt --disable-kvm --disable-xen

Building QEMU

The following command line builds QEMU to run on the host computer.

1
make

Download Linux kernel && devicetree

Download xilinx release image, version zynq 2016.4. From url http://www.wiki.xilinx.com/Zynq%202016.4%20Release we can get file 2016.4-zc706-release.tar.zx, compress this file and we will get dtb && uImage. Besides, we can produce our own devicetree and customed kernel.

Download Ubuntu Filesystem

At this time, we choose a existed filesystem. From source https://rcn-ee.com/rootfs/eewiki/minfs/ we download file ubuntu-16.04.4-minimal-armhf-2018-03-26.tar.xz. Compress the file and we will get the rootfs x.tar.

Make a startup disk

1
2
3
4
5
6
7
8
9
dd if=/dev/zero of=ubuntu.ext4 # produce a file named ubuntu.ext4
mkfs.ext4 ubuntu.ext4 # Format ubuntu.ext4
sudo mkdir -p /mnt/rootfs # make a dir /mnt/rootfs
sudo mount ubuntu.ext4 /mnt/rootfs # mount ubuntu.ext4 to /mnt/rootfs
sudo tar x.tar -C /mnt/rootfs/
sync #
sudo chown root:root /mnt/rootfs/
sudo chmod 755 /mnt/rootfs
sudo umount /mnt/rootfs

Start Up Qemu

In the file qemu, excute the following command

1
2
3
4
5
6
7
./aarch64-softmmu/qemu-system-aarch64  
-M arm-generic-fdt-7series -machine linux=on
-serial /dev/null -serial mon:stdio -display none
-kernel ../project/2016.4-zc706-release/zc706/uImage
-dtb ../project/2016.4-zc706-release/zc706/my.dtb
-sd ../project/ubuntu.ext4
-append 'root=/dev/mmcblk0 rw rootwait console=ttyPS0 devtmpfs mount=0'

Anoter way to start qemu:

1
2
3
4
5
6
7
 ./aarch64-softmmu/qemu-system-aarch64  
-M arm-generic-fdt-7series -machine linux=on
-serial /dev/null -serial mon:stdio -display none
-kernel ../project/2016.4-zc706-release/zc706/uImage
-dtb ../project/2016.4-zc706-release/zc706/my.dtb
-drive if=sd,cache=writeback,file=../project/ubuntu.ext4
-append 'root=/dev/mmcblk0 rw rootwait console=ttyPS0 devtmpfs mount=0'

Anotations below to specify the meanings of the arguments:

1
2
3
4
5
6
7
# qemu-system-aarch64
# -M
# -serial
# -kernel
# -dtb
# -drive
# -append

Standard Arguments Required

The standard arguments to startup qemu can been seen @: https://qemu.weilnetz.de/doc/qemu-doc.html#pcsys_005fquickstart

Reference: Xilinx Qemu Wiki