blob: d07781861443e18afcf861279130d74db1ef0876 [file] [log] [blame]
David Brazdil6c63a262019-12-23 13:23:46 +00001#!/usr/bin/env python3
David Brazdil7a462ec2019-08-15 12:27:47 +01002#
3# Copyright 2019 The Hafnium Authors.
4#
Andrew Walbrane959ec12020-06-17 15:01:09 +01005# Use of this source code is governed by a BSD-style
6# license that can be found in the LICENSE file or at
7# https://opensource.org/licenses/BSD-3-Clause.
David Brazdil7a462ec2019-08-15 12:27:47 +01008
9"""Wrapper around Device Tree Compiler (dtc)"""
10
11import argparse
12import os
13import subprocess
14import sys
15
David Brazdil5715f042019-08-27 11:11:51 +010016HF_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
David Brazdil0dbb41f2019-09-09 18:03:35 +010017DTC_ROOT = os.path.join(HF_ROOT, "prebuilts", "linux-x64", "dtc")
18DTC = os.path.join(DTC_ROOT, "dtc")
19FDTOVERLAY = os.path.join(DTC_ROOT, "fdtoverlay")
David Brazdil7a462ec2019-08-15 12:27:47 +010020
David Brazdil0dbb41f2019-09-09 18:03:35 +010021def cmd_compile(args):
22 exec_args = [
David Brazdil52256ff2019-08-23 15:15:15 +010023 DTC,
24 "-I", "dts", "-O", "dtb",
25 "--out-version", "17",
26 ]
27
28 if args.output_file:
David Brazdil0dbb41f2019-09-09 18:03:35 +010029 exec_args += [ "-o", args.output_file ]
David Brazdil52256ff2019-08-23 15:15:15 +010030 if args.input_file:
David Brazdil0dbb41f2019-09-09 18:03:35 +010031 exec_args += [ args.input_file ]
David Brazdil52256ff2019-08-23 15:15:15 +010032
David Brazdil0dbb41f2019-09-09 18:03:35 +010033 return subprocess.call(exec_args)
34
35def cmd_overlay(args):
36 exec_args = [
37 FDTOVERLAY,
38 "-i", args.base_dtb,
39 "-o", args.output_dtb,
40 ] + args.overlay_dtb
41 return subprocess.call(exec_args)
42
43def main():
44 parser = argparse.ArgumentParser()
45 subparsers = parser.add_subparsers(dest="command")
46
47 parser_compile = subparsers.add_parser("compile", help="compile DTS to DTB")
48 parser_compile.add_argument("-i", "--input-file")
49 parser_compile.add_argument("-o", "--output-file")
50
51 parser_overlay = subparsers.add_parser("overlay", help="merge DTBs")
52 parser_overlay.add_argument("output_dtb")
53 parser_overlay.add_argument("base_dtb")
54 parser_overlay.add_argument("overlay_dtb", nargs='*')
55
56 args = parser.parse_args()
57
58 if args.command == "compile":
59 return cmd_compile(args)
60 elif args.command == "overlay":
61 return cmd_overlay(args)
62 else:
63 raise Error("Unknown command: {}".format(args.command))
David Brazdil7a462ec2019-08-15 12:27:47 +010064
65if __name__ == "__main__":
66 sys.exit(main())