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

Search for path of property-value pair #10

Open
alilee opened this issue Jan 12, 2020 · 3 comments
Open

Search for path of property-value pair #10

alilee opened this issue Jan 12, 2020 · 3 comments

Comments

@alilee
Copy link

alilee commented Jan 12, 2020

Nice work!

Do you have any thoughts on adding some search functionality like this?

let reader = Reader::read_from_address(pdtb as usize).unwrap();
let (node, _) = reader.struct_items().path_struct_items("/interrupt-parent").next().unwrap();
let phandle = node.value().unwrap();

let intc_path = reader.struct_items().find_path_to("phandle", phandle).unwrap();

let (intc, _) = reader.struct_items().path_struct_items(intc_path).next().unwrap();
@alilee alilee changed the title common use-case for dtb Search for path of property-value pair Jan 12, 2020
@ababo
Copy link
Owner

ababo commented Jan 12, 2020

So you need to find path for a given node? IMO it's a really artificial use case.

@alilee
Copy link
Author

alilee commented Jan 12, 2020

The scenario is that /interrupt-parent gives the phandle of the interrupt controller. You search through the tree to find the node with the given phandle, when you don't know its name. Check out phandle in the device tree spec. Alternatively, you could search through for interrupt-controller.

@ababo
Copy link
Owner

ababo commented Jan 12, 2020

@alilee, gotcha. I see it like that:

let reader = unsafe { Reader::read_from_address(pdtb as usize).unwrap(); }
let (prop, _) = reader.struct_items().path_struct_items("/interrupt-parent").next().unwrap();
let phandle = prop.value_u32().unwrap(); // I think we don't have `value_u32()`, I would add it.
let (node, iter) = reader.find_phandle(phandle).unwrap();

Pretty straightforward implementation using StructItems iterator. Feel free to create PR. :0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants