#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) Martin Schmiedel
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
#

source "${BASH_SOURCE%/*}/include/imx8_common.inc"
OFFSET=32

# i.MX8Mx families needs for boot:
# - atf
# - hdmi firmware (some)
# - ddr firmware
# - uboot

# make some board specific adjustments
case $BOARD in
	mba8mpxl*)
		ATFSOURCE='https://github.com/tq-systems/atf' # required for ram
		ATFBRANCH="branch:TQMa8-imx_5.4.70_2.3.0"
		ATF_ADDR="0x00970000"
		BOOTSOURCE='https://github.com/tq-systems/u-boot-tqmaxx.git' # u-boot mainlining is hard and has low-priority
		BOOTBRANCH='branch:TQMa8-v2020.04_imx_5.4.70_2.3.0'
		BOOTPATCHDIR="u-boot-tqma" # could be removed when distro boot patches are integrated
		;;
esac

# bootloader releated
pre_config_uboot_target()
{
	# get the firmware
	rm -rf ${IMX_FIRMWARE}*
	wget https://www.nxp.com/lgfiles/NMG/MAD/YOCTO/${IMX_FIRMWARE}.bin -O ${IMX_FIRMWARE}.bin
	chmod +x ${IMX_FIRMWARE}.bin
	./${IMX_FIRMWARE}.bin --auto-accept

	# copy needed files for uboot (used by all imx8m cpu's)
	cp ${IMX_FIRMWARE}/firmware/hdmi/cadence/signed_hdmi_imx8m.bin .
	cp ${IMX_FIRMWARE}/firmware/hdmi/cadence/signed_dp_imx8m.bin .
	cp ${IMX_FIRMWARE}/firmware/ddr/synopsys/lpddr4*.bin .

	export ATF_LOAD_ADDR=${ATF_ADDR}
}

write_uboot_platform()
{
	echo ${OFFSET}
	dd if=$1/flash.bin of=$2 bs=1K seek=${OFFSET} status=noxfer conv=fsync > /dev/null 2>&1
}

# bsp related
family_tweaks_bsp() {
	:
}