From 734859e112a2c3fce38250c1cd087753f1927d5e Mon Sep 17 00:00:00 2001
From: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Date: Wed, 24 Apr 2019 21:59:38 +0200
Subject: [PATCH] sparc64: Switch bootloader for d-i images from silo to
 grub-ieee1275

---
 build/boot/sparc64/debian.txt       | 17 --------
 build/boot/sparc64/grub-cdrom.cfg   | 40 +++++++++++++++++++
 build/boot/sparc64/notsupported.txt |  5 ---
 build/boot/sparc64/silo.conf        | 33 ---------------
 build/config/sparc64.cfg            | 62 ++++++++++++++++++++++++++---
 build/config/sparc64/cdrom.cfg      |  9 ++---
 build/config/sparc64/miniiso.cfg    | 30 --------------
 build/config/sparc64/netboot.cfg    | 19 ++-------
 debian/changelog                    |  3 ++
 debian/control                      |  4 +-
 10 files changed, 109 insertions(+), 113 deletions(-)
 delete mode 100644 build/boot/sparc64/debian.txt
 create mode 100644 build/boot/sparc64/grub-cdrom.cfg
 delete mode 100644 build/boot/sparc64/notsupported.txt
 delete mode 100644 build/boot/sparc64/silo.conf
 delete mode 100644 build/config/sparc64/miniiso.cfg

diff --git a/build/boot/sparc64/debian.txt b/build/boot/sparc64/debian.txt
deleted file mode 100644
index 1bae0c634..000000000
--- a/build/boot/sparc64/debian.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-
-                  Welcome to Debian GNU/Linux ${DEBIAN_VERSION}!
-
-This is a Debian installation ${MEDIA_TYPE}, built on ${BUILD_DATE}.
-Keep it once you have installed your system, as you can boot from it
-to repair the system on your hard disk if that ever becomes necessary.
-
-WARNING: You should completely back up all of your hard disks before
-  proceeding. The installation procedure can completely and irreversibly
-  erase them! If you haven't made backups yet, remove the rescue CD from
-  the drive and press L1-A to get back to the OpenBoot prompt.
-
-Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted
-by applicable law.
-
-[ ENTER - Boot install ]   [ Type "expert" - Boot into expert mode ]
-                           [ Type "rescue" - Boot into rescue mode ]
diff --git a/build/boot/sparc64/grub-cdrom.cfg b/build/boot/sparc64/grub-cdrom.cfg
new file mode 100644
index 000000000..41af6af63
--- /dev/null
+++ b/build/boot/sparc64/grub-cdrom.cfg
@@ -0,0 +1,40 @@
+set default=2
+set timeout=-1
+
+insmod echo
+insmod gzio
+insmod minicmd
+insmod normal
+
+menuentry "Debian GNU/Linux installer boot menu" {
+	true
+}
+
+menuentry "" {
+	true
+}
+
+function boot_one {
+	echo "Loading ..."
+	linux	${KERNEL} $options --- quiet
+	initrd	${INITRD}
+}
+
+menuentry "Default install" {
+        boot_one
+}
+
+menuentry "Automated install" {
+	set options="auto=true priority=critical"
+	boot_one
+}
+
+menuentry "Expert install" {
+	set options="priority=low"
+	boot_one
+}
+
+menuentry "Rescue mode" {
+	set options="rescue/enable=true"
+	boot_one
+}
diff --git a/build/boot/sparc64/notsupported.txt b/build/boot/sparc64/notsupported.txt
deleted file mode 100644
index 871731fb3..000000000
--- a/build/boot/sparc64/notsupported.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-
-This subarchitecture is currently not supported by Debian.
-Only 64-bit systems are supported (sparc64).
-
-The last Debian release to support sparc32 (sun4m) was Etch (4.0).
diff --git a/build/boot/sparc64/silo.conf b/build/boot/sparc64/silo.conf
deleted file mode 100644
index 307e1fe09..000000000
--- a/build/boot/sparc64/silo.conf
+++ /dev/null
@@ -1,33 +0,0 @@
-partition=1
-timeout=600
-message=/boot/debian.txt
-default=install
-initrd=/boot/initrd.gz
-read-write
-
-# Standard boot images
-image[sun4u]=/boot/vmlinuz-sparc64
-  label=install
-image[sun4,sun4c,sun4d,sun4m]="cat /boot/notsupported.txt"
-  label=install
-
-# Expert boots
-image[sun4u]=/boot/vmlinuz-sparc64
-  label=expert
-  append="priority=low"
-image[sun4,sun4c,sun4d,sun4m]="cat /boot/notsupported.txt"
-  label=expert
-
-# Rescue boots
-image[sun4u]=/boot/vmlinuz-sparc64
-  label=rescue
-  append="rescue/enable=true"
-image[sun4,sun4c,sun4d,sun4m]="cat /boot/notsupported.txt"
-  label=rescue
-
-# Auto install boots
-image[sun4u]=/boot/vmlinuz-sparc64
-  label=auto
-  append="auto=true priority=critical"
-image[sun4,sun4c,sun4d,sun4m]="cat /boot/notsupported.txt"
-  label=auto
diff --git a/build/config/sparc64.cfg b/build/config/sparc64.cfg
index 521d6ba95..ddcb9376a 100644
--- a/build/config/sparc64.cfg
+++ b/build/config/sparc64.cfg
@@ -1,15 +1,65 @@
-MEDIUM_SUPPORTED = cdrom netboot #miniiso
-
-VERSIONED_SYSTEM_MAP = t
+MEDIUM_SUPPORTED = cdrom netboot
 
 KERNELMAJOR = 2.6
