xref: /aosp_15_r20/bootable/libbootloader/gbl/libgbl/src/boot_reason.rs (revision 5225e6b173e52d2efc6bcf950c27374fd72adabc)
1 // Copyright 2023, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 //! Possible boot reasons.
16 
17 use core::fmt::{Debug, Display, Formatter};
18 
19 #[derive(Debug, PartialEq, Clone)]
20 /// Boot reasons that could be used in [BootMode]
21 pub enum KnownBootReason {
22     // kernel
23     /// Watchdog
24     Watchdog,
25     /// Kerner panic
26     KernelPanic,
27     // strong
28     /// Recovery
29     Recovery,
30     /// Bootloader
31     Bootloader,
32     // blunt
33     /// Generally indicates a full reset of all devices, including memory
34     Cold,
35     /// Generally indicates the hardware has its state reset and ramoops should retain persistent
36     /// content
37     Hard,
38     /// Generally indicates the memory and the devices retain some state, and the ramoops (see
39     /// pstore driver in kernel) backing store contains persistent content
40     Warm,
41     // super blunt
42     /// Shutdown
43     Shutdown,
44     /// Generally means the ramoops state is unknown and the hardware state is unknown. This value
45     /// is a catchall as the cold, hard, and warm values provide clues as to the depth of the reset
46     /// for the device
47     Reboot,
48 }
49 
50 impl Display for KnownBootReason {
fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result51     fn fmt(&self, f: &mut Formatter<'_>) -> core::fmt::Result {
52         let str = match self {
53             // kernel
54             KnownBootReason::Watchdog => "watchdog",
55             KnownBootReason::KernelPanic => "kernel_panic",
56             // strong
57             KnownBootReason::Recovery => "recovery",
58             KnownBootReason::Bootloader => "bootloader",
59             // blunt
60             KnownBootReason::Cold => "cold",
61             KnownBootReason::Hard => "hard",
62             KnownBootReason::Warm => "warm",
63             // super blunt
64             KnownBootReason::Shutdown => "shutdown",
65             KnownBootReason::Reboot => "reboot",
66         };
67         write!(f, "{str}")
68     }
69 }
70