]> git.zerfleddert.de Git - m1-debian/blob - m1n1_uboot_kernel.sh
f9c39752b02c74456825206cefb7fa5717120af5
[m1-debian] / 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 unset LC_CTYPE
17 unset LANG
18
19 handle_crosscompile()
20 {
21 if [ "`uname -m`" != 'aarch64' ]; then
22 export ARCH=arm64
23 export CROSS_COMPILE=aarch64-linux-gnu-
24 sudo apt install -y libc6-dev-arm64-cross
25 fi
26 }
27
28 build_linux()
29 {
30 (
31 handle_crosscompile
32 test -d linux || git clone https://github.com/AsahiLinux/linux
33 cd linux
34 git fetch -a -t
35 git reset --hard origin/asahi-wip;
36 curl -sL https://tg.st/u/5ec32cdb6555bf935fd621ef8923410a1f51b5b9.patch | git am -
37 cat ../../config.txt > .config
38 make LLVM=${CLANG_VERSION} rustavailable
39 make LLVM=${CLANG_VERSION} olddefconfig
40 make -j `nproc` LLVM=${CLANG_VERSION} V=0 bindeb-pkg > /dev/null
41 )
42 }
43
44 build_m1n1()
45 {
46 (
47 test -d m1n1 || git clone --recursive https://github.com/AsahiLinux/m1n1
48 cd m1n1
49 git fetch -a -t
50 git reset --hard v1.2.7;
51 make -j `nproc`
52 )
53 }
54
55 build_uboot()
56 {
57 (
58 handle_crosscompile
59 test -d u-boot || git clone https://github.com/AsahiLinux/u-boot
60 cd u-boot
61 git fetch -a -t
62 git reset --hard asahi-v2023.01-3;
63 curl https://tg.st/u/0001-apple-Generate-EFI-boot-option-for-the-EFI-system-pa.patch | git am -
64
65 make apple_m1_defconfig
66 make -j `nproc`
67 )
68 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
69 }
70
71 package_boot_bin()
72 {
73 (
74 export M1N1_VERSION=1.2.7
75 rm -rf m1n1_${M1N1_VERSION}_arm64
76 mkdir -p m1n1_${M1N1_VERSION}_arm64/DEBIAN m1n1_${M1N1_VERSION}_arm64/usr/lib/m1n1/
77 cp u-boot.bin m1n1_${M1N1_VERSION}_arm64/usr/lib/m1n1/boot.bin
78 cat <<EOF > m1n1_${M1N1_VERSION}_arm64/DEBIAN/control
79 Package: m1n1
80 Version: $M1N1_VERSION
81 Section: base
82 Priority: optional
83 Architecture: arm64
84 Maintainer: Thomas Glanzmann <thomas@glanzmann.de>
85 Description: Apple silicon boot loader
86 Next to m1n1 this also contains the device trees and u-boot.
87 EOF
88
89 cat > m1n1_${M1N1_VERSION}_arm64/DEBIAN/postinst <<'EOF'
90 #!/bin/bash
91
92 export PATH=/bin
93 if [ -f /boot/efi/m1n1/boot.bin ]; then
94 cp /boot/efi/m1n1/boot.bin /boot/efi/m1n1/`date +%Y%m%d%H%M`.bin
95 fi
96 mkdir -p /boot/efi/m1n1/
97 cp /usr/lib/m1n1/boot.bin /boot/efi/m1n1/
98 EOF
99
100 chmod 755 m1n1_${M1N1_VERSION}_arm64/DEBIAN/postinst
101 dpkg-deb --build m1n1_${M1N1_VERSION}_arm64
102 )
103 }
104
105 if type clang-15; then
106 export CLANG_VERSION=-15
107 elif type clang-11; then
108 export CLANG_VERSION=-11
109 fi
110
111 mkdir -p build
112 cd build
113
114 build_linux
115 build_m1n1
116 build_uboot
117 package_boot_bin
Impressum, Datenschutz