Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Cú pháp DTO
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Định dạng nguồn cây thiết bị (DTS) là một bản trình bày dạng văn bản của cây thiết bị (DT).
Trình biên dịch cây thiết bị (DTC) xử lý định dạng này thành DT nhị phân, đây là hình thức mà nhân Linux dự kiến.
Sử dụng tệp đối chiếu
Dự án DTC (trình biên dịch Cây thiết bị + bản vá lớp phủ) mô tả định dạng DTS trong dtc-format.txt và manual.txt.
Quy tắc và định dạng DTO được mô tả trong tệp dt-object-internal.txt.
Các tài liệu này mô tả cách cập nhật DT chính bằng cách sử dụng nút fragment@x
và cú pháp __overlay__
trong DT lớp phủ. Ví dụ:
/ {
fragment@0 {
target = <&some_node>;
__overlay__ {
some_prop = "okay";
...
};
};
};
Tuy nhiên, Google khuyên bạn không sử dụng fragment@x
và cú pháp __overlay__
, mà thay vào đó hãy sử dụng cú pháp tham chiếu. Ví dụ:
&some_node {
some_prop = "okay";
...
};
Cú pháp tham chiếu được dtc
biên dịch thành cùng một đối tượng như ở trên bằng cách sử dụng cú pháp __overlay__
. Cú pháp này không bắt buộc bạn phải đánh số các mảnh, cho phép bạn dễ dàng đọc và ghi lớp phủ DTS. Nếu dtc
không hỗ trợ cú pháp đơn giản này, hãy sử dụng dtc trong AOSP.
Sử dụng nhãn
Để cho phép các tệp tham chiếu không xác định đến các nút không xuất hiện tại thời điểm biên dịch, tệp .dts
DT lớp phủ phải có thẻ /plugin/
trong tiêu đề. Ví dụ:
/dts-v1/;
/plugin/;
Từ đây, bạn có thể nhắm đến các nút cần phủ bằng cách sử dụng một tệp tham chiếu, đây là một đường dẫn nút tuyệt đối có tiền tố là ký hiệu và (&). Ví dụ: đối với node@0
trong DT chính:
Xác định nhãn trong DT chính ... |
... sau đó sử dụng nhãn. |
[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>;
};
|
Ghi đè
Nếu thuộc tính mục tiêu tham chiếu tồn tại trong DT chính, thì thuộc tính này sẽ bị ghi đè sau DTO; nếu không, thuộc tính này sẽ được thêm vào. Ví dụ:
main.dts |
overlay.dts |
Kết quả hợp nhất |
[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";
};
};
|
Thêm
Nếu thuộc tính mục tiêu tham chiếu không tồn tại trong DT chính, thì thuộc tính này sẽ được thêm vào sau DTO. Ví dụ:
main.dts |
overlay.dts |
Kết quả hợp nhất |
[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";
};
};
|
Nút con
Ví dụ về cú pháp nút con:
main.dts |
overlay.dts |
Kết quả hợp nhất |
[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";
};
};
};
|
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-08-21 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 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\"; }; }; }; ``` |"]]