michael.hudson@canonical.com edf0acbeac
Add Python boot configuration package
Add architecture-specific boot configurators that translate the
debian-cd boot shell scripts (boot-amd64, boot-arm64, boot-ppc64el,
boot-riscv64, boot-s390x) into Python.

The package uses a class hierarchy:
- BaseBootConfigurator: abstract base with common functionality
- GrubBootConfigurator: shared GRUB config generation
- UEFIBootConfigurator: UEFI-specific shim/ESP handling
- Architecture classes: AMD64, ARM64, PPC64EL, RISCV64, S390X

A factory function make_boot_configurator_for_arch() creates the
appropriate configurator for each architecture.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-17 10:47:13 +13:00

82 lines
2.5 KiB
Python

"""ARM 64-bit architecture boot configuration."""
import pathlib
from .uefi import UEFIBootConfigurator
from .base import default_kernel_params
class ARM64BootConfigurator(UEFIBootConfigurator):
"""Boot setup for ARM 64-bit architecture."""
efi_suffix = "aa64"
grub_target = "arm64"
arch = "arm64"
def mkisofs_opts(self) -> list[str | pathlib.Path]:
"""Return mkisofs options for ARM64."""
opts: list[str | pathlib.Path] = [
"-J",
"-joliet-long",
"-l",
"-c",
"boot/boot.cat",
]
# Add common UEFI options
opts.extend(self.get_uefi_mkisofs_opts())
# ARM64-specific: partition cylinder alignment
opts.extend(["-partition_cyl_align", "all"])
opts.append(self.boot_tree)
return opts
def extract_files(self) -> None:
"""Download and extract bootloader packages for ARM64."""
with self.logger.logged("extracting ARM64 boot files"):
self.extract_uefi_files()
def generate_grub_config(self) -> None:
"""Generate grub.cfg for ARM64."""
kernel_params = default_kernel_params(self.project)
grub_cfg = self.grub_dir.joinpath("grub.cfg")
# Write common GRUB header
self.write_grub_header(grub_cfg)
# ARM64-specific: Snapdragon workarounds
with grub_cfg.open("a") as f:
f.write(
"""set cmdline=
smbios --type 4 --get-string 5 --set proc_version
regexp "Snapdragon.*" "$proc_version"
if [ $? = 0 ]; then
# Work around Snapdragon X firmware bug. cutmem is not allowed in lockdown mode.
if [ $lockdown != "y" ]; then
cutmem 0x8800000000 0x8fffffffff
fi
# arm64.nopauth works around 8cx Gen 3 firmware bug
cmdline="clk_ignore_unused pd_ignore_unused arm64.nopauth"
fi
menuentry "Try or Install {self.humanproject}" {{
\tset gfxpayload=keep
\tlinux\t/casper/vmlinuz $cmdline {kernel_params} console=tty0
\tinitrd\t/casper/initrd
}}
"""
)
# HWE kernel option if available
self.write_hwe_menu_entry(
grub_cfg,
"vmlinuz",
f"{kernel_params} console=tty0",
extra_params="$cmdline ",
)
# Note: ARM64 HWE also includes $dtb in the original shell script,
# but it's not actually set anywhere in the grub.cfg, so we omit it here
# UEFI Entries (ARM64 is UEFI-only, no grub_platform check needed)
self.write_uefi_menu_entries(grub_cfg)