2012年6月1日 星期五

android reboot process

  1. frameworks/base/core/java/android/os/Power.java  android_os_Power_reboot()
  2. frameworks/base/core/jni/android_os_Power.cpp 
    reboot()
  3. bionic/libc/unistd/reboot.c
    reboot(__reboot)
  4. bionic/libc/arch-arm/syscalls/__reboot.S
  5. kernel/arch/sh/kernel/reboot.c
    struct machine_ops machine_ops = {
        .power_off  = native_machine_power_off,
        .shutdown   = native_machine_shutdown,
        .restart    = native_machine_restart,
        .halt       = native_machine_halt,
    }
  6. bionic/libc/include/sys/linux-syscalls.h
    #define __NR_reboot                       (__NR_SYSCALL_BASE + 88)
  7. ./arch/arm/kernel/calls.S
    __NR_reboot 就是系统函数sys_reboot
  8. ./kernel/sys.c

    kernel_restart
    {
          kernel_restart_prepare(cmd);  
        if (!cmd)
            printk(KERN_EMERG "Restarting system.\n");
        else
            printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd);
        kmsg_dump(KMSG_DUMP_RESTART); 
        machine_restart(cmd);

    }

    void kernel_restart_prepare(char *cmd)
    {
        blocking_notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
        system_state = SYSTEM_RESTART;
        usermodehelper_disable();
        device_shutdown();
        syscore_shutdown();
    }

    void kernel_power_off(void)
    {
        kernel_shutdown_prepare(SYSTEM_POWER_OFF);
        if (pm_power_off_prepare)
            pm_power_off_prepare();
        disable_nonboot_cpus();
        syscore_shutdown();
        printk(KERN_EMERG "Power down.\n");
        kmsg_dump(KMSG_DUMP_POWEROFF);
        machine_power_off();
    }


  9. kernel/arch/arm/kernel/process.c
    void machine_shutdown(void)
    {
    #ifdef CONFIG_SMP
        smp_send_stop();
    #endif
    }

    void machine_halt(void)
    {
        machine_shutdown();
        while (1);
    }

    void machine_power_off(void)
    {
        machine_shutdown();
        if (pm_power_off)
            pm_power_off();
    }

    void machine_restart(char *cmd)
    {
        machine_shutdown();
        arm_pm_restart(reboot_mode, cmd);
    }
  10. If you would like to trace power_off
    kernel/driver/mfd/xxxx_poweroff.c
    You will see:
    pm_power_off=xxxx_poweroff

沒有留言:

張貼留言