Base on Android 4.2
Recovery and reboot processes
Part 1.reboot recovery process. 1,recoverysystem.java private static file Recovery_dir = new file ("/cache/recovery");
private static File Command_file = new file (Recovery_dir, "COMMAND"); Pm.reboot ("recovery"); = "Powermanager.java public void reboot (String reason) {try {
Mservice. Reboot (False, reason, true);
} catch (RemoteException e) {
}
}Mservice is an example of Powermanagerservice.java because public final class Powermanagerservice extends Ipowermanager.stub
=>powermanagerservice.javareboot () {shutdownorrebootinternal (false, confirm, reason, wait);}
private void Shutdownorrebootinternal (final Boolean shutdown, final Boolean confirm,
Final String reason, Boolean wait) {Shutdownthread.reboot(Mcontext, reason, confirm);}
=>shutdownthread.java
public static void Reboot (final context context, String reason, Boolean confirm) {
Mreboot = true;
Mrebootsafemode = false;
Mrebootreason = reason;
Shutdowninner(context, confirm);
}
Shutdowninner
-"Beginshutdownsequence Take two wake_lock let the system not standby, let the screen solid and then Sinstance.start (); This shutdwonthread instance start. Call its Run method
In the Run method, turn off Am,radio .... After that, call rebootorshutdown-public static void Rebootorshutdown (Boolean reboot, String reason)
-"powermanagerservice.lowlevelreboot (reason); Powermanagerservice again.
->powermanagerservice lowlevelreboot () systemproperties.set ("Sys.powerctl", "reboot," + reason); It was passed to kernel into reboot.
= "So where's the next step?" Reference: "after the KK Google will be shutdown/Restart the last transfer to the INIT process execution. Other process is notified by the system property SYS.POWERCTL init execution.
Sys.powerctl configuration in the init.rc, you can refer toOn property:sys.powerctl=*
Powerctl ${sys.powerctl}
Then execute the SYSTEM/CORE/INIT/BUILTINS.C#DO_POWERCTL function, call Android_reboot restart or shutdown. why can't adb reboot in Factory mode? The key is that ADB reboot can be restarted under normal circumstances because there is no definition in mediatek/config/{platform}factory_init.rc
On property:sys.powerctl=*
Powerctl ${sys.powerctl}
If you want to add this feature, you can only add these two lines to the factory_init.rc"Continue with
= "in init.rc and an associated on trigger 396 on property:sys.powerctl=*
397 Powerctl ${sys.powerctl}
= "Will call BUILTINS.C, reference between Reboot,recoveryint do_powerctl (int nargs, char **args)
=>return android_reboot (cmd, 0, reboot_target), cmd = ANDROID_RB_RESTART2//# define ANDROID_REBOOT.H in Android_rb_ RESTART2 0xdead0003reboot_target = Second reference recovery
= "/system/core/libcutils/android_reboot.c" in the Execution of Android_reboot ();
Case ANDROID_RB_RESTART2:
121 ret =__reboot(Linux_reboot_magic1, Linux_reboot_magic2,
122 Linux_reboot_cmd_restart2, ARG); arg = Recovery
= = This is defined in the bionic/libc/include/sys/reboot.h. Description This is a standard system call to extern int __reboot (int, int, int, void *);
Specifically located in Bionic/libc/arch-arm/syscalls/__reboot. S 1/* autogenerated by gensyscalls.py */
2 #include <asm/unistd.h>
3 #include <linux/err.h>
4 #include <machine/asm.h>
5
6 ENTRY (__reboot)
7 mov ip, R7
8 Ldr R7, =__nr_reboot
9 SWI #0
Ten mov R7, IP
CMN R0, # (Max_errno + 1)
Bxls LR
Neg R0, R0
b __set_errno
END (__reboot)
= "will eventually enter KERNELKERNEL/SYS.C case LINUX_REBOOT_CMD_RESTART2:
if (Strncpy_from_user (&buffer[0], ARG, sizeof (buffer)-1) < 0) {
ret =-efault;
Break
}
buffer[sizeof (buffer)-1] = ' + ';
Kernel_restart(buffer); Buffer = arg= Recovery
Break
=>machine_restart ()
=>arch/arm/kernel/process.cvoid Machine_restart (char *cmd)
{
Local_irq_disable ();
Smp_send_stop ();
/* Flush the console to make sure all the relevant messages make it
* out to the console drivers */
Arm_machine_flush_console ();
Arm_pm_restart(Reboot_mode, CMD);
/* Give A grace period for failure to restart of 1s */
Mdelay (1000); No restart completed within 1s reboot failed.
/* Whoops-the platform is unable to reboot. Tell the user! */
PRINTK ("Reboot failed-System halted\n");
Local_irq_disable ();
while (1);
}
= "void (*arm_pm_restart) (char str, const char *cmd) = arm_machine_restart;=" void Arm_machine_restart (char mode, const CHA R *cmd) {... aml_write_reg32 (P_AO_RTI_STATUS_REG1, Reboot_reason);//This flag register ...
Arch_reset (mode, cmd); mode = ' h ' cmd = ' recovery '}
It's almost done, so try it.
Then it is necessary to understand this register P_AO_RTI_STATUS_REG1 at the next boot, when Uboot is read. This enables the state to be saved after some shutdown.
Android shutdown (reboot) process