Android Reboot briefing

1. shutdown flow

0: run command

# reboot -p tired
# /system/bin/reboot -p tired

1: set property

system/core/reboot/reboot.c
function:
property_set("sys.powerctl", "shutdown,tired")
log:
[ 115.889033] init: Received sys.powerctl='shutdown,tired' from pid: 3200 (reboot)

2: init

init/reboot.cpp
function:
->HandlePowerctlMessage("shutdown,tired")
-->DoReboot(cmd=ANDROID_RB_POWEROFF, reason="shutdown,tired", reboot_target="")
log:
[ 115.997095] init: Reboot start, reason: shutdown,tired, reboot_target:

3.4 init

init/reboot_utils.cpp
function:
RebootSystem(cmd=ANDROID_RB_POWEROFF, rebootTarget="")
->reboot(RB_POWER_OFF)
log:
[ 120.301823] init: Reboot ending, jumping to kernel

5.6 bionic

bionic/libc/bionic/reboot.cpp
function:
reboot(mode=LINUX_REBOOT_CMD_POWER_OFF)
->__reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, mode, nullptr)
log:

  1. kernel
[   83.079073] reboot: Power down

2. reboot flow

The main difference is reboot will invoke kernel syscall __NR_reboot directly.

reboot target

boot target sys.powerctl kernel misc note
normal reboot,userrequested kernel_restart(“userrequested”)
bootloader reboot,bootoader kernel_restart(“bootloader”) (command=bootonce-bootloader)
fastbootd reboot,fastboot kernel_restart(“recovery”) (command=boot-recovery, status=, recovery=recovery –fastboot) w/ dynamic partition
bootloader reboot,fastboot kernel_restart(“bootloader”) (command=bootonce-bootloader) w/o dynamic partition
fastbootd - - (command=boot-fastboot, status=, recovery=recovery )
recovery reboot,recovery kernel_restart(“recovery”)
rescue - - (command=boot-rescue, status=, recovery=recovery)
sideload reboot,sideload kernel_restart(“recovery”)
sideload reboot,sideload-auto-reboot kernel_restart(“recovery”) (command=boot-recovery, status=, recovery=recovery –sideload_auto_reboot )