Skip to content

Integrate out-of-tree DKMS modules into the kernel at build time - #54

Merged
Bjordis Collaku (bjordiscollaku) merged 3 commits into
qcom/debian/latestfrom
feat/dkms-build-time-module-integration
Aug 27, 2026
Merged

Bjordis Collaku (bjordiscollaku) merged 3 commits into
qcom/debian/latestfrom
feat/dkms-build-time-module-integration

Conversation

@bjordiscollaku

@bjordiscollaku Bjordis Collaku (bjordiscollaku) commented Jun 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds a build-time mechanism that compiles out-of-tree kernel modules from
their DKMS source packages and bundles them into the kernel package, in the same
run that builds the kernel. The device receives one self-contained kernel
package: the module is present and pinned to the exact kernel it was built
against, with no DKMS, compiler, or headers required on the target.

The mechanism is module-agnostic. It is implemented as a standalone, documented
tool (debian/scripts/bundle-dkms-modules.sh) that debian/rules invokes during
the build, and it is driven by a manifest, so onboarding any out-of-tree module
is a two-line change with no change to the build logic.

Design history and rationale: #44.

How it works, in order

flowchart TD
    P["module DKMS source package<br/>(from the distro apt source)"]
    K["1. Build kernel + headers<br/>in one packaging run"]
    H["2. Stage headers in the build tree"]
    R["3. debian/rules calls<br/>bundle-dkms-modules.sh"]
    RES["4. Resolve source + tokens<br/>via dpkg -L and dkms.conf"]
    D["5. dkms build against the<br/>staged headers (private tree)"]
    J{"6. Built a .ko?"}
    X["Fail the build<br/>with precise diagnostics"]
    S["7. Extract debug to -dbg,<br/>strip the shipped copy"]
    B["8. Bundle into the kernel image<br/>under lib/modules/KVER/extra"]
    O["9. On device: depmod indexes it,<br/>modprobe + autoload work"]

    P -. "Build-Depends" .-> RES
    K --> H --> R --> RES --> D --> J
    J -- "no" --> X
    J -- "yes" --> S --> B --> O
Loading
  1. The module's *-dkms package is installed via Build-Depends (build-time
    only; it never enters any binary package's runtime dependencies).
  2. The kernel and its headers are built and staged in the same run.
  3. debian/rules (override_dh_auto_install) invokes the bundling tool once the
    trees are staged.
  4. For each manifest module the tool resolves the source directory and the dkms
    name/version tokens from dpkg -L and the shipped dkms.conf.
  5. It runs dkms build against the staged headers in a private DKMS tree, so the
    module matches the exact kernel and the build stays rootless under fakeroot.
  6. It judges success by the produced artifact, not by exit codes, and fails the
    build with precise diagnostics if a listed module produces nothing.
  7. It extracts the module's debug into the -dbg package and strips the shipped
    copy, the same two-stage handling an in-tree module gets.
  8. It installs the module into the kernel image under lib/modules/<KVER>/extra/,
    guarding against duplicate and in-tree name collisions.
  9. On the device, the standard postinst depmod indexes extra/, so modprobe
    and autoload resolve the module.

The tool: debian/scripts/bundle-dkms-modules.sh

The bundling logic is a single standalone tool with a documented CLI, so
debian/rules stays a thin call, future changes (a new guard, signing,
compression) touch one file, and a developer can re-run just the bundling step
against already-staged trees.

Required:
  --kver KVER               kernel release (uname -r)
  --headers-dir DIR         absolute path to the staged kernel headers root
  --image-pkg-dir DIR       linux-image staging tree root
  --dbg-pkg-dir DIR         linux-image-dbg staging tree root
Optional:
  --modules-manifest FILE   default: debian/dkms-modules
  --arch ARCH               default: aarch64 (uname -m vocabulary for dkms)
  --objcopy PATH            default: aarch64-linux-gnu-objcopy, then objcopy
  -h, --help                full usage, prerequisites, and examples

The tool resolves each module authoritatively (no path globbing), judges
outcomes by artifacts, hard-fails when a declared module produces nothing, prints actionable diagnostics on failure
(the make.log tail for a build failure, or the dkms.conf gates evaluated
against the kernel config for a skip), and guards against name collisions.

CI path: debian/rules calls the tool

override_dh_auto_install invokes the tool with explicit, absolute paths after
the kernel, headers, and debug trees are staged:

$(CURDIR)/debian/scripts/bundle-dkms-modules.sh \
    --kver            "$$BASE" \
    --headers-dir     "$(CURDIR)/debian/linux-headers-$$BASE-qcom/usr/src/linux-headers-$$BASE" \
    --image-pkg-dir   "$(CURDIR)/$$PKG" \
    --dbg-pkg-dir     "$(CURDIR)/$$DBG_PKG" \
    --arch            "$(DKMS_ARCH)" \
    --objcopy         "$(OBJCOPY)" \
    --modules-manifest "$(CURDIR)/debian/dkms-modules"

dh_installmodules (called in override_dh_installdeb) wires the postinst
depmod that indexes extra/ on the device.

Developer path: run the tool standalone

A developer who has already staged the kernel trees can re-run just the bundling
step, without re-running the whole dpkg-buildpackage:

debian/scripts/bundle-dkms-modules.sh \
  --kver        <kernelrelease> \
  --headers-dir   /path/to/staged/linux-headers-<kernelrelease> \
  --image-pkg-dir /path/to/staged/linux-image-<kernelrelease>-qcom \
  --dbg-pkg-dir   /path/to/staged/linux-image-<kernelrelease>-qcom-dbg

--help documents the full CLI, prerequisites, and a host-arch note (the tool
builds with the host toolchain and is intended to run on a native arm64 host).

The manifest: debian/dkms-modules

A plain-text list of module names, one per line. Comments, blank lines, and CRLF
endings are tolerated. This is the single place that decides which modules are
built and bundled; the tool and debian/rules are untouched when it changes.

Adding a module is two lines:

  1. Append the module name to debian/dkms-modules.
  2. Add dkms and <name>-dkms (>= x.y.z) to Build-Depends in
    debian/control.in.

Module load policy

Blacklisting and load policy are orthogonal to this change. The bundled module is
installed under /lib/modules/<KVER>/extra/ and indexed by the standard depmod,
so to the loader it is an ordinary module: the usual controls apply by module name,
unchanged (a blacklist or install line in modprobe.d, or modprobe.blacklist=
or module_blacklist= on the kernel command line). The kernel package intentionally
ships no load policy of its own, because a blacklist is board and policy specific
while this package is shared across boards; that decision stays external to this
mechanism, at the image build stage.

Validation

Both runs below were built from this branch's packaging
(pkg-linux-qcom-ref: feat/dkms-build-time-module-integration) after the rebase
onto the multi-variant packaging from #62, against kernel
7.2.0-qcom-next-20260826 and kgsl-dkms 1.0.12.

CI (Ubuntu, resolute). Run
33023768993.
kgsl-dkms 1.0.12-0qli1 is pulled in through Build-Depends, and the module is
built against the headers staged earlier in the same run rather than against
anything on the build host:

[bundle-dkms]   modules:          kgsl
[bundle-dkms] Building DKMS module kgsl/1.0.12 for 7.2.0-qcom-next-20260826
[bundle-dkms]   source:           /usr/src/kgsl-1.0.12
[bundle-dkms]   kernelsourcedir:  .../debian/linux-headers-7.2.0-qcom-next-20260826/usr/src/...
[bundle-dkms]   Installed: .../lib/modules/7.2.0-qcom-next-20260826/extra/msm_kgsl.ko (stripped)
[bundle-dkms]   Debug:     .../linux-image-...-dbg/usr/lib/debug/lib/modules/.../extra/msm_kgsl.ko

