generate-fat.sh revision 303297
1#!/bin/sh 2 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. 7# 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. 11 12# $FreeBSD: stable/10/sys/boot/efi/boot1/generate-fat.sh 303297 2016-07-25 14:36:55Z emaste $ 13 14FAT_SIZE=1600 #Size in 512-byte blocks of the produced image 15 16BOOT1_SIZE=128k 17 18# 19# Known filenames 20# amd64: BOOTx64.efi 21# arm64: BOOTaa64.efi 22# 23if [ -z "$1" ]; then 24 echo "Usage: $0 filename" 25 exit 1 26fi 27 28FILENAME=$1 29 30# Generate 800K FAT image 31OUTPUT_FILE=fat.tmpl 32 33dd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$FAT_SIZE 34DEVICE=`mdconfig -a -f $OUTPUT_FILE` 35newfs_msdos -F 12 -L EFI $DEVICE 36mkdir stub 37mount -t msdosfs /dev/$DEVICE stub 38 39# Create and bless a directory for the boot loader 40mkdir -p stub/efi/boot 41 42# Make a dummy file for boot1 43echo 'Boot1 START' | dd of=stub/efi/boot/$FILENAME cbs=$BOOT1_SIZE count=1 conv=block 44# Provide a fallback startup.nsh 45echo $FILENAME > stub/efi/boot/startup.nsh 46 47umount stub 48mdconfig -d -u $DEVICE 49rmdir stub 50 51# Locate the offset of the fake file 52BOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ') 53 54# Convert to number of blocks 55BOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}') 56 57echo '# This file autogenerated by generate-fat.sh - DO NOT EDIT' > Makefile.fat 58echo '# $FreeBSD: stable/10/sys/boot/efi/boot1/generate-fat.sh 303297 2016-07-25 14:36:55Z emaste $' >> Makefile.fat 59echo "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.fat 60 61bzip2 $OUTPUT_FILE 62echo 'FAT template boot filesystem created by generate-fat.sh' > $OUTPUT_FILE.bz2.uu 63echo 'DO NOT EDIT' >> $OUTPUT_FILE.bz2.uu 64echo '$FreeBSD: stable/10/sys/boot/efi/boot1/generate-fat.sh 303297 2016-07-25 14:36:55Z emaste $' >> $OUTPUT_FILE.bz2.uu 65 66uuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu 67rm $OUTPUT_FILE.bz2 68 69