Merge changes from topic "sign_target_files_iot-aosp"

* changes:
  Write combined bpt definition directly into META/partition-table.bpt
  Support regenerating partition table with bpttool in sign_target_files_apks
  Don't suppress stderr for 'avbtool make_vbmeta_image'
  Include default Android Things AVB keys in otatools.zip
diff --git a/core/Makefile b/core/Makefile
index 0b7950b..781bc27 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -2352,6 +2352,7 @@
   $(HOST_OUT_EXECUTABLES)/delta_generator \
   $(AVBTOOL) \
   $(BLK_ALLOC_TO_BASE_FS) \
+  $(BPTTOOL) \
   $(BROTLI) \
   $(BUILD_VERITY_METADATA) \
   $(BUILD_VERITY_TREE)
@@ -2401,6 +2402,8 @@
 
 OTATOOLS_DEPS := \
   system/extras/ext4_utils/mke2fs.conf \
+  external/avb/test/data/atx_metadata.bin \
+  external/avb/test/data/testkey_atx_psk.pem \
   external/avb/test/data/testkey_rsa4096.pem \
   $(sort $(shell find system/update_engine/scripts -name \*.pyc -prune -o -type f -print)) \
   $(sort $(shell find build/target/product/security -type f -name \*.x509.pem -o -name \*.pk8 -o \
diff --git a/tools/releasetools/add_img_to_target_files.py b/tools/releasetools/add_img_to_target_files.py
index c6460ca..8ac039f 100755
--- a/tools/releasetools/add_img_to_target_files.py
+++ b/tools/releasetools/add_img_to_target_files.py
@@ -415,9 +415,10 @@
         assert found, 'failed to find %s' % (image_path,)
     cmd.extend(split_args)
 
-  p = common.Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-  p.communicate()
-  assert p.returncode == 0, "avbtool make_vbmeta_image failed"
+  p = common.Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+  stdoutdata, _ = p.communicate()
+  assert p.returncode == 0, \
+      "avbtool make_vbmeta_image failed:\n{}".format(stdoutdata)
   img.Write()
 
 
@@ -427,7 +428,7 @@
   img = OutputFile(
       output_zip, OPTIONS.input_tmp, "IMAGES", "partition-table.img")
   bpt = OutputFile(
-      output_zip, OPTIONS.input_tmp, "IMAGES", "partition-table.bpt")
+      output_zip, OPTIONS.input_tmp, "META", "partition-table.bpt")
 
   # use BPTTOOL from environ, or "bpttool" if empty or not set.
   bpttool = os.getenv("BPTTOOL") or "bpttool"
@@ -444,9 +445,10 @@
   if args:
     cmd.extend(shlex.split(args))
 
-  p = common.Run(cmd, stdout=subprocess.PIPE)
-  p.communicate()
-  assert p.returncode == 0, "bpttool make_table failed"
+  p = common.Run(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+  stdoutdata, _ = p.communicate()
+  assert p.returncode == 0, \
+      "bpttool make_table failed:\n{}".format(stdoutdata)
 
   img.Write()
   bpt.Write()
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index 14d0ca4..1deb031 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -222,6 +222,15 @@
             vendor_base_fs_file,))
         del d["vendor_base_fs_file"]
 
+    # If board_bpt_input_files property is defined then bpttool is being used to
+    # generate the partition table. When signing target-files, the combined
+    # partition table definition is copied into META/partition-table.bpt since
+    # the original input files aren't available.
+    if "board_bpt_input_files" in d:
+      board_bpt_input_files = os.path.join(input_dir, "META", "partition-table.bpt")
+      if os.path.exists(board_bpt_input_files):
+        d["board_bpt_input_files"] = board_bpt_input_files
+
   def makeint(key):
     if key in d:
       d[key] = int(d[key], 0)