michael.hudson@canonical.com ff3addb2f8
Extract packages to scratch dirs instead of boot tree subdirs
Package contents were being extracted into subdirectories of the boot
tree (grub_dir, shim_dir), which meant the boot tree contained both
the final boot files and the raw package extractions. Extract packages
into scratch directories instead, copying only the needed files into
the boot tree. This also removes the grub_dir/shim_dir instance
variables and the create_dirs overrides, and moves copy_grub_modules
to a standalone function in grub.py.
2026-02-19 13:17:35 +13:00

82 lines
2.6 KiB
Python

"""PowerPC 64-bit Little Endian architecture boot configuration."""
import pathlib
import shutil
from .grub import (
copy_grub_common_files_to_boot_tree,
copy_grub_modules,
GrubBootConfigurator,
)
from .base import default_kernel_params
class PPC64ELBootConfigurator(GrubBootConfigurator):
"""Boot setup for PowerPC 64-bit Little Endian architecture."""
def mkisofs_opts(self) -> list[str | pathlib.Path]:
"""Return mkisofs options for PPC64EL."""
# Add cd-boot-tree to the ISO
return [self.boot_tree]
def extract_files(self) -> None:
"""Download and extract bootloader packages for PPC64EL."""
self.logger.log("extracting PPC64EL boot files")
grub_pkg_dir = self.scratch.joinpath("grub-pkg")
# Download and extract bootloader packages
self.download_and_extract_package("grub2-common", grub_pkg_dir)
self.download_and_extract_package("grub-ieee1275-bin", grub_pkg_dir)
# Add common files for GRUB to tree
copy_grub_common_files_to_boot_tree(grub_pkg_dir, self.boot_tree)
# Add IEEE1275 ppc boot files
ppc_dir = self.boot_tree.joinpath("ppc")
ppc_dir.mkdir(parents=True, exist_ok=True)
grub_boot_dir = self.boot_tree.joinpath("boot", "grub", "powerpc-ieee1275")
grub_boot_dir.mkdir(parents=True, exist_ok=True)
src_grub_dir = grub_pkg_dir.joinpath("usr", "lib", "grub", "powerpc-ieee1275")
# Copy bootinfo.txt to ppc directory
shutil.copy(
src_grub_dir.joinpath("bootinfo.txt"), ppc_dir.joinpath("bootinfo.txt")
)
# Copy eltorito.elf to boot/grub as powerpc.elf
shutil.copy(
src_grub_dir.joinpath("eltorito.elf"),
self.boot_tree.joinpath("boot", "grub", "powerpc.elf"),
)
# Copy GRUB modules
copy_grub_modules(src_grub_dir, grub_boot_dir, ["*.mod", "*.lst"])
def generate_grub_config(self) -> None:
"""Generate grub.cfg for PPC64EL."""
kernel_params = default_kernel_params(self.project)
grub_cfg = self.boot_tree.joinpath("boot", "grub", "grub.cfg")
# Write common GRUB header
self.write_grub_header(grub_cfg)
# Main menu entry
with grub_cfg.open("a") as f:
f.write(
f"""menuentry "Try or Install {self.humanproject}" {{
\tset gfxpayload=keep
\tlinux\t/casper/vmlinux quiet {kernel_params}
\tinitrd\t/casper/initrd
}}
"""
)
# HWE kernel option if available
self.write_hwe_menu_entry(
grub_cfg, "vmlinux", kernel_params, extra_params="quiet "
)