Android 关机(reboot)流程(2)

=》最后会进入Kernel
kernel/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] = '\0';

kernel_restart(buffer);  //buffer = arg= recovery
          break;

=>machine_restart()

=>arch/arm/kernel/process.c
void 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); // 1s之内没有restart完成就reboot失败。

/* Whoops - the platform was 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 char *cmd)
{
...
aml_write_reg32(P_AO_RTI_STATUS_REG1, reboot_reason); //这一个标志寄存器
...

arch_reset(mode, cmd); // mode = 'h' cmd = "recovery"
}

差不多了,尝试就如此吧。

那么有必要了解这个寄存器P_AO_RTI_STATUS_REG1在下次启动的时候,uboot是什么时候读。这就可以实现一些关机之后的状态保存。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/5386ae77c760d0d9a845d0730a2dbf94.html