{"id":2139,"date":"2017-03-20T10:43:37","date_gmt":"2017-03-20T02:43:37","guid":{"rendered":"http:\/\/www.51cos.com\/?p=2139"},"modified":"2017-03-20T10:43:43","modified_gmt":"2017-03-20T02:43:43","slug":"linux%e5%86%85%e6%a0%b8%e4%b8%ad%e7%9a%84kconfig%e3%80%81makefile%e3%80%81-config%e4%b8%8emenuconfig","status":"publish","type":"post","link":"http:\/\/www.51cos.com\/?p=2139","title":{"rendered":"Linux\u5185\u6838\u4e2d\u7684kconfig\u3001makefile\u3001.config\u4e0emenuconfig"},"content":{"rendered":"<p>kconfig\uff1a\u4e00\u4e2a\u6587\u672c\u5f62\u5f0f\u7684\u6587\u4ef6\uff0c\u5176\u4e2d\u4e3b\u8981\u4f5c\u7528\u662f\u5728\u5185\u6838\u914d\u7f6e\u65f6\u5019\uff0c\u4f5c\u4e3a\u914d\u7f6e\u9009\u9879\u3002<br \/>\n.config\uff1a\u6587\u4ef6\u662f\u5728\u8fdb\u884c\u5185\u6838\u914d\u7f6e\u7684\u65f6\u5019\uff0c\u7ecf\u8fc7\u914d\u7f6e\u540e\u751f\u6210\u7684\u5185\u6838\u7f16\u8bd1\u53c2\u8003\u6587\u4ef6\u3002<br \/>\nmakefile\uff1a\u4e00\u4e2a\u6587\u672c\u5f62\u5f0f\u7684\u6587\u4ef6\uff0c\u5176\u4e2d\u5305\u542b\u4e00\u4e9b\u89c4\u5219\u544a\u8bc9make\u7f16\u8bd1\u54ea\u4e9b\u6587\u4ef6\u4ee5\u53ca\u600e\u6837\u7f16\u8bd1\u8fd9\u4e9b\u6587\u4ef6\u3002<\/p>\n<p>Kconfig<\/p>\n<p>1.\u5148\u4e86\u89e3\u4e00\u4e0bKconfig\u7684\u8bed\u6cd5\uff1a<br \/>\n\u4e00\u4e2a\u5178\u578b\u7684\u5185\u6838\u914d\u7f6e\u83dc\u5355\u5982\u4e0b\uff1a<\/p>\n<pre class=\"lang:default decode:true \">menu \"Network device support\"<br \/>\nconfig NETDEVICES<br \/>\n    bool \"Enable Net Devices\"<br \/>\n    depends on NET<br \/>\n    default y<br \/>\nhelp<br \/>\n    This is help desciption\u3002<br \/>\nendmenu <\/p>\n<p>\u5305\u542b\u5728menu\/endmenu\u4e2d\u7684\u5185\u5bb9\u4f1a\u6210\u4e3aNetwork device support\u7684\u5b50\u83dc\u5355\u3002<br \/>\n\u6bcf\u4e00\u4e2a\u5b50\u83dc\u5355\u9879\u90fd\u662f\u7531config\u6765\u5b9a\u4e49\u7684\u3002<br \/>\ncongfig\u4e0b\u65b9\u7684\u90a3\u4e9bbool\u3001depends on\u3001default\u3001help\u7b49\u4e3aconfig\u7684\u5c5e\u6027\uff0c<br \/>\n\u7528\u4e8e\u5b9a\u4e49\u8be5\u83dc\u5355\u9879\u7684\u7c7b\u578b\u3001\u4f9d\u8d56\u9879\u3001\u9ed8\u8ba4\u503c\u3001\u5e2e\u52a9\u4fe1\u606f\u7b49\u3002<\/p>\n<p>2. \u8865\u5145\u8bf4\u660e\u4e00\u4e0b\u7c7b\u578b\u5b9a\u4e49\u90e8\u5206\uff1a<br \/>\n\u6bcf\u4e2aconfig\u83dc\u5355\u9879\u90fd\u8981\u6709\u7c7b\u578b\u5b9a\u4e49:<br \/>\nbool\u5e03\u5c14\u7c7b\u578b\u3001 tristate\u4e09\u6001(\u5185\u5efa\u3001\u6a21\u5757\u3001\u79fb\u9664)\u3001string\u5b57\u7b26\u4e32\u3001 hex\u5341\u516d\u8fdb\u5236\u3001 integer\u6574\u578b\u3002<br \/>\n\u4f8b\u5982\uff1a<br \/>\nconfig HELLO_MODULE<br \/>\nbool \"hello test module\"<br \/>\nbool \u7c7b\u578b\u7684\u53ea\u80fd\u9009\u4e2d\u6216\u4e0d\u9009\u4e2d\uff0c\u663e\u793a\u4e3a[ ]; tristate\u7c7b\u578b\u7684\u83dc\u5355\u9879\u591a\u4e86\u7f16\u8bd1\u6210\u5185\u6838\u6a21\u5757\u7684\u9009\u9879\uff0c\u663e\u793a\u4e3a&lt; &gt; , \u5047\u5982\u9009\u62e9\u7f16\u8bd1\u6210\u5185\u6838\u6a21\u5757\uff0c\u5219\u4f1a\u5728.config\u4e2d\u751f\u6210\u4e00\u4e2a CONFIG_HELLO_MODULE=m\u7684\u914d\u7f6e\uff0c\u5047\u5982\u9009\u62e9\u5185\u5efa\uff0c\u5c31\u662f\u76f4\u63a5\u7f16\u8bd1\u6210\u5185\u6838\uff0c\u5c31\u4f1a\u5728.config\u4e2d\u751f\u6210\u4e00\u4e2a CONFIG_HELLO_MODULE=y\u7684\u914d\u7f6e\u3002<\/p>\n<p>Makefile<\/p>\n<p>2.6\u5185\u6838\u7684Makefile\u5206\u4e3a5\u4e2a\u7ec4\u6210\u90e8\u5206\uff1a<br \/>\n1. \u6700\u9876\u5c42\u7684Makefile<br \/>\n2. \u5185\u6838\u7684.config\u914d\u7f6e\u6587\u4ef6<br \/>\n3. \u5728arch\/<span class=\"katex math inline\">(ARCH) \u76ee\u5f55\u4e0b\u7684\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u7684Makefile<br \/>\n4. \u5728s\u76ee\u5f55\u4e0b\u7684 Makefile.* \u6587\u4ef6\uff0c\u662f\u4e00\u4e9bMakefile\u7684\u901a\u7528\u89c4\u5219<br \/>\n5. \u5404\u7ea7\u76ee\u5f55\u4e0b\u7684\u5927\u6982\u7ea6500\u4e2akbuild Makefile\u6587\u4ef6<\/p>\n<p>\u9876\u5c42\u7684Makefile\u6587\u4ef6\u8bfb\u53d6.config\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u5e76\u603b\u4f53\u4e0a\u8d1f\u8d23build\u5185\u6838\u548c\u6a21\u5757\u3002<br \/>\nArch Makefile\u5219\u63d0\u4f9b\u8865\u5145\u4f53\u7cfb\u7ed3\u6784\u76f8\u5173\u7684\u4fe1\u606f\u3002<br \/>\ns\u76ee\u5f55\u4e0b\u7684Makefile\u6587\u4ef6\u5305\u542b\u4e86\u6240\u6709\u7528\u6765\u6839\u636ekbuild Makefile \u6784\u5efa\u5185\u6838\u6240\u9700\u7684\u5b9a\u4e49\u548c\u89c4\u5219\u3002<\/p>\n<p>Kbuild Makefile<br \/>\n\u5bf9\u4e8eMakefiles\u7684\u4e0d\u540c\u7ec4\u6210\u90e8\u5206\uff0c\u6709\u4e00\u4e9b\u4e0d\u540c\u7684\u8bed\u6cd5\u89c4\u5219\u3002\u9488\u5bf9\u7684\u5bf9\u8c61\u4e5f\u4e0d\u540c\uff0c\u5bf9\u4e8e\u5927\u90e8\u5206\u5185\u6838\u6a21\u5757\u6216\u8bbe\u5907\u9a71\u52a8\u7684\u5f00\u53d1\u8005\u548c\u4f7f\u7528\u8005\u6765\u8bf4\uff0c\u6700\u5e38\u63a5\u89e6\u5230\u7684\u5c31\u662f\u5404\u5c42\u76ee\u5f55\u4e0b\u57fa\u4e8ekbuild\u67b6\u6784\u7684kbuild Makefile\u6587\u4ef6\u3002Kbuild Makefile\u6838\u5fc3\u5185\u5bb9\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n<p>1.\u76ee\u6807\u5b9a\u4e49<br \/>\n\u76ee\u6807\u5b9a\u4e49\u5c31\u662f\u7528\u6765\u5b9a\u4e49\u54ea\u4e9b\u5185\u5bb9\u8981\u505a\u4e3a\u6a21\u5757\u7f16\u8bd1\uff0c\u54ea\u4e9b\u8981\u7f16\u8bd1\u94fe\u63a5\u8fdb\u5185\u6838\u3002\u5982\uff1a<br \/>\nobj-y += foo.o<br \/>\n\u8868\u793a\u8981\u7531foo.c\u6216\u8005foo.s\u6587\u4ef6\u7f16\u8bd1\u5f97\u5230foo.o\u5e76\u94fe\u63a5\u8fdb\u5185\u6838\uff0c\u800cobj-m\u5219\u8868\u793a\u8be5\u6587\u4ef6\u8981\u4f5c\u4e3a\u6a21\u5757\u7f16\u8bd1\u3002 \u9664\u4e86y\uff0cm\u4ee5\u5916\u7684obj-x\u5f62\u5f0f\u7684\u76ee\u6807\u90fd\u4e0d\u4f1a\u88ab\u7f16\u8bd1\u3002\u800c\u66f4\u5e38\u89c1\u7684\u505a\u6cd5\u662f\u6839\u636e.config\u6587\u4ef6\u7684CONFIG_ \u53d8\u91cf\u6765\u51b3\u5b9a\u6587\u4ef6\u7684\u7f16\u8bd1\u65b9\u5f0f\uff0c\u5982\uff1a<br \/>\nobj-<\/span>(CONFIG_EXT2) += ext2.o<\/p>\n<p>Step1\uff1a\u7f16\u8f91\u914d\u7f6e\u6587\u4ef6Kconfig\uff0c\u52a0\u5165\u9a71\u52a8\u9009\u9879\uff0c\u4f7f\u4e4b\u5728make menuconfig \u7684\u65f6\u5019\u51fa\u73b0.\u6253\u5f00 linux-2.6.32.2\/drivers\/char\/Kconfig \u6587\u4ef6\uff0c\u6dfb\u52a0\u5982\u56fe\u6240\u793a\uff1a<\/p>\n<p><a href=\"http:\/\/images.cnblogs.com\/cnblogs_com\/taomaomao\/201201\/201201051049228169.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/www.51cos.com\/wp-content\/uploads\/2017\/03\/a6f57f3884f664963fe3797e15f4a213.png\" alt=\"image\" width=\"475\" height=\"333\" border=\"0\" \/><\/a><\/p>\n<p>\u4fdd\u5b58\u9000\u51fa\uff0c\u8fd9\u65f6\u5728linux-2.6.32.2 \u76ee\u5f55\u4f4d\u7f6e\u8fd0\u884c\u4e00\u4e0bmake menuconfig \u5c31\u53ef\u4ee5\u5728Device \/Drivers Character devices \u83dc\u5355\u4e2d\u770b\u5230\u521a\u624d\u6240\u6dfb\u52a0\u7684\u9009\u9879\u4e86\uff0c\u6309\u4e0b\u7a7a\u683c\u952e\u5c06\u4f1a\u9009\u62e9\u4e3a&lt;M&gt;\uff0c \u6b64\u610f\u4e3a\u8981\u628a\u8be5\u9009\u9879\u7f16\u8bd1\u4e3a\u6a21\u5757\u65b9\u5f0f\uff1b\u518d\u6309\u4e0b\u7a7a\u683c\u4f1a\u53d8\u4e3a&lt;*&gt;\uff0c\u610f\u4e3a\u8981\u628a\u8be5\u9009\u9879\u7f16\u8bd1\u5230\u5185\u6838\u4e2d\uff0c \u5728\u6b64\u6211\u4eec\u9009\u62e9&lt;M&gt;\uff0c\u5982\u56fe\uff1a<\/p>\n<p><a href=\"http:\/\/images.cnblogs.com\/cnblogs_com\/taomaomao\/201201\/201201051049241809.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/www.51cos.com\/wp-content\/uploads\/2017\/03\/76ef6d4f9958af013472bc0553420989.png\" alt=\"image\" width=\"473\" height=\"324\" border=\"0\" \/><\/a><\/p>\n<p>Step2\uff1a\u901a\u8fc7\u4e0a\u4e00\u6b65\uff0c\u6211\u4eec\u867d\u7136\u53ef\u4ee5\u5728\u914d\u7f6e\u5185\u6838\u7684\u65f6\u5019\u8fdb\u884c\u9009\u62e9\uff0c\u4f46\u5b9e\u9645\u4e0a\u6b64\u65f6\u6267\u884c\u7f16\u8bd1\u5185\u6838\u8fd8\u662f\u4e0d\u80fd\u628amini2440_hello_module.c \u7f16\u8bd1\u8fdb\u53bb\u7684\uff0c\u8fd8\u9700\u8981\u5728Makefile \u4e2d\u628a\u5185\u6838\u914d\u7f6e\u9009\u9879\u548c\u771f\u6b63\u7684\u6e90\u4ee3\u7801\u8054\u7cfb\u8d77\u6765\uff0c\u6253\u5f00linux-2.6.32.2\/drivers\/char\/Makefile\uff0c\u5982\u56fe\u6dfb\u52a0\u5e76\u4fdd\u5b58\u9000\u51fa\uff1a<\/p>\n<p><a href=\"http:\/\/images.cnblogs.com\/cnblogs_com\/taomaomao\/201201\/201201051049261262.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/www.51cos.com\/wp-content\/uploads\/2017\/03\/a5356f51dacca285cd1db8952e6bf1f5.png\" alt=\"image\" width=\"471\" height=\"321\" border=\"0\" \/><\/a><\/p>\n<p>Step3\uff1a\u8fd9\u65f6\u56de\u5230linux-2.6.32.2 \u6e90\u4ee3\u7801\u6839\u76ee\u5f55\u4f4d\u7f6e\uff0c\u6267\u884cmake modules\uff0c\u5c31\u53ef\u4ee5\u751f\u6210\u6211\u4eec\u6240\u9700\u8981\u7684\u5185\u6838\u6a21\u5757\u6587\u4ef6 mini2440_hello_module.ko \u4e86\uff0c\u5982\u56fe\uff1a\u81f3\u6b64\uff0c\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u6a21\u5757\u9a71\u52a8\u7684\u7f16\u8bd1\u3002<\/p>\n<p><a href=\"http:\/\/images.cnblogs.com\/cnblogs_com\/taomaomao\/201201\/201201051049298490.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"http:\/\/www.51cos.com\/wp-content\/uploads\/2017\/03\/b035f0ece1b00400c40dab763d19655c.png\" alt=\"image\" width=\"468\" height=\"319\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>kconfig\uff1a\u4e00\u4e2a\u6587\u672c\u5f62\u5f0f\u7684\u6587\u4ef6\uff0c\u5176\u4e2d\u4e3b\u8981\u4f5c\u7528\u662f\u5728\u5185\u6838\u914d\u7f6e\u65f6\u5019\uff0c\u4f5c\u4e3a\u914d\u7f6e\u9009\u9879\u3002 .config\uff1a\u6587\u4ef6\u662f\u5728\u8fdb\u884c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2139","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/2139","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2139"}],"version-history":[{"count":1,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/2139\/revisions"}],"predecessor-version":[{"id":2144,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/2139\/revisions\/2144"}],"wp:attachment":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2139"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2139"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2139"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}