Fdt

Struct Fdt 

Source
pub struct Fdt {
    pub boot_cpuid_phys: u32,
    pub memory_reservations: Vec<MemoryReservation>,
    pub root: Node,
    /* private fields */
}
Expand description

可编辑的 FDT

Fields§

§boot_cpuid_phys: u32

引导 CPU ID

§memory_reservations: Vec<MemoryReservation>

内存保留块

§root: Node

根节点

Implementations§

Source§

impl Fdt

Source

pub fn new() -> Self

创建新的空 FDT

Source

pub fn from_bytes(data: &[u8]) -> Result<Self, FdtError>

从原始 FDT 数据解析

Source

pub unsafe fn from_ptr(ptr: *mut u8) -> Result<Self, FdtError>

从原始指针解析

§Safety

调用者必须确保指针有效且指向有效的 FDT 数据

Source

pub fn rebuild_phandle_cache(&mut self)

重建 phandle 缓存

Source

pub fn resolve_alias(&self, alias: &str) -> Option<&str>

解析别名,返回对应的完整路径

从 /aliases 节点查找别名对应的路径

Source

pub fn aliases(&self) -> Vec<(String, String)>

获取所有别名

返回 (别名, 路径) 的列表

Source

pub fn find_by_phandle(&self, phandle: Phandle) -> Option<NodeRef<'_>>

根据 phandle 查找节点 返回 (节点引用, 完整路径)

Source

pub fn find_by_phandle_mut(&mut self, phandle: Phandle) -> Option<NodeMut<'_>>

根据 phandle 查找节点(可变) 返回 (节点可变引用, 完整路径)

Source

pub fn root(&self) -> &Node

获取根节点

Source

pub fn root_mut(&mut self) -> &mut Node

获取根节点(可变)

Source

pub fn apply_overlay(&mut self, overlay: &Fdt) -> Result<(), FdtError>

应用设备树覆盖 (Device Tree Overlay)

支持两种 overlay 格式:

  1. fragment 格式:包含 fragment@N 节点,每个 fragment 有 target/target-path 和 overlay
  2. 简单格式:直接包含 overlay 节点
§示例
// fragment 格式
fragment@0 {
    target-path = "/soc";
    __overlay__ {
        new_node { ... };
    };
};
Source

pub fn apply_overlay_with_delete( &mut self, overlay: &Fdt, delete_disabled: bool, ) -> Result<(), FdtError>

删除节点(通过设置 status = “disabled” 或直接删除)

如果 overlay 中的节点有 status = “disabled”,则禁用目标节点

Source

pub fn remove_node(&mut self, path: &str) -> Result<Option<Node>, FdtError>

通过精确路径删除节点及其子树 只支持精确路径匹配,不支持模糊匹配 支持通过别名删除节点,并自动删除对应的别名条目

§参数
  • path: 删除路径,格式如 “soc/gpio@1000” 或 “/soc/gpio@1000” 或别名
§返回值

Ok(Option<Node>): 如果找到并删除了节点,返回被删除的节点;如果路径不存在,返回 None Err(FdtError): 如果路径格式无效

§示例
let mut fdt = Fdt::new();

// 先添加节点再删除
let mut soc = Node::new("soc");
soc.add_child(Node::new("gpio@1000"));
fdt.root.add_child(soc);

// 精确删除节点(使用完整路径)
let removed = fdt.remove_node("/soc/gpio@1000")?;
assert!(removed.is_some());

// 尝试删除不存在的节点会返回错误
let not_found = fdt.remove_node("/soc/nonexistent");
assert!(not_found.is_err());
Source

pub fn all_nodes(&self) -> impl Iterator<Item = NodeRef<'_>> + '_

获取所有节点的深度优先迭代器

返回包含根节点及其所有子节点的迭代器,按照深度优先遍历顺序

Source

pub fn all_nodes_mut(&mut self) -> impl Iterator<Item = NodeMut<'_>> + '_

Source

pub fn find_by_path<'a>( &'a self, path: &str, ) -> impl Iterator<Item = NodeRef<'a>>

Source

pub fn get_by_path<'a>(&'a self, path: &str) -> Option<NodeRef<'a>>

Source

pub fn get_by_path_mut<'a>(&'a mut self, path: &str) -> Option<NodeMut<'a>>

Source

pub fn find_compatible(&self, compatible: &[&str]) -> Vec<NodeRef<'_>>

Source

pub fn encode(&self) -> FdtData

序列化为 FDT 二进制数据

Trait Implementations§

Source§

impl Clone for Fdt

Source§

fn clone(&self) -> Fdt

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Fdt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Fdt

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for Fdt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Fdt

§

impl RefUnwindSafe for Fdt

§

impl Send for Fdt

§

impl Sync for Fdt

§

impl Unpin for Fdt

§

impl UnwindSafe for Fdt

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.