Discussion:
Driver reading configuration file
(too old to reply)
Bill
2008-02-04 01:19:56 UTC
Permalink
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.
Janaka
2008-02-04 01:49:25 UTC
Permalink
Post by Bill
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.
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"
Bill
2008-02-04 01:55:35 UTC
Permalink
Post by Janaka
Post by Bill
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.
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"
insmod mymodule iobase=0x300 irq=3 mystring="this is a cool string"
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.
przemek klosowski
2008-02-04 05:38:30 UTC
Permalink
Post by Bill
Post by Bill
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.
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
insmod mymodule iobase=0x300 irq=3 mystring="this is a cool string"
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.
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>
Janaka
2008-02-04 23:24:12 UTC
Permalink
Post by Bill
Post by Janaka
Post by Bill
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.
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"
insmod mymodule iobase=0x300 irq=3 mystring="this is a cool string"
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.
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.
Bill
2008-02-07 22:50:44 UTC
Permalink
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.

Continue reading on narkive:
Loading...