Skip to content

Commit

Permalink
bios+ppc64le: Support being passed a whole device
Browse files Browse the repository at this point in the history
And automatically find the PReP partition.

Closes: coreos#837
Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Feb 11, 2025
1 parent b13dc60 commit 9175a0a
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 13 deletions.
116 changes: 109 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ path = "src/main.rs"
[dependencies]
anyhow = "1.0"
bincode = "1.3.2"
bootc-blockdev = { git = "https://github.com/containers/bootc", rev = "9a586935e3c88a3802ea4308b0ec364b6448c59e", package = "blockdev" }
bootc-utils = { git = "https://github.com/containers/bootc", rev = "9a586935e3c88a3802ea4308b0ec364b6448c59e" }
bootc-blockdev = { git = "https://github.com/containers/bootc", rev = "69264e0836c07d2203b29b780cdb8c6dcddfffbc" }
bootc-utils = { git = "https://github.com/containers/bootc", rev = "69264e0836c07d2203b29b780cdb8c6dcddfffbc" }
cap-std-ext = "4.0.4"
camino = "1.1.9"
chrono = { version = "0.4.39", features = ["serde"] }
Expand Down
37 changes: 33 additions & 4 deletions src/bios.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use anyhow::{bail, Result};
#[cfg(target_arch = "powerpc64")]
use std::borrow::Cow;
use std::io::prelude::*;
use std::os::unix::io::AsRawFd;
use std::path::Path;
Expand All @@ -12,6 +14,30 @@ use crate::packagesystem;
// grub2-install file path
pub(crate) const GRUB_BIN: &str = "usr/sbin/grub2-install";

#[cfg(target_arch = "powerpc64")]
fn target_device(device: &str) -> Result<Cow<str>> {
const PREPBOOT_GUID: &str = "9E1A2D38-C612-4316-AA26-8B49521E5A8B";
/// We make a best-effort to support MBR partitioning too.
const PREPBOOT_MBR_TYPE: &str = "41";

// Here we use lsblk to see if the device has any partitions at all
let dev = bootc_blockdev::list_dev(device.into())?;
if dev.children.is_none() {
return Ok(device.into());
};
// If it does, directly call `sfdisk` and bypass lsblk because inside a container
// we may not have all the cached udev state (that I think is in /run).
let device = bootc_blockdev::partitions_of(device.into())?;
let prepdev = device
.partitions
.iter()
.find(|p| matches!(p.parttype.as_str(), PREPBOOT_GUID | PREPBOOT_MBR_TYPE))
.ok_or_else(|| {
anyhow::anyhow!("Failed to find PReP partition with GUID {PREPBOOT_GUID}")
})?;
Ok(prepdev.path().as_str().to_owned().into())
}

#[derive(Default)]
pub(crate) struct Bios {}

Expand Down Expand Up @@ -54,10 +80,13 @@ impl Bios {
.arg(device);

#[cfg(target_arch = "powerpc64")]
cmd.args(&["--target", "powerpc-ieee1275"])
.args(&["--boot-directory", boot_dir.to_str().unwrap()])
.arg("--no-nvram")
.arg(device);
{
let device = target_device(device)?;
cmd.args(&["--target", "powerpc-ieee1275"])
.args(&["--boot-directory", boot_dir.to_str().unwrap()])
.arg("--no-nvram")
.arg(&*device);
}

let cmdout = cmd.output()?;
if !cmdout.status.success() {
Expand Down

0 comments on commit 9175a0a

Please sign in to comment.