1.9. Building the boot loader

The boot loader in official m0n0wall images is configured to read only one block at a time to work around incompatibilities between certain brands of CF cards and BIOSes. Also, it's compiled not to use fancy terminal emulation, as that usually messes up the output on a serial console. If you're going to build an image for a generic PC, you may be able to do without these modifications and just use the boot loader from /boot that was installed with FreeBSD. Otherwise, read on.

Edit /sys/boot/i386/libi386/Makefile and comment out the line that says CFLAGS+= -DTERM_EMU. Now apply the single-sector-read patch, if desired:

cd /usr/src
patch < $MWPATCHDIR/boot/boot.patch

When building a boot loader for WRAP boards, boot1.s needs to be modified not to fiddle with gate A20, since the WRAP doesn't have a keyboard controller:

patch < $MWPATCHDIR/boot/boot-wrap.patch

Compile the boot loader:

cd /sys/boot
make clean && make obj && make

Make a directory somewhere to hold the boot files until you're ready to create the image, and copy the necessary files to it:

mkdir $BOOTDIR
cp /usr/obj/usr/src/sys/boot/i386/loader/loader $BOOTDIR
cp /usr/obj/usr/src/sys/boot/i386/boot2/{boot1,boot2} $BOOTDIR
cp /usr/obj/usr/src/sys/boot/i386/cdboot/cdboot $BOOTDIR

1.9.1. Preparing loader.rc

loader.rc is the file that the loader reads and interprets. For m0n0wall, it is used to disable ATA DMA (to increase compatibility with odd hardware, especially since CF/HD performance isn't very important in m0n0wall) and load the kernel and the MFS root file system.

Create the file $BOOTDIR/loader.rc with the following contents:

set hw.ata.atapi_dma="0"
set hw.ata.ata_dma="0"
load /kernel
load -t mfs_root /mfsroot
boot

If you're building for a platform that only has a serial console, add the flag "-h" (without the quotes) to the "boot" command on the last line.