Index: release/amd64/make-memstick.sh =================================================================== --- release/amd64/make-memstick.sh +++ release/amd64/make-memstick.sh @@ -36,11 +36,24 @@ rm ${1}/etc/fstab rm ${1}/etc/rc.conf.local + +dd if=/dev/zero of=efiboot.img bs=1k count=33292 +device=`mdconfig -a -t vnode -f efiboot.img` +newfs_msdos -F 32 -c 1 -L EFISYS /dev/$device +mkdir efi +mount -t msdosfs /dev/$device efi +mkdir -p efi/efi/boot +cp -p "${1}/boot/loader.efi" efi/efi/boot/bootx64.efi +umount efi +rmdir efi +mdconfig -d -u $device + mkimg -s mbr \ -b ${1}/boot/mbr \ - -p efi:=${1}/boot/boot1.efifat \ + -p efi:=efiboot.img \ -p freebsd:-"mkimg -s bsd -b ${1}/boot/boot -p freebsd-ufs:=${2}.part" \ -a 2 \ -o ${2} +rm efiboot.img rm ${2}.part Index: release/arm64/make-memstick.sh =================================================================== --- release/arm64/make-memstick.sh +++ release/arm64/make-memstick.sh @@ -36,9 +36,23 @@ rm ${1}/etc/fstab rm ${1}/etc/rc.conf.local + +dd if=/dev/zero of=efiboot.img bs=1k count=33292 +device=`mdconfig -a -t vnode -f efiboot.img` +newfs_msdos -F 32 -c 1 -L EFISYS /dev/$device +mkdir efi +mount -t msdosfs /dev/$device efi +mkdir -p efi/efi/boot +cp -p "${1}/boot/loader.efi" efi/efi/boot/bootaa64.efi +umount efi +rmdir efi +mdconfig -d -u $device + + mkimg -s gpt \ - -p efi:=${1}/boot/boot1.efifat \ + -p efi:=efiboot.img \ -p freebsd:=${2}.part \ -o ${2} +rm efiboot.img rm ${2}.part Index: release/i386/make-memstick.sh =================================================================== --- release/i386/make-memstick.sh +++ release/i386/make-memstick.sh @@ -36,9 +36,23 @@ rm ${1}/etc/fstab rm ${1}/etc/rc.conf.local + +dd if=/dev/zero of=efiboot.img bs=1k count=33292 +device=`mdconfig -a -t vnode -f efiboot.img` +newfs_msdos -F 32 -c 1 -L EFISYS /dev/$device +mkdir efi +mount -t msdosfs /dev/$device efi +mkdir -p efi/efi/boot +cp -p "${1}/boot/loader.efi" efi/efi/boot/bootia32.efi +umount efi +rmdir efi +mdconfig -d -u $device + mkimg -s mbr \ -b ${1}/boot/mbr \ + -p efi:=efiboot.img -p freebsd:-"mkimg -s bsd -b ${1}/boot/boot -p freebsd-ufs:=${2}.part" \ -o ${2} +rm efiboot.img rm ${2}.part Index: stand/efi/boot1/Makefile =================================================================== --- stand/efi/boot1/Makefile +++ stand/efi/boot1/Makefile @@ -51,7 +51,7 @@ .PATH: ${LDRSRC} CFLAGS+= -I${LDRSRC} -FILES= boot1.efi boot1.efifat +FILES= boot1.efi FILESMODE_boot1.efi= ${BINMODE} LDSCRIPT= ${EFISRC}/loader/arch/${MACHINE}/ldscript.${MACHINE} @@ -88,22 +88,7 @@ -j .rela.dyn -j .reloc -j .eh_frame \ --output-target=${EFI_TARGET} ${.ALLSRC} ${.TARGET} -# The following inserts our objects into a template FAT file system -# created by generate-fat.sh -.include "Makefile.fat" - -boot1.efifat: boot1.efi - @set -- `ls -l ${.ALLSRC}`; \ - x=$$(($$5-${BOOT1_MAXSIZE})); \ - if [ $$x -ge 0 ]; then \ - echo "boot1 $$x bytes too large; regenerate FAT templates?" >&2 ;\ - exit 1; \ - fi - echo ${.OBJDIR} - xz -d -c ${BOOTSRC}/efi/boot1/fat-${MACHINE}.tmpl.xz > ${.TARGET} - ${DD} if=${.ALLSRC} of=${.TARGET} seek=${BOOT1_OFFSET} conv=notrunc - -CLEANFILES+= boot1.efi boot1.efifat +CLEANFILES+= boot1.efi .include Index: stand/efi/boot1/Makefile.fat =================================================================== --- stand/efi/boot1/Makefile.fat +++ stand/efi/boot1/Makefile.fat @@ -1,4 +0,0 @@ -# This file autogenerated by generate-fat.sh - DO NOT EDIT -# $FreeBSD$ -BOOT1_OFFSET=0x2d -BOOT1_MAXSIZE=393216 Index: stand/efi/boot1/generate-fat.sh =================================================================== --- stand/efi/boot1/generate-fat.sh +++ /dev/null @@ -1,79 +0,0 @@ -#!/bin/sh - -# This script generates the dummy FAT filesystem used for the EFI boot -# blocks. It uses newfs_msdos to generate a template filesystem with the -# relevant interesting files. These are then found by grep, and the offsets -# written to a Makefile snippet. -# -# Because it requires root, and because it is overkill, we do not -# do this as part of the normal build. If makefs(8) grows workable FAT -# support, this should be revisited. - -# $FreeBSD$ - -FAT_SIZE=1600 #Size in 512-byte blocks of the produced image - -BOOT1_OFFSET=2d -BOOT1_SIZE=384k - -if [ $(id -u) != 0 ]; then - echo "${0##*/}: must run as root" >&2 - exit 1 -fi - -# Record maximum boot1 size in bytes -case $BOOT1_SIZE in -*k) - BOOT1_MAXSIZE=$(expr ${BOOT1_SIZE%k} '*' 1024) - ;; -*) - BOOT1_MAXSIZE=$BOOT1_SIZE - ;; -esac - -echo '# This file autogenerated by generate-fat.sh - DO NOT EDIT' > Makefile.fat -echo "# \$FreeBSD\$" >> Makefile.fat -echo "BOOT1_OFFSET=0x$BOOT1_OFFSET" >> Makefile.fat -echo "BOOT1_MAXSIZE=$BOOT1_MAXSIZE" >> Makefile.fat - -while read ARCH FILENAME; do - # 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 EFISYS $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 - - xz -f $OUTPUT_FILE -done <fstab->fs_vfstype = strdup("msdosfs"); + if (strcmp("efi", type) == 0) + md->fstab->fs_mntops = strdup("noauto"); else md->fstab->fs_vfstype = strdup(type); /* Guess */ if (strcmp(type, "freebsd-swap") == 0) { Index: usr.sbin/bsdinstall/partedit/partedit_arm64.c =================================================================== --- usr.sbin/bsdinstall/partedit/partedit_arm64.c +++ usr.sbin/bsdinstall/partedit/partedit_arm64.c @@ -36,7 +36,6 @@ /* EFI partition size in bytes */ #define EFI_BOOTPART_SIZE (200 * 1024 * 1024) -#define EFI_BOOTPART_PATH "/boot/boot1.efifat" const char * default_scheme(void) @@ -81,6 +80,7 @@ { /* Only EFI is supported as boot partition */ + *mountpoint = "/boot/efi"; return ("efi"); } @@ -95,10 +95,7 @@ partcode_path(const char *part_type, const char *fs_type) { - if (strcmp(part_type, "GPT") == 0) - return (EFI_BOOTPART_PATH); - - /* No boot partition data for non-GPT */ + /* No boot partition data for ARM64 */ return (NULL); } Index: usr.sbin/bsdinstall/partedit/partedit_x86.c =================================================================== --- usr.sbin/bsdinstall/partedit/partedit_x86.c +++ usr.sbin/bsdinstall/partedit/partedit_x86.c @@ -36,7 +36,6 @@ /* EFI partition size in bytes */ #define EFI_BOOTPART_SIZE (200 * 1024 * 1024) -#define EFI_BOOTPART_PATH "/boot/boot1.efifat" static const char * x86_bootmethod(void) @@ -114,8 +113,10 @@ bootpart_type(const char *scheme, const char **mountpoint) { - if (strcmp(x86_bootmethod(), "UEFI") == 0) + if (strcmp(x86_bootmethod(), "UEFI") == 0) { + *mountpoint = "/boot/efi"; return ("efi"); + } return ("freebsd-boot"); } @@ -141,16 +142,14 @@ partcode_path(const char *part_type, const char *fs_type) { - if (strcmp(part_type, "GPT") == 0) { - if (strcmp(x86_bootmethod(), "UEFI") == 0) - return (EFI_BOOTPART_PATH); - else if (strcmp(fs_type, "zfs") == 0) + if (strcmp(part_type, "GPT") == 0 && strcmp(x86_bootmethod(), "UEFI") != 0) { + if (strcmp(fs_type, "zfs") == 0) return ("/boot/gptzfsboot"); else return ("/boot/gptboot"); } - /* No partcode except for GPT */ + /* No partcode except for non-UEFI GPT */ return (NULL); } Index: usr.sbin/bsdinstall/scripts/bootconfig =================================================================== --- usr.sbin/bsdinstall/scripts/bootconfig +++ usr.sbin/bsdinstall/scripts/bootconfig @@ -1,5 +1,6 @@ #!/bin/sh #- +# Copyright (c) 2018 Rebecca Cran # Copyright (c) 2017 Nathan Whitehorn # All rights reserved. # @@ -35,6 +36,10 @@ fi fi -# For new-style EFI booting, add code here -# Add boot0cfg for MBR BIOS booting? +# Update the ESP (EFI System Partition) with the new bootloader +if [ `sysctl -n machdep.bootmethod` == UEFI ]; then + mkdir -p $BSDINSTALL_CHROOT/boot/efi/EFI/FreeBSD + cp $BSDINSTALL_CHROOT/boot/loader.efi $BSDINSTALL_CHROOT/boot/efi/EFI/FreeBSD +fi +# Add boot0cfg for MBR BIOS booting?