From 15199251498fbbdca0550493b36a8d511229db19 Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Fri, 16 Mar 2018 09:26:05 -0700 Subject: [PATCH 1/2] bootstat: shutdown reports reboot Some devices report the following canonical boot reason for all shutdown operations: reboot,kernel_power_off_charging__reboot_system because shutdown switches to a charging kernel, and reboots into the system when the user presses the power button. Thus last kernel messages arrives as: <0>.(0)[53:pmic_thread]reboot: Restarting system with command \ 'kernel power off charging reboot system' -> "shutdown" (w/o last boot reason) -> "shutdown," (w/last boot reason) The reboot reason from that charging instance propagates as a fortified boot reason blocking interpretation of the last boot reason that manages shutdown canonical boot reason determination. The fix is to change reboot,kernel_power_off_charging__reboot_system to shutdown, so that it is viewed as a blunt reason that can be overridden by last boot reason. We added the above boot reason to kBootReasonMap because the Bit Error Handler can use it to reconstruct if there is any damage to the last kernel messages content. The sad thing is that the enum will never propagate as we are filtering it out and reporting "shutdown" instead. Of course, we are now covered for a can not happen. Test: boot_reason_test.sh Bug: 74595769 Bug: 63736262 Change-Id: I28987f0871af7d967cc4bbbffed43bd42349acdd --- bootstat/bootstat.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp index 3250b3e34..fb0423a6e 100644 --- a/bootstat/bootstat.cpp +++ b/bootstat/bootstat.cpp @@ -201,7 +201,7 @@ const std::map kBootReasonMap = { {"cold", 56}, {"hard", 57}, {"warm", 58}, - // {"recovery", 59}, // Duplicate of enum 3 above. Immediate reuse possible. + {"reboot,kernel_power_off_charging__reboot_system", 59}, // Can not happen {"thermal-shutdown", 60}, {"shutdown,thermal", 61}, {"shutdown,battery", 62}, @@ -850,6 +850,10 @@ std::string BootReasonStrToReason(const std::string& boot_reason) { ret = "reboot," + subReason; // legitimize unknown reasons } } + // Some bootloaders shutdown results record in last kernel message. + if (!strcmp(ret.c_str(), "reboot,kernel_power_off_charging__reboot_system")) { + ret = "shutdown"; + } } // Check for kernel panics, allowed to override reboot command. From 186f67625c70478f1c04b99cea2f700a453a4d0e Mon Sep 17 00:00:00 2001 From: Mark Salyzyn Date: Fri, 16 Mar 2018 11:00:26 -0700 Subject: [PATCH 2/2] bootstat: refine boot reasons Received some clarity as to some of the boot reasons. List of boot reasons and new translations to Canonical boot reason: - "power_key" -> "cold,powerkey" (existing) - "usb" -> "cold,charger" (existing) - "rtc" -> "cold,rtc" (existing) - "wdt" -> "reboot" (changed) - "wdt_by_pass_pwk" -> "warm" (changed) - "tool_by_pass_pwd" -> "reboot,tool" (changed) - "2sec_reboot" -> "cold,rtc,2sec" (changed) - "unknown" -> "reboot,unknown" (existing) - "kernel_panic" (existing) - "reboot" (existing) - "watchdog" (existing) Add the new string to enums for the new Boot Reason. Test: boot_reason_test.sh (on affected device) Bug: 74595769 Bug: 63736262 Change-Id: Iecedc3b1f7c47f26d0c77b1f316f745c6d2c1256 --- bootstat/boot_reason_test.sh | 4 ++++ bootstat/bootstat.cpp | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/bootstat/boot_reason_test.sh b/bootstat/boot_reason_test.sh index 01b894842..8ed92a680 100755 --- a/bootstat/boot_reason_test.sh +++ b/bootstat/boot_reason_test.sh @@ -445,6 +445,10 @@ validate_reason() { *hw_reset* ) var="hard,hw_reset" ;; *usb* ) var="cold,charger" ;; *rtc* ) var="cold,rtc" ;; + *2sec_reboot* ) var="cold,rtc,2sec" ;; + *wdt_by_pass_pwk* ) var="warm" ;; + wdt ) var="reboot" ;; + *tool_by_pass_pwk* ) var="reboot,tool" ;; *bootloader* ) var="bootloader" ;; * ) var="reboot" ;; esac diff --git a/bootstat/bootstat.cpp b/bootstat/bootstat.cpp index fb0423a6e..529d0c942 100644 --- a/bootstat/bootstat.cpp +++ b/bootstat/bootstat.cpp @@ -228,7 +228,7 @@ const std::map kBootReasonMap = { {"2sec_reboot", 83}, {"reboot,by_key", 84}, {"reboot,longkey", 85}, - {"reboot,2sec", 86}, + {"reboot,2sec", 86}, // Deprecate in two years, replaced with cold,rtc,2sec {"shutdown,thermal,battery", 87}, {"reboot,its_just_so_hard", 88}, // produced by boot_reason_test {"reboot,Its Just So Hard", 89}, // produced by boot_reason_test @@ -790,7 +790,10 @@ std::string BootReasonStrToReason(const std::string& boot_reason) { {"hard,hw_reset", "hw_reset"}, {"cold,charger", "usb"}, {"cold,rtc", "rtc"}, - {"reboot,2sec", "2sec_reboot"}, + {"cold,rtc,2sec", "2sec_reboot"}, + {"!warm", "wdt_by_pass_pwk"}, // change flavour of blunt + {"!reboot", "^wdt$"}, // change flavour of blunt + {"reboot,tool", "tool_by_pass_pwk"}, {"bootloader", ""}, };