pvmfw: Print RebootReason on secondary UART
When rebooting due to a business logic error, print the reason as a
formatted string to a dedicated UART, in the same way Microdroid does it
on its /dev/tty1, to provide the host with extra information about the
reason for the pVM rebooting.
Since aosp/2646391, all the pvmfw code runs with the UART properly
initialized, which greatly simplifies printing of the reboot reason as
start() can now assume that the secondary UART is also ready to be used.
This CL was verified through the logs of virtualizationmanager e.g. in
MicrodroidHostTests#protectedVmWithImageSignedWithDifferentKeyRunsPvmfw:
virtmgr : virtualizationmanager::crosvm: VM returned failure reason 'PVM_FIRMWARE_PAYLOAD_VERIFICATION_FAILED'
Note that the host still has to be taught about the new PVM_FIRMWARE_*.
Bug: 300636104
Test: atest MicrodroidHostTestCases
Change-Id: I5d382be9dae02da7e463193400dfa0474ca5e378
diff --git a/vmbase/src/console.rs b/vmbase/src/console.rs
index f829eb5..bbbcb07 100644
--- a/vmbase/src/console.rs
+++ b/vmbase/src/console.rs
@@ -65,7 +65,7 @@
/// Writes a formatted string followed by a newline to the n-th console.
///
/// Panics if the n-th console was not initialized by calling [`init`] first.
-pub(crate) fn writeln(n: usize, format_args: Arguments) {
+pub fn writeln(n: usize, format_args: Arguments) {
let mut guard = CONSOLES[n].lock();
let uart = guard.as_mut().unwrap();
@@ -88,13 +88,26 @@
let _ = uart.write_str("\n");
}
+/// Prints the given formatted string to the n-th console, followed by a newline.
+///
+/// Panics if the console has not yet been initialized. May hang if used in an exception context;
+/// use `eprintln!` instead.
+#[macro_export]
+macro_rules! console_writeln {
+ ($n:expr, $($arg:tt)*) => ({
+ $crate::console::writeln($n, format_args!($($arg)*))
+ })
+}
+
+pub(crate) use console_writeln;
+
/// Prints the given formatted string to the console, followed by a newline.
///
/// Panics if the console has not yet been initialized. May hang if used in an exception context;
/// use `eprintln!` instead.
macro_rules! println {
($($arg:tt)*) => ({
- $crate::console::writeln($crate::console::DEFAULT_CONSOLE_INDEX, format_args!($($arg)*))
+ $crate::console::console_writeln!($crate::console::DEFAULT_CONSOLE_INDEX, $($arg)*)
})
}