Building OFW to Load from BIOS: Difference between revisions

From OpenBIOS
Jump to navigation Jump to search
(Instructions for building OFW to boot under a conventional BIOS)
 
m (moved Building OFW to Run Under BIOS to Building OFW to Load from BIOS: New title is more accurate)
 
(3 intermediate revisions by the same user not shown)
Line 2: Line 2:


In addition to this BIOS-loaded version, there are two other ways to run OFW under QEMU:
In addition to this BIOS-loaded version, there are two other ways to run OFW under QEMU:
* * You can build an OFW image that replaces the QEMU BIOS ROM image, entirely from code in the OFW tree - see [[Building OFW for QEMU]].
* You can build an OFW image that replaces the QEMU BIOS ROM image, entirely from code in the OFW tree - see [[Building OFW for QEMU]].
* You can build an OFW image that replaces the QEMU BIOS ROM image, using OFW as a "payload" for Coreboot, so Coreboot does the early-startup stuff - see [[OFW as a Coreboot Payload]].
* You can build an OFW image that replaces the QEMU BIOS ROM image, using OFW as a "payload" for Coreboot, so Coreboot does the early-startup stuff - see [[OFW as a Coreboot Payload]].


Line 8: Line 8:


* qemu-0.9.1 or VirtualBox
* qemu-0.9.1 or VirtualBox
* Open Firmware rev. >= 1051
* Open Firmware rev. >= 1053
* GCC and GNU make -  most versions work for builing OFW
* GCC and GNU make -  most versions work for builing OFW


=== Building Open Firmware ===
=== Getting Open Firmware Source ===


Get the Open Firmware source:
$ svn co svn://openfirmware.info/openfirmware


  svn co svn://openfirmware.info/openfirmware
=== Building OFW ===
 
=== Build OFW ===


  $ cd cpu/x86/pc/biosload/
  $ cd cpu/x86/pc/biosload/
Line 31: Line 29:
You will use the "floppyofw.img" output file in a later step.
You will use the "floppyofw.img" output file in a later step.


=== Make a bootable Floppy Image ===
=== Making a bootable Floppy Image ===


  $ ../../../Linux/forth fw.dic ../makefloppy.fth
  $ ../../../Linux/forth fw.dic ../makefloppy.fth
Line 38: Line 36:
FAT12 filesystem.  This step only has to be done once.
FAT12 filesystem.  This step only has to be done once.


=== Copy OFW onto the Floppy Image ===
=== Copying OFW onto the Floppy Image ===


  $ mkdir flp
  $ mkdir flp
Line 47: Line 45:
Copy floppy.img to the QEMU or VirtualBox directory.
Copy floppy.img to the QEMU or VirtualBox directory.


=== Boot OFW from QEMU ===
=== Booting OFW from QEMU ===


  $ qemu -L <dir> -boot a -fda floppy.img
  $ qemu -L <dir> -boot a -fda floppy.img
Line 53: Line 51:
"<dir>" is the directory that contains QEMU's BIOS and VGA BIOS files.
"<dir>" is the directory that contains QEMU's BIOS and VGA BIOS files.


=== Boot OFW from VirtualBox ===
=== Booting OFW from VirtualBox ===


The following VirtualBox configuration settings work for me:
The following VirtualBox configuration settings work for me:
Line 75: Line 73:
copy the new OFW version to ofw.img .
copy the new OFW version to ofw.img .


== What is on the Floppy Image ==
=== What is on the Floppy Image ===


The floppy image is a bootable floppy with a FAT12 filesystem.  Its first two
The floppy image is a bootable floppy with a FAT12 filesystem.  Its first two
Line 91: Line 89:
zeros.
zeros.


== Making a Prototype Floppy Image with Linux Commands ==
=== Making a Prototype Floppy Image with Linux Commands ===


Here's a pair of Linux commands that accomplish the same thing
Here's a pair of Linux commands that accomplish the same thing
Line 126: Line 124:
   kernel ofw.c32
   kernel ofw.c32


