writing to /sys/class/gpio/export failing - gpio

I am working on a project which needs me to configure the gpio pins and add sensors to atom board. The kernel has configured the gpio ... CONFIG_GPIO_SYSFS=y is one of the kernel options.
I am using fedora version 2.6.29-10
But i am not able to write to export file in gpio folder using
GPIO=22 // to add pin 22 to userspace
echo $GPIO > /sys/class/gpio/export
I get the error
bash: echo: write error: Invalid argument
I also tried the same with sudo and sh -c but no use ,unless i can expose these pins to userspace i cant write any code.What am i doing wrong?
Is the problem with the kernel version or some other kernel options needs to set??
Thanks in advance

Well , for the GPIO pins to be used as I have described. you need to load a module using insmod or modprobe.
After a long wait i got those modules from the manufacturers of our atom board.
The problem described above is now solved.

Related

Adding kernel module to Debian

I have imx6-quad and Debian Jessie installed on it. Here is the full info about (uname -a):
Linux linaro-alip 4.1.15-g5599520 #1 SMP PREEMPT Sun Jan 8 13:03:20 IST 2017 armv7l GNU/Linux
I'm trying to run tunslip application for CC1350 Launchpad, but there is no kernel module "tun" in my OS. When I run command modprobe tun, I given an error:
modprobe: FATAL: Module tun not found.
At this point, I don't know how to install tun module to my Debian. I even don't know where to start. Is it possible to add tun module to running operation system or should I compile whole kernel from scratch? If I can add kernel module, how could I add to running OS?
Any help is too precious for me.
So, to sum up the discussion in the comments in case someone else will come here with the same problem:
Unfortunately, the precompiled kernel image provided by Variscite here doesn't come with tun support at all. Neither in modules nor compiled into the kernel.
If you want tun support, you will have to compile the kernel in your own. Sources can be found here on github.
Previous Answer:
Since I'm not allowed to comment yet, please take this less as an answer but more as a suggestion where to look for a solution.
What does the following command give you?
cat /boot/config-4.1.15-g5599520 | grep CONFIG_TUN
It should say CONFIG_TUN=m. If it doesn't, it may be that your kernel already supports tun devices.
Have you tried searching for tunmodules in /lib/modules? If not, run
find /lib/modules/ -name '*tun.ko*'
and let us know what it gives you.
as you are building your kernel. there are a couple of methods one is to compile the module separately and to install it on the existing image. The other is to create the tun module along with the kernel and the sdcard image creation will take care of your module.
TO build tun module. use menuconfig from the kernel folder. search for something matching to CONFIG_TUN if its is a module change its value to m. Rebuild and create the sdcard again. This is the easy way.
You can also craete the module separately and then bring the module to your filesystem but that can be more error prone.

XRUSB raspberry pi

I'm working with a raspberry pi connected with xrusb to a controller using python.I use make file to Compile and install the common usb serial driver module and it works fine. After reboot i have problem. The driver is lost. I have to install the module again using this
modprobe usbserial
insmod ./xr_usb_serial_common.ko
Any idea?
Now my answer might be off because of the way you say "install the driver". I bet the make script most likely just loaded the driver just like you did via modprobe.
In order to get the module to be loaded at boot time, you need to tell udev what to load/do during bootup. And tell the kernel to load your driver.. Otherwise it assumes you don't want it to be loaded at boot time.
Either you can do a automatic module handling via:
#nano /etc/modules-load.d/usbserial.conf
usbserial
or, you can specify options:
#nano /etc/modprobe.d/usbserial.conf
options usbserial parameter_name=parameter_value
Here's some documentation on how this works:
http://man7.org/linux/man-pages/man5/modules-load.d.5.html
https://wiki.archlinux.org/index.php/kernel_modules
(Even if you're not running Arch on your RPi, they still have one of the best documentation websites for Linux out there. User friendly, in depth etc. So apply the information there to your Distribution, they should be very much the same this day and age)
I found maybe a temporary solution so i can finish my project and look for the best way later.
I make a script to run after reboot to load the driver.
use:
sudo crontab -e
then go to the bottom and write
#reboot bash /your/path/script/script.sh
`

How to disable the autoloading of a specific module in Linux

I compiled my Linux kernel according to the Linux Device Driver Chapter 4: Debugging Techniques. After I loaded my first hello world module and then checked the output by dmesg, however, all I can see is evbug: ........
I know I can turn off evbug's output by execute sudo rmmod evbug. But, obviously, it is inconvenient to execute this command after each reboot.
How could I disable this module's autoloading? I just want to load it manually when I need it.
You need to blacklist the module. For debian systems see https://wiki.debian.org/KernelModuleBlacklisting. For redhat systems see https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/rescuemode_drivers-blacklisting.html

Linux: load module based on another module

Is it possible to dynamically load (via MOD_ALIAS() maybe?) a module that requires another module to first be loaded?
Background: I have a USB->I2C bridge on my system, and attached to the i2c end is a touchscreen. The kernel module that brings up the i2c automatically loads/unloads whenever the USB cable is connected/disconnected. I'm looking for a way to also load/unload the touchscreen driver on the same events.
You're talking about module dependencies, generated by depmod -A. The actual dependency information is stored in /lib/modules/version/modules.dep.
If /lib/modules/2.6.29/kernel/a.ko depends on b.ko (in the same directory) you could add the line:
/lib/modules/2.6.29/kernel/a.ko: /lib/modules/2.6.29/kernel/b.ko
To create the dependency.
What you want is modprobe.d
Add a <module>.conf file where <module> is the name of your kernel module that is dynamically loaded.
Define the install and remove options within the above conf file to run the relevant commands instead of the modprobe (in the required order).
If you want to automatically load the module bob after loading the module alice,
# /etc/modprobe.d/alice.conf
install alice /sbin/modprobe --ignore-install alice; /sbin/modprobe bob;"
The --ignore-install, stops the modprobe from running the same install command again.
Similarly define the remove section within the same conf file.
For more details, checkout the man page of modprobe.d.

Quickest way to modify/reload existing Linux driver

I am trying to understand an existing Linux Wi-Fi driver for a USB Wi-Fi adapter. While I can read the C code, I would also like to be able to insert debug/print statements at certain critical spots in the driver to see how it behaves when executed. On a Linux system, after modifying the driver code, how does one go about loading it into the kernel in such a way that it replaces the old driver? Is there a way to "hotplug substitute" it straight over the old driver, or is it more complicated than that?
I intend on doing this inside of an expendible virtual machine, so I am not concerned about messing up the original driver, for what it counts.
If the driver is compiled as a module, all you need to do is to add your debug print outs, compile the module, rmmod the original module, insmod your new module and initiate the WLAN connection as usual.
If you want to test and edit on the fly :
lsmod to find the module name
rmmod it
edit source
Make sur you got a Makefile : obj-m := module_name.o
recompile (on Ubuntu) : make -C /usr/src/linux-headers-'uname -r' M='pwd' modules
insmod module_name.ko
If it's a device module, you might want to rm any devices in /dev, then do a mknod to remake them (see mknod man) and finally chmod to correct rights.

Resources