Skip to content

Commit

Permalink
feat: support systemd-boot bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
RadxaYuntian committed Nov 20, 2024
1 parent 738971f commit 9e1a30c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/libexec/rsdk/rsdk-build
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ generate_rootfs() {
fi

if [[ -n $RSDK_OPTION_SYSTEMD_BOOT ]]; then
JSONNET_ARGS+=("--tla-code" "sdboot=$RSDK_OPTION_SYSTEMD_BOOT")
JSONNET_ARGS+=("--ext-code" "sdboot=$RSDK_OPTION_SYSTEMD_BOOT")
fi

# Prepare keyrings
Expand Down
41 changes: 36 additions & 5 deletions src/share/rsdk/build/image.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,33 @@ else
echo "Copying content from rootfs..."
!mkdir -p "%(temp_dir)s/u-boot"
copy-out /usr/lib/u-boot/ "%(temp_dir)s"
copy-out /boot/extlinux/extlinux.conf "%(temp_dir)s/"
echo "Updating files with disk info..."
blkid /dev/sda1 | grep "^UUID:" | cut -d " " -f 2 | xargs printf "UUID=%%s /config vfat defaults,x-systemd.automount 0 2\n" > "%(temp_dir)s/fstab"
||| % {
copy-out /boot/extlinux/extlinux.conf "%(temp_dir)s"
||| % {
deploy_method: (if std.endsWith(rootfs, ".tar")
then
"tar-in %(rootfs)s / xattrs:true" % { rootfs: rootfs }
else
"copy-in %(rootfs)s/. /" % { rootfs: rootfs }
),
temp_dir: temp_dir,
}+
(if sdboot
then
|||
!mkdir -p "%(temp_dir)s/entries"
copy-out /boot/efi/loader/entries "%(temp_dir)s"
||| % {
temp_dir: temp_dir,
}
else
""
) +
|||
echo "Updating files with disk info..."
blkid /dev/sda1 | grep "^UUID:" | cut -d " " -f 2 | xargs printf "UUID=%%s /config vfat defaults,x-systemd.automount 0 2\n" > "%(temp_dir)s/fstab"
||| % {
temp_dir: temp_dir,
} +
(if efi
then
Expand All @@ -111,6 +126,22 @@ else
!sed -i "s/root=[^[:space:]]*/root=UUID=$(cat "%(temp_dir)s/rootfs_uuid")/g" "%(temp_dir)s/extlinux.conf"
copy-in "%(temp_dir)s/fstab" /etc/
copy-in "%(temp_dir)s/extlinux.conf" /boot/extlinux/
||| % {
temp_dir: temp_dir,
rootdev: rootdev(efi),
} +
(if sdboot
then
|||
!sed -i -E "s/(options[[:space:]]*)/\1root=UUID=$(cat "%(temp_dir)s/rootfs_uuid") /g" %(temp_dir)s/entries/*.conf
copy-in "%(temp_dir)s/entries" /boot/efi/loader/
||| % {
temp_dir: temp_dir,
}
else
""
) +
|||
echo "Shrinking rootfs..."
unmount-all
Expand Down
17 changes: 17 additions & 0 deletions src/share/rsdk/build/mod/packages/categories/core.libjsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ else

mkdir -p "$1/boot/efi"
mount -t tmpfs rsdk "$1/boot/efi"
|||,
(if suite == "bookworm" && std.extVar("sdboot")
then
|||
set -e

APT_CONFIG="$MMDEBSTRAP_APT_CONFIG" \
apt-get install -oDPkg::Chroot-Directory="$1" -y \
systemd-boot
chroot "$1" sh -c "SYSTEMD_RELAX_ESP_CHECKS=1 bootctl install --esp-path=/boot/efi/ --no-variables"
|||
else
"echo 'Skip systemd-boot installation.'"
),
|||
set -e
export SYSTEMD_RELAX_ESP_CHECKS=1

APT_CONFIG="$MMDEBSTRAP_APT_CONFIG" \
apt-get install -oDPkg::Chroot-Directory="$1" -y \
Expand Down
3 changes: 1 addition & 2 deletions src/share/rsdk/build/rootfs.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function(
vendor_packages = true,
linux_override = "",
u_boot_override = "",
sdboot = false,
) distro(suite, distro_mirror, architecture)
+ additional_repos(suite, radxa_mirror, radxa_repo_suffix, product, temp_dir)
+ packages(suite, edition, product, temp_dir, vendor_packages, linux_override, u_boot_override)
Expand Down Expand Up @@ -96,6 +95,6 @@ function(
vendor_packages: vendor_packages,
linux_override: linux_override,
u_boot_override: u_boot_override,
sdboot: sdboot,
sdboot: std.extVar("sdboot"),
},
}

0 comments on commit 9e1a30c

Please sign in to comment.