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

Chosen: convey kernel info inside chosen node #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 25 additions & 1 deletion src/standard_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ use crate::{
Fdt,
};

pub struct KernelInfo {
address: u64,
size: u64,
}

/// Represents the `/chosen` node with specific helper methods
#[derive(Debug, Clone, Copy)]
pub struct Chosen<'b, 'a: 'b> {
pub(crate) node: FdtNode<'b, 'a>,
node: FdtNode<'b, 'a>,
}

impl<'b, 'a: 'b> Chosen<'b, 'a> {
Expand All @@ -23,6 +28,25 @@ impl<'b, 'a: 'b> Chosen<'b, 'a> {
.and_then(|n| core::str::from_utf8(&n.value[..n.value.len() - 1]).ok())
}

/// Get kernel image location and size
pub fn kernel_info(self) -> Option<KernelInfo> {
let address = self.node
.properties()
.find(|n| n.name == "linux,kernel-start")
.and_then(|n| n.value)

if address.is_none() {
return None;
}

let size = self.node
.properties()
.find(|n| n.name == "linux,kernel-size")
.and_then(|n| n.value)

Some(KernelInfo(address, size))
}

/// Searches for the node representing `stdout`, if the property exists,
/// attempting to resolve aliases if the node name doesn't exist as-is
pub fn stdout(self) -> Option<StdInOutPath<'b, 'a>> {
Expand Down