From nobody Fri Sep 20 14:59:23 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4X9FsR6Nfqz5XT6l; Fri, 20 Sep 2024 14:59:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X9FsR4JTLz4NX5; Fri, 20 Sep 2024 14:59:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726844363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4JG0tX7Nz4i5E65PWpA99hcOJono2UzBcrNGdZMW7vs=; b=nL9sle2C4iO2YNHV1oPoHPQ/l/CxNKXbxoTWS5Ijj17fZh3lBXkrj6FRD0Lc3LaBG47HjO cvdC1n3G42PcDo3PmTJ7I6to7FdWDO64Y+HRkwImSdA30odwfVmC8M+viXdW0ZyFF5yoTo 02FOqZGLmosFOjN/ubP2GAfqdEKe3oXd1hnT8SCJsRYvssdYrRRuzVNfNypN2ElNrq8H07 uGgAMqBqXem/AXJfJe3eroMQ08gtU89kRk3FCrjkKb1oJ7EAr3rILu+FZzRIWT+VusQV3M l24yuI8imUc7ll43T8MnindTVaDsxvm5xcVHem7qON1M8QreE04h0cKgXPirAw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726844363; a=rsa-sha256; cv=none; b=yaaSDiFvtunSg5EJ/FRy2Le+uhiwaGT8mpDYMCqBsgLquyid9m8HZpDHdmT3suEO06tYhe e5DPwDJZ1PSJ2ooGqOHWJn5X8jpaU6pZcA57RvYrqr9RaUunG/pcyEdWd89RG6IH2nFYXU 2rm4DroaOWXtyq+7uJy3hicT8D+dj4JJhFWaURSO9GdJ0050IKaJomne2H4vwsnNsETe6m a62Fo4Li28RL4WMIvJiCNg7AEIBsHnmmbQXsdyZfxnIZujC61aZcpGM3yw5BsJf1eiHRvw 7BcqZi58YbwbwuHMrEWkrOQjT9vqYK9i2KcGqwQ2Ge6c+uK5tw93zavgDmRN5Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726844363; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=4JG0tX7Nz4i5E65PWpA99hcOJono2UzBcrNGdZMW7vs=; b=HtE6BxwLiPiZAQKH3BBhkrVP4fCane6OEtyLLu+ADNQ2+X9zmMI7GBOZ8Kqq38SvFBltn/ 0gs+dWhMHb5h/VVP4Z6U8mEDTBxK9Mn7/cFwERiZcTeDssMm/S8yuzp3QfYUCpMLDcM/FQ +p+EJHVfBbR51OT0Fe6z5Ep6apdJR/3B5mpTPyuMQ+I1QtxBjivR3ufDmaOfsZnrPl9eHB DLs1UDXFkmRAfjsNckxxIRc6/JsBFD0VdqyoMuVvzC+blcWu+YrJyY6HLoX64TU5ZbOkh4 ZDxldqDfI/ypsAc2JaNf5xWX3JEl5pBpK5ZKJmaql3wIKxeZHcHRPLIKpAVgkA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4X9FsR3bDpztLC; Fri, 20 Sep 2024 14:59:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48KExNsw046863; Fri, 20 Sep 2024 14:59:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48KExN7H046860; Fri, 20 Sep 2024 14:59:23 GMT (envelope-from git) Date: Fri, 20 Sep 2024 14:59:23 GMT Message-Id: <202409201459.48KExN7H046860@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 599273f942b8 - main - Copy the new ia32 loader List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 599273f942b8dc6f957487bb28f36694dab9dad2 Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=599273f942b8dc6f957487bb28f36694dab9dad2 commit 599273f942b8dc6f957487bb28f36694dab9dad2 Author: Ahmad Khalifa AuthorDate: 2024-06-03 01:53:44 +0000 Commit: Warner Losh CommitDate: 2024-09-20 14:45:10 +0000 Copy the new ia32 loader This handles copying in install-boot.sh and bsdinstall's bootconfig. install-boot.sh: make_esp_file now optionally takes extra arguments so it can copy multiple files. This is used by the amd64 release scripts. make_esp_device also takes an extra optional argument for efibootname. This is currently unused, but it can be used in the future to do something like: make_esp_device loader.efi bootx64 make_esp_device loader_ia32.efi bootia32 Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1098 --- release/amd64/make-memstick.sh | 7 ++++- release/amd64/mkisoimages.sh | 7 ++++- tools/boot/install-boot.sh | 52 +++++++++++++++++++++++++--------- usr.sbin/bsdinstall/scripts/bootconfig | 36 ++++++++++++++--------- 4 files changed, 72 insertions(+), 30 deletions(-) diff --git a/release/amd64/make-memstick.sh b/release/amd64/make-memstick.sh index 4c51d7d65af4..cbb80e971343 100755 --- a/release/amd64/make-memstick.sh +++ b/release/amd64/make-memstick.sh @@ -60,7 +60,12 @@ fi # Make an ESP in a file. espfilename=$(mktemp /tmp/efiboot.XXXXXX) -make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi +if [ -f "${BASEBITSDIR}/boot/loader_ia32.efi" ]; then + make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi bootx64 \ + ${BASEBITSDIR}/boot/loader_ia32.efi bootia32 +else + make_esp_file ${espfilename} ${fat32min} ${BASEBITSDIR}/boot/loader.efi +fi mkimg -s mbr \ -b ${BASEBITSDIR}/boot/mbr \ diff --git a/release/amd64/mkisoimages.sh b/release/amd64/mkisoimages.sh index 3cc7a6cc919e..245beb660c3f 100644 --- a/release/amd64/mkisoimages.sh +++ b/release/amd64/mkisoimages.sh @@ -64,7 +64,12 @@ if [ "$1" = "-b" ]; then espfilename=$(mktemp /tmp/efiboot.XXXXXX) # ESP file size in KB. espsize="2048" - make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi + if [ -f "${BASEBITSDIR}/boot/loader_ia32.efi" ]; then + make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi bootx64 \ + ${BASEBITSDIR}/boot/loader_ia32.efi bootia32 + else + make_esp_file ${espfilename} ${espsize} ${BASEBITSDIR}/boot/loader.efi + fi bootable="$bootable -o bootimage=i386;${espfilename} -o no-emul-boot -o platformid=efi" shift diff --git a/tools/boot/install-boot.sh b/tools/boot/install-boot.sh index 332756582137..217bf0ff1457 100755 --- a/tools/boot/install-boot.sh +++ b/tools/boot/install-boot.sh @@ -42,11 +42,10 @@ get_uefi_bootname() { } make_esp_file() { - local file sizekb loader device stagedir fatbits efibootname + local file sizekb device stagedir fatbits efibootname file=$1 sizekb=$2 - loader=$3 if [ "$sizekb" -ge "$fat32min" ]; then fatbits=32 @@ -58,8 +57,25 @@ make_esp_file() { stagedir=$(mktemp -d /tmp/stand-test.XXXXXX) mkdir -p "${stagedir}/EFI/BOOT" - efibootname=$(get_uefi_bootname) - cp "${loader}" "${stagedir}/EFI/BOOT/${efibootname}.efi" + + # Allow multiple files to be copied. + # We do this in pairs, e.g: + # make_esp_file ... loader1.efi bootx64 loader2.efi bootia32 + # + # If the second argument is left out, + # determine it automatically. + shift; shift # Skip $file and $sizekb + while [ ! -z $1 ]; do + if [ ! -z $2 ]; then + efibootname=$2 + else + efibootname=$(get_uefi_bootname) + fi + cp "$1" "${stagedir}/EFI/BOOT/${efibootname}.efi" + + shift; shift || : # Ignore failure to shift + done + makefs -t msdos \ -o fat_type=${fatbits} \ -o sectors_per_cluster=1 \ @@ -70,13 +86,20 @@ make_esp_file() { } make_esp_device() { - local dev file mntpt fstype efibootname kbfree loadersize efibootfile + local dev file dst mntpt fstype efibootname kbfree loadersize efibootfile local isboot1 existingbootentryloaderfile bootorder bootentry # ESP device node dev=$1 file=$2 + # Allow caller to override the default + if [ ! -z $3 ]; then + efibootname=$3 + else + efibootname=$(get_uefi_bootname) + fi + dst=$(basename ${file%.efi}) mntpt=$(mktemp -d /tmp/stand-test.XXXXXX) # See if we're using an existing (formatted) ESP @@ -93,7 +116,6 @@ make_esp_device() { echo "Mounted ESP ${dev} on ${mntpt}" - efibootname=$(get_uefi_bootname) kbfree=$(df -k "${mntpt}" | tail -1 | cut -w -f 4) loadersize=$(stat -f %z "${file}") loadersize=$((loadersize / 1024)) @@ -114,7 +136,7 @@ make_esp_device() { fi fi - if [ ! -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -lt "$loadersize" ]; then + if [ ! -f "${mntpt}/EFI/freebsd/${dst}.efi" ] && [ "$kbfree" -lt "$loadersize" ]; then umount "${mntpt}" rmdir "${mntpt}" echo "Failed to update the EFI System Partition ${dev}" @@ -126,24 +148,26 @@ make_esp_device() { mkdir -p "${mntpt}/EFI/freebsd" # Keep a copy of the existing loader.efi in case there's a problem with the new one - if [ -f "${mntpt}/EFI/freebsd/loader.efi" ] && [ "$kbfree" -gt "$((loadersize * 2))" ]; then - cp "${mntpt}/EFI/freebsd/loader.efi" "${mntpt}/EFI/freebsd/loader-old.efi" + if [ -f "${mntpt}/EFI/freebsd/${dst}.efi" ] && [ "$kbfree" -gt "$((loadersize * 2))" ]; then + cp "${mntpt}/EFI/freebsd/${dst}.efi" "${mntpt}/EFI/freebsd/${dst}-old.efi" fi echo "Copying loader to /EFI/freebsd on ESP" - cp "${file}" "${mntpt}/EFI/freebsd/loader.efi" + cp "${file}" "${mntpt}/EFI/freebsd/${dst}.efi" - if [ -n "${updatesystem}" ]; then - existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/loader.efi") + # efibootmgr won't work on systems with ia32 UEFI firmware + # since we only use it to boot the 64-bit kernel + if [ -n "${updatesystem}" ] && [ ${efibootname} != "bootia32" ]; then + existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}//EFI/freebsd/${dst}.efi") if [ -z "$existingbootentryloaderfile" ]; then # Try again without the double forward-slash in the path - existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}/EFI/freebsd/loader.efi") + existingbootentryloaderfile=$(efibootmgr -v | grep "${mntpt}/EFI/freebsd/${dst}.efi") fi if [ -z "$existingbootentryloaderfile" ]; then echo "Creating UEFI boot entry for FreeBSD" - efibootmgr --create --label FreeBSD --loader "${mntpt}/EFI/freebsd/loader.efi" > /dev/null + efibootmgr --create --label FreeBSD --loader "${mntpt}/EFI/freebsd/${dst}.efi" > /dev/null if [ $? -ne 0 ]; then die "Failed to create new boot entry" fi diff --git a/usr.sbin/bsdinstall/scripts/bootconfig b/usr.sbin/bsdinstall/scripts/bootconfig index bd69195f76ff..618a1966095e 100755 --- a/usr.sbin/bsdinstall/scripts/bootconfig +++ b/usr.sbin/bsdinstall/scripts/bootconfig @@ -109,32 +109,40 @@ if [ -n "$(awk '{if ($2=="/boot/efi") printf("%s\n",$1);}' $PATH_FSTAB)" ]; then # i386) ARCHBOOTNAME=ia32 ;; # no support for this in i386 kernels, rare machines *) die "Unsupported arch $(uname -m) for UEFI install" esac + + if [ `sysctl -n machdep.efi_arch` == i386 ]; then + ARCHBOOTNAME=ia32 + file=loader_ia32.efi + else + file=loader.efi + fi + BOOTDIR="/efi/boot" BOOTNAME="${BOOTDIR}/boot${ARCHBOOTNAME}.efi" FREEBSD_BOOTDIR="/efi/freebsd" - FREEBSD_BOOTNAME="${FREEBSD_BOOTDIR}/loader.efi" + FREEBSD_BOOTNAME="${FREEBSD_BOOTDIR}/${file}" mntpt="$BSDINSTALL_CHROOT/boot/efi" - f_dprintf "Installing loader.efi onto ESP" + f_dprintf "Installing ${file} onto ESP" mkdir -p "${mntpt}/${FREEBSD_BOOTDIR}" "${mntpt}/${BOOTDIR}" - cp "$BSDINSTALL_CHROOT/boot/loader.efi" "${mntpt}/${FREEBSD_BOOTNAME}" + cp "$BSDINSTALL_CHROOT/boot/${file}" "${mntpt}/${FREEBSD_BOOTNAME}" # - # The following shouldn't be necessary. UEFI defines a way to - # specifically select what to boot (which we do via - # efibootmgr). However, virtual environments often times lack - # support for the NV variables efibootmgr sets. In addition, - # some UEFI implementations have features that interfere with - # the setting of these variables. To combat that, we install the - # default removable media boot file as a fallback if it doesn't - # exist. We don't install it all the time since that can - # interfere with other installations on the drive (like rEFInd). + # UEFI defines a way to specifically select what to boot + # (which we do via efibootmgr). However, if we booted from an ia32 + # UEFI environment, we wouldn't have access to efirt. In addition, + # virtual environments often times lack support for the NV variables + # efibootmgr sets, and some UEFI implementations have features that + # interfere with the setting of these variables. To combat that, we + # install the default removable media boot file if it doesn't exist. + # We don't install it all the time since that can interfere with other + # installations on the drive (like rEFInd). # if [ ! -f "${mntpt}/${BOOTNAME}" ]; then - cp "$BSDINSTALL_CHROOT/boot/loader.efi" "${mntpt}/${BOOTNAME}" + cp "$BSDINSTALL_CHROOT/boot/${file}" "${mntpt}/${BOOTNAME}" fi - if [ "$BSDINSTALL_CONFIGCURRENT" ]; then + if [ "$BSDINSTALL_CONFIGCURRENT" ] && [ "$ARCHBOOTNAME" != ia32 ]; then update_uefi_bootentry fi