blob: 1513120b15e14c84386516eb7e1fe7166c8d530c [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
Olivier Deprez9fa36962021-09-20 14:32:14 +010016DTC = "dtc"
17FDTOVERLAY = "fdtoverlay"
David Brazdil7a462ec2019-08-15 12:27:47 +010018
David Brazdil0dbb41f2019-09-09 18:03:35 +010019def cmd_compile(args):
20 exec_args = [
David Brazdil52256ff2019-08-23 15:15:15 +010021 DTC,
22 "-I", "dts", "-O", "dtb",
23 "--out-version", "17",
24 ]
25
26 if args.output_file:
David Brazdil0dbb41f2019-09-09 18:03:35 +010027 exec_args += [ "-o", args.output_file ]
David Brazdil52256ff2019-08-23 15:15:15 +010028 if args.input_file:
David Brazdil0dbb41f2019-09-09 18:03:35 +010029 exec_args += [ args.input_file ]
David Brazdil52256ff2019-08-23 15:15:15 +010030
David Brazdil0dbb41f2019-09-09 18:03:35 +010031 return subprocess.call(exec_args)
32
33def cmd_overlay(args):
34 exec_args = [
35 FDTOVERLAY,
36 "-i", args.base_dtb,
37 "-o", args.output_dtb,
38 ] + args.overlay_dtb
39 return subprocess.call(exec_args)
40
41def main():
42 parser = argparse.ArgumentParser()
43 subparsers = parser.add_subparsers(dest="command")
44
45 parser_compile = subparsers.add_parser("compile", help="compile DTS to DTB")
46 parser_compile.add_argument("-i", "--input-file")
47 parser_compile.add_argument("-o", "--output-file")
48
49 parser_overlay = subparsers.add_parser("overlay", help="merge DTBs")
50 parser_overlay.add_argument("output_dtb")
51 parser_overlay.add_argument("base_dtb")
52 parser_overlay.add_argument("overlay_dtb", nargs='*')
53
54 args = parser.parse_args()
55
56 if args.command == "compile":
57 return cmd_compile(args)
58 elif args.command == "overlay":
59 return cmd_overlay(args)
60 else:
61 raise Error("Unknown command: {}".format(args.command))
David Brazdil7a462ec2019-08-15 12:27:47 +010062
63if __name__ == "__main__":
64 sys.exit(main())