]> git.zerfleddert.de Git - m1-debian/blame - bootstrap.sh
manual merge
[m1-debian] / bootstrap.sh
CommitLineData
aae6cdc3 1#!/usr/bin/env bash
2df410ee 2
605f3b2d
TG
3# SPDX-License-Identifier: MIT
4
aae6cdc3
TG
5set -o errexit
6set -o nounset
7set -o pipefail
8set -o xtrace
9
10cd "$(dirname "$0")"
2df410ee
TG
11
12unset LC_CTYPE
13unset LANG
14
0bffa1b0
TG
15export DEBOOTSTRAP=debootstrap
16
808831b6
TG
17<<<<<<< HEAD
18=======
0bffa1b0
TG
19handle_crosscompile()
20{
21 if [ "`uname -m`" != 'aarch64' ]; then
22 export ARCH=arm64
23 export CROSS_COMPILE=aarch64-linux-gnu-
24 export DEBOOTSTRAP=qemu-debootstrap
5aad5df2 25 sudo apt install -y libc6-dev-arm64-cross
0bffa1b0
TG
26 fi
27}
28
e4c546cc
TG
29build_linux()
30{
31(
0bffa1b0 32 handle_crosscompile
07fb90c7 33 test -d linux || git clone https://github.com/AsahiLinux/linux
e4c546cc 34 cd linux
826691d6 35 git fetch -a -t
8509d16f 36 git reset --hard asahi-6.1-rc8-3; git clean -f -x -d &> /dev/null
f804a5ec 37 cat ../../config-16k.txt > .config
e4c546cc 38 make olddefconfig
4f1af1fb 39 make -j `nproc` V=0 bindeb-pkg > /dev/null
e4c546cc
TG
40)
41}
42
5920ad39
TG
43build_m1n1()
44{
45(
9e30aad2 46 test -d m1n1 || git clone --recursive https://github.com/AsahiLinux/m1n1
5920ad39 47 cd m1n1
7cb0393c 48 git fetch -a -t
f2052d69 49 # https://github.com/AsahiLinux/PKGBUILDs/blob/main/m1n1/PKGBUILD
6a6e1b4d 50 git reset --hard v1.2.3; git clean -f -x -d &> /dev/null
9d00677c 51 make -j `nproc`
5920ad39
TG
52)
53}
54
55build_uboot()
56{
57(
0bffa1b0 58 handle_crosscompile
ec336431 59 test -d u-boot || git clone https://github.com/AsahiLinux/u-boot
5920ad39 60 cd u-boot
7cb0393c 61 git fetch -a -t
2a337eb9 62 # For tag, see https://github.com/AsahiLinux/PKGBUILDs/blob/main/uboot-asahi/PKGBUILD
f379dcd9 63 git reset --hard asahi-v2022.10-1; git clean -f -x -d &> /dev/null
f477e5ed 64 git revert --no-edit 4d2b02faf69eaddd0f73758ab26c456071bd2017
3aa6611d 65
5920ad39 66 make apple_m1_defconfig
9d00677c 67 make -j `nproc`
5920ad39
TG
68)
69
2726c310
TG
70 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
71 cat m1n1/build/m1n1.macho `find linux/arch/arm64/boot/dts/apple/ -name \*.dtb` <(gzip -c u-boot/u-boot-nodtb.bin) > u-boot.macho
ef13ce40 72 cp u-boot.bin 4k.bin
c034753e
TG
73 cp u-boot.bin 2k.bin
74 echo 'display=2560x1440' >> 2k.bin
ef13ce40 75 echo 'display=wait,3840x2160' >> 4k.bin
c034753e 76
5920ad39
TG
77}
78
808831b6 79>>>>>>> 0469ea3ee783f57bd1b368502d3286d96064e6e1
f325b48f 80build_rootfs()
ce8ebd75
TG
81{
82(
0bffa1b0 83 handle_crosscompile
350079f4 84 sudo rm -rf testing
ae43a6ec 85 mkdir -p cache
8b2a692f 86 sudo eatmydata ${DEBOOTSTRAP} --cache-dir=`pwd`/cache --arch=arm64 --include initramfs-tools,pciutils,wpasupplicant,tcpdump,vim,tmux,vlan,ntpdate,parted,curl,wget,grub-efi-arm64,mtr-tiny,dbus,ca-certificates,sudo,openssh-client,mtools,gdisk,cryptsetup testing testing http://deb.debian.org/debian
ce8ebd75 87
08045305
TG
88 export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
89
ce8ebd75
TG
90 cd testing
91
a6fc4794 92 sudo mkdir -p boot/efi
60b2ebc1 93
16cad30f 94 sudo bash -c 'echo debian > etc/hostname'
f325b48f 95
350079f4 96 sudo bash -c 'echo > etc/motd'
ce8ebd75 97
08045305
TG
98 sudo cp ../../files/sources.list etc/apt/sources.list
99 sudo cp ../../files/hosts etc/hosts
8d82f6b0 100 sudo cp ../../files/resolv.conf etc/resolv.conf
08045305 101 sudo cp ../../files/quickstart.txt root/
da7dd4b8 102 sudo cp ../../files/interfaces etc/network/interfaces
7a54df2e 103 sudo cp ../../files/wpa.conf etc/wpa_supplicant/wpa_supplicant.conf
b96f460f 104 sudo cp ../../files/rc.local etc/rc.local
ce8ebd75 105
f325b48f 106 sudo bash -c 'chroot . apt update'
0bffa1b0 107 sudo bash -c 'chroot . apt install -y firmware-linux'
ce8ebd75
TG
108
109 sudo -- perl -p -i -e 's/root:x:/root::/' etc/passwd
110
f325b48f 111 sudo -- ln -s lib/systemd/systemd init
ce8ebd75 112
08045305
TG
113 sudo cp ../${KERNEL} .
114 sudo chroot . dpkg -i ${KERNEL}
115 sudo rm ${KERNEL}
ce8ebd75 116
60cb512a 117 sudo bash -c 'chroot . apt-get clean'
ce8ebd75
TG
118)
119}
5920ad39 120
bca3e283 121build_live_stick()
f325b48f
TG
122{
123(
bca3e283
TG
124 rm -rf live-stick
125 mkdir -p live-stick/efi/boot live-stick/efi/debian/
f493aec2
TG
126 sudo cp ../files/wifi.pl testing/etc/rc.local
127 sudo bash -c 'cd testing; find . | cpio --quiet -H newc -o | pigz -9 > ../live-stick/initrd.gz'
bca3e283
TG
128 cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi live-stick/efi/boot/bootaa64.efi
129 cp testing/boot/vmlinuz* live-stick/vmlinuz
130 cp ../files/grub.cfg live-stick/efi/debian/grub.cfg
7a54df2e 131 (cd live-stick; tar cf ../asahi-debian-live.tar .)
f325b48f
TG
132)
133}
5920ad39 134
0ffed154
TG
135build_efi()
136{
137(
7da211a3 138 rm -rf EFI
60b2ebc1 139 mkdir -p EFI/boot EFI/debian
0ffed154
TG
140 cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi EFI/boot/bootaa64.efi
141
142 export INITRD=`ls -1 testing/boot/ | grep initrd`
143 export VMLINUZ=`ls -1 testing/boot/ | grep vmlinuz`
eb57d280 144 export UUID=`blkid -s UUID -o value media`
60b2ebc1 145 cat > EFI/debian/grub.cfg <<EOF
0ffed154 146search.fs_uuid ${UUID} root
60b2ebc1
TG
147linux (\$root)/boot/${VMLINUZ} root=UUID=${UUID} rw
148initrd (\$root)/boot/${INITRD}
0ffed154
TG
149boot
150EOF
151 tar czf efi.tgz EFI
152)
153}
154
5d41b6d6
TG
155build_asahi_installer_image()
156{
304bd206
TG
157(
158 rm -rf aii
1cf0f22b 159 mkdir -p aii/esp/m1n1
304bd206 160 cp -a EFI aii/esp/
1cf0f22b 161 cp u-boot.bin aii/esp/m1n1/boot.bin
304bd206
TG
162 ln media aii/media
163 cd aii
1cf0f22b 164 zip -r9 ../debian-base.zip esp media
304bd206 165)
5d41b6d6
TG
166}
167
3b4d866f 168publish_artefacts()
bb14d862
TG
169{
170 export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
171 cp ${KERNEL} k.deb
59b40e06 172 sudo cp efi.tgz asahi-debian-live.tar debian-base.zip /u/
bb14d862
TG
173}
174
08045305
TG
175mkdir -p build
176cd build
177
56d14923 178sudo apt-get install -y build-essential bash git locales gcc-aarch64-linux-gnu libc6-dev device-tree-compiler imagemagick ccache eatmydata debootstrap pigz libncurses-dev qemu-user-static binfmt-support rsync git flex bison bc kmod cpio libncurses5-dev libelf-dev:native libssl-dev dwarves
0bffa1b0 179
bc45a4cc 180build_linux
6859a054
TG
181build_m1n1
182build_uboot
183build_rootfs
6859a054
TG
184build_efi
185build_asahi_installer_image
186build_live_stick
f77f8aca 187publish_artefacts
Impressum, Datenschutz