Monday, April 6, 2015

Building simple Linux distro for ARM qemu

Building

The simplest way to build Linux for qemu machine is to use some automated build tool. I'm aware of at least two such projects:
In this post we'll use buildroot. First download buildroot tarball from download section of buildroot home page. I'm using buildoot-2015.02 release. Extract it somewhere in your home directory. Now you'll prepare default rootfs and kernel for versatile express emulated board. Extract buildroot and prepare default configuration for this target:
wget http://buildroot.uclibc.org/downloads/buildroot-2015.02.tar.gz
tar xzf buildroot-2015.02.tar.gz
cd buildroot-2015.02/
make qemu_arm_vexpress_defconfig
Now you should be able to build your first, default, Linux distribution for qemu emulated ARM based board.
make
Note that buildroot will automatically download all needed dependencies such as cross compiler, libc, kernel, busybox etc. This will take a while when run for the first time. For example, buildroot will compile brand new gcc for cross compilation and this is relative long process. Coffee break!

Running

After completing the build you can try out how it works in conjunction with previously built qemu. All needed files are placed in output/images directory. For now we have only two files there:
  • zImage - kernel image
  • rootfs.ext2 - ext2 filesystem image with root filesystem (all userland applications, configuration files etc)
Simply run:
qemu-system-arm -M vexpress-a9 -kernel output/images/zImage -drive file=output/images/rootfs.ext2,if=sd -append "console=ttyAMA0,115200 root=/dev/mmcblk0" -serial stdio
After few seconds you should see login prompt in your terminal. Type root and press enter. Now you are in your emulated ARM Versatile Express board running your custom Linux system. Press Ctrl+C to exit VM.

This is all for today. :) Enjoy.

No comments:

Post a Comment