-
Notifications
You must be signed in to change notification settings - Fork 0
/
asahi-scripts.patch
237 lines (228 loc) · 10.6 KB
/
asahi-scripts.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
diff -uraN asahi-scripts-20221220/etc/mkinitcpio.d/linux-sd-asahi-edge.preset.x sd-asahi-scripts/etc/mkinitcpio.d/linux-sd-asahi-edge.preset.x
--- asahi-scripts-20221220/etc/mkinitcpio.d/linux-sd-asahi-edge.preset.x 1970-01-01 00:00:00.000000000 +0000
+++ sd-asahi-scripts/etc/mkinitcpio.d/linux-sd-asahi-edge.preset.x 2022-12-22 23:07:57.038306930 +0000
@@ -0,0 +1,10 @@
+# mkinitcpio preset file for the 'linux-sd-asahi' boot process
+
+ALL_config="/etc/mkinitcpio.conf"
+ALL_kver="/boot/vmlinuz-linux-asahi-edge"
+
+PRESETS=('default' 'fallback')
+
+default_image="/boot/initramfs-linux-sd-asahi-edge.img"
+fallback_image="/boot/initramfs-linux-sd-asahi-edge-fallback.img"
+fallback_options="-S autodetect"
diff -uraN asahi-scripts-20221220/etc/mkinitcpio.d/linux-sd-asahi.preset.x sd-asahi-scripts/etc/mkinitcpio.d/linux-sd-asahi.preset.x
--- asahi-scripts-20221220/etc/mkinitcpio.d/linux-sd-asahi.preset.x 1970-01-01 00:00:00.000000000 +0000
+++ sd-asahi-scripts/etc/mkinitcpio.d/linux-sd-asahi.preset.x 2022-12-22 23:07:57.038306930 +0000
@@ -0,0 +1,10 @@
+# mkinitcpio preset file for the 'linux-sd-asahi' boot process
+
+ALL_config="/etc/mkinitcpio.conf"
+ALL_kver="/boot/vmlinuz-linux-asahi"
+
+PRESETS=('default' 'fallback')
+
+default_image="/boot/initramfs-linux-sd-asahi.img"
+fallback_image="/boot/initramfs-linux-sd-asahi-fallback.img"
+fallback_options="-S autodetect"
diff -uraN asahi-scripts-20221220/initcpio/hooks/asahi sd-asahi-scripts/initcpio/hooks/asahi
--- asahi-scripts-20221220/initcpio/hooks/asahi 2022-12-20 08:29:20.000000000 +0000
+++ sd-asahi-scripts/initcpio/hooks/asahi 2022-12-22 23:07:57.038306930 +0000
@@ -50,6 +50,7 @@
}
run_latehook() {
+ [ -e /vendorfw ] || return
msg ":: Asahi: Copying vendor firmware to tmpfs under root filesystem..."
mkdir -p /new_root/lib/firmware/vendor
mount -t tmpfs vendorfw /new_root/lib/firmware/vendor
diff -uraN asahi-scripts-20221220/initcpio/install/sd-asahi sd-asahi-scripts/initcpio/install/sd-asahi
--- asahi-scripts-20221220/initcpio/install/sd-asahi 1970-01-01 00:00:00.000000000 +0000
+++ sd-asahi-scripts/initcpio/install/sd-asahi 2022-12-22 23:07:57.038306930 +0000
@@ -0,0 +1,38 @@
+#!/bin/bash
+# SPDX-License-Identifier: MIT
+
+build() {
+
+ asahi_base_build
+
+ # ~~~~~~~~~~~~~~~~~~~ SYSTEMD ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ #
+ # Runhook is replaced by systemd units
+ # These need to be in /usr/lib/systemd/system
+
+ map add_systemd_unit 'sd-asahi-early-firmware.target' 'sd-asahi-late-firmware.target'
+
+ # We need to manually link the units because systemd doesn't have a way of enabling for initramfs (??) but this
+
+ add_symlink '/usr/lib/systemd/system/sysinit.target.wants/sd-asahi-early-firmware.target' '/usr/lib/systemd/system/sd-asahi-early-firmware.target'
+
+ add_dir '/usr/lib/systemd/system/initrd.target.wants'
+
+ add_symlink '/usr/lib/systemd/system/initrd.target.wants/sd-asahi-late-firmware.target' '/usr/lib/systemd/system/sd-asahi-late-firmware.target'
+
+ # The following are added automatically by add_systemd_unit because of Requires=
+
+ # 'sd-asahi-early-firmware.service'
+ # 'sd-asahi-late-firmware.service'
+
+ # The script used by these services is also automatically added by add_systemd_unit
+
+ # add_binary '/usr/share/asahi-scripts/systemd/fwhooks'
+}
+
+# what needs to be appended:
+# the build function under the alias asahi_base_build, with the add_runscript line removed:
+# the help function, no alias
+# this bottom comment => '# vim: set ft=sh ts=4 sw=4 et:'
+# in total (the following is assuming that build() is @ line 4):
+# sed '1,2d;4s/build/asahi_base_build/;/add_runscript/d' initcpio/install/asahi >> initcpio/install/sd-asahi
diff -uraN asahi-scripts-20221220/Makefile sd-asahi-scripts/Makefile
--- asahi-scripts-20221220/Makefile 2022-12-20 08:29:20.000000000 +0000
+++ sd-asahi-scripts/Makefile 2022-12-22 23:07:57.038306930 +0000
@@ -36,6 +36,18 @@
install -dD $(DESTDIR)$(PREFIX)/lib/initcpio/hooks
install -m0644 -t $(DESTDIR)$(PREFIX)/lib/initcpio/hooks initcpio/hooks/asahi
+install-sd-asahi: install
+ chmod +x sd-asahi-build
+ ./sd-asahi-build
+ install -dD $(DESTDIR)/etc/mkinitcpio.d
+ install -dD $(DESTDIR)$(PREFIX)/lib/initcpio/install
+ install -dD $(DESTDIR)$(PREFIX)/lib/systemd/system
+ install -dD $(DESTDIR)$(PREFIX)/share/asahi-scripts
+ install -m0644 -t $(DESTDIR)/etc/mkinitcpio.d etc/mkinitcpio.d/*
+ install -m0644 -t $(DESTDIR)$(PREFIX)/lib/initcpio/install initcpio/install/sd-asahi
+ install -m0644 -t $(DESTDIR)$(PREFIX)/lib/systemd/system systemd/sd-asahi-*
+ install -m0755 -t $(DESTDIR)$(PREFIX)/share/asahi-scripts systemd/fwhooks
+
install-dracut: install
install -dD $(DESTDIR)$(DRACUT_CONF_DIR)
install -m0644 -t $(DESTDIR)$(DRACUT_CONF_DIR) dracut/dracut.conf.d/10-asahi.conf
@@ -44,7 +56,7 @@
install -m0755 -t $(DESTDIR)$(DRACUT_MODULES_DIR)/99asahi-firmware dracut/modules.d/99asahi-firmware/load-asahi-firmware.sh
install -m0755 -t $(DESTDIR)$(DRACUT_MODULES_DIR)/99asahi-firmware dracut/modules.d/99asahi-firmware/module-setup.sh
-install-arch: install install-mkinitcpio
+install-arch: install install-mkinitcpio install-sd-asahi
install -m0755 -t $(DESTDIR)$(BIN_DIR)/ $(BUILD_ARCH_SCRIPTS)
install -dD $(DESTDIR)$(PREFIX)/lib/systemd/system
install -dD $(DESTDIR)$(PREFIX)/lib/systemd/system/{multi-user,sysinit}.target.wants
@@ -64,10 +76,15 @@
rm -f $(DESTDIR)$(PREFIX)/lib/initcpio/install/asahi
rm -f $(DESTDIR)$(PREFIX)/lib/initcpio/hooks/asahi
+uninstall-sd-asahi:
+ rm -f $(DESTDIR)$(PREFIX)/lib/initcpio/install/sd-asahi
+ rm -f $(DESTDIR)$(PREFIX)/lib/systemd/system/sd-asahi-*
+ rm -f $(DESTDIR)/etc/mkinitcpio.d/linux-sd-asahi.preset*
+
uninstall-dracut:
rm -f $(DESTDIR)$(DRACUT_CONF_DIR)/10-asahi.conf
-uninstall-arch: uninstall-mkinitcpio
+uninstall-arch: uninstall-mkinitcpio uninstall-sd-asahi
rm -f $(addprefix $(DESTDIR)$(BIN_DIR)/,$(ARCH_SCRIPTS))
rm -f $(addprefix $(DESTDIR)$(PREFIX)/lib/systemd/system/,$(UNITS))
rm -f $(addprefix $(DESTDIR)$(PREFIX)/lib/systemd/system/multi-user.target.wants/,$(MULTI_USER_WANTS))
@@ -75,4 +92,4 @@
uninstall-fedora: uninstall-dracut
-.PHONY: clean install install-mkinitcpio install-dracut install-arch install-fedora uninstall uninstall-mkinitcpio uninstall-dracut uninstall-arch uninstall-fedora
+.PHONY: clean install install-mkinitcpio install-sd-asahi install-dracut install-arch install-fedora uninstall uninstall-mkinitcpio uninstall-sd-asahi uninstall-dracut uninstall-arch uninstall-fedora
diff -uraN asahi-scripts-20221220/sd-asahi-build sd-asahi-scripts/sd-asahi-build
--- asahi-scripts-20221220/sd-asahi-build 1970-01-01 00:00:00.000000000 +0000
+++ sd-asahi-scripts/sd-asahi-build 2022-12-22 23:07:57.038306930 +0000
@@ -0,0 +1,3 @@
+#!/bin/sh
+sed '1,2d;s/new_root/sysroot/g;$s/$/\n\n$1/' initcpio/hooks/asahi >> systemd/fwhooks
+sed '1,2d;4s/build/asahi_base_build/;/add_runscript/d' initcpio/install/asahi >> initcpio/install/sd-asahi
diff -uraN asahi-scripts-20221220/systemd/fwhooks sd-asahi-scripts/systemd/fwhooks
--- asahi-scripts-20221220/systemd/fwhooks 1970-01-01 00:00:00.000000000 +0000
+++ sd-asahi-scripts/systemd/fwhooks 2022-12-22 23:07:57.038306930 +0000
@@ -0,0 +1,33 @@
+#!/usr/bin/sh
+# SPDX-License-Identifier: MIT
+
+# init functions are not available with systemd out of the box
+
+msg() {
+ local mesg=$1; shift
+ printf "$_color_green==>$_color_none $_color_bold$mesg$_color_none\n" "$@" >&1
+}
+
+early_load() {
+ run_earlyhook
+}
+
+late_mount() {
+ msg ":: Asahi: Waiting until sysroot and vendorfw become available..."
+
+ # initrd-fs.target does not exactly mean that sysroot is fully mounted, we need to wait for both of these to appear.
+ # I've also tried `sleep 0.1` but systemd kills it way too fast, better this real infinite loop
+
+ while true; do
+ [[ -d /sysroot/lib && -d /vendorfw ]] && break
+ done
+
+ run_latehook
+}
+
+# what should be appended:
+# the functions (w body): `run_earlyhook`, `run_latehook`, with new_root replaced with sysroot
+# `\n$1`, since the function running needs to be selected during boot
+# all preferably indented for readability
+# in total:
+# sed '1,2d;s/new_root/sysroot/g;$s/$/\n\n$1/' initcpio/hooks/asahi >> systemd/fwhook.sh
diff -uraN asahi-scripts-20221220/systemd/sd-asahi-early-firmware.service sd-asahi-scripts/systemd/sd-asahi-early-firmware.service
--- asahi-scripts-20221220/systemd/sd-asahi-early-firmware.service 1970-01-01 00:00:00.000000000 +0000
+++ sd-asahi-scripts/systemd/sd-asahi-early-firmware.service 2022-12-22 23:07:57.038306930 +0000
@@ -0,0 +1,8 @@
+[Unit]
+Description=Asahi Early Firmware Service
+DefaultDependencies=no
+Conflicts=shutdown.target
+Before=shutdown.target
+
+[Service]
+ExecStart=+/usr/share/asahi-scripts/fwhooks early_load
diff -uraN asahi-scripts-20221220/systemd/sd-asahi-early-firmware.target sd-asahi-scripts/systemd/sd-asahi-early-firmware.target
--- asahi-scripts-20221220/systemd/sd-asahi-early-firmware.target 1970-01-01 00:00:00.000000000 +0000
+++ sd-asahi-scripts/systemd/sd-asahi-early-firmware.target 2022-12-22 23:07:57.038306930 +0000
@@ -0,0 +1,7 @@
+[Unit]
+Description=Asahi Early Firmware
+Before=systemd-udevd.service
+Requires=sd-asahi-early-firmware.service
+
+[Install]
+WantedBy=sysinit.target
diff -uraN asahi-scripts-20221220/systemd/sd-asahi-late-firmware.service sd-asahi-scripts/systemd/sd-asahi-late-firmware.service
--- asahi-scripts-20221220/systemd/sd-asahi-late-firmware.service 1970-01-01 00:00:00.000000000 +0000
+++ sd-asahi-scripts/systemd/sd-asahi-late-firmware.service 2022-12-22 23:07:57.038306930 +0000
@@ -0,0 +1,8 @@
+[Unit]
+Description=Asahi Late Firmware Service
+DefaultDependencies=no
+Conflicts=shutdown.target
+Before=shutdown.target
+
+[Service]
+ExecStart=+/usr/share/asahi-scripts/fwhooks late_mount
diff -uraN asahi-scripts-20221220/systemd/sd-asahi-late-firmware.target sd-asahi-scripts/systemd/sd-asahi-late-firmware.target
--- asahi-scripts-20221220/systemd/sd-asahi-late-firmware.target 1970-01-01 00:00:00.000000000 +0000
+++ sd-asahi-scripts/systemd/sd-asahi-late-firmware.target 2022-12-22 23:07:57.038306930 +0000
@@ -0,0 +1,7 @@
+[Unit]
+Description=Asahi Late Firmware
+After=initrd-fs.target cryptsetup.target
+Requires=sd-asahi-late-firmware.service
+
+[Install]
+WantedBy=initrd.target
diff -uraN asahi-scripts-20221220/update-m1n1 sd-asahi-scripts/update-m1n1
--- asahi-scripts-20221220/update-m1n1 2022-12-20 08:29:20.000000000 +0000
+++ sd-asahi-scripts/update-m1n1 2022-12-22 23:07:57.038306930 +0000
@@ -5,6 +5,8 @@
[ -e /etc/default/update-m1n1 ] && . /etc/default/update-m1n1
+[ -n $M1N1_UPDATE_DISABLED ] && exit 0
+
if [ -e "$(dirname "$0")"/functions.sh ]; then
. "$(dirname "$0")"/functions.sh
else