# Omarchy's uboot-asahi: asahi-alarm's uboot-asahi (asahi-alarm/PKGBUILDs)
# with a silent console, no banner, no logo and no boot delay, so the Mac
# boots straight to the boot menu and the splash without U-Boot's text.
#
# Same name as asahi-alarm's, and nothing generic depends on it: it is only
# installed when named, or as an upgrade of an installed uboot-asahi.
# pacman takes a package from the first repository that carries its name:
# with [omarchy] ahead of [asahi-alarm] this build is installed and kept even
# after asahi-alarm moves on; with [asahi-alarm] ahead it is installed only as
# omarchy/uboot-asahi, kept over their build at the same pkgver, and replaced
# by a newer one. Keep pkgver and the patch set in step with asahi-alarm's and
# pkgrel above theirs. No epoch, which would outrank every future asahi-alarm
# release.

pkgname=uboot-asahi
_ver=2026.07
_asahirel=2

pkgver=${_ver}.asahi${_asahirel}
pkgrel=4
pkgdesc='U-Boot for Apple Silicon Macs (Omarchy build: silent console)'
_commit_id=asahi-v${_ver}-${_asahirel}
_srcname=u-boot-${_commit_id}
arch=('aarch64')
url='http://asahilinux.org'
license=('MIT' 'GPL2')
makedepends=( bc imagemagick )
source=(
  "u-boot-${_commit_id}.tar.gz::https://github.com/AsahiLinux/u-boot/archive/${_commit_id}.tar.gz"
  'disable-VBE-by-default.patch'
  'enable-bootmenu-by-default.patch'
  'uefi-distro-load-FDT-from-any-partition-on-boot-device.patch'
  'uefi-Add-all-options-for-EFI-System-Partitions.patch'
  'uefi-initial-find_fdt_location-for-finding-the-DT-on-disk.patch'
  'uefi-enable-SetVariableRT-with-volotile-storage.patch'
  'uefi-enable-https-boot-by-default.patch'
  'pylibfdt-Replace-removed-SWIG-Python-2-compatibility-macros.patch'
  'USB-PD-TCPM-improvements.patch'
  'rockchip-Enable-preboot-start-for-pci-usb.patch'
  'rockchip-rk3568-nanopi-r5-Drop-duplicated-extra-sdhc.patch'
  'rockchip-rk356x-Stop-overriding-sdhci-mmc-aliases.patch'
  'p3450-fix-board.patch'
  'JetsonTX2-Fix-upstream-device-tree-naming.patch'
  'Allwinner-fix-booting-on-a-number-of-devices.patch'
  'Fix-NVMe-not-only-on-Raspberry-Pi-5.patch'
  'raspberrypi-Add-quirk-for-RPi5-2Gb-rev-1.0.patch'
  'openssl-no-engine.patch'
  'quiet-console.patch'
)
sha256sums=('ff36bacdeb91c2bb911ce6fdd198fb1a943c47a6931f986cecd22443b04c1b06'
            '501fe48668729525520253228945dc728c9bf2d9f0a41744711ca51a060e9c7b'
            '9d1796f8c1492bb50c13f865b4bc6854f825218836e55ce36e348c4dd77caa74'
            '0f980cf61fab268a6aa2440408548d3874aee1de6eb6e3be291690b1d2eb6904'
            '16904a97fc62bba84bde3a18885156b8c202c366bb6a0e0dd54414c016695876'
            '32d966701ebd7675092c1fd991e2444a0a1d08d83a10f34c88e05a3c19b41834'
            'c77853d6c25b11b7ffca8d522e03bf8e1305b8637e27c5074ddeef3a22956bbf'
            'f9106baa633f742f7fff396b5335a9c0ead4fa7416cdfd2fea743c1da433960d'
            '1a152c1ddc46316ec94aa19be40b96e1e8bab71a82f1e11ca59c9f5ec86808a5'
            '3dd92f1f51fccfbb1ceae701db68a6ae42916ddc2d4645b3a61486b582721a54'
            '3ee57dcf7d36351de5905dadf41803cf2994bba40d77f4fe5e3fcd9131ddb54e'
            '064e51eabf34d04cfade37115d3fd76c4e8005973faf4dedf410f0b5bbd1ea18'
            '4aa93c1c3ae7fe20e844505d521b921b9649dae03b74ad847ebd6318f02f71a2'
            '9cf3e7694efd82a0fe6725069b12971a4f32d05e4e9862089cbf1779a7d2df7c'
            '77aff72eb2319d3a80e0ccb63bdfb7d1c503c91fb515acc9525d029b25bb1fdc'
            '0bb2e47484d67935f1ef6107433f51747211a143f549b4ba60081a143026fb22'
            '300ed1bd17136bed9ff2528dcdc029396e6c373c0606653dc7905625bb8511a7'
            'dbc08bd374f299d92fc0e9022e37a1629055675bc874a904c1eefe5fb9699e2f'
            '3ede37fd744d60d934a7d5186f0bcd13d67ae9a48d973283356bbe7451d337e4'
            '9c3db1a504c5eeac54fadb1dadb45ac5ea36316c39fadb73836102ac4bf125f0')
