dt.rs80.00%
1
// Copyright 2024 Google LLC2
//3
// Licensed under the Apache License, Version 2.0 (the "License");4
// you may not use this file except in compliance with the License.5
// You may obtain a copy of the License at6
//7
// https://www.apache.org/licenses/LICENSE-2.08
//9
// Unless required by applicable law or agreed to in writing, software10
// distributed under the License is distributed on an "AS IS" BASIS,11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12
// See the License for the specific language governing permissions and13
// limitations under the License.14
15
pub mod dtb;16
17
use std::collections::HashMap;18
use std::mem::size_of_val;19
20
#[derive(Debug, Clone)]21
pub enum PropVal {22
Empty,23
U32(u32),24
U64(u64),25
String(String),26
Str(&'static str),27
PHandle(u32),28
StringList(Vec<String>),29
U32List(Vec<u32>),30
U64List(Vec<u64>),31
Bytes(Vec<u8>),32
}33
34
impl PropVal {35
pub fn size(&self) -> usize {30x36
match self {30x37
PropVal::Empty => 0,3x38
PropVal::U32(_) | PropVal::PHandle(_) => 4,6x39
PropVal::U64(_) => 8,3x40
PropVal::String(s) => s.len() + 1,3x41
PropVal::Str(s) => s.len() + 1,3x42
PropVal::Bytes(d) => d.len(),3x43
PropVal::U32List(r) => size_of_val(r.as_slice()),3x44
PropVal::U64List(r) => size_of_val(r.as_slice()),3x45
PropVal::StringList(l) => l.iter().map(|s| s.len() + 1).sum(),6x46
}47
}30x48
}49
50
#[derive(Debug, Clone, Default)]51
pub struct Node {52
pub props: HashMap<&'static str, PropVal>,53
pub nodes: Vec<(String, Node)>,54
}55
56
#[derive(Debug, Clone, Default)]57
pub struct DeviceTree {58
pub root: Node,59
pub reserved_mem: Vec<(usize, usize)>,60
pub boot_cpuid_phys: u32,61
}62
63
impl DeviceTree {64
pub fn new() -> Self {65
DeviceTree::default()66
}67
}68
69
#[cfg(test)]70
#[path = "dt_test.rs"]71
mod tests;72