]>
Commit | Line | Data |
---|---|---|
9ac5deac TG |
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 | ||
9eed8ca6 TG |
12 | export CARGO_HOME="$(pwd)/build/cargo" |
13 | export RUSTUP_HOME="$(pwd)/build/rust" | |
14 | source "$(pwd)/build/cargo/env" | |
15 | ||
9ac5deac TG |
16 | unset LC_CTYPE |
17 | unset LANG | |
18 | ||
6a1d2ed2 TG |
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 | ||
9ac5deac TG |
28 | build_linux() |
29 | { | |
30 | ( | |
6a1d2ed2 | 31 | handle_crosscompile |
9ac5deac TG |
32 | test -d linux || git clone https://github.com/AsahiLinux/linux |
33 | cd linux | |
34 | git fetch -a -t | |
74c7bd01 | 35 | git reset --hard asahi-6.4-9; |
7dcd418b | 36 | cat ../../config.txt > .config |
e7515ac0 TG |
37 | make LLVM=${CLANG_VERSION} rustavailable |
38 | make LLVM=${CLANG_VERSION} olddefconfig | |
39 | make -j `nproc` LLVM=${CLANG_VERSION} V=0 bindeb-pkg > /dev/null | |
9ac5deac TG |
40 | ) |
41 | } | |
42 | ||
43 | build_m1n1() | |
44 | { | |
45 | ( | |
46 | test -d m1n1 || git clone --recursive https://github.com/AsahiLinux/m1n1 | |
47 | cd m1n1 | |
48 | git fetch -a -t | |
74c7bd01 | 49 | git reset --hard v1.3.3; |
9ac5deac TG |
50 | make -j `nproc` |
51 | ) | |
52 | } | |
53 | ||
54 | build_uboot() | |
55 | { | |
56 | ( | |
6a1d2ed2 | 57 | handle_crosscompile |
9ac5deac TG |
58 | test -d u-boot || git clone https://github.com/AsahiLinux/u-boot |
59 | cd u-boot | |
60 | git fetch -a -t | |
983712fb | 61 | git reset --hard asahi-v2023.07.02-2; |
9ac5deac TG |
62 | |
63 | make apple_m1_defconfig | |
64 | make -j `nproc` | |
65 | ) | |
66 | 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 | |
9ac5deac TG |
67 | } |
68 | ||
ce492006 TG |
69 | package_boot_bin() |
70 | { | |
71 | ( | |
74c7bd01 | 72 | export M1N1_VERSION=1.3.3 |
59b40e06 TG |
73 | rm -rf m1n1_${M1N1_VERSION}_arm64 |
74 | mkdir -p m1n1_${M1N1_VERSION}_arm64/DEBIAN m1n1_${M1N1_VERSION}_arm64/usr/lib/m1n1/ | |
75 | cp u-boot.bin m1n1_${M1N1_VERSION}_arm64/usr/lib/m1n1/boot.bin | |
76 | cat <<EOF > m1n1_${M1N1_VERSION}_arm64/DEBIAN/control | |
ce492006 TG |
77 | Package: m1n1 |
78 | Version: $M1N1_VERSION | |
79 | Section: base | |
80 | Priority: optional | |
81 | Architecture: arm64 | |
82 | Maintainer: Thomas Glanzmann <thomas@glanzmann.de> | |
83 | Description: Apple silicon boot loader | |
84 | Next to m1n1 this also contains the device trees and u-boot. | |
85 | EOF | |
86 | ||
d201f029 | 87 | cat > m1n1_${M1N1_VERSION}_arm64/DEBIAN/postinst <<'EOF' |
ce492006 TG |
88 | #!/bin/bash |
89 | ||
90 | export PATH=/bin | |
b5a41dd1 TG |
91 | if [ -f /boot/efi/m1n1/boot.bin ]; then |
92 | cp /boot/efi/m1n1/boot.bin /boot/efi/m1n1/`date +%Y%m%d%H%M`.bin | |
93 | fi | |
94 | mkdir -p /boot/efi/m1n1/ | |
ce492006 TG |
95 | cp /usr/lib/m1n1/boot.bin /boot/efi/m1n1/ |
96 | EOF | |
97 | ||
59b40e06 TG |
98 | chmod 755 m1n1_${M1N1_VERSION}_arm64/DEBIAN/postinst |
99 | dpkg-deb --build m1n1_${M1N1_VERSION}_arm64 | |
cd6d1106 | 100 | ) |
ce492006 TG |
101 | } |
102 | ||
e7515ac0 TG |
103 | if type clang-15; then |
104 | export CLANG_VERSION=-15 | |
105 | elif type clang-11; then | |
106 | export CLANG_VERSION=-11 | |
107 | fi | |
108 | ||
9ac5deac TG |
109 | mkdir -p build |
110 | cd build | |
111 | ||
5a6d8c66 | 112 | build_linux |
029bb7dc TG |
113 | build_m1n1 |
114 | build_uboot | |
115 | package_boot_bin |