2001-10-11 20:48:14

by Mark Atwood

[permalink] [raw]
Subject: Module read a file?

I'm modifying a PCMCIA driver module so that it can load new firmware
into the card when it's inserted.

Rather than including the firmware inside the module's binary, I would
much rather be able to read it out of the filesystem.

Are their any good examples of kernel code or kernel modules reading a
file out of the filesystem that I could copy or at least look to for
inspiration?

--
Mark Atwood | I'm wearing black only until I find something darker.
[email protected] | http://www.pobox.com/~mra


2001-10-11 21:17:46

by Chris Friesen

[permalink] [raw]
Subject: Re: Module read a file?

Mark Atwood wrote:
>
> I'm modifying a PCMCIA driver module so that it can load new firmware
> into the card when it's inserted.
>
> Rather than including the firmware inside the module's binary, I would
> much rather be able to read it out of the filesystem.
>
> Are their any good examples of kernel code or kernel modules reading a
> file out of the filesystem that I could copy or at least look to for
> inspiration?

What about adding an ioctl() and making a userspace tool to pass the new
firmware down in a buffer? This lets you do more complicated error-checking and
maybe some sort of validation of the firmware in userspace, saving on kernel
size.

Chris

--
Chris Friesen | MailStop: 043/33/F10
Nortel Networks | work: (613) 765-0557
3500 Carling Avenue | fax: (613) 765-2986
Nepean, ON K2H 8E9 Canada | email: [email protected]

2001-10-11 21:25:08

by Mark Atwood

[permalink] [raw]
Subject: Re: Module read a file?

"Christopher Friesen" <[email protected]> writes:
> Mark Atwood wrote:
> > I'm modifying a PCMCIA driver module so that it can load new firmware
> > into the card when it's inserted.
> > Are their any good examples of kernel code or kernel modules reading a
> > file out of the filesystem that I could copy or at least look to for
> > inspiration?
>
> What about adding an ioctl() and making a userspace tool to pass the
> new firmware down in a buffer? This lets you do more complicated
> error-checking and maybe some sort of validation of the firmware in
> userspace, saving on kernel size.

Because the firmware is stored in volitile memory on the card, and
vanishes on a card reset or removal, and I would like to have it Just
Work with the pcmcia-cs package with minimal changes.

Having to remember "run this userspace tool after every card reset"
(which includes power suspends and so forth) would be a major pain.

Besides, the card already has a good validator in it.

--
Mark Atwood | I'm wearing black only until I find something darker.
[email protected] | http://www.pobox.com/~mra

2001-10-11 21:38:08

by Chris Friesen

[permalink] [raw]
Subject: Re: Module read a file?

Mark Atwood wrote:
>
> "Christopher Friesen" <[email protected]> writes:
> > Mark Atwood wrote:
> > > I'm modifying a PCMCIA driver module so that it can load new firmware
> > > into the card when it's inserted.
> > > Are their any good examples of kernel code or kernel modules reading a
> > > file out of the filesystem that I could copy or at least look to for
> > > inspiration?
> >
> > What about adding an ioctl() and making a userspace tool to pass the
> > new firmware down in a buffer? This lets you do more complicated
> > error-checking and maybe some sort of validation of the firmware in
> > userspace, saving on kernel size.
>
> Because the firmware is stored in volitile memory on the card, and
> vanishes on a card reset or removal, and I would like to have it Just
> Work with the pcmcia-cs package with minimal changes.

Ah, okay. I was assuming that the firmware was stored in nonvolatile memory.

--
Chris Friesen | MailStop: 043/33/F10
Nortel Networks | work: (613) 765-0557
3500 Carling Avenue | fax: (613) 765-2986
Nepean, ON K2H 8E9 Canada | email: [email protected]

2001-10-11 21:54:19

by Greg KH

[permalink] [raw]
Subject: Re: Module read a file?

On Thu, Oct 11, 2001 at 02:25:09PM -0700, Mark Atwood wrote:
>
> Because the firmware is stored in volitile memory on the card, and
> vanishes on a card reset or removal, and I would like to have it Just
> Work with the pcmcia-cs package with minimal changes.

Then add a script in the proper place in the linux-hotplug [1] package,
which will run everytime your card is inserted. This is how USB
firmware loads will be done in 2.5.

thanks,

greg k-h

[1] http://linux-hotplug.sf.net/

2001-10-11 21:57:09

by John Adams

[permalink] [raw]
Subject: Re: Module read a file?

