]> cvs.zerfleddert.de Git - m1-debian/blame - bootstrap.sh
prepare version dump with issues fixed Linus reported
[m1-debian] / bootstrap.sh
CommitLineData
2df410ee
TG
1#!/bin/bash
2
605f3b2d
TG
3# SPDX-License-Identifier: MIT
4
2df410ee
TG
5set -x
6set -e
7
8unset LC_CTYPE
9unset LANG
10
0bffa1b0
TG
11export DEBOOTSTRAP=debootstrap
12
13handle_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
e4c546cc
TG
22build_linux()
23{
24(
0bffa1b0 25 handle_crosscompile
8bc111cf 26 test -d linux || git clone --depth 1 https://github.com/AsahiLinux/linux -b asahi
e4c546cc
TG
27 cd linux
28 git fetch
8bc111cf 29 git reset --hard origin/asahi; git clean -f -x -d &> /dev/null
6620d516 30 curl -s https://tg.st/u/40c9642c7569c52189f84621316fc9149979ee65.patch | git am -
433c0730
TG
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
e4c546cc 33 make olddefconfig
4f1af1fb 34 make -j `nproc` V=0 bindeb-pkg > /dev/null
e4c546cc
TG
35)
36}
37
5920ad39
TG
38build_m1n1()
39{
40(
9e30aad2 41 test -d m1n1 || git clone --recursive https://github.com/AsahiLinux/m1n1
5920ad39
TG
42 cd m1n1
43 git fetch
9e30aad2 44 git reset --hard origin/main; git clean -f -x -d &> /dev/null
9d00677c 45 make -j `nproc`
5920ad39
TG
46)
47}
48
49build_uboot()
50{
51(
0bffa1b0 52 handle_crosscompile
0c225228 53 test -d u-boot || git clone --depth 1 https://github.com/AsahiLinux/u-boot
5920ad39 54 cd u-boot
d0071c0b 55 git fetch
d024d4c7 56 git reset --hard origin/asahi; git clean -f -x -d &> /dev/null
5920ad39 57 make apple_m1_defconfig
9d00677c 58 make -j `nproc`
5920ad39
TG
59)
60
2726c310
TG
61 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
62 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 63 cp u-boot.bin 4k.bin
c034753e
TG
64 cp u-boot.bin 2k.bin
65 echo 'display=2560x1440' >> 2k.bin
ef13ce40 66 echo 'display=wait,3840x2160' >> 4k.bin
c034753e 67
5920ad39
TG
68}
69
f325b48f 70build_rootfs()
ce8ebd75
TG
71{
72(
0bffa1b0 73 handle_crosscompile
350079f4 74 sudo rm -rf testing
ae43a6ec 75 mkdir -p cache
a636dc48 76 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
ce8ebd75 77
08045305
TG
78 export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
79
ce8ebd75
TG
80 cd testing
81
a6fc4794 82 sudo mkdir -p boot/efi
60b2ebc1 83
16cad30f 84 sudo bash -c 'echo debian > etc/hostname'
f325b48f 85
350079f4 86 sudo bash -c 'echo > etc/motd'
ce8ebd75 87
08045305
TG
88 sudo cp ../../files/sources.list etc/apt/sources.list
89 sudo cp ../../files/hosts etc/hosts
8d82f6b0 90 sudo cp ../../files/resolv.conf etc/resolv.conf
08045305 91 sudo cp ../../files/quickstart.txt root/
da7dd4b8 92 sudo cp ../../files/interfaces etc/network/interfaces
7a54df2e 93 sudo cp ../../files/wpa.conf etc/wpa_supplicant/wpa_supplicant.conf
b96f460f 94 sudo cp ../../files/rc.local etc/rc.local
ce8ebd75 95
f325b48f 96 sudo bash -c 'chroot . apt update'
0bffa1b0 97 sudo bash -c 'chroot . apt install -y firmware-linux'
ce8ebd75
TG
98
99 sudo -- perl -p -i -e 's/root:x:/root::/' etc/passwd
100
f325b48f 101 sudo -- ln -s lib/systemd/systemd init
ce8ebd75 102
08045305
TG
103 sudo cp ../${KERNEL} .
104 sudo chroot . dpkg -i ${KERNEL}
105 sudo rm ${KERNEL}
ce8ebd75 106
60cb512a 107 sudo bash -c 'chroot . apt-get clean'
ce8ebd75
TG
108)
109}
5920ad39 110
bca3e283 111build_live_stick()
f325b48f
TG
112{
113(
bca3e283
TG
114 rm -rf live-stick
115 mkdir -p live-stick/efi/boot live-stick/efi/debian/
f493aec2
TG
116 sudo cp ../files/wifi.pl testing/etc/rc.local
117 sudo bash -c 'cd testing; find . | cpio --quiet -H newc -o | pigz -9 > ../live-stick/initrd.gz'
bca3e283
TG
118 cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi live-stick/efi/boot/bootaa64.efi
119 cp testing/boot/vmlinuz* live-stick/vmlinuz
120 cp ../files/grub.cfg live-stick/efi/debian/grub.cfg
7a54df2e 121 (cd live-stick; tar cf ../asahi-debian-live.tar .)
f325b48f
TG
122)
123}
5920ad39 124
50ef4b20 125build_dd()
088368ea
TG
126{
127(
128 rm -f media
19e0ac3c 129 dd if=/dev/zero of=media bs=1 count=0 seek=2G
088368ea 130 mkdir -p mnt
743b1c81 131 mkfs.ext4 media
088368ea
TG
132 tune2fs -O extents,uninit_bg,dir_index -m 0 -c 0 -i 0 media
133 sudo mount -o loop media mnt
134 sudo cp -a testing/* mnt/
135 sudo rm mnt/init
136 sudo umount mnt
f493aec2 137 tar cf - media | pigz -9 > m1.tgz
088368ea
TG
138)
139}
140
0ffed154
TG
141build_efi()
142{
143(
7da211a3 144 rm -rf EFI
60b2ebc1 145 mkdir -p EFI/boot EFI/debian
0ffed154
TG
146 cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi EFI/boot/bootaa64.efi
147
148 export INITRD=`ls -1 testing/boot/ | grep initrd`
149 export VMLINUZ=`ls -1 testing/boot/ | grep vmlinuz`
eb57d280 150 export UUID=`blkid -s UUID -o value media`
60b2ebc1 151 cat > EFI/debian/grub.cfg <<EOF
0ffed154 152search.fs_uuid ${UUID} root
60b2ebc1
TG
153linux (\$root)/boot/${VMLINUZ} root=UUID=${UUID} rw
154initrd (\$root)/boot/${INITRD}
0ffed154
TG
155boot
156EOF
157 tar czf efi.tgz EFI
158)
159}
160
5d41b6d6
TG
161build_asahi_installer_image()
162{
304bd206
TG
163(
164 rm -rf aii
1cf0f22b 165 mkdir -p aii/esp/m1n1
304bd206 166 cp -a EFI aii/esp/
1cf0f22b 167 cp u-boot.bin aii/esp/m1n1/boot.bin
304bd206
TG
168 ln media aii/media
169 cd aii
1cf0f22b 170 zip -r9 ../debian-base.zip esp media
304bd206 171)
5d41b6d6
TG
172}
173
569d551a
TG
174build_di_stick()
175{
176 rm -rf di-stick
03d47296 177 mkdir -p di-stick/efi/boot di-stick/efi/debian/
de907bb6
TG
178 rm -f initrd.gz
179 wget https://d-i.debian.org/daily-images/arm64/daily/netboot/debian-installer/arm64/initrd.gz
03d47296
TG
180 sudo rm -rf initrd; mkdir initrd; (cd initrd; gzip -cd ../initrd.gz | sudo cpio -imd --quiet)
181 sudo rm -rf initrd/lib/modules/*
182 sudo cp -a testing/lib/modules/* initrd/lib/modules/
4acf5b00
TG
183 sudo cp ../files/wifi.sh initrd/
184 sudo cp ../files/boot.sh initrd/
f493aec2 185 (cd initrd; find . | cpio --quiet -H newc -o | pigz -9 > ../di-stick/initrd.gz)
03d47296
TG
186 sudo rm -rf initrd
187 cp testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi di-stick/efi/boot/bootaa64.efi
188 cp testing/boot/vmlinuz* di-stick/vmlinuz
189 cp ../files/grub.cfg di-stick/efi/debian/grub.cfg
7a54df2e
TG
190 export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
191 cp ${KERNEL} di-stick/
192 (cd di-stick; tar cf ../m1-d-i.tar .)
569d551a
TG
193}
194
3b4d866f 195publish_artefacts()
bb14d862
TG
196{
197 export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
198 cp ${KERNEL} k.deb
c034753e 199 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/
bb14d862
TG
200}
201
08045305
TG
202mkdir -p build
203cd build
204
7cf1e21d 205sudo 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
0bffa1b0 206
bc45a4cc 207build_linux
6859a054
TG
208build_m1n1
209build_uboot
210build_rootfs
793f7339 211#build_di_stick
6859a054
TG
212build_dd
213build_efi
214build_asahi_installer_image
215build_live_stick
f77f8aca 216publish_artefacts
Impressum, Datenschutz