]> cvs.zerfleddert.de Git - m1-debian/blob - bootstrap.sh
manual merge
[m1-debian] / bootstrap.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 unset LC_CTYPE
13 unset LANG
14
15 export DEBOOTSTRAP=debootstrap
16
17 <<<<<<< HEAD
18 =======
19 handle_crosscompile()
20 {
21 if [ "`uname -m`" != 'aarch64' ]; then
22 export ARCH=arm64
23 export CROSS_COMPILE=aarch64-linux-gnu-
24 export DEBOOTSTRAP=qemu-debootstrap
25 sudo apt install -y libc6-dev-arm64-cross
26 fi
27 }
28
29 build_linux()
30 {
31 (
32 handle_crosscompile
33 test -d linux || git clone https://github.com/AsahiLinux/linux
34 cd linux
35 git fetch -a -t
36 git reset --hard asahi-6.1-rc8-3; git clean -f -x -d &> /dev/null
37 cat ../../config-16k.txt > .config
38 make olddefconfig
39 make -j `nproc` V=0 bindeb-pkg > /dev/null
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
49 # https://github.com/AsahiLinux/PKGBUILDs/blob/main/m1n1/PKGBUILD
50 git reset --hard v1.2.3; git clean -f -x -d &> /dev/null
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 # For tag, see https://github.com/AsahiLinux/PKGBUILDs/blob/main/uboot-asahi/PKGBUILD
63 git reset --hard asahi-v2022.10-1; git clean -f -x -d &> /dev/null
64 git revert --no-edit 4d2b02faf69eaddd0f73758ab26c456071bd2017
65
66 make apple_m1_defconfig
67 make -j `nproc`
68 )
69
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
72 cp u-boot.bin 4k.bin
73 cp u-boot.bin 2k.bin
74 echo 'display=2560x1440' >> 2k.bin
75 echo 'display=wait,3840x2160' >> 4k.bin
76
77 }
78
79 >>>>>>> 0469ea3ee783f57bd1b368502d3286d96064e6e1
80 build_rootfs()
81 {
82 (
83 handle_crosscompile
84 sudo rm -rf testing
85 mkdir -p cache
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
87
88 export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
89
90 cd testing
91
92 sudo mkdir -p boot/efi
93
94 sudo bash -c 'echo debian > etc/hostname'
95
96 sudo bash -c 'echo > etc/motd'
97
98 sudo cp ../../files/sources.list etc/apt/sources.list
99 sudo cp ../../files/hosts etc/hosts
100 sudo cp ../../files/resolv.conf etc/resolv.conf
101 sudo cp ../../files/quickstart.txt root/
102 sudo cp ../../files/interfaces etc/network/interfaces
103 sudo cp ../../files/wpa.conf etc/wpa_supplicant/wpa_supplicant.conf
104 sudo cp ../../files/rc.local etc/rc.local
105
106 sudo bash -c 'chroot . apt update'
107 sudo bash -c 'chroot . apt install -y firmware-linux'
108
109 sudo -- perl -p -i -e 's/root:x:/root::/' etc/passwd
110
111 sudo -- ln -s lib/systemd/systemd init
112
113 sudo cp ../${KERNEL} .
114 sudo chroot . dpkg -i ${KERNEL}
115 sudo rm ${KERNEL}
116
117 sudo bash -c 'chroot . apt-get clean'
118 )
119 }
120
121 build_live_stick()
122 {
123 (
124 rm -rf live-stick
125 mkdir -p live-stick/efi/boot live-stick/efi/debian/
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'
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
131 (cd live-stick; tar cf ../asahi-debian-live.tar .)
132 )
133 }
134
135 build_efi()
136 {
137 (
138 rm -rf EFI
139 mkdir -p EFI/boot EFI/debian
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`
144 export UUID=`blkid -s UUID -o value media`
145 cat > EFI/debian/grub.cfg <<EOF
146 search.fs_uuid ${UUID} root
147 linux (\$root)/boot/${VMLINUZ} root=UUID=${UUID} rw
148 initrd (\$root)/boot/${INITRD}
149 boot
150 EOF
151 tar czf efi.tgz EFI
152 )
153 }
154
155 build_asahi_installer_image()
156 {
157 (
158 rm -rf aii
159 mkdir -p aii/esp/m1n1
160 cp -a EFI aii/esp/
161 cp u-boot.bin aii/esp/m1n1/boot.bin
162 ln media aii/media
163 cd aii
164 zip -r9 ../debian-base.zip esp media
165 )
166 }
167
168 publish_artefacts()
169 {
170 export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
171 cp ${KERNEL} k.deb
172 sudo cp efi.tgz asahi-debian-live.tar debian-base.zip /u/
173 }
174
175 mkdir -p build
176 cd build
177
178 sudo 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
179
180 build_linux
181 build_m1n1
182 build_uboot
183 build_rootfs
184 build_efi
185 build_asahi_installer_image
186 build_live_stick
187 publish_artefacts
Impressum, Datenschutz