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