Merge changes Ic87a736b,I5bc9f541

* changes:
  Change file permission of checkvintf binary
  Allow specifying null vbmeta.img for production system.img
This commit is contained in:
Treehugger Robot
2018-06-12 02:22:32 +00:00
committed by Gerrit Code Review

View File

@@ -1,18 +1,20 @@
#!/bin/bash -ex #!/bin/bash -ex
usage () { usage () {
echo "Create a Mixed Build archive with the given GSI and device archives." echo "Create a Mixed Build archive with the given system and device archives."
echo echo
echo "Usage: $0 [-v <vendor_version>] [-m <modify_system_image_path>] " echo "Usage: $0 [-v <vendor_version>] [-m <modify_system_image_path>] [-p <override_vbmeta_image_path>]"
echo " gsi_build_dir device_build_dir out_dir [check_tool]" echo " system_build_dir device_build_dir out_dir [check_tool]"
echo echo
echo "Options -v and -m must precede positional arguments." echo "Options -v, -m, -p must precede positional arguments."
echo echo
echo "vendor_version is the version of the vendor image when the mixed" echo "vendor_version is the version of the vendor image when the mixed"
echo " build is inter branch. Optional." echo " build is inter branch. Optional."
echo " eg. 8.1.0 for a mixed build of GSI and O-MR1 vendor image." echo " eg. 8.1.0 for a mixed build of GSI and O-MR1 vendor image."
echo "modify_system_image_path is the path to the script that modifies the" echo "modify_system_image_path is the path to the script that modifies the"
echo " system image for an inter branch build target. Optional." echo " system image for an inter branch build target. Optional."
echo "gsi_build_dir is the path to the GSI build" echo "override_vbmeta_image_path is the path to a vbmeta.img to use"
echo " to override the existing vbmeta.img of device. Optional."
echo "system_build_dir is the path to the system build"
echo " eg. aosp_arm64_ab-userdebug." echo " eg. aosp_arm64_ab-userdebug."
echo "device_build_dir is the path to the device build" echo "device_build_dir is the path to the device build"
echo " eg. sailfish-user." echo " eg. sailfish-user."
@@ -39,7 +41,7 @@ cleanup_and_exit () {
trap cleanup_and_exit EXIT trap cleanup_and_exit EXIT
while getopts :v:m: opt; do while getopts :v:m:p: opt; do
case "$opt" in case "$opt" in
v) v)
readonly VENDOR_VERSION="$OPTARG" readonly VENDOR_VERSION="$OPTARG"
@@ -47,6 +49,9 @@ while getopts :v:m: opt; do
m) m)
readonly MODIFY_SYSTEM_SCRIPT="$OPTARG" readonly MODIFY_SYSTEM_SCRIPT="$OPTARG"
;; ;;
p)
readonly OVERRIDE_VBMETA_IMAGE_PATH="$OPTARG"
;;
\?) \?)
exit_badparam "Invalid options: -"$OPTARG"" exit_badparam "Invalid options: -"$OPTARG""
;; ;;
@@ -56,7 +61,7 @@ while getopts :v:m: opt; do
esac esac
done done
if [[ "$OPTIND" -gt 1 && "$OPTIND" -lt 5 ]]; then if [[ -z "${VENDOR_VERSION+x}" && ! -z "${MODIFY_SYSTEM_SCRIPT+x}" ]] || [[ ! -z "${VENDOR_VERSION+x}" && -z "${MODIFY_SYSTEM_SCRIPT+x}" ]]; then
exit_badparam "Options -v and -m must be set together." exit_badparam "Options -v and -m must be set together."
fi fi
@@ -66,19 +71,23 @@ if [[ ! -z "${MODIFY_SYSTEM_SCRIPT+x}" && ! -f "$MODIFY_SYSTEM_SCRIPT" ]]; then
exit_badparam "Script not found: "$MODIFY_SYSTEM_SCRIPT"" exit_badparam "Script not found: "$MODIFY_SYSTEM_SCRIPT""
fi fi
if [[ ! -z "${OVERRIDE_VBMETA_IMAGE_PATH+x}" && ! -f "$OVERRIDE_VBMETA_IMAGE_PATH" ]]; then
exit_badparam "Specified vbmeta.img not found: "$OVERRIDE_VBMETA_IMAGE_PATH""
fi
if [[ $# -lt 3 ]]; then if [[ $# -lt 3 ]]; then
exit_badparam "Unexpected number of arguments" exit_badparam "Unexpected number of arguments"
fi fi
readonly GSI_DIR="$1" readonly SYSTEM_DIR="$1"
readonly DEVICE_DIR="$2" readonly DEVICE_DIR="$2"
readonly DIST_DIR="$3" readonly DIST_DIR="$3"
readonly CHECK_TOOL="$4" readonly CHECK_TOOL="$4"
readonly TEMP_DIR="$(mktemp -d /tmp/"$(basename $0)"_XXXXXXXX)" readonly TEMP_DIR="$(mktemp -d /tmp/"$(basename $0)"_XXXXXXXX)"
readonly GSI_TARGET_FILES_ARCHIVE="$(find "$GSI_DIR" -name "*-target_files-*.zip" -print)" readonly SYSTEM_TARGET_FILES_ARCHIVE="$(find "$SYSTEM_DIR" -name "*-target_files-*.zip" -print)"
if [[ ! -f "$GSI_TARGET_FILES_ARCHIVE" ]]; then if [[ ! -f "$SYSTEM_TARGET_FILES_ARCHIVE" ]]; then
exit_badparam "Could not find GSI target_files archive in $GSI_DIR." exit_badparam "Could not find system target files archive in $SYSTEM_DIR."
fi fi
readonly DEVICE_ARCHIVE="$(find "$DEVICE_DIR" -name "*-img-*.zip" -print)" readonly DEVICE_ARCHIVE="$(find "$DEVICE_DIR" -name "*-img-*.zip" -print)"
@@ -93,19 +102,19 @@ fi
readonly DEVICE_ARTIFACTS_DIR="$TEMP_DIR"/device_archive_artifacts readonly DEVICE_ARTIFACTS_DIR="$TEMP_DIR"/device_archive_artifacts
readonly DEVICE_IMAGES_DIR="$DEVICE_ARTIFACTS_DIR"/IMAGES readonly DEVICE_IMAGES_DIR="$DEVICE_ARTIFACTS_DIR"/IMAGES
readonly GSI_ARTIFACTS_DIR="$TEMP_DIR"/gsi_artifacts readonly SYSTEM_ARTIFACTS_DIR="$TEMP_DIR"/system_artifacts
readonly GSI_IMAGES_DIR="$GSI_ARTIFACTS_DIR"/IMAGES readonly SYSTEM_IMAGES_DIR="$SYSTEM_ARTIFACTS_DIR"/IMAGES
readonly SPL_PROPERTY_NAME="ro.build.version.security_patch" readonly SPL_PROPERTY_NAME="ro.build.version.security_patch"
readonly SYSTEM_BUILD_PROP="SYSTEM/build.prop" readonly SYSTEM_BUILD_PROP="SYSTEM/build.prop"
### ###
# Uncompress the archives. # Uncompress the archives.
mkdir -p "$GSI_ARTIFACTS_DIR" mkdir -p "$SYSTEM_ARTIFACTS_DIR"
# Get the GSI images and meta data. # Get the system images and meta data.
unzip "$GSI_TARGET_FILES_ARCHIVE" \ unzip "$SYSTEM_TARGET_FILES_ARCHIVE" \
IMAGES/system.img IMAGES/vbmeta.img META/system_matrix.xml META/system_manifest.xml "$SYSTEM_BUILD_PROP" \ IMAGES/system.img IMAGES/vbmeta.img META/system_matrix.xml META/system_manifest.xml "$SYSTEM_BUILD_PROP" \
-d "$GSI_ARTIFACTS_DIR" -d "$SYSTEM_ARTIFACTS_DIR"
mkdir -p "$DEVICE_IMAGES_DIR" mkdir -p "$DEVICE_IMAGES_DIR"
# Get the device images. # Get the device images.
@@ -116,30 +125,31 @@ unzip "$DEVICE_TARGET_FILES_ARCHIVE" \
-d "$DEVICE_ARTIFACTS_DIR" -d "$DEVICE_ARTIFACTS_DIR"
### ###
# Check compatibility between the GSI compatibility vs the device. # Check compatibility between the system and device.
if [[ -f "$CHECK_TOOL" ]]; then if [[ -f "$CHECK_TOOL" ]]; then
chmod 755 "$CHECK_TOOL"
"$CHECK_TOOL" \ "$CHECK_TOOL" \
"$DEVICE_ARTIFACTS_DIR"/META/vendor_manifest.xml \ "$DEVICE_ARTIFACTS_DIR"/META/vendor_manifest.xml \
"$GSI_ARTIFACTS_DIR"/META/system_matrix.xml "$SYSTEM_ARTIFACTS_DIR"/META/system_matrix.xml
"$CHECK_TOOL" \ "$CHECK_TOOL" \
"$GSI_ARTIFACTS_DIR"/META/system_manifest.xml \ "$SYSTEM_ARTIFACTS_DIR"/META/system_manifest.xml \
"$DEVICE_ARTIFACTS_DIR"/META/vendor_matrix.xml "$DEVICE_ARTIFACTS_DIR"/META/vendor_matrix.xml
fi fi
### ###
# Modify system.img if vendor version is provided. # Modify system.img if vendor version is provided.
if [[ ! -z "${VENDOR_VERSION+x}" ]]; then if [[ ! -z "${VENDOR_VERSION+x}" ]]; then
# Create copy of GSI target files package that can be modified # Create copy of system target files package that can be modified
# since the original $GSI_TARGET_FILES_ARCHIVE is a symlink to # since the original $SYSTEM_TARGET_FILES_ARCHIVE is a symlink to
# prebuilt files in cache # prebuilt files in cache
cp "$GSI_TARGET_FILES_ARCHIVE" "$TEMP_DIR" cp "$SYSTEM_TARGET_FILES_ARCHIVE" "$TEMP_DIR"
readonly COPY_GSI_TARGET_FILES_ARCHIVE="$TEMP_DIR"/"$(basename "$GSI_TARGET_FILES_ARCHIVE")" readonly COPY_SYSTEM_TARGET_FILES_ARCHIVE="$TEMP_DIR"/"$(basename "$SYSTEM_TARGET_FILES_ARCHIVE")"
# Check compatibility of security patch level # Check compatibility of security patch level
readonly SYSTEM_SPL=$(sed -n -r "s/^"$SPL_PROPERTY_NAME"=(.*)$/\1/p" "$GSI_ARTIFACTS_DIR"/"$SYSTEM_BUILD_PROP") readonly SYSTEM_SPL=$(sed -n -r "s/^"$SPL_PROPERTY_NAME"=(.*)$/\1/p" "$SYSTEM_ARTIFACTS_DIR"/"$SYSTEM_BUILD_PROP")
readonly VENDOR_SPL=$(sed -n -r "s/^"$SPL_PROPERTY_NAME"=(.*)$/\1/p" "$DEVICE_ARTIFACTS_DIR"/"$SYSTEM_BUILD_PROP") readonly VENDOR_SPL=$(sed -n -r "s/^"$SPL_PROPERTY_NAME"=(.*)$/\1/p" "$DEVICE_ARTIFACTS_DIR"/"$SYSTEM_BUILD_PROP")
declare -a args declare -a args
args=(-v "$VENDOR_VERSION" "$COPY_GSI_TARGET_FILES_ARCHIVE") args=(-v "$VENDOR_VERSION" "$COPY_SYSTEM_TARGET_FILES_ARCHIVE")
if [[ "$SYSTEM_SPL" != "$VENDOR_SPL" ]]; then if [[ "$SYSTEM_SPL" != "$VENDOR_SPL" ]]; then
echo "Security patch level mismatch detected..." echo "Security patch level mismatch detected..."
echo " SPL of system: "$SYSTEM_SPL"" echo " SPL of system: "$SYSTEM_SPL""
@@ -148,17 +158,18 @@ if [[ ! -z "${VENDOR_VERSION+x}" ]]; then
fi fi
"$MODIFY_SYSTEM_SCRIPT" "${args[@]}" "$MODIFY_SYSTEM_SCRIPT" "${args[@]}"
# Replace system.img with newly modified system.img # Replace system.img with newly modified system.img
unzip -o "$COPY_GSI_TARGET_FILES_ARCHIVE" IMAGES/system.img -d "$GSI_ARTIFACTS_DIR" unzip -o "$COPY_SYSTEM_TARGET_FILES_ARCHIVE" IMAGES/system.img -d "$SYSTEM_ARTIFACTS_DIR"
fi fi
### ###
# Overwrite artifacts in the device archive to create the Mixed Build artifacts. # Overwrite artifacts in the device archive to create the Mixed Build artifacts.
cp "$GSI_IMAGES_DIR"/system.img "$DEVICE_IMAGES_DIR"/ cp "$SYSTEM_IMAGES_DIR"/system.img "$DEVICE_IMAGES_DIR"/
# Only override vbmeta if it is already present since fastboot update will try # Only override vbmeta if it is already present since fastboot update will try
# to flash whatever is in the archive. # to flash whatever is in the archive.
if [[ -f "$DEVICE_IMAGES_DIR"/vbmeta.img ]]; then if [[ -f "$DEVICE_IMAGES_DIR"/vbmeta.img ]]; then
cp "$GSI_IMAGES_DIR"/vbmeta.img "$DEVICE_IMAGES_DIR"/ readonly VBMETA_IMAGE_PATH="${OVERRIDE_VBMETA_IMAGE_PATH:-"$SYSTEM_IMAGES_DIR"/vbmeta.img}"
cp "$VBMETA_IMAGE_PATH" "$DEVICE_IMAGES_DIR"/
fi fi
### ###