Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aarch64 support: efi stub and devicetree selection #722

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 40 additions & 4 deletions bin/generate-zbm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use File::stat;
use File::Path qw(make_path remove_tree);
use File::Glob qw(:globally :nocase);
use Sort::Versions;
use Config;
use bigint qw(hex);

use Pod::Usage qw(pod2usage);
Expand Down Expand Up @@ -684,10 +685,12 @@ sub createUEFIBundle {
}
} else {

# For now, default stub locations are x86_64 only
my @uefi_stub_defaults = qw(
/usr/lib/systemd/boot/efi/linuxx64.efi.stub
);
my @uefi_stub_defaults;
if ( $Config{archname} =~ m/x86_64/ ) {
push( @uefi_stub_defaults, '/usr/lib/systemd/boot/efi/linuxx64.efi.stub' );
} elsif ( $Config{archname} =~ m/aarch64/ ) {
push( @uefi_stub_defaults, '/usr/lib/systemd/boot/efi/linuxaa64.efi.stub' );
}

foreach my $stubloc (@uefi_stub_defaults) {
if ( -f $stubloc ) {
Expand Down Expand Up @@ -771,6 +774,39 @@ sub createUEFIBundle {
$uki_offset = addBundleSection( \@cmd, ".splash", $config{EFI}{SplashImage}, $uki_offset, $uki_alignment );
}

if ( has_value $config{EFI}{DeviceTree} ) {
my $dtb_try;

if ( $config{EFI}{DeviceTree} =~ m,^/, ) {
if ( $config{EFI}{DeviceTree} =~ m/\Q%{kernel}/ ) {

# Possibly a templated file path
$dtb_try = $config{EFI}{DeviceTree};
$dtb_try =~ s/\Q%{kernel}/$runConf{kernel_version}/;
} else {

# Possibly an absolute path to a file
$dtb_try = $config{EFI}{DeviceTree};
}
} else {

# Possibly a partial path
$dtb_try = sprintf( "/boot/dtbs/dtbs-%s/%s", $runConf{kernel_version}, $config{EFI}{DeviceTree} );
}

if ( has_value $dtb_try && -f $dtb_try ) {
$uki_offset = addBundleSection( \@cmd, ".dtb", $dtb_try, $uki_offset, $uki_alignment );
} else {
if ( has_value $dtb_try ) {
printf "EFI.DeviceTree key set to '%s', file not found at '%s'\n", $config{EFI}{DeviceTree}, $dtb_try;
exit 1;
} else {
printf "EFI.DeviceTree key set to '%s', file not found\n", $config{EFI}{DeviceTree};
exit 1;
}
}
Comment on lines +797 to +807
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( has_value $dtb_try && -f $dtb_try ) {
$uki_offset = addBundleSection( \@cmd, ".dtb", $dtb_try, $uki_offset, $uki_alignment );
} else {
if ( has_value $dtb_try ) {
printf "EFI.DeviceTree key set to '%s', file not found at '%s'\n", $config{EFI}{DeviceTree}, $dtb_try;
exit 1;
} else {
printf "EFI.DeviceTree key set to '%s', file not found\n", $config{EFI}{DeviceTree};
exit 1;
}
}
if ( has_value $dtb_try) {
if ( -f $dtb_try ) {
$uki_offset = addBundleSection( \@cmd, ".dtb", $dtb_try, $uki_offset, $uki_alignment );
} else {
printf "EFI.DeviceTree key set to '%s', file not found at '%s'\n", $config{EFI}{DeviceTree}, $dtb_try;
exit 1;
}
} else {
printf "EFI.DeviceTree key set to '%s', but no DeviceTree file could be found\n", $config{EFI}{DeviceTree};
exit 1;
}

}

$uki_offset = addBundleSection( \@cmd, ".initrd", $initramfs, $uki_offset, $uki_alignment );

# Add the kernel last, so that it can decompress without overflowing other sections
Expand Down
33 changes: 33 additions & 0 deletions zfsbootmenu/lib/zfsbootmenu-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ mount_zfs() {

kexec_kernel() {
local selected fs kernel initramfs output hook_envs
local dtb_prop dtb_try dtb_file kver

selected="${1}"
if [ -z "${selected}" ]; then
Expand Down Expand Up @@ -390,8 +391,39 @@ kexec_kernel() {
cli_args="$( load_be_cmdline "${fs}" )"
root_prefix="$( find_root_prefix "${fs}" "${mnt}" )"

dtb_prop="$( zfs get -H -o value org.zfsbootmenu:devicetree "${fs}" 2>/dev/null )"
if [ -n "${dtb_prop}" ] && [ "${dtb_prop}" != '-' ] ; then
zdebug "devicetree property set to '${dtb_prop}'"

# this is cursed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really cursed, it's how we map kernels to initramfs images as well.

kver="${kernel#"${kernel%%-*}"-}"

if [ "${dtb_prop:0:1}" = "/" ] ; then
if [[ "${dtb_prop}" =~ %\{kernel\} ]] ; then
# possibly a templated absolute path to a file
dtb_try="${mnt}${dtb_prop//%\{kernel\}/${kver}}"
else
# possibly an absolute path to a file
dtb_try="${mnt}${dtb_prop}"
fi
else
# possibly a suffix to a well-known path
dtb_try="${mnt}/boot/dtbs/dtbs-${kver}/${dtb_prop}"
fi

if [ -n "${dtb_try}" ] && [ -f "${dtb_try}" ] ; then
zdebug "devicetree file exists: '${dtb_try}'"
dtb_file="${dtb_try}"
else
zdebug "devicetree file missing: '${dtb_try}'"
fi
else
zdebug "no devicetree property set"
fi

if ! output="$( kexec -a -l "${mnt}${kernel}" \
--initrd="${mnt}${initramfs}" \
${dtb_file:+--dtb="${dtb_file}"} \
--command-line="${root_prefix}${fs} ${cli_args}" 2>&1 )"
then
zerror "unable to load ${mnt}${kernel} and ${mnt}${initramfs} into memory"
Expand Down Expand Up @@ -2019,6 +2051,7 @@ zreport() {
read -r INITRD_VERSION < /VERSION
INITRD_VERSION="mkinitcpio ${INITRD_VERSION}"
elif [ -f /etc/initrd-release ] ; then
# shellcheck disable=SC1091
source /etc/initrd-release
[ -n "${DRACUT_VERSION}" ] && INITRD_VERSION="Dracut ${DRACUT_VERSION}"
fi
Expand Down