#!/bin/bash -x
#trustedcore packager
#created by h00206996

#DEBUG=0
DEBUG=1

COMPARE_IMAGE=$4

if [[ ${ANDROID_PRODUCT_OUT} == '' ]]; then
    echo "env error"
    exit -1
fi

KERNEL_TEXT_BASE=$1
echo "kernel text base=${KERNEL_TEXT_BASE}"
PLATFORM_CHOOSE=$3
echo "platform is ${PLATFORM_CHOOSE}"

CHIP_CHOOSE=$5
echo "chip is ${CHIP_CHOOSE}"

IMG_PATH=${ANDROID_PRODUCT_OUT}/obj/EXECUTABLES
KERNEL_NAME=rtosck.img
KERNEL_PATH=${ANDROID_PRODUCT_OUT}/${KERNEL_NAME}
DST_PATH=${ANDROID_PRODUCT_OUT}/trustedcore.img
CURDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

TASK1_NAME=globaltask.img
TASK1_UUID="00000000000000000000000000000000"
TASK1_PATH=${IMG_PATH}/${TASK1_NAME}_intermediates/${TASK1_NAME}

TASK2_NAME=task_teetest.elf
TASK2_UUID="03030303030303030303030303030303"

TASK3_NAME=task_echo.elf
TASK3_UUID="01010101010101010101010101010101"

TASK5_NAME=task_storage.elf
TASK5_UUID="02020202020202020202020202020202"

TASK8_NAME=task_keymaster.elf
TASK8_UUID="07070707070707070707070707070707"

TASK9_NAME=task_secboot.elf
TASK9_UUID="08080808080808080808080808080808"

TASK11_NAME=task_reet.elf
TASK11_UUID="0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A0A"

TASK12_NAME=task_gatekeeper.elf
TASK12_UUID="0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"

TASK13_NAME=task_keyboard.elf
TASK13_UUID="0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C"

TASK14_NAME=task_mdpp.elf
TASK14_UUID="41d21d0f975741f18706b3baa35fe82f"

TASK15_NAME=task_vdec.elf
TASK15_UUID="4a1a44e83ed74e009c1e02a2577ea24a"
TASK16_NAME=task_ssa.elf
TASK16_UUID="999286b954da42359e7796e81fea1ee4"

TASK17_NAME=task_antiroot.elf
TASK17_UUID="e7ed1f64468741da96dccbe4f27c838f"

TASK18_NAME=task_hi_vcodec.elf
TASK18_UUID="528822b7fc78466bb57e62093d6034a7"

if [ "${PLATFORM_CHOOSE}" == "WITH_DEVCHIP_PLATFORM" ];then
	TASK1_DEVCHIP_NAME=task_hisi_demo.elf
	TASK1_DEVCHIP_UUID="0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B0B"
	TASK2_DEVCHIP_NAME=task_stb_drm.elf
	TASK2_DEVCHIP_UUID="14047d2df23648a0a0c4c1cccbb64546"
	TASK3_DEVCHIP_NAME=task_sec_mmz.elf
	TASK3_DEVCHIP_UUID="0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C"
	TASK4_DEVCHIP_NAME=task_sec_hdmi.elf
	TASK4_DEVCHIP_UUID="08080601010000000000000000000001"
	TASK5_DEVCHIP_NAME=vfmw_task.elf
	TASK5_DEVCHIP_UUID="0D0D0D0D0D0D0D0D0D0D0D0D0D0D0D0D"
	TASK6_DEVCHIP_NAME=task_hisi_vpss.elf
	TASK6_DEVCHIP_UUID="3acc8b1ba7e1e511b86d9a79f06e9478"
	TASK7_DEVCHIP_NAME=smmu_task.elf
	TASK7_DEVCHIP_UUID="0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F"
	TASK8_DEVCHIP_NAME=task_hisi_test.elf
	TASK8_DEVCHIP_UUID="0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E0E"
	TASK9_DEVCHIP_NAME=task_hisi_dmx.elf
	TASK9_DEVCHIP_UUID="10101010101010101010101010101010"
	TASK10_DEVCHIP_NAME=task_hisi_pvr.elf
	TASK10_DEVCHIP_UUID="11111111111111111111111111111111"
	TASK11_DEVCHIP_NAME=task_wv_server.elf
	TASK11_DEVCHIP_UUID="79b7778897894a7aa2beb60155eef5f8"
	TASK12_DEVCHIP_NAME=task_hisi_vdp.elf
	TASK12_DEVCHIP_UUID="1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E1E"
	TASK13_DEVCHIP_NAME=VMXTA.elf
	TASK13_DEVCHIP_UUID="22222222222222222222222222222222"
	TASK14_DEVCHIP_NAME=videomarkTA.elf
	TASK14_DEVCHIP_UUID="33333333333333333333333333333333"
