hotplug firmware

  Linux 2.6.x hotplug 和firmware 功能

因为工作中需要,我做了一些了解,因此写了一点心得。所以这篇文章并不是一个完整的教材。

1.: 一些概念
hotplug 它是系统在安装即插即用模块常用的工具 例如:PCI,USB,PCMCIA.
大概流程如下:
(1) Linux 系统启动后,一切都在工作中;
(2) 用户插入USB-DISK(U盘);
(3) 系统加载了U盘驱动;
(4) 体统调用/sbin/hotplug 脚本,实现自动mount动作;
关于hotplug的网站如下:
http://linux-hotplug.sourceforge.net/

firmware 名字含义是固件,Linux 引用这个功能可能从2.6.x开始;
它的作用是让硬件驱动通过kernel加载设备固件驱动;
在实际应用中,我们系统中PCI,USB设备或许需要自己的驱动固件,
设备只有通过这个固件才能驱动自己;由于固件也在升级中,或者因为生产时
减少烧录固件这道工序,所以人们选择在加载驱动的时候通过程序将固件
传给设备.
所以Linux 提供了 firmware load 函数给驱动程序使用;

2.: 使用方法
这里主要介绍硬件驱动使用 Linux kernel 提供Firmware load 功能的方法;
(1) kernel source code :
drivers/base/firmware_class.c // linux 2.6.11
(2) header file:
<linux/firmware.h>
(3) document
Document/firmware/
(4) 使用例子
Documentation/firmware_class/firmware_sample_driver.c

3.: 原理和操作步骤
当我们按照例子使用下面函数操作时:
request_firmware(&fw_entry, "sample_driver_fw", &ghost_device);
从firmware_class.c 可以看出request_firmware作了如下动作:

(1) . 创建 ghost_device 所在节点文件;
(2) . 调用hotplug; (Documentation/firmware_class/hotplug-script,应放在/sbin/hotplug)
完成load动作;

理解hotplug例子;
HOTPLUG_FW_DIR=/usr/lib/hotplug/firmware/
//本机存放firmware.bin 目录,也就是目标固件文件所放置的位置;

echo 1 > /sys/$DEVPATH/loading
cat $HOTPLUG_FW_DIR/$FIRMWARE > /sys/$DEVPATH/data
//通过用户程序将固件cp 给 kernel 创建 的ghot_device 文件;
// 这样kernel就获取了固件数据;

echo 0 > /sys/$DEVPATH/loading


When a driver calls request_firmware(), a uevent is sent by the kernel to udev over a netlink(7) socket, requesting that a specific file is uploaded. udevd runs /lib/udev/firmware.agent, a simple shell script which will look for the $FIRMWARE file in a few directories and then copy it to the designated place in the driver $DEVPATH in sysfs.
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值