generate-fat.sh revision 281238
158314Sache#!/bin/sh 226497Sache 326497Sache# This script generates the dummy FAT filesystem used for the EFI boot 426497Sache# blocks. It uses newfs_msdos to generate a template filesystem with the 526497Sache# relevant interesting files. These are then found by grep, and the offsets 626497Sache# written to a Makefile snippet. 726497Sache# 826497Sache# Because it requires root, and because it is overkill, we do not 926497Sache# do this as part of the normal build. If makefs(8) grows workable FAT 1026497Sache# support, this should be revisited. 1126497Sache 1258314Sache# $FreeBSD: head/sys/boot/efi/boot1/generate-fat.sh 281238 2015-04-07 21:41:26Z emaste $ 1326497Sache 1426497SacheFAT_SIZE=1600 #Size in 512-byte blocks of the produced image 1526497Sache 1626497SacheBOOT1_SIZE=128k 1726497Sache 1826497Sache# 1926497Sache# Known filenames 2026497Sache# amd64: BOOTx64.efi 2126497Sache# aarch64: BOOTaa64.efi 2226497Sache# arm: BOOTarm.efi 2358314Sache# i386: BOOTia32.efi 2426497Sache# 2526497Sacheif [ -z "$2" ]; then 2626497Sache echo "Usage: $0 arch boot-filename" 2726497Sache exit 1 2826497Sachefi 2926497Sache 3047563SacheARCH=$1 3147563SacheFILENAME=$2 3226497Sache 3326497Sache# Generate 800K FAT image 3426497SacheOUTPUT_FILE=fat-${ARCH}.tmpl 3526497Sache 3626497Sachedd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$FAT_SIZE 3726497SacheDEVICE=`mdconfig -a -f $OUTPUT_FILE` 3826497Sachenewfs_msdos -F 12 -L EFI $DEVICE 3926497Sachemkdir stub 4026497Sachemount -t msdosfs /dev/$DEVICE stub 4126497Sache 4235489Sache# Create and bless a directory for the boot loader 4335489Sachemkdir -p stub/efi/boot 4435489Sache 4535489Sache# Make a dummy file for boot1 4635489Sacheecho 'Boot1 START' | dd of=stub/efi/boot/$FILENAME cbs=$BOOT1_SIZE count=1 conv=block 4735489Sache 4858314Sacheumount stub 4947563Sachemdconfig -d -u $DEVICE 5026497Sachermdir stub 5158314Sache 5258314Sache# Locate the offset of the fake file 5375409SacheBOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ') 5458314Sache 5558314Sache# Convert to number of blocks 5658314SacheBOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}') 5747563Sache 5875409Sacheecho '# This file autogenerated by generate-fat.sh - DO NOT EDIT' > Makefile.fat 5947563Sacheecho '# $FreeBSD: head/sys/boot/efi/boot1/generate-fat.sh 281238 2015-04-07 21:41:26Z emaste $' >> Makefile.fat 6026497Sacheecho "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.fat 6158314Sache 6258314Sachebzip2 $OUTPUT_FILE 6358314Sacheecho 'FAT template boot filesystem created by generate-fat.sh' > $OUTPUT_FILE.bz2.uu 6426497Sacheecho 'DO NOT EDIT' >> $OUTPUT_FILE.bz2.uu 6547563Sacheecho '$FreeBSD: head/sys/boot/efi/boot1/generate-fat.sh 281238 2015-04-07 21:41:26Z emaste $' >> $OUTPUT_FILE.bz2.uu 6647563Sache 6726497Sacheuuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu 6826497Sacherm $OUTPUT_FILE.bz2 6926497Sache 7075409Sache