It's not executed. The command has a corresponding numerical value, which is passed to reboot mode driver to write to the reboot reason register. After rebooting the bootloader reads the reason value from the register and decides to start e.g. fastboot, recovery, etc depending on the command chosen.
E.g. phones based on Qualcomm MSM8916 SOC have Power On device, which contains such a reboot reason register. The commands (in the form mode-<command>
) and corresponding reason values are described in its device tree:
pon@800 {
compatible = "qcom,pm8916-pon";
reg = <0x800>;
mode-bootloader = <0x2>;
mode-recovery = <0x1>;
Thus when reboot(2)
is called with bootloader
command string, the driver for Power On device writes 0x2
to the reboot reason register.
On next boot the bootloader (e.g. lk2nd) checks the reason register and boots into appropriate mode (from aboot_init()
in aboot.c):
#if USE_PON_REBOOT_REG
reboot_mode = check_hard_reboot_mode();
#else
reboot_mode = check_reboot_mode();
#endif
if (reboot_mode == RECOVERY_MODE)
{
boot_into_recovery = 1;
}
else if(reboot_mode == FASTBOOT_MODE)
{
boot_into_fastboot = true;
}
RECOVERY_MODE
and FASTBOOT_MODE
are defined in lk2nd reboot.h and have the same values as in device tree above (except "fastboot" is called "bootloader" there):
#define RECOVERY_MODE 0x01
#define FASTBOOT_MODE 0x02
I don't know of utility that can reboot with the command to test this behavior, but you can do it in python with ctypes:
python -c "import ctypes; ctypes.CDLL('libc.so').syscall(142, 0xfee1dead, 0x20112000, 0xa1b2c3d4, b'bootloader')"
142
above is reboot(2)
syscall number on arm64. Hex magic numbers are from man 2 reboot
.