From 59f5037ab9bcbc76ee6e9b205742a63e19c2d0b5 Mon Sep 17 00:00:00 2001
From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Date: Fri, 26 Apr 2019 22:40:29 +0200
Subject: [PATCH] ia64: Switch bootloader from ELILO to GRUB

---
 build/config/ia64.cfg | 153 ++++++++++++++++++++++--------------------
 debian/control        |   1 +
 2 files changed, 80 insertions(+), 74 deletions(-)

diff --git a/build/config/ia64.cfg b/build/config/ia64.cfg
index 454a662ba..1a32f80e4 100644
--- a/build/config/ia64.cfg
+++ b/build/config/ia64.cfg
@@ -1,6 +1,3 @@
-# How big a floppy image should I make? (in kilobytes)
-FLOPPY_SIZE = 32768
-
 MEDIUM_SUPPORTED = cdrom netboot
 
 # The version of the kernel to use.
@@ -12,86 +9,94 @@ DEBIAN_RELEASE = unstable
 
 KEYRING = /usr/share/keyrings/debian-ports-archive-keyring.gpg
 
-INITRD_FS = initramfs
+GRUB_EFI=y
+GRUB_PLATFORM=ia64-efi
+GRUB_EFI_NAME=ia64
 
-# The DOS volume id to use for DOS floppies. This is a 32 bit hexidecimal
-# number.
-DOS_VOLUME_ID = deb00001
-# The DOS volume label to use for DOS floppies. This is a 11 character
-# string.
-DOS_VOLUME_LABEL = "Debian Inst"
+arch_boot_screens:
+arch_tree:
 
+# The font to load in GRUB
+GRUB_FONT = /usr/share/grub/ascii.pf2
 
-arch_tree:
+# Extract GRUB EFI files.
+.PHONY: ia64_grub_efi
+ia64_grub_efi:
+ifeq ($(GRUB_EFI),y)
+	efi-image $(TEMP_GRUB_EFI) $(GRUB_PLATFORM) $(GRUB_EFI_NAME) $(NETBOOT_PATH)
+endif
 
