Emulating an ARM versatile express in Linux system using Qemu with minimal file system1. Requirements
a) Qemu
b) toolchain – cross compiling
c) Linux Kernel source code
d) Busybox – file system
a) Steps for installing Qemu
1. Create a directory
$ mkdir Source_Code
2. enter into the directory
$ cd Source_Code
3. clone the souce code of qemu from github
$ git clone git://git.qemu-project.org/qemu.git
4. enter in to the cloned directory
$ cd qemu
5. checkout the stable version from git
$ git checkout remotes/origin/stable-2.5 -b stable-2.5
6. create a path to compile the ./config file from qemu
$ cd ../../
$ mkdir -p Binary_images/Qemu_Bin
7. enter into the source directory qemu again
$ cd Source_Code/qemu
8.change the target location to the preferred directory
$ ./configure --target-list=arm-softmmu --prefix= ../../Binary_images/Qemu_Bin
9. This will create a Makefile in the directory and Build it
$ make
10. Now make it install by using the cmd
$ make install
b) Steps for downloading Toolchain
1.Enter to the link
http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi/
2.Download the latest version from the list
arm-2014.05-29-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
3. Enter to the Binary_images directory and create a directory
$ cd Binary_images
$ mkdir -p ARM_Cross_Tools
4. Enter to the ARM_Cross_Tools and download the toolchain into ithe folder
$ cp ~/Downloads/arm-2014.05-29-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2 ~/Desktop/Source_Code/Binary_images/ARM_Cross_Tools
5. Enter into the ARM_Cross_Tools directory
$ cd ARM_Cross_Tools
6. Extract the toolchain with tar cmd into the same directory
$ tar xvf arm-2014.05-29-arm-none-linux-gnueabi-i686-pc-linux-gnu.tar.bz2
b.1) Exporting the path to make it fixed for all time purpose
1. open the bashrc file
$ vi ~/.bashrc
2. add the line to the end of the file
export PATH= ~/Desktop/Source_Code/Binary_images/ARM_Cross_Tools/arm-2014.05/bin:$PATH
3. save the file with :wq! Or with ZZ.
c) Steps for Downloading Linux Kernel source code
1. Enter into the source_code directory again
$ cd Source_Code
2. clone the souce code of Likux kernel from github
$ git clone https://github.com/torvalds/linux
3. enter in to the cloned directory
$ cd linux
4. Checkout the stable version from git by Switching to version v4.4, Where linux kernel get updated daily
$ git checkout v4.4
This kernel source doesn't have any file system so we can take Busybox which gives us Rfs.
d) Steps for Downloading Busybox for Root file Sytem.
1.Enter to the link
https://busybox.net/downloads/
2.Download the latest version from the list
busybox-1.26.1.tar.bz2
3. Enter to the Binary_images directory
$ cd Binary_images
4. Enter to the Binary_images and download the Busybox into the folder
$ cp ~/Downloads/busybox-1.26.1.tar.bz2 ~/Desktop/Source_Code/Binary_images/
5. Enter into the Binary_images directory
$ cd ~/Desktop/Source_Code/Binary_images/
6. Extract the busybox source code with tar cmd into the same directory
$ tar xvf busybox-1.26.1.tar.bz2
Emulating steps
Step 1 – Selecting the Kernel config file:
1. Enter into the Linux source code
$ cd ~/Desktop/Source_Code/linux
2. Load default config for target board from ~/Documents/qemu-test/source_code/linux/arch/arm/ configs
Here we can find different defconfig files for different boards now we are doing for ARM versatile express board i.e vexpress_defconfig
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- vexpress_defconfig
3. To enable some features for the device menuconfig can be used or save it as default settings
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- menuconfig
step 2 – Compiling the kernel
1. After configuring the menu it will create a Makefile
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- all
2. Run qemu with kernel image and check wheteher it is running successfully
$ ~/Binary_images/Qemu_Bin/qemu-system-arm -M vexpress-a9 -m 512M -dtb ./arch/arm/boot/ dts/vexpress-v2p-ca9.dtb -kernel ./arch/arm/boot/zImage -append “console=ttyAMA0” -serial stdio
Explanation in the previous command
qemu-system-arm:- ARM architecture emulation
-M vexpress-a9 :- simulation vexpress-a9 veneer, for different target u can find by command qemu-system-arm -M ? which list supported target.
-dtb file :- Use file as a device tree binary (dtb) image and pass it to the kernel on boot.
-kernel :- to provide the Linux kernel image zImage
-append “console=ttyAMA0” :- kernel boot parameters, here to tell the kernel vexpress board runs, serial device which tty.
After this comiplation terminal will end in kernel panic mode. Because it doesn't have the rfs to load.
Step 3 – Busybox compilation
1. Enter into the Binary_images directory where Busybox is extracted previously
$ cd ~/Desktop/Source_Code/Binary_images/ busybox-1.26.1
2. Create a default defconfig file
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- defconfig
3. To enable Busybox as static library
$make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- menuconfig
4. In menuconfig GUI
Enter the Busybox Settings and in Build option enable the Busybox as static library.
5. Exit the menuconfig by saving
6. Now compile the Busybox
$ make ARCH=arm CROSS_COMPILE=arm-none-linux-gnueabi- install
Step 4 – Folder for VFS
1. The above build of Busybox will creates a directory called _install containing the root filesystem tree.
2. Enter into the _install directory
$ cd ~/Desktop/Source_Code/Binary_images/ busybox-1.26.1/_install
3. Add some more direcotires which make a minimal file system
$ mkdir -p proc sys tmp root var mnt dev Home etc/init.d
step 5 – Download embedded linux files from git
1.Enter into the Binar_images directory
$ cd ~/Desktop/Source_Code/Binary_images/
2. Clone the files from git
$ git clone https://github.com/mahadevvinay/Embedded_Linux_Files.git
3. enter in to the cloned directory
$ cd Embedded_Linux_Files
4. Copy the file to the respective directories in _install directory.
$ cp fstab ~/Desktop/Source_Code/Binary_images/ busybox-1.26.1/_install/etc/
$ cp inittab ~/Desktop/Source_Code/Binary_images/ busybox-1.26.1/_install/etc/
$ cp rcS ~/Desktop/Source_Code/Binary_images/ busybox-1.26.1/_install/etc/init.d/
Step 6 – File in the rcs should be given permission
$ chmod 777 ~/Desktop/Source_Code/Binary_images/ busybox-1.26.1/_install/etc/init.d/rcS
step 7 - Creating ext3 image file and Copy all the files in our _install folder to image:
$ dd if=/dev/zero of=RootFS.ext3 bs=1M count=$((32))
$ sudo mkfs.ext3 RootFS.ext3
$ mkdir tmpfs
$ sudo mount -t ext3 RootFS.ext3 tmpfs/ -o loop
$ sudo cp -r _install/* tmpfs/.
$ sudo umount tmpfs
Step 8 – Emulating the Qemu
~/Desktop/Source_Code/Binary_images/Qemu_Bin/bin/qemu-system-arm -M vexpress-a9 -dtb ~/Desktop/Source_Code/linux/arch/arm/boot/dts/vexpress-v2p-ca9.dtb -kernel ~/Desktop/Source_ Code/linux/arch/arm/boot/zImage -append "root=/dev/mmcblk0 console=ttyAMA0" -sd ~/Desktop/ Source_Code/Binary_images/busybox-1.26.1/RootFS.ext3 -serial stdio
Done. This will emulate the system terminal with Root file System.
You have learnt a new thing now.............All the best:-)