[wip] try to use fdt-rs for DTB parsing
This commit is contained in:
parent
5c7de9ceec
commit
0466589ddf
|
@ -2,6 +2,12 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bit_field"
|
name = "bit_field"
|
||||||
version = "0.10.1"
|
version = "0.10.1"
|
||||||
|
@ -35,18 +41,40 @@ version = "0.3.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "dtb"
|
|
||||||
version = "0.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "be6c6e1672a044abd9652045ba11beb1c7fbec7e5262dcba54795e82aa577971"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "either"
|
name = "either"
|
||||||
version = "1.6.1"
|
version = "1.6.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "endian-type-rs"
|
||||||
|
version = "0.1.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6419a5c75e40011b9fe0174db3fe24006ab122fbe1b7e9cc5974b338a755c76"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fallible-iterator"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "fdt-rs"
|
||||||
|
version = "0.4.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "99a40cabc11c8258822a593f5c51f2d9f4923e715ca9e2a0630cf77ae15f390b"
|
||||||
|
dependencies = [
|
||||||
|
"endian-type-rs",
|
||||||
|
"fallible-iterator",
|
||||||
|
"memoffset",
|
||||||
|
"num-derive",
|
||||||
|
"num-traits",
|
||||||
|
"rustc_version",
|
||||||
|
"static_assertions",
|
||||||
|
"unsafe_unwrap",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itertools"
|
name = "itertools"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
|
@ -56,6 +84,35 @@ dependencies = [
|
||||||
"either",
|
"either",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "memoffset"
|
||||||
|
version = "0.5.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-derive"
|
||||||
|
version = "0.3.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.27"
|
version = "1.0.27"
|
||||||
|
@ -86,6 +143,30 @@ version = "1.0.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "bd7a31eed1591dcbc95d92ad7161908e72f4677f8fabf2a32ca49b4237cbf211"
|
checksum = "bd7a31eed1591dcbc95d92ad7161908e72f4677f8fabf2a32ca49b4237cbf211"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc_version"
|
||||||
|
version = "0.2.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
|
||||||
|
dependencies = [
|
||||||
|
"semver",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver"
|
||||||
|
version = "0.9.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
|
||||||
|
dependencies = [
|
||||||
|
"semver-parser",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "semver-parser"
|
||||||
|
version = "0.7.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shrinkwraprs"
|
name = "shrinkwraprs"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
@ -120,6 +201,12 @@ dependencies = [
|
||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "static_assertions"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.73"
|
version = "1.0.73"
|
||||||
|
@ -143,6 +230,12 @@ version = "0.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unsafe_unwrap"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1230ec65f13e0f9b28d789da20d2d419511893ea9dac2c1f4ef67b8b14e5da80"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "usize_conversions"
|
name = "usize_conversions"
|
||||||
version = "0.2.0"
|
version = "0.2.0"
|
||||||
|
@ -163,7 +256,7 @@ dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"cortex-a",
|
"cortex-a",
|
||||||
"dtb",
|
"fdt-rs",
|
||||||
"qemu-exit",
|
"qemu-exit",
|
||||||
"r0",
|
"r0",
|
||||||
"shrinkwraprs",
|
"shrinkwraprs",
|
||||||
|
|
|
@ -35,7 +35,9 @@ bitflags = "1.2"
|
||||||
cfg-if = "1.0"
|
cfg-if = "1.0"
|
||||||
snafu = { version = "0.7.0-beta.0", default-features = false }
|
snafu = { version = "0.7.0-beta.0", default-features = false }
|
||||||
shrinkwraprs = { version = "0.3", default-features = false }
|
shrinkwraprs = { version = "0.3", default-features = false }
|
||||||
dtb = "0.2" # Dec 2019 by Simon Prikhodko
|
#dtb = "0.2" # Dec 2019 by Simon Prikhodko
|
||||||
# Alternatives to dtb to look at:
|
# Alternatives to dtb to look at:
|
||||||
#device_tree = "1.1.0" # Jun 2016 by Marc Brinkmann
|
#device_tree = "1.1.0" # Jun 2016 by Marc Brinkmann
|
||||||
#fdt-rs = "0.4.2" # Aug 2020 by Sean Wilson
|
# fdt-rs latest 0.4.3 Jul 2021 by Sean Wilson -- interface is more basic than in dtb
|
||||||
|
fdt-rs = { version = "0.4", default-features = false }
|
||||||
|
# @todo Added from_raw_pointer() finally
|
||||||
|
|
|
@ -52,6 +52,7 @@ use {
|
||||||
vc::VC,
|
vc::VC,
|
||||||
},
|
},
|
||||||
cfg_if::cfg_if,
|
cfg_if::cfg_if,
|
||||||
|
fdt_rs::base::DevTree,
|
||||||
};
|
};
|
||||||
|
|
||||||
entry!(kmain);
|
entry!(kmain);
|
||||||
|
@ -168,12 +169,11 @@ pub fn kmain(dtb: u32) -> ! {
|
||||||
println!("DTB loaded at {:x}", dtb);
|
println!("DTB loaded at {:x}", dtb);
|
||||||
|
|
||||||
// Safety: we got the address from the bootloader, if it lied - well, we're screwed!
|
// Safety: we got the address from the bootloader, if it lied - well, we're screwed!
|
||||||
let device_tree = crate::device_tree::DeadTree::new(unsafe {
|
let device_tree =
|
||||||
dtb::Reader::read_from_address(dtb as usize).expect("DeviceTree not found")
|
unsafe { DevTree::from_raw_pointer(dtb as *const _).expect("DeviceTree failed to read") };
|
||||||
});
|
|
||||||
|
|
||||||
// List unusable memory, and remove it from the memory regions for the allocator.
|
// List unusable memory, and remove it from the memory regions for the allocator.
|
||||||
for entry in device_tree.reserved_mem_entries() {
|
for entry in device_tree.compatible_nodes("memory") {
|
||||||
println!("reserved: {:?} bytes at {:?}", entry.size, entry.address);
|
println!("reserved: {:?} bytes at {:?}", entry.size, entry.address);
|
||||||
}
|
}
|
||||||
// Also, remove the DTB memory region.
|
// Also, remove the DTB memory region.
|
||||||
|
|
Loading…
Reference in New Issue