# Contributor: Milan P. Stanić <mps@arvanta.net>
# Contributor: Maxim Karasev <begs@disroot.org>
# Maintainer: Bart Ribbers <bribbers@disroot.org>
pkgname=arm-trusted-firmware
pkgver=9999
_pkgver=2.8.0
pkgrel=9
pkgdesc="ARM Trusted Firmware-A (TF-A)"
url="https://github.com/ARM-software/arm-trusted-firmware"
arch="aarch64"
license="BSD-3-Clause"
makedepends="dtc openssl-dev gcc-arm-none-eabi"
source="https://github.com/ARM-software/arm-trusted-firmware/archive/v$_pkgver/arm-trusted-firmware-v$_pkgver.tar.gz"
options="!check" # No tests

_plats="
	sun50i_a64
	sun50i_h6
	rk3399
	rk3328
	"
builddir="$srcdir/$pkgname-$_pkgver"

build() {
	unset LDFLAGS
	for plat in $_plats; do
		local opts=""

		case "$plat" in
			sun50i_a64)
				opts="SUNXI_SETUP_REGULATORS=0 SUNXI_AMEND_DTB=1"
				;;
		esac

		msg "Building ATF for $plat (opts='$opts')"
		LDFLAGS="$LDFLAGS -no-warn-rwx-segment" make E=0 PLAT=$plat bl31 $opts
	done
}

package() {
	for plat in $_plats; do
		case $plat in
			rk3399|rk3328)
				install -D "$builddir"/build/$plat/release/bl31/bl31.elf \
					"$pkgdir"/usr/share/$pkgname/$plat/bl31.elf
					;;
			*)
				install -D "$builddir"/build/$plat/release/bl31.bin \
					"$pkgdir"/usr/share/$pkgname/$plat/bl31.bin
					;;
		esac
	done
}

sha512sums="
958cf8f9e258638e59d0fbd8b053fce7d8a9ea2fc922686c9d20ea16f79f55219ac18a12ab240c528ee98e49c2e0eef4c963fdb255cc14b92437a5b3cffc8640  arm-trusted-firmware-v2.8.0.tar.gz
"
