[RK 3399][Android 7.1]簡易コンパイルシステムimagesスクリプト


Platform: RK3399 OS: Android 7.1 Kernel: v4.4.83
システムが持っているコンパイルスクリプトの機能が不十分で、書き直して、コンパイルしたrk 3399_mid engバージョン.
#!/bin/bash
#Kris,180619, Created from rk3288 project.

#android build option
PLATFORM_PRODUCT=rk3399_mid
choice=${PLATFORM_PRODUCT}-eng
PRODUCT_OUT=out/target/product/${PLATFORM_PRODUCT}/
build_path=./
log_file=${build_path}/${choice}_build.log

uboot_path=${build_path}/u-boot
kernel_path=${build_path}/kernel


#Setup JDK env.
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
#export CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar


source ${build_path}/build/envsetup.sh >/dev/null


IMAGE_PATH=rockdev/Image-${PLATFORM_PRODUCT}
IMAGE_PATH_FINAL=rockdev/${choice}

cpu_num=`cat /proc/cpuinfo  | grep "processor" | wc -l`

OEM_TARGET=$1
need_rename=1
#ota_update=ota



build_uboot()
{
    cd ${uboot_path}
    make rk3399_defconfig
    make ARCHV=aarch64
    if [ $? -eq 0 ]; then
        echo "Build uboot ok!"
    else
        echo "Build uboot failed!"
        exit 1
    fi
    cd -
}

clean_uboot()
{
    cd ${uboot_path}
    make clean
    cd -
}

build_kernel()
{
    cd  ${kernel_path}
    make ARCH=arm64 rockchip_defconfig
    make ARCH=arm64 rk3399-mid-818-android.img -j${cpu_num}
    if [ $? -eq 0 ]; then
        echo "Build kernel ok!"
    else
        echo "Build kernel failed!"
        exit 1
    fi
    cd -
}

clean_kernel()
{
    cd  ${kernel_path}
    make clean
    cd -
}

build_all()
{
    build_uboot
    build_kernel
    lunch $choice

    if [ "$1" == $OEM_TARGET ]; then
        make otapackage -j${cpu_num} 2>&1 | tee ${log_file}
    else
        make  -j${cpu_num} 2>&1 | tee ${log_file}
    fi
    if [ $? -eq 0 ]; then
        echo "Build android ok!"
    else
        echo "Build android failed!"
        exit 1
    fi
    ./mkimage.sh ${ota_update}
}

clean_and_build_all()
{
    clean_uboot
    build_uboot
    clean_kernel
    build_kernel
    lunch $choice
    make installclean
    if [ $? -eq 0 ]; then
        echo "Build android ok!"
    else
        echo "Build android failed!"
        exit 1
    fi

}

build_module()
{
    lunch $choice
    make $OEM_TARGET -j${cpu_num} 2>&1 | tee ${log_file}
}

copy_image()
{
    if [ $OEM_TARGET == "uboot" ]; then
        cp ${uboot_path}/uboot.img	${IMAGE_PATH}/
        cp ${uboot_path}/rk3399_loader_v1.08.*.bin ${IMAGE_PATH}/
        cp ${uboot_path}/trust.img	${IMAGE_PATH}/
    elif [ $OEM_TARGET == "kernel" ]; then
        cp ${kernel_path}/kernel.img	${IMAGE_PATH}/
        cp ${kernel_path}/resource.img	${IMAGE_PATH}/
    elif [ $OEM_TARGET == "recoveryimage" ]; then
        cp ${PRODUCT_OUT}/recovery.img  ${IMAGE_PATH_FINAL}/
    elif [ $OEM_TARGET == "android" -o $OEM_TARGET == "otapackage" ]; then
        #mkimage.sh will copy following images.
        #cp ${uboot_path}/uboot.img	${IMAGE_PATH}/
        #cp ${uboot_path}/rk3399_loader_v1.08.*.bin ${IMAGE_PATH}/
        #cp ${kernel_path}/kernel.img	${IMAGE_PATH}/
        #cp ${kernel_path}/resource.img	${IMAGE_PATH}/
        cp ${PRODUCT_OUT}/recovery.img  ${IMAGE_PATH_FINAL}/
        cp ${PRODUCT_OUT}/system.img  ${IMAGE_PATH_FINAL}/
        cp ${PRODUCT_OUT}/boot.img  ${IMAGE_PATH_FINAL}/
        if [ $OEM_TARGET == "otapackage" ]; then 
            if [ -f ${PRODUCT_OUT}/rk33399-ota*.zip ]; then
                cp ${PRODUCT_OUT}/rk33399-ota*.zip ${IMAGE_PATH}/
            fi
        fi
    fi
}

create_dir_if_not_exist()
{
    if [ ! -d ${IMAGE_PATH} ]; then 
        mkdir -p ${IMAGE_PATH}
    fi


    if [ ! -d ${IMAGE_PATH_FINAL} ]; then 
        mkdir -p ${IMAGE_PATH_FINAL}
    fi
}

create_dir_if_not_exist

if [ -z $OEM_TARGET ]; then
    echo "Default build android all images..."
    OEM_TARGET="android"
fi

#Update build.prop while building systemimage.
if [ "$OEM_TARGET" == "systemimage" -o "$OEM_TARGET" == "android" ]; then
    if [ -f ${PRODUCT_OUT}/system/build.prop ]; then
        rm ${PRODUCT_OUT}/system/build.prop
    fi
    if [ -f ${PRODUCT_OUT}/obj/ETC/system_build_prop_intermediates ]; then
        rm -rf ${PRODUCT_OUT}/obj/ETC/system_build_prop_intermediates
    fi
fi

if [ $OEM_TARGET == "android" ]; then
    build_all
elif [ $OEM_TARGET == "kernel" ]; then
    build_kernel
elif [ $OEM_TARGET == "uboot" ]; then
    build_uboot
elif [ $OEM_TARGET == "otapackage" ]; then
    build_all $OEM_TARGET
else
    if [ $OEM_TARGET == "bootimage" -o $OEM_TARGET == "recoveryimage" ]; then
        build_kernel
        rm ${PRODUCT_OUT}/kernel
        if [ $OEM_TARGET == "bootimage" ]; then
            rm ${PRODUCT_OUT}/boot.img
        else
            rm ${PRODUCT_OUT}/recovery.img
        fi
    fi
        build_module
    if [ $OEM_TARGET == "bootimage" -o $OEM_TARGET == "recoveryimage" -o  $OEM_TARGET == "systemimage" ]; then
        need_rename=1
        ./mkimage.sh ${ota_update}
    else
        need_rename=0
    fi
fi

    copy_image

if [ $need_rename != "0" ]; then
    mv $IMAGE_PATH/* $IMAGE_PATH_FINAL/
fi