从内核空间关闭(嵌入式)Linux [英] Shutdown (embedded) linux from kernel-space

查看:226
本文介绍了从内核空间关闭(嵌入式)Linux的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Olinuxino(基于ARM9的平台)开发2.6.35内核的修改版本.我正在尝试修改电源管理驱动程序(特定于体系结构的部分).

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 part).

处理器是飞思卡尔i.MX23.该处理器具有一个称为"PSWITCH"的特殊"引脚,该引脚触发由电源管理驱动程序处理的中断. 如果按下该开关,系统将进入待机状态.这是通过在驱动程序中调用pm_suspend(PM_SUSPEND_STANDBY)来完成的.

The processor is a Freescale i.MX23. This processor has a "special" pin, called PSWITCH, that triggers an interrupt that is handled by the power management driver. If the switch is pressed,the system goes to standby. This is done in the driver by calling pm_suspend(PM_SUSPEND_STANDBY).

鉴于我的硬件设置,我想关闭系统. 所以我的问题是:

Given my hardware setup, I'd like to, instead, shutdown the system. So my question is:

内核空间进程触发干净的系统停止/关机的首选方式是什么?

我想那里有一个不错的小函数,但是到目前为止我找不到.

I suppose there's a nice little function call out there, but I couldn't find it so far.

我的内核代码(我正在处理的文件是arch/arm/mach-mx23/pm.c)可以在这里找到:

My kernel code (the file I'm working on is arch/arm/mach-mx23/pm.c) can be found here: github.com/spairal/linux-for-lobster, though my question calls for a general Linux kernel approach.

推荐答案

最通用的方法是驱动程序调用shutdown作为用户空间助手:

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);

(假设您已安装/sbin/shutdown二进制文件).这将彻底关闭用户空间,卸载文件系统,然后请求关闭内核并关闭电源.

(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.

但是,您也许可以做得更好-例如,如果您可以保证没有以读写方式安装的磁盘文件系统,则可以告诉内核线程调用kernel_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).

这篇关于从内核空间关闭(嵌入式)Linux的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