
function download_atf() {
  rm -rf atf
  mkdir atf; cd atf
  git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git || exit 1
  pushd trusted-firmware-a || exit 1
    git status
    git fsck
    ATF_VER=$( echo $(git rev-list --count master).$(git rev-parse --short master) )
    find . -name '.git*' -print0 | xargs -0 rm -rf

    # Patches for ATF:
    # Manjaro carry the ATF patches within their U-Boot tree:
    # https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-pinebookpro/-/tree/master
    # https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-rockpro64
    # Now merged.
    #wget https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-pinebookpro/-/raw/master/0001-fix-rk3399-suspend-correct-LPDDR4-resume-sequence.patch
    #wget https://gitlab.manjaro.org/manjaro-arm/packages/core/uboot-pinebookpro/-/raw/master/0002-fix-rockchip-rk3399-fix-dram-section-placement.patch
  popd
  tar -Jcf ../arm-trusted-firmware-$ATF_VER.tar.xz trusted-firmware-a/
  cd ..
  rm -rf atf
}

download_atf
