Tiny Core Linux

General TC => General TC Talk => Topic started by: gharig on April 28, 2022, 01:41:51 PM

Title: loading driver with modeprobe or insmod with parameters
Post by: gharig on April 28, 2022, 01:41:51 PM
Hello,

So I'm trying to figure out why parameters being passed while loading a kernel module using modprobe or insmod  are not working as to the way I believe they should work.

Code: [Select]
sudo modprobe someDriver Param1=123 Param2=456 OR
Code: [Select]
sudo insmod ./someDriver.ko Param1=123 Param2=456
The driver assigns default value for Param1 = 0 and Param2 = 1

The driver prints out the values Param1 = 0 and Param2 = 1 in dmesg
What I expect is that Param1 = 123 and Param2 = 456

Is the busybox version of modprobe the issue?
Maybe there is some small detail that I'm overlooking.

Thanks
gharig


I mentioned this earlier in another post too.
http://forum.tinycorelinux.net/index.php/topic,24005.msg151255.html#msg151255 (http://forum.tinycorelinux.net/index.php/topic,24005.msg151255.html#msg151255)
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: Rich on April 28, 2022, 02:19:50 PM
Hi gharig
Based on your other post, it sounds like like you are not reading the values being passed to your module.
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: gharig on April 28, 2022, 03:27:21 PM
Hi Rich,

My understanding is that the macro module_param( variable_name, type, permission ) handles this when the kernel module is loaded.


this is for a very simple kernel module
Code: [Select]

//.......
static int Param1= 0;
static int Param2 = 1;

module_param( Param1, int, 0 );
module_param( Param2, int, 0 );

//.........


static int __init test_init(void)
{
 
        printk(KERN_INFO "Param1 = %d  \n", Param1);
        printk(KERN_INFO "Param2 = %d  \n", Param2);
        printk(KERN_INFO "Kernel Module Loaded Successfully...\n");
    return 0;
}

static void __exit test_exit(void)
{
    printk(KERN_INFO "Kernel Module Removed Successfully...\n");
}

module_init(test_init);
module_exit(test_exit);




So after I make and install the module I can call modprobe with the values I pass in with the parameters.

Code: [Select]
sudo modprobe someDriver Param1=123 Param2=456

So that when I look at dmesg I should see the following

Code: [Select]
Param1=123
Param2=456
Kernel Module Loaded Successfully...

So when you say that I'm not reading the values I'm a bit confused.
Any light you could shed on me would be greatly appreciated.

Thanks
gharig
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: Rich on April 28, 2022, 04:55:20 PM
Hi gharig
My understanding is that the macro module_param( variable_name, type, permission ) handles this  ...

