blob: 2ae8efe42c2b55415c28d555cf83d0ea29085147 [file] [log] [blame]
David Brazdil7a462ec2019-08-15 12:27:47 +01001#!/usr/bin/env python
2#
3# Copyright 2019 The Hafnium Authors.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# https://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17"""Wrapper around Device Tree Compiler (dtc)"""
18
19import argparse
20import os
21import subprocess
22import sys
23
David Brazdil5715f042019-08-27 11:11:51 +010024HF_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
David Brazdil0dbb41f2019-09-09 18:03:35 +010025DTC_ROOT = os.path.join(HF_ROOT, "prebuilts", "linux-x64", "dtc")
26DTC = os.path.join(DTC_ROOT, "dtc")
27FDTOVERLAY = os.path.join(DTC_ROOT, "fdtoverlay")
David Brazdil7a462ec2019-08-15 12:27:47 +010028
David Brazdil0dbb41f2019-09-09 18:03:35 +010029def cmd_compile(args):
30 exec_args = [
David Brazdil52256ff2019-08-23 15:15:15 +010031 DTC,
32 "-I", "dts", "-O", "dtb",
33 "--out-version", "17",
34 ]
35
36 if args.output_file:
David Brazdil0dbb41f2019-09-09 18:03:35 +010037 exec_args += [ "-o", args.output_file ]
David Brazdil52256ff2019-08-23 15:15:15 +010038 if args.input_file:
David Brazdil0dbb41f2019-09-09 18:03:35 +010039 exec_args += [ args.input_file ]
David Brazdil52256ff2019-08-23 15:15:15 +010040
David Brazdil0dbb41f2019-09-09 18:03:35 +010041 return subprocess.call(exec_args)
42
43def cmd_overlay(args):
44 exec_args = [
45 FDTOVERLAY,
46 "-i", args.base_dtb,
47 "-o", args.output_dtb,
48 ] + args.overlay_dtb
49 return subprocess.call(exec_args)
50
51def main():
52 parser = argparse.ArgumentParser()
53 subparsers = parser.add_subparsers(dest="command")
54
55 parser_compile = subparsers.add_parser("compile", help="compile DTS to DTB")
56 parser_compile.add_argument("-i", "--input-file")
57 parser_compile.add_argument("-o", "--output-file")
58
59 parser_overlay = subparsers.add_parser("overlay", help="merge DTBs")
60 parser_overlay.add_argument("output_dtb")
61 parser_overlay.add_argument("base_dtb")
62 parser_overlay.add_argument("overlay_dtb", nargs='*')
63
64 args = parser.parse_args()
65
66 if args.command == "compile":
67 return cmd_compile(args)
68 elif args.command == "overlay":
69 return cmd_overlay(args)
70 else:
71 raise Error("Unknown command: {}".format(args.command))
David Brazdil7a462ec2019-08-15 12:27:47 +010072
73if __name__ == "__main__":
74 sys.exit(main())