David Brazdil | 6c63a26 | 2019-12-23 13:23:46 +0000 | [diff] [blame^] | 1 | #!/usr/bin/env python3 |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 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 | |
| 19 | import argparse |
| 20 | import os |
| 21 | import subprocess |
| 22 | import sys |
| 23 | |
David Brazdil | 5715f04 | 2019-08-27 11:11:51 +0100 | [diff] [blame] | 24 | HF_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 25 | DTC_ROOT = os.path.join(HF_ROOT, "prebuilts", "linux-x64", "dtc") |
| 26 | DTC = os.path.join(DTC_ROOT, "dtc") |
| 27 | FDTOVERLAY = os.path.join(DTC_ROOT, "fdtoverlay") |
David Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 28 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 29 | def cmd_compile(args): |
| 30 | exec_args = [ |
David Brazdil | 52256ff | 2019-08-23 15:15:15 +0100 | [diff] [blame] | 31 | DTC, |
| 32 | "-I", "dts", "-O", "dtb", |
| 33 | "--out-version", "17", |
| 34 | ] |
| 35 | |
| 36 | if args.output_file: |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 37 | exec_args += [ "-o", args.output_file ] |
David Brazdil | 52256ff | 2019-08-23 15:15:15 +0100 | [diff] [blame] | 38 | if args.input_file: |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 39 | exec_args += [ args.input_file ] |
David Brazdil | 52256ff | 2019-08-23 15:15:15 +0100 | [diff] [blame] | 40 | |
David Brazdil | 0dbb41f | 2019-09-09 18:03:35 +0100 | [diff] [blame] | 41 | return subprocess.call(exec_args) |
| 42 | |
| 43 | def 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 | |
| 51 | def 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 Brazdil | 7a462ec | 2019-08-15 12:27:47 +0100 | [diff] [blame] | 72 | |
| 73 | if __name__ == "__main__": |
| 74 | sys.exit(main()) |