Do you have a question? Post it now! No Registration Necessary
Subject
- Posted on
Driver reading configuration file
- 02-04-2008
February 4, 2008, 1:19 am

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.
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

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

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

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>
Przemek Klosowski, Ph.D. <przemek.klosowski at gmail>

Re: Driver reading configuration file

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.
Site Timeline
- » ISR
- — Next thread in » Embedded Linux
-
- » spin_unlock_irqrestore parse error
- — Previous thread in » Embedded Linux
-
- » Crosscompiling for ARM: reloc type R_ARM_ABS32 is not supported for PIC - ...
- — Newest thread in » Embedded Linux
-
- » Quanta corrente potrà fornire?
- — The site's Newest Thread. Posted in » Electronics Hobby (Italian)
-