Skip to content

Commit

Permalink
added package creation and flash script
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderwolz committed Dec 15, 2023
1 parent 510104e commit cdcce0f
Show file tree
Hide file tree
Showing 7 changed files with 299 additions and 52 deletions.
70 changes: 34 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -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:

Expand All @@ -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:
Expand All @@ -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```
9 changes: 0 additions & 9 deletions bin/avd_wipe.sh

This file was deleted.

2 changes: 1 addition & 1 deletion bin/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down
147 changes: 147 additions & 0 deletions bin/create_local_product_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#!/bin/bash
# Copyright (C) 2023 Alexander Wolz <mail@alexanderwolz.de>


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
108 changes: 108 additions & 0 deletions bin/flash_product_zip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash
# Copyright (C) 2023 Alexander Wolz <mail@alexanderwolz.de>

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"
Loading

0 comments on commit cdcce0f

Please sign in to comment.