固件firmware_Linux内核

1.相关函数

复制代码
1.相关函数
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)) /*失败时传入的fw=NULL*/

int request_firmware(const struct firmware **firmware_p, const char *name, struct device *device)

void release_firmware(const struct firmware *fw)
复制代码

 

2.函数调用关系

request_firmware_nowait
    INIT_WORK(&fw_work->work, request_firmware_work_func); schedule_work(&fw_work->work); 这就是异步的实现方法,queue到内核线程中去执行
        fw_get_filesystem_firmware
            kernel_read_file_from_path
                file = filp_open(path, O_RDONLY, 0);
                kernel_read_file(file, buf, size, max_size, id);

 

2.相关结构体

复制代码
/* direct firmware loading support */
static char fw_path_para[256];
static const char * const fw_path[] = { /* 固件查找路径 */
    fw_path_para,                       /* 模块参数,可作为启动参数 */
    "/lib/firmware/updates/" UTS_RELEASE,
    "/lib/firmware/updates",
    "/lib/firmware/" UTS_RELEASE,
    "/lib/firmware"
};
module_param_string(path, fw_path_para, sizeof(fw_path_para), 0644);  /*这个还做为模块参数供用户配置*/
MODULE_PARM_DESC(path, "customized firmware image search path with a higher priority than default path");
复制代码
struct firmware {
    size_t size;
    const u8 *data;        /*data里面存的直接是打卡固件里面的数据*/
    struct page **pages;

    /* firmware loader private fields */
    void *priv; /*_request_firmware_prepare中指向struct firmware_buf *buf, 若驱动App这里指定为null,内核分配的buff就存在这里*/
};

 

3.实验测试

复制代码
error = request_firmware_nowait(THIS_MODULE, true, "maxtouch.cfg", &client->dev, GFP_KERNEL, data, mxt_config_cb);

mxt_config_cb(const struct firmware *cfg, void *ctx)
{
    printk(KERN_INFO"hello: size=%d, content=%s\n", cfg->size, buff);
}

# mkdir -p /lib/firmware/updates
# touch /lib/firmware/updates/maxtouch.cfg
# ehco abcdefghijklmnopqrst > /lib/firmware/updates/maxtouch.cfg

打印:
hello: size=21, content=abcdefghijklmnopqrst
复制代码

 

好文:http://blog.chinaunix.net/uid-30512847-id-5576781.html

posted on   Hello-World3  阅读(1204)  评论(0编辑  收藏  举报

编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示