From e9004e6273208ef4bf50e1bf72efd405e02be7d3 Mon Sep 17 00:00:00 2001 From: Alexandre Ghiti Date: Tue, 12 Jul 2022 10:45:53 +0200 Subject: [PATCH 1/7] riscv: Add support to build LicheeRV Dock images The LicheeRV Dock board comes with only 512MB of DRAM so the only difference with a Nezha image is the fact that we have to remove cryptsetup-initramfs package which makes the initrd too big for the board to boot. Signed-off-by: Alexandre Ghiti --- live-build/auto/config | 4 +-- .../hooks.d/base/disk-image-uefi.binary | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/live-build/auto/config b/live-build/auto/config index 1fb84478..da2fdfbc 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -345,7 +345,7 @@ fi # one also must request disk1-img-xz image format if [ "$IMAGEFORMAT" = "ext4" ] && [ "$PROJECT" = "ubuntu-cpc" ]; then case $ARCH:$SUBARCH in - armhf:raspi2|riscv64:sifive_*|riscv64:nezha|riscv64:visionfive|*:generic) + armhf:raspi2|riscv64:sifive_*|riscv64:nezha|riscv64:visionfive|riscv64:licheerv|*:generic) IMAGE_HAS_HARDCODED_PASSWORD=1 if [ -z "${IMAGE_TARGETS:-}" ]; then export IMAGE_TARGETS="disk1-img-xz" @@ -939,7 +939,7 @@ case $PROJECT in riscv64*) if [ -n "$SUBARCH" ]; then case "${SUBARCH:-}" in - nezha) + nezha|licheerv) KERNEL_FLAVOURS=allwinner ;; visionfive) 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 aaf4e401..5a7a7fc5 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 @@ -73,8 +73,8 @@ create_partitions() { --typecode=15:ef00 \ --new=1:: \ --attributes=1:set:2 - elif [ "${SUBARCH:-}" = "nezha" ]; then - # Nezha D1 board + elif [ "${SUBARCH:-}" = "nezha" ] || [ "${SUBARCH:-}" = "licheerv" ]; then + # Nezha/LicheeRV D1 boards sgdisk "${disk_image}" \ --set-alignment=2 \ --new=13:256:25575 \ @@ -223,25 +223,35 @@ install_grub() { if [ -n "${SUBARCH:-}" ]; then # Per-device images case "${SUBARCH}" in - "nezha") - echo "Installing U-Boot for Nezha board" &1>2 + "nezha"|"licheerv") + echo "Installing U-Boot for ${SUBARCH} board" &1>2 # flash-kernel is needed to install the dtb for update-grub: it uses the # /proc/device-tree/model value to pick the correct dtb and as we are in a chroot, # the model value is wrong and we need to use /etc/flash-kernel/machine instead. # This explains why we install flash-kernel here. chroot mountpoint mkdir -p /etc/flash-kernel/ - chroot mountpoint bash -c "echo 'Allwinner D1 Nezha' > /etc/flash-kernel/machine" + if [ "$SUBARCH" = "nezha" ]; then + chroot mountpoint bash -c "echo 'Allwinner D1 Nezha' > /etc/flash-kernel/machine" + elif [ "$SUBARCH" = "licheerv" ]; then + chroot mountpoint bash -c "echo 'Sipeed Lichee RV Dock' > /etc/flash-kernel/machine" + # cryptsetup-initramfs is a large contributor of the initrd size: we have to + # remove it for the LicheeRV board, otherwise it fails to boot. cryptsetup-initramfs + # needs to embed plymouth (and then the drm/gpu stuff) for interacting with the user + # to decrypt the rootfs (passphrase key). + chroot mountpoint bash -c "apt remove -qqy cryptsetup-initramfs" + fi chroot mountpoint bash -c 'FK_FORCE=yes apt-get install -qqy grub-efi-riscv64 flash-kernel' efi_target=riscv64-efi + # nezha-boot0 is actually compatible with the LicheeRV boards (and probably other D1-based boards) chroot mountpoint apt-get install -qqy nezha-boot0 # FSBL, which gets U-Boot SPL loader1="/dev/mapper${loop_device///dev/}p13" dd if=mountpoint/usr/lib/u-boot/nezha/boot0_sdcard_sun20iw1p1.bin of=$loader1 # The real U-Boot - chroot mountpoint apt-get install -qqy u-boot-nezha + chroot mountpoint apt-get install -qqy u-boot-${SUBARCH} loader2="/dev/mapper${loop_device///dev/}p14" - dd if=mountpoint/usr/lib/u-boot/nezha/u-boot.toc1 of=$loader2 + dd if=mountpoint/usr/lib/u-boot/${SUBARCH}/u-boot.toc1 of=$loader2 # Provide end-user modifyable CIDATA cidata_dev="/dev/mapper${loop_device///dev/}p12" setup_cidata "${cidata_dev}" @@ -250,7 +260,7 @@ install_grub() { # without a cloud datasource. setup_cinocloud mountpoint - # u-boot-nezha will boot using UEFI if it does not find + # u-boot-${SUBARCH} will boot using UEFI if it does not find # any extlinux.conf or boot.scr: but flash-kernel will # install a boot.scr if it believes it did not boot in # EFI mode, so make sure we don't leave a boot.scr @@ -336,7 +346,7 @@ EOF chroot mountpoint u-boot-update fi - if [ "${SUBARCH:-}" != "visionfive" ] && [ "${SUBARCH:-}" != "nezha" ]; then + if [ "${SUBARCH:-}" != "visionfive" ] && [ "${SUBARCH:-}" != "nezha" ] && [ "${SUBARCH:-}" != "licheerv" ]; then ## TODO remove below once we have grub-efi-riscv64 for the platforms rm mountpoint/tmp/device.map umount mountpoint/boot/efi From 0940dd3cd8bf01f7e7837d44453d51692301ac7b Mon Sep 17 00:00:00 2001 From: Alexandre Ghiti Date: Tue, 30 Aug 2022 14:59:28 +0200 Subject: [PATCH 2/7] riscv: Add support to build Microchip Icicle Kit image Signed-off-by: Alexandre Ghiti Replace FK_FORCE_CONTAINER by FK_FORCE (LP: #1989194) Signed-off-by: Heinrich Schuchardt --- live-build/auto/config | 2 +- .../hooks.d/base/disk-image-uefi.binary | 45 ++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/live-build/auto/config b/live-build/auto/config index da2fdfbc..832b8408 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -345,7 +345,7 @@ fi # one also must request disk1-img-xz image format if [ "$IMAGEFORMAT" = "ext4" ] && [ "$PROJECT" = "ubuntu-cpc" ]; then case $ARCH:$SUBARCH in - armhf:raspi2|riscv64:sifive_*|riscv64:nezha|riscv64:visionfive|riscv64:licheerv|*:generic) + armhf:raspi2|riscv64:sifive_*|riscv64:nezha|riscv64:visionfive|riscv64:licheerv|riscv64:icicle|*:generic) IMAGE_HAS_HARDCODED_PASSWORD=1 if [ -z "${IMAGE_TARGETS:-}" ]; then export IMAGE_TARGETS="disk1-img-xz" 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 5a7a7fc5..6dd27c48 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 @@ -93,6 +93,20 @@ create_partitions() { --change-name=12:CIDATA \ --new=1:: \ --attributes=1:set:2 + elif [ "${SUBARCH:-}" = "icicle" ]; then + # Microchip Icicle Kit + sgdisk "${disk_image}" \ + --set-alignment=2 \ + --new=13:256:25575 \ + --change-name=13:loader \ + --typecode=13:ef02 \ + --new=15::+106M \ + --typecode=15:ef00 \ + --change-name=15:ESP \ + --new=12::+4M \ + --change-name=12:CIDATA \ + --new=1:: \ + --attributes=1:set:2 elif [ "${SUBARCH:-}" = "visionfive" ]; then # VisionFive sgdisk "${disk_image}" \ @@ -223,6 +237,35 @@ install_grub() { if [ -n "${SUBARCH:-}" ]; then # Per-device images case "${SUBARCH}" in + "icicle") + echo "Installing GRUB for ${SUBARCH} board" &1>2 + # flash-kernel is needed to install the dtb for update-grub: it uses the + # /proc/device-tree/model value to pick the correct dtb and as we are in a chroot, + # the model value is wrong and we need to use /etc/flash-kernel/machine instead. + # This explains why we install flash-kernel here. + chroot mountpoint mkdir -p /etc/flash-kernel/ + chroot mountpoint bash -c "echo 'Microchip PolarFire-SoC Icicle Kit' > /etc/flash-kernel/machine" + chroot mountpoint bash -c 'FK_FORCE=yes apt-get install -qqy grub-efi-riscv64 flash-kernel' + efi_target=riscv64-efi + # The real U-Boot + chroot mountpoint apt-get install -qqy u-boot-microchip + loader="/dev/mapper${loop_device///dev/}p13" + dd if=mountpoint/usr/lib/u-boot/microchip_icicle/u-boot.payload of=$loader + # Provide end-user modifyable CIDATA + cidata_dev="/dev/mapper${loop_device///dev/}p12" + setup_cidata "${cidata_dev}" + # Provide stock nocloud datasource + # Allow interactive login on baremetal board, + # without a cloud datasource. + setup_cinocloud mountpoint + + # u-boot-microchip will boot using UEFI if it does not find + # any extlinux.conf or boot.scr: but flash-kernel will + # install a boot.scr if it believes it did not boot in + # EFI mode, so make sure we don't leave a boot.scr + # behind. + chroot mountpoint rm -f /boot/boot.scr + ;; "nezha"|"licheerv") echo "Installing U-Boot for ${SUBARCH} board" &1>2 # flash-kernel is needed to install the dtb for update-grub: it uses the @@ -346,7 +389,7 @@ EOF chroot mountpoint u-boot-update fi - if [ "${SUBARCH:-}" != "visionfive" ] && [ "${SUBARCH:-}" != "nezha" ] && [ "${SUBARCH:-}" != "licheerv" ]; then + if [ "${SUBARCH:-}" != "visionfive" ] && [ "${SUBARCH:-}" != "nezha" ] && [ "${SUBARCH:-}" != "licheerv" ] && [ "${SUBARCH:-}" != "icicle" ]; then ## TODO remove below once we have grub-efi-riscv64 for the platforms rm mountpoint/tmp/device.map umount mountpoint/boot/efi From 8ba2493a80e5c2169de160af098faf384e63d797 Mon Sep 17 00:00:00 2001 From: Alexandre Ghiti Date: Thu, 8 Sep 2022 16:16:49 +0200 Subject: [PATCH 3/7] riscv: LicheeRV must use u-boot-nezha package Signed-off-by: Alexandre Ghiti --- live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 6dd27c48..bc6749ff 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 @@ -292,7 +292,8 @@ install_grub() { loader1="/dev/mapper${loop_device///dev/}p13" dd if=mountpoint/usr/lib/u-boot/nezha/boot0_sdcard_sun20iw1p1.bin of=$loader1 # The real U-Boot - chroot mountpoint apt-get install -qqy u-boot-${SUBARCH} + # u-boot-nezha actually contains both the LicheeRV and the Nezha boards support + chroot mountpoint apt-get install -qqy u-boot-nezha loader2="/dev/mapper${loop_device///dev/}p14" dd if=mountpoint/usr/lib/u-boot/${SUBARCH}/u-boot.toc1 of=$loader2 # Provide end-user modifyable CIDATA From c4dc7bce4c94e354ceed31e5f0765ff5668d4168 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 13 Oct 2022 04:06:46 +0200 Subject: [PATCH 4/7] riscv: remove invalid redirections Remove redirections of type command &1>2 Executing the command in the background and creating and empty file '2' was never intended. As the messages are information only redirecting to stderr would not make sense either. Signed-off-by: Heinrich Schuchardt --- live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 bc6749ff..5ff8fa33 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 @@ -238,7 +238,7 @@ install_grub() { # Per-device images case "${SUBARCH}" in "icicle") - echo "Installing GRUB for ${SUBARCH} board" &1>2 + echo "Installing GRUB for ${SUBARCH} board" # flash-kernel is needed to install the dtb for update-grub: it uses the # /proc/device-tree/model value to pick the correct dtb and as we are in a chroot, # the model value is wrong and we need to use /etc/flash-kernel/machine instead. @@ -267,7 +267,7 @@ install_grub() { chroot mountpoint rm -f /boot/boot.scr ;; "nezha"|"licheerv") - echo "Installing U-Boot for ${SUBARCH} board" &1>2 + echo "Installing U-Boot for ${SUBARCH} board" # flash-kernel is needed to install the dtb for update-grub: it uses the # /proc/device-tree/model value to pick the correct dtb and as we are in a chroot, # the model value is wrong and we need to use /etc/flash-kernel/machine instead. @@ -312,7 +312,7 @@ install_grub() { chroot mountpoint rm -f /boot/boot.scr ;; "visionfive") - echo "Installing GRUB for VisionFive board" &1>2 + echo "Installing GRUB for VisionFive board" # flash-kernel is needed to install the dtb for update-grub: it uses the # /proc/device-tree/model value to pick the correct dtb and as we are in a chroot, # the model value is wrong and we need to use /etc/flash-kernel/machine instead. From 0016cada169e0f88b4912bd2bf3e788ae47a8b2f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Thu, 13 Oct 2022 04:13:11 +0200 Subject: [PATCH 5/7] riscv: reduce initrd size for Nezha and LicheeRV boards The Nezha and the LicheeRV boards do not have enough memory for an initrd with most modules. Therefore the number of included modules has to be reduced. Create file /etc/initramfs-tools/conf.d/modules_list.conf to set MODULES=list. Signed-off-by: Heinrich Schuchardt --- live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary | 5 +++++ .../hooks.d/base/initramfs-tools/modules_list.conf | 6 ++++++ 2 files changed, 11 insertions(+) create mode 100644 live-build/ubuntu-cpc/hooks.d/base/initramfs-tools/modules_list.conf 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 5ff8fa33..6ba378ea 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 @@ -267,6 +267,11 @@ install_grub() { chroot mountpoint rm -f /boot/boot.scr ;; "nezha"|"licheerv") + local my_d=$(dirname $(readlink -f ${0})) + echo "Reducing initramfs size for ${SUBARCH} board" + mkdir -p mountpoint/etc/initramfs-tools/conf.d/ + cp ${my_d}/initramfs-tools/modules_list.conf mountpoint/etc/initramfs-tools/conf.d/ + chroot mountpoint update-initramfs -c -v -k all echo "Installing U-Boot for ${SUBARCH} board" # flash-kernel is needed to install the dtb for update-grub: it uses the # /proc/device-tree/model value to pick the correct dtb and as we are in a chroot, diff --git a/live-build/ubuntu-cpc/hooks.d/base/initramfs-tools/modules_list.conf b/live-build/ubuntu-cpc/hooks.d/base/initramfs-tools/modules_list.conf new file mode 100644 index 00000000..99cb474f --- /dev/null +++ b/live-build/ubuntu-cpc/hooks.d/base/initramfs-tools/modules_list.conf @@ -0,0 +1,6 @@ +# The Nezha and the LicheeRV boards do not have enough memory for an initrd with +# most modules. Therefore the number of included modules has to be reduced. +# +# If further modules are needed, add them to /etc/initramfs-tools/modules. + +MODULES=list From 0fa7ab23ed0c8fbf46f64541243903ec520e91d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20=27sil2100=27=20Zemczak?= Date: Fri, 14 Oct 2022 10:49:25 +0200 Subject: [PATCH 6/7] Add an additional subdir. --- live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary | 2 +- .../base/{ => riscv64}/initramfs-tools/modules_list.conf | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename live-build/ubuntu-cpc/hooks.d/base/{ => riscv64}/initramfs-tools/modules_list.conf (100%) 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 6ba378ea..0610e413 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 @@ -270,7 +270,7 @@ install_grub() { local my_d=$(dirname $(readlink -f ${0})) echo "Reducing initramfs size for ${SUBARCH} board" mkdir -p mountpoint/etc/initramfs-tools/conf.d/ - cp ${my_d}/initramfs-tools/modules_list.conf mountpoint/etc/initramfs-tools/conf.d/ + cp ${my_d}/riscv64/initramfs-tools/modules_list.conf mountpoint/etc/initramfs-tools/conf.d/ chroot mountpoint update-initramfs -c -v -k all echo "Installing U-Boot for ${SUBARCH} board" # flash-kernel is needed to install the dtb for update-grub: it uses the diff --git a/live-build/ubuntu-cpc/hooks.d/base/initramfs-tools/modules_list.conf b/live-build/ubuntu-cpc/hooks.d/base/riscv64/initramfs-tools/modules_list.conf similarity index 100% rename from live-build/ubuntu-cpc/hooks.d/base/initramfs-tools/modules_list.conf rename to live-build/ubuntu-cpc/hooks.d/base/riscv64/initramfs-tools/modules_list.conf From 591b0a343227f6da84764b99480fab71dd20b317 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Mon, 17 Oct 2022 13:57:01 +0200 Subject: [PATCH 7/7] riscv64: use efi=debug earlycon RISC-V boards tend to boot slowly. We should provide progress information when booting. Use 'efi=debug earlycon' on the Linux command line via new file /etc/default/grub.d/cmdline.cfg. Signed-off-by: Heinrich Schuchardt --- live-build/ubuntu-cpc/hooks.d/base/disk-image-uefi.binary | 5 ++++- live-build/ubuntu-cpc/hooks.d/base/riscv64/grub/cmdline.cfg | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 live-build/ubuntu-cpc/hooks.d/base/riscv64/grub/cmdline.cfg 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 0610e413..df8cb4af 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 @@ -236,6 +236,10 @@ install_grub() { # TODO grub-efi-riscv64 exists, but is not used by all the images yet if [ -n "${SUBARCH:-}" ]; then # Per-device images + local my_d=$(dirname $(readlink -f ${0})) + echo "Adjusting GRUB defaults for ${ARCH}" + mkdir -p mountpoint/etc/default/grub.d/ + cp ${my_d}/riscv64/grub/cmdline.cfg mountpoint/etc/default/grub.d/ case "${SUBARCH}" in "icicle") echo "Installing GRUB for ${SUBARCH} board" @@ -267,7 +271,6 @@ install_grub() { chroot mountpoint rm -f /boot/boot.scr ;; "nezha"|"licheerv") - local my_d=$(dirname $(readlink -f ${0})) echo "Reducing initramfs size for ${SUBARCH} board" mkdir -p mountpoint/etc/initramfs-tools/conf.d/ cp ${my_d}/riscv64/initramfs-tools/modules_list.conf mountpoint/etc/initramfs-tools/conf.d/ diff --git a/live-build/ubuntu-cpc/hooks.d/base/riscv64/grub/cmdline.cfg b/live-build/ubuntu-cpc/hooks.d/base/riscv64/grub/cmdline.cfg new file mode 100644 index 00000000..c8cf57d0 --- /dev/null +++ b/live-build/ubuntu-cpc/hooks.d/base/riscv64/grub/cmdline.cfg @@ -0,0 +1,4 @@ +# Booting on many riscv64 systems is slow. Let the user view progress. +# For minimum output use +# GRUB_CMDLINE_LINUX_DEFAULT="quiet" +GRUB_CMDLINE_LINUX_DEFAULT="efi=debug earlycon"