summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtools/add_riscv_gpt8
-rwxr-xr-xtools/boot/noble/boot-riscv6444
-rw-r--r--tools/boot/noble/common.sh64
3 files changed, 93 insertions, 23 deletions
diff --git a/tools/add_riscv_gpt b/tools/add_riscv_gpt
index 454b63d0..f48cdb0d 100755
--- a/tools/add_riscv_gpt
+++ b/tools/add_riscv_gpt
@@ -27,10 +27,10 @@ gdisk -l "${disk_image}" || { echo "GPT table not found!"; exit 1; }
sgdisk "$disk_image" \
--set-alignment=2 \
-d 1 \
- -n 1:2082:10273 -c 1:U-Boot -t 1:2E54B353-1271-4842-806F-E436D6AF6985 \
- -n 3:10274:12321 -c 3:U-Boot-SPL -t 3:5B193300-FC78-40CD-8002-E86C45580B47 \
- -c 2:ESP || { echo "Failed to modify partitions."; exit 1; }
-
+ -n 1:2082:10273 -c 1:loader2 -t 1:2E54B353-1271-4842-806F-E436D6AF6985 \
+ -n 3:10274:12321 -c 3:loader1 -t 3:5B193300-FC78-40CD-8002-E86C45580B47 \
+ -c 2:ESP \
+ -r=2:3 || { echo "Failed to modify partitions."; exit 1; }
# Write u-boot.itb to the first partition
echo "Writing u-boot.itb to first partition"
dd if="u-boot-sifive/usr/lib/u-boot/sifive_unmatched/u-boot.itb" of="$disk_image" bs=512 seek=2082 conv=notrunc || { echo "Failed to write u-boot.itb to disk image."; exit 1; }
diff --git a/tools/boot/noble/boot-riscv64 b/tools/boot/noble/boot-riscv64
index b52c4d03..cda2917d 100755
--- a/tools/boot/noble/boot-riscv64
+++ b/tools/boot/noble/boot-riscv64
@@ -26,33 +26,39 @@ if [ -e $CDDIR/casper/filesystem.kernel-generic-hwe ]; then
mv $CDDIR/casper/filesystem.initrd-generic-hwe $CDDIR/casper/hwe-initrd
fi
-# download, extract and include cd-boot-images
-mkdir cd-boot-images
-$BASEDIR/tools/apt-selection download cd-boot-images-riscv64
-dpkg --fsys-tarfile cd-boot-images-riscv64*_all.deb | tar xf - -C cd-boot-images
-# copy the bootable bits to the live-media rootfs
-cp -aT cd-boot-images/usr/share/cd-boot-images-riscv64/tree $CDDIR
-
-# to get the images bootable on SiFive unmatched out-of-the-box, let's also
-# pre-flash a matching u-boot there. Users can always override it in case they
-# want to use the image on a different platform
-# (this should probably be part of cd-boot-images-riscv64)
-$BASEDIR/tools/apt-selection download u-boot-sifive
-mkdir -p u-boot-sifive
-dpkg --fsys-tarfile u-boot-sifive*_riscv64.deb | tar xf - -C u-boot-sifive
-
-# we need to include the live-media's DTBs in the ESP
-# currently this is the best place to do it
+# download and extract bootloader packages
+download_and_extract_package grub-common grub
+download_and_extract_package grub-efi-riscv64-bin grub
+download_and_extract_package u-boot-sifive u-boot-sifive
+
+TREE_DIR=cd-boot-tree
+
+# add GRUB to tree
+copy_grub_common_files_to_boot_tree grub $TREE_DIR
+copy_unsigned_monolithic_grub_to_boot_tree grub riscv64 riscv64 $TREE_DIR
+
+# add DTBs to tree
unsquashfs -no-xattrs -d kernel-layer CD1/casper/ubuntu-server-minimal.ubuntu-server.installer.generic.squashfs usr/lib/firmware
-mcopy -s -i cd-boot-images/usr/share/cd-boot-images-riscv64/images/boot/grub/efi.img kernel-layer/usr/lib/firmware/*/device-tree/* ::/dtb/.
+mkdir -p $TREE_DIR/dtb
+cp -r kernel-layer/usr/lib/firmware/*/device-tree/* $TREE_DIR/dtb
rm -rf kernel-layer
+# copy tree contents to live-media rootfs
+cp -aT $TREE_DIR $CDDIR
+
+# create ESP image with GRUB and dtbs
+mkfs.msdos -n ESP -C -v efi.img 32768
+# add EFI files to ESP
+mcopy -s -i efi.img $TREE_DIR/EFI ::/.;
+# add DTBs to ESP
+mcopy -s -i efi.img $TREE_DIR/dtb ::/.;
+
# partion_offset is specified in 2 KiB units and contains a copy of
# the ISO metadata. It is followed by the rootfs and the ESP
cat <<EOF >> $N.mkisofs_opts
-joliet on
-compliance joliet_long_names
---append_partition 2 0xef cd-boot-images/usr/share/cd-boot-images-riscv64/images/boot/grub/efi.img
+--append_partition 2 0xef efi.img
-boot_image any partition_offset=10240
-boot_image any partition_cyl_align=all
-boot_image any efi_path=--interval:appended_partition_2:all::
diff --git a/tools/boot/noble/common.sh b/tools/boot/noble/common.sh
index c3c18e55..264334d5 100644
--- a/tools/boot/noble/common.sh
+++ b/tools/boot/noble/common.sh
@@ -14,3 +14,67 @@ default_kernel_params() {
}
HUMANPROJECT="$(echo "$CAPPROJECT" | sed 's/-/ /g')"
+
+# download and extract a package
+download_and_extract_package() {
+ local package_name=$1
+ local target_dir=$2
+
+ mkdir -p $target_dir
+ $BASEDIR/tools/apt-selection download $package_name
+ dpkg --fsys-tarfile $package_name*.deb | tar xf - -C $target_dir
+}
+
+# copy common files for GRUB (e.g. unicode font) to boot tree
+copy_grub_common_files_to_boot_tree() {
+ local grub_dir=$1
+ local boot_tree=$2
+
+ mkdir -p $boot_tree/boot/grub/fonts
+ cp $grub_dir/usr/share/grub/unicode.pf2 $boot_tree/boot/grub/fonts/unicode.pf2
+}
+
+# copy signed shim and GRUB to boot tree
+# NOTE: we are using the non-NX shim here for now, in future the default should be updated here
+copy_signed_shim_grub_to_boot_tree() {
+ local shim_dir=$1
+ local grub_dir=$2
+ local efi_suffix=$3
+ local grub_target=$4
+ local boot_tree=$5
+
+ mkdir -p $boot_tree/EFI/boot
+ cp $shim_dir/usr/lib/shim/shim$efi_suffix.efi.signed.latest $boot_tree/EFI/boot/boot$efi_suffix.efi
+ cp $shim_dir/usr/lib/shim/mm$efi_suffix.efi $boot_tree/EFI/boot/mm$efi_suffix.efi
+ cp $grub_dir/usr/lib/grub/$grub_target-efi-signed/gcd$efi_suffix.efi.signed $boot_tree/EFI/boot/grub$efi_suffix.efi
+
+ mkdir -p $boot_tree/boot/grub/$grub_target-efi
+ cp -r $grub_dir/usr/lib/grub/$grub_target-efi/*.mod $boot_tree/boot/grub/$grub_target-efi
+ cp -r $grub_dir/usr/lib/grub/$grub_target-efi/*.lst $boot_tree/boot/grub/$grub_target-efi
+}
+
+# copy unsigned monolithic GRUB to boot tree
+copy_unsigned_monolithic_grub_to_boot_tree() {
+ local grub_dir=$1
+ local efi_suffix=$2
+ local grub_target=$3
+ local boot_tree=$4
+
+ mkdir -p $boot_tree/EFI/boot
+ cp $grub_dir/usr/lib/grub/$grub_target-efi/monolithic/gcd$efi_suffix.efi $boot_tree/EFI/boot/boot$efi_suffix.efi
+
+ mkdir -p $boot_tree/boot/grub/$grub_target-efi
+ cp -r $grub_dir/usr/lib/grub/$grub_target-efi/*.mod $boot_tree/boot/grub/$grub_target-efi
+ cp -r $grub_dir/usr/lib/grub/$grub_target-efi/*.lst $boot_tree/boot/grub/$grub_target-efi
+}
+
+# create an ESP image for insertion into the El-Torito catalog
+# NOTE: this needs dosfstools and mtools installed
+create_eltorito_esp_image() {
+ local boot_tree=$1
+ local target_file=$2
+
+ mkfs.msdos -n ESP -C -v $target_file \
+ $(( $(du -s --apparent-size --block-size=1024 $boot_tree/EFI/ | cut -f 1 ) + 1024))
+ mcopy -s -i $target_file $boot_tree/EFI ::/.;
+}