Linux驱动使用request_firmware固件子系统

背景

在使用外围模块器件时,经常有时候会进行固件的启动加载和升级,比如LCD,TP;之前的方式是把固件转换为十六进制放在代码的数组中,在需要加载固件时传入数组名即可;但是这种数组方式不够灵活,不方便后面的固件升级,也会导致内核镜像文件变大;最近发现还有一种高级的方式:使用request_firmware固件子系统,驱动在遇到需要加载固件时,使用request_firmware接口向用户空间请求文件数据。

驱动

Device Drivers  --->
	Generic Driver Options  ---> 
		[*] Select only drivers that don't need compile-time external firmware                                             
		[*] Prevent firmware from being built                                                                              
		{*} Userspace firmware loading support                                                                             
		[*]   Include in-kernel firmware blobs in kernel binary                                                            
		()    External firmware blobs to build into the kernel binary                                                      
		[*] Fallback user-helper invocation for firmware loading        	

代码

#if defined(CONFIG_FW_LOADER) || (defined(CONFIG_FW_LOADER_MODULE) && defined(MODULE))
int request_firmware(const struct firmware **fw, const char *name,
             struct device *device);
int request_firmware_nowait(
    struct module *module, bool uevent,
    const char *name, struct device *device, gfp_t gfp, void *context,
    void (*cont)(const struct firmware *fw, void *context));
int request_firmware_direct(const struct firmware **fw, const char *name,
                struct device *device);
int request_firmware_into_buf(const struct firmware **firmware_p,
    const char *name, struct device *device, void *buf, size_t size);

void release_firmware(const struct firmware *fw);

使用

在驱动中使用request_firmware方式,需要把驱动编译成ko模块,待跟文件系统挂载后加载模块,才能正常的加载固件;

固件需要放在跟文件系统的/lib/firmware下面,然后把文件路径传给name指针。

调试

# USB Support
    CONFIG_PACKAGE_kmod-usb-core=y
    CONFIG_PACKAGE_kmod-usb3=y

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值