Driver reading configuration file

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Is it possible for a Linux device driver to read a variable put into a
configuration file, e.g., modules.conf, when it is loaded?  If so
how?  What is the syntax in the configuration file and what is the
syntax in the driver?  This variable would be created specifically for
this driver.

I have seen documentation that hinted at a Linux device driver reading
a configuration file, but I have not found an example as to how to
actually do it in the configuration file and in the driver.

I am running Linux 2.4.26 on an MPC8248.

Re: Driver reading configuration file
Quoted text here. Click to load it

I don't know about files, but you can send all the values you want to
a kernel module at load time by using module parameters.  Module
parameters take the format  "parameter=value"
eg:
insmod mymodule iobase=0x300 irq=3 mystring="this is a cool string"

Re: Driver reading configuration file
Quoted text here. Click to load it

Would iobase and mystring be global variables in the module that could
read as usual?  Would they need to be declared in the module?

I am not sure if that will work.  We want to put the variable into a
configuration file that both the application and the driver that is
closely related to it can read.

Re: Driver reading configuration file

Quoted text here. Click to load it


If you want to open a file and read the contents from within your kernel
module, you are to be discouraged. It's possible but frowned upon, and
the way mentioned to you is simpler and better. To recap, the parameters
for the module are passed via the module loader, which is either
explicitly invoked as part of startup scripts for your program, or pulled
in from the configuration files by the automatic module loading facility
such as devfs.

There is one other way: load or statically include your module, and then
have your application open the corresponding device, and pass the
parameter via a special ioctl() syscall.


--
        Przemek Klosowski, Ph.D. <przemek.klosowski at gmail>

Re: Driver reading configuration file
Quoted text here. Click to load it

Yes.  The module parameters will have to be normal global variables.
Yes they will have to be declared in the module and will have to be
associated with a module parameter with the macro
"module_param( iobase, int, 0)".
If you really want it to use the same config file, I suggest you use
the IOCTL method that Przemek has described.

Re: Driver reading configuration file
I wrote a script that reads the variable's value in the config file
and then passed it to the driver via insmod.  This works fine.  Thanks
for the recommendations.

Site Timeline