/ m1n1_uboot_kernel.sh
m1n1_uboot_kernel.sh
  1  #!/usr/bin/env bash
  2  
  3  # SPDX-License-Identifier: MIT
  4  
  5  set -o errexit
  6  set -o nounset
  7  set -o pipefail
  8  set -o xtrace
  9  
 10  cd "$(dirname "$0")"
 11  
 12  # export CARGO_HOME="$(pwd)/build/cargo"
 13  # export RUSTUP_HOME="$(pwd)/build/rust"
 14  # source "$(pwd)/build/cargo/env"
 15  
 16  export PATH=/usr/local/bin:/usr/local/bin:/usr/bin:/usr/bin:/sbin:/bin
 17  
 18  export CLANG_VERSION=-19
 19  
 20  unset LC_CTYPE
 21  unset LANG
 22  
 23  export KERNEL_VERSION=asahi-6.15.8-1
 24  export KERNEL_LOCALVERSION=-1-cy8aer0
 25  export M1N1_VERSION=1.4.14-cy8aer0
 26  export M1N1_GIT=v1.4.14
 27  
 28  handle_crosscompile()
 29  {
 30      if [ "`uname -m`" != 'aarch64' ]; then
 31          export ARCH=arm64
 32          export CROSS_COMPILE=aarch64-linux-gnu-
 33          sudo apt install -y libc6-dev-arm64-cross
 34      fi
 35  }
 36  
 37  build_linux()
 38  {
 39      (
 40  	handle_crosscompile
 41  	test -d linux || git clone https://github.com/AsahiLinux/linux
 42  	cd linux
 43  	git fetch -a -t
 44  	git fetch origin speakers/enablement-READ-COMMIT-MESSAGE
 45  	git reset --hard $KERNEL_VERSION;
 46  	cat ../../config.txt > .config
 47  	make LLVM=${CLANG_VERSION} rustavailable
 48  	make LLVM=${CLANG_VERSION} olddefconfig
 49  	cp .config ~/tmp/config
 50  	make -j `nproc` LLVM=${CLANG_VERSION} V=0 bindeb-pkg LOCALVERSION=$KERNEL_LOCALVERSION > /dev/null
 51      )
 52  }
 53  
 54  build_m1n1()
 55  {
 56      (
 57          test -d m1n1 || git clone --recursive https://github.com/AsahiLinux/m1n1
 58          cd m1n1
 59          git fetch -a -t
 60          git reset --hard $(M1N1_GIT);
 61          make -j `nproc`
 62      )
 63  }
 64  
 65  build_uboot()
 66  {
 67      (
 68          handle_crosscompile
 69          test -d u-boot || git clone https://github.com/AsahiLinux/u-boot
 70          cd u-boot
 71          git fetch -a -t
 72          git reset --hard asahi-v2025.04-1;  # asahi branch from 8. Jan. 2024, 19:51 MEZ
 73          patch -p1 <../../files/u-boot-bootmenu.patch
 74  	make clean
 75          make apple_m1_defconfig
 76          make -j `nproc`
 77      )
 78      cat m1n1/build/m1n1.bin   `find linux/arch/arm64/boot/dts/apple/ -name \*.dtb` <(gzip -c u-boot/u-boot-nodtb.bin) > u-boot.bin
 79  }
 80  
 81  package_u-boot-asahi()
 82  {
 83      {
 84  	export U_BOOT_VERSION=2025.04-1+cy8aer1
 85  	rm -rf u-boot-asahi_${U_BOOT_VERSION}_arm64
 86  	mkdir -p u-boot-asahi_${U_BOOT_VERSION}_arm64/usr/lib/u-boot-asahi/
 87  	mkdir -p u-boot-asahi_${U_BOOT_VERSION}_arm64/DEBIAN
 88  	cp u-boot/u-boot.bin u-boot-asahi_${U_BOOT_VERSION}_arm64/usr/lib/u-boot-asahi/u-boot.bin
 89  	cp u-boot/u-boot-nodtb.bin u-boot-asahi_${U_BOOT_VERSION}_arm64/usr/lib/u-boot-asahi/u-boot-nodtb.bin
 90  	cat <<EOF > u-boot-asahi_${U_BOOT_VERSION}_arm64/DEBIAN/control
 91  Package:     u-boot-asahi
 92  Version: $U_BOOT_VERSION
 93  Section: base
 94  Depends: asahi-scripts (>= 20230821-3)
 95  Priority: optional
 96  Architecture: arm64
 97  Maintainer: Thomas Renard <thomas.renard@g3la.de>
 98  Description: U-Boot boot loader Apple silicon
 99   This is the asahi version of u-boot with asahi patches.
100  EOF
101  
102  	cat > u-boot-asahi_${U_BOOT_VERSION}_arm64/DEBIAN/postinst <<'EOF'
103  #!/bin/bash
104  
105  export PATH=/bin
106  if [ -f /boot/efi/m1n1/boot.bin ]; then
107          cp /boot/efi/m1n1/boot.bin /boot/efi/m1n1/`date +%Y%m%d%H%M`.bin
108  fi
109  /usr/bin/update-m1n1
110  EOF
111  
112          chmod 755 u-boot-asahi_${U_BOOT_VERSION}_arm64/DEBIAN/postinst
113  
114  
115  	dpkg-deb --build u-boot-asahi_${U_BOOT_VERSION}_arm64
116      }
117  }
118  
119  package_m1n1()
120  {
121      (
122          rm -rf m1n1_${M1N1_VERSION}_arm64
123          mkdir -p m1n1_${M1N1_VERSION}_arm64/DEBIAN m1n1_${M1N1_VERSION}_arm64/usr/lib/m1n1/
124          cp u-boot.bin m1n1_${M1N1_VERSION}_arm64/usr/lib/m1n1/boot.bin
125          cp m1n1/build/m1n1.bin m1n1_${M1N1_VERSION}_arm64/usr/lib/m1n1/m1n1.bin
126          cat <<EOF > m1n1_${M1N1_VERSION}_arm64/DEBIAN/control
127  Package: m1n1
128  Version: $M1N1_VERSION
129  Section: base
130  Depends: asahi-scripts (>= 20231219.1-1)
131  Priority: optional
132  Architecture: arm64
133  Maintainer: Thomas Renard <thomas.renard@g3la.de>
134  Description: Apple silicon boot loader
135   Next to m1n1 this also contains the device trees and u-boot.
136  EOF
137  
138  
139          cat > m1n1_${M1N1_VERSION}_arm64/DEBIAN/postinst <<'EOF'
140  #!/bin/bash
141  
142  export PATH=/bin
143  if [ -f /boot/efi/m1n1/boot.bin ]; then
144          cp /boot/efi/m1n1/boot.bin /boot/efi/m1n1/`date +%Y%m%d%H%M`.bin
145  fi
146  /usr/bin/update-m1n1
147  EOF
148  
149          chmod 755 m1n1_${M1N1_VERSION}_arm64/DEBIAN/postinst
150  
151  	dpkg-deb --build m1n1_${M1N1_VERSION}_arm64
152      )
153  }
154  
155  
156  mkdir -p build
157  cd build
158  
159  build_linux
160  build_m1n1
161  build_uboot
162  # package_m1n1
163  package_u-boot-asahi