Call truncate through perl.

The binary is not available, and we can't pack it in otatools in AOSP,
have to use an alternative.

Bug: 27880501
Test: Generate a payload for boot.img which is not multiple of 4KiB.

(cherry picked from commit d0e9a893163bb6f70b2bb003cda238d7e1a532ed)

Change-Id: I45998cacda2111ba434e6d5c899d348f5b0bc50a
diff --git a/scripts/brillo_update_payload b/scripts/brillo_update_payload
index 47e1f29..1649106 100755
--- a/scripts/brillo_update_payload
+++ b/scripts/brillo_update_payload
@@ -219,6 +219,18 @@
   echo "${default_value}"
 }
 
+# truncate_file <file_path> <file_size>
+#
+# Truncate the given |file_path| to |file_size| using perl.
+# The truncate binary might not be available.
+truncate_file() {
+  local file_path="$1"
+  local file_size="$2"
+  perl -e "open(FILE, \"+<\", \$ARGV[0]); \
+           truncate(FILE, ${file_size}); \
+           close(FILE);" "${file_path}"
+}
+
 # Create a temporary file in the work_dir with an optional pattern name.
 # Prints the name of the newly created file.
 create_tempfile() {
@@ -421,7 +433,7 @@
         echo "Rounding UP partition ${part}.img to a multiple of 4 KiB."
         : $(( filesize = (filesize + 4095) & -4096 ))
       fi
-      truncate --size="${filesize}" "${part_file}"
+      truncate_file "${part_file}" "${filesize}"
     fi
 
     eval "${partitions_array}[\"${part}\"]=\"${part_file}\""