Shutdown (embedded) linux from kernel-space

前端 未结 1 1261
谎友^
谎友^ 2021-01-05 09:58

I\'m working on a modified version of the 2.6.35 kernel for Olinuxino, an ARM9 based platform. I\'m trying to modify the power management driver (the architecture specific p

相关标签:
1条回答
  • 2021-01-05 10:25

    The most general way would be for your driver to invoke shutdown as a userspace helper:

    static const char * const shutdown_argv[] = 
        { "/sbin/shutdown", "-h", "-P", "now", NULL };
    
    call_usermodehelper(shutdown_argv[0], shutdown_argv, NULL, UMH_NO_WAIT);
    

    (Presuming you have a /sbin/shutdown binary installed). This will shut userspace down cleanly, unmount filesystems and then request the kernel shutdown and power off.

    However, you may be able to do better than this - for example if you can guarantee that there's no disk filesystems mounted read/write, you could tell a kernel thread to invoke the kernel_power_off() function (it shouldn't be done from interrupt context).

    0 讨论(0)
提交回复
热议问题