Re: firmware.sh questions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Guys

On Mon, Feb 9, 2009 at 8:08 AM, Leandro Dorileo <ldorileo@xxxxxxxxx> wrote:
> Hi Guys
>
> On Sun, Feb 8, 2009 at 11:22 AM, Kay Sievers <kay.sievers@xxxxxxxx> wrote:
>> On Sat, Feb 7, 2009 at 05:10, Dan Nicholson <dbn.lists@xxxxxxxxx> wrote:
>>> On Fri, Feb 6, 2009 at 4:40 AM, Leandro Dorileo <ldorileo@xxxxxxxxx> wrote:
>>>> Few days ago I wanted to understand a bit better udev, and started
>>>> reading its source code, and went to TODO file to see how I could
>>>> start contributing, and picket the line: "convert firmware.sh to C ".
>>>> In that regard I have some questions:
>>>>
>>>> 1 - there isn`t any a udev rule using firmware.sh in upstream source
>>>> code(I may have forgot something but a grep -r 'firmware.sh' in
>>>> rules.d didn`t show me any thing), do distributors set one? I also
>>>> couldn`t find one in fedora 10.
>>>
>>> There's a rule in extras/firmware/50-firmware.rules that gets
>>> installed along with firmware.sh.
>>>
>>>> 2 - who does set $DEVPATH, $FIRMWARE variables used in firmware.sh?
>>>
>>> The kernel sets them as part of the uevent, I believe.
>>
>> DEVPATH is always defined in every uevent and set by the kernel,
>> FIRMWARE is set by the kernel's "firmware" class and carries the
>> requested name, which the in-kernel driver has supplied to the
>> request_firmware() call.
>
> hum! So I`ll have to implement a kernel module to generate an uevent
> to test my implementation.

I wrote a small kernel module to test my future implementations for
firmware loading udev ext, but I`m having problems in that regard(code
in end of the body message).

In my module I do:
  1 - register a class(ufw_cls);
  2 - register a char device(ufwloader);
  3 - make a dev(major 240, minor 0);
  4 - create a device;
  5 - request firmware;

When request_firmware is run the value set to $DEVPATH is
/devices/virtual/ufw_cls/ufwloader/ufwloader, shouldn`t that be
/devices/virtual/ufw_cls/ufwloader ? Am I doing something wrong?

The module source code:

/*
 *	ufwloader.c - a udev firmware loading module test
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/firmware.h>
#include <linux/fs.h>
#include <linux/device.h>

#define FIRMWARE_NAME "tst/ufwloader.bin"
#define DRV_NAME "ufwloader"
#define DEV_MAJOR 240
#define CLASS_NAME "ufw_cls"

static struct class *ufwloader_class;
static struct device *device;
static dev_t *dev;

struct file_operations ufwloader_fops = {
	.owner	=	THIS_MODULE,
};

/**
 * Generates the uevent.
 *
 */
static int ufwloader_request_firmware(struct device *dev){
	const char *fw_name = FIRMWARE_NAME;
	const struct firmware *fw;
	int err;

	err = request_firmware(&fw, fw_name, dev);
	if(err != 0)
		goto fail_request_firmware;

	return 0;

fail_request_firmware:
	printk("Failed requesting firmware");
	return err;
}

/**
 * starts the module
 *
 */
static int __init ufwloader_init(void){
	int err;

	ufwloader_class = class_create(THIS_MODULE, CLASS_NAME);
	err = PTR_ERR(ufwloader_class);
	if(IS_ERR(ufwloader_class))
		goto fail_class_create;

	err = register_chrdev (DEV_MAJOR, DRV_NAME, &ufwloader_fops);
	if(err != 0)
		goto fail_register_chrdev;


	dev = MKDEV(DEV_MAJOR, 0);
	device = device_create(ufwloader_class, NULL, dev, NULL,
					"%s", DRV_NAME);
	if(IS_ERR(device)){
		err = PTR_ERR(device);
		goto fail_device_create;
	}

	err = ufwloader_request_firmware(device);
	if(err != 0)
		goto fail_request_firmware;
	return 0;

fail_register_chrdev:
	printk("Failed to register ufwloader char test device");
	return -EIO;

fail_class_create:
	printk("Failed to create %s class", CLASS_NAME);
	class_destroy(ufwloader_class);

fail_device_create:
fail_request_firmware:
	device_destroy(ufwloader_class, MKDEV(DEV_MAJOR, 0));
	class_destroy(ufwloader_class);
	unregister_chrdev (DEV_MAJOR, DRV_NAME);

	return err;
}

/**
 * free something
 */
static void __exit ufwloader_exit(void){
	device_destroy(ufwloader_class, MKDEV(DEV_MAJOR, 0));
	class_destroy(ufwloader_class);
	unregister_chrdev (DEV_MAJOR, DRV_NAME);
}

module_init(ufwloader_init);
module_exit(ufwloader_exit);

MODULE_AUTHOR("Leandro Dorileo");
MODULE_DESCRIPTION("A udev firmware loading module test");
MODULE_LICENSE("GPL");


Thanks in advanced

-- 
(°=   Leandro Dorileo
//\    ldorileo@xxxxxxxxx   -   http://www.dorilex.net
V_/  Software is a matter of freedom.
--
To unsubscribe from this list: send the line "unsubscribe linux-hotplug" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel]     [Linux DVB]     [Asterisk Internet PBX]     [DCCP]     [Netdev]     [X.org]     [Util Linux NG]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux