ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
ไวยากรณ์ DTO
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
รูปแบบแหล่งที่มาของแผนผังอุปกรณ์ (DTS) คือการแสดงแผนผังอุปกรณ์ (DT) เป็นข้อความ
คอมไพเลอร์ Device Tree (DTC) จะประมวลผลรูปแบบนี้ให้เป็น DT แบบไบนารี ซึ่งเป็นรูปแบบที่เคอร์เนล Linux คาดไว้
ใช้ข้อมูลอ้างอิง
โปรเจ็กต์ DTC (คอมไพเลอร์ต้นไม้อุปกรณ์ + แพตช์การวางซ้อน) จะอธิบายรูปแบบ DTS ใน dtc-format.txt และ manual.txt
รูปแบบและกฎของ DTO อธิบายไว้ใน dt-object-internal.txt
เอกสารเหล่านี้อธิบายวิธีอัปเดต DT หลักโดยใช้โหนด fragment@x
และไวยากรณ์ __overlay__
ใน DT การวางซ้อน เช่น
/ {
fragment@0 {
target = <&some_node>;
__overlay__ {
some_prop = "okay";
...
};
};
};
อย่างไรก็ตาม Google ขอแนะนําอย่างยิ่งให้คุณไม่ใช้ fragment@x
และไวยากรณ์ __overlay__
และใช้ไวยากรณ์อ้างอิงแทน เช่น
&some_node {
some_prop = "okay";
...
};
dtc
จะคอมไพล์ไวยากรณ์อ้างอิงให้เป็นออบเจ็กต์เดียวกับด้านบนโดยใช้ไวยากรณ์ __overlay__
รูปแบบคำสั่งนี้ไม่บังคับให้คุณต้องระบุหมายเลขของข้อมูลโค้ด ทำให้อ่านและเขียน DTS การวางซ้อนได้ง่ายๆ หาก dtc
ไม่รองรับไวยากรณ์ที่ง่ายขึ้นนี้ ให้ใช้ dtc ใน AOSP
ใช้ป้ายกำกับ
หากต้องการอนุญาตการอ้างอิงที่ไม่ระบุซึ่งไม่มีอยู่ ณ เวลาคอมไพล์ ไฟล์ DT .dts
ของการวางซ้อนต้องมีแท็ก /plugin/
ในส่วนหัว เช่น
/dts-v1/;
/plugin/;
จากที่นี่ คุณสามารถกําหนดเป้าหมายโหนดที่จะวางซ้อนโดยใช้การอ้างอิง ซึ่งเป็นเส้นทางโหนดแบบสัมบูรณ์ที่มีเครื่องหมายแอมเพอร์แซนด์ (&) นําหน้า เช่น สําหรับnode@0
ใน DT หลัก
กำหนดป้ายกำกับใน DT หลัก ... |
... จากนั้นใช้ป้ายกำกับ |
[my_main_dt.dts]
/dts-v1/;
/ {
my_node: node@0 {
status = "disabled";
my_child: child@0 {
value = <0xffffffff>;
};
};
};
|
[my_overlay_dt.dts]
/dts-v1/;
/plugin/;
&my_node {
status = "okay";
};
&my_child {
value = <0x1>;
};
|
ลบล้าง
หากพร็อพเพอร์ตี้เป้าหมายอ้างอิงมีอยู่ใน DT หลัก ระบบจะลบล้างพร็อพเพอร์ตี้นั้นหลังจาก DTO มิเช่นนั้น ระบบจะเพิ่มพร็อพเพอร์ตี้นั้นต่อท้าย เช่น
main.dts |
overlay.dts |
ผลลัพธ์ที่ผสานรวม |
[my_main_dt.dts]
/dts-v1/;
/ {
compatible = "corp,foo";
my_node: node@0 {
status = "disabled";
};
};
|
[my_overlay_dt.dts]
/dts-v1/;
/plugin/;
&my_node {
status = "okay";
};
|
/dts-v1/;
/ {
compatible = "corp,foo";
...
node@0 {
linux,phandle = <0x1>;
phandle = <0x1>;
status = "okay";
};
};
|
ต่อท้าย
หากพร็อพเพอร์ตี้เป้าหมายอ้างอิงไม่อยู่ใน DT หลัก ระบบจะเพิ่มพร็อพเพอร์ตี้นั้นต่อท้าย DTO เช่น
main.dts |
overlay.dts |
ผลลัพธ์ที่ผสานรวม |
[my_main_dt.dts]
/dts-v1/;
/ {
compatible = "corp,foo";
my_node: node@0 {
status = "okay";
};
};
|
[my_overlay_dt.dts]
/dts-v1/;
/plugin/;
&my_node {
new_prop = "bar";
};
|
/dts-v1/;
/ {
compatible = "corp,foo";
...
node@0 {
linux,phandle = <0x1>;
phandle = <0x1>;
status = "okay";
new_prop = "bar";
};
};
|
โหนดย่อย
ตัวอย่างไวยากรณ์ของโหนดย่อย
main.dts |
overlay.dts |
ผลลัพธ์ที่ผสานรวม |
[my_main_dt.dts]
/dts-v1/;
/ {
compatible = "corp,foo";
my_nodes: nodes {
compatible = "corp,bar";
node@0 {
status = "disabled";
};
};
};
|
[my_overlay_dt.dts]
/dts-v1/;
/plugin/;
&my_nodes {
new_prop1 = "abc";
node@0 {
status = "okay";
new_prop2 = "xyz";
};
};
|
/dts-v1/;
/ {
compatible = "corp,foo";
...
nodes {
linux,phandle = <0x1>;
phandle = <0x1>;
compatible = "corp,bar";
new_prop1 = "abc";
node@0 {
linux,phandle = <0x2>;
phandle = <0x2>;
status = "okay";
new_prop2 = "xyz";
};
};
};
|
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-08-21 UTC"],[],[],null,["# DTO syntax\n\nDevice tree source (DTS) format is a textual representation of a device tree (DT).\nThe device tree compiler (DTC) processes this format into a binary DT,\nwhich is the form expected by the Linux kernel.\n\nUse references\n--------------\n\nThe [DTC](https://github.com/pantoniou/dtc)\n(device Tree compiler + overlay patches) project describes the DTS format in\n[dtc-format.txt](https://android.googlesource.com/platform/external/dtc/+/refs/heads/android16-release/Documentation/dts-format.txt)\nand\n[manual.txt](https://android.googlesource.com/platform/external/dtc/+/refs/heads/android16-release/Documentation/manual.txt).\nDTO format and rules are described in\n[dt-object-internal.txt](https://android.googlesource.com/platform/external/dtc/+/refs/heads/android16-release/Documentation/dt-object-internal.txt).\nThese documents describe how to update the main DT using node\n`fragment@x` and syntax `__overlay__` in overlay DT. For\nexample: \n\n```objective-c\n/ {\n fragment@0 {\n target = \u003c&some_node\u003e;\n __overlay__ {\n some_prop = \"okay\";\n ...\n };\n };\n};\n```\n\nHowever, Google strongly recommends you do **not** use\n`fragment@x` and syntax `__overlay__`, and instead use the\nreference syntax. For example: \n\n```scdoc\n&some_node {\n some_prop = \"okay\";\n ...\n};\n```\n\nReference syntax is compiled by `dtc` into the same object as the\nabove using syntax `__overlay__`. This syntax doesn't force you to\nnumber the fragments, enabling you to read and write overlay DTS easily. If your\n`dtc` doesn't support this syntactic sugar, use the\n[dtc\nin AOSP](https://android.googlesource.com/platform/external/dtc).\n\nUse labels\n----------\n\nTo allow undefined references to nodes not present at compilation time, the\noverlay DT `.dts` file must have a tag `/plugin/` in its\nheader. For example: \n\n```text\n/dts-v1/;\n/plugin/;\n```\n\nFrom here you can target the nodes to be overlaid using a reference, which is\nan absolute node path prefixed with an ampersand (\\&). For example, for\n`node@0` in the main DT:\n\n| Define labels in the main DT ... | ... then use the labels. |\n|-------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------|\n| ```ini [my_main_dt.dts] /dts-v1/; / { my_node: node@0 { status = \"disabled\"; my_child: child@0 { value = \u003c0xffffffff\u003e; }; }; }; ``` | ```ini [my_overlay_dt.dts] /dts-v1/; /plugin/; &my_node { status = \"okay\"; }; &my_child { value = \u003c0x1\u003e; }; ``` |\n\nOverride\n--------\n\nIf the reference target property exists in the main DT, it is overridden\nafter DTO; otherwise, it is appended. For example:\n\n| main.dts | overlay.dts | Merged Result |\n|-----------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|\n| ```ini [my_main_dt.dts] /dts-v1/; / { compatible = \"corp,foo\"; my_node: node@0 { status = \"disabled\"; }; }; ``` | ```ini [my_overlay_dt.dts] /dts-v1/; /plugin/; &my_node { status = \"okay\"; }; ``` | ```objective-c /dts-v1/; / { compatible = \"corp,foo\"; ... node@0 { linux,phandle = \u003c0x1\u003e; phandle = \u003c0x1\u003e; status = \"okay\"; }; }; ``` |\n\nAppend\n------\n\nIf the reference target property doesn't exist in the main DT, it is\nappended after DTO. For example:\n\n| main.dts | overlay.dts | Merged Result |\n|-------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ```ini [my_main_dt.dts] /dts-v1/; / { compatible = \"corp,foo\"; my_node: node@0 { status = \"okay\"; }; }; ``` | ```ini [my_overlay_dt.dts] /dts-v1/; /plugin/; &my_node { new_prop = \"bar\"; }; ``` | ```objective-c /dts-v1/; / { compatible = \"corp,foo\"; ... node@0 { linux,phandle = \u003c0x1\u003e; phandle = \u003c0x1\u003e; status = \"okay\"; new_prop = \"bar\"; }; }; ``` |\n\nChild nodes\n-----------\n\nExamples of child node syntax:\n\n| main.dts | overlay.dts | Merged Result |\n|------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ```ini [my_main_dt.dts] /dts-v1/; / { compatible = \"corp,foo\"; my_nodes: nodes { compatible = \"corp,bar\"; node@0 { status = \"disabled\"; }; }; }; ``` | ```ini [my_overlay_dt.dts] /dts-v1/; /plugin/; &my_nodes { new_prop1 = \"abc\"; node@0 { status = \"okay\"; new_prop2 = \"xyz\"; }; }; ``` | ```objective-c /dts-v1/; / { compatible = \"corp,foo\"; ... nodes { linux,phandle = \u003c0x1\u003e; phandle = \u003c0x1\u003e; compatible = \"corp,bar\"; new_prop1 = \"abc\"; node@0 { linux,phandle = \u003c0x2\u003e; phandle = \u003c0x2\u003e; status = \"okay\"; new_prop2 = \"xyz\"; }; }; }; ``` |"]]