b2sums=('8041a979068ea00ac8402dcf35b34277907e497b2de060edf43a1960abddcfb5449d963334eb2a8c9f9a869452be55bf4c728dbda7c381892a145de72f3a59aa'
        '8fcba2b6c098125fc6ddee33b634af35bc6a8ae93c4f9cf3698f3f4455f97e22c6d8630c60776710770128f73377d2a9364c70dab6705707c1f3223e7493ce14'
        '79709278b47f8e21e7376031c3dc472070c5b18b29b48eefc9d3a4d97b69104eae9325ed8fff8e7a509a89727c8335c90345807d72afacee069557e46ff5724c'
        '34bebf1fe1126ff03d31abaca5908036268c231a77beebbe683cca3f80a4add12faf0e0ed27975c5fa1ba2a9994395ad0ee8115e9ecb8d3686975602981bf136'
        'b4ede5b7eced7a3459a169f5d49712647cc7cc3aec9935eea6283522245b6c3cc300ed8fb81be0dd942dddefd3bda49530270ec3f9215d2f9a52efa4c3bc5ba9'
        'b1cca3b2f31a1ab50f5fb637122d24593c23f99d773abba5a145d8701471dcb159de2bed937ea4a40b57501efb442c2ac5a2d49ab595f8b111320b11a182e710'
        '2a61869cdefd59715d8d860e4860d52a6e3fc33f2b8511c5d6f78c68f7dda00195b29bf9a213668a3eedf445958b923bc7051fc38c6965c3b7803266cae16bb2'
        '4bb6155f1db7a9df5e735cf353d5c1cc04525b5a2cd06fba93d3046a216a7210a6d0e1bf3e2deb07bbb58391d47804208e6e12b724000d68df9c5de5d2c52aae'
        'faa1ee756bda5714c31105b40fded40167c31d8458bc2b460dda06ad42fec60b7a71ed32a26fb036f744c8496641e3f271a39fd85f4de3ad86f1b8e9efec2dd1'
        '6cf5a8fe4631a60247df626e4fea6efadad4d2ccf62dd30330fa0a98546deee17a394d8b7fef8fa5446311f01c05a303f88818a4ffa6b49810c5ec06fae1aa46'
        '06c2d9f2d1b9285faf10245a325bb3937f6c98170f069e9517bf1662c0f3f4ea8499c911169c60e474a97c54b74d96297ccf0268edb0a3e602f7d0302668484d'
        '3905954cb92f54a9b1f479515a1f8b949b2692eeabad1955ec2c013bf920e2c79a2008408fc569f246c1184443baea4c96a63226cd32afd1149b681adb5b07d4'
        'ab734d11f811c467bad6e417700c67188dd82593e636172ac75f36aded39eea095b7a432ab7b4d377d4bb5e824a99592fb99017b7437b6f9bfeeb1cf962f35a6'
        '828275a8cdda2df5ef0698f12871cb24bcd758373d43907120495eb094fc1ddf6e25414384a52c56f2c5629a2b1702571fd368c02f1ae67ae25a2d59c0a850f3'
        '08bd592cc066e2dc9216228384a6c1d650860479ae3fa8fbe4ac0b6cf8596a25e5c11bbb52a19e3c35a4de279b4746e30e376ba4273f0121c2889d7ebc6a938d'
        'b018ec8f631f9ec15bb054f85b526fb4b4bb04b954ef9a038a6c9fd1230bbbb5af8d82b04d30c220820cb5f35c77ad1e3763835244da93486f3261fe12d1f06a'
        '338e2cd0b3e36f523ec7bbc59b91418fd5b6ec73588a510f488168a579de83d2b3978bb7ad641ed3a0a931e1e1555b43a2cd59f63da389545afca1579df4f256'
        'd63591d50862f07faf35e0adb52d73c669b4c29d046585878dcd4142faa049dd84088a9f21d34159f7103971b2b443d33f8a28ed77f4265f0e9d976bd66334f8'
        '81a2b3b089267d636cc60f23a0f4f82ba36ecb5e210c84c7cbdf2af1b764e0c40ba3b22fec26bc7c8eab052cfa30893aac4b3c76b9a56d763841b8f7821820de'
        '451006bb05bf4107347267dfb62b670d25d8991dcdb93c23221eca876bc8a2f9af7dc9e76e2c675aa44a34ef1a86deb00c128bf57f4096301f5a235ebfd69ca7')