fi

if [ $DEBUG -gt 0 ];then
    TASK2_PATH=${IMG_PATH}/${TASK2_NAME%.*}_intermediates/${TASK2_NAME}
    TASK3_PATH=${IMG_PATH}/${TASK3_NAME%.*}_intermediates/${TASK3_NAME}
    TASK5_PATH=${IMG_PATH}/${TASK5_NAME%.*}_intermediates/${TASK5_NAME}
    TASK8_PATH=${IMG_PATH}/${TASK8_NAME%.*}_intermediates/${TASK8_NAME}
    TASK9_PATH=${IMG_PATH}/${TASK9_NAME%.*}_intermediates/${TASK9_NAME}
    TASK11_PATH=${IMG_PATH}/${TASK11_NAME%.*}_intermediates/${TASK11_NAME}
    TASK12_PATH=${IMG_PATH}/${TASK12_NAME%.*}_intermediates/${TASK12_NAME}
    TASK13_PATH=${IMG_PATH}/${TASK13_NAME%.*}_intermediates/${TASK13_NAME}
    TASK14_PATH=${IMG_PATH}/${TASK14_NAME%.*}_intermediates/${TASK14_NAME}
    TASK15_PATH=${IMG_PATH}/${TASK15_NAME%.*}_intermediates/${TASK15_NAME}
    TASK16_PATH=${IMG_PATH}/${TASK16_NAME%.*}_intermediates/${TASK16_NAME}
    TASK17_PATH=${IMG_PATH}/${TASK17_NAME%.*}_intermediates/${TASK17_NAME}
    TASK18_PATH=${IMG_PATH}/${TASK18_NAME%.*}_intermediates/${TASK18_NAME}
if [ "${PLATFORM_CHOOSE}" == "WITH_DEVCHIP_PLATFORM" ];then
	TASK1_DEVCHIP_PATH=${IMG_PATH}/${TASK1_DEVCHIP_NAME%.*}_intermediates/${TASK1_DEVCHIP_NAME}
	TASK2_DEVCHIP_PATH=${IMG_PATH}/${TASK2_DEVCHIP_NAME%.*}_intermediates/${TASK2_DEVCHIP_NAME}
	TASK3_DEVCHIP_PATH=${IMG_PATH}/${TASK3_DEVCHIP_NAME%.*}_intermediates/${TASK3_DEVCHIP_NAME}
	TASK4_DEVCHIP_PATH=${IMG_PATH}/${TASK4_DEVCHIP_NAME%.*}_intermediates/${TASK4_DEVCHIP_NAME}
	TASK5_DEVCHIP_PATH=${IMG_PATH}/${TASK5_DEVCHIP_NAME%.*}_intermediates/${TASK5_DEVCHIP_NAME}
	TASK6_DEVCHIP_PATH=${IMG_PATH}/${TASK6_DEVCHIP_NAME%.*}_intermediates/${TASK6_DEVCHIP_NAME}
	TASK7_DEVCHIP_PATH=${IMG_PATH}/${TASK7_DEVCHIP_NAME%.*}_intermediates/${TASK7_DEVCHIP_NAME}
	TASK8_DEVCHIP_PATH=${IMG_PATH}/${TASK8_DEVCHIP_NAME%.*}_intermediates/${TASK8_DEVCHIP_NAME}
	TASK9_DEVCHIP_PATH=${IMG_PATH}/${TASK9_DEVCHIP_NAME%.*}_intermediates/${TASK9_DEVCHIP_NAME}
	TASK10_DEVCHIP_PATH=${IMG_PATH}/${TASK10_DEVCHIP_NAME%.*}_intermediates/${TASK10_DEVCHIP_NAME}
	TASK11_DEVCHIP_PATH=${IMG_PATH}/${TASK11_DEVCHIP_NAME%.*}_intermediates/${TASK11_DEVCHIP_NAME}
	TASK12_DEVCHIP_PATH=${IMG_PATH}/${TASK12_DEVCHIP_NAME%.*}_intermediates/${TASK12_DEVCHIP_NAME}
	TASK13_DEVCHIP_PATH=${IMG_PATH}/${TASK13_DEVCHIP_NAME%.*}_intermediates/${TASK13_DEVCHIP_NAME}
	TASK14_DEVCHIP_PATH=${IMG_PATH}/${TASK14_DEVCHIP_NAME%.*}_intermediates/${TASK14_DEVCHIP_NAME}
