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

bios+ppc64le: Support being passed a whole device #839

Merged
merged 2 commits into from
Feb 12, 2025
Merged
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
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 = "v1.1.5" }
bootc-utils = { git = "https://github.com/containers/bootc", rev = "v1.1.5" }
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>> {
Copy link
Member

Choose a reason for hiding this comment

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

Just one minor suggestion, not blocker, better to rename target_device to get_prepboot_device(), and move it to src/blockdev.rs? I am also OK to keep it here as it is only used on ppc64.

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