Skip to content

Commit 11e7522

Browse files
committed
fdt/aarch64: add an stdout-path entry
On aarch64, some guests use the chosen/stdout-path entry to find out the console they should use during boot. If we have a legacy serial console configure, let's create such entry to enable those guests to boot with a console. Linux guests will still switch to a virtio-console if it becomes available at some point during boot, so there isn't a risk we override that decision. Signed-off-by: Sergio Lopez <slp@redhat.com>
1 parent fb3b203 commit 11e7522

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/devices/src/fdt/aarch64.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub fn create_fdt<T: DeviceInfoForFDT + Clone + Debug>(
9898
fdt.property_u32("interrupt-parent", GIC_PHANDLE)?;
9999
create_cpu_nodes(&mut fdt, &vcpu_mpidr)?;
100100
create_memory_node(&mut fdt, guest_mem, arch_memory_info)?;
101-
create_chosen_node(&mut fdt, cmdline, initrd)?;
101+
create_chosen_node(&mut fdt, cmdline, initrd, device_info)?;
102102
create_gic_node(&mut fdt, gic_device)?;
103103
create_timer_node(&mut fdt)?;
104104
create_clock_node(&mut fdt)?;
@@ -189,14 +189,24 @@ fn create_memory_node(
189189
Ok(())
190190
}
191191

192-
fn create_chosen_node(
192+
fn create_chosen_node<T: DeviceInfoForFDT + Clone + Debug>(
193193
fdt: &mut FdtWriter,
194194
cmdline: &str,
195195
initrd: &Option<InitrdConfig>,
196+
dev_info: &HashMap<(DeviceType, String), T>,
196197
) -> Result<()> {
197198
let chosen_node = fdt.begin_node("chosen")?;
198199
fdt.property_string("bootargs", cmdline)?;
199200

201+
// If we have a legacy serial device, tell the guest this is the default console.
202+
// Clever guests will still switch to a better console (like virtio-console) if
203+
// it becomes available later, and this gives us a good fallback.
204+
for ((device_type, _device_id), info) in dev_info {
205+
if device_type == &DeviceType::Serial {
206+
fdt.property_string("stdout-path", &format!("/uart@{:x}", info.addr()))?;
207+
}
208+
}
209+
200210
if let Some(initrd_config) = initrd {
201211
fdt.property_u64("linux,initrd-start", initrd_config.address.raw_value())?;
202212
fdt.property_u64(

0 commit comments

Comments
 (0)