{"id":293209,"date":"2024-09-27T04:02:47","date_gmt":"2024-09-26T20:02:47","guid":{"rendered":"https:\/\/lrxjmw.cn\/jyqzvkfbdjdq.html"},"modified":"2024-09-27T04:02:47","modified_gmt":"2024-09-26T20:02:47","slug":"jyqzvkfbdjdq","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/jyqzvkfbdjdq.html","title":{"rendered":"\u57fa\u4e8e\u5168\u5fd7 V3S \u5f00\u53d1\u677f\u7684\u7b80\u5355\u9a71\u52a8\u7a0b\u5e8f\u548c\u6d4b\u8bd5\u5e94\u7528\u7a0b\u5e8f\u8bbe\u8ba1\u6d41\u7a0b"},"content":{"rendered":"
1.\u5e8f\u8a00<\/p>\n
\u672c\u6587\u63cf\u8ff0\u4e86\u57fa\u4e8e\u5168\u5fd7V3S\u5f00\u53d1\u677f\u7684\u7b80\u5355\u9a71\u52a8\u7a0b\u5e8f\u548c\u6d4b\u8bd5\u5e94\u7528\u7a0b\u5e8f\u7684\u8bbe\u8ba1\u6d41\u7a0b\u3002\u6211\u4eec\u8bbe\u8ba1\u7684\u9a71\u52a8\u7a0b\u5e8f\u548c\u6d4b\u8bd5\u7a0b\u5e8f\u975e\u5e38\u7b80\u5355\uff0c\u9002\u5b9c\u521d\u5b66\u8005\u4e0a\u624b\u5b66\u4e60\u3002<\/p>\n
\u8f6f\u4ef6\u8fd0\u884c\u7684\u786c\u4ef6\u73af\u5883\u662f\u57fa\u4e8eV3S\u5f00\u53d1\u677f\u4e2d\u7684\u5168\u5fd7V3S\u5904\u7406\u5668\uff0c\u8be5\u5904\u7406\u5668\u96c6\u6210\u4e86\u4e00\u4e2a1.2GHz\u5de5\u4f5c\u663e\u5b58\u7684\u5355ARMCortexTM-A7\u6838\uff0c\u82af\u7247\u5185\u90e8\u96c6\u6210\u4e8664MBDRAM\u50a8\u5b58\u5668\u3002<\/p>\n
<\/p>\n
\u8f6f\u4ef6\u8bbe\u8ba1\u662f\u57fa\u4e8elinux3.4\u5185\u6838\u3002<\/p>\n
<\/p>\n
2.\u8bbe\u8ba1\u6d41\u7a0b\u6982\u8ff0<\/p>\n
\u8bbe\u8ba1\u7684\u6b65\u9aa4\u4f9d\u6b21\u662f\uff1a<\/p>\n
\u6b65\u9aa4\u4e00\uff1a\u7f16\u64b0\u4e00\u4e2ademo_driver.c\u7684\u9a71\u52a8\u7a0b\u5e8f\u3002<\/p>\n
\u6b65\u9aa4\u4e8c\uff1a\u7f16\u64b0makefile\u6587\u4ef6\u3002<\/p>\n
\u6b65\u9aa4\u4e09\uff1a\u7f16\u64b0\u4e00\u4e2ademo_app.c\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n
\u6b65\u9aa4\u56db\uff1a\u5728V3S\u5f00\u53d1\u677f\u4e2d\u5b89\u88c5demo_driver\u9a71\u52a8\u7a0b\u5e8f\u7ea2\u65d7linux\u7cfb\u7edf\uff0c\u5e76\u6d4b\u8bd5demo_app\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n
linux\u7cfb\u7edf\u662f\u4e00\u4e2a\u5206\u5c42\u7ed3\u6784\uff0c\u6211\u4eec\u8bbe\u8ba1\u7684demo_driver\u5750\u843d\u5185\u6838\u4e2d\u7684\u9a71\u52a8\u90e8\u4efd\uff0cdemo_app\u5750\u843d\u7528\u6237\u7ea7\u3002<\/p>\n
<\/p>\n
3.\u7f16\u64b0\u9a71\u52a8\u7a0b\u5e8f<\/p>\n
\u7f16\u64b0\u4e00\u4e2ademo_driver.c\u7684\u9a71\u52a8\u7a0b\u5e8f\uff0c\u9a71\u52a8\u7a0b\u5e8f\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n
\n
\/**\n*********************************************************************************************************\n* \t\tdemo_driver\n* (c) Copyright 2021-2031\n* All Rights Reserved\n*\n* @File : \n* @By : liwei\n* @Version : V0.01\n* \n*********************************************************************************************************\n**\/\n\/**********************************************************************************************************\nIncludes \n**********************************************************************************************************\/\n#include \n#include \n#include \n#include \n\/**********************************************************************************************************\nDefine\n**********************************************************************************************************\/\n#define DRIVER_MAJOR 188\n#define DEVICE_NAME \"demo_driver\"\n\/***********************************************************************************************************\n* @\u63cf\u8ff0\t: \n***********************************************************************************************************\/\nstatic int demo_open(struct inode *inode, struct file *file)\n{\t\n\tprintk(KERN_EMERG \"======================demo_open======================n\");\n\treturn 0;\n}\n\/***********************************************************************************************************\n* @\u63cf\u8ff0\t: \n***********************************************************************************************************\/\nstatic ssize_t demo_write(struct file *file, const char __user * buf, size_t count, loff_t *ppos)\n{\n printk(KERN_EMERG \"======================demo_write======================n\");\n return 0;\n}\n\/***********************************************************************************************************\n* @\u63cf\u8ff0\t: \n***********************************************************************************************************\/\nstatic ssize_t demo_read(struct file *file, char __user * buf, size_t count, loff_t *ppos)\n{\n printk(KERN_EMERG \"======================demo_read ======================n\"); \n return 0;\n}\n\/***********************************************************************************************************\n* @\u63cf\u8ff0\t: \n***********************************************************************************************************\/\nstatic int demo_close(struct inode *inode, struct file *file)\n{\n printk(KERN_EMERG \"======================demo_close ======================n\");\n return 0;\n}\n\/***********************************************************************************************************\n* @\u63cf\u8ff0\t: \n***********************************************************************************************************\/\nstatic struct file_operations demo_flops = \n{\n\t.owner = THIS_MODULE,\n\t.open = demo_open, \n\t.write = demo_write,\n\t.read \t= \tdemo_read,\n\t.release = demo_close,\n};\n\/***********************************************************************************************************\n* @\u63cf\u8ff0\t: \n***********************************************************************************************************\/\nstatic int __init demo_init(void)\n{\n int ret;\n \t\t\n\t\/\/\u6ce8\u518c\u8bbe\u5907\n ret = register_chrdev(DRIVER_MAJOR,DEVICE_NAME, &demo_flops);\n if (ret < 0) \n\t{\n printk(KERN_EMERG DEVICE_NAME " can't register major number.n");\n return ret;\n }\n\telse\n\t{\n\t\tprintk(KERN_EMERG DEVICE_NAME " ======================demo init======================n");\n\t}\n return 0;\n}\n\/***********************************************************************************************************\n* @\u63cf\u8ff0\t: \n***********************************************************************************************************\/\nstatic void __exit demo_exit(void)\n{\n unregister_chrdev(DRIVER_MAJOR, DEVICE_NAME);\n printk(KERN_EMERG DEVICE_NAME " ======================demoexit======================n");\n}\nmodule_init(demo_init);\nmodule_exit(demo_exit);\nMODULE_LICENSE("GPL");\n\/***********************************************END*******************************************************\/\n<\/code><\/pre>\n<\/p>\n\u7f16\u8bd1\u9a71\u52a8\u7a0b\u5e8f\u4f9d\u8d56linux\u5185\u6838\u6e90\u7801\u73af\u5883\uff0c\u987b\u8981\u628a\u9a71\u52a8C\u6587\u4ef6\u7f6e\u4e8elinux\u6e90\u7801\u76ee\u5f55\u4e2d\uff0c\u901a\u8fc7\u7f16\u8bd1linux\u5185\u6838\u7684\u5f62\u5f0f\u5f97\u5230\u9a71\u52a8ko\u6587\u4ef6\u3002<\/p>\n
<\/p>\n
\u4e3a\u4e86\u5f97\u5230\u9a71\u52a8ko\uff0c\u6211\u4eec\u5728easyboard\/corelinux\/v3ssdk\/linux-3.4\/drivers\/char\u76ee\u5f55\u4e0b\u8fb9\u521b\u5efa\u4e00\u4e2ademo_driver\u7684\u6587\u4ef6\u5939\uff0c\u5e76\u628ademo_driver.c\u7a0b\u5e8f\u62f7\u8d1d\u5230demo_driver\u7684\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n
4.\u7f16\u64b0makefile<\/p>\n
\u6211\u4eec\u901a\u8fc7\u7f16\u8bd1linux\u5185\u6838\u7684\u5f62\u5f0f\u5f97\u5230\u9a71\u52a8ko\u6587\u4ef6linux \u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f<\/strong>linux \u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f<\/strong>\uff0c\u4e3a\u4e86\u5728\u7f16\u8bd1\u5185\u6838\u65f6\u5f97\u5230\u76f8\u5e94\u7684\u9a71\u52a8\uff0c\u6211\u4eec\u987b\u8981\u5728linux-3.4\u5185\u6838\u4ee3\u7801\u4e2d\u964d\u4f4e\u548c\u66f4\u6539Makefile\u6587\u4ef6\uff08Makefile\u7684\u4f5c\u7528\u6307\u5b9a\u4e86\u5de5\u7a0b\u7f16\u8bd1\u7684\u65b9\u5f0f\u548c\u6b65\u9aa4\uff09\u3002<\/p>\n\u9996\u5148\u6211\u4eec\u66f4\u6539easyboard\/corelinux\/v3ssdk\/linux-3.4\/drivers\/char\u76ee\u5f55\u4e0bMakefile\u6587\u4ef6linux\u64cd\u4f5c\u7cfb\u7edf\u4ecb\u7ecd\uff0c\u5728Makefile\u6587\u4ef6\u5185\u5bb9\u6700\u672b\u884c\u52a0\u5165\u4e00\u884c\u4ee3\u7801\uff1a<\/p>\n
\n
obj += demo_driver\/<\/code><\/pre>\n<\/p>\n\u8fd9\u53e5\u4ee3\u7801\u7684\u610f\u601d\u662f\uff1a\u7f16\u8bd1\u5185\u6838\u65f6\uff0c\u5b50\u76ee\u5f55demo_driver\/\u4e0b\u7684\u6587\u4ef6\u4e5f\u5c06\u8fdb\u884c\u7f16\u8bd1\u3002<\/p>\n
<\/p>\n
\u6211\u4eec\u5728easyboard\/corelinux\/v3ssdk\/linux-3.4\/drivers\/char\/demo_driver\u4e2d\u521b\u5efa\u4e00\u4e2aMakefile\u6587\u4ef6\uff0c\u540c\u65f6\u5728Makefile\u6587\u4ef6\u4e2d\u52a0\u5165\u4e00\u884c\u4ee3\u7801\uff1a<\/p>\n
\n
obj-m\t\t+= demo_driver.o<\/code><\/pre>\n<\/p>\n\u8fd9\u53e5\u4ee3\u7801\u7684\u610f\u601d\u662f\uff1a\u7f16\u8bd1\u5f53\u524d\u76ee\u5f55\u4e2d\u7684demo_driver.c\u6587\u4ef6\uff0c\u8f93\u51fa\u4e00\u4e2ademo_driver.ko\u7684\u9a71\u52a8\u6587\u4ef6\u3002<\/p>\n
<\/p>\n
\u6253\u7b97\u597ddemo_driver.c\u6587\u4ef6\u548cMakefile\u6587\u4ef6\u540e\uff0c\u6211\u4eec\u6267\u884c\u7f16\u8bd1\u5185\u6838\u6307\u4ee4\u3002<\/p>\n
\n
.\/linux_docker_build.sh<\/code><\/pre>\n<\/p>\n\u5185\u6838\u7f16\u8bd1\u987b\u8981\u7b49\u5f8510\u5206\u949f\u5de6\u53f3\u3002<\/p>\n
\u7ecf\u8fc7\u4e0a\u8ff0\u4e00\u6ce2\u64cd\u4f5c\uff0c\u6211\u4eec\u5f97\u5230\u4e86demo_driver.ko\u7684\u9a71\u52a8\u6587\u4ef6\u3002<\/p>\n
<\/p>\n
\u5230\u76ee\u524d\u4e3a\u6b62\u6211\u4eec\u7684\u4ee3\u7801\u8bbe\u8ba1\u5de5\u4f5c\u5b8c\u6210\u4e8650%\uff0c\u5982\u53f3\u56fe\u6240\u793a\uff1a<\/p>\n
<\/p>\n
5.\u7f16\u64b0\u5e94\u7528\u7a0b\u5e8f<\/p>\n
\u7f16\u64b0\u4e00\u4e2ademo_app.c\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u7a0b\u5e8f\u6e90\u7801\u5982\u4e0b\uff1a<\/p>\n
\n
\/**\n*********************************************************************************************************\n* \t\tdemo_driver\n* (c) Copyright 2021-2031\n* All Rights Reserved\n*\n* @File : \n* @By : liwei\n* @Version : V0.01\n* \n*********************************************************************************************************\n**\/\n\/**********************************************************************************************************\nIncludes \n**********************************************************************************************************\/\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n\/***********************************************************************************************************\n* @\u63cf\u8ff0\t: \n***********************************************************************************************************\/\nint main(int arvc, char *argv[])\n{\n\tint fd;\n\tint value = 0;\n\tprintf(\"==========demo_test==================n\");\n\t\/\/\u6253\u5f00\u9a71\u52a8 \n\tfd = open(\"\/dev\/demo_driver\",O_RDWR);\n\twhile(1)\n\t{\n\t\t\/\/\u6267\u884c\u9a71\u52a8\u8bfb\u64cd\u4f5c\n\t\tread(fd,&value,4);\n\t\tsleep(1);\n\t\t\/\/\u6267\u884c\u9a71\u52a8\u5199\u64cd\u4f5c\n\t\twrite(fd,&value,4);\n\t\tsleep(1);\t\n\t\t\n\t\tprintf(\"==========run==================n\");\n\t}\n\treturn 0;\n}\n\/***********************************************END*******************************************************\/\n<\/code><\/pre>\n<\/p>\n\u5c06\u5e94\u7528\u7a0b\u5e8f\u6e90\u7801\u7f6e\u4e8e\u865a\u62df\u673a\u7684\u4efb\u610f\u4e00\u4e2a\u76ee\u5f55\u4e2d\u5982\uff1a\/home\/easyboard\/work\/demo<\/p>\n
\u4e4b\u540e\u6211\u4eec\u5728\u7ec8\u7aef\u4e2d\u6b65\u5165\/home\/easyboard\/work\/demo\u76ee\u5f55\uff0c\u5728\u8be5\u76ee\u5f55\u4e0b\u6267\u884c\u5982\u4e0bgcc\u7f16\u8bd1\u6307\u4ee4\uff1a<\/p>\n
\n
arm-buildroot-linux-gnueabihf-gcc -o demo_app demo_app.c\n<\/code><\/pre>\n<\/p>\n\u4e8e\u662f\u6211\u4eec\u5f97\u5230\u4e00\u4e2ademo_app\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n
<\/p>\n
\u5728\u865a\u62df\u673a\u4e2d\u6211\u4eec\u501f\u52a9\u4ea4\u53c9\u7f16\u8bd1\u5de5\u5177\uff0c\u76f4\u63a5\u7f16\u8bd1\u5373\u53ef\u5f97\u5230V3S\u76ee\u6807\u677f\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n
<\/p>\n
\u5230\u76ee\u524d\u4e3a\u6b62\u6211\u4eec\u7684\u4ee3\u7801\u8bbe\u8ba1\u5de5\u4f5c\u5b8c\u6210100%\uff0c\u5982\u53f3\u56fe\u6240\u793a\uff1a<\/p>\n
6.\u5b89\u88c5\u9a71\u52a8\u53ca\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f<\/p>\n
<\/p>\n
\u7ecf\u8fc7\u4e0a\u8ff0\u64cd\u4f5c\uff0c\u6211\u4eec\u5f97\u5230\u4e86demo_driver.ko\u548cdemo_app\u4e24\u4e2a\u6587\u4ef6\uff0c\u6211\u4eec\u4f7f\u7528SecureCRTPortable\u5de5\u5177\u5c06\u8fd9\u4e24\u4e2a\u6587\u4ef6\u4f20\u8f93\u5230V3S\u5f00\u53d1\u677f\u4e2d\u3002\uff08\u4f20\u8f93\u624b\u6bb5\u4e0d\u9650\uff0c\u7528\u81ea\u5df1\u719f\u6089\u7684\u65b9\u5f0f\u5c06\u6587\u4ef6\u590d\u5236\u5230\u5f00\u53d1\u677f\u4e2d\u5373\u53ef\uff09<\/p>\n
<\/p>\n
\u5b8c\u6210\u6587\u4ef6\u4f20\u8f93\u540e\uff0c\u6211\u4eec\u987b\u8981\u5148\u5b89\u88c5\u6211\u4eec\u7f16\u8bd1\u7684\u9a71\u52a8ko\u6587\u4ef6\uff0c\u4e4b\u540e\u8fd0\u884c\u6d4b\u8bd5\u7a0b\u5e8f\uff0c\u64cd\u4f5c\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n
\u64cd\u4f5c\u4e00\uff1a\u6267\u884c\u5b89\u88c5\u9a71\u52a8\u6307\u4ee4\uff1a<\/p>\n
\n
insmod demo_driver.ko <\/code><\/pre>\n<\/p>\n<\/p>\n
\u64cd\u4f5c\u4e8c\uff1a\u6267\u884c\u521b\u5efa\u6587\u4ef6\u8282\u70b9\u6307\u4ee4\uff1a<\/p>\n
\n
mknod \/dev\/demo_driver c 188 0<\/code><\/pre>\n<\/p>\n188\u7684\u662f\u8bbe\u5907\u53f7\uff0c\u6211\u4eec\u5728\u8bbe\u8ba1\u7684\u9a71\u52a8C\u6587\u4ef6\u4e2d\u6709\u5982\u4e0b\u5b9a\u4e49\uff1a<\/p>\n
\n
\/**********************************************************************************************************\nDefine\n**********************************************************************************************************\/\n#define DRIVER_MAJOR 188\n#define DEVICE_NAME \"demo_driver\"\n<\/code><\/pre>\n<\/p>\n\u64cd\u4f5c\u4e09\uff08\u53ef\u9009\uff09\uff1a\u6267\u884c\u67e5\u770b\u9a71\u52a8\u8bbe\u5907\u6307\u4ee4\uff1a<\/p>\n
\n
ls \/dev\n<\/code><\/pre>\n<\/p>\n