# U-Boot: BeagleBone Green
# Maintainer: Isaac David <isacdaavid@at@isacdaavid@dot@info>

pkgname=uboot-am335x_green
_gitver='d5abcf94c7123167725fc22ace342f0d455093c1'
pkgver=20170328.g${_gitver:0:10}
pkgrel=1
pkgdesc="U-Boot for BeagleBone Green (git version)"
arch=('armv7h')
url="http://git.denx.de/u-boot.git/"
makedepends=('git' 'bc' 'uboot-tools')
depends=('linux-libre')
replaces=('uboot-beaglebone')
conflicts=('uboot4extlinux-am335x_bone' 'uboot4grub-am335x_bone'
           'grub-am335x_bone' 'uboot-am335x_bone')
license=('GPL')
install=${pkgname}.install
source=("u-boot-${_gitver:0:10}::git+http://git.denx.de/u-boot.git"
        '0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch'
        '0002-Forward-port-parabola-patch.patch'
        '0003-Beaglebone-green.patch'
        'uEnv.txt'
        'boot.cmd')
sha256sums=('SKIP'
            'c02bdad650f62e5fc465a2113f9b8c19f55833afc99d14230952cce712496502'
            'ca21d84c57f31878ee3288f52450dc09d5dc9de807de77d5bdf7d9b88d8dba59'
            '7a659bf26d6c126da41723b6005d95fe0bb1e989ee42134104fbb757bb108c90'
            '4ef3c3177e4476cdb1790dd021d2383ef9913c029d005ffbeb61b958e753672e'
            '34e920015ba60acebd443b5d4d9b060cc9ae8aa6ed5f405f86645b6cdec0dbc1')

prepare() {
  cd u-boot-${_gitver:0:10}
  git reset --hard ${_gitver}
  patch -Np1 -i ../0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
  patch -Np1 -i ../0002-Forward-port-parabola-patch.patch
  patch -Np1 -i ../0003-Beaglebone-green.patch
}

build() {
  cd u-boot-${_gitver:0:10}

  unset CFLAGS CXXFLAGS LDFLAGS

  make distclean
  make am335x_evm_config
  make
  mkimage -A arm -O linux -T script -C none -d "${srcdir}"/boot.cmd boot.scr
}

package() {
  cd u-boot-${_gitver:0:10}
  mkdir -p "${pkgdir}"/boot
  cp MLO u-boot.img boot.scr "${srcdir}"/uEnv.txt "${pkgdir}"/boot
}
