Skip to content
Snippets Groups Projects
PKGBUILD 5.62 KiB
Newer Older
fkardame's avatar
fkardame committed
# U-Boot: Pinephone Pro based on PKGBUILD for RK3399
Philip Müller's avatar
Philip Müller committed
# Maintainer: Philip Müller <philm@manjaro.org>
fkardame's avatar
fkardame committed
# Contributor: Furkan Kardame <furkan@fkardame.com>
# Contributor: Dan Johansen <strit@manjaro.org>
# Contributor: Dragan Simic <dsimic@buserror.io>
fkardame's avatar
fkardame committed

pkgname=uboot-pinephonepro
pkgver=2023.07rc2
pkgrel=0.1
Philip Müller's avatar
Philip Müller committed
epoch=5
_nonfoss=yes
Philip Müller's avatar
Philip Müller committed
_tfaver=lts-v2.8.4
_tfanon=rk3399_ddr_933MHz_v1.30.bin
_tfanonc=851d6dcb793ef83f625f51fb5fecee93f86f3149
_bl31non=rk3399_bl31_v1.36.elf
_bl31nonc=1d47b8d9369522dfc2c5af420b6e41a9993ddd78
_commit=981097c0d80c488ef7b8c6a6fc114639e03ae4b6
pkgdesc="U-Boot for Pine64 PinePhone Pro"
fkardame's avatar
fkardame committed
arch=('aarch64')
url='https://source.denx.de/u-boot/u-boot'
[[ $_nonfoss == yes ]] && license=('GPL' 'Custom')
[[ $_nonfoss != yes ]] && license=('GPL')
Philip Müller's avatar
Philip Müller committed
makedepends=('git' 'arm-none-eabi-gcc' 'dtc' 'bc' 'swig' 'python-setuptools' 'python-pyelftools')
depends=('uboot-tools')
fkardame's avatar
fkardame committed
provides=('uboot')
conflicts=('uboot')
install=${pkgname}.install
source=("git+https://xff.cz/git/u-boot#commit=$_commit"
Philip Müller's avatar
Philip Müller committed
        "arm-trusted-firmware-${_tfaver}.tar.gz::https://github.com/ARM-software/arm-trusted-firmware/archive/refs/tags/${_tfaver}.tar.gz"
        "https://github.com/rockchip-linux/rkbin/raw/$_bl31nonc/bin/rk33/$_bl31non"       
        "https://github.com/rockchip-linux/rkbin/raw/$_tfanonc/bin/rk33/$_tfanon"
        "LICENSE.TXT"
Philip Müller's avatar
Philip Müller committed
        "boot.txt"
        "ppp-uboot-flash"
        "ppp-uboot-mkscr"
        "ppp-prepare-fstab"
        "ppp-prepare-fstab.service")
sha256sums=('SKIP'
Philip Müller's avatar
Philip Müller committed
            '9887ca101cfa2d4efe2af9d2671aa64b9ba82a7f28409e5854696a7778b35225'
            '3be6cdf32462d7f676d109bb2a97af9a1f469f058674ef0a5cb20941af2923d5'
            'aab3b04166c098c8ba1d9a734c509cdf75b47b64c37c49196c7242526ce32179'
            '0b37e1522c36cf4579c45dfb138798c3cb5665fcf6302b95377179fbed38e35c'
Philip Müller's avatar
Philip Müller committed
            '12311da7e1a8d7bf19ddf78568e58da0888b0ca89e937aecccae4d896d20b7e2'
            'e4c7f9320432cada1af9a2cbf3143f296b0762812099dda3d03368a3277a16b4'
            '4bdcf15b540feb4529cbcac0e72dce444049bb33dff8dcd94e06d4f6aa477684'
            'de7e36cdc7ed2fb5abb9155c97f87926361aa5be87d794c9016776160f3430ec'
            'e55fb02dfb6213eabbb899b468dc5f68d36a11c05feda4c14e80282415222fea')
fkardame's avatar
fkardame committed

