Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
222 lines (157 sloc) 9.06 KB
Boot sector program for Intel's Developer's UEFI Emulation (DUET)
1. Limitations of BootDuet
We can think of the following present limitations for BootDuet.
- BootDuet isn't able to find its own partition on the disk. That would
require scanning both MBR and GPT partitions. This couldn't be done on the
same boot program that scans the FAT file system.
Traditionally the boot program on the Master Boot Record passes in the
register SI a pointer to the MBR partition entry which is being booted and
that's how MS-DOS/Windows/etc boot programs know their own partition.
However, this BootDuet will probably find more use in GPT partitioned disks
and therefore we couldn't rely on this.
We therefore rely on another mechanism of MS-DOS/FAT partitions: the hidden
sectors field in the BPB. This is the number of sectors before the boot
sector of the partition, and is exactly the start LBA of the partition.
- BootDuet doesn't want to guess the BIOS drive number where it should find
its own partition. Normally, MBR boot programs always pass the boot BIOS
drive number in the DL register to the partition boot program.
And that's how BootDuet normally knows the drive number of its partition.
However, one important MBR boot program does not do that, which is the program in EFI DUET.
For that case, there is the option of compiling BootDuet with the
WITH_HARDCODED_DRIVE option (see Makefile), and in that case, BootDuet
will use the BIOS drive number which is hard coded on the Boot Parameter
Block of its own partition.
- BootDuet can't handle a root directory with more than 32 KiB whether in
FAT12, FAT16 or FAT32. It won't do anything useful or even reasonable in
that case.
- BootDuet can't handle FAT12 partitions on 64-bit LBA. That's because the
code for FAT12 partitions is more complex and so is the code for 64-bit LBA.
I couldn't squeeze it into 448 bytes.
- The 64-bit LBA version of BootDuet does no validation of the boot sector and
will fail silently on some error conditions which the 32-bit LBA version
would detect. That's also because the 64-bit LBA code is larger.
2. Prepare a boot partition
The boot partition must only be large enough to contain EFILDR and EFIVAR.BIN,
together they are less than a megabyte.
A very small partition should use 12-bit FAT file system, a bigger one should
use 16-bit FAT and only a partition larger than 512 MiB should use 32-bit FAT
While some tools allow the use of FAT16 or FAT32 on small partitions, other
tools actually distinguish between FAT12 and FAT32 with base on the number of
BootDuet requires the Hidden Sectors field of the Boot Parameter Block (BPB)
structure to be filled in, as mentioned in the previous section, and this is
typically not filled in by default by format programs.
If your partition starts at an LBA of, say, 390074368, then this is exactly
what you must use for the Hidden Sectors field.
If you're using Linux and dosfstools for formating this partition, and your
partition is /dev/sda20, then you can use a command such as:
# mkfs.msdos -h 390074368 /dev/sda20
If your partition is already formated, then you must fill in this value by
hand. You can do that with any of many different tools. For me, on Linux, it
would be practical to use the following command:
# echo 00: 00 10 40 17 | xxd -r | dd of=/dev/sda20 bs=1 seek=28
Where xxd is a tool for hexdumps that comes with vim and 00 10 40 17 is a
little endian dump for the hex number 17401000 which is 390074368.
The versions of BootDuet compiled with WITH_HARDCODED_DRIVE, the "hd" versions,
also require that the BIOS drive number field of the Boot Parameter Block of
its own partition to be set to the correct drive number.
Many format tools, specifically dosfstools, don't set that.
Note that you only need to do this if you plan to use EFI DUET's for
the MBR boot program.
That field may be set with a command such as:
For FAT12 or FAT16:
# echo 00: 80 | xxd -r | dd of=/dev/sda20 bs=1 seek=36
For FAT32:
# echo 00: 80 | xxd -r | dd of=/dev/sda20 bs=1 seek=64
Where 80 would be the BIOS drive number in hex. The convention for BIOS drive
numbers is 00 for the first floppy drive (A: in MS-DOS), 01 for the second
(B:), 80 for the first hard drive (C:), 81 for the second hard drive (D:).
If you absolutely must use 64-bit LBA (remember, it does no validation of the
boot sector), then you would have to fill in the high 32-bit part of your
start LBA for the partition, because the Hidden Sectors field only is 32 bit.
In that case, assuming your partition is already formated, and it starts at
LBA 39007436800, then, you would have to convert this number to hex, which is
915064000, byte reverse and pad it to 8 bytes as 00 40 06 15 09 00 00 00, and
then something like:
# echo 00: 00 40 06 15 | xxd -r | dd of=/dev/sda20 bs=1 seek=28
# echo 00: 09 00 00 00 | xxd -r | dd of=/dev/sda20 bs=1 seek=506
3. Compile BootDuet
On Linux, to compile the 32-bit LBA binaries, just use make. The makefile is a
GNU makefile and we assume that some version of gcc and binutils is installed.
# make
If additionally you want to build the 64-bit LBA binaries, then use:
# make lba64
If you want to build BootDuet versions that use the hard-coded BIOS drive
number (such as if your planning to use EFI DUET's for the MBR), then
# make hardcoded-drive
4. Install BootDuet on the boot sector
When installing BootDuet on the boot sector of a FAT formated partition, care
must be taken not to overwrite the Boot Parameter Block (BPB) and Extended BPB
(EBPB). Also, the EBPB is slightly larger for FAT32 partitions, so be careful
about which command you pick to copy&paste.
One way to install BootDuet on Linux is using the dd tool.
For FAT12, do:
# dd if=bd12.bin of=/dev/sda20 bs=1 skip=62 seek=62 count=448
For FAT16, do:
# dd if=bd16.bin of=/dev/sda20 bs=1 skip=62 seek=62 count=448
For FAT32, do:
# dd if=bd32.bin of=/dev/sda20 bs=1 skip=90 seek=90 count=420
For 64-bit LBA versions, you must take four bytes from that count, as those
will be the high 32-bits of the start LBA of your boot partition (as mentioned
in the previous section).
For FAT12, with 64-bit LBA, do:
# dd if=bd12_64.bin of=/dev/sda20 bs=1 skip=62 seek=62 count=444
For FAT16, with 64-bit LBA, do:
# dd if=bd16_64.bin of=/dev/sda20 bs=1 skip=62 seek=62 count=444
For FAT32, with 64-bit LBA, do:
# dd if=bd32_64.bin of=/dev/sda20 bs=1 skip=90 seek=90 count=416
This is exactly what the install targets of the makefile do. So, on a
UNIX-like OS you can do:
# make DEVICE=/dev/sda20 install-bd12
# make DEVICE=/dev/sda20 install-bd16
# make DEVICE=/dev/sda20 install-bd32
5. Copy the files you need
Finally (or before if you prefer) you can copy the files you need to the boot
partition, this will be at least the boot loader program.
On Linux, and assuming you mounted your partition at /mnt, use:
For FAT12:
# cp ./EfiLdr /mnt/EFILDR
For FAT16:
# cp ./EfiLdr16 /mnt/EFILDR16
For FAT32:
# cp ./EfiLdr20 /mnt/EFILDR20
6. Troubleshooting
If you have installed BootDuet on the boot sector of a FAT partition and have
some MBR program loading it and you still can't get DUET to load, then some of
the verifications that BootDuet does may help you solve the problem.
6.1 The system hangs and the work Bad is written on the screen
This may happen if:
- You haven't set the Hidden Sectors field of the BPB as explained in section
2 of this guide. This is necessary for BootDuet to find its own partition.
- You used some too old or too new format program for your FAT partition.
BootDuet expects the EBPB signature byte to be 0x29 (see wikipedia).
Maybe try another format tool.
- You installed a FAT12 or FAT16 version of BootDuet into a FAT32 partition or
vice versa.
6.2 The system hangs and "Missing EFILDR/EFILDR16/EFILDR20" is on the screen
You must copy the missing file to your boot FAT partition. Note that the FAT12
version expects the file to be called EFILDR, the FAT16 version expects
EFILDR16 and the FAT32 version expects EFILDR20. This is for similarity with
Intel's original boot sector code of DUET.
You can find a compiled version of that file on:
Note that you can just rename EfiLdr20 to EFILDR, EFILDR16 or EFILDR20.
The same program recognizes the three types of FAT file systems.
6.3 The system hangs and only "EFILDR/EFILDR16/EFILDR20" or "EFIVAR.BIN" is
written on the screen
Some kind of error occurred while loading that file. Maybe your file system is
corrupted or maybe it is a bug in BootDuet. Try formating, installing and
copying everything all over again, or try something else.
Miguel Lopes Santos Ramos, 2011
Something went wrong with that request. Please try again.