{"id":17588,"date":"2024-11-18T08:09:42","date_gmt":"2024-11-18T00:09:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/17588\/"},"modified":"2024-11-18T08:09:42","modified_gmt":"2024-11-18T00:09:42","slug":"linux-dts%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/17588\/","title":{"rendered":"Linux DTS\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u4f7f\u7528\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/000\/887\/227\/170928451164586.jpg\" class=\"aligncenter\" title=\"Linux DTS\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u4f7f\u7528\uff1f\u63d2\u56fe\" alt=\"Linux DTS\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u4f7f\u7528\uff1f\u63d2\u56fe\" \/><\/p>\n<p>Linux DTS\uff08Device Tree Source\uff09\u662f\u4e00\u79cd\u63cf\u8ff0\u786c\u4ef6\u4fe1\u606f\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4e3b\u8981\u7528\u4e8e\u63cf\u8ff0\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\u5404\u4e2a\u786c\u4ef6\u8bbe\u5907\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u8bbe\u5907\u7684\u5730\u5740\u3001\u4e2d\u65ad\u3001\u5bc4\u5b58\u5668\u914d\u7f6e\u4ee5\u53ca\u8bbe\u5907\u9a71\u52a8\u7b49\u3002\u5728Linux\u5185\u6838\u4e2d\uff0cDTS\u6587\u4ef6\u901a\u5e38\u88ab\u7528\u6765\u63cf\u8ff0\u677f\u8f7d\u8bbe\u5907\u7684\u786c\u4ef6\u4fe1\u606f\uff0c\u4ee5\u4fbf\u64cd\u4f5c\u7cfb\u7edf\u80fd\u591f\u6b63\u786e\u5730\u8bc6\u522b\u548c\u4f7f\u7528\u786c\u4ef6\u8bbe\u5907\u3002<\/p>\n<h3>DTS\u6587\u4ef6\u7ed3\u6784<\/h3>\n<p>\u4e00\u4e2a\u5178\u578b\u7684DTS\u6587\u4ef6\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>\/dts-v1\/;\n\n#include &lt;imx6qdl-pico.dtsi&gt;\n#include &lt;imx6qdl-pico-m4.dtsi&gt;\n\n\/ {\n    compatible = \"fsl,imx6q-pico\", \"fsl,imx6q\";\n    \n    model = \"Boundary Devices i.MX6 Quad SABRE Lite\";\n    \n    memory {\n        device_type = \"memory\";\n        reg = ;\n    };\n    \n    chosen {\n        compatible = \"brcm,bcm2835\";\n        uart_boot = ;\n    };\n\n    aliases {\n        serial0 = &amp;amp;uart1;\n    };\n\n    soc {\n        compatible = \"simple-bus\";\n        #address-cells = ;\n        #size-cells = ;\n        ranges;\n        \n        gpio: gpio@0209c000 {\n            compatible = \"fsl,imx6ul-gpio\";\n            reg = ;\n            interrupts = &lt;gpion irqn&gt;;\n            gpio-controller;\n            #gpio-cells = ;\n        };\n    \n    };\n    \n    uart1: serial@02020000 {\n        compatible = \"fsl,imx6q-uart\", \"fsl,imx21-uart\";\n        reg = ;\n        interrupts = ;\n        clocks = ;\n        clock-names = \"ipg\", \"per\";\n        status = \"okay\";\n    };\n    \n    sound {\n        compatible = \"fsl,imx6-sai\";\n        model = \"imx6-sai\";\n        status = \"okay\";\n        \/* SSI1 *\/\n        ssi@021d8000 {\n            compatible = \"fsl,imx6-sai\";\n            reg = ;\n            interrupts = ;\n            clocks = ;\n            dmas = , , ;\n            dma-names = \"tx\", \"rx\", \"mclk\";\n            status = \"okay\";\n        };\n    };\n};&lt;\/gpion&gt;&lt;\/imx6qdl-pico-m4.dtsi&gt;&lt;\/imx6qdl-pico.dtsi&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<h3>DTS\u6587\u4ef6\u5185\u5bb9\u8bf4\u660e<\/h3>\n<ul>\n<li>\/dts-v1\/: \u6307\u5b9a\u7248\u672c\u4e3aDTS\u7248\u672c1\uff0c\u63cf\u8ff0DTS\u6587\u4ef6\u7684\u7248\u672c\u4fe1\u606f\u3002<\/li>\n<li>#include  : \u5305\u542b\u5176\u4ed6DTS\u6587\u4ef6\uff0c\u53ef\u590d\u7528\u5176\u5b9a\u4e49\u3002  <\/li>\n<li>\/: \u6839\u8282\u70b9\uff0c\u63cf\u8ff0\u6574\u4e2a\u8bbe\u5907\u6811\u7ed3\u6784\u3002<\/li>\n<li>compatible: \u6307\u5b9a\u8bbe\u5907\u517c\u5bb9\u6027\u4fe1\u606f\u3002<\/li>\n<li>model: \u8bbe\u5907\u578b\u53f7\u4fe1\u606f\u3002<\/li>\n<li>memory: \u63cf\u8ff0\u5185\u5b58\u4fe1\u606f\u3002<\/li>\n<li>chosen: \u63cf\u8ff0\u4e00\u4e9b\u9009\u9879\u4fe1\u606f\u3002<\/li>\n<li>aliases: \u5b9a\u4e49\u8bbe\u5907\u522b\u540d\u3002<\/li>\n<li>soc: \u63cf\u8ff0SoC\u76f8\u5173\u4fe1\u606f\u3002<\/li>\n<li>gpio: \u63cf\u8ff0GPIO\u63a7\u5236\u5668\u3002<\/li>\n<li>uart1: \u63cf\u8ff0UART1\u786c\u4ef6\u4fe1\u606f\u3002<\/li>\n<li>sound: \u63cf\u8ff0\u58f0\u97f3\u8bbe\u5907\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<h3>\u5982\u4f55\u4f7f\u7528Linux DTS<\/h3>\n<ol>\n<li>\u7f16\u8f91DTS\u6587\u4ef6\uff1a\u5728Linux\u5185\u6838\u6e90\u7801\u4e2d\u7684arch\/arm\/boot\/dts\/\u76ee\u5f55\u4e0b\u627e\u5230\u5bf9\u5e94\u5e73\u53f0\u7684DTS\u6587\u4ef6\uff08\u5982imx6qdl-pico.dtsi\uff09\uff0c\u6839\u636e\u5b9e\u9645\u786c\u4ef6\u4fe1\u606f\u7f16\u8f91DTS\u6587\u4ef6\u3002<\/li>\n<li>\n<p>\u7f16\u8bd1DTS\u6587\u4ef6\uff1a\u5728Linux\u5185\u6838\u6e90\u7801\u6839\u76ee\u5f55\u4e0b\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u7f16\u8bd1DTS\u6587\u4ef6\uff1a<\/p>\n<pre>make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- dtbs<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/li>\n<li>\u66ff\u6362\u8bbe\u5907\u6811\u4e8c\u8fdb\u5236\u6587\u4ef6\uff1a\u5c06\u751f\u6210\u7684.dtb\u6587\u4ef6\uff08\u8bbe\u5907\u6811\u4e8c\u8fdb\u5236\u6587\u4ef6\uff09\u66ff\u6362\u5230\u76ee\u6807\u8bbe\u5907\u7684\u5f15\u5bfc\u5206\u533a\u3002<\/li>\n<li>\u4f7f\u7528\u8bbe\u5907\u6811\uff1a\u5728Linux\u5185\u6838\u542f\u52a8\u65f6\uff0c\u4f1a\u52a0\u8f7d\u8bbe\u5907\u6811\u6587\u4ef6\u6765\u63cf\u8ff0\u786c\u4ef6\u4fe1\u606f\uff0c\u4ece\u800c\u6b63\u786e\u8bc6\u522b\u548c\u914d\u7f6e\u786c\u4ef6\u8bbe\u5907\u3002<\/li>\n<\/ol>\n<h3>\u4ee3\u7801\u793a\u4f8b<\/h3>\n<pre>#include &lt;linux&gt;\n#include &lt;linux&gt;\n#include &lt;linux&gt;\n\nstatic int my_driver_probe(struct platform_device *pdev)\n{\n    struct device_node *np = pdev-&amp;gt;dev.of_node;\n    \n    if (!np) {\n        dev_err(&amp;amp;pdev-&amp;gt;dev, \"No device tree node found\n\");\n        return -ENODEV;\n    }\n    \n    \/\/ \u89e3\u6790\u8bbe\u5907\u6811\u8282\u70b9\u4fe1\u606f\n    u32 reg;\n    if (of_property_read_u32(np, \"reg\", &amp;amp;reg)) {\n        dev_err(&amp;amp;pdev-&amp;gt;dev, \"Failed to read 'reg' property\n\");\n        return -EINVAL;\n    }\n    \n    dev_info(&amp;amp;pdev-&amp;gt;dev, \"Got 'reg' property: %u\n\", reg);\n    \n    return 0;\n}\n\nstatic const struct of_device_id my_driver_of_match[] = {\n    { .compatible = \"my_driver\", },\n    { },\n};\nMODULE_DEVICE_TABLE(of, my_driver_of_match);\n\nstatic struct platform_driver my_driver = {\n    .probe = my_driver_probe,\n    .driver = {\n        .name = \"my_driver\",\n        .of_match_table = my_driver_of_match,\n        .owner = THIS_MODULE,\n    }\n};\n\nmodule_platform_driver(my_driver);\n\nMODULE_LICENSE(\"GPL\");\nMODULE_AUTHOR(\"Author Name\");\nMODULE_DESCRIPTION(\"Sample driver using Device Tree\");&lt;\/linux&gt;&lt;\/linux&gt;&lt;\/linux&gt;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u662f\u4e00\u4e2a\u7b80\u5355\u7684Linux\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\u793a\u4f8b\uff0c\u901a\u8fc7\u89e3\u6790\u8bbe\u5907\u6811\u8282\u70b9\u4e2d\u7684\u5c5e\u6027\u6765\u914d\u7f6e\u786c\u4ef6\u8bbe\u5907\u3002\u5728probe\u51fd\u6570\u4e2d\uff0c\u9996\u5148\u83b7\u53d6\u8bbe\u5907\u6811\u8282\u70b9\uff0c\u7136\u540e\u8bfb\u53d6\u5176\u4e2d\u7684reg\u5c5e\u6027\u5e76\u8f93\u51fa\u3002\u5728of_device_id\u4e2d\u58f0\u660e\u4e86\u9700\u8981\u5339\u914d\u7684\u8bbe\u5907\u6811\u8282\u70b9\u7684\u517c\u5bb9\u6027\u4fe1\u606f\uff0c\u4ee5\u4fbf\u9a71\u52a8\u7a0b\u5e8f\u6b63\u786e\u5339\u914d\u8bbe\u5907\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fLinux DTS\u662f\u4ec0\u4e48\uff1f\u5982\u4f55\u4f7f\u7528\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Linux DTS\uff08Device Tree Source\uff09\u662f\u4e00\u79cd\u63cf\u8ff0\u786c\u4ef6\u4fe1\u606f\u7684\u6570\u636e\u7ed3\u6784\uff0c\u4e3b\u8981\u7528\u4e8e\u63cf\u8ff0\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\u5404\u4e2a\u786c\u4ef6\u8bbe\u5907\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u8bbe\u5907\u7684\u5730\u5740\u3001\u4e2d\u65ad\u3001\u5bc4\u5b58\u5668\u914d\u7f6e\u4ee5\u53ca\u8bbe\u5907\u9a71\u52a8\u7b49\u3002\u5728Linux\u5185\u6838\u4e2d\uff0cDTS\u6587\u4ef6\u901a\u5e38\u88ab\u7528\u6765\u63cf\u8ff0\u677f\u8f7d\u8bbe\u5907\u7684\u786c\u4ef6\u4fe1\u606f\uff0c\u4ee5\u4fbf\u64cd\u4f5c\u7cfb\u7edf\u80fd\u591f\u6b63\u786e\u5730\u8bc6\u522b\u548c\u4f7f\u7528\u786c\u4ef6\u8bbe\u5907\u3002 DTS\u6587\u4ef6\u7ed3\u6784 \u4e00\u4e2a\u5178\u578b\u7684DTS\u6587\u4ef6\u5982\u4e0b\u6240\u793a\uff1a \/dts-v1\/; #include &lt;imx6qdl-pico.dtsi&gt; #include &lt;imx6qdl-pico-m4.dtsi&gt; \/ { compatible = &#8220;fsl,imx6q-pico&#8221;, &#8220;fsl,imx6q&#8221;; model = &#8220;Boundary Devices i.MX6 Quad SABRE Lite&#8221;; memory { device_type = &#8220;memory&#8221;; reg = ; }; chosen { compatible = &#8220;brcm,bcm2835&#8221;; uart_boot = ; }; aliases { serial0 = &amp;amp;uart1; }; soc { compatible = &#8220;simple-bus&#8221;; #address-cells [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-17588","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17588","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=17588"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/17588\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=17588"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=17588"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=17588"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}