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
18 # Generate 800K FAT image
21 dd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$FAT_SIZE
22 DEVICE=`mdconfig -a -f $OUTPUT_FILE`
23 newfs_msdos -F 12 $DEVICE
25 mount -t msdosfs /dev/$DEVICE stub
27 # Create and bless a directory for the boot loader
28 mkdir -p stub/efi/boot
30 # Make a dummy file for boot1
31 echo 'Boot1 START' | dd of=stub/efi/boot/BOOTx64.efi cbs=$BOOT1_SIZE count=1 conv=block
34 mdconfig -d -u $DEVICE
37 # Locate the offsets of the two fake files
38 BOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ')
40 # Convert to numbers of blocks
41 BOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}')
43 echo '# This file autogenerated by generate-fat.sh - DO NOT EDIT' > Makefile.fat
44 echo '# $FreeBSD$' >> Makefile.fat
45 echo "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.fat
48 echo 'FAT template boot filesystem created by generate-fat.sh' > $OUTPUT_FILE.bz2.uu
49 echo 'DO NOT EDIT' >> $OUTPUT_FILE.bz2.uu
50 echo '$FreeBSD$' >> $OUTPUT_FILE.bz2.uu
52 uuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu