Files
system76-edk2/OvmfPkg/AmdSev/Grub/grub.sh
James Bottomley b261a30c90 OvmfPkg/AmdSev: add Grub Firmware Volume Package
This is used to package up the grub bootloader into a firmware volume
where it can be executed as a shell like the UEFI Shell.  Grub itself
is built as a minimal entity into a Fv and then added as a boot
option.  By default the UEFI shell isn't built but for debugging
purposes it can be enabled and will then be presented as a boot option
(This should never be allowed for secure boot in an external data
centre but may be useful for local debugging).  Finally all other boot
options except grub and possibly the shell are stripped and the boot
timeout forced to 0 so the system will not enter a setup menu and will
only boot to grub.  This is done by copying the
Library/PlatformBootManagerLib into Library/PlatformBootManagerLibGrub
and then customizing it.

Boot failure is fatal to try to prevent secret theft.

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3077
Signed-off-by: James Bottomley <jejb@linux.ibm.com>
Message-Id: <20201130202819.3910-4-jejb@linux.ibm.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
[lersek@redhat.com: replace local variable initialization with assignment]
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
[lersek@redhat.com: squash 'OvmfPkg: add "gGrubFileGuid=Grub" to
 GuidCheck.IgnoreDuplicates', reviewed stand-alone by Phil (msgid
 <e6eae551-8563-ccfb-5547-7a97da6d46e5@redhat.com>) and Ard (msgid
 <10aeda37-def6-d9a4-6e02-4c66c1492f57@arm.com>)]
2020-12-14 19:56:18 +00:00

94 lines
2.1 KiB
Bash

## @file
# Build a version of grub capable of decrypting a luks volume with a SEV
# Supplied secret
#
# Copyright (C) 2020 James Bottomley, IBM Corporation.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
set -e
remove_efi=1
cleanup() {
# remove the intermediates
for f in disk.fat grub-bootstrap.cfg; do
rm -f -- "${basedir}/$f"
done
if [ $remove_efi -eq 1 ]; then
rm -f -- "${basedir}/grub.efi"
fi
}
trap cleanup EXIT
GRUB_MODULES="
part_msdos
part_gpt
cryptodisk
luks
gcry_rijndael
gcry_sha256
ext2
btrfs
xfs
fat
configfile
memdisk
sleep
normal
echo
test
regexp
linux
linuxefi
reboot
sevsecret
"
basedir=$(dirname -- "$0")
# don't run a build if grub.efi exists and is newer than the config files
if [ -e "${basedir}/grub.efi" ] && \
[ "${basedir}/grub.efi" -nt "${basedir}/grub.cfg" ] && \
[ "${basedir}/grub.efi" -nt "${basedir}/grub.sh" ]; then
remove_efi=0
echo "preserving existing grub.efi" >&2
exit 0
fi
##
# different distributions have different names for grub-mkimage, so
# search all the known ones
##
mkimage=
for b in grub2-mkimage grub-mkimage; do
if which "$b" > /dev/null 2>&1; then
mkimage="$b"
break
fi
done
if [ -z "$mkimage" ]; then
echo "Can't find grub mkimage" >&2
exit 1
fi
# GRUB's rescue parser doesn't understand 'if'.
echo 'normal (memdisk)/grub.cfg' > "${basedir}/grub-bootstrap.cfg"
# Now build a memdisk with the correct grub.cfg
rm -f -- "${basedir}/disk.fat"
mkfs.msdos -C -- "${basedir}/disk.fat" 64
mcopy -i "${basedir}/disk.fat" -- "${basedir}/grub.cfg" ::grub.cfg
${mkimage} -O x86_64-efi \
-p '(crypto0)' \
-c "${basedir}/grub-bootstrap.cfg" \
-m "${basedir}/disk.fat" \
-o "${basedir}/grub.efi" \
${GRUB_MODULES}
remove_efi=0
echo "grub.efi generated in ${basedir}"