Quickest way to modify/reload existing Linux driver - linux

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.

Related

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

Booting a newly compiled linux kernel

I have started reading the book Essential Linux Device Drivers. I am following the process for compiling and booting into a new kernel. However I am unable to boot into the newly compiled kernel - I select the new kernel in grub and then ..nothing...the screen just stays the same.
Here are the steps I am taking, as described in the book (I am using kernel 2.6.24 as that is what the book is based on) -
cd /usr/src/linux-2.6.24 (the base dir of the kernel I downloaded)
make clean
cp arch/x86/configs/i386_defconfig .config
make bzImage cp arch/x86/boot/bzImage /boot/vmlinuz
The book says that 'you might need to alert your bootloader about the arrival of the new boot image. If you are using the GRUB bootloader, it figures this out automatically'.
Well it didn't figure it out automatically in my case as there was no option to select this kernel in GRUB. So I did it manually by typing update-grub in the terminal. And this didn't work either. However once I changed the filename from vmlinuz to vmlinuz-2.6.24 and type update-grub it picked it up. So on page 11 of the book there seems to already be multiple things left out...
The book says to then reboot the machine.
Anyway, I am now able to select this kernel in GRUB but as I said above it doeesn't boot properly, the screen just goes blank and never changes. So am I missing something? I have followed the instructions in the book exactly.
Most automatic grub setups include kernel options to hide the messages generated as the kernel attempts to boot. For example:
/boot/vmlinuz-x.x.x.x-generic root=UUID=something ro quiet splash
While on the grub menu line of the kernel you wish to boot, press 'e' to temporarily edit it, and delete options such as quiet and splash (but leave the ro).
Then boot the temporarily modified line, and see the progress messages in order to get an idea where the boot is failing.
The default configuration probably requires an initrd (e.g. because the file system and root device needs their driver, from modules, which is what initrd provides).
You could either configure your kernel appropriately (carefully enabling as in-kernel, not in-modules, the essential drivers) for your particular hardware, or use a procedure to build a kernel package with its initrd.
You should find a procedure appropriate for your linux distribution and habits, e.g. something like this or that. I am using on Debian:
time fakeroot make-kpkg -j2 --initrd --revision=3.4.2 --append-to-version=-amd64 binary

Want to permanently mount Kernel-Driver into System

I wrote my own kernel driver for a usb-device. After I compile it with make, I have the kernelobejct file usbdriver.ko and with sudo insmod usbdriver.ko I can install and then use it.
But if I restart my Debian, I need to do do insmod again to use it ...
How can i mount/install that driver permanently into the system, so that it loads when the os is starting? And how can I also grant other users than only root to access the asscoiated device-files under /dev/usbdriver0?
Copy your driver to /lib/modules/$(uname -r)/kernel/drivers/ and add it to /etc/modules: http://www.cyberciti.biz/tips/compiling-linux-kernel-module.html.
I don't know but I think it's in the source code somewhere.

writing to /sys/class/gpio/export failing

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.

Resources