Re: Documentation

Alain KNAFF (Alain.Knaff@imag.fr)
Thu, 30 May 1996 19:39:23 +0200


> As I was doing the final steps to get my driver integrated into the kernel
> tree, I got to thinking about the silliness of having two distinct ways
> of tailoring modules depending on whether they are linked into the kernel
> or loaded with insmod.
>
> If this is an issue that's been thrashed about before and I missed it,
> I apologise for bringing it up again, but I really don't see any good
> reason for the current situation.
>
> Consider my driver, ppa. If it is built in to the kernel, main.c will
> call ppa_setup after parsing something of the form
>
> ppa=0x378,0,3
>
> And ppa_setup will do the assignments:
>
> ppa_base=0x378; ppa_speed_high=0; ppa_speed_low=3;
>
> But if the driver is built as a module, it must be inserted with the
> command:
>
> insmod ppa.o ppa_base=0x378 ppa_speed_high=0 ppa_speed_low=3
>
> to achieve the same effect.

The way I handle this in the floppy driver is to have a string
variable to which you can assign the LILO configuration string when
using modules. The ability to set string variables is available since
modules-1.3.57.
Thus, you can insert the module using the following command line:

insmod floppy.o floppy=0,4,cmos

where floppy=0,4,cmos is also a valid boot option.

The routine to parse this is rather simple:

char *floppy=NULL;

static void parse_floppy_cfg_string(char *cfg)
{
char *ptr;
int ints[11];

while(*cfg) {
for(ptr = cfg;*cfg && *cfg != ' ' && *cfg != '\t'; cfg++);
if(*cfg) {
*cfg = '\0';
cfg++;
}
if(*ptr)
floppy_setup(get_options(ptr,ints),ints);
}
}

and is called with:
if(floppy)
parse_floppy_cfg_string(floppy);

(Sorry if this code snippet gets garbled on its way through vger. If
that happens, you may look it up in floppy.c)

Unfortunately, this breaks with more recent module utilities, which
got a little bit too smart :-( Indeed, modules-1.3.69k for instance
interprets a comma separated list as an array :-( . In order to avoid
this interpretation, you have to quote the string:

insmod floppy.o 'floppy="0,4,cmos"'

We could extend the module utilities to understand the following:

insmod floppy.o -string floppy=0,4,cmos

Or even better:

insmod floppy.o 0,4,cmos

which would place 0,4,cmos into an static variable called argv in the
module. We could make this a char **, in order to allow for more than
one argument.

Alain

-----------------------------------------------------------------------.
Email: Alain.Knaff@inrialpes.fr Alain Lucien Knaff .
Tel.(work): (33) 76 61 52 68 .
Tel.(home): (33) 76 85 23 05 Appartement 310b .
(répondeur) =====O=====/ 11,rue Général Mangin.
Fax : (33) 76 61 52 52 =====O=====/ 38100 Grenoble France.