Philip Müller's avatar
Philip Müller committed
prepare() {
  mv u-boot u-boot-${pkgver/rc/-rc}
Philip Müller's avatar
Philip Müller committed
  apply_patches() {
      local PATCH
      for PATCH in "${source[@]}"; do
          PATCH="${PATCH%%::*}"
          PATCH="${PATCH##*/}"
          [[ ${PATCH} = $1*.patch ]] || continue
          msg2 "Applying patch: ${PATCH}..."
Philip Müller's avatar
Philip Müller committed
          patch -N -p1 < "../${PATCH}"
Philip Müller's avatar
Philip Müller committed
  cd u-boot-${pkgver/rc/-rc}
Philip Müller's avatar
Philip Müller committed

  # Patches specific to the PinePhone Pro
Philip Müller's avatar
Philip Müller committed
  # NOTE: Patch "1012-Configure-USB-power-settings-for-PinePhone-Pro.patch"
Philip Müller's avatar
Philip Müller committed
  #       is disabled temporarily because it's currently not in usable state,
  #       but it will be reworked later
Philip Müller's avatar
Philip Müller committed
  apply_patches 1

  # Patches from the U-Boot repository or mailing list
  apply_patches 2
Philip Müller's avatar
Philip Müller committed

  # Temporary patches that will be folded into the first patch group later,
  # together with updating the device tree for the PinePhone Pro
  # TODO: While folding, also remove the now unused "pmugrf" variable in
  #       board/pine64/pinephone-pro-rk3399/pinephone-pro-rk3399.c
  apply_patches 3
Philip Müller's avatar
Philip Müller committed
}
fkardame's avatar
fkardame committed

build() {
  # Avoid build warnings by editing a .config option in place instead of
  # appending an option to .config, if an option is already present
  update_config() {
    if ! grep -q "^$1=$2$" .config; then
      if grep -q "^# $1 is not set$" .config; then
        sed -i -e "s/^# $1 is not set$/$1=$2/g" .config
      elif grep -q "^$1=" .config; then
        sed -i -e "s/^$1=.*/$1=$2/g" .config
      else
        echo "$1=$2" >> .config
      fi
    fi
  }

fkardame's avatar
fkardame committed
  unset CFLAGS CXXFLAGS CPPFLAGS LDFLAGS
  if $_nonfoss != yes; then
      cd arm-trusted-firmware-${_tfaver}
      echo -e "\nBuilding FOSS TF-A for Pine64 PinePhone Pro...\n"
      make PLAT=rk3399    
      export BL31=../arm-trusted-firmware-${_tfaver}/build/rk3399/release/bl31/bl31.elf
      cd ../u-boot-${pkgver/rc/-rc}
      echo -e "\nusing Binary TF-A for Pine64 PinePhone Pro...\n"
      export BL31=../rk3399_bl31_v1.35.elf
      export ROCKCHIP_TPL=../rk3399_ddr_933MHz_v1.30.bin
      cd u-boot-${pkgver/rc/-rc}

  echo -e "\nBuilding U-Boot for Pine64 PinePhone Pro...\n"
fkardame's avatar
fkardame committed
  make pinephone-pro-rk3399_defconfig

  update_config 'CONFIG_IDENT_STRING' '" Manjaro Linux ARM"'
  update_config 'CONFIG_BOOTDELAY' '0'
Philip Müller's avatar
Philip Müller committed
  
  # Some DDR4 RAMs need training at 400 MHz to successfully boot
  update_config 'CONFIG_RAM_RK3399_LPDDR4' 'y'
fkardame's avatar
fkardame committed

  # Try a couple of SPI tweaks;  if actually needed, these options
  # will be propely moved to a PinePhone Pro configuration patch later
  update_config 'CONFIG_SPL_DM_SEQ_ALIAS' 'y'
  update_config 'CONFIG_SF_DEFAULT_BUS' '1'

Philip Müller's avatar
Philip Müller committed
  # Disable DMA for eMMC, to make suspend/resume work;  this option
  # will be propely moved to a PinePhone Pro configuration patch later
  update_config 'CONFIG_SPL_MMC_SDHCI_SDMA' 'n'

Philip Müller's avatar
Philip Müller committed
  # Add some settings from Megi
  [[ $_nonfoss != yes ]] && update_config 'CONFIG_ROCKCHIP_EXTERNAL_TPL' 'n'
Philip Müller's avatar
Philip Müller committed
  update_config 'CONFIG_SYS_USB_OHCI_MAX_ROOT_PORTS' '2'

fkardame's avatar
fkardame committed
  make EXTRAVERSION=-${pkgrel}
}

package() {
Philip Müller's avatar
Philip Müller committed
  cd u-boot-${pkgver/rc/-rc}
fkardame's avatar
fkardame committed

  install -D -m 0644 idbloader.img u-boot.itb -t "${pkgdir}/boot"
  install -D -m 0644 "${srcdir}/boot.txt" -t "${pkgdir}/boot"
  install -D -m 0755 "${srcdir}/ppp-uboot-mkscr" -t "${pkgdir}/usr/bin"
fkardame's avatar
fkardame committed

  install -D -m 0755 "${srcdir}/ppp-prepare-fstab" -t "${pkgdir}/usr/bin"
  install -D -m 0644 "${srcdir}/ppp-prepare-fstab.service" -t "${pkgdir}/usr/lib/systemd/system"
  install -D -m 0755 "${srcdir}/ppp-uboot-flash" -t "${pkgdir}/usr/bin"
  [[ $_nonfoss == yes ]] && install -m644 -Dt "${pkgdir}/usr/share/licenses/${pkgname}" \
  ${srcdir}/LICENSE.TXT