source "${BASH_SOURCE%/*}/include/meson64_common.inc"
if [[ $BOARD == odroidc2 ]]; then
	UBOOT_TARGET_MAP=";;$SRC/cache/sources/odroidc2-blobs/bl1.bin.hardkernel u-boot.bin"
fi

uboot_custom_postprocess()
{
	if [[ $BOARD == odroidc2 ]]; then
		local t=$SRC/cache/sources/odroidc2-blobs/
		$PKG_PREFIX$t/fip_create	--bl30  $t/gxb/bl30.bin \
				--bl301 $t/gxb/bl301.bin \
				--bl31  $t/gxb/bl31.bin \
				--bl33  u-boot.bin \
				fip.bin
		$PKG_PREFIX$t/fip_create --dump fip.bin
		cat $t/gxb/bl2.package fip.bin > boot_new.bin
		rm -f u-boot.img
		$PKG_PREFIX$t/gxb/aml_encrypt_gxb --bootsig \
                                --input boot_new.bin \
                                --output u-boot.img
		rm -f u-boot.bin
		dd if=u-boot.img of=u-boot.bin bs=512 skip=96 status=none
	fi

	if [[ $BOARD == nanopik2-s905 ]]; then
		local t=$SRC/cache/sources/odroidc2-blobs/
		mv u-boot.bin bl33.bin

		$t/blx_fix.sh 	$t/k2/bl30.bin \
				$t/k2/zero_tmp \
				$t/k2/bl30_zero.bin \
				$t/k2/bl301.bin \
				$t/k2/bl301_zero.bin \
				$t/k2/bl30_new.bin bl30

		$PKG_PREFIX$t/k2/fip_create --bl30 $t/k2/bl30_new.bin \
				 --bl31 $t/k2/bl31.img \
				 --bl33 bl33.bin \
				 $t/k2/fip.bin

		$PKG_PREFIX$t/k2/fip_create --dump $t/k2/fip.bin

		python $t/acs_tool.pyc $t/k2/bl2.bin \
				$t/k2/bl2_acs.bin \
				$t/k2/acs.bin 0

		$t/blx_fix.sh 	$t/k2/bl2_acs.bin \
				$t/k2/zero_tmp \
				$t/k2/bl2_zero.bin \
				$t/k2/bl21.bin \
				$t/k2/bl21_zero.bin \
				$t/k2/bl2_new.bin bl2

		cat $t/k2/bl2_new.bin $t/k2/fip.bin > boot_new.bin

		$PKG_PREFIX$t/k2/aml_encrypt_gxb --bootsig \
                                --input boot_new.bin \
                                --output u-boot.bin

	fi
}

if [[ $BOARD == odroidc2 ]]; then

	write_uboot_platform()
	{
		dd if=$1/bl1.bin.hardkernel of=$2 bs=1 count=442 conv=fsync > /dev/null 2>&1
		dd if=$1/bl1.bin.hardkernel of=$2 bs=512 skip=1 seek=1 conv=fsync > /dev/null 2>&1
		dd if=$1/u-boot.bin of=$2 bs=512 seek=97 conv=fsync > /dev/null 2>&1
	}

fi
