@@ -27,6 +27,10 @@ pub struct BootloaderConfig {
27
27
/// Configuration for the frame buffer that can be used by the kernel to display pixels
28
28
/// on the screen.
29
29
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 ,
30
34
}
31
35
32
36
impl BootloaderConfig {
@@ -35,7 +39,7 @@ impl BootloaderConfig {
35
39
0x3D ,
36
40
] ;
37
41
#[ doc( hidden) ]
38
- pub const SERIALIZED_LEN : usize = 115 ;
42
+ pub const SERIALIZED_LEN : usize = 116 ;
39
43
40
44
/// Creates a new default configuration with the following values:
41
45
///
@@ -48,6 +52,7 @@ impl BootloaderConfig {
48
52
version : ApiVersion :: new_default ( ) ,
49
53
mappings : Mappings :: new_default ( ) ,
50
54
frame_buffer : FrameBuffer :: new_default ( ) ,
55
+ log_level : LevelFilter :: Trace ,
51
56
}
52
57
}
53
58
@@ -61,6 +66,7 @@ impl BootloaderConfig {
61
66
mappings,
62
67
kernel_stack_size,
63
68
frame_buffer,
69
+ log_level,
64
70
} = self ;
65
71
let ApiVersion {
66
72
version_major,
@@ -133,13 +139,15 @@ impl BootloaderConfig {
133
139
} ,
134
140
) ;
135
141
136
- concat_106_9 (
142
+ let buf = concat_106_9 (
137
143
buf,
138
144
match minimum_framebuffer_width {
139
145
Option :: None => [ 0 ; 9 ] ,
140
146
Option :: Some ( addr) => concat_1_8 ( [ 1 ] , addr. to_le_bytes ( ) ) ,
141
147
} ,
142
- )
148
+ ) ;
149
+
150
+ concat_115_1 ( buf, ( * log_level as u8 ) . to_le_bytes ( ) )
143
151
}
144
152
145
153
/// Tries to deserialize a config byte array that was created using [`Self::serialize`].
@@ -252,6 +260,13 @@ impl BootloaderConfig {
252
260
( frame_buffer, s)
253
261
} ;
254
262
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
+
255
270
if !s. is_empty ( ) {
256
271
return Err ( "unexpected rest" ) ;
257
272
}
@@ -261,6 +276,7 @@ impl BootloaderConfig {
261
276
kernel_stack_size : u64:: from_le_bytes ( kernel_stack_size) ,
262
277
mappings,
263
278
frame_buffer,
279
+ log_level,
264
280
} )
265
281
}
266
282
@@ -271,6 +287,7 @@ impl BootloaderConfig {
271
287
mappings : Mappings :: random ( ) ,
272
288
kernel_stack_size : rand:: random ( ) ,
273
289
frame_buffer : FrameBuffer :: random ( ) ,
290
+ log_level : LevelFilter :: Trace ,
274
291
}
275
292
}
276
293
}
@@ -534,6 +551,42 @@ impl Default for Mapping {
534
551
}
535
552
}
536
553
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
+
537
590
/// Taken from https://github.com/rust-lang/rust/blob/e100ec5bc7cd768ec17d75448b29c9ab4a39272b/library/core/src/slice/mod.rs#L1673-L1677
538
591
///
539
592
/// TODO replace with `split_array` feature in stdlib as soon as it's stabilized,
0 commit comments