1 |
commit: 153a877d333d3b85920267535aef950056c92192 |
2 |
Author: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Sep 9 00:16:42 2021 +0000 |
4 |
Commit: Thomas Deutschmann <whissi <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Sep 9 00:59:03 2021 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=153a877d |
7 |
|
8 |
Refactor (compressed) kernel module handling |
9 |
|
10 |
To support a specific module compression algorithm, two things are needed: |
11 |
|
12 |
Used depmod utility on host system building the kernel must support chosen |
13 |
module compression algorithm to generate proper modules.dep file or |
14 |
genkernel would be unable to read module dependencies when copying modules |
15 |
to initramfs. |
16 |
|
17 |
At runtime, used modprobe utility must be able to handle chosen module |
18 |
compression algorithm or modules would be unloadable. |
19 |
|
20 |
To address the first requirement, genkernel will now check if used kmod |
21 |
utility on host system supports chosen module compression algorithm. |
22 |
|
23 |
To address the runtime requirement, this commit will switch from BusyBox's |
24 |
modutils implementation to kmod because BusyBox does not support ZSTD |
25 |
compression (yet). |
26 |
|
27 |
Bug: https://bugs.gentoo.org/809344 |
28 |
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org> |
29 |
|
30 |
gen_configkernel.sh | 7 ++++ |
31 |
gen_determineargs.sh | 6 +++ |
32 |
gen_funcs.sh | 72 ++++++++++++++++++++++++++++++++++++ |
33 |
gen_initramfs.sh | 22 ++++++++++- |
34 |
gkbuilds/kmod.gkbuild | 26 ++++++++++++- |
35 |
patches/kmod/29/kmod-29-static.patch | 12 ++++++ |
36 |
6 files changed, 143 insertions(+), 2 deletions(-) |
37 |
|
38 |
diff --git a/gen_configkernel.sh b/gen_configkernel.sh |
39 |
index bff3fdc..62113dc 100755 |
40 |
--- a/gen_configkernel.sh |
41 |
+++ b/gen_configkernel.sh |
42 |
@@ -347,6 +347,13 @@ config_kernel() { |
43 |
unset kconfig_md5sum_old kconfig_md5sum_new |
44 |
fi |
45 |
|
46 |
+ # Check for suitable kmod |
47 |
+ determine_KEXT |
48 |
+ if ! isTrue "$(is_kext_supported_by_kmod "${KEXT}")" |
49 |
+ then |
50 |
+ gen_die "${KMOD_CMD} does not support chosen module compression algorithm. Please re-emerge sys-apps/kmod with USE=$(get_kext_kmod_use_flag "${KEXT}") enabled or adjust CONFIG_MODULE_COMPRESS_* kernel option!" |
51 |
+ fi |
52 |
+ |
53 |
local -a required_kernel_options |
54 |
[ -f "${KCONFIG_MODIFIED_MARKER}" ] && rm "${KCONFIG_MODIFIED_MARKER}" |
55 |
|
56 |
|
57 |
diff --git a/gen_determineargs.sh b/gen_determineargs.sh |
58 |
index 21d3b22..027c696 100755 |
59 |
--- a/gen_determineargs.sh |
60 |
+++ b/gen_determineargs.sh |
61 |
@@ -314,6 +314,12 @@ determine_real_args() { |
62 |
gen_die "'realpath -m /' failed. We need a realpath version which supports '-m' mode!" |
63 |
fi |
64 |
|
65 |
+ KMOD_CMD=$(which kmod 2>/dev/null) |
66 |
+ if [ -z "${KMOD_CMD}" ] |
67 |
+ then |
68 |
+ gen_die "kmod not found. Is sys-apps/kmod installed?" |
69 |
+ fi |
70 |
+ |
71 |
if hash grep &>/dev/null |
72 |
then |
73 |
GREP_CMD=grep |
74 |
|
75 |
diff --git a/gen_funcs.sh b/gen_funcs.sh |
76 |
index d40607c..6bc59e6 100755 |
77 |
--- a/gen_funcs.sh |
78 |
+++ b/gen_funcs.sh |
79 |
@@ -287,6 +287,48 @@ is_psf_file() { |
80 |
echo "${file_is_psf}" |
81 |
} |
82 |
|
83 |
+is_kext_supported_by_kmod() { |
84 |
+ [[ ${#} -ne 1 ]] \ |
85 |
+ && gen_die "$(get_useful_function_stack "${FUNCNAME}")Invalid usage of ${FUNCNAME}(): Function takes exactly one argument (${#} given)!" |
86 |
+ |
87 |
+ local requested_feature=${1} |
88 |
+ requested_feature=${requested_feature##*.} |
89 |
+ requested_feature=${requested_feature^^} |
90 |
+ |
91 |
+ local is_supported=no |
92 |
+ |
93 |
+ if [[ "${requested_feature}" == GZ ]] |
94 |
+ then |
95 |
+ requested_feature=ZLIB |
96 |
+ elif [[ "${requested_feature}" == ZST ]] |
97 |
+ then |
98 |
+ requested_feature=ZSTD |
99 |
+ fi |
100 |
+ |
101 |
+ case "${requested_feature}" in |
102 |
+ KO) |
103 |
+ is_supported=yes |
104 |
+ ;; |
105 |
+ *) |
106 |
+ local line |
107 |
+ while read line; do |
108 |
+ if [[ ! ${line} =~ ^[\+\-] ]] |
109 |
+ then |
110 |
+ continue |
111 |
+ fi |
112 |
+ |
113 |
+ if [[ ${line} =~ \+${requested_feature} ]] |
114 |
+ then |
115 |
+ is_supported=yes |
116 |
+ break |
117 |
+ fi |
118 |
+ done < <("${KMOD_CMD}" -V) |
119 |
+ ;; |
120 |
+ esac |
121 |
+ |
122 |
+ echo "${is_supported}" |
123 |
+} |
124 |
+ |
125 |
is_valid_ssh_host_keys_parameter_value() { |
126 |
local parameter_value=${1} |
127 |
|
128 |
@@ -2123,6 +2165,36 @@ make_bootdir_writable() { |
129 |
fi |
130 |
} |
131 |
|
132 |
+get_kext_kmod_use_flag() { |
133 |
+ [[ ${#} -ne 1 ]] \ |
134 |
+ && gen_die "$(get_useful_function_stack "${FUNCNAME}")Invalid usage of ${FUNCNAME}(): Function takes exactly one argument (${#} given)!" |
135 |
+ |
136 |
+ local kext=${1} |
137 |
+ kext=${kext##*.} |
138 |
+ kext=${kext^^} |
139 |
+ |
140 |
+ local use_flag= |
141 |
+ |
142 |
+ case "${kext}" in |
143 |
+ GZ) |
144 |
+ use_flag="zlib" |
145 |
+ ;; |
146 |
+ KO) |
147 |
+ ;; |
148 |
+ XZ) |
149 |
+ use_flag="lzma" |
150 |
+ ;; |
151 |
+ ZST) |
152 |
+ use_flag="zstd" |
153 |
+ ;; |
154 |
+ *) |
155 |
+ gen_die "$(get_useful_function_stack)Internal error: KEXT '${kext}' is unknown!" |
156 |
+ ;; |
157 |
+ esac |
158 |
+ |
159 |
+ echo "${use_flag}" |
160 |
+} |
161 |
+ |
162 |
# @FUNCTION: get_nproc |
163 |
# @USAGE: [${fallback:-1}] |
164 |
# @DESCRIPTION: |
165 |
|
166 |
diff --git a/gen_initramfs.sh b/gen_initramfs.sh |
167 |
index b9aeb0b..8f11127 100755 |
168 |
--- a/gen_initramfs.sh |
169 |
+++ b/gen_initramfs.sh |
170 |
@@ -1727,9 +1727,19 @@ append_modules() { |
171 |
rm -r "${TDIR}" || gen_die "Failed to clean out existing '${TDIR}'!" |
172 |
fi |
173 |
|
174 |
+ populate_binpkg kmod |
175 |
+ |
176 |
mkdir "${TDIR}" || gen_die "Failed to create '${TDIR}'!" |
177 |
+ |
178 |
+ unpack "$(get_gkpkg_binpkg kmod)" "${TDIR}" |
179 |
+ |
180 |
cd "${TDIR}" || gen_die "Failed to chdir to '${TDIR}'!" |
181 |
|
182 |
+ # Delete unneeded files |
183 |
+ rm -rf \ |
184 |
+ usr/include \ |
185 |
+ usr/lib |
186 |
+ |
187 |
local mydir= |
188 |
for mydir in \ |
189 |
etc/modules \ |
190 |
@@ -1788,7 +1798,7 @@ append_modules() { |
191 |
|| gen_die "Failed to copy '${modules_srcdir}/modules*' to '${modules_dstdir}'!" |
192 |
|
193 |
print_info 2 "$(get_indent 2)modules: Updating modules.dep ..." |
194 |
- local a depmod_cmd=( depmod -a -b "${TDIR}" ${KV} ) |
195 |
+ local depmod_cmd=( depmod -a -b "${TDIR}" ${KV} ) |
196 |
print_info 3 "COMMAND: ${depmod_cmd[*]}" 1 0 1 |
197 |
eval "${depmod_cmd[@]}" || gen_die "Failed to run '${depmod_cmd[*]}'!" |
198 |
|
199 |
@@ -1986,6 +1996,16 @@ append_data() { |
200 |
create_initramfs() { |
201 |
print_info 1 "initramfs: >> Initializing ..." |
202 |
|
203 |
+ if ! isTrue "${BUILD_KERNEL}" |
204 |
+ then |
205 |
+ # Check early for suitable kmod |
206 |
+ determine_KEXT |
207 |
+ if ! isTrue "$(is_kext_supported_by_kmod "${KEXT}")" |
208 |
+ then |
209 |
+ gen_die "${KMOD_CMD} does not support chosen module compression algorithm. Please re-emerge sys-apps/kmod with USE=$(get_kext_kmod_use_flag "${KEXT}") enabled or adjust CONFIG_MODULE_COMPRESS_* kernel option!" |
210 |
+ fi |
211 |
+ fi |
212 |
+ |
213 |
# Create empty cpio |
214 |
CPIO_ARCHIVE="${TMPDIR}/${GK_FILENAME_TEMP_INITRAMFS}" |
215 |
append_data 'devices' # WARNING, must be first! |
216 |
|
217 |
diff --git a/gkbuilds/kmod.gkbuild b/gkbuilds/kmod.gkbuild |
218 |
index 8572b77..ac6b3e2 100644 |
219 |
--- a/gkbuilds/kmod.gkbuild |
220 |
+++ b/gkbuilds/kmod.gkbuild |
221 |
@@ -20,8 +20,9 @@ src_prepare() { |
222 |
src_configure() { |
223 |
local myconf=( |
224 |
--enable-static |
225 |
+ --disable-manpages |
226 |
--disable-python |
227 |
- --disable-tools |
228 |
+ --enable-tools |
229 |
--with-xz |
230 |
--with-zlib |
231 |
--with-zstd |
232 |
@@ -48,4 +49,27 @@ src_install() { |
233 |
|
234 |
rm -rf \ |
235 |
"${D}"/usr/share/ |
236 |
+ |
237 |
+ "${STRIP}" --strip-all "${D}"/usr/bin/kmod \ |
238 |
+ || die "Failed to strip '${D}/usr/bin/kmod'!" |
239 |
+ |
240 |
+ mkdir "${D}"/bin || die "Failed to create '${D}/bin'!" |
241 |
+ |
242 |
+ mkdir "${D}"/sbin || die "Failed to create '${D}/sbin'!" |
243 |
+ |
244 |
+ # We need to install these links where busybox would create them |
245 |
+ local symlink_targets=() |
246 |
+ symlink_targets+=( /sbin/depmod ) |
247 |
+ symlink_targets+=( /sbin/insmod ) |
248 |
+ symlink_targets+=( /sbin/lsmod ) |
249 |
+ symlink_targets+=( /sbin/modinfo ) |
250 |
+ symlink_targets+=( /sbin/modprobe ) |
251 |
+ symlink_targets+=( /sbin/rmmod ) |
252 |
+ |
253 |
+ local symlink_target= |
254 |
+ for symlink_target in "${symlink_targets[@]}" |
255 |
+ do |
256 |
+ ln -s ../usr/bin/kmod "${D}${symlink_target}" \ |
257 |
+ || die "Failed to create symlink '${D}${symlink_target}' to '${D}/usr/bin/kmod'!" |
258 |
+ done |
259 |
} |
260 |
|
261 |
diff --git a/patches/kmod/29/kmod-29-static.patch b/patches/kmod/29/kmod-29-static.patch |
262 |
new file mode 100644 |
263 |
index 0000000..c29ab7f |
264 |
--- /dev/null |
265 |
+++ b/patches/kmod/29/kmod-29-static.patch |
266 |
@@ -0,0 +1,12 @@ |
267 |
+--- a/Makefile.am |
268 |
++++ b/Makefile.am |
269 |
+@@ -155,6 +155,8 @@ tools_kmod_SOURCES += \ |
270 |
+ tools/remove.c |
271 |
+ endif |
272 |
+ |
273 |
++tools_kmod_LDFLAGS = -all-static |
274 |
++ |
275 |
+ tools_kmod_LDADD = \ |
276 |
+ shared/libshared.la \ |
277 |
+ libkmod/libkmod-internal.la |
278 |
+ |