generate-fat.sh revision 281526
152419Sjulian#!/bin/sh
252419Sjulian
3139823Simp# This script generates the dummy FAT filesystem used for the EFI boot
4139823Simp# blocks. It uses newfs_msdos to generate a template filesystem with the
5139823Simp# relevant interesting files. These are then found by grep, and the offsets
652419Sjulian# written to a Makefile snippet.
752419Sjulian#
852419Sjulian# Because it requires root, and because it is overkill, we do not
952419Sjulian# do this as part of the normal build. If makefs(8) grows workable FAT
1052419Sjulian# support, this should be revisited.
1152419Sjulian
1252419Sjulian# $FreeBSD: head/sys/boot/efi/boot1/generate-fat.sh 281526 2015-04-14 13:55:01Z andrew $
1352419Sjulian
1452419SjulianFAT_SIZE=1600 			#Size in 512-byte blocks of the produced image
1552419Sjulian
1652419SjulianBOOT1_SIZE=128k
1752419Sjulian
1852419Sjulian#
1952419Sjulian# Known filenames
2052419Sjulian# amd64:   BOOTx64.efi
2152419Sjulian# arm64:   BOOTaa64.efi
2252419Sjulian# arm:     BOOTarm.efi
2352419Sjulian# i386:    BOOTia32.efi
2452419Sjulian#
2552419Sjulianif [ -z "$2" ]; then
2652419Sjulian	echo "Usage: $0 arch boot-filename"
2752419Sjulian	exit 1
2852419Sjulianfi
2952419Sjulian
3052419SjulianARCH=$1
3152419SjulianFILENAME=$2
3252419Sjulian
3352419Sjulian# Generate 800K FAT image
3452419SjulianOUTPUT_FILE=fat-${ARCH}.tmpl
3552419Sjulian
3652419Sjuliandd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$FAT_SIZE
3752419SjulianDEVICE=`mdconfig -a -f $OUTPUT_FILE`
3867506Sjuliannewfs_msdos -F 12 -L EFI $DEVICE
3952419Sjulianmkdir stub
4052419Sjulianmount -t msdosfs /dev/$DEVICE stub
4152752Sjulian
4252419Sjulian# Create and bless a directory for the boot loader
4352419Sjulianmkdir -p stub/efi/boot
4452419Sjulian
4552419Sjulian# Make a dummy file for boot1
4652419Sjulianecho 'Boot1 START' | dd of=stub/efi/boot/$FILENAME cbs=$BOOT1_SIZE count=1 conv=block
4752419Sjulian
4852419Sjulianumount stub
4953997Sarchiemdconfig -d -u $DEVICE
5052419Sjulianrmdir stub
5152419Sjulian
5252419Sjulian# Locate the offset of the fake file
5352419SjulianBOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ')
5453997Sarchie
5552419Sjulian# Convert to number of blocks
5652419SjulianBOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}')
5752419Sjulian
5870870Sjulianecho '# This file autogenerated by generate-fat.sh - DO NOT EDIT' > Makefile.fat
5970870Sjulianecho '# $FreeBSD: head/sys/boot/efi/boot1/generate-fat.sh 281526 2015-04-14 13:55:01Z andrew $' >> Makefile.fat
6070870Sjulianecho "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.fat
6170870Sjulian
6270870Sjulianbzip2 $OUTPUT_FILE
6370870Sjulianecho 'FAT template boot filesystem created by generate-fat.sh' > $OUTPUT_FILE.bz2.uu
6470870Sjulianecho 'DO NOT EDIT' >> $OUTPUT_FILE.bz2.uu
6570870Sjulianecho '$FreeBSD: head/sys/boot/efi/boot1/generate-fat.sh 281526 2015-04-14 13:55:01Z andrew $' >> $OUTPUT_FILE.bz2.uu
6652419Sjulian
6752419Sjulianuuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu
6852419Sjulianrm $OUTPUT_FILE.bz2
6952419Sjulian
7052419Sjulian