# U-Boot: Rock64
# Maintainer: Kevin Mihelich <kevin@archlinuxarm.org>

buildarch=8

pkgname=uboot-rock64
pkgver=2020.01
pkgrel=1
pkgdesc="U-Boot for Rock64"
arch=('aarch64')
url='http://www.denx.de/wiki/U-Boot/WebHome'
license=('GPL')
backup=('boot/boot.txt' 'boot/boot.scr')
makedepends=('bc' 'git' 'rockchip-tools' 'python' 'swig' 'dtc')
install=${pkgname}.install
_commit_rkbin=15a3e065a49ba7981945d725207618e92ebe8ebb
source=("ftp://ftp.denx.de/pub/u-boot/u-boot-${pkgver/rc/-rc}.tar.bz2"
        "git+https://github.com/rockchip-linux/rkbin.git#commit=$_commit_rkbin"
        'rk3328trust.ini'
        'boot.txt'
        'mkscr')
md5sums=('b6b2e0787b6874e6b57da0a065a84f5a'
         'SKIP'
         '48946b910716b90d81f47caafb752fef'
         'c926f318d8fa7a5c89108331cbd3f8e2'
         '021623a04afd29ac3f368977140cfbfd')

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

  unset CLFAGS CXXFLAGS CPPFLAGS LDFLAGS

  make distclean
  make evb-rk3328_defconfig
  echo 'CONFIG_CMD_BTRFS=y' >> .config
  echo 'CONFIG_FS_BTRFS=y' >> .config
  echo 'CONFIG_NETCONSOLE=y' >> .config
  echo 'CONFIG_IDENT_STRING=" Arch Linux ARM"' >> .config
  make -j4 EXTRAVERSION=-${pkgrel}
}

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

  mkdir -p "${pkgdir}/boot"

  tools/mkimage -n rk3328 -T rksd -d ../rkbin/bin/rk33/rk3328_ddr_333MHz_v1.16.bin "${pkgdir}/boot/idbloader.img"
  cat ../rkbin/bin/rk33/rk322xh_miniloader_v2.50.bin >> "${pkgdir}/boot/idbloader.img"

  loaderimage --pack --uboot u-boot-dtb.bin "${pkgdir}/boot/uboot.img" 0x200000

  trust_merger ../rk3328trust.ini

  cp u-boot-dtb.bin trust.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
}

