From 4428dbbf8f998c138093e3208bc7a0e7034714be Mon Sep 17 00:00:00 2001
From: Dimitri John Ledkov <xnox@ubuntu.com>
Date: Thu, 11 Mar 2021 17:06:38 +0000
Subject: [PATCH] riscv64: generalise slightly how preinstalled server images
 are built, to allow using subarch to pick u-boot binaries to install.

---
 debian/changelog                                          | 7 +++++++
 live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary | 8 ++++++--
 live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary     | 2 +-
 3 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index ac0b167b..540498be 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,10 @@
+livecd-rootfs (2.717) UNRELEASED; urgency=medium
+
+  * riscv64: generalise slightly how preinstalled server images are built,
+    to allow using subarch to pick u-boot binaries to install.
+
+ -- Dimitri John Ledkov <xnox@ubuntu.com>  Wed, 10 Mar 2021 14:16:23 +0000
+
 livecd-rootfs (2.716) hirsute; urgency=medium
 
   * Use the correct config keys in suppressing cloud-init output during boot
diff --git a/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary b/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary
index b9745db6..a619299b 100755
--- a/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary
+++ b/live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary
@@ -136,13 +136,17 @@ install_grub() {
             chroot mountpoint u-boot-update
 
             if [ -n "${SUBARCH:-}" ]; then
+                u_boot_arch="${SUBARCH}"
+                if [ "${u_boot_arch}" = "hifive" ]; then
+                    u_boot_arch=sifive_fu540
+                fi
                 chroot mountpoint apt-get install -qqy u-boot-sifive
                 # FSBL, which gets U-Boot SPL
                 loader1="/dev/mapper${loop_device///dev/}p13"
                 # The real U-Boot
                 loader2="/dev/mapper${loop_device///dev/}p14"
-                dd if=mountpoint/usr/lib/u-boot/sifive_fu540/u-boot-spl.bin of=$loader1
-                dd if=mountpoint/usr/lib/u-boot/sifive_fu540/u-boot.itb of=$loader2
+                dd if=mountpoint/usr/lib/u-boot/${u_boot_arch}/u-boot-spl.bin of=$loader1
+                dd if=mountpoint/usr/lib/u-boot/${u_boot_arch}/u-boot.itb of=$loader2
                 # Provide end-user modifyable CIDATA
                 cidata_dev="/dev/mapper${loop_device///dev/}p12"
                 setup_cidata "${cidata_dev}"
diff --git a/live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary b/live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary
index a4851e26..5b38fe69 100755
--- a/live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary
+++ b/live-build/ubuntu-cpc/hooks.d/base/qcow2-image.binary
@@ -7,7 +7,7 @@ case $ARCH:$SUBARCH in
 		xz -T4 -c binary/boot/disk.ext4 > livecd.ubuntu-cpc.disk1.img.xz
 	        exit 0
 		;;
-	riscv64:hifive)
+	riscv64:hifive|riscv64:sifive_*)
 		xz -T4 -c binary/boot/disk-uefi.ext4 > livecd.ubuntu-cpc.disk1.img.xz
 	        exit 0
 		;;