generate-fat.sh revision 264993
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: head/sys/boot/amd64/boot1.efi/generate-fat.sh 264993 2014-04-27 00:45:08Z nwhitehorn $
13
14FAT_SIZE=1600 			#Size in 512-byte blocks of the produced image
15
16BOOT1_SIZE=64k
17
18# Generate 800K FAT image
19OUTPUT_FILE=fat.tmpl
20
21dd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$FAT_SIZE
22DEVICE=`mdconfig -a -f $OUTPUT_FILE`
23newfs_msdos -F 12 $DEVICE
24mkdir stub
25mount -t msdosfs /dev/$DEVICE stub
26
27# Create and bless a directory for the boot loader
28mkdir -p stub/efi/boot
29
30# Make a dummy file for boot1
31echo 'Boot1 START' | dd of=stub/efi/boot/BOOTx64.efi cbs=$BOOT1_SIZE count=1 conv=block
32
33umount stub
34mdconfig -d -u $DEVICE
35rmdir stub
36
37# Locate the offsets of the two fake files
38BOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ')
39
40# Convert to numbers of blocks
41BOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}')
42
43echo '# This file autogenerated by generate-fat.sh - DO NOT EDIT' > Makefile.fat
44echo '# $FreeBSD: head/sys/boot/amd64/boot1.efi/generate-fat.sh 264993 2014-04-27 00:45:08Z nwhitehorn $' >> Makefile.fat
45echo "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.fat
46
47bzip2 $OUTPUT_FILE
48echo 'FAT template boot filesystem created by generate-fat.sh' > $OUTPUT_FILE.bz2.uu
49echo 'DO NOT EDIT' >> $OUTPUT_FILE.bz2.uu
50echo '$FreeBSD: head/sys/boot/amd64/boot1.efi/generate-fat.sh 264993 2014-04-27 00:45:08Z nwhitehorn $' >> $OUTPUT_FILE.bz2.uu
51
52uuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu
53rm $OUTPUT_FILE.bz2
54
55