The contents of the built packages confirm the two-stage handling landed in the
right places:

-rw-r--r-- root/root 2969328 ./lib/modules/7.2.0-qcom-next-20260826/extra/msm_kgsl.ko
-rw-r--r-- root/root 1379672 ./usr/lib/debug/lib/modules/7.2.0-qcom-next-20260826/extra/msm_kgsl.ko

All six packages build (image, headers, their debug companions, and both
metapackages) at 7.2.0+20260826-0qli~26.04.1~, and the run is green through the
S3 upload.

CI (Debian, trixie). Run
33023767189.
The source package is submitted to Debusine, both work requests complete
successfully, and the same six packages are produced at
7.2.0+20260826-0qli~bpo13+1~, retrieved from the workspace and published to S3.

The binary build runs on Debusine, so its sbuild log is not streamed back into
the GitHub log; the bundling output visible above for Ubuntu is therefore not
reproduced here. The build completing is itself the signal: kgsl is listed in
debian/dkms-modules, and a listed module that yields no .ko fails the build
rather than shipping an image without it. For a byte-level check, the .deb can
be pulled from S3 and inspected with dpkg -c.

Local (standalone tool, 18 of 18). The tool was exercised through its CLI
against shimmed leaf tools, so its real control flow, resolution, outcome
judgment, collision guards, and path layout all run:

Area Cases
Happy path module installed to extra/, debug written to the -dbg tree, strip ran on the shipped copy
Resolution failures package not installed, multiple dkms.conf, missing PACKAGE_NAME
Outcome diagnosis build failure prints the make.log tail; gated skip with config set, with config unset, and with no gates declared; compressed output reported
Collisions in-tree name clash, duplicate bundled basename, duplicate manifest entry
Manifest comment-only manifest skips cleanly, missing manifest fails closed, default path resolves correctly

Enablement status

This PR delivers the mechanism in full, with a reference module (kgsl) wired
in and validated end to end on both distro families (the two runs above, on
kernel 7.2.0-qcom-next-20260826).

A module can only be built on a family whose apt source publishes its *-dkms
package. For the reference module this is now satisfied on both: the source is
on Qualcomm Artifactory (the Ubuntu path) and, as of the rebuild in
qualcomm-linux/pkg-kgsl#62, on the Debusine workspace (the Debian path). Both
nightly families (trixie via Debusine, resolute via docker) build and bundle it
green, so the reference module stays wired in at merge.

The per-family principle still applies to future modules: turn a module on for
a family (a manifest line plus a Build-Depends entry) only once that family's
apt source carries the module source. Happy to sequence this whichever way the
maintainers prefer.

Requirements (R1 to R7)
# Requirement
R1 One kernel package: kernel image plus every required out-of-tree module, built in the same run. No DKMS on the device.
R2 The kernel build declares a Build-Depends on the DKMS source packages. DKMS is a build-time tool, not a runtime mechanism.
R3 DKMS packages must not appear in Depends, Recommends, or Suggests of any binary package.
R4 Each module is compiled from source against the exact kernel produced in the same run. No cached artifact.
R5 A change to a DKMS package requires a kernel rebuild. Multiple changes can be batched into one rebuild.
R6 Each module's own CI stays independent and validates its own *-dkms package. The kernel CI only consumes it.
R7 The bundled module is handled like an in-tree module: stripped in the shipped package, debug symbols in the -dbg package.
Design decisions
Decision Rationale
Build-time DKMS, not on-device Single self-contained package, no toolchain or headers on the target, module pinned to the exact kernel (R1, R4).
DKMS as a build dependency only The module is baked in, so nothing is resolved at install time and the runtime dependency graph stays clean (R3).
A standalone, documented tool The logic lives in one file with a CLI, so debian/rules is a thin call, future changes touch one place, and the step is independently re-runnable.
Build against this run's staged headers The module is compiled against the headers produced earlier in the same run, so it matches and loads against this kernel (R4).
Manifest driven Which modules to build is separated from how to build them; a new module is two lines with no logic change.
Fail on a missing module If a manifest module produces no artifact, the build fails rather than silently shipping without it. Never inferred from the module's own gates, so a misconfigured gate cannot silently drop a declared module.
Judge outcomes by artifacts, not exit codes DKMS exit-code conventions vary across versions (a skip can exit 0). Success is a built module; failure diagnosis comes from the make.log and the dkms.conf gates.
Resolve identity from dpkg and dkms.conf dpkg -L names the one dkms.conf the package ships; its PACKAGE_NAME/PACKAGE_VERSION are the tokens dkms keys on. No path globbing.
Private DKMS tree plus source symlink Lets the build run rootless under fakeroot, away from the root-owned /var/lib/dkms.
In-tree-equivalent debug handling Debug to the -dbg package via objcopy --only-keep-debug, then strip the shipped copy via strip --strip-debug.
Commits (3)
debian/control.in: declare dkms as a build-time dependency
packaging: build out-of-tree DKMS modules and bundle them into the kernel image
debian/control.in: declare kgsl-dkms as a build-time dependency

