Column 4: Getting started under QEMU. (2011-07-20)

Everybody who runs Linux can have at least some hands-on experience with Coreboot. The PC emulator QEMU can use a Coreboot ROM image file instead of its normal BIOS ROM image. So there is absolutely no risk of frying your motherboard with that. On the downside: you can only test the "easy part" of Coreboot. The hard part (low-level chipset and RAM initialization) under QEMU will not be representative of real hardware (RAM just works from the start in QEMU).

Before you begin

In this document I will explain how to get started with Coreboot using Ubuntu Linux 11.04. It may (and probably will) work on different recent Linux distributions and possibly some non-Linux distributions as well. QEMU will run on Windows but its paths for ROM images are different from Linux. If you run Windows you have some viable options to run the development tools as well, such as Cygwin and running Ubuntu itself under QEMU. The following packages will be needed.

Under Ubuntu 11.04 you can get all required packages at once using the following command:

$ sudo apt-get install qemu git flex bison ncurses-dev

It is worth reading the Coreboot Build Howto and the the Coreboot SeaBIOS page at the main Coreboot site.

Getting yourself up to speed with QEMU

Before you start running Coreboot on QEMU, it is very well worth you time to get familiar with QEMU using its own BIOS (which is SeaBIOS by the way).

Obtaining the sources

The Coreboot project uses git as its version control system. Anonymous read-only access is available. Obtain the project with the following command.

git clone http://review.coreboot.org/p/coreboot

This command downloads the sources of Coreboot project only, but not the payloads. When building Coreboot with SeaBIOS (the default), the make procedure will automatically download the SeaBIOS sources.

Under the "coreboot" directory you can later type the "git pull" command to update the source tree to the latest available version.

$ cd coreboot
$ git pull

Building the cross compiler

Even though your PC will likely use the same CPU architecture as Coreboot (both x86), it is still strongly recommended to use a cross compiler. Especially where it comes to 16-bit code and properly linking the code into a single ROM image, it is very important to use the exact correct version of certain tools. If there are bugs in certain versions of GNU tools, at least you can be fairly sure that they are the same as those encountered by the main developers. This is true when you use the same version of GCC, bintils and all related tools as the developers are using.

Because the build procedure is fully scripted, building the cross toolchain is only hard for your computer, not for you (and hopefully it is a one-time job). Make sure the development tools including bison and flex are in place before you start.

Type the following commands and take a long break.

$ cd coreboot
$ make crossgcc

Stealing the VGA BIOS

Fortunately this is legal, at least for the open source VGA BIOS image included with QEMU. Neither Coreboot nor SeaBIOS includes a usable VGA BIOS, so it is necessary to reuse the VGA BIOS that came from QEMU. This will be included in the main ROM image, so it won't be a separate ROM image.

Make sure you are in the coreboot directory and copy the image from the directory where QEMU stores it.

$ cp /usr/share/qemu/vgabios-cirrus.bin .

Configuring and building the BIOS

Now it's time to configure Coreboot. The default "mainboard" is already set to "QEMU" and the default payload is already set to "SeaBIOS", but there are still a few things left to do. First run the following command:

$ make menuconfig

If you have ever configured a Linux kernel, this interface should be very familiar to you. Perform the following configuration steps.

Exit and save as usual.

Now you are ready to run make.

$ make
The make command downloads the SeaBIOS project with git and builds it as a payload. It builds Coreboot itself and at the end it puts everything into a single file named "coreboot.rom" in the "build" directory. This is a ROM image file.

Testing the result

Now that the ROM image is made, the only thing left to do is to make it visible for QEMU. In this example we start QEMU from the "coreboot" directory. Next we can run QEMU.

$ ln -s build/coreboot.rom bios.bin
$ qemu -L . -hda ../images/debian_hd.img -cdrom ../images/debian-6.0.1a-i386-netinst.iso -m 512 -serial stdio

A few remarks:

Where to go from here?

Hopefully the first attempt to run Coreboot under QEMU was a success. Now you are ready to experiment. There are many things you can try:

So even the "easy part" offers lots of room for experimentation.