From owner-svn-src-head@freebsd.org Mon Sep 11 00:37:01 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BBAA4E0D50C; Mon, 11 Sep 2017 00:37:01 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 95C98675ED; Mon, 11 Sep 2017 00:37:01 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v8B0b0L9024082; Mon, 11 Sep 2017 00:37:00 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v8B0b0Ks024081; Mon, 11 Sep 2017 00:37:00 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201709110037.v8B0b0Ks024081@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Mon, 11 Sep 2017 00:37:00 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323407 - head/sys/boot/efi/boot1 X-SVN-Group: head X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: head/sys/boot/efi/boot1 X-SVN-Commit-Revision: 323407 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Sep 2017 00:37:01 -0000 Author: emaste Date: Mon Sep 11 00:37:00 2017 New Revision: 323407 URL: https://svnweb.freebsd.org/changeset/base/323407 Log: boot1 generate-fat: generate all templates at once In advance of other changes to the fat template generation process, have generate-fat.sh create all template files at the same time so that they cannot get out of sync. Also correct a longstanding but where BOOT1_OFFSET was overwritten on each invocation. A previous version of this patch stored a per-arch offset (e.g. BOOT1_arm64_OFFSET) but that was deemed unnecessary. Instead just hardcode the known offset that applies to all archs (0x2d) and fail if the offset happens to be different. Ongiong work (using newfs_msdos in bsdinstall and adding msdosfs support to makefs) will eventually allow us to do away with this fat template hack altogether, but in the near term we have a few improvements that will build on this. Reviewed by: allanjude, imp, Eric McCorkle MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D10931 Modified: head/sys/boot/efi/boot1/generate-fat.sh Modified: head/sys/boot/efi/boot1/generate-fat.sh ============================================================================== --- head/sys/boot/efi/boot1/generate-fat.sh Mon Sep 11 00:19:09 2017 (r323406) +++ head/sys/boot/efi/boot1/generate-fat.sh Mon Sep 11 00:37:00 2017 (r323407) @@ -13,50 +13,14 @@ FAT_SIZE=1600 #Size in 512-byte blocks of the produced image +BOOT1_OFFSET=2d BOOT1_SIZE=128k -# -# Known filenames -# amd64: BOOTx64.efi -# arm64: BOOTaa64.efi -# arm: BOOTarm.efi -# i386: BOOTia32.efi -# -if [ -z "$2" ]; then - echo "Usage: $0 arch boot-filename" +if [ $(id -u) != 0 ]; then + echo "${0##*/}: must run as root" >&2 exit 1 fi -ARCH=$1 -FILENAME=$2 - -# Generate 800K FAT image -OUTPUT_FILE=fat-${ARCH}.tmpl - -dd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$FAT_SIZE -DEVICE=`mdconfig -a -f $OUTPUT_FILE` -newfs_msdos -F 12 -L EFI $DEVICE -mkdir stub -mount -t msdosfs /dev/$DEVICE stub - -# Create and bless a directory for the boot loader -mkdir -p stub/efi/boot - -# Make a dummy file for boot1 -echo 'Boot1 START' | dd of=stub/efi/boot/$FILENAME cbs=$BOOT1_SIZE count=1 conv=block -# Provide a fallback startup.nsh -echo $FILENAME > stub/efi/boot/startup.nsh - -umount stub -mdconfig -d -u $DEVICE -rmdir stub - -# Locate the offset of the fake file -BOOT1_OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ') - -# Convert to number of blocks -BOOT1_OFFSET=$(echo 0x$BOOT1_OFFSET | awk '{printf("%x\n",$1/512);}') - # Record maximum boot1 size in bytes case $BOOT1_SIZE in *k) @@ -72,11 +36,50 @@ echo "# \$FreeBSD\$" >> Makefile.fat echo "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.fat echo "BOOT1_MAXSIZE=$BOOT1_MAXSIZE" >> Makefile.fat -bzip2 $OUTPUT_FILE -echo 'FAT template boot filesystem created by generate-fat.sh' > $OUTPUT_FILE.bz2.uu -echo 'DO NOT EDIT' >> $OUTPUT_FILE.bz2.uu -echo "\$FreeBSD\$" >> $OUTPUT_FILE.bz2.uu +while read ARCH FILENAME; do + # Generate 800K FAT image + OUTPUT_FILE=fat-${ARCH}.tmpl -uuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu -rm $OUTPUT_FILE.bz2 + dd if=/dev/zero of=$OUTPUT_FILE bs=512 count=$FAT_SIZE + DEVICE=`mdconfig -a -f $OUTPUT_FILE` + newfs_msdos -F 12 -L EFI $DEVICE + mkdir stub + mount -t msdosfs /dev/$DEVICE stub + # Create and bless a directory for the boot loader + mkdir -p stub/efi/boot + + # Make a dummy file for boot1 + echo 'Boot1 START' | dd of=stub/efi/boot/$FILENAME cbs=$BOOT1_SIZE count=1 conv=block + # Provide a fallback startup.nsh + echo $FILENAME > stub/efi/boot/startup.nsh + + umount stub + mdconfig -d -u $DEVICE + rmdir stub + + # Locate the offset of the fake file + OFFSET=$(hd $OUTPUT_FILE | grep 'Boot1 START' | cut -f 1 -d ' ') + + # Convert to number of blocks + OFFSET=$(echo 0x$OFFSET | awk '{printf("%x\n",$1/512);}') + + # Validate the offset + if [ $OFFSET != $BOOT1_OFFSET ]; then + echo "Incorrect offset $OFFSET != $BOOT1_OFFSET" >&2 + exit 1 + fi + + bzip2 $OUTPUT_FILE + echo 'FAT template boot filesystem created by generate-fat.sh' > $OUTPUT_FILE.bz2.uu + echo 'DO NOT EDIT' >> $OUTPUT_FILE.bz2.uu + echo "\$FreeBSD\$" >> $OUTPUT_FILE.bz2.uu + + uuencode $OUTPUT_FILE.bz2 $OUTPUT_FILE.bz2 >> $OUTPUT_FILE.bz2.uu + rm $OUTPUT_FILE.bz2 +done <