Skip to content

Commit 7024041

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 <jianyong.wu@arm.com>
1 parent 1db9bf8 commit 7024041

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/fdt.rs

Lines changed: 51 additions & 0 deletions
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,50 @@ 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").map(|n| n.value);
73+
74+
let addr = match address {
75+
Some(addr) => {
76+
let mut a: u64 = 0;
77+
for p in addr.iter().take(8) {
78+
a = (a << 8) + *p as u64;
79+
}
80+
a
81+
}
82+
None => {
83+
return None;
84+
}
85+
};
86+
87+
let size = chosen
88+
.properties()
89+
.find(|n| n.name == "linux,kernel-size").map(|n| n.value);
90+
91+
let sz = match size {
92+
Some(sz) => {
93+
let mut s: u64 = 0;
94+
for p in sz.iter().take(8) {
95+
s = (s << 8) + *p as u64;
96+
}
97+
s
98+
}
99+
None => {
100+
return None;
101+
}
102+
};
103+
104+
Some(KernelInfo {
105+
address: addr,
106+
size: sz,
107+
})
108+
}
58109
}
59110

60111
impl Info for StartInfo<'_> {

0 commit comments

Comments
 (0)