Author: wmb
Date: 2008-12-06 11:40:16 +0100 (Sat, 06 Dec 2008)
New Revision: 1025
Added:
cpu/x86/pc/biosload/HOWTO_QEMU.txt
cpu/x86/pc/biosload/config-virtualbox.fth
cpu/x86/pc/biosload/makefloppy.fth
Modified:
cpu/x86/pc/biosload/mbootsec.fth
Log:
Biosload version - added instructions for creating a floppy
image that will boot under QEMU.
Added: cpu/x86/pc/biosload/HOWTO_QEMU.txt
===================================================================
--- cpu/x86/pc/biosload/HOWTO_QEMU.txt (rev 0)
+++ cpu/x86/pc/biosload/HOWTO_QEMU.txt 2008-12-06 10:40:16 UTC (rev 1025)
@@ -0,0 +1,82 @@
+== Booting OFW Under QEMU ==
+
+You can boot OFW directly from the BIOS in QEMU; you don't need
+Coreboot (formerly LinuxBIOS) or external bootloaders like GRUB
+or Lilo or syslinux. OFW has its own little (two sector) BIOS
+bootloader that can be used to make a bootable floppy image.
+
+The instructions below tell how to prepare a bootable floppy
+disk image that can be booted from QEMU, VirtualBox, or several
+other emulators.
+
+=== Build OFW ===
+
+ $ cd cpu/x86/pc/biosload/
+ $ cp config-virtualbox.fth config.fth
+ $ cd build
+ $ cd cpu/x86/pc/biosload/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 itt is a subcase
+of the CoreBoot-payload configuration.
+
+You will use the "floppyofw.img" output file in a later step.
+
+=== Make 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.
+
+=== Copy 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
+
+=== Boot OFW from QEMU ===
+
+ $ qemu -L <dir> -boot a -fda floppy.img
+
+"<dir>" is the directory that contains QEMU's BIOS and VGA BIOS files.
+
+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. 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 conistent. 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 happens to fill
+in the holes).
Added: cpu/x86/pc/biosload/config-virtualbox.fth
===================================================================
--- cpu/x86/pc/biosload/config-virtualbox.fth (rev 0)
+++ cpu/x86/pc/biosload/config-virtualbox.fth 2008-12-06 10:40:16 UTC (rev 1025)
@@ -0,0 +1,136 @@
+\ See license at end of file
+purpose: Establish configuration definitions
+
+\ create pc \ Demo version for generic PC
+\ create pc-linux \ Demo version for generic PC and Linux
+\ create pc-serial \ Demo version for generic PC
+
+\ --- The environment that "boots" OFW ---
+\ - Image Format - Example Media - previous stage bootloader
+
+\ - (Syslinux) COM32 format - USB Key w/ FAT FS - Syslinux
+\ create syslinux-loaded
+
+\ - Linux kernel format - USB Key w/ FAT FS - LinuxBIOS w/ stripped Linux payload
+\ create bzimage-loaded
+
+\ - ELF format w/ Multiboot signature - various - GRUB
+\ create grub-loaded
+\ create etherboot-variant \ Enable additional tweaks for Etherboot
+
+\ - ELF format (no pheader) - ROM - LinuxBIOS direct
+\ create linuxbios-loaded
+
+\ Load and run in qemu
+\ create qemu-loaded
+
+\ Load and run in VirtualBox
+create virtualbox-loaded
+
+\ Load from ROM by preOF code from Intel
+\ create preof-loaded
+
+[ifdef] pc-serial
+create serial-console
+create pc
+[then]
+
+[ifdef] qemu-loaded \ LinuxBIOS+OFW under QEMU currently does not do VGA right
+create serial-console
+[then]
+
+[ifdef] virtualbox-loaded
+\ create debug-startup
+\ create serial-console
+create resident-packages
+create addresses-assigned \ Don't reassign PCI addresses
+\ create virtual-mode
+\ create use-root-isa
+create use-timestamp-counter
+create use-pci-isa
+create use-isa-ide
+create use-ega
+create use-elf
+\ create use-ne2000
+create use-watch-all
+create use-null-nvram
+\ create no-floppy-node
+[then]
+
+[ifdef] etherboot-variant
+create debug-startup
+create serial-console
+[then]
+
+[ifdef] pc-linux
+\ In virtual mode, OFW runs with the MMU on. The advantages are
+\ that OFW can automatically locate itself out of the way, at the
+\ top of physical memory, it can dynamically allocate exactly as
+\ much physical memory as it needs, and it can remain alive after
+\ the OS starts. The disadvantage is that it is more confusing -
+\ you always have to be aware of the distinction between virtual
+\ and physical addresses.
+
+\ Here we use virtual mode for Linux, so that we can debug past
+\ the point where Linux starts using the MMU. It is not strictly
+\ necessary to use virtual mode if you just want to boot Linux
+\ and then have OFW disappear.
+create virtual-mode
+create pc
+create linux-support
+[then]
+
+[ifdef] pc
+\ create pseudo-nvram
+create resident-packages
+create addresses-assigned \ Don't reassign PCI addresses
+\ create virtual-mode
+create use-root-isa
+create use-isa-ide
+create use-ega
+create use-elf
+create use-ne2000
+create use-watch-all
+create use-null-nvram
+create no-floppy-node
+[then]
+
+[ifdef] preof-loaded
+create serial-console
+create use-timestamp-counter
+create resident-packages
+create addresses-assigned \ Don't reassign PCI addresses
+\ create virtual-mode
+create use-root-isa
+create use-isa-ide
+create use-elf
+create use-watch-all
+create use-null-nvram
+create no-floppy-node
+[then]
+
+fload ${BP}/cpu/x86/pc/biosload/addrs.fth
+
+\ LICENSE_BEGIN
+\ Copyright (c) 2006 FirmWorks
+\
+\ Permission is hereby granted, free of charge, to any person obtaining
+\ a copy of this software and associated documentation files (the
+\ "Software"), to deal in the Software without restriction, including
+\ without limitation the rights to use, copy, modify, merge, publish,
+\ distribute, sublicense, and/or sell copies of the Software, and to
+\ permit persons to whom the Software is furnished to do so, subject to
+\ the following conditions:
+\
+\ The above copyright notice and this permission notice shall be
+\ included in all copies or substantial portions of the Software.
+\
+\ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+\ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+\ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+\ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+\ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+\ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+\ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+\
+\ LICENSE_END
Added: cpu/x86/pc/biosload/makefloppy.fth
===================================================================
--- cpu/x86/pc/biosload/makefloppy.fth (rev 0)
+++ cpu/x86/pc/biosload/makefloppy.fth 2008-12-06 10:40:16 UTC (rev 1025)
@@ -0,0 +1,55 @@
+\ This program creates a bootable 1.44 MB floppy disk image with an
+\ initially-empty FAT12 filesystem.
+\ The FATs begin at sector 2. Sectors 0 and 1 contain a simple
+\ FAT filesystem reader that uses INT 13 to load the file "\OFW.IMG"
+\ into memory, then jumps to it.
+
+hex
+
+d# 512 constant /sector
+/sector buffer: sector-buf
+
+create ofw-boot-sectors
+ " ${BP}/cpu/x86/pc/biosload/build/bootsec.img" $file,
+here ofw-boot-sectors - constant /ofw-boot-sectors
+
+: make-floppy-image ( -- )
+ " floppy.img" $new-file
+
+ \ Write boot sectors
+ ofw-boot-sectors /ofw-boot-sectors ofd @ fputs
+
+ \ Init FATs
+ sector-buf /sector erase
+
+ \ BPB offset h#10.b is NumFATCopies
+ ofw-boot-sectors h# 10 + c@ 0 ?do \ Loop over number of FATs
+ h# 00fffff0 sector-buf le-l! \ First FAT12 entry
+ sector-buf /sector ofd @ fputs
+ 0 sector-buf le-l!
+
+ \ BPB offset h#16.w is SectorsPerFAT
+ ofw-boot-sectors h# 16 + le-w@ 1- 0 ?do \ Remainder of FAT
+ sector-buf /sector ofd @ fputs
+ loop
+ loop
+
+ \ Init root directory
+ \ BPB offset h#11.w is RootDirEntries. Each entry is h#20 bytes.
+ ofw-boot-sectors h# 11 + le-w@ ( #root-dir-entries )
+ h# 20 * ( root-dir-bytes )
+ /sector / 0 ?do \ Loop over root dir sectors
+ sector-buf /sector ofd @ fputs
+ loop
+
+ \ Zero the rest of the floppy image
+ ofw-boot-sectors h# 13 + le-w@ ( total#sectors )
+ /sector * ofd @ fsize ?do
+ sector-buf /sector ofd @ fputs
+ /sector +loop
+
+ ofd @ fclose
+ ." Open Firmware bootable floppy image created as floppy.img ." cr
+ ." Loopback-mount it and copy OFW.IMG to it." cr
+;
+make-floppy-image
Modified: cpu/x86/pc/biosload/mbootsec.fth
===================================================================
--- cpu/x86/pc/biosload/mbootsec.fth 2008-12-06 10:40:12 UTC (rev 1024)
+++ cpu/x86/pc/biosload/mbootsec.fth 2008-12-06 10:40:16 UTC (rev 1025)
@@ -69,6 +69,11 @@
ofw-boot-sectors 11 + lew@ 20 * /sector / 0 ?do
sector-buf /sector ofd @ fputs
loop
+
+ \ Fill the rest of the disk image with zeros
+ d# 1440 d# 1024 * ofd @ fsize ?do
+ sector-buf /sector ofd @ fputs
+ /sector +loop
[then]
ofd @ fclose