@@ -14,12 +14,15 @@ without = [
1414
1515[components .kernel .build .defines ]
1616# RPM release number for the Azure Linux kernel package
17- azl_pkgrelease = " 18 "
17+ azl_pkgrelease = " 19 "
1818# 4th version component from the AZL kernel source (6.18.5.1). Included in specrelease so it appears
1919# in the RPM Release tag, uname -r, and /lib/modules/ path (e.g. 6.18.5-1.3.azl4.aarch64).
2020kextraversion = " 1"
2121# CBL-Mariner branch number (used in tarball path)
2222azurelinux_version = " 3"
23+ # NVIDIA open GPU kernel module version (built as a subpackage of the kernel)
24+ nvidia_open_version = " 595.58.03"
25+ nvidia_open_branch = " 595"
2326
2427# Download the source tarball from the AzureLinux kernel repo
2528[[components .kernel .source-files ]]
@@ -28,6 +31,13 @@ hash = "0d8c755e02857704eb4c4396657ad30b22b474296233b8681365aeaa2fc16926afe31f55
2831hash-type = " SHA512"
2932origin = { type = " download" , uri = " https://github.com/microsoft/CBL-Mariner-Linux-Kernel/archive/rolling-lts/mariner-3/6.18.5.1.tar.gz" }
3033
34+ # Download the NVIDIA open GPU kernel module source tarball
35+ [[components .kernel .source-files ]]
36+ filename = " open-gpu-kernel-modules-595.58.03.tar.gz"
37+ hash = " e0c4659ddf15e4f4e19cee05b49f88c9ba08ef3add0dfe08249798f58d0fe75e"
38+ hash-type = " SHA256"
39+ origin = { type = " download" , uri = " https://github.com/NVIDIA/open-gpu-kernel-modules/archive/refs/tags/595.58.03.tar.gz" }
40+
3141# Insert version and release information from the component defines into the spec file, and update the source URL to match the AzureLinux kernel source structure
3242[[components .kernel .overlays ]]
3343description = " Set specrpmversion to 6.18.5"
@@ -157,3 +167,169 @@ lines = [
157167 " cd ../.." ,
158168 " %endif" ,
159169]
170+
171+ # ============================================================================
172+ # kmod subpackage framework — modular kmod builds alongside the kernel
173+ #
174+ # This framework allows building out-of-tree kernel modules as subpackages of
175+ # the kernel RPM. Each kmod is defined in its own .inc file (e.g.
176+ # kmod-nvidia-open.inc) with phase-gated sections that run at each RPM build
177+ # phase (%description, %prep, %build, %install, %files).
178+ #
179+ # To add a new kmod:
180+ # 1. Create kmod-<name>.inc with phase-gated sections
181+ # 2. Add file-add overlays for .inc and any extra source files
182+ # 3. Add spec-insert-tag overlays to register sources (Source6xxx range)
183+ # 4. Add spec-search-replace overlays targeting the AZL-KMOD-*-ANCHOR
184+ # sentinels for each phase (the anchor survives replacement so the
185+ # next kmod can chain onto it)
186+ # ============================================================================
187+
188+ # --- kmod-nvidia-open: source file registration ---
189+ # Registers the NVIDIA open GPU kernel module sources and configuration files.
190+ # Source numbers 6000-6099 are reserved for nvidia-open.
191+
192+ [[components .kernel .overlays ]]
193+ description = " Add kmod-nvidia-open.inc subpackage definition to sources"
194+ type = " file-add"
195+ file = " kmod-nvidia-open.inc"
196+ source = " kmod-nvidia-open.inc"
197+
198+ [[components .kernel .overlays ]]
199+ description = " Add NVIDIA modprobe config file for kmod-nvidia-open subpackage"
200+ type = " file-add"
201+ file = " kmod-nvidia-open-modprobe.conf"
202+ source = " kmod-nvidia-open-modprobe.conf"
203+
204+ [[components .kernel .overlays ]]
205+ description = " Register NVIDIA open-gpu-kernel-modules tarball as Source6000"
206+ type = " spec-insert-tag"
207+ tag = " Source6000"
208+ value = " open-gpu-kernel-modules-%{nvidia_open_version}.tar.gz"
209+
210+ [[components .kernel .overlays ]]
211+ description = " Register NVIDIA modprobe config as Source6001"
212+ type = " spec-insert-tag"
213+ tag = " Source6001"
214+ value = " kmod-nvidia-open-modprobe.conf"
215+
216+ [[components .kernel .overlays ]]
217+ description = " Register kmod-nvidia-open.inc as Source6002"
218+ type = " spec-insert-tag"
219+ tag = " Source6002"
220+ value = " kmod-nvidia-open.inc"
221+
222+ # --- kmod framework: phase anchor insertion ---
223+ # These overlays insert unique sentinel comments at unconditional locations in
224+ # the upstream spec. Per-kmod overlays below target these sentinels with
225+ # spec-search-replace, replacing SENTINEL with <kmod include> + SENTINEL so
226+ # each sentinel survives for the next kmod to chain onto.
227+
228+ [[components .kernel .overlays ]]
229+ description = " Insert kmod package anchor after main %description — unconditional location for kmod subpackage declarations"
230+ type = " spec-append-lines"
231+ section = " %description"
232+ lines = [
233+ " " ,
234+ " # AZL-KMOD-PACKAGE-ANCHOR — do not remove (kmod overlays chain here)" ,
235+ ]
236+
237+ [[components .kernel .overlays ]]
238+ description = " Insert kmod prep anchor at end of %prep — unconditional location for kmod source extraction"
239+ type = " spec-append-lines"
240+ section = " %prep"
241+ lines = [
242+ " " ,
243+ " # AZL-KMOD-PREP-ANCHOR — do not remove (kmod overlays chain here)" ,
244+ ]
245+
246+ [[components .kernel .overlays ]]
247+ description = " Insert kmod build anchor before modsign macros — unconditional location at the end of the active %build body"
248+ type = " spec-search-replace"
249+ regex = ' # Module signing \(modsign\)'
250+ replacement = """ # AZL-KMOD-BUILD-ANCHOR — do not remove (kmod overlays chain here)
251+
252+ # Module signing (modsign)"""
253+
254+ [[components .kernel .overlays ]]
255+ description = " Insert kmod install anchor before ### clean — unconditional location at the end of the active %install body"
256+ type = " spec-search-replace"
257+ regex = ' ### clean'
258+ replacement = """ # AZL-KMOD-INSTALL-ANCHOR — do not remove (kmod overlays chain here)
259+
260+ ###
261+ ### clean"""
262+
263+ [[components .kernel .overlays ]]
264+ description = " Insert kmod files anchor after %files modules-extra-matched — unconditional location for kmod file lists"
265+ type = " spec-append-lines"
266+ section = " %files"
267+ package = " modules-extra-matched"
268+ lines = [
269+ " " ,
270+ " # AZL-KMOD-FILES-ANCHOR — do not remove (kmod overlays chain here)" ,
271+ ]
272+
273+ # --- kmod-nvidia-open: phase injection ---
274+ # RPM %include is a preprocessor directive — it must appear directly in the spec
275+ # text (not inside a %define macro). Each phase sets _kmod_phase and _kmod_name
276+ # globals, then includes the kmod .inc file. The .inc file's %if guards select
277+ # the correct section for that phase.
278+ #
279+ # To add a new kmod: duplicate the phase blocks below, changing _kmod_name and
280+ # the %include path. Each block targets the framework anchor for its phase.
281+
282+ [[components .kernel .overlays ]]
283+ description = " Run kmod 'package' phase at package anchor — declares kmod subpackages"
284+ type = " spec-search-replace"
285+ regex = ' # AZL-KMOD-PACKAGE-ANCHOR'
286+ replacement = """ # AZL: kmod subpackage declarations (nvidia-open)
287+ %global _kmod_phase package
288+ %global _kmod_name nvidia-open
289+ %include %{_sourcedir}/kmod-nvidia-open.inc
290+
291+ # AZL-KMOD-PACKAGE-ANCHOR"""
292+
293+ [[components .kernel .overlays ]]
294+ description = " Run kmod 'prep' phase at prep anchor — extracts kmod source tarballs"
295+ type = " spec-search-replace"
296+ regex = ' # AZL-KMOD-PREP-ANCHOR'
297+ replacement = """ # AZL: Prepare kmod subpackage sources (nvidia-open)
298+ %global _kmod_phase prep
299+ %global _kmod_name nvidia-open
300+ %include %{_sourcedir}/kmod-nvidia-open.inc
301+
302+ # AZL-KMOD-PREP-ANCHOR"""
303+
304+ [[components .kernel .overlays ]]
305+ description = " Run kmod 'build' phase at build anchor — compiles NVIDIA modules against the just-built kernel"
306+ type = " spec-search-replace"
307+ regex = ' # AZL-KMOD-BUILD-ANCHOR'
308+ replacement = """ # AZL: Build kmod subpackage modules (nvidia-open)
309+ %global _kmod_phase build
310+ %global _kmod_name nvidia-open
311+ %include %{_sourcedir}/kmod-nvidia-open.inc
312+
313+ # AZL-KMOD-BUILD-ANCHOR"""
314+
315+ [[components .kernel .overlays ]]
316+ description = " Run kmod 'install' phase at install anchor — installs NVIDIA modules, configs, and licenses"
317+ type = " spec-search-replace"
318+ regex = ' # AZL-KMOD-INSTALL-ANCHOR'
319+ replacement = """ # AZL: Install kmod subpackage files (nvidia-open)
320+ %global _kmod_phase install
321+ %global _kmod_name nvidia-open
322+ %include %{_sourcedir}/kmod-nvidia-open.inc
323+
324+ # AZL-KMOD-INSTALL-ANCHOR"""
325+
326+ [[components .kernel .overlays ]]
327+ description = " Run kmod 'files' phase at files anchor — adds %post/%postun/%files for NVIDIA kmod subpackage"
328+ type = " spec-search-replace"
329+ regex = ' # AZL-KMOD-FILES-ANCHOR'
330+ replacement = """ # AZL: kmod subpackage file lists and scriptlets (nvidia-open)
331+ %global _kmod_phase files
332+ %global _kmod_name nvidia-open
333+ %include %{_sourcedir}/kmod-nvidia-open.inc
334+
335+ # AZL-KMOD-FILES-ANCHOR"""
0 commit comments