]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - sys/boot/amd64/boot1.efi/generate-fat.sh
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / sys / boot / amd64 / boot1.efi / generate-fat.sh
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$
13
14 FAT_SIZE=1600                   #Size in 512-byte blocks of the produced image
15
16 BOOT1_SIZE=64k
17
18 # Generate 800K FAT image
19 OUTPUT_FILE=fat.tmpl
20
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
24 mkdir stub
25 mount -t msdosfs /dev/$DEVICE stub
26
27 # Create and bless a directory for the boot loader
28 mkdir -p stub/efi/boot
29
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
32
33 umount stub
34 mdconfig -d -u $DEVICE
35 rmdir stub
36
37 # Locate the offsets of the two fake files
38 BOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ')
39
40 # Convert to numbers of blocks
41 BOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}')
42
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
46
47 bzip2 $OUTPUT_FILE
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
51
52 uuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu
53 rm $OUTPUT_FILE.bz2
54