mkbootimg: add support for --dt

Change-Id: I19f149fac693420cf1f630b51293bbd3650a1b59
diff --git a/mkbootimg.py b/mkbootimg.py
index ec29581..b76ed15 100755
--- a/mkbootimg.py
+++ b/mkbootimg.py
@@ -219,7 +219,7 @@
     # flash page size
     args.output.write(pack('I', args.pagesize))
     # version of boot image header
-    args.output.write(pack('I', args.header_version))
+    args.output.write(pack('I', max(args.header_version, filesize(args.dt))))
     # os version and patch level
     args.output.write(pack('I', (args.os_version << 11) | args.os_patch_level))
     # asciiz product name
@@ -230,6 +230,7 @@
     update_sha(sha, args.kernel)
     update_sha(sha, args.ramdisk)
     update_sha(sha, args.second)
+    update_sha(sha, args.dt)
 
     if args.header_version > 0:
         update_sha(sha, args.recovery_dtbo)
@@ -540,6 +541,7 @@
                         help='print the image ID on standard output')
     parser.add_argument('--header_version', type=parse_int, default=0,
                         help='boot image header version')
+    parser.add_argument('--dt', help='path to the device tree image', type=FileType('rb'))
     parser.add_argument('-o', '--output', type=FileType('wb'),
                         help='output file name')
     parser.add_argument('--vendor_boot', type=FileType('wb'),
@@ -568,6 +570,8 @@
     if len(extra_args) > 0:
         raise ValueError(f'Unrecognized arguments: {extra_args}')
 
+    if args.header_version > 0 and args.dt != None:
+        raise ValueError('header_version and dt cannot be set at the same time')
     if args.header_version < 3:
         args.extra_cmdline = args.cmdline[BOOT_ARGS_SIZE-1:]
         args.cmdline = args.cmdline[:BOOT_ARGS_SIZE-1] + b'\x00'
@@ -617,6 +621,7 @@
     write_padded_file(args.output, args.kernel, pagesize)
     write_padded_file(args.output, args.ramdisk, pagesize)
     write_padded_file(args.output, args.second, pagesize)
+    write_padded_file(args.output, args.dt, pagesize)
 
     if args.header_version > 0 and args.header_version < 3:
         write_padded_file(args.output, args.recovery_dtbo, pagesize)