From acd1cd8f21b59e82e018fa461b10cbd02c507606 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
Date: Wed, 18 Oct 2017 10:46:28 +0000
Subject: [PATCH] scripts/mkimg.base: add efi loaders to the iso image

Strictly the 'efi' folder is not needed since it's in the efi.img.
However, converting .iso to USB stick is a lot simpler when the
EFI folder is in the .iso too. This allows just copying .iso contents
to the USB stick and EFI boot will work. While Rufus supports
extracting the boot files from efi.img, it was considered more
portable to add the copy. This also simplifies updating setup-bootable
to prepare EFI bootable disks.
---
 scripts/mkimg.base.sh | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/scripts/mkimg.base.sh b/scripts/mkimg.base.sh
index 2e904ba62959..6cdd0699e7b9 100755
--- a/scripts/mkimg.base.sh
+++ b/scripts/mkimg.base.sh
@@ -165,28 +165,20 @@ grub_gen_earlyconf() {
 	EOF
 }
 
-build_grubefi_img() {
+build_grub_efi() {
 	local _format="$1"
 	local _efi="$2"
-	local _tmpdir="$WORKDIR/efiboot.$3"
-
-	# extra packages needed: grub-efi mtools
 
 	# Prepare grub-efi bootloader
-	mkdir -p "$_tmpdir/efi/boot"
-	grub_gen_earlyconf > "$_tmpdir"/grub_early.cfg
+	mkdir -p "$DESTDIR/efi/boot"
+	grub_gen_earlyconf > "$WORKDIR/grub_early.$3.cfg"
 	grub-mkimage \
-		--config="$_tmpdir"/grub_early.cfg \
+		--config="$WORKDIR/grub_early.$3.cfg" \
 		--prefix="/boot/grub" \
-		--output="$_tmpdir/efi/boot/$_efi" \
+		--output="$DESTDIR/efi/boot/$_efi" \
 		--format="$_format" \
 		--compression="xz" \
 		$grub_mod
-
-	# Create the EFI image
-	mkdir -p ${DESTDIR}/boot/grub/
-	mformat -i ${DESTDIR}/boot/grub/efi.img -C -f 1440 ::
-	mcopy -i ${DESTDIR}/boot/grub/efi.img -s $_tmpdir/efi ::
 }
 
 section_grubieee1275() {
@@ -197,7 +189,7 @@ section_grubieee1275() {
 	build_section grub_cfg boot/grub/grub.cfg $(grub_gen_config | checksum)
 }
 
-section_grubefi() {
+section_grub_efi() {
 	[ -n "$grub_mod" ] || return 0
 	[ "$output_format" = "iso" ] || return 0
 
@@ -217,7 +209,7 @@ section_grubefi() {
 	esac
 
 	build_section grub_cfg boot/grub/grub.cfg $(grub_gen_config | checksum)
-	build_section grubefi_img $_format $_efi $(grub_gen_earlyconf | checksum)
+	build_section grub_efi $_format $_efi $(grub_gen_earlyconf | checksum)
 }
 
 create_image_iso() {
@@ -236,8 +228,12 @@ create_image_iso() {
 			-boot-info-table
 			"
 	fi
-	if [ -e "${DESTDIR}/boot/grub/efi.img" ]; then
-		# efi boot enabled
+	if [ -e "${DESTDIR}/efi" -a -e "${DESTDIR}/boot/grub" ]; then
+		# Create the EFI boot partition image
+		mformat -i ${DESTDIR}/boot/grub/efi.img -C -f 1440 ::
+		mcopy -i ${DESTDIR}/boot/grub/efi.img -s ${DESTDIR}/efi ::
+
+		# Enable EFI boot
 		if [ -z "$_isolinux" ]; then
 			# efi boot only
 			_efiboot="
-- 
GitLab