{"id":154,"date":"2023-11-06T11:07:19","date_gmt":"2023-11-06T03:07:19","guid":{"rendered":"https:\/\/www.xuzhe.tj.cn\/?p=154"},"modified":"2025-05-03T09:50:42","modified_gmt":"2025-05-03T01:50:42","slug":"openwrt%e5%9b%ba%e4%bb%b6%e5%b0%81%e8%a3%85%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.xuzhe.tj.cn\/index.php\/2023\/11\/06\/openwrt%e5%9b%ba%e4%bb%b6%e5%b0%81%e8%a3%85%e6%96%b9%e6%b3%95\/","title":{"rendered":"OpenWRT\u56fa\u4ef6\u5c01\u88c5\u65b9\u6cd5"},"content":{"rendered":"<p>\u5728\u5d4c\u5165\u5f0f\u5f0f\u5f00\u53d1\u9886\u57df\uff0c\u5b9a\u5236\u56fa\u4ef6\u955c\u50cf\u6216\u56fa\u4ef6\u6620\u50cf\u5b9a\u5236\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u505a\u6cd5\u3002\u8fd9\u79cd\u505a\u6cd5\u5141\u8bb8\u5f00\u53d1\u8005\u6839\u636e\u7279\u5b9a\u7684\u9700\u6c42\u548c\u5e94\u7528\u573a\u666f\uff0c\u5b9a\u5236\u5e76\u5c01\u88c5\u81ea\u5df1\u7684\u56fa\u4ef6\u3002\u672c\u6587\u5c06\u4ee5OpenWRT\u7cfb\u7edf\u4e3a\u4f8b\uff0c\u8be6\u7ec6\u4ecb\u7ecd\u56fa\u4ef6\u5c01\u88c5\u7684\u65b9\u6cd5\u3002<\/p>\n<p><!--more--><\/p>\n<h1>1. \u81ea\u5b9a\u4e49\u6587\u4ef6<\/h1>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e86\u89e3\u5982\u4f55\u5728OpenWRT\u7cfb\u7edf\u4e2d\u5305\u542b\u81ea\u5b9a\u4e49\u7684\u914d\u7f6e\u6587\u4ef6\u3002\u6839\u636eOpenWRT\u7684<a href=\"https:\/\/openwrt.org\/docs\/guide-developer\/toolchain\/use-buildsystem#custom_files\">\u5b98\u65b9\u6587\u6863<\/a>\uff0c\u81ea\u5b9a\u4e49\u7684\u914d\u7f6e\u6587\u4ef6\u5e94\u8be5\u653e\u5728<code>&lt;buildroot&gt;\/files\/<\/code>\u76ee\u5f55\u4e0b\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u8981\u5728\u56fa\u4ef6\u955c\u50cf\u4e2d\u5305\u542b\u81ea\u5b9a\u4e49\u7684<code>\/etc\/config\/firewall<\/code>\u6216<code>\/etc\/sysctl.conf<\/code>\uff0c\u4f60\u5e94\u8be5\u521b\u5efa\u4ee5\u4e0b\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-shell\">&lt;buildroot&gt;\/files\/etc\/config\/firewall\n&lt;buildroot&gt;\/files\/etc\/sysctl.conf<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u7684<code>&lt;buildroot&gt;<\/code>\u662f<code>~\/source<\/code>\uff0c\u5e76\u4e14\u4f60\u5e0c\u671b\u5c06\u4e00\u4e9b\u6587\u4ef6\u590d\u5236\u5230\u56fa\u4ef6\u955c\u50cf\u7684<code>\/etc\/config<\/code>\u76ee\u5f55\u4e0b\uff0c\u90a3\u4e48\u4f60\u5e94\u8be5\u5c06\u8fd9\u4e9b\u6587\u4ef6\u653e\u5728<code>~\/source\/files\/etc\/config<\/code>\u76ee\u5f55\u4e0b\u3002<\/p>\n<p>OpenWRT\u5f3a\u70c8\u5efa\u8bae\u4f7f\u7528<code>uci-defaults<\/code>\u6765\u9010\u6b65\u96c6\u6210\u53ea\u9700\u8981\u7684\u5b9a\u5236\u5185\u5bb9\u3002\u8fd9\u6709\u52a9\u4e8e\u6700\u5c0f\u5316\u4e0e\u81ea\u52a8\u751f\u6210\u8bbe\u7f6e\u4e4b\u95f4\u7684\u51b2\u7a81\uff0c\u8fd9\u4e9b\u8bbe\u7f6e\u53ef\u80fd\u4f1a\u5728\u7248\u672c\u4e4b\u95f4\u53d1\u751f\u53d8\u5316\u3002<\/p>\n<h1>2. \u7cfb\u7edf\u5b9a\u5236\u5185\u5bb9<\/h1>\n<p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u6765\u770b\u4e00\u4e2a\u5177\u4f53\u7684\u4f8b\u5b50\u3002\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u7cfb\u7edf\u7684\u5b9a\u5236\u5185\u5bb9\u4e3b\u8981\u662f\u5bf9\u7cfb\u7edf\u7684\u914d\u7f6e\u6587\u4ef6<code>\/etc\/config\/system<\/code>\u8fdb\u884c\u4fee\u6539\u3002\u4fee\u6539\u540e\u7684\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-shell\">config system\n    option hostname Jotale\n    option timezone UTC\n\nconfig timeserver ntp\n    list server 0.openwrt.pool.ntp.org\n    list server 1.openwrt.pool.ntp.org\n    list server 2.openwrt.pool.ntp.org\n    list server 3.openwrt.pool.ntp.org\n    option enabled 1\n    option enable_server 0\n\nconfig led\n    option default &#039;0&#039;\n    option name &#039;system&#039;\n    option sysfs &#039;mediatek:green:system&#039;\n    option trigger &#039;timer&#039;\n    option delayon &#039;1000&#039;\n    option delayoff &#039;1000&#039;\n\nconfig led\n    option default &#039;0&#039;\n    option name &#039;wifi&#039;\n    option sysfs &#039;mediatek:green:wifi&#039;\n    option trigger &#039;netdev&#039;\n    option dev &#039;ra0&#039;\n    option mode &#039;link tx rx&#039;\n\nconfig button             \n        option button   BTN_1\n        option action   released\n        option handler  reboot\n    option min  0\n    option max  2\n\nconfig button\n    option button   BTN_1\n    option action   released\n    option handler  &#039;jffs2reset -y &amp;&amp; reboot&#039;\n    option min  6\n    option max  30\n\nconfig button\n    option button   BTN_2\n    option action   pressed\n    option handler  &#039;kill -SIGUSR2 $(pgrep my_program)&#039;<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u4e86BTN_2 button\u7684\u914d\u7f6e\uff0c\u4f7f\u5f97\u901a\u8fc7\u6309\u952e\u53ef\u4ee5\u53d1\u9001\u4fe1\u53f7\u7ed9<code>my_program<\/code>\u3002<code>my_program<\/code>\u662f\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u7a0b\u5e8f\uff0c\u7528\u6765\u63a7\u5236\u7cfb\u7edf\u7684\u4e00\u4e9b\u529f\u80fd\u3002\u5728\u5237\u5199\u56fa\u4ef6\u540e\uff0c\u8fd9\u4e2a\u914d\u7f6e\u6587\u4ef6\u5c31\u66ff\u6362\u4e86\u7cfb\u7edf\u4e2d\u7684<code>\/etc\/config\/system<\/code>\u6587\u4ef6\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u52a0\u5165\u81ea\u5b9a\u4e49\u7684\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c<code>my_program<\/code>\u7684\u7f16\u8bd1\u540e\u7684\u53ef\u76f4\u63a5\u8fd0\u884c\u7684\u7a0b\u5e8f\u4ee5\u53ca\u7a0b\u5e8f\u7684\u914d\u7f6e\u6587\u4ef6\u7b49\u3002\u5c06\u8fd9\u4e9b\u6587\u4ef6\u653e\u5728<code>&lt;buildroot&gt;\/files\/opt\/cky\/<\/code>\u76ee\u5f55\u4e0b\uff0c\u8fd9\u6837\u5728\u7f16\u8bd1\u56fa\u4ef6\u7684\u65f6\u5019\uff0c\u8fd9\u4e9b\u6587\u4ef6\u5c31\u4f1a\u88ab\u7f16\u8bd1\u8fdb\u56fa\u4ef6\u4e2d\u3002\u5728\u5237\u5199\u56fa\u4ef6\u540e\uff0c\u8fd9\u4e9b\u6587\u4ef6\u5c31\u4f1a\u88ab\u653e\u5728<code>\/opt\/cky\/<\/code>\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c<code>my_program<\/code>\u7a0b\u5e8f\u3002<\/p>\n<h1>3. \u96c6\u6210\u8f6f\u4ef6\u5305<\/h1>\n<p>\u9664\u4e86\u914d\u7f6e\u6587\u4ef6\u548c\u81ea\u5b9a\u4e49\u7a0b\u5e8f\uff0c\u8fd8\u53ef\u4ee5\u96c6\u6210\u4e00\u4e9b\u8f6f\u4ef6\u5305\u3002\u4f8b\u5982\uff0c\u8fd0\u884cC++\u7a0b\u5e8f\u9700\u8981\u7684<code>libstdcpp_4.8-linaro-1_ramips_24kec.ipk<\/code>\u4ee5\u53ca<code>kmod-gpio_control_driver_3.18.29-1_ramips_24kec.ipk<\/code>\u8f6f\u4ef6\u5305\uff0c\u8fd9\u4e9b\u5305\u662f\u53ef\u4ee5\u901a\u8fc7<code>make menuconfig<\/code>\u76f4\u63a5\u7f16\u8bd1\u8fdb\u56fa\u4ef6\u4e2d\u7684\u3002\u8fd9\u6837\u5728\u5237\u5199\u56fa\u4ef6\u540e\uff0c\u8fd9\u4e9b\u5305\u5c31\u4f1a\u88ab\u5b89\u88c5\u5230\u7cfb\u7edf\u4e2d\u3002<\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u7684\u6b65\u9aa4\uff0cOpenWRT\u7cfb\u7edf\u7684\u914d\u7f6e\u6587\u4ef6\u3001\u8f6f\u4ef6\u5305\u4ee5\u53ca\u81ea\u5b9a\u4e49\u7684\u7a0b\u5e8f\u5c31\u90fd\u53ef\u4ee5\u96c6\u4e2d\u5728\u4e00\u4e2a\u56fa\u4ef6\u4e2d\u4e86\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a\u5b8c\u5168\u5b9a\u5236\u7684OpenWRT\u56fa\u4ef6\uff0c\u6ee1\u8db3\u7279\u5b9a\u7684\u9700\u6c42\u548c\u5e94\u7528\u573a\u666f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5d4c\u5165\u5f0f\u5f0f\u5f00\u53d1\u9886\u57df\uff0c\u5b9a\u5236\u56fa\u4ef6\u955c\u50cf\u6216\u56fa\u4ef6\u6620\u50cf\u5b9a\u5236\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u505a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":530,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[9],"class_list":["post-154","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-10","tag-openwrt"],"_links":{"self":[{"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":3,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"predecessor-version":[{"id":157,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions\/157"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/media\/530"}],"wp:attachment":[{"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xuzhe.tj.cn\/index.php\/wp-json\/wp\/v2\/tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}