From 6d0fe4b9202fed64414f8891ec99e37117affedf Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Wed, 16 Mar 2022 16:02:53 +0100
Subject: [PATCH 01/16] document chainloading

---
 bootstrap.sh  | 21 +++++++++++----------
 doc/notes.txt |  3 +++
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/bootstrap.sh b/bootstrap.sh
index 58661ad..97a39ff 100644
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -29,7 +29,8 @@ build_linux()
         git reset --hard origin/asahi; git clean -f -x -d &> /dev/null
         curl -s https://tg.st/u/40c9642c7569c52189f84621316fc9149979ee65.patch | git am -
         curl -s https://tg.st/u/0001-4k-iommu-patch-2022-03-11.patch | git am -
-        curl -s https://tg.st/u/config-2022-03-15-4k > .config
+        # curl -s https://tg.st/u/config-2022-03-15-4k > .config
+        curl -s https://tg.st/u/config-debian-distro-kernel-2022-03-09-4k > .config
         make olddefconfig
         make -j `nproc` V=0 bindeb-pkg > /dev/null
 )
@@ -200,12 +201,12 @@ cd build
 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
 
 build_linux
-build_m1n1
-build_uboot
-build_rootfs
-build_di_stick
-build_dd
-build_efi
-build_asahi_installer_image
-build_live_stick
-publish_artefacts
+# build_m1n1
+# build_uboot
+# build_rootfs
+# build_di_stick
+# build_dd
+# build_efi
+# build_asahi_installer_image
+# build_live_stick
+# publish_artefacts
diff --git a/doc/notes.txt b/doc/notes.txt
index 8f26397..39bcf1c 100644
--- a/doc/notes.txt
+++ b/doc/notes.txt
@@ -390,3 +390,6 @@ ctl.!default {
 
 07:19 < chadmed> Glanzmann: https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/2210
 07:47 < chadmed> pushed some changes to asahi-audio, should sound better than it did before now. FIRs are also installed to the directory i proposed in the feature request
+
+15:49 < j`ey> https://github.com/AsahiLinux/asahi-installer/blob/main/src/osinstall.py#L141
+15:49 < j`ey> cat m1n1.bin <(echo 'chainload=$ESP_UUID;$BOOT_OBJ_PATH') > blah.bin
-- 
2.39.5


From c8171eb601c978cbd829adab8c354cefdc387a82 Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Wed, 16 Mar 2022 16:45:29 +0100
Subject: [PATCH 02/16] more notes

---
 doc/notes.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/notes.txt b/doc/notes.txt
index 39bcf1c..1e11ecb 100644
--- a/doc/notes.txt
+++ b/doc/notes.txt
@@ -393,3 +393,5 @@ ctl.!default {
 
 15:49 < j`ey> https://github.com/AsahiLinux/asahi-installer/blob/main/src/osinstall.py#L141
 15:49 < j`ey> cat m1n1.bin <(echo 'chainload=$ESP_UUID;$BOOT_OBJ_PATH') > blah.bin
+
+16:43 < povik> marcan: two fixes on top of 'asahi' that should make it into the release: https://github.com/povik/linux/commits/asahi-fixes
-- 
2.39.5


From dbe80fbaa772cbd46fc8d08be4e410d2f2036861 Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Wed, 16 Mar 2022 16:46:03 +0100
Subject: [PATCH 03/16] more notes

---
 doc/notes.txt | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/doc/notes.txt b/doc/notes.txt
index 1e11ecb..ccddce8 100644
--- a/doc/notes.txt
+++ b/doc/notes.txt
@@ -395,3 +395,11 @@ ctl.!default {
 15:49 < j`ey> cat m1n1.bin <(echo 'chainload=$ESP_UUID;$BOOT_OBJ_PATH') > blah.bin
 
 16:43 < povik> marcan: two fixes on top of 'asahi' that should make it into the release: https://github.com/povik/linux/commits/asahi-fixes
+
+# Manually install m1n1 in chainloading mode:
+# boot into 1tr
+diskutil list
+diskutil info <identifier of esp>
+curl -sLo tg.st/u/m1n1-rust.bin
+cat m1n1-rust.bin <(echo 'chainload=<Partition UUID>;m1n1/boot.bin') > object.bin
+kmutil configure-boot -c object.bin --raw --entry-point 2048 --lowest-virtual-address 0 -v /Volumes/Linux
-- 
2.39.5


From 7f82212ff6c112055927086f5f734ebea39ffb24 Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Wed, 16 Mar 2022 20:40:35 +0100
Subject: [PATCH 04/16] insight from jannau

---
 doc/notes.txt | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/doc/notes.txt b/doc/notes.txt
index ccddce8..dbbdaa3 100644
--- a/doc/notes.txt
+++ b/doc/notes.txt
@@ -403,3 +403,10 @@ diskutil info <identifier of esp>
 curl -sLo tg.st/u/m1n1-rust.bin
 cat m1n1-rust.bin <(echo 'chainload=<Partition UUID>;m1n1/boot.bin') > object.bin
 kmutil configure-boot -c object.bin --raw --entry-point 2048 --lowest-virtual-address 0 -v /Volumes/Linux
+
+20:29 < Glanzmann> One question though what is difference between chosen.asahi,efi-system-partition=EFI-PARTITION-PARTUUID and chainload=EFI-PARTITION-PARTUUID;m1n1/boot.bin?
+20:30 < jannau> chainload tell's the 1st stage m1n1 from where to load the second stage
+20:31 < jannau> chosen.asahi,efi-system-partition is added to the dt mostly to allow u-boot to boot from the correct ESP
+20:32 < Glanzmann> I see. Thank you for the elaboration.
+20:32 < jannau> chosen.asahi,efi-system-partition is passed from the 1st stage forward to the second stage
+20:33 < Glanzmann> I see, so the first stage informs the second stage about the uuid of the esp partition which is than passed using dt to u-boot which can than select the right esp to select the efi binary.
-- 
2.39.5


From 2726c310bf41a97245abcfb1e8cea91cc2a51e4e Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Wed, 16 Mar 2022 20:43:25 +0100
Subject: [PATCH 05/16] Note that U-Boot is compressed before appending.
 Uncompressed kernels may cause issues with variables getting lost, since
 their size cannot be accurately determined.

---
 bootstrap.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bootstrap.sh b/bootstrap.sh
index 97a39ff..4a8ef80 100644
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -59,8 +59,8 @@ build_uboot()
         make -j `nproc`
 )
 
-        cat m1n1/build/m1n1.bin   `find linux/arch/arm64/boot/dts/apple/ -name \*.dtb` u-boot/u-boot-nodtb.bin > u-boot.bin
-        cat m1n1/build/m1n1.macho `find linux/arch/arm64/boot/dts/apple/ -name \*.dtb` u-boot/u-boot-nodtb.bin > u-boot.macho
+        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
+        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
 }
 
 build_rootfs()
-- 
2.39.5


From 612569c3a76770d75a8da4c7c38a62d69fd47785 Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Wed, 16 Mar 2022 20:44:12 +0100
Subject: [PATCH 06/16] distro kernel config is not yet working due to missing
 usb

---
 bootstrap.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/bootstrap.sh b/bootstrap.sh
index 4a8ef80..5240777 100644
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -29,8 +29,8 @@ build_linux()
         git reset --hard origin/asahi; git clean -f -x -d &> /dev/null
         curl -s https://tg.st/u/40c9642c7569c52189f84621316fc9149979ee65.patch | git am -
         curl -s https://tg.st/u/0001-4k-iommu-patch-2022-03-11.patch | git am -
-        # curl -s https://tg.st/u/config-2022-03-15-4k > .config
-        curl -s https://tg.st/u/config-debian-distro-kernel-2022-03-09-4k > .config
+        curl -s https://tg.st/u/config-2022-03-15-4k > .config
+        # curl -s https://tg.st/u/config-debian-distro-kernel-2022-03-09-4k > .config
         make olddefconfig
         make -j `nproc` V=0 bindeb-pkg > /dev/null
 )
-- 
2.39.5


From 6859a05464757427709d99deda07223e379d1296 Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Wed, 16 Mar 2022 20:44:35 +0100
Subject: [PATCH 07/16] enable all build targets

---
 bootstrap.sh | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/bootstrap.sh b/bootstrap.sh
index 5240777..e1ed0a9 100644
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -201,12 +201,12 @@ cd build
 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
 
 build_linux
-# build_m1n1
-# build_uboot
-# build_rootfs
-# build_di_stick
-# build_dd
-# build_efi
-# build_asahi_installer_image
-# build_live_stick
-# publish_artefacts
+build_m1n1
+build_uboot
+build_rootfs
+build_di_stick
+build_dd
+build_efi
+build_asahi_installer_image
+build_live_stick
+publish_artefacts
-- 
2.39.5


From ce51ec1f93229813219c5bbd50636529cece6e04 Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Wed, 16 Mar 2022 21:49:39 +0100
Subject: [PATCH 08/16] fix instructions for future u-boot boot-chain

---
 doc/notes.txt | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/doc/notes.txt b/doc/notes.txt
index dbbdaa3..7652f17 100644
--- a/doc/notes.txt
+++ b/doc/notes.txt
@@ -396,12 +396,11 @@ ctl.!default {
 
 16:43 < povik> marcan: two fixes on top of 'asahi' that should make it into the release: https://github.com/povik/linux/commits/asahi-fixes
 
-# Manually install m1n1 in chainloading mode:
 # boot into 1tr
 diskutil list
 diskutil info <identifier of esp>
 curl -sLo tg.st/u/m1n1-rust.bin
-cat m1n1-rust.bin <(echo 'chainload=<Partition UUID>;m1n1/boot.bin') > object.bin
+cat m1n1-rust.bin <(echo 'chainload=<ESP Partition UUID>;m1n1/boot.bin') <(echo 'chosen.asahi,efi-system-partition=<ESP Parition UUID>') > object.bin
 kmutil configure-boot -c object.bin --raw --entry-point 2048 --lowest-virtual-address 0 -v /Volumes/Linux
 
 20:29 < Glanzmann> One question though what is difference between chosen.asahi,efi-system-partition=EFI-PARTITION-PARTUUID and chainload=EFI-PARTITION-PARTUUID;m1n1/boot.bin?
-- 
2.39.5


From 800e7640f20392a312c2a1513b3248a4116f2aab Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Thu, 17 Mar 2022 16:07:59 +0100
Subject: [PATCH 09/16] di stick is missing again

---
 bootstrap.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/bootstrap.sh b/bootstrap.sh
index e1ed0a9..b551e19 100644
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -204,7 +204,7 @@ build_linux
 build_m1n1
 build_uboot
 build_rootfs
-build_di_stick
+# build_di_stick
 build_dd
 build_efi
 build_asahi_installer_image
-- 
2.39.5


From 8837532b0d117c3b2f98984b8fb3f154cdfca731 Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Thu, 17 Mar 2022 16:45:51 +0100
Subject: [PATCH 10/16] add notes how to cleanup from speaker setup

---
 doc/notes.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/notes.txt b/doc/notes.txt
index 7652f17..aebfd3c 100644
--- a/doc/notes.txt
+++ b/doc/notes.txt
@@ -191,6 +191,8 @@ exec /bin/bash
 21:56 < povik> that mode of playing in parallel through the speakers and jack has a defect
 21:57 < povik> there's noise mixed-in then, at a period
 21:57 < povik> don't know how that happens yet
+When disabling the speakers, run rm -rf ~/.config/pulse/ and reboot otherwise the jack will be in the future off or 100% (which is too loud).
+
 
 If you see this in Xorg.0.log, it means that simpledrm has not initialized.
 ...
-- 
2.39.5


From 03e35824b3ecad0a992255fd24d402da2909a257 Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Thu, 17 Mar 2022 21:30:36 +0100
Subject: [PATCH 11/16] add missing kernel config option for usb-c

---
 patch_kernel_config.pl | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/patch_kernel_config.pl b/patch_kernel_config.pl
index 3c08b36..782977f 100644
--- a/patch_kernel_config.pl
+++ b/patch_kernel_config.pl
@@ -59,6 +59,7 @@ my %asahi_options = (
         'CONFIG_FB_EFI' => 'y',
         'CONFIG_BACKLIGHT_CLASS_DEVICE' => 'y',
         'CONFIG_BACKLIGHT_GPIO' => 'm',
+        'CONFIG_TYPEC_TPS6598X' => 'y',
 );
 
 my %debian_options;
@@ -70,13 +71,18 @@ for (@lines) {
 }
 
 for my $o (keys %asahi_options) {
-        if (not exists $debian_options{$o}) {
+        if ((not exists $debian_options{$o}) && $asahi_options{$o} ne 'n') {
                 print "$o missing, adding\n";
                 $debian_options{$o} = $asahi_options{$o};
+        } elsif ((exists $debian_options{$o}) && ($asahi_options{$o} eq 'n')) {
+                print "$o present, removing\n";
+                delete $debian_options{$o};
+        } elsif ((exists $asahi_options{$o} && exists $debian_options{$o}) && ($debian_options{$o} ne $asahi_options{$o})) {
+                print "$o different\n";
         }
 }
 
-open(CONFIG, '>', 'config') || die;
+open(CONFIG, '>', 'config.new') || die;
 for (keys %debian_options) {
         print CONFIG $_ . '=' . $debian_options{$_} . "\n";
 }
-- 
2.39.5


From 6e2c42070d8013bd187757aae4c753ca80643729 Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Thu, 17 Mar 2022 22:30:10 +0100
Subject: [PATCH 12/16] using debian distro kernel

---
 bootstrap.sh | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/bootstrap.sh b/bootstrap.sh
index b551e19..44f27be 100644
--- a/bootstrap.sh
+++ b/bootstrap.sh
@@ -29,8 +29,7 @@ build_linux()
         git reset --hard origin/asahi; git clean -f -x -d &> /dev/null
         curl -s https://tg.st/u/40c9642c7569c52189f84621316fc9149979ee65.patch | git am -
         curl -s https://tg.st/u/0001-4k-iommu-patch-2022-03-11.patch | git am -
-        curl -s https://tg.st/u/config-2022-03-15-4k > .config
-        # curl -s https://tg.st/u/config-debian-distro-kernel-2022-03-09-4k > .config
+        curl -s https://tg.st/u/config-2022-03-17-distro-sven-jannau.txt > .config
         make olddefconfig
         make -j `nproc` V=0 bindeb-pkg > /dev/null
 )
@@ -192,7 +191,7 @@ publish_artefacts()
 {
         export KERNEL=`ls -1rt linux-image*.deb | grep -v dbg | tail -1`
         cp ${KERNEL} k.deb
-        sudo cp m1-d-i.tar m1.tgz efi.tgz asahi-debian-live.tar u-boot.bin u-boot.macho di-stick/vmlinuz k.deb m1n1/build/m1n1.bin m1n1/build/m1n1.macho testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi debian-base.zip /u/
+        sudo cp m1-d-i.tar m1.tgz efi.tgz asahi-debian-live.tar u-boot.bin u-boot.macho k.deb m1n1/build/m1n1.bin m1n1/build/m1n1.macho testing/usr/lib/grub/arm64-efi/monolithic/grubaa64.efi debian-base.zip /u/
 }
 
 mkdir -p build
@@ -204,7 +203,7 @@ build_linux
 build_m1n1
 build_uboot
 build_rootfs
-# build_di_stick
+# build_di_stick - Debian failed to upload the initrd.gz
 build_dd
 build_efi
 build_asahi_installer_image
-- 
2.39.5


From 77431dc9424ba4049e8acd401d5743b198e41d5c Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Fri, 18 Mar 2022 16:04:56 +0100
Subject: [PATCH 13/16] add quickstart for iwd

---
 files/quickstart.txt | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/files/quickstart.txt b/files/quickstart.txt
index 93b1d76..c93706a 100644
--- a/files/quickstart.txt
+++ b/files/quickstart.txt
@@ -126,3 +126,34 @@ mv /mnt/initrd.gz /mnt/initrd.old
 cd /
 find . -xdev | cpio --quiet -H newc -o | pigz -9 > /mnt/initrd.gz
 umount /mnt
+
+iwd
+===
+With iwd you can force to use 5ghz. The following needs to be done to get iwd
+running.
+
+sudo apt-get install iwd
+
+cat <<EOF > /etc/iwd/main.conf
+[Rank]
+        BandModifier5Ghz=10
+EOF
+
+# Remove or comment out the following interfaces from /etc/network/interfaces
+# allow-hotplug wlp1s0f0
+# iface wlp1s0f0 inet dhcp
+#         wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
+
+# Add the following interfaces to /etc/network/interfaces
+allow-hotplug wlan0
+iface wlan0 inet dhcp
+
+# Reboot
+reboot
+
+# Configure iwd:
+sudo iwctl
+device list
+station wlan0 scan
+station wlan0 get-networks
+station wlan0 connect SSID
-- 
2.39.5


From 49e0d4d9b9c2e03b06a570fc0b5c380e4ccf0ca1 Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Fri, 18 Mar 2022 16:16:13 +0100
Subject: [PATCH 14/16] improve quickstart

---
 files/quickstart.txt | 176 +++++++++++++++++++++++++++++--------------
 1 file changed, 120 insertions(+), 56 deletions(-)

diff --git a/files/quickstart.txt b/files/quickstart.txt
index c93706a..0e701a6 100644
--- a/files/quickstart.txt
+++ b/files/quickstart.txt
@@ -1,45 +1,47 @@
-# grow the root partition
-sgdisk -n 0:0
-
-# grow root filesystem
-lsblk
-resize2fs /dev/nvme0n1pX
+Set root password
+=================
+passwd
+pwconv
+
+Configure wifi
+==============
+vi /etc/wpa/wpa_supplicant.conf
+ifup wlp1s0f0
+# remove the '#' before allow-hotplug to let wifi come up after boot
+vi /etc/network/interfaces
 
-# Ethernet
-ip l s
-dhclient <device>
+Install openssh
+===============
+# Login for root is disabled by default. So you need another user
+sudo apt update
+sudo apt install -y openssh-server
 
-# Wifi
-rmmod brcmfmac
-rmmod brcmutil
-mount /dev/sda1 /mnt
-tar -C /lib/firmware/ -xf /mnt/linux-firmware.tar
-umount /mnt
-modprobe brcmfmac
-vim /etc/wpa_supplicant/wpa_supplicant.conf
-wpa_supplicant -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf
-dhclient wlan0
+Configure timezone
+==================
+dpkg-reconfigure tzdata
 
-# Time
-ntpdate pool.ntp.org
-date --set 2022-01-25
-date --set 14:21
+Create a user
+=============
+useradd -m -c 'firstname lastname' -s /bin/bash username
+passwd username
 
-# Configure timezone
-dpkg-reconfigure tzdata
+Lightweight desktop
+===================
+apt-get install lightdm blackbox xterm firefox-esr
+/etc/init.d/lightdm start
 
-# Fix grub
-# We deinstall grub-efi-arm64-signed- because it creates a file fbaa64.efi
-# which makes u-boot hang.
-apt-get install grub-efi grub-efi-arm64-signed-
-grub-install --target=arm64-efi --efi-directory=/boot/efi --removable
-update-grub
-# Set removable media to yes and nvram to no to make later grub updates work
-dpkg-reconfigure grub-efi-arm64
+Install gnome
+=============
+apt-get install gnome
+/etc/init.d/gdm3 start
 
-See also: https://github.com/AsahiLinux/docs/wiki/U-Boot
+Disable sleep, hibernate and suspend targets
+============================================
+# asahi does not handle sleep well at the moment
+sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
 
-# xorg
+Xorg
+====
 
 # Keyboard use capslock as additional ctrl
 cat > /etc/X11/xorg.conf.d/00-keyboard.conf <<'EOF'
@@ -78,38 +80,100 @@ Section "InputClass"
 EndSection
 EOF
 
-# Create a user
-useradd -m -c 'firstname lastname' -s /bin/bash username
-passwd username
 
-# Lightweight desktop
-apt-get install lightdm blackbox xterm firefox-esr
+Install latest kernel and m1n1 stage 2 (m1n1, dtbs, u-boot)
+===========================================================
+curl -sL tg.st/u/ksh | sudo bash
 
-# Install gnome
-apt-get install gnome
-/etc/init.d/gdm3 start
+Use the live system to install debian
+=====================================
 
-# If you need to install the kernel on a bootstrapped system or one that needs recovery
-wget https://tg.st/u/k.deb
-dpkg -i k.deb
+parted -a optimal /dev/nvme0n1 print free
+parted -a optimal /dev/nvme0n1 mkpart primary ext4 <begin of free> <end of free>
+tune2fs -O extents,uninit_bg,dir_index -m 0 -c 0 -i 0 /dev/nvme0n1p5
 
-# asahi does not handle sleep well at the moment
-sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
+mount /dev/nvme0n1p5 /mnt
 
-- You can also use the live system to install Debian on the m1, the rough outline is:
+debootstrap --arch=arch64 testing /mnt http://deb.debian.org/debian
 
-        - Create two paritions:
+mount -t sysfs none /mnt/sys
+mount -t efivarfs none /mnt/sys/firmware/efi/efivars
+mount -t proc none /mnt/proc
+mount -o bind /dev /mnt/dev
+mount -o bind /dev/pts /mnt/dev/pts
 
-                - One 1 GB vfat
-                - Rest with ext4
+mkdir -p /mnt/boot/efi
+mount /dev/nvme0n1p4 /mnt/boot/efi
 
-        - Use debootstrap to bootstrap debian
+cd /mnt
+chroot . bin/bash
 
-        - Install the kernel
+cat <<EOF > /etc/fstab
+/dev/nvme0n1p5 /         ext4 defaults 0 0
+/dev/nvme0n1p4 /boot/efi vfat defaults 0 0
+EOF
 
-        - Install grub
+cat <<EOF > /etc/apt/sources.list
+deb http://ftp.debian.org/debian testing main contrib non-free
+deb-src http://ftp.debian.org/debian testing main contrib non-free
+EOF
+
+apt update
+apt-get -y install 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
+
+apt-get install -y grub-efi-arm64-signed-
+echo 'grub-efi-arm64 grub2/update_nvram boolean false' | debconf-set-selections
+echo 'grub-efi-arm64 grub2/force_efi_extra_removable boolean true' | debconf-set-selections
+dpkg-reconfigure -fnoninteractive grub-efi-arm64
+update-grub
+grub-install --removable /boot/efi
+
+echo 'nameserver 8.8.8.8' > /etc/resolv.conf
+
+export HOSTNAME=debian
+echo $HOSTNAME > /etc/hostname
+cat <<EOF > /etc/hosts
+127.0.0.1 localhost $HOSTNAME
+EOF
+
+cat <<EOF > /etc/wpa_supplicant/wpa_supplicant.conf
+network={
+        ssid="ssid"
+        scan_ssid=1
+        key_mgmt=WPA-PSK
+        psk="password"
+}
+EOF
+
+tar -C /lib/firmware/ -xf /boot/efi/vendorfw/firmware.tar
 
-        - reboot
+cat <<EOF > /etc/network/interfaces
+# interfaces(5) file used by ifup(8) and ifdown(8)
+# Include files from /etc/network/interfaces.d:
+source /etc/network/interfaces.d/*
+
+allow-hotplug enp3s0
+iface enp3s0 inet dhcp
+
+# allow-hotplug wlp1s0f0
+iface wlp1s0f0 inet dhcp
+        wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
+EOF
+
+curl -sLo /tmp/k.deb tg.st/u/k.deb
+curl -sLo /boot/efi/m1n1/boot.bin tg.st/u/u-boot.bin
+dpkg -i /tmp/k.deb
+
+exit
+
+cd /
+umount /mnt/boot/efi
+umount /mnt/sys
+umount /mnt/proc
+umount /mnt/dev/pts
+umount /mnt/dev
+umount /mnt
+reboot
 
 Repack live
 ===========
-- 
2.39.5


From ab29a9ca349685408f369e0b636083c258fb09da Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Fri, 18 Mar 2022 16:33:54 +0100
Subject: [PATCH 15/16] document how to deinstall linux

---
 files/quickstart.txt | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/files/quickstart.txt b/files/quickstart.txt
index 0e701a6..f6e2a02 100644
--- a/files/quickstart.txt
+++ b/files/quickstart.txt
@@ -221,3 +221,39 @@ device list
 station wlan0 scan
 station wlan0 get-networks
 station wlan0 connect SSID
+
+Deinstall Linux
+===============
+# Lets assume you have the following partioning
+
+(mini) [~] sudo parted /dev/nvme0n1 print
+Model: APPLE SSD AP0256Q (nvme)
+Disk /dev/nvme0n1: 251GB
+Sector size (logical/physical): 4096B/4096B
+Partition Table: gpt
+Disk Flags:
+
+Number  Start   End    Size    File system  Name                  Flags
+ 1      24.6kB  524MB  524MB                iBootSystemContainer
+ 2      524MB   101GB  100GB
+ 3      101GB   103GB  2500MB
+ 4      103GB   104GB  513MB   fat32                              boot, esp
+ 5      104GB   246GB  142GB   ext4
+ 6      246GB   251GB  5369MB               RecoveryOSContainer
+
+# Never delete the first, the second and the last partition because that either
+# renders your mac unbootable (first two) or unupgradable (last one). However
+# you can recover the system by using a second system if you screw up.
+
+# In the above example we need to delete the partition number 3 (stub partition
+# you can identify it by the size 2500 MB). The partition 4 (you can identtify
+# it by the fact that it is fat32 and the flags boot, esp). And the partition
+# number 5 (you can identify it by the fact that it is ext4).
+
+You delete the partitions by doing:
+
+# n is the partition number
+sudo parted /dev/nvme0n1 rm <n>
+
+# If you're asked if you want to proceed, say 'y'. If your asked if you want to
+# ignore, say, ignore.
-- 
2.39.5


From facdeb6d8eddc08d2e3d279fbdd0ebae493c7d7f Mon Sep 17 00:00:00 2001
From: Thomas Glanzmann <thomas@glanzmann.de>
Date: Fri, 18 Mar 2022 17:27:37 +0100
Subject: [PATCH 16/16] script to extract firmware from ipsw

---
 doc/notes.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/doc/notes.txt b/doc/notes.txt
index aebfd3c..5a9fdd1 100644
--- a/doc/notes.txt
+++ b/doc/notes.txt
@@ -411,3 +411,5 @@ kmutil configure-boot -c object.bin --raw --entry-point 2048 --lowest-virtual-ad
 20:32 < Glanzmann> I see. Thank you for the elaboration.
 20:32 < jannau> chosen.asahi,efi-system-partition is passed from the 1st stage forward to the second stage
 20:33 < Glanzmann> I see, so the first stage informs the second stage about the uuid of the esp partition which is than passed using dt to u-boot which can than select the right esp to select the efi binary.
+
+17:25 < Jamie[m]1> I had a dumb idea and had to implement it: using http range requests and DEFLATE trickery to download Wifi firmware from Apple's CDN with only 18MB of transfer (out of a 13GB ipsw) http://github.com/JJJollyjim/firmware-abomination
-- 
2.39.5