From 80527af5fe5a469740640c166b0da3fb3169ce98 Mon Sep 17 00:00:00 2001 From: Aelin Reidel Date: Fri, 15 May 2026 04:21:42 +0200 Subject: [PATCH] feat(aarch64): Fall back to detecting kernel at linux,initrd-start From what I can tell, cloud-hypervisor has no equivalent to QEMU's guest loader functionality, so I currently just pass the loader image as the kernel and the kernel image as the initramfs. It's fairly straightforward to fall back to parsing the kernel image from there, so I think this makes sense to support. --- src/arch/aarch64/mod.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/arch/aarch64/mod.rs b/src/arch/aarch64/mod.rs index 775cd609..43fc59ef 100644 --- a/src/arch/aarch64/mod.rs +++ b/src/arch/aarch64/mod.rs @@ -57,6 +57,7 @@ pub fn find_kernel() -> &'static [u8] { Fdt::from_ptr(ptr::with_exposed_provenance(DEVICE_TREE as usize)) .expect(".fdt file has invalid header") }; + let module_start = fdt .find_node("/chosen") .unwrap() @@ -71,12 +72,20 @@ pub fn find_kernel() -> &'static [u8] { } else { value.parse().unwrap() } - }) - .unwrap(); + }); + + let initrd_start = fdt + .find_node("/chosen") + .unwrap() + .properties() + .find(|prop| prop.name == "linux,initrd-start") + .map(|prop| usize::from_be_bytes(prop.value.try_into().unwrap())); + + let kernel_start = module_start.or(initrd_start).unwrap(); let header = unsafe { &*core::mem::transmute::<*const u8, *const Header>(ptr::with_exposed_provenance( - module_start, + kernel_start, )) }; @@ -96,7 +105,7 @@ pub fn find_kernel() -> &'static [u8] { unsafe { core::slice::from_raw_parts( - ptr::with_exposed_provenance(module_start), + ptr::with_exposed_provenance(kernel_start), file_size.try_into().unwrap(), ) }