Android系统关机的全流程解析

2019-12-10 19:02:04刘景俊

好的,只是一个函数指针,而且做了全局操作,整个kernel都可以调用它。以高通msm7x30为例,在arch/arm/mach-msm/pm2.c中对这个函数指针进行了赋值:

pm_power_off = msm_pm_power_off; 

msm_pm_power_off的具体实现就不再跟踪了,各家的都不一样,跟下去没有太大意义。现在只要知道,我分析的这个kernel是给了这个函数指针赋值的,所以不为空,关机命令将正常执行。
接下来就是这个函数的正题了,对用户命令进行解析操作,同时这个过程是用reboot_mutex互斥锁来进行保护的,以保证同一时间只可能有一个解析过程,避免冲突。
下边贴出所有关机重启相关的命令定义:

/* 
 * Commands accepted by the _reboot() system call. 
 *    
 * RESTART   Restart system using default command and mode. 
 * HALT    Stop OS and give system control to ROM monitor, if any. 
 * CAD_ON   Ctrl-Alt-Del sequence causes RESTART command. 
 * CAD_OFF   Ctrl-Alt-Del sequence sends SIGINT to init task. 
 * POWER_OFF  Stop OS and remove all power from system, if possible. 
 * RESTART2  Restart system using given command string. 
 * SW_SUSPEND Suspend system using software suspend if compiled in. 
 * KEXEC    Restart system using a previously loaded Linux kernel 
 */    
     
#define LINUX_REBOOT_CMD_RESTART  0x01234567 
#define LINUX_REBOOT_CMD_HALT    0xCDEF0123 
#define LINUX_REBOOT_CMD_CAD_ON   0x89ABCDEF 
#define LINUX_REBOOT_CMD_CAD_OFF  0x00000000  
#define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC 
#define LINUX_REBOOT_CMD_RESTART2  0xA1B2C3D4 
#define LINUX_REBOOT_CMD_SW_SUSPEND 0xD000FCE2 
#define LINUX_REBOOT_CMD_KEXEC   0x45584543 

注释中的说明很详细了,比较陌生的就是关于CAD,其实就是用来想用Ctrl+Alt+Del操作的;然后SW_SYSPEND是软件休眠;KEXEC就太高端了,属于内核的一个补丁,用来利用老内核重启,详细资料:http://www.easck.com/developerworks/cn/linux/l-kexec/?ca=dwcn-newsletter-linux