(There is also some support in the source code / config.fth for building a version to boot via Grub, but I haven't tested that for some time, so it might be broken.)
=== Booting on a Real PC via GRUB or Etherboot ===
 
You can make a version in "Multiboot" format that you can boot with GRUB:
 
  $ cd openfirmware/cpu/x86/biosload
  $ cp config-grub.fth config.fth
  $ cd build
  $ make
 
The output file is "ofwgrub.elf".  Copy that in to /boot on your GRUB-enabled disk and add this to /boot/grub/menu.lst:
 
  title Open Firmware
  kernel /boot/ofwgrub.elf
 
That version can also be booted via Etherboot.  Here's an example of how to Etherboot it with QEMU (assuming that the ofwgrub.elf file is in /tmp on the host machine):
 
  qemu -L . -boot n -tftp /tmp -bootp /ofwgrub.elf

Latest revision as of 22:00, 18 March 2011

This page tells how to build the x86 version of Open Firmware to boot under a conventional BIOS. These instructions specifically describe a configuration that is good for running on the QEMU and VirtualBox emulators, but very similar instructions can be used to make a version that runs on any PC. In this version, OFW is stored on a floppy disk image. The conventional BIOS boots it as if it were an operating system like DOS or Windows. OFW then "takes over" the machine, ignoring the conventional BIOS that booted it. That BIOS has already done the work of early-startup machine initialization - turning on the memory controller and configuring chipset-dependent registers.

In addition to this BIOS-loaded version, there are two other ways to run OFW under QEMU:

  • You can build an OFW image that replaces the QEMU BIOS ROM image, entirely from code in the OFW tree - see Building OFW for QEMU.
  • You can build an OFW image that replaces the QEMU BIOS ROM image, using OFW as a "payload" for Coreboot, so Coreboot does the early-startup stuff - see OFW as a Coreboot Payload.

Software Requirements

  • qemu-0.9.1 or VirtualBox
  • Open Firmware rev. >= 1053
  • GCC and GNU make - most versions work for builing OFW

Getting Open Firmware Source

$ svn co svn://openfirmware.info/openfirmware

Building OFW

$ cd cpu/x86/pc/biosload/
$ cp config-virtualbox.fth config.fth
$ cd build
$ make floppyofw.img

The "config-virtualbox.fth" configuration is known to work with QEMU. Other configurations may work also - but the "qemu-loaded" config option isn't what you want for this technique, because it's a subcase of the CoreBoot-payload configuration.

You will use the "floppyofw.img" output file in a later step.

Making a bootable Floppy Image

$ ../../../Linux/forth fw.dic ../makefloppy.fth

This creates a file that is a bootable floppy image with an empty FAT12 filesystem. This step only has to be done once.

Copying OFW onto the Floppy Image

$ mkdir flp
$ sudo mount -t msdos -o loop floppy.img flp
$ sudo cp floppyofw.img flp/ofw.img
$ sudo umount flp

Copy floppy.img to the QEMU or VirtualBox directory.

Booting OFW from QEMU

$ qemu -L <dir> -boot a -fda floppy.img

"<dir>" is the directory that contains QEMU's BIOS and VGA BIOS files.

Booting OFW from VirtualBox

The following VirtualBox configuration settings work for me:

 OS Type = Other/Unknown
 Base Memory = 64 MB
 Video Memory = 8 MB
 Boot Order = Floppy, Hard Disk
 ACPI = Disabled
 IO APIC = Disabled
 VT-x/AMD-V = Disabled
 PAE/NX = Disabled
 Floppy Image = floppy.img
 Network Adapter 1  = PCnet-PCI II (host interface, <tap name>)
 (other settings are mostly irrelevant)

Recompiling

If you want to make changes and recompile OFW, you need not repeat the "makefloppy" step; you can just loopback mount the floppy image and copy the new OFW version to ofw.img .

What is on the Floppy Image

The floppy image is a bootable floppy with a FAT12 filesystem. Its first two sectors contain a simple bootloader program that uses BIOS INT 13 callbacks to read floppy sectors. The program scans the FAT root directory entries to find the file "ofw.img", then loads that into memory and jumps to it.

When you build floppyofw.img, as a side effect it also builds bootsec.img, which is that simple bootloader. The source code (Forth-style assembly language) is in biosload/bootsec.fth .

The "makefloppy.fth" program that creates the image is pretty simple; it copies bootsec.img to the output file "floppy.img", creates a couple of initially empty FAT tables, zeros the root directory area, and fills the data area with zeros.

Making a Prototype Floppy Image with Linux Commands

Here's a pair of Linux commands that accomplish the same thing as makefloppy.fth:

Step6a $ /sbin/mkdosfs -C -f 2 -F 12 -R 2 -r 224 -s 1 -S 512 floppy.img 1440
Step6b $ dd <bootsec.img of=floppy.img conv=nocreat,notrunc

The arguments to mkdosfs force the filesystem layout to match the layout that is specified in the BIOS parameter block in bootsec.img.

The advantage of makefloppy.fth is that it reads the filesystem layout parameters from the BPB in bootsec.img, so its guaranteed to be consistent. If bootsec.fth were edited to change the layout, the arguments to "mkdosfs" would have to change. (But there's little need to change that layout, since it's a standard floppy size.)

The advantage of the Linux command sequence is that it creates a file with "holes", thus saving disk space for awhile (until something fills in the holes).

Booting on a Real PC from a USB Key

To build for a real PC:

 $ cd openfirmware/cpu/x86/biosload
 $ cp config-usbkey.fth config.fth
 $ cd build
 $ make

That will create a file named "ofw.c32" that can be booted from a USB key that has "syslinux" installed on it. http://www.911cd.net/forums//index.php?showtopic=21902 has some tips on how to install syslinux.

Your syslinux.cfg file needs a line that says:

 kernel ofw.c32

Booting on a Real PC via GRUB or Etherboot

You can make a version in "Multiboot" format that you can boot with GRUB:

 $ cd openfirmware/cpu/x86/biosload
 $ cp config-grub.fth config.fth
 $ cd build
 $ make

The output file is "ofwgrub.elf". Copy that in to /boot on your GRUB-enabled disk and add this to /boot/grub/menu.lst:

 title Open Firmware
 kernel /boot/ofwgrub.elf

That version can also be booted via Etherboot. Here's an example of how to Etherboot it with QEMU (assuming that the ofwgrub.elf file is in /tmp on the host machine):

 qemu -L . -boot n -tftp /tmp -bootp /ofwgrub.elf