From cdcce0f241594b3ac9d4ec63e81f6efc25c88e6d Mon Sep 17 00:00:00 2001 From: Alexander Wolz Date: Fri, 15 Dec 2023 14:29:55 +0100 Subject: [PATCH] added package creation and flash script --- README.md | 70 +++++++------ bin/avd_wipe.sh | 9 -- bin/common.sh | 2 +- bin/create_local_product_package.sh | 147 ++++++++++++++++++++++++++++ bin/flash_product_zip.sh | 108 ++++++++++++++++++++ bin/sync_remote_emulator_images.sh | 12 ++- bin/sync_remote_product_out.sh | 3 +- 7 files changed, 299 insertions(+), 52 deletions(-) delete mode 100755 bin/avd_wipe.sh create mode 100755 bin/create_local_product_package.sh create mode 100644 bin/flash_product_zip.sh diff --git a/README.md b/README.md index 6957a00..dbe3ec8 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,9 @@ -# Tool Collection for Whale Shark AAOS devices +# Tool Collection for AOSP and AAOS builds -![GitHub release (latest by date)](https://img.shields.io/github/v/release/alexanderwolz/android_device_whaleshark_tools) -![GitHub](https://img.shields.io/badge/aosp-14-orange) -![GitHub](https://img.shields.io/github/license/alexanderwolz/android_device_whaleshark_tools) -![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/alexanderwolz/android_device_whaleshark_tools) -![GitHub all releases](https://img.shields.io/github/downloads/alexanderwolz/android_device_whaleshark_tools/total?color=informational) +![GitHub release (latest by date)](https://img.shields.io/github/v/release/alexanderwolz/android-build-tools) +![GitHub](https://img.shields.io/github/license/alexanderwolz/android-build-tools) +![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/alexanderwolz/android-build-tools) +![GitHub all releases](https://img.shields.io/github/downloads/alexanderwolz/android-build-tools/total?color=informational) ## 🧑‍💻 About @@ -34,8 +33,35 @@ You can also add ```SSH_KEY="~/.ssh/id_rsa"``` if your SSH is set up with key-pa ## 🛠️ Scripts -### **bin/sync_remote_product_out.sh** +### **bin/create_local_product_package.sh** + +This scripts creates a zip package that can be flashed to Android devices. Use the script like this: + +``` + bash bin/create_local_product_package.sh + bash bin/create_local_product_package.sh $DEVICE_NAME +``` + +### **bin/flash_local_product_out.sh** + +This scripts flashes all existing images from ```ANDROID_PRODUCT_OUT``` to a connected Android device. + +``` + bash bin/flash_local_product_out.sh + bash bin/flash_local_product_out.sh $DEVICE_NAME +``` + + +### **bin/flash_product_zip.sh** + +This scripts flashes a given product zip to a connected Android device. + +``` + bash bin/flash_product_zip.sh $ZIP_FILE +``` + +### **bin/sync_remote_product_out.sh** This script synchronizes the product files of a given target in ```$ANDROID_PRODUCT_OUT``` on a remote server to ```localhost```. *SSH* and *rsync* must be setup on both ends. @@ -46,8 +72,8 @@ Use the script like this: bash bin/sync_remote_product_out.sh $DEVICE_NAME ``` -### **bin/flash_local_product_out.sh** +### **bin/flash_local_product_out.sh** Use the script like this: @@ -61,7 +87,6 @@ This script has been tested with images built for Google Pixel Tablet (tangorpro ### **bin/sync_remote_emulator_images.sh** - This script synchronizes emulator image files of a given target in ```$ANDROID_PRODUCT_OUT``` on a remote server to ```localhost``` according to the ```ANDROID_SDK```-location. *SSH* and *rsync* must be setup on both ends. Use the script like this: @@ -70,30 +95,3 @@ Use the script like this: bash bin/sync_remote_emulator_images.sh bash bin/sync_remote_emulator_images.sh $DEVICE_NAME ``` - - -## ⚙️ Android Virtual Device (AVD) configuration - -### Setup - -Copy the appropriate avd folder to ```$HOME/.android/avd``` - -```mkdir -p $HOME/.android/avd``` - -```cp -r avd/API34/whaleshark.avd $HOME/.android/avd/whaleshark.avd``` - -```cp avd/API34/whaleshark.ini $HOME/.android/avd/whaleshark.ini``` - - -### Run the Emulator - -Install the Android SDK and set ```$ANDROID_SDK_HOME``` - -Install the Android Emulator with version 33.1.23.0 or higher - -Execute the Emulator: ```$ANDROID_SDK_HOME/emulator/emulator -avd whaleshark -show-kernel``` - - -### Clear the Emulator - -```bash bin/avd_wipe.sh``` diff --git a/bin/avd_wipe.sh b/bin/avd_wipe.sh deleted file mode 100755 index 800771b..0000000 --- a/bin/avd_wipe.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -AVD_FOLDER="$HOME/.android/avd/whaleshark.avd" - -pushd "$AVD_FOLDER" >/dev/null || exit 1 -echo "Wiping $AVD_FOLDER" -find . -mindepth 1 ! -name "config.ini" -delete -echo "Done" -popd >/dev/null \ No newline at end of file diff --git a/bin/common.sh b/bin/common.sh index 08902b2..6032ea1 100644 --- a/bin/common.sh +++ b/bin/common.sh @@ -70,7 +70,7 @@ function chooseDevice() { fi if [ ${#DEVICE_NAMES[@]} == 1 ]; then DEVICE_NAME="${DEVICE_NAMES[0]}" - echo "There is only one device availabe, using '$DEVICE_NAME'" + echo "There is only one device available, using '$DEVICE_NAME'" else echo "" echo "There are several devices, please choose one:" diff --git a/bin/create_local_product_package.sh b/bin/create_local_product_package.sh new file mode 100755 index 0000000..8981a88 --- /dev/null +++ b/bin/create_local_product_package.sh @@ -0,0 +1,147 @@ +#!/bin/bash +# Copyright (C) 2023 Alexander Wolz + + +function add() { + local ELEMENT=$ANDROID_PRODUCT_OUT/$1 + if [ -f $ELEMENT ] || [ -d $ELEMENT ]; then + if [ ! -z $2 ]; then + cp -rf $ELEMENT "$PACKAGE_IMAGE_DIR/$2" + else + cp -rf $ELEMENT "$PACKAGE_IMAGE_DIR/$1" + fi + else + echo "Skipping - No such file: $1" + fi +} + +echo "" +echo "---------------------------------------------------------------" +echo "Create product package Tool" +echo "---------------------------------------------------------------" + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "$SCRIPT_DIR/common.sh" || exit 1 + +DEVICE_NAMES=($(ls $LOCAL_AOSP_SYNCH)) +if [ ${#DEVICE_NAMES[@]} == 0 ]; then + echo "There are no devices available at $LOCAL_AOSP_SYNCH" + echo "" + exit 1 +fi + +if [ ! -z $1 ]; then + DEVICE_NAME=$1 +else + echo "---------------------------------------------------------------" + echo "Reading product device list .." + chooseDevice "${DEVICE_NAMES[@]}" || exit 1 +fi + +if [ -z $DEVICE_NAME ]; then + echo "Something's wrong, try again" + echo "" + exit 1 +fi + +ANDROID_PRODUCT_OUT="$LOCAL_AOSP_SYNCH/$DEVICE_NAME" +export ANDROID_PRODUCT_OUT + +echo "---------------------------------------------------------------" +echo "Using product: $DEVICE_NAME" +echo "---------------------------------------------------------------" + +echo "" +while true; do + read -p "Do you wish to create package for '$DEVICE_NAME'? [y/n] " selection + case $selection in + [y]*) break ;; + [n]*) exit ;; + *) echo "Please answer y or n." ;; + esac +done + +BUILD_PROPERTIES_FILE="$ANDROID_PRODUCT_OUT/system/build.prop" + +if [ ! -f $BUILD_PROPERTIES_FILE ]; then + echo "Missing file $BUILD_PROPERTIES_FILE" + exit 1 +fi + +BUILD_PROPERTIES=$(cat $BUILD_PROPERTIES_FILE) || exit 1 + +API_LEVEL=$(echo "$BUILD_PROPERTIES" | grep ro.build.version.sdk= | cut -d'=' -f2) || exit 1 +BUILD_FLAVOR=$(echo "$BUILD_PROPERTIES" | grep ro.build.flavor= | cut -d'=' -f2) || exit 1 +PRODUCT_NAME=$(echo "$BUILD_PROPERTIES"| grep ro.build.product= | cut -d'=' -f2) || exit 1 +ANDROID_VERSION=$(echo "$BUILD_PROPERTIES" | grep ro.system.build.version.release= | cut -d'=' -f2) || exit 1 +BUILD_TYPE=$(echo "$BUILD_PROPERTIES" | grep ro.system.build.type= | cut -d'=' -f2) || exit 1 +BUILD_ID=$(echo "$BUILD_PROPERTIES" | grep ro.system.build.id= | cut -d'=' -f2) || exit 1 + +NOW=$(date +"%Y%m%d-%H%M%S") +BEGIN=$(date -u +%s) + +PACKAGE_ROOT=$PARENT_DIR"/packages" +PACKAGE_DIR=$PACKAGE_ROOT"/"$BUILD_FLAVOR"_android"$ANDROID_VERSION"_"$NOW +PACKAGE_IMAGE_DIR=$PACKAGE_DIR"/images-"$BUILD_FLAVOR"_android"$ANDROID_VERSION + +PACKAGE_IMAGE_ZIP=$PACKAGE_IMAGE_DIR.zip +PACKAGE_DIR_ZIP=$PACKAGE_DIR.zip + +mkdir -p $PACKAGE_IMAGE_DIR || exit 1 + +echo "Checking files .." + +FLASH_FILE=$PACKAGE_DIR/flash.sh +cp $SCRIPT_DIR/flash_product_zip.sh $FLASH_FILE +sed -i '' -e "s/ZIP_FILE=\$1/ZIP_FILE=$(basename $PACKAGE_IMAGE_ZIP)/g" $FLASH_FILE +chmod +x $FLASH_FILE + +BOOTLOADER="$ANDROID_PRODUCT_OUT/bootloader.img" +if [ -f $BOOTLOADER ]; then + echo "Adding bootloader.img" + cp $BOOTLOADER $PACKAGE_DIR || exit 1 +fi + +add system/build.prop build.prop +add android-info.txt +add boot.img +add dtbo.img +add init_boot.img +add product.img +add pvmfw.img +add super_empty.img +add system_dlkm.img +add system_ext.img +add system_other.img +add system.img +add vbmeta_system.img +add vbmeta_vendor.img +add vbmeta.img +add vendor_boot.img +add vendor_dlkm.img +add vendor_kernel_boot.img +add vendor.img +add vendor/ #TODO merge this into image + +echo "Zipping images .." +pushd $PACKAGE_IMAGE_DIR > /dev/null +zip -r $PACKAGE_IMAGE_ZIP . || exit 1 +popd > /dev/null + +#zip -r -j $PACKAGE_IMAGE_ZIP $PACKAGE_IMAGE_DIR/* || exit 1 +rm -rf $PACKAGE_IMAGE_DIR || exit 1 + +echo "Zipping all content .." +zip -j $PACKAGE_DIR_ZIP $PACKAGE_DIR/* || exit 1 + +echo "Cleaning up .." +rm -rf $PACKAGE_DIR + + +DURATION=$(($(date -u +%s)-$BEGIN)) +echo "---------------------------------------------------------------" +echo "Package can be found at $PACKAGE_DIR_ZIP" +echo "---------------------------------------------------------------" +echo "Finished - took $(($DURATION / 60)) minutes and $(($DURATION % 60)) seconds" +echo "---------------------------------------------------------------" +echo "" #newline \ No newline at end of file diff --git a/bin/flash_product_zip.sh b/bin/flash_product_zip.sh new file mode 100644 index 0000000..dc09c00 --- /dev/null +++ b/bin/flash_product_zip.sh @@ -0,0 +1,108 @@ +#!/bin/bash +# Copyright (C) 2023 Alexander Wolz + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + +#copied from The Android Open Source Project +if ! [ $($(which fastboot) --version | grep "version" | cut -c18-23 | sed 's/\.//g' ) -ge 3301 ]; then + echo "fastboot too old; please download the latest version at https://developer.android.com/studio/releases/platform-tools.html" + exit 1 +fi + +echo "" +echo "---------------------------------------------------------------" +echo "Flashing tool" +echo "---------------------------------------------------------------" + +ZIP_FILE=$1 + +if [ -z $ZIP_FILE ]; then + echo "Please specify zip file" + exit 1 +fi + +while true; do + read -p "Do you wish to flash? [y/n] " selection + case $selection in + [y]*) break ;; + [n]*) exit ;; + *) echo "Please answer y or n." ;; + esac +done + +adb reboot bootloader + +if [ -f "$SCRIPT_DIR/bootloader.img" ]; then + fastboot flash bootloader "$SCRIPT_DIR/bootloader.img" + fastboot reboot-bootloader + sleep 5 +fi + +fastboot -w update $ZIP_FILE + + + +# now comes the tricky part with vendor files.. + +echo "waiting for device to come up .." +adb wait-for-device + +echo "setting adb root .." +adb root + +VERITY_MODE=$(adb shell getprop ro.boot.veritymode) +if [ "$VERITY_MODE" == "enabled" ]; then + echo "disabling verity .." + adb disable-verity + sleep 3 + + echo "rebooting .." + adb reboot + + echo "waiting for device to come up .." + adb wait-for-device + + echo "setting adb root .." + adb root + + sleep 2 +else + echo "Verity is already disabled, skipping" +fi + +echo "Remounting .." +adb remount +if [ "$?" -ne 0 ]; then + echo "Committing checkpoint .." + adb shell vdc checkpoint commitChanges + adb remount + + echo "rebooting .." + adb reboot + + echo "waiting for device to come up .." + adb wait-for-device + + echo "setting adb root .." + adb root + + echo "Try remount again .." + adb remount +fi + +#extracting vendor from zip to tmp folder +ANDROID_PRODUCT_OUT_TMP="$SCRIPT_DIR/.product_out_tmp" +rm -rf $ANDROID_PRODUCT_OUT_TMP +mkdir -p $ANDROID_PRODUCT_OUT_TMP +unzip $ZIP_FILE "vendor/*" -d "$ANDROID_PRODUCT_OUT_TMP" > /dev/null || exit 1 +export ANDROID_PRODUCT_OUT=$ANDROID_PRODUCT_OUT_TMP + +echo "Syncing vendor partition .." +adb sync vendor + +echo "Rebooting .." +adb reboot || exit 1 + +rm -rf $ANDROID_PRODUCT_OUT_TMP + +echo "done" \ No newline at end of file diff --git a/bin/sync_remote_emulator_images.sh b/bin/sync_remote_emulator_images.sh index 3864201..61b3388 100755 --- a/bin/sync_remote_emulator_images.sh +++ b/bin/sync_remote_emulator_images.sh @@ -31,7 +31,7 @@ fi echo "---------------------------------------------------------------" if [[ ${DEVICE_NAMES[@]} =~ $DEVICE_NAME ]]; then - echo "Syncing target: '$DEVICE_NAME' from $SSH_HOST" + echo "Syncing target device '$DEVICE_NAME' from $SSH_HOST" else echo "Device $DEVICE_NAME does not exist" echo "" @@ -43,14 +43,16 @@ TARGET="$REMOTE_PRODUCT_PARENT_FOLDER/$DEVICE_NAME" BUILD_PROPERTIES=$($SSH_CMD $REMOTE cat $TARGET/system/build.prop) API_LEVEL=$(echo "$BUILD_PROPERTIES" | grep ro.build.version.sdk= | cut -d'=' -f2) || exit 1 -ARCH=$(echo "$BUILD_PROPERTIES" | grep ro.product.cpu.abi= | cut -d'=' -f2) || exit 1 # TODO: switch to ro.system.product.cpu.abilist ?? +ARCH=$(echo "$BUILD_PROPERTIES" | grep ro.product.cpu.abi= | cut -d'=' -f2) || exit 1 +BUILD_FLAVOR=$(echo "$BUILD_PROPERTIES" | grep ro.build.flavor= | cut -d'=' -f2) || exit 1 +TARGET_NAME=$(echo "$BUILD_FLAVOR" | cut -d'_' -f1)|| exit 1 -echo "Target has API level $API_LEVEL for arch $ARCH" +echo "Product '$TARGET_NAME' has API level $API_LEVEL for arch $ARCH" echo "" while true; do - read -p "Do you wish to synch '$DEVICE_NAME'? [y/n] " selection + read -p "Do you wish to synch '$TARGET_NAME' ($DEVICE_NAME)? [y/n] " selection case $selection in [y]*) break ;; [n]*) exit ;; @@ -58,7 +60,7 @@ while true; do esac done -SYSIMG_DIR="$ANDROID_HOME/system-images/android-$API_LEVEL/whaleshark/$ARCH" +SYSIMG_DIR="$ANDROID_HOME/system-images/android-$API_LEVEL/$TARGET_NAME/$ARCH" mkdir -p $SYSIMG_DIR BEGIN=$(date -u +%s) diff --git a/bin/sync_remote_product_out.sh b/bin/sync_remote_product_out.sh index 2e1b47f..30986eb 100755 --- a/bin/sync_remote_product_out.sh +++ b/bin/sync_remote_product_out.sh @@ -52,7 +52,8 @@ done REMOTE_PRODUCT_FOLDER="$REMOTE_PRODUCT_PARENT_FOLDER/$DEVICE_NAME" BEGIN=$(date -u +%s) -rsync -aP -e "$SSH_OPTS" "$SSH_USER@$SSH_HOST":$REMOTE_PRODUCT_FOLDER $LOCAL_AOSP_SYNCH +#copy everything from $ANDROID_PRODUCT_OUT except symbols folder +rsync -aP -e "$SSH_OPTS" --exclude symbols "$SSH_USER@$SSH_HOST":$REMOTE_PRODUCT_FOLDER $LOCAL_AOSP_SYNCH DURATION=$(($(date -u +%s)-$BEGIN)) echo "---------------------------------------------------------------" echo "AOSP product can be found at $LOCAL_AOSP_SYNCH/$DEVICE_NAME"