#!/bin/bash
source build/envsetup.sh
lunch $1-userdebug
if [ ! -z"msm_defconfig" ]
then
rm -fout/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ/.config;
make -C kernelO=../out/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ ARCH=arm64CROSS_COMPILE=aarch64-linux-android- msm_defconfig;
make -C kernelO=../out/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ ARCH=arm64CROSS_COMPILE=aarch64-linux-android- headers_install
fi
if [ ! -z"" ]
then
echo "Overriding kernel configwith ''";
echo >> out/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ/.config;
make -C kernelO=../out/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ ARCH=arm64CROSS_COMPILE=aarch64-linux-android- oldconfig
fi
echo"####################### Buildingkernel ##########################"
rm -rf out/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ/arch/arm64/boot/dts
make -C kernelO=../out/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ ARCH=arm64CROSS_COMPILE=aarch64-linux-android- KCFLAGS=-mno-android -j16
make -C kernelO=../out/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ ARCH=arm64CROSS_COMPILE=aarch64-linux-android- KCFLAGS=-mno-android modules -j16
make -C kernelO=../out/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJINSTALL_MOD_PATH=../../system INSTALL_MOD_STRIP=1 ARCH=arm64CROSS_COMPILE=aarch64-linux-android- modules_install -j16
cp out/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ/arch/arm64/boot/Image.gz-dtb out/target/product/$TARGET_PRODUCT/kernel
#echo "Targetdt image: out/target/product/$TARGET_PRODUCT/dt.img"
#out/host/linux-x86/bin/dtbTool-o out/target/product/$TARGET_PRODUCT/dt.img -s 2048 -pout/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ/scripts/dtc/out/target/product/$TARGET_PRODUCT/obj/KERNEL_OBJ/arch/arm64/boot/dts/
#chmod a+rout/target/product/$TARGET_PRODUCT/dt.img
echo "Targetboot image: out/target/product/$TARGET_PRODUCT/boot.img"
out/host/linux-x86/bin/mkbootimg --kernelout/target/product/$TARGET_PRODUCT/kernel --ramdiskout/target/product/$TARGET_PRODUCT/ramdisk.img --cmdline"console=ttyHSL0,115200,n8 androidboot.console=ttyHSL0androidboot.hardware=qcom msm_rtb.filter=0x237 ehci-hcd.park=3androidboot.bootdevice=7824900.sdhci lpm_levels.sleep_disabled=1earlyprintk" --base 0x80000000 --pagesize 2048 --outputout/target/product/$TARGET_PRODUCT/boot.img
out/host/linux-x86/bin/boot_signer/boot out/target/product/$TARGET_PRODUCT/boot.imgbuild/target/product/security/verity_private_dev_keyout/target/product/$TARGET_PRODUCT/boot.img