@@ -27,6 +27,10 @@ pub struct BootloaderConfig {
2727 /// Configuration for the frame buffer that can be used by the kernel to display pixels
2828 /// on the screen.
2929 pub frame_buffer : FrameBuffer ,
30+
31+ /// Configuration for changing the level of the filter of the messages that are shown in the
32+ /// screen when booting. The default is 'Trace'.
33+ pub log_level : LevelFilter ,
3034}
3135
3236impl BootloaderConfig {
@@ -35,7 +39,7 @@ impl BootloaderConfig {
3539 0x3D ,
3640 ] ;
3741 #[ doc( hidden) ]
38- pub const SERIALIZED_LEN : usize = 115 ;
42+ pub const SERIALIZED_LEN : usize = 116 ;
3943
4044 /// Creates a new default configuration with the following values:
4145 ///
@@ -48,6 +52,7 @@ impl BootloaderConfig {
4852 version : ApiVersion :: new_default ( ) ,
4953 mappings : Mappings :: new_default ( ) ,
5054 frame_buffer : FrameBuffer :: new_default ( ) ,
55+ log_level : LevelFilter :: Trace ,
5156 }
5257 }
5358
@@ -61,6 +66,7 @@ impl BootloaderConfig {
6166 mappings,
6267 kernel_stack_size,
6368 frame_buffer,
69+ log_level,
6470 } = self ;
6571 let ApiVersion {
6672 version_major,
@@ -133,13 +139,15 @@ impl BootloaderConfig {
133139 } ,
134140 ) ;
135141
136- concat_106_9 (
142+ let buf = concat_106_9 (
137143 buf,
138144 match minimum_framebuffer_width {
139145 Option :: None => [ 0 ; 9 ] ,
140146 Option :: Some ( addr) => concat_1_8 ( [ 1 ] , addr. to_le_bytes ( ) ) ,
141147 } ,
142- )
148+ ) ;
149+
150+ concat_115_1 ( buf, ( * log_level as u8 ) . to_le_bytes ( ) )
143151 }
144152
145153 /// Tries to deserialize a config byte array that was created using [`Self::serialize`].
@@ -252,6 +260,13 @@ impl BootloaderConfig {
252260 ( frame_buffer, s)
253261 } ;
254262
263+ let ( & log_level, s) = split_array_ref ( s) ;
264+ let log_level = LevelFilter :: from_u8 ( u8:: from_le_bytes ( log_level) ) ;
265+ let log_level = match log_level {
266+ Option :: Some ( level) => level,
267+ Option :: None => return Err ( "log_level invalid" ) ,
268+ } ;
269+
255270 if !s. is_empty ( ) {
256271 return Err ( "unexpected rest" ) ;
257272 }
@@ -261,6 +276,7 @@ impl BootloaderConfig {
261276 kernel_stack_size : u64:: from_le_bytes ( kernel_stack_size) ,
262277 mappings,
263278 frame_buffer,
279+ log_level,
264280 } )
265281 }
266282
@@ -271,6 +287,7 @@ impl BootloaderConfig {
271287 mappings : Mappings :: random ( ) ,
272288 kernel_stack_size : rand:: random ( ) ,
273289 frame_buffer : FrameBuffer :: random ( ) ,
290+ log_level : LevelFilter :: Trace ,
274291 }
275292 }
276293}
@@ -534,6 +551,42 @@ impl Default for Mapping {
534551 }
535552}
536553
554+ /// An enum representing the available verbosity level filters of the logger.
555+ ///
556+ /// Based on
557+ /// https://github.com/rust-lang/log/blob/dc32ab999f52805d5ce579b526bd9d9684c38d1a/src/lib.rs#L552-565
558+ #[ repr( u8 ) ]
559+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
560+ pub enum LevelFilter {
561+ /// A level lower than all log levels.
562+ Off ,
563+ /// Corresponds to the `Error` log level.
564+ Error ,
565+ /// Corresponds to the `Warn` log level.
566+ Warn ,
567+ /// Corresponds to the `Info` log level.
568+ Info ,
569+ /// Corresponds to the `Debug` log level.
570+ Debug ,
571+ /// Corresponds to the `Trace` log level.
572+ Trace ,
573+ }
574+
575+ impl LevelFilter {
576+ /// Converts a u8 into a Option<LevelFilter>
577+ pub fn from_u8 ( value : u8 ) -> Option < LevelFilter > {
578+ match value {
579+ 0 => Some ( Self :: Off ) ,
580+ 1 => Some ( Self :: Error ) ,
581+ 2 => Some ( Self :: Warn ) ,
582+ 3 => Some ( Self :: Info ) ,
583+ 4 => Some ( Self :: Debug ) ,
584+ 5 => Some ( Self :: Trace ) ,
585+ _ => None ,
586+ }
587+ }
588+ }
589+
537590/// Taken from https://github.com/rust-lang/rust/blob/e100ec5bc7cd768ec17d75448b29c9ab4a39272b/library/core/src/slice/mod.rs#L1673-L1677
538591///
539592/// TODO replace with `split_array` feature in stdlib as soon as it's stabilized,
0 commit comments