prepare() {
  cd "${srcdir}/$_srcname"

  cat ../disable-VBE-by-default.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../enable-bootmenu-by-default.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../uefi-distro-load-FDT-from-any-partition-on-boot-device.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../uefi-Add-all-options-for-EFI-System-Partitions.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../uefi-initial-find_fdt_location-for-finding-the-DT-on-disk.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../uefi-enable-SetVariableRT-with-volotile-storage.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../uefi-enable-https-boot-by-default.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../pylibfdt-Replace-removed-SWIG-Python-2-compatibility-macros.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../USB-PD-TCPM-improvements.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../rockchip-Enable-preboot-start-for-pci-usb.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../rockchip-rk3568-nanopi-r5-Drop-duplicated-extra-sdhc.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../rockchip-rk356x-Stop-overriding-sdhci-mmc-aliases.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../p3450-fix-board.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../JetsonTX2-Fix-upstream-device-tree-naming.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../Allwinner-fix-booting-on-a-number-of-devices.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../Fix-NVMe-not-only-on-Raspberry-Pi-5.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../raspberrypi-Add-quirk-for-RPi5-2Gb-rev-1.0.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../openssl-no-engine.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f
  cat ../quiet-console.patch | patch -p1 -s --fuzz=0 --no-backup-if-mismatch -f

  make apple_m1_defconfig
  scripts/config --file .config \
    -e OF_UPSTREAM_BUILD_VENDOR \
    --set-str OF_UPSTREAM_VENDOR apple
  # Silent console: nothing on the panel or the serial port from U-Boot
  # itself (the banner, the environment load, the bootflow scan). The
  # environment's silent=1 applies from relocation on; the console stays
  # muted until that environment is read. The kernel's console is not
  # touched, and the U-Boot logo is not drawn. No boot delay: with nothing
  # shown there is nothing to interrupt.
  scripts/config --file .config \
    -e SILENT_CONSOLE \
    -e SILENT_CONSOLE_UPDATE_ON_SET \
    -e SILENT_CONSOLE_UPDATE_ON_RELOC \
    -e SILENT_CONSOLE_UNTIL_ENV \
    -e SILENT_U_BOOT_ONLY \
    -d VIDEO_LOGO \
    --set-val BOOTDELAY 0
  make olddefconfig
}

build() {
  cd "${srcdir}/$_srcname"
  make
}

package() {
  cd "${srcdir}"

  tgtdir="$pkgdir/usr/lib/asahi-boot"
  dtbdir="$_srcname/dts/upstream/src/arm64/apple"

  install -Dt "$tgtdir" -m644 "$_srcname/u-boot-nodtb.bin"
  install -d "$tgtdir/dtb"

  # Exclude known non-Apple-Silicon DT families:
  # t7000: A8-based iPhone 6 / 6 Plus
  # t7001: A8X-based iPad Air 2
  # t8010: A10-based iPhone 7 / 7 Plus, iPad 6 / 7, iPod touch 7
  # t8011: A10X-based Apple TV 4K (1st gen), iPad Pro 10.5 / 12.9 (2nd gen)
  # t8012: T2-based Intel Macs
  # t8015: A11-based iPhone 8 / 8 Plus / X
  find "$dtbdir" -maxdepth 1 -type f -name 't*.dtb' \
    ! -name 't7000-*.dtb' \
    ! -name 't7001-*.dtb' \
    ! -name 't8010-*.dtb' \
    ! -name 't8011-*.dtb' \
    ! -name 't8012-*.dtb' \
    ! -name 't8015-*.dtb' \
    -exec install -m644 -t "$tgtdir/dtb" {} +
}
