Skip to content

Commit

Permalink
[doc] Add more doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Azure-stars committed Nov 4, 2024
1 parent 11c66bd commit 45a6550
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# of

A pure-Rust #![no_std] crate for parsing Flattened Devicetrees with the goal of having a very ergonomic and idiomatic API.

9 changes: 9 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn find_compatible_node(
.unwrap()
}

/// Whether the device pointed by the node is available
pub fn of_device_is_available(node: OfNode<'static>) -> bool {
let status = node.properties().find(|p| p.name == "status");
let ret = match status {
Expand All @@ -106,6 +107,7 @@ pub fn of_device_is_available(node: OfNode<'static>) -> bool {
ret
}

/// Read a u32 property from a node
pub fn of_property_read_u32(
node: OfNode<'static>,
name: &'static str,
Expand All @@ -123,19 +125,22 @@ pub fn of_property_read_u32(
)
}

/// Bootargs from the FDT
pub fn bootargs() -> Option<&'static str> {
MY_MACHINE_FDT
.as_ref()
.and_then(|fdt| fdt.0.chosen().bootargs())
}

/// Returns the size of the FDT
pub fn fdt_size() -> usize {
MY_MACHINE_FDT
.as_ref()
.map(|fdt| fdt.0.total_size())
.unwrap_or(0)
}

/// All memory nodes in the FDT
pub fn memory_nodes() -> Option<impl Iterator<Item = Memory>> {
MY_MACHINE_FDT.as_ref().map(|fdt| {
fdt.0
Expand All @@ -144,6 +149,7 @@ pub fn memory_nodes() -> Option<impl Iterator<Item = Memory>> {
})
}

/// Psci node in the FDT
pub fn pcsi() -> Option<kernel_nodes::Pcsi> {
MY_MACHINE_FDT.as_ref().and_then(|fdt| {
fdt.0
Expand All @@ -152,16 +158,19 @@ pub fn pcsi() -> Option<kernel_nodes::Pcsi> {
})
}

/// CPU nodes in the FDT
pub fn cpus() -> Option<impl Iterator<Item = fdt::standard_nodes::Cpu<'static, 'static>>> {
MY_MACHINE_FDT.as_ref().map(|fdt| fdt.0.cpus())
}

/// Find a phandle in the FDT
pub fn find_phandle(phandle: u32) -> Option<OfNode<'static>> {
MY_MACHINE_FDT
.as_ref()
.and_then(|fdt| fdt.0.find_phandle(phandle))
}

/// Parse a phandle with arguments
pub fn of_parse_phandle_with_args(
node: OfNode<'static>,
list_name: &'static str,
Expand Down

0 comments on commit 45a6550

Please sign in to comment.