When ever i press the button it need to run a shell command

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

When ever i press the button it need to run a shell command

Jump to solution
1,762 Views
aravinthkumarja
Senior Contributor II

Hi All,

I'm using iMX6 sabresd board and Android 6 platform. Any one of gpio i configured as button.

When ever the user press the button, i need to run a shell command(or shell script) on board.

How can i do this .?

Regards,

Aravinth

Labels (4)
0 Kudos
Reply
1 Solution
1,429 Views
aravinthkumarja
Senior Contributor II

Thanks for your response Carlos. I have used call_usermodehelper function to call shell command in kernel.

Regards,

Aravinth

View solution in original post

0 Kudos
Reply
6 Replies
1,428 Views
Carlos_Musich
NXP Employee
NXP Employee

Hi,

in the following link you will find the code for a .ko module which handles a GPIO interrupt and the device tree configuration required for this.

Issue with configuring GPIO as an interrupt - i.MX6Q 

For the shell command you can just use a system call E.g. sytem("command");


Regards,
Carlos

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,428 Views
aravinthkumarja
Senior Contributor II

Hi Carlos,

Thanks for your response.  For system function what library i have to use in imx6 kernel.?

Regards,

Aravinth

0 Kudos
Reply
1,429 Views
Carlos_Musich
NXP Employee
NXP Employee

it is stdio.h, this is a general C question, you can find a lot of information if you Google "linux shell command in c program" or "linux c system function".

0 Kudos
Reply
1,429 Views
aravinthkumarja
Senior Contributor II

Hi carlos,

I have used system function in normal c application. But in kernel code we can't add stdio.h. So i'm not able to use system function in kernel.!

Regards,

Aravinth

0 Kudos
Reply
1,429 Views
Carlos_Musich
NXP Employee
NXP Employee

You can make an application that communicates with the kernel module. So the module will use copy_to_user function to tell the applications that a button was pressed and the application will execute the shell command.

0 Kudos
Reply
1,430 Views
aravinthkumarja
Senior Contributor II

Thanks for your response Carlos. I have used call_usermodehelper function to call shell command in kernel.

Regards,

Aravinth

0 Kudos
Reply