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