Reorganized per review: the generic dkms build-dependency, the mechanism
itself, and the kgsl-specific build-dependency (now unpinned) are separate
commits. The mechanism lands directly as the generic tool, with the
incremental bring-up-then-extract history squashed away.

No package relationship (Conflicts, Breaks, Provides, Replaces) is
declared against the -dkms packages in this PR. That question is deferred
to a follow-up so it does not hold up the mechanism.

Not in this PR

  • On-target validation: installing the package on a device and confirming the
    module loads and functions (modprobe, autoload). Hardware validation, owned by
    the device team.

Notes

  • Target branch: qcom/debian/latest.
  • All commits are DCO signed off and single authored.

@bjordiscollaku
Bjordis Collaku (bjordiscollaku) force-pushed the feat/dkms-build-time-module-integration branch from 1d842df to 916da65 Compare June 25, 2026 18:49
Bjordis Collaku (bjordiscollaku) added a commit that referenced this pull request Jul 8, 2026
The Debian Debusine build path now needs kgsl-dkms as a build dependency
(via PR #54 against qcom/debian/latest). The package is published in the
qli Debusine workspace, so the build step must expose qli as an extra
build-dependency source when invoking debusine-action/lib/build.

Set EXTRA_BUILD_DEP_WORKSPACES=qli in Build in Debusine and pass
DEBUSINE_USER, which lib/build currently requires to apply its
extra_repositories compatibility workaround.
Bjordis Collaku (bjordiscollaku) added a commit that referenced this pull request Jul 8, 2026
The Debian Debusine build path now needs kgsl-dkms as a build dependency
(via PR #54 against qcom/debian/latest). The package is published in the
qli Debusine workspace, so the build step must expose qli as an extra
build-dependency source when invoking debusine-action/lib/build.

Set EXTRA_BUILD_DEP_WORKSPACES=qli in Build in Debusine and pass
DEBUSINE_USER, which lib/build currently requires to apply its
extra_repositories compatibility workaround.

Signed-off-by: Bjordis Collaku <bcollaku@qti.qualcomm.com>
@bjordiscollaku
Bjordis Collaku (bjordiscollaku) force-pushed the feat/dkms-build-time-module-integration branch from 9917688 to 916da65 Compare July 11, 2026 00:22
@obbardc

Copy link
Copy Markdown
Contributor

Bjordis Collaku (@bjordiscollaku) what is the status of this PR? would be great to get it in :-)

@bjordiscollaku

Copy link
Copy Markdown
Contributor Author

Bjordis Collaku (Bjordis Collaku (@bjordiscollaku)) what is the status of this PR? would be great to get it in :-)

