rs-embedded / fdt-rs Goto Github PK
View Code? Open in Web Editor NEWA full-featured FDT/DTB parser for embedded systems written in rust.
License: MIT License
A full-featured FDT/DTB parser for embedded systems written in rust.
License: MIT License
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?
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.");
}
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
Issue stems from my faulty assertion that structs would be 32-bit aligned. (The fdt_reserve_entry is 64-bit aligned since its members are uniquely 64be typed.)
Unfortunately, because the API returns a reference to each parsed field the API to access this field will need to change. (We can't return a misaligned reference.) Since internally this isn't a particularly widely used field, API blowback should be minimal.
We should either return a special wrapper that supports misaligned references/raw pointers or just return a raw pointer and have the consumer deal with the read_unaligned call. (I'm leaning towards using a wrapper type for safety.)
/// Return the current offset as a fdt_reserve_entry reference.
///
/// # Safety
///
/// The caller must verify that the current offset of this iterator is 32-bit aligned.
/// (Each field is 32-bit aligned and they may be read individually.)
unsafe fn read(&'a self) -> Result<&'dt fdt_reserve_entry> {
Ok(&*self.fdt.ptr_at(self.offset)?)
}
}
impl<'a, 'dt: 'a> Iterator for DevTreeReserveEntryIter<'a, 'dt> {
type Item = &'dt fdt_reserve_entry;
fn next(&mut self) -> Option<Self::Item> {
...
// We guaruntee the read will be aligned to 32 bits because:
// - We construct with guarunteed 32-bit aligned offset
// - We always increment by an aligned amount
let ret = unsafe { self.read().unwrap() };
...
Some(ret)
thread 'reserved_entries_iter' panicked at 'misaligned pointer dereference: address must be a multiple of 0x8 but is 0x1026398c4', src/base/iters.rs:41:12
stack backtrace:
0: rust_begin_unwind
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
1: core::panicking::panic_fmt
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
2: core::panicking::panic_misaligned_pointer_dereference
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:174:5
3: fdt_rs::base::iters::DevTreeReserveEntryIter::read
at ./src/base/iters.rs:41:12
4: <fdt_rs::base::iters::DevTreeReserveEntryIter as core::iter::traits::iterator::Iterator>::next
at ./src/base/iters.rs:54:32
5: core::iter::traits::iterator::Iterator::fold
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/iter/traits/iterator.rs:2481:29
6: core::iter::traits::iterator::Iterator::count
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/iter/traits/iterator.rs:267:9
7: parsing_test::reserved_entries_iter
at ./tests/parsing_test.rs:88:17
8: parsing_test::reserved_entries_iter::{{closure}}
at ./tests/parsing_test.rs:85:28
9: core::ops::function::FnOnce::call_once
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
10: core::ops::function::FnOnce::call_once
at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
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.
I wanted to load the tree and modify that in memory, and eventually flash that to the file again. Is this supported?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.