summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorGuEe-GUI <[email protected]>2025-06-24 10:38:18 +0800
committerRbb666 <[email protected]>2025-06-30 09:42:39 +0800
commitad2de6e477cad1da7f5c930f4b0f0945fd67a0cd (patch)
tree179d90369758396503bb8b96b23ab3f8c5aede7e /tools
parent3e4f0ec015d6ad8e8c1f43b01b33efe2f6e12b68 (diff)
[TOOLS] Add DTC (Devicetree Compiler) tools
Signed-off-by: GuEe-GUI <[email protected]>
Diffstat (limited to 'tools')
-rw-r--r--tools/dtc.py52
1 files changed, 52 insertions, 0 deletions
diff --git a/tools/dtc.py b/tools/dtc.py
new file mode 100644
index 0000000000..67d7d04f61
--- /dev/null
+++ b/tools/dtc.py
@@ -0,0 +1,52 @@
+#
+# Copyright (c) 2006-2023, RT-Thread Development Team
+#
+# SPDX-License-Identifier: Apache-2.0
+#
+# Change Logs:
+# Date Author Notes
+# 2023-05-10 GuEe-GUI the first version
+#
+
+import os, re
+
+from building import *
+
+__dtc_install_tip = """
+You should install dtc (devicetree compiler) in your system:
+ Linux:
+ Debian/Ubuntu: apt-get install device-tree-compiler
+ Arch/Manjaro: pacman -Sy dtc
+
+ MacOS:
+ brew install dtc
+
+ Windows (MinGW):
+ msys2: pacman -S dtc
+"""
+
+def __check_dtc(value):
+ if value != 0 and os.system("dtc -v") != 0:
+ print(__dtc_install_tip)
+
+def dts_to_dtb(RTT_ROOT, dts_list, options = "", include_paths = [], ignore_warning = []):
+ path = GetCurrentDir() + '/'
+ warning_ops = ""
+ for warning in ignore_warning:
+ warning_ops += " -W no-" + warning
+ for dts in dts_list:
+ dtb = dts.replace('.dts', '.dtb')
+ if not os.path.exists(path + dtb) or os.path.getmtime(path + dtb) < os.path.getmtime(path + dts):
+ tmp_dts = dts + '.tmp'
+ Preprocessing(dts, None, output = tmp_dts, CPPPATH=[RTT_ROOT + '/components/drivers/include'] + include_paths)
+ ret = os.system("dtc -I dts -O dtb -@ -A {} {} {} -o {}".format(warning_ops, options, path + tmp_dts, path + dtb))
+ __check_dtc(ret)
+ if os.path.exists(path + tmp_dts):
+ os.remove(path + tmp_dts)
+
+def dtb_to_dts(RTT_ROOT, dtb_name, dts_name = None, options = ""):
+ path = GetCurrentDir() + '/'
+ if dts_name == None:
+ dts_name = re.sub(r'\.dtb[o]*$', '.dts', dtb_name)
+ ret = os.system("dtc -I dtb -O dts {} {} -o {}".format(options, path + dtb_name, path + dts_name))
+ __check_dtc(ret)