Skip to content

Commit a28b256

Browse files
Revert "sys-kernel/coreos-modules: Install external mod build files with script"
This reverts commit 2d3af88.
1 parent c997aa4 commit a28b256

File tree

3 files changed

+102
-15
lines changed

3 files changed

+102
-15
lines changed

changelog/changes/2025-10-30-kmod-build.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

sdk_container/src/third_party/coreos-overlay/eclass/coreos-kernel.eclass

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ kmake() {
117117
if gcc-specs-pie; then
118118
kernel_cflags="-nopie -fstack-check=no ${kernel_cflags}"
119119
fi
120-
emake "--directory=${KERNEL_DIR}" \
120+
emake "--directory=${S}/source" \
121121
ARCH="${kernel_arch}" \
122122
CROSS_COMPILE="${CHOST}-" \
123-
KBUILD_OUTPUT="${S}/build" \
123+
KBUILD_OUTPUT="../build" \
124124
KCFLAGS="${kernel_cflags}" \
125125
LDFLAGS="" \
126126
"V=1" \
@@ -184,6 +184,85 @@ shred_keys() {
184184
cp certs/modules.pub.pem "${sig_key}" || die
185185
}
186186

187+
# Populate /lib/modules/$(uname -r)/{build,source}
188+
install_build_source() {
189+
local kernel_arch=$(tc-arch-kernel)
190+
local host_kernel_arch=$(tc-ninja_magic_to_arch kern "${CBUILD}")
191+
192+
# NOTE: We have to get ${archabspaths} before removing symlinks under
193+
# /usr/lib/modules. However, do not exclude "dt-bindings" for now,
194+
# as it looks architecture-independent.
195+
local archabspaths=($(ls -1d ${D}/usr/lib/modules/${KV_FULL}/source/scripts/dtc/include-prefixes/* \
196+
| grep -v dt-bindings ))
197+
198+
# remove the broken symlinks referencing $ROOT
199+
rm "${D}/usr/lib/modules/${KV_FULL}/build" || die
200+
201+
# Compose list of architectures to be excluded from the kernel modules
202+
# tree in the final image. It is an array to be used as a pattern for
203+
# grep command below at the end of "find source/scripts" command for
204+
# fetching kernel modules list, e.g.:
205+
# find source/scripts -follow -print \
206+
# | grep -E -v -w "include-prefixes/arc|include-prefixes/xtensa"
207+
declare -a excarchlist
208+
local excarchstr
209+
210+
for apath in "${archabspaths[@]}"; do
211+
local arch
212+
arch=$(basename "${apath}")
213+
if [[ "${arch}" != "${kernel_arch}" ]]; then
214+
excarchlist+=("include-prefixes/${arch}")
215+
216+
# Do not append delimiter '|' in case of the last element.
217+
if [[ "${apath}" != "${archabspaths[-1]}" ]]; then
218+
excarchlist+=("|")
219+
fi
220+
fi
221+
done
222+
223+
# Remove every whitespace from the grep pattern string, to make pattern
224+
# matching work well.
225+
excarchstr=$(echo "${excarchlist[@]}" | sed -e 's/[[:space:]]*//g')
226+
227+
# Install a stripped source for out-of-tree module builds (Debian-derived)
228+
#
229+
# NOTE: we need to exclude unsupported architectures from source/scripts,
230+
# to prevent the final image from having unnecessary directories under
231+
# /usr/lib/modules/${KV_FULL}/source/scripts/dtc/include-prefixes.
232+
# The grep must run with "-w" to exclude exact patterns like either arm
233+
# or arm64.
234+
{
235+
echo source/Makefile
236+
find source/arch/${host_kernel_arch} -follow -maxdepth 1 -name 'Makefile*' -print
237+
find source/arch/${kernel_arch} -follow -maxdepth 1 -name 'Makefile*' -print
238+
find source/arch/${kernel_arch} -follow \( -name 'module.lds' -o -name 'Kbuild.platforms' -o -name 'Platform' \) -print
239+
find $(find source/arch/${kernel_arch} -follow \( -name include -o -name scripts \) -follow -type d -print) -print
240+
find source/include -follow -print
241+
find source/scripts -follow -print | grep -E -v -w "${excarchstr}"
242+
find build/ -print
243+
} | cpio -pd \
244+
--preserve-modification-time \
245+
--owner=root:root \
246+
--dereference \
247+
"${D}/usr/lib/modules/${KV_FULL}" || die
248+
# ./build/source is a symbolic link so cpio ends up creating an empty dir.
249+
# Restore the symlink.
250+
pushd "${D}/usr/lib/modules/${KV_FULL}"
251+
rmdir build/source || die
252+
ln -sr source build || die
253+
# Symlink includes into the build directory to resemble Ubuntu's /lib/modules
254+
# layout. This lets the Nvidia driver build when passing SYSSRC=/lib/modules/../build
255+
# instead of requiring SYSOUT/SYSSRC.
256+
{
257+
find source/include -mindepth 1 -maxdepth 1 -type d
258+
find source/arch/${kernel_arch}/include -mindepth 1 -maxdepth 1 -type d
259+
} | while read src; do
260+
dst="${src/source/build}"
261+
ln -sr "${src}" "${dst}" || die
262+
done || die
263+
popd
264+
}
265+
187266
coreos-kernel_pkg_pretend() {
188267
[[ "${MERGE_TYPE}" == binary ]] && return
189268

@@ -201,7 +280,10 @@ coreos-kernel_pkg_setup() {
201280
}
202281

203282
coreos-kernel_src_unpack() {
283+
# we more or less reproduce the layout in /lib/modules/$(uname -r)/
204284
mkdir -p "${S}/build" || die
285+
mkdir -p "${S}/source" || die
286+
ln -s "${KERNEL_DIR}"/* "${S}/source/" || die
205287
}
206288

207289
coreos-kernel_src_configure() {

sdk_container/src/third_party/coreos-overlay/sys-kernel/coreos-modules/coreos-modules-6.6.129.ebuild

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,34 @@ src_compile() {
3535
}
3636

3737
src_install() {
38-
local build="lib/modules/${KV_FULL}/build"
39-
4038
# Install modules to /usr, assuming USE=symlink-usr
39+
# Install firmware to a temporary (bogus) location.
40+
# The linux-firmware package will be used instead.
4141
# Stripping must be done here, not portage, to preserve sigs.
42-
kmake INSTALL_MOD_PATH="${ED}/usr" \
42+
kmake INSTALL_MOD_PATH="${D}/usr" \
4343
INSTALL_MOD_STRIP="--strip-debug" \
44+
INSTALL_FW_PATH="${T}/fw" \
4445
modules_install
4546

4647
# Install to /usr/lib/debug with debug symbols intact
47-
kmake INSTALL_MOD_PATH="${ED}/usr/lib/debug/usr" \
48+
kmake INSTALL_MOD_PATH="${D}/usr/lib/debug/usr" \
49+
INSTALL_FW_PATH="${T}/fw" \
4850
modules_install
49-
rm "${ED}/usr/lib/debug/usr/lib/modules/${KV_FULL}"/{build,modules.*} || die
51+
rm "${D}/usr/lib/debug/usr/lib/modules/${KV_FULL}/"modules.* || die
52+
rm "${D}/usr/lib/debug/usr/lib/modules/${KV_FULL}/build" || die
53+
54+
# Clean up the build tree
55+
shred_keys
56+
kmake clean
57+
find "build/" -type d -empty -delete || die
58+
rm "build/.config.old" || die
5059

51-
# Replace the broken /lib/modules/${KV_FULL}/build symlink with a copy of
52-
# the files needed to build out-of-tree modules.
53-
rm "${ED}/usr/${build}" || die
54-
kmake run-command KBUILD_RUN_COMMAND="${KERNEL_DIR}/scripts/package/install-extmod-build ${ED}/usr/${build}"
60+
# Install /lib/modules/${KV_FULL}/{build,source}
61+
install_build_source
5562

5663
# Not strictly required but this is where we used to install the config.
64+
dodir "/usr/boot"
65+
local build="lib/modules/${KV_FULL}/build"
5766
dosym "../${build}/.config" "/usr/boot/config-${KV_FULL}"
5867
dosym "../${build}/.config" "/usr/boot/config"
59-
60-
# Symlink "source" to "build" for compatibility. Fedora does this.
61-
dosym build "/usr/${build}/../source"
6268
}

0 commit comments

Comments
 (0)