# Building OFW for QEMU This page tells how to build the x86 version of Open Firmware to run under the QEMU emulator. In this version, OFW replaces QEMU's normal "bios.bin" file, so QEMU boots directly into OFW, without a conventional BIOS. This version supports most of QEMU's I/O capabilities, illustrating some of the things that OFW can do. See the QEMU Options / Things to Try section. The OFW tree contains a version of the platform-specific "early startup" code that is suitable for initializing QEMU's virtual hardware. The early-startup code for QEMU is as simple as such code can possibly be, because the QEMU core system "hardware" requires no initialization. On real hardware, you must turn on PLLs, configure bus bridges and superIO chips, detect DRAM characteristics and configure memory controllers, and do other complex chipset-dependent things in the early stages of startup. QEMU omits all that "magic" stuff that is outside of generic x86 programming models, so the only system-specific early startup code for QEMU is a simple memory sizing loop. In addition to this "direct" version, there are two other ways to run OFW under QEMU: - You can build OFW as "payload" for coreboot, so Core boot does the early-startup stuff - see [OFW as a coreboot Payload](OFW_as_a_coreboot_Payload). - You can boot OFW from a conventional BIOS - see [Building OFW to Load from BIOS](Building_OFW_to_Load_from_BIOS) ## Software Requirements - qemu-0.9.1 - Open Firmware rev. \>= 1051 - GCC and GNU make - OFW builds with most versions ## Getting QEMU Get QEMU \>= 0.9.1 from ## Building Open Firmware Get the Open Firmware source:  svn co svn://openfirmware.info/openfirmware Build OFW:  cd openfirmware/cpu/x86/pc/emu/build  make After make is finished (it shouldn't take long) there should be a file "emuofw.rom" in the build directory. Copy this to your qemu directory. ## Run Your ROM Image  qemu  -L . -bios emuofw.rom  -hda fat:. That is the basic invocation; you should get a console window with OFW running in it. OFW is using the emulated Cirrus graphics display in linear framebuffer mode, not in VGA mode. ## QEMU Options / Things to Try QEMU has lots of options that let you do all sorts of fun things. The following sections illustrate a few of OFW's I/O capabilities. ### Memory Size If you look in OFW's startup banner, you should see "128 MiB memory installed". That is QEMU's default memory size. You can change that by adding "-m NNN" to the qemu command line, for example:  qemu  -L . -bios emuofw.rom  -hda fat:.  -m 32 OFW as configured will work with power-of-two size between 32 and 2048 MiB (although my QEMU installation only works up to 1024 MB). Those limits aren't inherent inheret OFW, but rather artifacts of the way this particular "port" is configured. ### Hard Disk Images The command line argument "-hda fat:." as shown above makes the current directory on the host system appear to OFW as an IDE hard disk with a read-only FAT filesystem. You can inspect it with:  ok .partitions c  ok dir c:\ The device name "c" is a devalias. You can see the actual device name with:  ok devalias c  ok devalias Instead of that "virtual FAT filesystem", you can make use Linux tools to make a filesystem image. In this example, we'll create a 10 MByte image with a single partition and an ext2 filesystem:  $ dd if=/dev/zero of=filesystem.img bs=1M count=10  $ /sbin/mke2fs -F filesystem.img  $ dd if=filesystem.img of=fs.img bs=512 seek=1  $ rm filesystem.img  $ /sbin/sfdisk -L -uS -C 10 -H 64 -S 32 fs.img \<\ syntax) for both. OFW has reasonably good support for a wide selection of USB mass storage devices - flash keys, disks, CDROMs, multi-card readers, etc. OFW also supports USB keyboards, but I haven't yet figured out how to make that work under QEMU. OFW supports some USB 2.0 network interfaces and some USB-to-serial adapters. You might be able to make those work using QEMU's ability to connect to real USB devices on the host. On real hardware, OFW supports UHCI (USB 1.1), OHCI (USB 1.1), and EHCI (USB 2.0) host controllers. ### Sound To enable sound support in QEMU, do this:  $ qemu  -L . -bios emuofw.rom  -hda fat:. -soundhw sb In OFW:  ok select /sound  ok d# 200 d# 2000 tone  ok unselect That plays a 200 Hz sine wave for 2 seconds (2000 mS). OFW can also play .wav files, but that's not included in this configuration. QEMU has a lot of options to control the sound emulation; read the documentation to get totally confused. OFW's SoundBlaster driver, as included in this configuration, is rather rudimentary. OFW has better drivers for the more common AC97 sound hardware.