-KERNELVERSION = $(LINUX_KERNEL_ABI)-sparc64
-
+BASEVERSION = $(LINUX_KERNEL_ABI)
+KERNELVERSION = $(BASEVERSION)-sparc64
 KERNELNAME = vmlinuz-${KERNELVERSION}
 
-DEBIAN_RELEASE = unstable
+VERSIONED_SYSTEM_MAP = t
 
+DEBIAN_RELEASE = unstable
 KEYRING = /usr/share/keyrings/debian-ports-archive-keyring.gpg
 
+GRUB_CFG_CDROM = boot/sparc64/grub-cdrom.cfg
+
+# GRUB modules
+GRUB_MODULES = echo gzio linux minicmd normal
+GRUB_MODULES_CDROM = iso9660
+
 arch_boot_screens:
 arch_tree:
+
+# Miniature CD image using GRUB, with only an initrd, no udebs or debs.
+.PHONY: arch_miniiso
+arch_miniiso: $(TEMP_INITRD) $(TEMP_KERNEL) $(TREE)
+	-rm -f $(TEMP_CD_TREE)/*
+	mkdir -p $(TEMP_CD_TREE)/boot/grub \
+		 $(TEMP_CD_TREE)/sparc64 \
+		 $(TEMP_CD_TREE)/install
+
+	cp $(TEMP_KERNEL) $(TEMP_CD_TREE)/install/vmlinux
+	cp $(TEMP_INITRD) $(TEMP_CD_TREE)/install/initrd.gz
+
+	cp -a /usr/lib/grub/sparc64-ieee1275 $(TEMP_CD_TREE)/boot/grub/
+
+	bootvars-subst \
+		KERNEL /install/vmlinux \
+		INITRD /install/initrd.gz \
+	< $(GRUB_CFG_CDROM) > $(TEMP_CD_TREE)/boot/grub/grub.cfg
+
+	grub-mkrescue --output=$(TEMP_MINIISO) $(TEMP_CD_TREE)
+
+# genisoimage CD info directory, including GRUB and configuration files.
+.PHONY: arch_cd_info_dir
+arch_cd_info_dir:
+	rm -rf $(TEMP_CD_INFO_DIR)
+	mkdir -p $(TEMP_CD_INFO_DIR)/boot/grub \
+		 $(TEMP_CD_INFO_DIR)/sparc64
+
+	cp -a /usr/lib/grub/sparc64-ieee1275 $(TEMP_CD_INFO_DIR)/boot/grub/
+
+	bootvars-subst \
+		KERNEL /install/vmlinux \
+		INITRD /install/initrd.gz \
+	< $(GRUB_CFG_CDROM) > $(TEMP_CD_INFO_DIR)/boot/grub/grub.cfg
+	grub-mkimage -O sparc64-ieee1275-cdcore -p '()/boot/grub' \
+		-o $(TEMP_CD_INFO_DIR)/boot/grub/core.img \
+		$(GRUB_MODULES) $(GRUB_MODULES_CDROM)
+
+# Netboot files
+.PHONY: arch_netboot_dir
+arch_netboot_dir:
+	-rm -f $(TEMP_NETBOOT_DIR)
+	mkdir -p $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)
+	cp $(TEMP_INITRD) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)
+	cp $(TEMP_KERNEL) $(TEMP_NETBOOT_DIR)/$(NETBOOT_PATH)
diff --git a/build/config/sparc64/cdrom.cfg b/build/config/sparc64/cdrom.cfg
index 22d6aa1d5..38547cbd0 100644
--- a/build/config/sparc64/cdrom.cfg
+++ b/build/config/sparc64/cdrom.cfg
@@ -1,9 +1,8 @@
 MEDIA_TYPE = CD-ROM
 
-TYPE = cdrom
-
-TARGET = $(INITRD) $(KERNEL)
+TARGET = $(INITRD) $(KERNEL) $(DEBIAN_CD_INFO)
 EXTRANAME = $(MEDIUM)/
 
-MANIFEST-INITRD = "initrd for CDROM"
-MANIFEST-KERNEL = "kernel for CDROM"
+MANIFEST-KERNEL = "kernel for use with mkisofs to build a CD"
+MANIFEST-INITRD = "initrd for use with mkisofs to build a CD"
+MANIFEST-DEBIAN_CD_INFO = "mkisofs config files for CD"
diff --git a/build/config/sparc64/miniiso.cfg b/build/config/sparc64/miniiso.cfg
deleted file mode 100644
index e9114c1b3..000000000
--- a/build/config/sparc64/miniiso.cfg
+++ /dev/null
@@ -1,30 +0,0 @@
-MEDIA_TYPE = CD-ROM
- 
-TYPE = netboot
-
-TARGET = $(TEMP_BOOT) $(MINIISO)
-
-MANIFEST-MINIISO = "tiny bootable CD image for pure network install"
- 
-.PHONY: arch_miniiso arch_boot_screens arch_boot
-arch_miniiso:
-	-rm -rf $(TEMP_CD_TREE)/*
-	install -m 644 -D $(TEMP)/initrd.gz $(TEMP_CD_TREE)/boot/initrd.gz
-	install -m 644 -D $(TEMP)/vmlinuz*64 $(TEMP_CD_TREE)/boot/vmlinuz-sparc64
-	install -m 644 /boot/second.b $(TEMP_CD_TREE)/boot
-	install -m 644 $(TEMP_BOOT_SCREENS)/debian.txt $(TEMP_CD_TREE)/boot
-	install -m 644 $(TEMP_BOOT_SCREENS)/notsupported.txt $(TEMP_CD_TREE)/boot
-	install -m 644 boot/sparc/silo.conf $(TEMP_CD_TREE)/boot
- 
-	genisoimage -r -J -o $(TEMP_MINIISO) -G /boot/isofs.b -B ... $(TEMP_CD_TREE)
-
-arch_boot_screens:
-	-rm -f $(TEMP_BOOT_SCREENS)/*
-	mkdir -p $(TEMP_BOOT_SCREENS)
-	bootvars-subst MEDIA_TYPE "$(MEDIA_TYPE)" \
-		DEBIAN_VERSION "$(DEBIAN_VERSION)" \
-		BUILD_DATE "$(BUILD_DATE)" \
-		< boot/sparc/debian.txt > $(TEMP_BOOT_SCREENS)/debian.txt
-	cp boot/sparc/notsupported.txt $(TEMP_BOOT_SCREENS)/notsupported.txt
-
-arch_boot:
diff --git a/build/config/sparc64/netboot.cfg b/build/config/sparc64/netboot.cfg
index 4a7072181..e38305f14 100644
--- a/build/config/sparc64/netboot.cfg
+++ b/build/config/sparc64/netboot.cfg
@@ -1,19 +1,8 @@
 MEDIA_TYPE = netboot image
- 
-TYPE = netboot
 
-TARGET = $(BOOT)
+NETBOOT_DIR_TARGETS = $(TEMP_INITRD) $(TEMP_KERNEL)
+TARGET = $(NETBOOT_DIR) $(NETBOOT_TAR) $(MINIISO)
 EXTRANAME = $(MEDIUM)/
 
-MANIFEST-BOOT = "tftp boot image for sparc64"
-
-TEMP_INITRD_XZ = $(TEMP)/initrd.xz
-
-$(TEMP_INITRD_XZ): $(TEMP_INITRD)
-	# xz options ensure that kernel's decoder can handle the image.
-	zcat $(TEMP_INITRD) | xz --check=crc32 --lzma2=dict=512KiB > $(TEMP_INITRD_XZ)
-
-.PHONY: arch_boot
-arch_boot: $(TEMP_INITRD_XZ)
-	gzip -c $(TEMP)/System.map-$(KERNELVERSION) >$(TEMP)/System.map.gz
-	tftpboot.sh $(TEMP_KERNEL) $(TEMP)/System.map.gz $(TEMP_INITRD_XZ) $(TEMP_BOOT)
+MANIFEST-NETBOOT_DIR = "boot directory for tftp server"
+MANIFEST-NETBOOT_TAR = "tarball of boot directory"
diff --git a/debian/changelog b/debian/changelog
index 263a2c836..3eae9e1ff 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -10,6 +10,9 @@ debian-installer (20190411) UNRELEASED; urgency=medium
     debian-ports-archive-keyring-udeb.
   * Add œŒ glyphs for the french translation.
 
+  [ John Paul Adrian Glaubitz ]
+  * sparc64: Switch bootloader for d-i images from silo to grub-ieee1275.
+
  -- Cyril Brulebois <kibi@debian.org>  Fri, 19 Apr 2019 22:45:44 +0200
 
 debian-installer (20190410) unstable; urgency=medium
diff --git a/debian/control b/debian/control
index b5e13507c..d38a5a864 100644
--- a/debian/control
+++ b/debian/control
@@ -90,7 +90,7 @@ Build-Depends:
 #		A previous version didn't have netabootwrap.
 	palo [hppa],
 #		Bootloader for hppa machines, to make netboot images.
-	silo [sparc sparc64],
+	silo [sparc],
 #		Using silo is problematic since it needs to run as root,
 #		so images that need it are not built by default, but we
 #		include it for completeness.
@@ -115,7 +115,7 @@ Build-Depends:
 	grub-efi-arm-bin [armhf],
 	grub-common [amd64 arm64 i386], xorriso,
 #		Used to make EFI bootable images
-	grub-ieee1275-bin [ppc64el],
+	grub-ieee1275-bin [ppc64el sparc64],
 #		IEEE1275 bootloader support.
 	u-boot-imx (>= 2019.01+dfsg-3) [armhf],
 	u-boot-omap (>= 2016.09~rc1) [armhf],
-- 
2.20.1

