Driver reading configuration file - Powerpc

This is a discussion on Driver reading configuration file - Powerpc ; 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 ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Driver reading configuration file

  1. Driver reading configuration file

    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.

  2. Re: Driver reading configuration file

    On Feb 4, 12:19 pm, Bill wrote:
    > 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"

  3. Re: Driver reading configuration file

    On Feb 3, 5:49 pm, Janaka wrote:
    > On Feb 4, 12:19 pm, Bill wrote:
    >
    > > 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"


    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.

  4. Re: Driver reading configuration file

    On Sun, 03 Feb 2008 17:55:35 -0800, Bill wrote:

    > On Feb 3, 5:49 pm, Janaka wrote:
    >> On Feb 4, 12:19 pm, Bill wrote:
    >>
    >> > 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"


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

  5. Re: Driver reading configuration file

    On Feb 4, 12:55 pm, Bill wrote:
    > On Feb 3, 5:49 pm, Janaka wrote:
    >
    >
    >
    > > On Feb 4, 12:19 pm, Bill wrote:

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

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

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

+ Reply to Thread