On Thursday 11 October 2001 17:25, Mark Atwood wrote:
> "Christopher Friesen" <[email protected]> writes:
> > Mark Atwood wrote:
> > > I'm modifying a PCMCIA driver module so that it can load new firmware
> > > into the card when it's inserted.
> > > Are their any good examples of kernel code or kernel modules reading
> > > a file out of the filesystem that I could copy or at least look to
> > > for inspiration?
> >
> > What about adding an ioctl() and making a userspace tool to pass the
> > new firmware down in a buffer? This lets you do more complicated
> > error-checking and maybe some sort of validation of the firmware in
> > userspace, saving on kernel size.
>
> Because the firmware is stored in volitile memory on the card, and
> vanishes on a card reset or removal, and I would like to have it Just
> Work with the pcmcia-cs package with minimal changes.
>
> Having to remember "run this userspace tool after every card reset"
> (which includes power suspends and so forth) would be a major pain.
>

Have a userspace job which
1) sleeps in the kernel
2) when woken, delivers the data from the filesystem via ioctl to the driver
3) goes back to sleep

Have a driver which
1) wakes the user space job
2) receives the data via ioctl
3) reloads the card

The userspace job is started at boot and lives forever.
Its probably easiest to build the driver into the kernel.

johna

2001-10-11 22:14:00

by Alan

[permalink] [raw]
Subject: Re: Module read a file?

> Because the firmware is stored in volitile memory on the card, and
> vanishes on a card reset or removal, and I would like to have it Just
> Work with the pcmcia-cs package with minimal changes.

Longer term that is precisely what the hot plug interface is there fore

> Having to remember "run this userspace tool after every card reset"
> (which includes power suspends and so forth) would be a major pain.
>
> Besides, the card already has a good validator in it.

What do you do if the card is compiled in and initialised before the
firmware holding fs is mounted ?

2001-10-11 22:30:01

by Mark Atwood

[permalink] [raw]
Subject: Re: Module read a file?

Alan Cox <[email protected]> writes:
> > Because the firmware is stored in volitile memory on the card, and
> > vanishes on a card reset or removal, and I would like to have it Just
> > Work with the pcmcia-cs package with minimal changes.
>
> Longer term that is precisely what the hot plug interface is there fore

And in the longer term, I plan on migrating this product over to the
hot plug interface.

In the medium term, this will be a really useful feature for quite a
few users of this driver.

In the short term, I just want to get this thing working.

>
> > Having to remember "run this userspace tool after every card reset"
> > (which includes power suspends and so forth) would be a major pain.
> >
> > Besides, the card already has a good validator in it.
>
> What do you do if the card is compiled in and initialised before the
> firmware holding fs is mounted ?

Tell the packager and/or user of the module Dont Do That, and have the
card_reset and card_insert functions return with an error.

--
Mark Atwood | I'm wearing black only until I find something darker.
[email protected] | http://www.pobox.com/~mra

2001-10-12 04:45:47

by T. A.

[permalink] [raw]
Subject: Re: Module read a file?

Check the PSS sound driver code. In either 2.2.x or 2.4.x. It allows you
to load a firmware from a selected file.

----- Original Message -----
From: "Mark Atwood" <[email protected]>
To: "Linux Kernel Development" <[email protected]>
Sent: Thursday, October 11, 2001 4:48 PM
Subject: Module read a file?


> I'm modifying a PCMCIA driver module so that it can load new firmware
> into the card when it's inserted.
>
> Rather than including the firmware inside the module's binary, I would
> much rather be able to read it out of the filesystem.
>
> Are their any good examples of kernel code or kernel modules reading a
> file out of the filesystem that I could copy or at least look to for
> inspiration?
>
> --
> Mark Atwood | I'm wearing black only until I find something darker.
> [email protected] | http://www.pobox.com/~mra
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>

2001-10-12 08:13:33

by Ian Stirling

[permalink] [raw]
Subject: Re: Module read a file?

>
> On Thu, Oct 11, 2001 at 02:25:09PM -0700, Mark Atwood wrote:
> >
> > Because the firmware is stored in volitile memory on the card, and
> > vanishes on a card reset or removal, and I would like to have it Just
> > Work with the pcmcia-cs package with minimal changes.
>
> Then add a script in the proper place in the linux-hotplug [1] package,
> which will run everytime your card is inserted. This is how USB
> firmware loads will be done in 2.5.

Or, the existing PCMCIA scripts from the pcmcia-cs package in
/etc/pcmcia
Assuming the card is recognised in some way, perhaps as a memory card,
you just stick the program to load the code into memory.opts