Hi Christopher Obbard (@obbardc), technically, status is READY :) It's been ready for a while from my end, it's gonne through iteration of improvements, and also been validated as part of pkg-linux-qcom build with pkg-kgsl enabled (please check PR description on validation), both for ubuntu resolute and debian trixie. One note, as specified at the end of PR " hardware validation, owned by the device team." --> so in this case we would want gfx team to confirm this on target device. Since this is a big chunk of change though, it'd be good to get the mechanism in, and if any incremental changes/improvements arise, we can take care in subsequent PRs.

Why it's not merged yet? We switched primary focus to #62 AND #63.

I'd say we get #62 and #63 in (they've been validated in production debusine workspce, github staging env and debs are now published in qli-staging, so all is left is to switch to github production env, and switch target workspace to qli + debian revisions to 0qli, esentially one liners in matrix), then rebase #54 on top, and get it in as next step.

I'd appreciate your review on all 3 if/when you get a chance! Thanks in advance, and happy to work together!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting to look great, but some minor thoughts attached. I think you can squash a few commits, I'd like this to build camx-dkms and iris-vpu-dkms to prove the logic, but we can look at that separately if you wish.

Comment thread debian/control.in Resolved
Comment thread debian/rules Resolved
Comment thread debian/rules Resolved
Comment thread debian/rules Resolved
Comment thread debian/rules Resolved
Comment thread debian/dkms-modules Resolved
Comment thread debian/dkms-modules Resolved
Comment thread debian/rules Resolved
Comment thread debian/scripts/bundle-dkms-modules.sh Resolved
Comment thread debian/rules Resolved
@bjordiscollaku

Copy link
Copy Markdown
Contributor Author

Thanks a lot for going through this commit by commit Christopher Obbard (@obbardc), really appreciate the detailed review. Replies inline. Short version: I'll squash the noisy intermediate commits into the extraction, split the deps commit, and drop the version pin. Will ping you once it's pushed.

@bjordiscollaku
Bjordis Collaku (bjordiscollaku) force-pushed the feat/dkms-build-time-module-integration branch from 916da65 to c496305 Compare August 26, 2026 22:14
debian/scripts/bundle-dkms-modules.sh (added in a follow-up commit) invokes
dkms build unconditionally once any module is listed in debian/dkms-modules.
Declare dkms itself here, separately from any specific module's own
-dkms package, so the generic build-time prerequisite for the mechanism
doesn't get tangled with per-module additions.

Signed-off-by: Bjordis Collaku <bcollaku@qti.qualcomm.com>
…rnel image

Compile out-of-tree kernel modules from their DKMS source packages and
bundle them into linux-image-<KVER>-qcom at dpkg-buildpackage time, in the
same run that builds the kernel. The device receives one self-contained
kernel package: the module is present and pinned to the exact kernel it
was built against, with no DKMS, compiler, or headers required on the
target.

The mechanism is module-agnostic and driven by debian/dkms-modules, a
plain-text manifest of module names (one per line; comments and blank
lines ignored). Onboarding a module is a two-line change: append its name
to the manifest, and add <name>-dkms to Build-Depends. Neither
debian/rules nor debian/scripts/bundle-dkms-modules.sh changes.

The logic lives in debian/scripts/bundle-dkms-modules.sh, a standalone,
documented tool that debian/rules' override_dh_auto_install delegates to
once the kernel image, modules, headers, and debug packages are staged.
It can also be invoked directly by a developer who has already staged
those trees, without re-running the full dpkg-buildpackage. For each
manifest module, the tool:

- Resolves the installed <name>-dkms package's source directory via
  dpkg -L (authoritative; no /usr/src globbing), and reads
  PACKAGE_NAME/PACKAGE_VERSION from the package's own dkms.conf.
- Runs dkms build against the kernel headers staged earlier in this same
  run, in a private --dkmstree (mktemp), so the module matches the exact
  kernel and the build stays rootless under fakeroot.
- Judges the outcome by produced .ko artifact, not dkms exit code: dkms
  exit-code conventions vary across versions, and a BUILD_EXCLUSIVE skip
  can exit 0. A manifest entry is a presence contract, so a module that
  produces nothing hard-fails the build with precise diagnostics (the
  make.log tail for a build failure, or the BUILD_EXCLUSIVE gates
  evaluated against the staged kernel .config for a silent skip).