fi
else
    TASK2_PATH=${CURDIR}/release/internal_tasks/${TASK2_NAME}
    TASK3_PATH=${CURDIR}/release/internal_tasks/${TASK3_NAME}
    TASK5_PATH=${CURDIR}/release/internal_tasks/${TASK5_NAME}
    TASK8_PATH=${CURDIR}/release/internal_tasks/${TASK8_NAME}
    TASK9_PATH=${IMG_PATH}/${TASK9_NAME%.*}_intermediates/${TASK9_NAME}
    TASK11_PATH=${CURDIR}/release/internal_tasks/${TASK11_NAME}
    TASK12_PATH=${CURDIR}/release/internal_tasks/${TASK12_NAME}
    TASK13_PATH=${CURDIR}/release/internal_tasks/${TASK13_NAME}
    TASK14_PATH=${CURDIR}/release/internal_tasks/${TASK14_NAME}
    TASK15_PATH=${IMG_PATH}/${TASK15_NAME%.*}_intermediates/${TASK15_NAME}
    TASK16_PATH=${CURDIR}/release/internal_tasks/${TASK16_NAME}
    TASK17_PATH=${CURDIR}/release/internal_tasks/${TASK17_NAME}
    TASK18_PATH=${IMG_PATH}/${TASK18_NAME%.*}_intermediates/${TASK18_NAME}
if [ "${PLATFORM_CHOOSE}" == "WITH_DEVCHIP_PLATFORM" ];then
    TASK1_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK1_DEVCHIP_NAME}
    TASK2_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK2_DEVCHIP_NAME}
    TASK3_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK3_DEVCHIP_NAME}
    TASK4_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK4_DEVCHIP_NAME}
    TASK5_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK5_DEVCHIP_NAME}
    TASK6_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK6_DEVCHIP_NAME}
    TASK7_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK7_DEVCHIP_NAME}
    TASK8_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK8_DEVCHIP_NAME}
    TASK9_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK9_DEVCHIP_NAME}
    TASK10_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK10_DEVCHIP_NAME}
    TASK11_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK11_DEVCHIP_NAME}
    TASK12_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK12_DEVCHIP_NAME}
    TASK13_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK13_DEVCHIP_NAME}
    TASK14_DEVCHIP_PATH=${CURDIR}/release/internal_tasks/${TASK14_DEVCHIP_NAME}
fi
fi
#Add new internal task here:
TASK_LIST="${TASK1_PATH},${TASK1_NAME%.*},${TASK1_UUID},0x1000
    ${TASK5_PATH},${TASK5_NAME%.*},${TASK5_UUID},0x1000 \
    ${TASK8_PATH},${TASK8_NAME%.*},${TASK8_UUID},0x1000 \
    ${TASK9_PATH},${TASK9_NAME%.*},${TASK9_UUID},0x1000 \
    ${TASK11_PATH},${TASK11_NAME%.*},${TASK11_UUID},0x1000 \
    ${TASK12_PATH},${TASK12_NAME%.*},${TASK12_UUID},0x1000 \
    ${TASK15_PATH},${TASK15_NAME%.*},${TASK15_UUID},0x1000 \
    ${TASK16_PATH},${TASK16_NAME%.*},${TASK16_UUID},0x1000 \
    ${TASK17_PATH},${TASK17_NAME%.*},${TASK17_UUID},0x1000 \
    "
TASK_UT_LIST="${TASK2_PATH},${TASK2_NAME%.*},${TASK2_UUID},0x1000 \
    ${TASK3_PATH},${TASK3_NAME%.*},${TASK3_UUID},0x1000 \
    "
TASK_BALONG_LIST="${TASK1_PATH},${TASK1_NAME%.*},${TASK1_UUID},0x1000 \
    ${TASK5_PATH},${TASK5_NAME%.*},${TASK5_UUID},0x1000 \
    ${TASK8_PATH},${TASK8_NAME%.*},${TASK8_UUID},0x1000 \
    ${TASK9_PATH},${TASK9_NAME%.*},${TASK9_UUID},0x1000 \
    ${TASK11_PATH},${TASK11_NAME%.*},${TASK11_UUID},0x1000 \
    ${TASK12_PATH},${TASK12_NAME%.*},${TASK12_UUID},0x1000 \
    ${TASK16_PATH},${TASK16_NAME%.*},${TASK16_UUID},0x1000 \
    "
TASK_HIVCODEC_LIST="${TASK18_PATH},${TASK18_NAME%.*},${TASK18_UUID},0x1000 \
    "
TASK_LIST=${TASK_LIST}
if [ "${PLATFORM_CHOOSE}" == "WITH_BALONG_V722_PLATFORM" ];then
    TASK_LIST=${TASK_BALONG_LIST}
fi
if [ "${PLATFORM_CHOOSE}" == "WITH_DEVCHIP_PLATFORM" ];then
	TASK_DEVCHIP_LIST="${TASK1_PATH},${TASK1_NAME%.*},${TASK1_UUID},0x1000 \
	    ${TASK5_PATH},${TASK5_NAME%.*},${TASK5_UUID},0x1000 \
	    ${TASK11_PATH},${TASK11_NAME%.*},${TASK11_UUID},0x1000 \
	    ${TASK16_PATH},${TASK16_NAME%.*},${TASK16_UUID},0x1000 \
	    ${TASK17_PATH},${TASK17_NAME%.*},${TASK17_UUID},0x1000 \
	    "
	if [ -f ${TASK1_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK1_DEVCHIP_PATH},${TASK1_DEVCHIP_NAME%.*},${TASK1_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK2_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK2_DEVCHIP_PATH},${TASK2_DEVCHIP_NAME%.*},${TASK2_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK3_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK3_DEVCHIP_PATH},${TASK3_DEVCHIP_NAME%.*},${TASK3_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK4_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK4_DEVCHIP_PATH},${TASK4_DEVCHIP_NAME%.*},${TASK4_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK5_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK5_DEVCHIP_PATH},${TASK5_DEVCHIP_NAME%.*},${TASK5_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK6_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK6_DEVCHIP_PATH},${TASK6_DEVCHIP_NAME%.*},${TASK6_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK7_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK7_DEVCHIP_PATH},${TASK7_DEVCHIP_NAME%.*},${TASK7_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK8_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK8_DEVCHIP_PATH},${TASK8_DEVCHIP_NAME%.*},${TASK8_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK9_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK9_DEVCHIP_PATH},${TASK9_DEVCHIP_NAME%.*},${TASK9_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK10_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK10_DEVCHIP_PATH},${TASK10_DEVCHIP_NAME%.*},${TASK10_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK11_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK11_DEVCHIP_PATH},${TASK11_DEVCHIP_NAME%.*},${TASK11_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK12_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK12_DEVCHIP_PATH},${TASK12_DEVCHIP_NAME%.*},${TASK12_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK13_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK13_DEVCHIP_PATH},${TASK13_DEVCHIP_NAME%.*},${TASK13_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
	if [ -f ${TASK14_DEVCHIP_PATH} ];then
		TASK_DEVCHIP="${TASK14_DEVCHIP_PATH},${TASK14_DEVCHIP_NAME%.*},${TASK14_DEVCHIP_UUID},0x1000 \
			"
		TASK_DEVCHIP_LIST=${TASK_DEVCHIP_LIST}${TASK_DEVCHIP}
	fi
    TASK_LIST=${TASK_DEVCHIP_LIST}
fi
echo "task list 1: is ${TASK_LIST}"
if [ "${CHIP_CHOOSE}" == "WITH_CHIP_HI3660" ];then
    TASK_LIST=${TASK_LIST}${TASK_HIVCODEC_LIST}
fi
echo "task list 2: is ${TASK_LIST}"

echo "1. repack globaltask.img and rtosck.img and place their symbol tables to the file tail"
if [ "${PLATFORM_CHOOSE}" == "WITH_BALONG_V722_PLATFORM" || \
	"${PLATFORM_CHOOSE}" == "WITH_DEVCHIP_PLATFORM" ];then
    gcc ${CURDIR}/tools/elf_extract.c -o ${CURDIR}/tools/elf_extract
else
    gcc ${CURDIR}/tools/elf_extract.c -o ${ANDROID_PRODUCT_OUT}/elf_extract
fi
KERNEL_ELF=${IMG_PATH}/${KERNEL_NAME}_intermediates/${KERNEL_NAME}.elf
KERNEL_SYMTAB_OFFSET=$(ls -l ${KERNEL_PATH}| awk '{print $5}')
if [ "${PLATFORM_CHOOSE}" == "WITH_BALONG_V722_PLATFORM" || \
	"${PLATFORM_CHOOSE}" == "WITH_DEVCHIP_PLATFORM" ];then
    ${CURDIR}/tools/elf_extract "rtosck" ${KERNEL_ELF} ${KERNEL_PATH}
else
    ${ANDROID_PRODUCT_OUT}/elf_extract "rtosck" ${KERNEL_ELF} ${KERNEL_PATH}
fi

TASK1_ELF=${IMG_PATH}/${TASK1_NAME}_intermediates/${TASK1_NAME}.elf
GLOBAL_SYMTAB_OFFSET=$(ls -l ${TASK1_PATH}| awk '{print $5}')
if [ "${PLATFORM_CHOOSE}" == "WITH_BALONG_V722_PLATFORM" || \
	"${PLATFORM_CHOOSE}" == "WITH_DEVCHIP_PLATFORM" ];then
    ${CURDIR}/tools/elf_extract "globaltask" ${TASK1_ELF} ${IMG_PATH}/${TASK1_NAME}_intermediates/${TASK1_NAME}
else
    ${ANDROID_PRODUCT_OUT}/elf_extract "globaltask" ${TASK1_ELF} ${IMG_PATH}/${TASK1_NAME}_intermediates/${TASK1_NAME}
fi

echo "2. generator symbol table header for globaltask.img and rtosck.img"
GLOBAL_SYMTAB_SIZE=$(readelf -S ${TASK1_ELF}| awk '{if ($2==".symtab") {print $6}}')
GLOBAL_STRTAB_SIZE=$(readelf -S ${TASK1_ELF}| awk '{if ($2==".strtab") {print $6}}')
GLOBAL_BSS_SIZE=$(readelf -S ${TASK1_ELF}| awk '{if ($2==".bss") {print $6}}')
KERNEL_SYMTAB_SIZE=$(readelf -S ${KERNEL_ELF}| awk '{if ($2==".symtab") {print $6}}')
KERNEL_STRTAB_SIZE=$(readelf -S ${KERNEL_ELF}| awk '{if ($2==".strtab") {print $6}}')
GLOBAL_SYM_HEAD="${GLOBAL_SYMTAB_OFFSET},${GLOBAL_SYMTAB_SIZE},${GLOBAL_STRTAB_SIZE},${GLOBAL_BSS_SIZE}"
KERNEL_SYM_HEAD="${KERNEL_SYMTAB_OFFSET},${KERNEL_SYMTAB_SIZE},${KERNEL_STRTAB_SIZE}"

echo "3. get globaltask.got size"
GOT_SIZE=$(size -A -x ${TASK1_ELF}| awk '{if ($1==".rel.dyn") {print $2}}')
echo "GOT_SIZE=${GOT_SIZE}"

echo "4. generate header"
#modify by l00202565, set globaltask relocation info to image header
ELFFILE=${CURDIR}/release/elfile
readelf -s -W ${TASK1_ELF} > ${ELFFILE}
#if [ "${CHIP_CHOOSE}" == "WITH_CHIP_HI3660" ];then
#    KECC1PUB_PLAT=kecc1pub_chicago
#fi
#if [ "${CHIP_CHOOSE}" == "WITH_CHIP_HI3650" ];then
#    KECC1PUB_PLAT=kecc1pub_austin
#fi
#if [ "${CHIP_CHOOSE}" == "WITH_CHIP_HI6250" ];then
#    KECC1PUB_PLAT=kecc1pub_dallas
#fi
${CURDIR}/header.py ${DST_PATH} ${KERNEL_PATH} ${KERNEL_TEXT_BASE} ${GOT_SIZE} \
    ${GLOBAL_SYM_HEAD} ${KERNEL_SYM_HEAD} ${TASK1_ELF} ${ELFFILE} ${COMPARE_IMAGE} ${KECC1PUB_PLAT} ${TASK_LIST}
if [ $? -ne 0 ]
then
    rm ${DST_PATH}
    echo failed to do header.py ret is $?
    exit 1
else
    echo succeed to execute head.py
fi
rm ${ELFFILE}
rm ${KERNEL_PATH}
rm  ${IMG_PATH}/${TASK1_NAME}_intermediates/${TASK1_NAME}
