33
44//! Command line arguments and parsing for openhcl_boot.
55
6- use crate :: boot_logger:: LoggerType ;
76use underhill_confidentiality:: OPENHCL_CONFIDENTIAL_DEBUG_ENV_VAR_NAME ;
87
9- /// Enable boot logging in the bootloader.
10- ///
11- /// Format of `OPENHCL_BOOT_LOG=<logger>`, with valid loggers being:
12- /// - `com3`: use the com3 serial port, available on no isolation or Tdx.
13- const BOOT_LOG : & str = "OPENHCL_BOOT_LOG=" ;
14- const SERIAL_LOGGER : & str = "com3" ;
15-
168/// Enable the private VTL2 GPA pool for page allocations. This is only enabled
179/// via the command line, because in order to support the VTL2 GPA pool
1810/// generically, the boot shim must read serialized data from the previous
@@ -36,7 +28,6 @@ const SIDECAR: &str = "OPENHCL_SIDECAR=";
3628
3729#[ derive( Debug , PartialEq ) ]
3830pub struct BootCommandLineOptions {
39- pub logger : Option < LoggerType > ,
4031 pub confidential_debug : bool ,
4132 pub enable_vtl2_gpa_pool : Option < u64 > ,
4233 pub sidecar : bool ,
@@ -46,7 +37,6 @@ pub struct BootCommandLineOptions {
4637impl BootCommandLineOptions {
4738 pub const fn new ( ) -> Self {
4839 BootCommandLineOptions {
49- logger : None ,
5040 confidential_debug : false ,
5141 enable_vtl2_gpa_pool : None ,
5242 sidecar : true , // sidecar is enabled by default
@@ -59,18 +49,10 @@ impl BootCommandLineOptions {
5949 /// Parse arguments from a command line.
6050 pub fn parse ( & mut self , cmdline : & str ) {
6151 for arg in cmdline. split_whitespace ( ) {
62- if arg. starts_with ( BOOT_LOG ) {
63- if let Some ( SERIAL_LOGGER ) = arg. split_once ( '=' ) . map ( |( _, arg) | arg) {
64- self . logger = Some ( LoggerType :: Serial )
65- }
66- } else if arg. starts_with ( OPENHCL_CONFIDENTIAL_DEBUG_ENV_VAR_NAME ) {
52+ if arg. starts_with ( OPENHCL_CONFIDENTIAL_DEBUG_ENV_VAR_NAME ) {
6753 let arg = arg. split_once ( '=' ) . map ( |( _, arg) | arg) ;
6854 if arg. is_some_and ( |a| a != "0" ) {
6955 self . confidential_debug = true ;
70- // Explicit logger specification overrides this default.
71- if self . logger . is_none ( ) {
72- self . logger = Some ( LoggerType :: Serial ) ;
73- }
7456 }
7557 } else if arg. starts_with ( ENABLE_VTL2_GPA_POOL ) {
7658 self . enable_vtl2_gpa_pool = arg. split_once ( '=' ) . and_then ( |( _, arg) | {
@@ -105,59 +87,6 @@ mod tests {
10587 options
10688 }
10789
108- #[ test]
109- fn test_console_parsing ( ) {
110- assert_eq ! (
111- parse_boot_command_line( "OPENHCL_BOOT_LOG=com3" ) ,
112- BootCommandLineOptions {
113- logger: Some ( LoggerType :: Serial ) ,
114- ..BootCommandLineOptions :: new( )
115- }
116- ) ;
117-
118- assert_eq ! (
119- parse_boot_command_line( "OPENHCL_BOOT_LOG=1" ) ,
120- BootCommandLineOptions {
121- logger: None ,
122- ..BootCommandLineOptions :: new( )
123- }
124- ) ;
125-
126- assert_eq ! (
127- parse_boot_command_line( "OPENHCL_BOOT_LOG=random" ) ,
128- BootCommandLineOptions {
129- logger: None ,
130- ..BootCommandLineOptions :: new( )
131- }
132- ) ;
133-
134- assert_eq ! (
135- parse_boot_command_line( "OPENHCL_BOOT_LOG==com3" ) ,
136- BootCommandLineOptions {
137- logger: None ,
138- ..BootCommandLineOptions :: new( )
139- }
140- ) ;
141-
142- assert_eq ! (
143- parse_boot_command_line( "OPENHCL_BOOT_LOGserial" ) ,
144- BootCommandLineOptions {
145- logger: None ,
146- ..BootCommandLineOptions :: new( )
147- }
148- ) ;
149-
150- let cmdline = format ! ( "{OPENHCL_CONFIDENTIAL_DEBUG_ENV_VAR_NAME}=1" ) ;
151- assert_eq ! (
152- parse_boot_command_line( & cmdline) ,
153- BootCommandLineOptions {
154- logger: Some ( LoggerType :: Serial ) ,
155- confidential_debug: true ,
156- ..BootCommandLineOptions :: new( )
157- }
158- ) ;
159- }
160-
16190 #[ test]
16291 fn test_vtl2_gpa_pool_parsing ( ) {
16392 assert_eq ! (
0 commit comments