Skip to content

Commit

Permalink
init: Support reboot reason with thermal warmreset
Browse files Browse the repository at this point in the history
Thermal shutdown could be due to tskin temperature or
battery temperature. Pass reason while rebooting the
system to reflect properly in boot.reason

Bug: 238464124
Test: Build and boot on device. Check reboot reason
for thermal shutdown and battery thermal shutdown with
thermal warmreset enabled.

Ignore-AOSP-First: AOSP already contains the change
Change-Id: I192562fed48ae7da7843e383362cd22a76ce479f
Merged-In: I192562fed48ae7da7843e383362cd22a76ce479f
  • Loading branch information
Sayanna Chandula committed Oct 11, 2022
1 parent 046a809 commit 3694b65
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions init/reboot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ static void DoReboot(unsigned int cmd, const std::string& reason, const std::str
if (sem_init(&reboot_semaphore, false, 0) == -1) {
// These should never fail, but if they do, skip the graceful reboot and reboot immediately.
LOG(ERROR) << "sem_init() fail and RebootSystem() return!";
RebootSystem(cmd, reboot_target);
RebootSystem(cmd, reboot_target, reason);
}

// Start a thread to monitor init shutdown process
Expand Down Expand Up @@ -636,7 +636,7 @@ static void DoReboot(unsigned int cmd, const std::string& reason, const std::str
// worry about unmounting it.
if (!IsDataMounted("*")) {
sync();
RebootSystem(cmd, reboot_target);
RebootSystem(cmd, reboot_target, reason);
abort();
}

Expand Down Expand Up @@ -769,7 +769,7 @@ static void DoReboot(unsigned int cmd, const std::string& reason, const std::str
LOG(INFO) << "Shutdown /data";
}
}
RebootSystem(cmd, reboot_target);
RebootSystem(cmd, reboot_target, reason);
abort();
}

Expand Down
9 changes: 6 additions & 3 deletions init/reboot_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ bool IsRebootCapable() {
return value == CAP_SET;
}

void __attribute__((noreturn)) RebootSystem(unsigned int cmd, const std::string& rebootTarget) {
void __attribute__((noreturn))
RebootSystem(unsigned int cmd, const std::string& rebootTarget, const std::string& reboot_reason) {
LOG(INFO) << "Reboot ending, jumping to kernel";

if (!IsRebootCapable()) {
Expand All @@ -127,10 +128,12 @@ void __attribute__((noreturn)) RebootSystem(unsigned int cmd, const std::string&

case ANDROID_RB_THERMOFF:
if (android::base::GetBoolProperty("ro.thermal_warmreset", false)) {
std::string reason = "shutdown,thermal";
if (!reboot_reason.empty()) reason = reboot_reason;

LOG(INFO) << "Try to trigger a warm reset for thermal shutdown";
static constexpr const char kThermalShutdownTarget[] = "shutdown,thermal";
syscall(__NR_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2,
LINUX_REBOOT_CMD_RESTART2, kThermalShutdownTarget);
LINUX_REBOOT_CMD_RESTART2, reason.c_str());
} else {
reboot(RB_POWER_OFF);
}
Expand Down
3 changes: 2 additions & 1 deletion init/reboot_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ void SetFatalRebootTarget(const std::optional<std::string>& reboot_target = std:
// so if any of the attempts to determine this fail, it will still return true.
bool IsRebootCapable();
// This is a wrapper around the actual reboot calls.
void __attribute__((noreturn)) RebootSystem(unsigned int cmd, const std::string& reboot_target);
void __attribute__((noreturn)) RebootSystem(unsigned int cmd, const std::string& reboot_target,
const std::string& reboot_reason = "");
void __attribute__((noreturn)) InitFatalReboot(int signal_number);
void InstallRebootSignalHandlers();

Expand Down

0 comments on commit 3694b65

Please sign in to comment.