#
# 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/
#
CPUMIN=392000
CPUMAX=996000
GOVERNOR=interactive
SERIALCON=ttymxc0
ARCH=armhf
UBOOT_TARGET_MAP=';;SPL:SPL.sdhc u-boot.img:u-boot.img.sdhc'
BOOTPATCHDIR='legacy/u-boot-imx6'

case $BRANCH in

	legacy)

		declare -g KERNEL_MAJOR_MINOR="6.1" # Major and minor versions of this kernel.
		;;

	current)

		declare -g KERNEL_MAJOR_MINOR="6.6" # Major and minor versions of this kernel.
		;;

	edge)

		declare -g KERNEL_MAJOR_MINOR="6.7" # Major and minor versions of this kernel.
		;;

esac

case $BOARD in

	udoo)

		BOOTBRANCH='tag:v2017.11'
		SERIALCON=ttymxc1
		BOOTSCRIPT="boot-udoo.cmd:boot.cmd"
		BOOTENV_FILE='udoo.txt'

		;;

	cubox-i)

		BOOTSOURCE='https://github.com/SolidRun/u-boot.git'
		BOOTBRANCH='branch:v2018.01-solidrun-imx6'
		BOOTSCRIPT='boot-cubox.cmd:boot.cmd'
		BOOTENV_FILE='cubox.txt'
		UBOOT_TARGET_MAP=';emmc;SPL:SPL.emmc u-boot.img:u-boot.img.emmc
						  ;sdhc;SPL:SPL.sdhc u-boot.img:u-boot.img.sdhc
						  ;sdhc;SPL:SPL.sata u-boot.img:u-boot.img.sata
						  ;sdhc;SPL:SPL.spi-flash u-boot.img:u-boot.img.spi-flash'

		;;

	wandboard)

		BOOTBRANCH="branch:v2017.03"
		BOOTSCRIPT='boot-udoo.cmd:boot.cmd'
		BOOTENV_FILE='cubox.txt'

		;;

esac

write_uboot_platform() {
	dd if=$1/SPL.sdhc of=$2 bs=1K seek=1 status=noxfer > /dev/null 2>&1
	dd if=$1/u-boot.img.sdhc of=$2 bs=1K seek=69 status=noxfer > /dev/null 2>&1
}

family_tweaks_bsp() {
	install -m 644 $SRC/packages/bsp/cubox/99-hdmi_fb0.conf $destination/etc/X11/xorg.conf.d/99-hdmi_fb0.conf
	install -m 755 $SRC/packages/bsp/cubox/brcm_patchram_plus $destination/usr/bin/brcm_patchram_plus
	cp $SRC/packages/bsp/cubox/brcm4330 $destination/etc/default/
	# TODO: replace by a systemd service
	mkdir $destination/etc/init.d/
	install -m 755 $SRC/packages/bsp/cubox/brcm4330-patch $destination/etc/init.d/brcm4330-patch
}
