xref: /aosp_15_r20/bootable/libbootloader/gbl/libgbl/src/boot_mode.rs (revision 5225e6b173e52d2efc6bcf950c27374fd72adabc)
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 modes.
16*5225e6b1SAndroid Build Coastguard Worker 
17*5225e6b1SAndroid Build Coastguard Worker // TODO: b/312605899 - find full list of supported boot modes
18*5225e6b1SAndroid Build Coastguard Worker // Looks like we need only compliant items from map: system/core/bootstat/bootstat.cpp
19*5225e6b1SAndroid Build Coastguard Worker // kBootReasonMap
20*5225e6b1SAndroid Build Coastguard Worker // It might be required to assemble this type in format: <reason>,<sub_reason>,<detil>,...
21*5225e6b1SAndroid Build Coastguard Worker // Bootloaders must provide a kernel set or a blunt set reason, and are strongly encouraged to
22*5225e6b1SAndroid Build Coastguard Worker // provide a subreason if it can be determined. For example, a power key long press that may or may
23*5225e6b1SAndroid Build Coastguard Worker // not have ramoops backup would have the boot reason "reboot,longkey".
24*5225e6b1SAndroid Build Coastguard Worker /* good reasons from kBootReasonMap
25*5225e6b1SAndroid Build Coastguard Worker {"reboot,[empty]", kEmptyBootReason},
26*5225e6b1SAndroid Build Coastguard Worker {"recovery", 3},
27*5225e6b1SAndroid Build Coastguard Worker {"reboot", 4},
28*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic", 7},
29*5225e6b1SAndroid Build Coastguard Worker {"watchdog", 40},
30*5225e6b1SAndroid Build Coastguard Worker {"shutdown,", 45},  // Trailing comma is intentional. Do NOT use.
31*5225e6b1SAndroid Build Coastguard Worker {"shutdown,userrequested", 46},
32*5225e6b1SAndroid Build Coastguard Worker {"reboot,bootloader", 47},
33*5225e6b1SAndroid Build Coastguard Worker {"reboot,cold", 48},
34*5225e6b1SAndroid Build Coastguard Worker {"reboot,recovery", 49},
35*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,sysrq", 52},
36*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,null", 53},
37*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,bug", 54},
38*5225e6b1SAndroid Build Coastguard Worker {"bootloader", 55},
39*5225e6b1SAndroid Build Coastguard Worker {"cold", 56},
40*5225e6b1SAndroid Build Coastguard Worker {"hard", 57},
41*5225e6b1SAndroid Build Coastguard Worker {"warm", 58},
42*5225e6b1SAndroid Build Coastguard Worker {"reboot,kernel_power_off_charging__reboot_system", 59},  // Can not happen
43*5225e6b1SAndroid Build Coastguard Worker {"shutdown,thermal", 61},
44*5225e6b1SAndroid Build Coastguard Worker {"shutdown,battery", 62},
45*5225e6b1SAndroid Build Coastguard Worker {"reboot,ota", 63},
46*5225e6b1SAndroid Build Coastguard Worker {"reboot,factory_reset", 64},
47*5225e6b1SAndroid Build Coastguard Worker {"reboot,", 65},
48*5225e6b1SAndroid Build Coastguard Worker {"reboot,shell", 66},
49*5225e6b1SAndroid Build Coastguard Worker {"reboot,adb", 67},
50*5225e6b1SAndroid Build Coastguard Worker {"reboot,userrequested", 68},
51*5225e6b1SAndroid Build Coastguard Worker {"shutdown,container", 69},  // Host OS asking Android Container to shutdown
52*5225e6b1SAndroid Build Coastguard Worker {"cold,powerkey", 70},
53*5225e6b1SAndroid Build Coastguard Worker {"warm,s3_wakeup", 71},
54*5225e6b1SAndroid Build Coastguard Worker {"hard,hw_reset", 72},
55*5225e6b1SAndroid Build Coastguard Worker {"shutdown,suspend", 73},    // Suspend to RAM
56*5225e6b1SAndroid Build Coastguard Worker {"shutdown,hibernate", 74},  // Suspend to DISK
57*5225e6b1SAndroid Build Coastguard Worker {"reboot,by_key", 84},
58*5225e6b1SAndroid Build Coastguard Worker {"reboot,longkey", 85},
59*5225e6b1SAndroid Build Coastguard Worker {"reboot,2sec", 86},  // Deprecate in two years, replaced with cold,rtc,2sec
60*5225e6b1SAndroid Build Coastguard Worker {"shutdown,thermal,battery", 87},
61*5225e6b1SAndroid Build Coastguard Worker {"reboot,its_just_so_hard", 88},  // produced by boot_reason_test
62*5225e6b1SAndroid Build Coastguard Worker {"reboot,rescueparty", 90},
63*5225e6b1SAndroid Build Coastguard Worker {"reboot,powerloss", 119},
64*5225e6b1SAndroid Build Coastguard Worker {"reboot,undervoltage", 120},
65*5225e6b1SAndroid Build Coastguard Worker {"cold,charger", 148},
66*5225e6b1SAndroid Build Coastguard Worker {"cold,rtc", 149},
67*5225e6b1SAndroid Build Coastguard Worker {"cold,rtc,2sec", 150},   // Mediatek
68*5225e6b1SAndroid Build Coastguard Worker {"reboot,tool", 151},     // Mediatek
69*5225e6b1SAndroid Build Coastguard Worker {"reboot,wdt", 152},      // Mediatek
70*5225e6b1SAndroid Build Coastguard Worker {"reboot,unknown", 153},  // Mediatek
71*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,audit", 154},
72*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,atomic", 155},
73*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,hung", 156},
74*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,hung,rcu", 157},
75*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,init", 158},
76*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,oom", 159},
77*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,stack", 160},
78*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,sysrq,livelock,alarm", 161},   // llkd
79*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,sysrq,livelock,driver", 162},  // llkd
80*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,sysrq,livelock,zombie", 163},  // llkd
81*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,modem", 164},
82*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,adsp", 165},
83*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,dsps", 166},
84*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,wcnss", 167},
85*5225e6b1SAndroid Build Coastguard Worker {"kernel_panic,_sde_encoder_phys_cmd_handle_ppdone_timeout", 168},
86*5225e6b1SAndroid Build Coastguard Worker {"recovery,quiescent", 169},
87*5225e6b1SAndroid Build Coastguard Worker {"reboot,quiescent", 170},
88*5225e6b1SAndroid Build Coastguard Worker {"reboot,rtc", 171},
89*5225e6b1SAndroid Build Coastguard Worker {"reboot,dm-verity_device_corrupted", 172},
90*5225e6b1SAndroid Build Coastguard Worker {"reboot,dm-verity_enforcing", 173},
91*5225e6b1SAndroid Build Coastguard Worker {"reboot,keys_clear", 174},
92*5225e6b1SAndroid Build Coastguard Worker {"reboot,pmic_off_fault,.*", 175},
93*5225e6b1SAndroid Build Coastguard Worker {"reboot,pmic_off_s3rst,.*", 176},
94*5225e6b1SAndroid Build Coastguard Worker {"reboot,pmic_off_other,.*", 177},
95*5225e6b1SAndroid Build Coastguard Worker {"reboot,userrequested,fastboot", 178},
96*5225e6b1SAndroid Build Coastguard Worker {"reboot,userrequested,recovery", 179},
97*5225e6b1SAndroid Build Coastguard Worker {"reboot,userrequested,recovery,ui", 180},
98*5225e6b1SAndroid Build Coastguard Worker {"shutdown,userrequested,fastboot", 181},
99*5225e6b1SAndroid Build Coastguard Worker {"shutdown,userrequested,recovery", 182},
100*5225e6b1SAndroid Build Coastguard Worker {"reboot,unknown[0-9]*", 183},
101*5225e6b1SAndroid Build Coastguard Worker {"reboot,longkey,.*", 184},
102*5225e6b1SAndroid Build Coastguard Worker {"reboot,boringssl-self-check-failed", 185},
103*5225e6b1SAndroid Build Coastguard Worker {"reboot,userspace_failed,shutdown_aborted", 186},
104*5225e6b1SAndroid Build Coastguard Worker {"reboot,userspace_failed,watchdog_triggered", 187},
105*5225e6b1SAndroid Build Coastguard Worker {"reboot,userspace_failed,watchdog_fork", 188},
106*5225e6b1SAndroid Build Coastguard Worker {"reboot,userspace_failed,*", 189},
107*5225e6b1SAndroid Build Coastguard Worker {"reboot,mount_userdata_failed", 190},
108*5225e6b1SAndroid Build Coastguard Worker {"reboot,forcedsilent", 191},
109*5225e6b1SAndroid Build Coastguard Worker {"reboot,forcednonsilent", 192},
110*5225e6b1SAndroid Build Coastguard Worker {"reboot,thermal,tj", 193},
111*5225e6b1SAndroid Build Coastguard Worker {"reboot,emergency", 194},
112*5225e6b1SAndroid Build Coastguard Worker {"reboot,factory", 195},
113*5225e6b1SAndroid Build Coastguard Worker {"reboot,fastboot", 196},
114*5225e6b1SAndroid Build Coastguard Worker {"reboot,gsa,hard", 197},
115*5225e6b1SAndroid Build Coastguard Worker {"reboot,gsa,soft", 198},
116*5225e6b1SAndroid Build Coastguard Worker {"reboot,master_dc,fault_n", 199},
117*5225e6b1SAndroid Build Coastguard Worker {"reboot,master_dc,reset", 200},
118*5225e6b1SAndroid Build Coastguard Worker {"reboot,ocp", 201},
119*5225e6b1SAndroid Build Coastguard Worker {"reboot,pin", 202},
120*5225e6b1SAndroid Build Coastguard Worker {"reboot,rom_recovery", 203},
121*5225e6b1SAndroid Build Coastguard Worker {"reboot,uvlo", 204},
122*5225e6b1SAndroid Build Coastguard Worker {"reboot,uvlo,pmic,if", 205},
123*5225e6b1SAndroid Build Coastguard Worker {"reboot,uvlo,pmic,main", 206},
124*5225e6b1SAndroid Build Coastguard Worker {"reboot,uvlo,pmic,sub", 207},
125*5225e6b1SAndroid Build Coastguard Worker {"reboot,warm", 208},
126*5225e6b1SAndroid Build Coastguard Worker {"watchdog,aoc", 209},
127*5225e6b1SAndroid Build Coastguard Worker {"watchdog,apc", 210},
128*5225e6b1SAndroid Build Coastguard Worker {"watchdog,apc,bl,debug,early", 211},
129*5225e6b1SAndroid Build Coastguard Worker {"watchdog,apc,bl,early", 212},
130*5225e6b1SAndroid Build Coastguard Worker {"watchdog,apc,early", 213},
131*5225e6b1SAndroid Build Coastguard Worker {"watchdog,apm", 214},
132*5225e6b1SAndroid Build Coastguard Worker {"watchdog,gsa,hard", 215},
133*5225e6b1SAndroid Build Coastguard Worker {"watchdog,gsa,soft", 216},
134*5225e6b1SAndroid Build Coastguard Worker {"watchdog,pmucal", 217},
135*5225e6b1SAndroid Build Coastguard Worker {"reboot,early,bl", 218},
136*5225e6b1SAndroid Build Coastguard Worker {"watchdog,apc,gsa,crashed", 219},
137*5225e6b1SAndroid Build Coastguard Worker {"watchdog,apc,bl31,crashed", 220},
138*5225e6b1SAndroid Build Coastguard Worker {"watchdog,apc,pbl,crashed", 221},
139*5225e6b1SAndroid Build Coastguard Worker {"reboot,memory_protect,hyp", 222},
140*5225e6b1SAndroid Build Coastguard Worker {"reboot,tsd,pmic,main", 223},
141*5225e6b1SAndroid Build Coastguard Worker {"reboot,tsd,pmic,sub", 224},
142*5225e6b1SAndroid Build Coastguard Worker {"reboot,ocp,pmic,main", 225},
143*5225e6b1SAndroid Build Coastguard Worker {"reboot,ocp,pmic,sub", 226},
144*5225e6b1SAndroid Build Coastguard Worker {"reboot,sys_ldo_ok,pmic,main", 227},
145*5225e6b1SAndroid Build Coastguard Worker {"reboot,sys_ldo_ok,pmic,sub", 228},
146*5225e6b1SAndroid Build Coastguard Worker {"reboot,smpl_timeout,pmic,main", 229},
147*5225e6b1SAndroid Build Coastguard Worker {"reboot,ota,.*", 230},
148*5225e6b1SAndroid Build Coastguard Worker {"reboot,periodic,.*", 231},
149*5225e6b1SAndroid Build Coastguard Worker */
150*5225e6b1SAndroid Build Coastguard Worker 
151*5225e6b1SAndroid Build Coastguard Worker /// Boot mode
152*5225e6b1SAndroid Build Coastguard Worker ///
153*5225e6b1SAndroid Build Coastguard Worker /// This is subset of compliant tems from map: system/core/bootstat/bootstat.cpp kBootReasonMap
154*5225e6b1SAndroid Build Coastguard Worker // Underlying format is <reason>,<sub_reason>,<detil>,...
155*5225e6b1SAndroid Build Coastguard Worker #[derive(Debug, PartialEq, Copy, Clone)]
156*5225e6b1SAndroid Build Coastguard Worker pub enum BootMode {
157*5225e6b1SAndroid Build Coastguard Worker     /// Normal system start
158*5225e6b1SAndroid Build Coastguard Worker     Normal,
159*5225e6b1SAndroid Build Coastguard Worker     /// Recovery mode
160*5225e6b1SAndroid Build Coastguard Worker     Recovery,
161*5225e6b1SAndroid Build Coastguard Worker     /// Request to boot into bootloader mode staying in CMD-line or fastboot mode.
162*5225e6b1SAndroid Build Coastguard Worker     Bootloader,
163*5225e6b1SAndroid Build Coastguard Worker     // TODO: b/312605899 - need full list of supported modes
164*5225e6b1SAndroid Build Coastguard Worker     // Quiescent,
165*5225e6b1SAndroid Build Coastguard Worker }
166