QEMU Build Tutorial
The wiki is being retired!
Documentation is now handled by the same processes we use for code: Add something to the Documentation/ directory in the coreboot repo, and it will be rendered to https://doc.coreboot.org/. Contributions welcome!
If you don't have a mainboard supported by coreboot don't worry: QEMU can help you to emulate one. Using coreboot with QEMU may serve the purpose to familiarize you as a developer with coreboot and may be a reference system during development.
This nice tutorial was written by Alan Carvalho de Assis, with additions by Ed Swierk (but please use the coreboot mailing list rather than emailing the authors directly).
While there are many ways to use coreboot to load and run a Linux kernel, this tutorial covers two of the most common:
- coreboot with FILO as payload, using FILO to load a Linux kernel (and optional initramfs) from a hard disk image. This approach involves a bit more mechanism (it relies on FILO's built-in disk and filesystem drivers) but it produces a tiny coreboot image.
- coreboot with a Linux kernel (and optional initramfs) as payload. This cuts FILO out of the picture, but the main challenge with this approach is squeezing the resulting coreboot image into QEMU's BIOS ROM area (currently 2 MB, but easy to extend by patching QEMU).
You need the following software packages:
- coreboot v4
- FILO 0.6 or greater (if using FILO)
plus a Linux kernel and root filesystem and a working development environment (make, gcc, etc.).
Building or finding a Linux kernel
If you are using FILO, you can simply grab a Linux kernel and initramfs from your favorite distribution.
Otherwise, you will probably need to build a kernel and initramfs from scratch, ensuring that the final coreboot image does not exceed QEMU's BIOS size limit (2MB if qemu-bios-size patch applied, 256KB otherwise). Building the kernel and initramfs is beyond the scope of this tutorial; how you configure them depends on your application.
If you plan to use kexec to chain-boot another Linux kernel, tools from these projects can help automate the process of generating a kernel and initramfs:
Building a FILO payload
If you plan to build your Linux kernel and root filesystem directly into coreboot, you can skip this section.
Download FILO, and cd to the filo directory
First invocation of make creates the config file.
$ make menuconfig
Run make again to create build/filo.elf, the ELF FILO image.
You will use this file (filo.elf) as the coreboot payload later on.
Building a Linux kernel payload
If you are using FILO, skip this section.
Specify the Linux as payload type and the Linux kernel (bzImage file), initrd and kernel command line that should be used in `make menuconfig`'s Payload section
See the Build HOWTO for information on how to build coreboot for this board.
This creates the coreboot image (build/coreboot.rom).
Qemu used to require patches to work with coreboot, but any current standard build (as packaged by distributions) should be good enough.
Creating a hard disk image
If you are using FILO, you must create a hard disk image containing the Linux kernel and optional initramfs that FILO loads.
Whether or not you use FILO, you may also wish to populate the disk image with the root filesystem of whatever Linux distribution you want to run.
Create an empty disk image:
$ qemu-img create -f raw disk.img 200M
$ mkfs.ext2 -F disk.img
The remaining steps must be performed as root. Create a temporary mountpoint and mount the image:
# mkdir /mnt/rootfs # mount -o loop disk.img /mnt/rootfs
Create a boot directory and copy your Linux kernel (vmlinuz) and initramfs (initrd) to it:
# mkdir /mnt/rootfs/boot # cp vmlinuz /mnt/rootfs/boot/vmlinuz # cp initrd /mnt/rootfs/boot/initrd
At this point, you can also copy a complete root filesystem to the disk image.
# cp -R /* /mnt/rootfs
Alternatively, with Debian you can use the debootstrap command to create a basic root filesystem:
# debootstrap --arch i386 sarge /mnt/rootfs http://ftp.debian.org/debian/
If you are using a debootstrap filesystem, open the file /mnt/rootfs/etc/inittab and change runlevel to level 1:
cd out of /mnt/rootfs and umount it:
# umount /mnt/rootfs
Exit from the root account:
Starting coreboot in QEMU
Execute QEMU using the following parameters:
$ qemu -bios path/to/coreboot.rom -hda disk.img -nographic
The -bios option tells QEMU to use path/to/coreboot.rom as its BIOS. The -nographic option suppresses the graphical VGA display and connects the virtual machine's serial port to your console. If you want to keep VGA display, you can use "-serial stdio" instead, which only redirects serial to the console.
You should now see all sorts of interesting coreboot messages, followed by Linux kernel boot messages or a FILO prompt.
If you are using FILO, enter at the boot: prompt:
kernel hda:/boot/vmlinuz root=/dev/hda initrd hda:/boot/initrd boot console=ttyS0