{"id":234863,"date":"2022-02-02T09:21:42","date_gmt":"2022-02-02T01:21:42","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=234863"},"modified":"2022-01-25T22:22:41","modified_gmt":"2022-01-25T14:22:41","slug":"linux-device-tree","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-device-tree.html","title":{"rendered":"\u804a\u804aLinux \u8fd0\u884c\u65f6\u8bbe\u5907\u6811"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u6839\u6587\u4ef6\u7cfb\u7edf\u4e2d\u67e5\u770b\u8bbe\u5907\u6811\uff0c\u662f\u4e00\u79cd\u4e0d\u9519\u7684\u8c03\u8bd5\u624b\u6bb5\u3002\u56e0\u4e3a\u5f88\u591a\u65f6\u5019\u4f1a\u51fa\u73b0\u4f60\u4fee\u6539\u4e86 dts \u6587\u4ef6\uff0c\u5e76\u4e14\u4e5f\u7f16\u8bd1\u4e86\u65b0\u7684 dtb\uff0c\u4f46\u662f\u4e0b\u8f7d\u5230\u677f\u5b50\u4e0a\u7684\u8fd8\u662f\u4ee5\u524d\u7684 dtb\uff0c\u56e0\u6b64\u67e5\u770b\u677f\u5b50\u4e2d\u771f\u5b9e\u751f\u6548\u7684\u8bbe\u5907\u6811\u914d\u7f6e\u4fe1\u606f\u662f\u5f88\u91cd\u8981\u7684\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
1\u3001\u8bbe\u5907\u6811\u539f\u59cb dtb \u683c\u5f0f<\/strong><\/div>\n

\u5728\u5982\u4e0b\u76ee\u5f55\uff0cfdt \u5c31\u662f\u6211\u4eec\u7684 \u8bbe\u5907\u6811*.dtb\u6587\u4ef6<\/p>\n

\r\n\/sys\/firmware\/fdt     \/\/\u539f\u59cbdtb\u6587\u4ef6\r\n<\/pre>\n

\u6267\u884c\u4ee5\u4e0b\u6307\u4ee4\u53ef\u770b<\/p>\n

\r\nhexdump -C \/sys\/firmware\/fdt\r\n<\/pre>\n

\u8fd9\u4e2a\u547d\u4ee4\u6253\u5f00\u540e\u662f\u5341\u516d\u8fdb\u5236\u6a21\u5f0f\uff0c\u5982\u56fe\uff1a<\/p>\n

\"\"<\/p>\n

\u8fd9\u6837\u662f\u5f88\u96be\u770b\u5230\u771f\u5b9e\u914d\u7f6e\u7684\uff0c\u53ef\u4ee5\u628a fdt \u5f04\u51fa\u6765\uff0c\u653e\u5230 ubuntu \u4e2d\uff0c\u4f7f\u7528 Linux \u6e90\u7801\u81ea\u5e26\u7684 DTC \u5de5\u5177\u53cd\u7f16\u8bd1\uff0c\u67e5\u770b\u771f\u5b9e\u7684\u914d\u7f6e\u3002\u53cd\u7f16\u8bd1\u547d\u4ee4\u4e3a\uff1a<\/p>\n

\r\n\/script\/dtc\/dtc -I dtb -O dts -o xxx.dts xxx.dtb\r\n<\/pre>\n

DTS \u662f\u8bbe\u5907\u6811\u6e90\u7801\u6587\u4ef6\uff0cDTB \u662f\u5c06 DTS \u7f16\u8bd1\u4ee5\u540e\u5f97\u5230\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002\u5c06 .c \u6587\u4ef6\u7f16\u8bd1\u4e3a .o \u9700\u8981\u7528\u5230 gcc \u7f16\u8bd1\u5668\uff0c\u90a3\u4e48\u5c06.dts \u7f16\u8bd1\u4e3a.dtb \u9700\u8981\u4ec0\u4e48\u5de5\u5177\u5462?\u9700\u8981\u7528\u5230 DTC \u5de5\u5177!\u53cd\u7f16\u8bd1\u4e5f\u662f\u8fd9\u4e2a\u5de5\u5177\uff0c\u53cd\u7f16\u8bd1\u540e\u53ef\u4ee5\u770b\u5230\u65b9\u4fbf\u67e5\u770b\u7684\u8bbe\u5907\u6811\uff0c\u5b57\u7b26\u4e32\u4f1a\u6062\u590d\uff0c\u6570\u5b57\u4f1a\u53d8\u6210\u5341\u516d\u8fdb\u5236\u683c\u5f0f\u3002<\/p>\n

\u5728 u-boot \u542f\u52a8\u5185\u6838\u65f6\uff0c\u4f1a\u5c06 dtb \u6587\u4ef6\u7684\u5185\u5b58\u5730\u5740\u4f20\u9012\u7ed9\u5185\u6838\uff0c\u5e76\u5c06\u5176\u6240\u5360\u5185\u5b58\u4fdd\u7559;\u56e0\u6b64\uff0c\u6211\u4eec\u5728\u5185\u6838\u542f\u52a8\u540e\uff0c\u8bbf\u95ee\u8be5\u5185\u5b58\uff0c\u83b7\u5f97\u539f\u59cb\u7684 dtb\u3002<\/p>\n

2\u3001\u8bbe\u5907\u6811\u76ee\u5f55\u7ed3\u6784 dtb \u683c\u5f0f<\/strong><\/div>\n
\r\n\/sys\/firmware\/devicetree\r\n<\/pre>\n

\u4ee5\u76ee\u5f55\u7ed3\u6784\u7a0b\u73b0\u7684 dtb \u6587\u4ef6, \u6839\u8282\u70b9\u5bf9\u5e94 base \u76ee\u5f55, \u6bcf\u4e00\u4e2a\u8282\u70b9\u5bf9\u5e94\u4e00\u4e2a\u76ee\u5f55, \u6bcf\u4e00\u4e2a\u5c5e\u6027\u5bf9\u5e94\u4e00\u4e2a\u6587\u4ef6\uff1a<\/p>\n

\"\"<\/p>\n

\u5728\u8fd9\u91cc\u4f60\u5c31\u53ef\u4ee5\u770b\u5230\u4f60\u914d\u7f6e\u7684\u8bbe\u5907\u6811\u8282\u70b9\u4fe1\u606f\uff0c\u5b57\u7b26\u4e32\u4f7f\u7528 cat\uff0c\u6570\u5b57\u4f7f\u7528 xxd \u3001hexdump \u547d\u4ee4\uff1a<\/p>\n

\"\"<\/p>\n

3\u3001\u5185\u6838\u4e2d\u73b0\u5b58\u7684\u6240\u6709 platform_device<\/strong><\/div>\n
\r\n\/sys\/devices\/platform \r\n<\/pre>\n

\u7cfb\u7edf\u4e2d\u6240\u6709\u7684 platform_device, \u6709\u6765\u81ea\u8bbe\u5907\u6811\u7684, \u4e5f\u6709\u6765\u6709 .c \u6587\u4ef6\u4e2d\u6ce8\u518c\u7684\u3002<\/p>\n

\u5bf9\u4e8e\u6765\u81ea\u8bbe\u5907\u6811\u7684 platform_device,\u53ef\u4ee5\u8fdb\u5165 \/sys\/devices\/platform\/<\u8bbe\u5907\u540d>\/of_node \u67e5\u770b\u5b83\u7684\u8bbe\u5907\u6811\u5c5e\u6027\u3002<\/p>\n

\u5bf9\u4e8e\u6709 of_node \u5c5e\u6027\u7684 platform_device\uff0c\u8bc1\u660e\u5176\u6765\u6e90\u4e8e dtb\u3002<\/p>\n

note\uff1a\/proc\/device-tree \u662f\u94fe\u63a5\u6587\u4ef6, \u6307\u5411 \/sys\/firmware\/devicetree\/base<\/p>\n

\u4ee5\u4e0a\u662f Linux \u539f\u751f\u7684\u8282\u70b9\uff0c\u53ef\u4ee5\u4f9b\u6211\u4eec\u4f7f\u7528\u3002\u5982\u679c\u4f60\u7528\u7684\u82af\u7247\u662f\u67d0\u4e2a\u5382\u5bb6\uff0c\u8fd9\u4e2a\u5382\u5bb6\u5ba2\u5236\u5316\u7684\u65f6\u5019\u4f1a\u589e\u52a0\u4e00\u4e9b\u8c03\u8bd5\u8282\u70b9\uff0c\u4f60\u53ef\u4ee5\u5f88\u65b9\u4fbf\u7684\u5728 IC \u5382\u5546\u589e\u52a0\u7684\u8c03\u8bd5\u8282\u70b9\u4e2d\u67e5\u770b\u8bbe\u5907\u6811\u4fe1\u606f\u3002<\/p>\n

\u91cd\u8981\u8865\u5145\uff1a<\/strong><\/div>\n

Linux \u5e38\u7528\u7684\u6587\u4ef6\u7cfb\u7edf\u6709\u4e09\u4e2a\uff1aprocfs\u3001sysfs\u3001debugfs<\/p>\n

procfs\uff1a\u8be5\u6587\u4ef6\u7cfb\u7edf\u4e3b\u8981\u7528\u6765\u53cd\u9988\u5185\u6838\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u7cfb\u7edf\u4e2d\u6240\u6709\u7684\u4e2d\u65ad\u3001\u8fdb\u7a0b\u4fe1\u606f\u90fd\u53ef\u4ee5\u5728\u8fd9\u91cc\u67e5\u770b\u3002\u6302\u8f7d\u5728 \/proc\/...<\/p>\n

sysfs\uff1a\u8be5\u6587\u4ef6\u7cfb\u7edf\u4e3b\u8981\u662f\u548c\u9a71\u52a8\u5f3a\u76f8\u5173\uff0c\u4f1a\u53cd\u9988\u6240\u6709\u7684\u9a71\u52a8\u4fe1\u606f\uff0c\u4ee5\u76ee\u5f55\u5f62\u5f0f\u663e\u793a\u3002\u6302\u8f7d\u5728 \/sys\/...<\/p>\n

debugfs\uff1a\u8be5\u6587\u4ef6\u7cfb\u7edf\u6302\u8f7d\u5728 \/sys\/kernel\/debug\/... \uff0c\u4e3b\u8981\u7528\u6765 debug\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5728\u5982\u4e0b\u76ee\u5f55\uff0cfdt \u5c31\u662f\u6211\u4eec\u7684 \u8bbe\u5907\u6811*.dtb\u6587\u4ef6 \/sys\/firmware\/fdt \/\/\u539f\u59cbdtb\u6587\u4ef6 […]<\/p>\n","protected":false},"author":370,"featured_media":55434,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-234863","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234863","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/370"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=234863"}],"version-history":[{"count":2,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234863\/revisions"}],"predecessor-version":[{"id":234868,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/234863\/revisions\/234868"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/55434"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=234863"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=234863"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=234863"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}