- Guards against name collisions: duplicate manifest entries resolving to
  the same dkms module, two modules bundling to the same .ko basename, and
  a bundled module's name clashing with an in-tree module (which would
  make depmod's search order ambiguous on the device).
- Installs the module under lib/modules/<KVER>/extra/, handling it exactly
  like an in-tree module: objcopy --only-keep-debug routes its debug
  symbols to the -dbg package before strip --strip-debug strips the
  shipped copy (--strip-debug, not a full strip, since kernel modules
  need their symtab and relocations to be loadable by the module loader).

On the device, the existing postinst depmod call indexes extra/, so
modprobe and autoload resolve the module with no other changes required.

kgsl is wired in as the reference module (declared in a follow-up commit,
separately from this generic mechanism), validated end to end on both the
Ubuntu/resolute (Docker) and Debian/trixie (Debusine) build paths.

Document the mechanism, the manifest format, and standalone developer use
in README.md.

Signed-off-by: Bjordis Collaku <bcollaku@qti.qualcomm.com>
Bjordis Collaku (bjordiscollaku) added a commit that referenced this pull request Aug 26, 2026
The Debian Debusine build path now needs kgsl-dkms as a build dependency
(via PR #54 against qcom/debian/latest). The package is published in the
qli Debusine workspace, so the build step must expose qli as an extra
build-dependency source when invoking debusine-action/lib/build.

Set EXTRA_BUILD_DEP_WORKSPACES=qli in Build in Debusine. DEBUSINE_USER,
which lib/build requires for its extra_repositories compatibility
workaround, is already set on this step (added independently for the
build signing key), so no change is needed for it here.

Signed-off-by: Bjordis Collaku <bcollaku@qti.qualcomm.com>
@bjordiscollaku
Bjordis Collaku (bjordiscollaku) force-pushed the feat/dkms-build-time-module-integration branch from c496305 to 3a9983c Compare August 26, 2026 23:25
Bjordis Collaku (bjordiscollaku) added a commit that referenced this pull request Aug 27, 2026
The Debian Debusine build path now needs kgsl-dkms as a build dependency
(via PR #54 against qcom/debian/latest). The package is published in the
qli Debusine workspace, so the build step must expose qli as an extra
build-dependency source when invoking debusine-action/lib/build.

Set EXTRA_BUILD_DEP_WORKSPACES=qli in Build in Debusine. DEBUSINE_USER,
which lib/build requires for its extra_repositories compatibility
workaround, is already set on this step (added independently for the
build signing key), so no change is needed for it here.

Signed-off-by: Bjordis Collaku <bcollaku@qti.qualcomm.com>
kgsl is the reference module wired into debian/dkms-modules, validated
end to end on both the Ubuntu/resolute (Docker) and Debian/trixie
(Debusine) build paths. Declare its -dkms package as a build-time-only
dependency, separately from the generic dkms tooling dependency, so
future per-module additions (camx-dkms, iris-vpu-dkms) each land as
their own commit alongside the manifest line they require, with no
change to debian/rules or the bundling tool itself.

No version floor: kgsl 1.0.4 is in qli and 1.0.10 is in qli-staging,
well past any earlier pin.

No package relationship is declared against the -dkms packages here.
Deciding whether the kernel image should Conflict with, Break, or
Provide them needs its own discussion: the kernel image ships a built
module for one kernel while a -dkms package serves every installed
kernel, and the -dkms package also ships runtime configuration that the
kernel image does not. Left for a follow-up so it does not hold up the
mechanism.

Signed-off-by: Bjordis Collaku <bcollaku@qti.qualcomm.com>
@bjordiscollaku
Bjordis Collaku (bjordiscollaku) merged commit e07dd41 into qcom/debian/latest Aug 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants