Skip to content

Commit b5af2a3

Browse files
committed
AArch64: Add interface to get kernel info from FDT
Add a utility function to retrive the info from FDT. It's VMM's responsibility to store kernel info inside FDT Chosen node then we can get it there. Signed-off-by: Jianyong Wu <[email protected]>
1 parent 1db9bf8 commit b5af2a3

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/fdt.rs

+53
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ use crate::{
88
layout::MemoryDescriptor,
99
};
1010

11+
// Container of kernel image location address and size
12+
#[cfg(target_arch = "aarch64")]
13+
pub struct KernelInfo {
14+
pub address: u64,
15+
pub size: u64,
16+
}
17+
1118
pub struct StartInfo<'a> {
1219
acpi_rsdp_addr: Option<u64>,
1320
fdt_entry: MemoryEntry,
@@ -55,6 +62,52 @@ impl StartInfo<'_> {
5562
}
5663
None
5764
}
65+
66+
// kernel info is a self-defind item that lays inside Chosen node which should be guaranteed by VMM
67+
#[cfg(target_arch = "aarch64")]
68+
pub fn find_kernel_info(&self) -> Option<KernelInfo> {
69+
let chosen = self.fdt.find_node("/chosen").unwrap();
70+
let address = chosen
71+
.properties()
72+
.find(|n| n.name == "linux,kernel-start")
73+
.map(|n| n.value);
74+
75+
let addr = match address {
76+
Some(addr) => {
77+
let mut a: u64 = 0;
78+
for p in addr.iter().take(8) {
79+
a = (a << 8) + *p as u64;
80+
}
81+
a
82+
}
83+
None => {
84+
return None;
85+
}
86+
};
87+
88+
let size = chosen
89+
.properties()
90+
.find(|n| n.name == "linux,kernel-size")
91+
.map(|n| n.value);
92+
93+
let sz = match size {
94+
Some(sz) => {
95+
let mut s: u64 = 0;
96+
for p in sz.iter().take(8) {
97+
s = (s << 8) + *p as u64;
98+
}
99+
s
100+
}
101+
None => {
102+
return None;
103+
}
104+
};
105+
106+
Some(KernelInfo {
107+
address: addr,
108+
size: sz,
109+
})
110+
}
58111
}
59112

60113
impl Info for StartInfo<'_> {

0 commit comments

Comments
 (0)