This tutorial introduces you to the world of Linux based embedded systems. Here we will learn to cross-compile your own Linux kernel and bring up a complete system with that kernel. And the best part is, you do not have to own a development board or brick your PC while learning this.
The main components involved in our tutorial today are
Qemu is the emulator that will help up work around the requirement of a physical development machine by providing a virtualized environment to bring up our kernel without putting your actual system in “harms way”
Buildroot is basically a set of scripts the that will automate the process of cross-compiling the kernel and tool-chain for you.
First, to get the basics right, To bring up any software in any new platform, you first need to have a tool chain that includes libraries, compiler, assembler, linker etc that supports your platform. In our case, the platform is a virtualized environment. So, we first need to cross-compile the tool chain itself. so that it can generate binaries sporting the platform.
Following this, we need to compile the Linux kernel code using the cross-tool chain that we generated to produce a “Linux kernel boot executable” for the platform.
Now, in a general sense, the kernel needs a root file system (RFS) to boot up and be usable. (We will discuss the details of why this is required in a later session)
Buildroot does all the above for you automatically. We just have to tell the details of the platform to buildroot and it will generate the tool-chain, kernel image and minimal RFS for you.
For this, first download the latest buildroot from here. At the time of writing
buildroot-2012.11.1 is the latest and greatest. Once you download the archive, un-compress it and go inside the folder.
The list of platforms with ready made support is in the configs directory.
In this tutorial , we are going to build a system around
qemu_x86_defconfig. So, give the following set of commands.
1 2 make qemu_x86_defconfig make
The first command will generate the
.config file used by buildroot and the second command will download all necessary source packages and compile the actual images for you. (This will take some time:). I got the following time stat while compiling in 16x build server with 12 parallel jobs )
1 2 3 real 14m57.942s user 39m29.166s sys 5m57.716s
Once the build is done, you can go to the
output/images folder and find the two output files:
bzImage: Linux kernel x86 boot executable RO-rootFS, swap_dev 0x1, Normal VGA
rootfs.ext2: Linux rev 0.0 ext2 filesystem data
The toolchain will be at
Buildroot generates a toolchain based on uclibc which is a fully functional, yet size optimized avatar of glibc.
Now, we need to fire-up qemu. Here Iam going to show a GUI method to bring qemu up on Windows. However, the steps are similar in Linux based systems also.
Download Qemu Manager here and install it. Open the qemu manager UI and do the following configuration.
Create a new Virtual machine named QemuLinuxTest with “Standard x86/x64 PC as the platform and “Linux Distribution” as the operating system.
For now, choose “Do not use a Virtual disk image”
Once this is done, Select the virtual machine from the panel in the left and do the following configuration.
Point “HardDisk 0” to the generated RFS image
Enter the kernel path and the additional command line append
root=/dev/sda in the advanced tab.
Now, click the start icon and see your own cross-compiled kernel coming to life
Even without qemu manager, you can manage to run the virtual machine by issuing the following command
qemu-system-i386 -M pc -kernel output/images/bzImage -drive file=output/images/rootfs.ext2,if=ide -append root=/dev/sda
In case you are working in a non-graphic environment, you can use
-cursesoption. In this case, use the
poweroffcommand to return to your system.
To make changes to the default configuration (
qemu_x86_defconfig) issue the following command after [
To make changes to the linux kernel configuration , issue
To make changes to the uclibc configuraition, issue
Share onTwitter Facebook Google+ LinkedIn
Leave a Comment
Your email address will not be published. Required fields are marked *