1#!/bin/bash
2
3# Copyright (C) 2020 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17echo pack_avd_img.sh packs AVD images you built to be used on other hosts.
18echo It copies necessary files from ANDROID_PRODUCT_OUT to OUT_DIR.
19
20if [[ -z $ANDROID_PRODUCT_OUT ]]; then
21    echo "err: please set ANDROID_PRODUCT_OUT='/android/out/target/product/generic_x86_64'"
22    exit
23fi
24
25if [[ -z $ANDROID_BUILD_TOP ]]; then
26    echo "err: please set ANDROID_BUILD_TOP='/android'"
27    exit
28fi
29
30if [[ -z $OUT_DIR ]]; then
31    echo "err: please set OUT_DIR='/my/out/dir/x86_64'"
32    exit
33fi
34
35echo Packing AVD images from $ANDROID_PRODUCT_OUT to $OUT_DIR
36
37if [[ ! -d $OUT_DIR ]]; then
38    mkdir $OUT_DIR
39fi
40
41echo System, qemu verion
42cp $ANDROID_PRODUCT_OUT/system-qemu.img $OUT_DIR/system.img
43
44echo Vendor, qemu verion
45cp $ANDROID_PRODUCT_OUT/vendor-qemu.img $OUT_DIR/vendor.img
46
47
48if [[ -f $ANDROID_PRODUCT_OUT/kernel-ranchu-64 ]]; then
49    echo Kernel: 64-bit, prebuilt
50    cp $ANDROID_PRODUCT_OUT/kernel-ranchu-64 $OUT_DIR/kernel-ranchu-64
51else
52    echo Kernel: 64-bit for 32-bit userspaces, prebuilt
53    cp $ANDROID_PRODUCT_OUT/kernel-ranchu $OUT_DIR/kernel-ranchu
54fi
55
56echo Ramdisk, prebuilt
57cp $ANDROID_PRODUCT_OUT/ramdisk.img $OUT_DIR/ramdisk.img
58
59echo Encryptionkey, prebuilt
60cp $ANDROID_PRODUCT_OUT/encryptionkey.img $OUT_DIR/encryptionkey.img
61
62echo Userdata, prebuilt
63# take prebuilt userdata.img
64#Ref:https://cs.android.com/android/platform/superproject/+/master:development/build/sdk.atree?q=userdata.img&ss=android%2Fplatform%2Fsuperproject:development%2Fbuild%2F
65cp $ANDROID_BUILD_TOP/device/generic/goldfish/data/etc/userdata.img $OUT_DIR/userdata.img
66
67echo User data
68#Todo: will this replace the need of userdata.img?
69cp -r $ANDROID_PRODUCT_OUT/data $OUT_DIR/data
70
71echo build properties
72cp $ANDROID_PRODUCT_OUT/system/build.prop $OUT_DIR/build.prop
73
74echo Verified Boot Parameters
75cp $ANDROID_PRODUCT_OUT/VerifiedBootParams.textproto $OUT_DIR/VerifiedBootParams.textproto
76
77echo Default AVD config.ini
78cp $ANDROID_PRODUCT_OUT/config.ini $OUT_DIR/config.ini
79
80echo Android Emulator Adviced Feature settings
81cp $ANDROID_PRODUCT_OUT/advancedFeatures.ini $OUT_DIR/advancedFeatures.ini
82
83echo
84echo In $OUT_DIR:
85ls -l $OUT_DIR
86
87if [[ -n $AVD_IMAGE_ZIP ]]; then
88
89    rm $AVD_IMAGE_ZIP
90
91    echo Zipping $OUT_DIR to $AVD_IMAGE_ZIP
92    # to perserve ABI in the zip, assuming OUT_DIR always ends with ABI
93    # e.g. /path/to/x86_64
94    ABI=${OUT_DIR##*/}  # = "x86_64"
95    PATH_TO_IMG_DIR=${OUT_DIR%/$ABI}  # = "/path/to"
96    cd $PATH_TO_IMG_DIR
97    zip -r $AVD_IMAGE_ZIP $ABI
98    cd -
99    unzip -l $AVD_IMAGE_ZIP
100fi
101