Android Restart reason mechanism

Source: Internet
Author: User

Reprint: http://blog.csdn.net/linux_devices_driver/article/details/17928663

Reboot Pass Parameters , making the boot into the fixed mode of the parameter (usually with our familiar bootloader and recovery , etc.), essentially in kernel shutdown is called to restart,

Write the mode value to the share memory , then in the boot bootloader stage, then read the memory,boot into the specified mode, if the match does not get up the normal boot, The following is the posted code;

Restart 2 different ways:

A:android_reboot (android_rb_restart2, 0, "rtcalarm");//Enter RTC Alarm mode

B:ADB reboot bootloader,adb reboot recovery; into our familiar bootloader and recorevy patterns.

RESTAR.C:

void*Restart_reason;/*function will be assigned to machine restart pointer*/voidMsm_restart (CharModeConst Char*cmd) {#ifdef Config_msm_dload_mode/*This looks is a normal reboot at this point.*/Set_dload_mode (0); /*Write Download Mode flags If we ' re panic ' ing*/Set_dload_mode (in_panic);/*Write Download Mode flags if Restart_mode says so*/ if(Restart_mode = =restart_dload) {Set_dload_mode (1); #ifdef Config_lge_crash_handler Writel (0x6d63c421, Restart_reason); GotoReset;#endif } /*Kill Download mode if Master-kill switch is set*/ if(!download_mode) Set_dload_mode (0);#endifPRINTK (Kern_notice"going down for restart now\n"); Pm8xxx_reset_pwr_off (1); if(cmd! =NULL) {  if(!STRNCMP (CMD,"bootloader",Ten) {__raw_writel (0x77665500, Restart_reason); } Else if(!STRNCMP (CMD,"Recovery",8) {__raw_writel (0x77665502, Restart_reason); } Else if(!STRNCMP (CMD,"oem-",4) ) {unsignedLongCode; Code= Simple_strtoul (cmd +4Null -) &0xFF; __raw_writel (0x6f656d00|code, Restart_reason); } Else{__raw_writel (0x77665501, Restart_reason); } } Else{__raw_writel (0x77665501, Restart_reason); } #ifdef Config_lge_crash_handlerif(In_panic = =1) Set_kernel_crash_magic_number (); Reset:#endif/* Config_lge_crash_handler */__raw_writel (0, Msm_tmr0_base +wdt0_en); if(! (Machine_is_msm8x60_fusion () | |Machine_is_msm8x60_fusn_ffa ()))  {MB (); __raw_writel (0, PSHOLD_CTL_SU);/*actually reset the chip*/Mdelay ( the); Pr_notice ("Ps_hold didn ' t work, falling back to watchdog\n"); } __raw_writel (1, Msm_tmr0_base +Wdt0_rst); __raw_writel (5*0x31f3, Msm_tmr0_base +wdt0_bark_time); __raw_writel (0x31f3, Msm_tmr0_base +wdt0_bite_time); __raw_writel (1, Msm_tmr0_base +wdt0_en); Mdelay (10000); PRINTK (Kern_err"restarting has failed\n");}Static int__init Msm_restart_init (void) {#ifdef Config_msm_dload_mode atomic_notifier_chain_register (&panic_notifier_list, &panic_blk); Dload_mode_addr= Msm_imem_base +dload_mode_addr, #ifdef config_lge_crash_handler lge_error_handler_cookie_addr= Msm_imem_base +lge_error_handler_magic_addr;#endifSet_dload_mode (download_mode);#endifMsm_tmr0_base=msm_timer_get_timer0_base (); Restart_reason= Msm_imem_base + restart_reason_addr;//Restart_reason is assigned memory addressPm_power_off=Msm_power_off;return 0;}

Lk:init.c

/*LK reads the restart value written by kernel*/unsigned check_reboot_mode (void) {unsigned Restart_reason=0; void*RESTART_REASON_ADDR = (void*)0x2a05f65c; /*Read reboot reason and scrub it*/Restart_reason=Readl (RESTART_REASON_ADDR); Writel (0x00, RESTART_REASON_ADDR); returnRestart_reason;}#defineRecovery_mode 0x77665502#defineFastboot_mode 0x77665500#defineAdb_reboot_mode 0x77665501/*Check reboot mode*/Reboot_mode=Check_reboot_mode ();#ifConfig_charing_while_mechine_trun_off {  externUnsignedintCustom_power_on_charger (void); if(Custom_power_on_charger () && reboot_mode && (reboot_mode!=fastboot_mode) && (Reboot_mode! =Adb_reboot_mode)) Boot_into_recovery=1; dprintf (0,"[charger]%s () Custom_power_on_charger () =%x check_reboot_mode () =%0x\n", __func__, Custom_power_on_charger (), Reboot_mode); } #endif  if(Reboot_mode = =Recovery_mode) {Boot_into_recovery=1; } Else if(Reboot_mode = =Fastboot_mode) {  GotoFastBoot;}

so familiar with this mechanism, we can add their own mode, such as alarm mode, Factory mode and so on;

Android Restart reason mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.