-# Create a bootable floppy image.
-# 1. make a dos filesystem image
-# 2. copy over kernel, initrd
-# 3. copy over elilo files
-.PHONY: arch_boot
-arch_boot:
-	dd if=/dev/zero of=$@.new bs=1k count=$(FLOPPY_SIZE)
-	mkfs.msdos --invariant -i $(DOS_VOLUME_ID) -n $(DOS_VOLUME_LABEL) -C $(TEMP_BOOT) $(FLOPPY_SIZE)
-
-	mmd -i$(TEMP_BOOT) ::/efi
-	mmd -i$(TEMP_BOOT) ::/efi/boot
-	mcopy -i$(TEMP_BOOT) $(TEMP_KERNEL) ::/linux
-	mcopy -i$(TEMP_BOOT) $(TEMP_INITRD) ::/initrd.gz
-	mcopy -i$(TEMP_BOOT) /usr/lib/elilo/elilo.efi ::/efi/boot/bootia64.efi
-	mcopy -i$(TEMP_BOOT) /usr/lib/elilo/elilo.efi ::/elilo.efi
-	
-	cat boot/ia64/elilo.conf \
-	| ramdisk-size-subst $(TEMP_INITRD) \
-	| bootvars-subst MEDIA_TYPE "$(MEDIA_TYPE)" \
-		DEBIAN_VERSION "$(DEBIAN_VERSION)" \
-		BUILD_DATE "$(BUILD_DATE)" \
-		SYSDIR "/efi/boot/" \
-		KERNEL /linux INITRD /initrd.gz \
-	> $(TEMP)/elilo-cd.conf
-	mcopy -i$(TEMP_BOOT) $(TEMP)/elilo-cd.conf ::/elilo.conf
-	mcopy -i$(TEMP_BOOT) $(TEMP)/elilo-cd.conf ::/efi/boot/elilo.conf
-	
-	$(foreach file,$(sort $(wildcard $(TEMP_BOOT_SCREENS)/*.msg)), \
-		mcopy -i$(TEMP_BOOT) $(file) ::/efi/boot/`basename $(file)`; \
-	)
-	echo "elilo linux" | mcopy -i$(TEMP_BOOT) - ::/install.nsh
+# Supply GRUB EFI configuration.
+.PHONY: arch_cd_info_dir
+arch_cd_info_dir: ia64_grub_efi
+	-rm -f $(TEMP_CD_INFO_DIR)/*
+	mkdir -p $(TEMP_CD_INFO_DIR)
 
-arch_boot_screens:
-	-rm -f $(TEMP_BOOT_SCREENS)/*
-	mkdir -p $(TEMP_BOOT_SCREENS)
-	$(foreach SCREEN,$(wildcard boot/ia64/*.msg), \
-		bootvars-subst MEDIA_TYPE "$(MEDIA_TYPE)" \
-			DEBIAN_VERSION "$(DEBIAN_VERSION)" \
-			BUILD_DATE "$(BUILD_DATE)" \
-		 < $(SCREEN) > $(TEMP_BOOT_SCREENS)/`basename $(SCREEN)`\
-	;)
+	if [ "$(GRUB_EFI)" = y ]; then \
+		set -e; \
+		mkdir -p $(TEMP_CD_INFO_DIR)/grub/$(GRUB_PLATFORM); \
+		cp -a $(TEMP_GRUB_EFI)/efi.img $(TEMP_CD_INFO_DIR)/grub/; \
+		grub-gencfg \
+			KERNEL /%install%/vmlinuz \
+			INITRD /%install%/initrd.gz \
+			HEADER boot/$(ARCH)/grub/grub-efi.cfg \
+		> $(TEMP_CD_INFO_DIR)/grub/grub.cfg; \
+		cp -a $(GRUB_FONT) $(TEMP_CD_INFO_DIR)/grub/font.pf2; \
+		cp -a $(TEMP_GRUB_EFI)/boot/grub/$(GRUB_PLATFORM)/* \
+			$(TEMP_CD_INFO_DIR)/grub/$(GRUB_PLATFORM)/; \
+	fi
 
 .PHONY: arch_miniiso
-arch_miniiso: $(TEMP_BOOT)
-	-rm -rf $(TEMP_CD_TREE)/*
-	install -m 644 -D $(TEMP_BOOT) $(TEMP_CD_TREE)/boot/boot.img
+arch_miniiso: ia64_grub_efi
+	-rm -f $(TEMP_CD_TREE)/*
+	mkdir -p $(TEMP_CD_TREE)
 
-	genisoimage -no-emul-boot -J -o $(TEMP_MINIISO) -b boot/boot.img \
-		-c boot/boot.catalog $(TEMP_CD_TREE)
+	ln -f $(TEMP_KERNEL) $(TEMP_CD_TREE)/linux
+	ln -f $(TEMP_INITRD) $(TEMP_CD_TREE)/initrd.gz
+
+	mkdir -p $(TEMP_CD_TREE)/.disk
+	echo "Debian GNU/Linux $(DEBIAN_VERSION) $(ARCH) - netboot mini.iso $(BUILD_DATE)"\
+	> $(TEMP_CD_TREE)/.disk/info
+
+	if [ "$(GRUB_EFI)" = y ]; then \
+		set -e; \
+		mkdir -p $(TEMP_CD_TREE)/boot/grub/$(GRUB_PLATFORM); \
+		cp -a $(TEMP_GRUB_EFI)/efi.img $(TEMP_CD_TREE)/boot/grub/; \
+		grub-gencfg \
+			KERNEL /linux \
+			INITRD /initrd.gz \
+			HEADER boot/$(ARCH)/grub/grub-efi.cfg \
+		> $(TEMP_CD_TREE)/boot/grub/grub.cfg; \
+		cp -a $(GRUB_FONT) $(TEMP_CD_TREE)/boot/grub/font.pf2; \
+		cp -a $(TEMP_GRUB_EFI)/boot/grub/$(GRUB_PLATFORM)/* \
+			$(TEMP_CD_TREE)/boot/grub/$(GRUB_PLATFORM)/; \
+	fi
+
+	if [ "$(GRUB_EFI)" = y ]; then \
+		xorriso -as mkisofs -r -J -c boot.cat \
+			-boot-load-size 4 -boot-info-table \
+			-eltorito-alt-boot \
+			--efi-boot boot/grub/efi.img -no-emul-boot \
+			-o $(TEMP_MINIISO) $(TEMP_CD_TREE); \
+	fi
 
 .PHONY: arch_netboot_dir
-arch_netboot_dir:
+arch_netboot_dir: ia64_grub_efi
 	-rm -f $(TEMP_NETBOOT_DIR)
 	mkdir -p $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)
-	cp $(TEMP_INITRD) $(TEMP_KERNEL) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)
-	
-	cp /usr/lib/elilo/elilo.efi $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)
-	cat boot/ia64/elilo.conf \
-	| ramdisk-size-subst $(TEMP_INITRD) \
-	| bootvars-subst MEDIA_TYPE "$(MEDIA_TYPE)" \
-		DEBIAN_VERSION "$(DEBIAN_VERSION)" \
-		BUILD_DATE "$(BUILD_DATE)" \
-		SYSDIR "$(BOOT_SCREEN_DIR)" \
-		KERNEL vmlinuz INITRD initrd.gz \
-	> $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/elilo.conf
-
-	mkdir -p $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/$(BOOT_SCREEN_DIR)
-	set -e; \
-	$(foreach file,$(wildcard $(TEMP_BOOT_SCREENS)/*.msg), \
-		cp $(file) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/$(BOOT_SCREEN_DIR); \
-	)
+	cp $(TEMP_KERNEL) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/linux
+	cp $(TEMP_INITRD) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/initrd.gz
+
+	if [ "$(GRUB_EFI)" = y ]; then \
+		set -e; \
+		mkdir -p $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/grub/$(GRUB_PLATFORM); \
+		cp -a $(TEMP_GRUB_EFI)/*.efi $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH); \
+		cp -a $(GRUB_FONT) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/grub/font.pf2; \
+		cp -a $(TEMP_GRUB_EFI)/boot/grub/$(GRUB_PLATFORM)/* \
+			$(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/grub/$(GRUB_PLATFORM)/; \
+		grub-gencfg \
+			KERNEL /$(NETBOOT_PATH)/linux \
+			INITRD /$(NETBOOT_PATH)/initrd.gz \
+			HEADER boot/$(ARCH)/grub/grub-efi.cfg \
+		> $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)/grub/grub.cfg; \
+	fi
diff --git a/debian/control b/debian/control
index 2aa96a25a..01e6b83ec 100644
--- a/debian/control
+++ b/debian/control
@@ -112,6 +112,7 @@ Build-Depends:
 #	        Signed bootloader components for UEFI Secure Boot
 	grub-efi-arm64-bin [arm64],
 	grub-efi-ia32-bin [i386],
+	grub-efi-ia64-bin [ia64],
 	grub-efi-arm-bin [armhf],
 	grub-common [amd64 arm64 i386], xorriso,
 #		Used to make EFI bootable images
-- 
2.20.1