Here you set the variable name and type.
Quote
Code: [Select]
module_param( Param1, int, 0 );
module_param( Param2, int, 0 );
For permission you used 0. I think that's your problem. Try it like this:
Code: [Select]
module_param( Param1, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
module_param( Param2, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: gharig on April 28, 2022, 06:15:32 PM
Hi Rich,

Sorry to be a pest, but I tried your suggestion for setting the permissions in module_param().
The results are the same.  So I have attached the test.c and the makefile.  Maybe when you get a chance you can see what is wrong.

If you are to see the parameters change on your system then maybe it might be something with my card.

I'm running Tinycore 13 32bit on a Winsystems C412 that has the following:
1 GHz DMP Vortex86DX3 Processor (Dual core) CPU
2 GB DDR3-LV System RAM
Low Power
10 Year Availability
Rugged Design for Demanding Environments
-40°C to +85°C Operating Temperature Range
PC/104-Plus Small Form Factor
Shock and Vibration Tested
Connectivity and I/O for Embedded Systems
Dual Ethernet (1x Fast Ethernet, 1x Gigabit)
4x USB 2.0
24x GPIO 5V with Event Sense
4x Serial Ports (2x RS-232, 2x RS-232/422/485)
Parallel Port LPT
Audio
Graphics Support
Dual video output (VGA, LVDS with digital backlight dimmer)
 


I haven't tried this on my Hyper-V, but I will tonight when I get home, and let you know the results from that system.


As always thanks for your help.
gharig

Title: Re: loading driver with modeprobe or insmod with parameters
Post by: Rich on April 28, 2022, 07:21:29 PM
Hi gharig
What happens if you change this:
Code: [Select]
int Param1, Param2;to this:
Code: [Select]
static int Param1=10;
static int Param2=20;

By the way, parameters should have a default value in case nothing is passed in.
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: gharig on April 28, 2022, 10:39:01 PM
Hi Rich,

Hi finally got home, from another great day at work. I must say that I have to pinch myself from time to time, I get paid to code. Anyway I did as you suggested, I changed the variables to be static, fried up the Hyper-V, ran the development setup compile.tcz and the lot.  Loaded the Tinycore modules.  Modified the code to change the variables to static. 

Code: [Select]

static int Param1=10;
static int Param2=20;


and then ran the following:
then I ran the following:

Code: [Select]

make

sudo make install

sudo modprobe test Param1=345 Param2=759



The param in dmesg values are:
Param1=10
Param2=20

But I'm expecting:
Param1=345
Param2=759

So this is consistant on two seperate systems, the winsystem c412 and my home computer running Tinycore 13 in Hyper-V

Still at a loss.

So I'm curious if you  built the test.c module  from files I attached in an earlier post, and did you end up getting a different result?

Thanks For all your help
gharig



Title: Re: loading driver with modeprobe or insmod with parameters
Post by: Rich on April 29, 2022, 11:42:55 AM
Hi gharig
I setup a build environment under TC10 x86 and tried several examples I found online. I had no luck setting any
parameters when loading any of those examples. I was able to make modifications to parameters through
/sys/module/DRIVERNAME/parameters.  This was confirmed by having the module print the parameters in the
routine listed in  module_exit().
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: gharig on April 29, 2022, 01:31:41 PM
Hi Rich,

Thank you for looking and confirming that you are seeing the exact same problem that I was seeing, I thought I was going crazy.
Yes I can probably do a work around by setting the parameters in /sys/module/DRIVERNAME/parameters and using the module_param_cb() function, and thank for confirming that too, but I would prefer not too if possible.
And for what I'm doing I could also create two different drivers with preassigned values, and just load the driver I want to use. There is no law saying that I can't do that.

So back to my first thought...
Do you think that it could be something in the Busybox tools for modprobe and insmod on how it got built out?  I have not checked yet, but will later this weekend, I'm curious to find out  if the same behavior occurs in the 64bit version. I will report back to you my findings.
Then my last question..., is this something that could be looked at, so that future versions will function the way they are suppose too?

Thanks for all your help. I still consider you to be a true genius....
gharig

Title: Re: loading driver with modeprobe or insmod with parameters
Post by: Juanito on April 29, 2022, 02:29:30 PM
Did you try the module-init-tools extension?
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: gharig on April 29, 2022, 02:40:45 PM
Hi Juanito,

I have not tried the module-init-tools extensions, I'm did not know about this, but I will, and I will let you know my results.

Thanks
gharig
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: gharig on April 29, 2022, 03:51:27 PM
Hi Juanito and Rich,

The suggestion that Juanito made, to install module_init_tools.tcz was just the ticket.
Now the test program that I created reports the correct values.

So when I run
Code: [Select]
sudo insmod ./test.ko Param1=345 Param2=567

In dmesg I see the following.

Code: [Select]
Param1=345
Param2=567

Thank You Very Much For your help.
Case Closed...


Thanks
gharig 
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: Rich on April 29, 2022, 05:00:00 PM
Hi gharig
... Case Closed...
Not so fast. Now that I know the problem wasn't the code, but a problem with the busybox loaders, I decided to
try something. I added the following to  /etc/modprobe.conf:
Code: [Select]
options hello-5 myint=7Then I ran:
Code: [Select]
modprobe hello-5Checking dmesg showed that  myint  had been changed from 1 to 7. So the busybox version of modprobe checks
/etc/modprobe.conf  for options.
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: Rich on April 29, 2022, 05:54:46 PM
Hi gharig
Although I did not try it, passing options as kernel parameters is something else that should work.

According to  Kernel Parameters  found here:
https://mjmwired.net/kernel/Documentation/kernel-parameters.txt
Quote
... modprobe looks through the kernel command line (/proc/cmdline) and
collects module parameters when it loads a module ...

Adding this boot code should have the same effect as using  /etc/modprobe.conf:
Code: [Select]
hello-5.myint=7
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: curaga on April 29, 2022, 11:33:46 PM
If there's a bug on busybox's modprobe params on command line, please report it to busybox.

edit: Oh, no bug, but a missing config option.
# CONFIG_FEATURE_CMDLINE_MODULE_OPTIONS is not set
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: Juanito on April 30, 2022, 12:55:40 AM
Hmm - I didn't unset that option, which suggests that when it was introduced the default was the opposite to what existed previously...
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: Juanito on April 30, 2022, 05:14:42 AM
Maybe you could try tc-13.1rc1 to check if things now work with busybox modprobe?

It seems to work for me:
Code: [Select]
sudo modprobe ipv6 disable_ipv6=1
cat /sys/module/ipv6/parameters/disable_ipv6
1
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: Rich on April 30, 2022, 05:45:21 AM
Hi Juanito
It worked under TC4, but not under TC9:
Code: [Select]
tc@box:~$ sudo modprobe usblp
tc@box:~$ cat /sys/module/usblp/parameters/proto_bias
-1
tc@box:~$ sudo modprobe -r usblp
tc@box:~$ sudo modprobe usblp proto_bias=1
tc@box:~$ cat /sys/module/usblp/parameters/proto_bias
-1
tc@box:~$
Title: Re: loading driver with modeprobe or insmod with parameters
Post by: gharig on April 30, 2022, 04:40:06 PM
Hi Rich and everyone else....

So today I wanted to verify what Rich suggested by adding options to the /etc/modprobe.conf  And slicker that slick it worked.
I did not load the module_init_tools.tcz.  I'm running Tinycore 13 and I'm only loading compile.tcz

So I added a line to modprobe.conf for my test.ko kernel module which can take two parameters Param1 and Param2, my default values for the test module program are Param1=10 and Param2=20.

Code: [Select]
# /etc/modprobe.conf: Modeprobe config file.
#
options test Param1=345 Param2=789

and when I ran dmesg:
Param1=345
Param2=789

Rich also talked about adding a boot code.
So I commented out the options I added to /etc/modprobe.conf earlier.

Then I modified the file /mnt/sda1/tce/boot/etxlinux/etxlinux.conf

Code: [Select]
#orignal
DEFAULT core
LABEL core
KERNEL /tce/boot/vmlinuz
INITRD /tce/boot/coregz
APPEND quiet syslog waitsub=5:UUID="some long guid" tce=UUID="some long guid"

and changed it to:
Code: [Select]
#new
DEFAULT core
LABEL core
KERNEL /tce/boot/vmlinuz
INITRD /tce/boot/coregz
APPEND quiet syslog test.Param1=111 test.Param2=222 waitsub=5:UUID="some long guid" tce=UUID="some long guid"

 I then rebooted Tinycore13, and reloaded my test module
Code: [Select]
#run as root
 modeprobe test


And the results in dmesg were:
Param1=111
Param2=222

This was success

I then uncommented out the /etc/modprobe.config file and unloaded my test module and made sure everything is clear.
I'm testing to see which has precedence, the boot code vs the modprobe.conf
I reloaded the test module looked at dmesg
And saw
Param1=111
Param2=222

The boot code is the winner it has precedence over modprobe.conf

Now I went to test insmod to see if it to would use the boot code or modprobe.conf
Code: [Select]
#run as root
 insmod ./test.ko
insmod  dose not use the bootcode nor dose it use modprobe.conf, the values in dmesg were the default value for the test module program
Param1=10
Param2=20

So Rich the boot codes work too.

Thanks Everyone
gharig

PS
cant wait to see Tinycore 13.1