# U-Boot: Dragonboard 410c
# Maintainer: Kevin Mihelich <kevin@archlinuxarm.org>

buildarch=8

pkgname=uboot-dragonboard
pkgver=2016.09
pkgrel=1
pkgdesc="U-Boot for Dragonboard 410c"
arch=('aarch64')
url='http://www.denx.de/wiki/U-Boot/WebHome'
license=('GPL')
install=$pkgname.install
backup=('boot/boot.txt' 'boot/boot.scr')
makedepends=('bc' 'dtc' 'git' 'skales')
source=("ftp://ftp.denx.de/pub/u-boot/u-boot-${pkgver/rc/-rc}.tar.bz2"
        '0001-arch-linux-arm-modifications.patch'
        'boot.txt'
        'mkscr')
md5sums=('2e69dda70eb28f8042d2f9fbeb1feaa1'
         '17601b63768a2c98a04fe20fdcb820c6'
         'fd933e5a372406ab0a9606e2dd696ab9'
         '021623a04afd29ac3f368977140cfbfd')

prepare() {
  cd u-boot-${pkgver/rc/-rc}

  git apply ../0001-arch-linux-arm-modifications.patch
}

build() {
  cd u-boot-${pkgver/rc/-rc}

  unset CFLAGS CXXFLAGS CPPFLAGS

  make distclean
  make dragonboard410c_config
  make EXTRAVERSION=-${pkgrel}
}

package() {
  cd u-boot-${pkgver/rc/-rc}

  mkdir -p "${pkgdir}"/boot

  touch rd
  dtbTool -o dt.img arch/arm/dts
  mkbootimg --kernel=u-boot-dtb.bin --output=u-boot.img --dt=dt.img  --pagesize 2048 --base 0x80000000 --ramdisk=rd --cmdline=""
  cp u-boot.img ${pkgdir}/boot

  tools/mkimage -A arm -O linux -T script -C none -n "U-Boot boot script" -d ../boot.txt "${pkgdir}"/boot/boot.scr
  cp ../{boot.txt,mkscr} "${pkgdir}"/boot
}