Skip to content

Commit a56133b

Browse files
committed
Add hardware reboot cause as actual reboot cause for soft reboot failed
1 parent f6ea036 commit a56133b

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

scripts/determine-reboot-cause

+31-8
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,41 @@ def main():
181181
# any additional_reboot_info it will be stored as a "comment" in REBOOT_CAUSE_HISTORY_FILE
182182
additional_reboot_info = "N/A"
183183

184-
# Check if the previous reboot was warm/fast reboot by testing whether there is "fast|fastfast|warm" in /proc/cmdline
184+
# 1. Check if the previous reboot was warm/fast reboot by testing whether there is "fast|fastfast|warm" in /proc/cmdline
185185
proc_cmdline_reboot_cause = find_proc_cmdline_reboot_cause()
186186

187-
# If /proc/cmdline does not indicate reboot cause, check if the previous reboot was caused by hardware
188-
if proc_cmdline_reboot_cause is None:
189-
previous_reboot_cause = find_hardware_reboot_cause()
190-
if previous_reboot_cause.startswith(REBOOT_CAUSE_NON_HARDWARE):
191-
# If the reboot cause is non-hardware, get the reboot cause from REBOOT_CAUSE_FILE
192-
previous_reboot_cause = find_software_reboot_cause()
187+
# 2. Check if the previous reboot was caused by hardware
188+
# If yes, the hardware reboot cause will be treated as the reboot cause
189+
hardware_reboot_cause = find_hardware_reboot_cause()
190+
191+
# 3. If there is a REBOOT_CAUSE_FILE, it will contain any software-related
192+
# reboot info. We will use it as the previous cause.
193+
software_reboot_cause = find_software_reboot_cause()
194+
195+
# The main decision logic of the reboot cause:
196+
# If there is a reboot cause indicated by /proc/cmdline, it should be warmreboot/fastreboot
197+
# the software_reboot_cause which is the content of /hosts/reboot-cause/reboot-cause.txt
198+
# will be treated as the reboot cause
199+
# Elif there is a reboot cause indicated by platform API,
200+
# the hardware_reboot_cause will be treated as the reboot cause
201+
# Else the software_reboot_cause will be treated as the reboot cause
202+
if proc_cmdline_reboot_cause is not None:
203+
if not hardware_reboot_cause.startswith(REBOOT_CAUSE_NON_HARDWARE):
204+
# Add the hardware_reboot_cause as actual reboot cause
205+
previous_reboot_cause = hardware_reboot_cause
206+
additional_reboot_info = software_reboot_cause
207+
else:
208+
previous_reboot_cause = software_reboot_cause
209+
elif hardware_reboot_cause is not None:
210+
# Check if any software reboot was issued before this hardware reboot happened
211+
if software_reboot_cause is not REBOOT_CAUSE_UNKNOWN:
212+
previous_reboot_cause = hardware_reboot_cause
213+
additional_reboot_info = software_reboot_cause
214+
else:
215+
previous_reboot_cause = hardware_reboot_cause
193216
else:
194217
# Get the reboot cause from REBOOT_CAUSE_FILE
195-
previous_reboot_cause = find_software_reboot_cause()
218+
previous_reboot_cause = software_reboot_cause
196219

197220
# Current time
198221
reboot_cause_gen_time = str(datetime.datetime.now().strftime('%Y_%m_%d_%H_%M_%S'))

0 commit comments

Comments
 (0)