#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2013-2023 Igor Pecovnik, igor@armbian.com
#
# This file is a part of the Armbian Build Framework
# https://github.com/armbian/build/
#
source "${BASH_SOURCE%/*}/include/meson64_common.inc"

# Fetch c2 blobs. Those are ancient, when first released by HK. Also used in meson-gxbb.conf
function fetch_sources_tools__amlogic_odroidc2_blobs_fip() {
	fetch_from_repo "https://github.com/armbian/odroidc2-blobs" "odroidc2-blobs" "branch:master"
}

if [[ $BOARD == lafrite ]]; then
	UBOOT_TARGET_MAP="u-boot-dtb.img;;u-boot.bin:u-boot.bin u-boot-dtb.img"
fi

if [[ $BOARD = khadas-vim1 ]]; then
	# temporally workaround - using prebuild u-boot from https://github.com/khadas/khadas-uboot/releases/tag/0.11
	UBOOT_TARGET_MAP=";;$SRC/packages/blobs/meson/u-boot-vim1-sd.bin:u-boot.bin"
fi

if [[ $BOARD = khadas-vim2 ]]; then
	# temporally workaround - using prebuild u-boot from https://github.com/khadas/khadas-uboot/releases/tag/0.11
	UBOOT_TARGET_MAP=";;$SRC/packages/blobs/meson/u-boot-vim2-sd.bin:u-boot.bin"
fi

family_tweaks() {
	:
}

uboot_custom_postprocess() {
	if [[ $BOARD == lepotato ]]; then
		uboot_gxl_postprocess $SRC/cache/sources/odroidc2-blobs/ gxl
	fi

	if [[ $BOARD == aml-s9xx-box ]]; then
		uboot_gxl_postprocess $SRC/cache/sources/odroidc2-blobs/ gxl
	fi

	if [[ $BOARD == khadas-vim1 ]]; then
		uboot_gxl_postprocess $SRC/cache/sources/odroidc2-blobs/ vim1
	fi

	if [[ $BOARD == khadas-vim2 ]]; then
		uboot_gxl_postprocess_ng $SRC/cache/sources/amlogic-boot-fip/khadas-vim2
	fi
}
