3 # This script generates the dummy FAT filesystem used for the EFI boot
4 # blocks. It uses newfs_msdos to generate a template filesystem with the
5 # relevant interesting files. These are then found by grep, and the offsets
6 # written to a Makefile snippet.
8 # Because it requires root, and because it is overkill, we do not
9 # do this as part of the normal build. If makefs(8) grows workable FAT
10 # support, this should be revisited.
14 FAT_SIZE=1600 #Size in 512-byte blocks of the produced image
19 if [ $(id -u) != 0 ]; then
20 echo "${0##*/}: must run as root" >&2
24 # Record maximum boot1 size in bytes
27 BOOT1_MAXSIZE=$(expr ${BOOT1_SIZE%k} '*' 1024)
30 BOOT1_MAXSIZE=$BOOT1_SIZE
34 echo '# This file autogenerated by generate-fat.sh - DO NOT EDIT' > Makefile.fat
35 echo "# \$FreeBSD\$" >> Makefile.fat
36 echo "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.fat
37 echo "BOOT1_MAXSIZE=$BOOT1_MAXSIZE" >> Makefile.fat
39 while read ARCH FILENAME; do
40 # Generate 800K FAT image
41 OUTPUT_FILE=fat-${ARCH}.tmpl
43 dd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$FAT_SIZE
44 DEVICE=`mdconfig -a -f $OUTPUT_FILE`
45 newfs_msdos -F 12 -L EFI $DEVICE
47 mount -t msdosfs /dev/$DEVICE stub
49 # Create and bless a directory for the boot loader
50 mkdir -p stub/efi/boot
52 # Make a dummy file for boot1
53 echo 'Boot1 START' | dd of=stub/efi/boot/$FILENAME cbs=$BOOT1_SIZE count=1 conv=block
54 # Provide a fallback startup.nsh
55 echo $FILENAME > stub/efi/boot/startup.nsh
58 mdconfig -d -u $DEVICE
61 # Locate the offset of the fake file
62 OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ')
64 # Convert to number of blocks
65 OFFSET=$(echo 0x$OFFSET | awk '{printf("%x\n",$1/512);}')
68 if [ $OFFSET != $BOOT1_OFFSET ]; then
69 echo "Incorrect offset $OFFSET != $BOOT1_OFFSET" >&2