Coder Social home page Coder Social logo

fdt-rs's Introduction

fdt-rs

crates.io downloads docs.rs master coveralls.io

A Flattened Device Tree parser for embedded no-std environments

Usage

Add this to your Cargo.toml:

[dependencies.fdt-rs]
version = "0.4"

and this to your crate root:

extern crate fdt_rs;

Features

This crate can be used without the standard library (#![no_std]) by disabling the default std feature. Use this in Cargo.toml:

[dependencies.fdt-rs]
version = "0.4"
default-features = false

Example

The following example stashes a flattened device tree in memory, parses that device tree into a fdt_rs::DevTree object, searches the device tree for "ns16550a" compatible nodes, and (if found) prints each nodes' name.

extern crate fdt_rs;
use fdt_rs::prelude::*;
use fdt_rs::base::*;

// Place a device tree image into the rust binary and
// align it to a 32-byte boundary by using a wrapper struct.
#[repr(align(4))] struct _Wrapper<T>(T);
pub const FDT: &[u8] = &_Wrapper(*include_bytes!("../tests/riscv64-virt.dtb")).0;

fn main() {
    // Initialize the devtree using an &[u8] array.
    let devtree = unsafe {

        // Get the actual size of the device tree after reading its header.
        let size = DevTree::read_totalsize(FDT).unwrap();
        let buf = &FDT[..size];

        // Create the device tree handle
        DevTree::new(buf).unwrap()
    };

    // Iterate through all "ns16550a" compatible nodes within the device tree.
    // If found, print the name of each node (including unit address).
    let mut node_iter = devtree.compatible_nodes("ns16550a");
    while let Some(node) = node_iter.next().unwrap() {
        println!("{}", node.name().unwrap());
    }
}

Also check out fdtdump for an example implementation of the fdtdump Device Tree utility using this library.

fdt-rs's People

Contributors

berkus avatar kritzefitz avatar lf- avatar skallwar avatar spwilson2 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

fdt-rs's Issues

fdt_rs::base prop().node() iteration appears to be bugged.

The following test fails in the "Device tree memory node missing 'reg' prop." expect clause using the riscv-5 device tree.

#[test]
fn get_memory_prop_node() {
    unsafe {
        let blob = DevTree::new(FDT).unwrap();

        let mem_prop = blob.props().find(|p| Ok(p.name()? == "device_type" && p.str()? == "memory"))
            .unwrap()
            .expect("Unable to find memory node.");
        let mem_node = mem_prop.node();
        let mem_reg_prop = mem_node.props()
            .find(|p| Ok(p.name()? == "reg"))
            .unwrap()
            .expect("Device tree memory node missing 'reg' prop.");
}

Documentation incomplete

Hi!

The documentation here states two examples in the base module which are identical and use index instead of actually devTree that is created in the example above. I believe his is an omission and should be improved somehow?

Compatible Search

Find all DevTreeNode objects which have their compatible property defined as "ns16550a":

vs.

Custom Search

Find all DevTreeNode objects which have their compatible property defined as "ns16550a":

Code is exactly the same in both sections.

Doesn't build on new nightly

error[E0557]: feature has been removed
  --> /home/jade/.cargo/git/checkouts/fdt-rs-13c2679c47ec7b62/2364d50/src/lib.rs:27:39
   |
27 | #![cfg_attr(RUSTC_IS_NIGHTLY, feature(external_doc))]
   |                                       ^^^^^^^^^^^^ feature has been removed
   |
   = note: use #[doc = include_str!("filename")] instead, which handles macro invocations

cargo doc not working

I included this library in a no_std project. Unfortunately, this breaks cargo doc builds.
It seems like the issue is fixed in master, so maybe push a new point release to crates.io?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.