From 06bdbdba69e073afb21b05f4fb2f3d344a85fa41 Mon Sep 17 00:00:00 2001 From: Aelin Date: Sat, 11 Jul 2026 19:09:10 +0200 Subject: [PATCH] temp/powervm-boot: new aport This is a bootloader for Open Firmware PowerPC systems that we will use to replace grub-ieee1275 in device-generic-ppc64le. Due to its use of RUSTC_BOOTSTRAP, this APKBUILD cannot go to Alpine at the moment, but once the Rust targets are added upstream, this can be moved to aports. Part-of: --- temp/powervm-boot/0001-Fix-compilation.patch | 13 ++++ .../0002-Fix-loader-directory-path.patch | 56 +++++++++++++++++ .../0003-Raise-kernel-size-limit.patch | 13 ++++ temp/powervm-boot/APKBUILD | 63 +++++++++++++++++++ temp/powervm-boot/powervm-boot.post-upgrade | 46 ++++++++++++++ 5 files changed, 191 insertions(+) create mode 100644 temp/powervm-boot/0001-Fix-compilation.patch create mode 100644 temp/powervm-boot/0002-Fix-loader-directory-path.patch create mode 100644 temp/powervm-boot/0003-Raise-kernel-size-limit.patch create mode 100644 temp/powervm-boot/APKBUILD create mode 100644 temp/powervm-boot/powervm-boot.post-upgrade diff --git a/temp/powervm-boot/0001-Fix-compilation.patch b/temp/powervm-boot/0001-Fix-compilation.patch new file mode 100644 index 000000000..560f16bfd --- /dev/null +++ b/temp/powervm-boot/0001-Fix-compilation.patch @@ -0,0 +1,13 @@ +diff --git a/src/fs.rs b/src/fs.rs +index 605327d..e5290ea 100644 +--- a/src/fs.rs ++++ b/src/fs.rs +@@ -34,7 +34,7 @@ impl BootFilesystem for FatPartition { + continue; + } + let key = String::from(&name[..name.len() - 5]); +- let mut reader = match entries_dir.open_file(name) { ++ let mut reader = match entries_dir.open_file(&name) { + Ok(r) => r, + Err(_) => continue, + }; diff --git a/temp/powervm-boot/0002-Fix-loader-directory-path.patch b/temp/powervm-boot/0002-Fix-loader-directory-path.patch new file mode 100644 index 000000000..20f785377 --- /dev/null +++ b/temp/powervm-boot/0002-Fix-loader-directory-path.patch @@ -0,0 +1,56 @@ +diff --git a/src/fs.rs b/src/fs.rs +index e5290ea..af190be 100644 +--- a/src/fs.rs ++++ b/src/fs.rs +@@ -4,7 +4,7 @@ use alloc::vec::Vec; + use crate::disk::{PROMDisk, Partition}; + + pub trait BootFilesystem { +- /// List BLS entries from loaders/entries/*.conf. ++ /// List BLS entries from loader/entries/*.conf. + /// Returns (filename_stem, file_content) pairs. + fn list_bls_entries(&self) -> Result, &'static str>; + +@@ -17,8 +17,8 @@ type FatPartition = hadris_fat::FatFs>; + impl BootFilesystem for FatPartition { + fn list_bls_entries(&self) -> Result, &'static str> { + let entries_dir = self +- .open_dir_path("loaders/entries") +- .map_err(|_| "failed to open loaders/entries")?; ++ .open_dir_path("loader/entries") ++ .map_err(|_| "failed to open loader/entries")?; + + let mut result = Vec::new(); + for entry in entries_dir.entries() { +@@ -75,7 +75,7 @@ impl BootFilesystem for IsoPartition { + fn list_bls_entries(&self) -> Result, &'static str> { + let root = self.root_dir(); + +- let loaders_dir_ref = { ++ let loader_dir_ref = { + let mut found = None; + for entry in root.iter(self).entries() { + let entry = match entry { +@@ -86,18 +86,18 @@ impl BootFilesystem for IsoPartition { + continue; + } + let name = entry.display_name(); +- if name.eq_ignore_ascii_case("loaders") { ++ if name.eq_ignore_ascii_case("loader") { + found = Some(entry.as_dir_ref(self).map_err(|_| "as_dir_ref failed")?); + break; + } + } +- found.ok_or("loaders directory not found")? ++ found.ok_or("loader directory not found")? + }; + + let entries_dir_ref = { +- let loaders_dir = self.open_dir(loaders_dir_ref); ++ let loader_dir = self.open_dir(loader_dir_ref); + let mut found = None; +- for entry in loaders_dir.entries() { ++ for entry in loader_dir.entries() { + let entry = match entry { + Ok(e) => e, + Err(_) => continue, diff --git a/temp/powervm-boot/0003-Raise-kernel-size-limit.patch b/temp/powervm-boot/0003-Raise-kernel-size-limit.patch new file mode 100644 index 000000000..2a05199ee --- /dev/null +++ b/temp/powervm-boot/0003-Raise-kernel-size-limit.patch @@ -0,0 +1,13 @@ +diff --git a/src/main.rs b/src/main.rs +index df41a25..fd2857b 100644 +--- a/src/main.rs ++++ b/src/main.rs +@@ -630,7 +630,7 @@ fn load_kernel_and_prepare_jump( + } + }; + +- if kernel_buf.is_empty() || kernel_buf.len() > 64 * 1024 * 1024 { ++ if kernel_buf.is_empty() || kernel_buf.len() > 512 * 1024 * 1024 { + prom.write_line("invalid kernel size"); + prom.power_off(); + } diff --git a/temp/powervm-boot/APKBUILD b/temp/powervm-boot/APKBUILD new file mode 100644 index 000000000..fb6a93678 --- /dev/null +++ b/temp/powervm-boot/APKBUILD @@ -0,0 +1,63 @@ +# This package can be upstreamed to Alpine once Rust MCP 988 is implemented: +# github.com/rust-lang/rust/issues/158199 +maintainer="Aelin " +pkgname=powervm-boot +pkgver=0.5.0_git20260318 +pkgrel=0 +_commit="38487a6357efb4e1dbc029033693a10b9e6c692d" +pkgdesc="Bootloader for IBM POWER systems that implements BLS on top of Open Firmware" +url="https://gitlab.com/aruiz/powerpc-bootloader" +arch="ppc64le" +license="MPL-2.0" +makedepends=" + cargo-auditable + rust-src + " +install="$pkgname.post-upgrade" +source="$pkgname-$pkgver.tar.gz::https://gitlab.com/aruiz/powerpc-bootloader/-/archive/$_commit/powerpc-bootloader/archive/$_commit.tar.gz + 0001-Fix-compilation.patch + 0002-Fix-loader-directory-path.patch + 0003-Raise-kernel-size-limit.patch + " +# !check: Test suite is somewhat specific to Fedora +# !strip: Foreign architecture +# net: cargo +options="!check !strip net pmb:cross-native" +builddir="$srcdir/powerpc-bootloader-$_commit" + +prepare() { + default_prepare + + cargo fetch --target powerpc-unknown-linux-gnu +} + +build() { + # FIXME: We need to cross compile to 32-bit because that's what Open Firmware + # requires. There is no bare metal 32-bit PowerPC target in Rust (yet!), there + # is however an accepted MCP to add one. Until that is in the Alpine Rust + # toolchain, we will have to cheat and use RUSTC_BOOTSTRAP=1 in combination with + # -Zbuild-std to be able to compile for a 32-bit target. + # This is also why this package is not in aports yet. + # + # The RUSTFLAGS mess is ugly because for some reason, abuild completely screws + # up the quoting!? + RUSTC_BOOTSTRAP=1 \ + RUSTFLAGS="-Clinker=powerpc64le-alpine-linux-musl-gcc -Clink-arg=-nostdlib -Clink-arg=-ffreestanding -Clink-arg=-fPIC -Clink-arg=-Ttext=100000 -Clink-arg=-mbig-endian -Clink-arg=-Wl,--build-id=none -Ctarget-feature=+crt-static" \ + cargo auditable build \ + --release \ + --target powerpc-unknown-linux-gnu \ + -Zbuild-std=core,alloc,compiler_builtins \ + -Zbuild-std-features=compiler-builtins-mem +} + +package() { + install -Dm644 target/powerpc-unknown-linux-gnu/release/powervm-boot \ + -t "$pkgdir"/usr/lib/powervm-boot/ +} + +sha512sums=" +1a332b3e79ccca5e2f284ede9717ca562b0adde0b195813b8b0b2f695c3c811ea2e2579fa1de8af2b16effff2827e49e849b1868f140ff18bc38aa2a385c0b91 powervm-boot-0.5.0_git20260318.tar.gz +09a8ebe2bf932e3f5ca6ea7ee9f587b6e0f2f2f917703d47f14cd2d321fbb5b307fc661f73c2afc90d5ec2aef7d9e2a49de0aa7ef872e46091d0c144870e11ee 0001-Fix-compilation.patch +a2a6fd1a834c22b310a52812342bc5382b9139f0697a001ffaa11f5fb6b2eceb98eb208f47eeecbcb7325ca174f2b6a6e36bb9205a91a6d67ceba6d4c43eb792 0002-Fix-loader-directory-path.patch +5a4542f98063c9b046dacd6629f4167b362bb97008b9aecc869ce2bea16948ed465171efc556a4396884a1d4e20091e66b2a69e3bf8b46b54652a33a429b1ee8 0003-Raise-kernel-size-limit.patch +" diff --git a/temp/powervm-boot/powervm-boot.post-upgrade b/temp/powervm-boot/powervm-boot.post-upgrade new file mode 100644 index 000000000..3a71ab324 --- /dev/null +++ b/temp/powervm-boot/powervm-boot.post-upgrade @@ -0,0 +1,46 @@ +#!/bin/sh + +if [ ! -f /usr/lib/powervm-boot/powervm-boot ]; then + echo "powervm-boot not found" + exit +fi + +PREP_GUID="9e1a2d38-c612-4316-aa26-8b49521e5a8b" +PREP_TYPE=0x41 + +lsblk -nrpo NAME,TYPE,PARTTYPE | +while read -r dev type parttype; do + [ "$type" = "part" ] || continue + + case "$(printf '%s' "$parttype" | tr '[:upper:]' '[:lower:]')" in + "$PREP_GUID"|"$PREP_TYPE") + echo "Found PReP boot partition $dev" + + magic=$(dd if="$dev" bs=1 count=4 2>/dev/null | od -An -tx1 | tr -d ' \n') + + if [ "$magic" != "7f454c46" ]; then + echo "Not an ELF file" + continue + fi + + class=$(dd if="$dev" bs=1 skip=4 count=1 2>/dev/null | od -An -tu1 | tr -d ' ') + + if [ "$class" != "1" ]; then + echo "Not ELF32" + continue + fi + + machine=$(dd if="$dev" bs=1 skip=18 count=2 2>/dev/null | od -An -tx1 | tr -d ' \n') + + if [ "$machine" != "0014" ]; then + echo "Not PowerPC ELF" + continue + fi + + echo "PReP boot partition with bootloader installed detected, flashing powervm-boot" + + dd if=/usr/lib/powervm-boot/powervm-boot of="$dev" bs=512 conv=notrunc + sync + ;; + esac +done