固件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 2018-11-15 22:40 Hello-World3 阅读(1162) 评论(0) 编辑 收藏 举报