]> git.zerfleddert.de Git - m1-debian/blob - bootstrap.sh
apply jannaus sdcard empty patch
[m1-debian] / bootstrap.sh
1 #!/bin/bash
2
3 # SPDX-License-Identifier: MIT
4
5 set -x
6 set -e
7
8 unset LC_CTYPE
9 unset LANG
10
11 export DEBOOTSTRAP=debootstrap
12
13 handle_crosscompile()
14 {
15 if [ "`uname -m`" != 'aarch64' ]; then
16 export ARCH=arm64
17 export CROSS_COMPILE=aarch64-linux-gnu-
18 export DEBOOTSTRAP=qemu-debootstrap
19 fi
20 }
21
22 build_linux()
23 {
24 (
25 handle_crosscompile
26 test -d linux || git clone --depth 1 https://github.com/AsahiLinux/linux -b asahi
27 cd linux
28 git fetch
29 git reset --hard origin/asahi; git clean -f -x -d &> /dev/null
30 curl -s https://tg.st/u/40c9642c7569c52189f84621316fc9149979ee65.patch | git am -
31 curl -s https://tg.st/u/0001-4k-iommu-patch-2022-07-20.patch | git am -
32 curl -s https://tg.st/u/config-2022-07-19-4k.txt > .config
33 make olddefconfig
34 make -j `nproc` V=0 bindeb-pkg > /dev/null
35 )
36 }
37
38 build_m1n1()
39 {
40 (
41 test -d m1n1 || git clone --recursive https://github.com/AsahiLinux/m1n1
42 cd m1n1
43 git fetch
44 # https://github.com/AsahiLinux/PKGBUILDs/blob/main/m1n1/PKGBUILD
45 git reset --hard v1.1.3; git clean -f -x -d &> /dev/null
46 make -j `nproc`
47 )
48 }
49
50 build_uboot()
51 {
52 (
53 handle_crosscompile
54 test -d u-boot || git clone https://github.com/AsahiLinux/u-boot
55 cd u-boot
56 git fetch
57 # For tag, see https://github.com/AsahiLinux/PKGBUILDs/blob/main/uboot-asahi/PKGBUILD
58 git reset --hard asahi-v2022.07-2; git clean -f -x -d &> /dev/null
59 curl -s https://tg.st/u/0001-usb-storage-continue-probe-on-Invalid-device.patch | git am -
60 make apple_m1_defconfig
61 make -j `nproc`
62 )
63
64 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
65 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
66 cp u-boot.bin 4k.bin
67 cp u-boot.bin 2k.bin
68 echo 'display=2560x1440' >> 2k.bin
69 echo 'display=wait,3840x2160' >> 4k.bin
70
71 }
72
73 build_rootfs()
74 {
75 (
76 handle_crosscompile
77 sudo rm -rf testing
78 mkdir -p cache
79 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 testing testing http://deb.debian.org/debian
80
81 export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
82
83 cd testing
84
85 sudo mkdir -p boot/efi
86
87 sudo bash -c 'echo debian > etc/hostname'
88
89 sudo bash -c 'echo > etc/motd'
90
91 sudo cp ../../files/sources.list etc/apt/sources.list
92 sudo cp ../../files/hosts etc/hosts
93 sudo cp ../../files/resolv.conf etc/resolv.conf
94 sudo cp ../../files/quickstart.txt root/
95 sudo cp ../../files/interfaces etc/network/interfaces
96 sudo cp ../../files/wpa.conf etc/wpa_supplicant/wpa_supplicant.conf
97 sudo cp ../../files/rc.local etc/rc.local
98
99 sudo bash -c 'chroot . apt update'
100 sudo bash -c 'chroot . apt install -y firmware-linux'
101
102 sudo -- perl -p -i -e 's/root:x:/root::/' etc/passwd
103
104 sudo -- ln -s lib/systemd/systemd init
105
106 sudo cp ../${KERNEL} .
107 sudo chroot . dpkg -i ${KERNEL}
108 sudo rm ${KERNEL}
109
110 sudo bash -c 'chroot . apt-get clean'
111 )
112 }
113
114 build_live_stick()
115 {
116 (
117 rm -rf live-stick
118 mkdir -p live-stick/efi/boot live-stick/efi/debian/
119 sudo cp ../files/wifi.pl testing/etc/rc.local
120 sudo bash -c 'cd testing; find . | cpio --quiet -H newc -o | pigz -9 > ../live-stick/initrd.gz'
121 cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi live-stick/efi/boot/bootaa64.efi
122 cp testing/boot/vmlinuz* live-stick/vmlinuz
123 cp ../files/grub.cfg live-stick/efi/debian/grub.cfg
124 (cd live-stick; tar cf ../asahi-debian-live.tar .)
125 )
126 }
127
128 build_dd()
129 {
130 (
131 rm -f media
132 dd if=/dev/zero of=media bs=1 count=0 seek=2G
133 mkdir -p mnt
134 mkfs.ext4 media
135 tune2fs -O extents,uninit_bg,dir_index -m 0 -c 0 -i 0 media
136 sudo mount -o loop media mnt
137 sudo cp -a testing/* mnt/
138 sudo rm mnt/init
139 sudo umount mnt
140 tar cf - media | pigz -9 > m1.tgz
141 )
142 }
143
144 build_efi()
145 {
146 (
147 rm -rf EFI
148 mkdir -p EFI/boot EFI/debian
149 cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi EFI/boot/bootaa64.efi
150
151 export INITRD=`ls -1 testing/boot/ | grep initrd`
152 export VMLINUZ=`ls -1 testing/boot/ | grep vmlinuz`
153 export UUID=`blkid -s UUID -o value media`
154 cat > EFI/debian/grub.cfg <<EOF
155 search.fs_uuid ${UUID} root
156 linux (\$root)/boot/${VMLINUZ} root=UUID=${UUID} rw
157 initrd (\$root)/boot/${INITRD}
158 boot
159 EOF
160 tar czf efi.tgz EFI
161 )
162 }
163
164 build_asahi_installer_image()
165 {
166 (
167 rm -rf aii
168 mkdir -p aii/esp/m1n1
169 cp -a EFI aii/esp/
170 cp u-boot.bin aii/esp/m1n1/boot.bin
171 ln media aii/media
172 cd aii
173 zip -r9 ../debian-base.zip esp media
174 )
175 }
176
177 build_di_stick()
178 {
179 rm -rf di-stick
180 mkdir -p di-stick/efi/boot di-stick/efi/debian/
181 rm -f initrd.gz
182 wget https://d-i.debian.org/daily-images/arm64/daily/netboot/debian-installer/arm64/initrd.gz
183 sudo rm -rf initrd; mkdir initrd; (cd initrd; gzip -cd ../initrd.gz | sudo cpio -imd --quiet)
184 sudo rm -rf initrd/lib/modules/*
185 sudo cp -a testing/lib/modules/* initrd/lib/modules/
186 sudo cp ../files/wifi.sh initrd/
187 sudo cp ../files/boot.sh initrd/
188 (cd initrd; find . | cpio --quiet -H newc -o | pigz -9 > ../di-stick/initrd.gz)
189 sudo rm -rf initrd
190 cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi di-stick/efi/boot/bootaa64.efi
191 cp testing/boot/vmlinuz* di-stick/vmlinuz
192 cp ../files/grub.cfg di-stick/efi/debian/grub.cfg
193 export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
194 cp ${KERNEL} di-stick/
195 (cd di-stick; tar cf ../m1-d-i.tar .)
196 }
197
198 publish_artefacts()
199 {
200 export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
201 cp ${KERNEL} k.deb
202 sudo cp m1-d-i.tar m1.tgz efi.tgz asahi-debian-live.tar u-boot.bin u-boot.macho 2k.bin 4k.bin k.deb m1n1/build/m1n1.bin m1n1/build/m1n1.macho testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi debian-base.zip /u/
203 }
204
205 mkdir -p build
206 cd build
207
208 sudo apt-get install -y build-essential bash git locales gcc-aarch64-linux-gnu libc6-dev-arm64-cross 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
209
210 build_linux
211 build_m1n1
212 build_uboot
213 build_rootfs
214 #build_di_stick
215 build_dd
216 build_efi
217 build_asahi_installer_image
218 build_live_stick
219 publish_artefacts
Impressum, Datenschutz