blob: 08d226276ed35fcd3e7871c42c60df9207800f60 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001pkg_postinst_modules () {
2if [ -z "$D" ]; then
3 depmod -a ${KERNEL_VERSION}
4else
5 # image.bbclass will call depmodwrapper after everything is installed,
6 # no need to do it here as well
7 :
8fi
9}
10
11pkg_postrm_modules () {
12if [ -z "$D" ]; then
13 depmod -a ${KERNEL_VERSION}
14else
15 depmodwrapper -a -b $D ${KERNEL_VERSION}
16fi
17}
18
19autoload_postinst_fragment() {
20if [ x"$D" = "x" ]; then
21 modprobe %s || true
22fi
23}
24
25do_install_append() {
26 install -d ${D}${sysconfdir}/modules-load.d/ ${D}${sysconfdir}/modprobe.d/
27}
28
29PACKAGESPLITFUNCS_prepend = "split_kernel_module_packages "
30
31KERNEL_MODULES_META_PACKAGE ?= "kernel-modules"
32
Patrick Williamsc0f7c042017-02-23 20:41:17 -060033KERNEL_MODULE_PACKAGE_PREFIX ?= ""
34
Patrick Williamsc124f4f2015-09-15 14:41:29 -050035python split_kernel_module_packages () {
36 import re
37
38 modinfoexp = re.compile("([^=]+)=(.*)")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039
40 def extract_modinfo(file):
41 import tempfile, subprocess
42 tempfile.tempdir = d.getVar("WORKDIR", True)
43 tf = tempfile.mkstemp()
44 tmpfile = tf[1]
45 cmd = "%sobjcopy -j .modinfo -O binary %s %s" % (d.getVar("HOST_PREFIX", True) or "", file, tmpfile)
46 subprocess.call(cmd, shell=True)
47 f = open(tmpfile)
48 l = f.read().split("\000")
49 f.close()
50 os.close(tf[0])
51 os.unlink(tmpfile)
52 vals = {}
53 for i in l:
54 m = modinfoexp.match(i)
55 if not m:
56 continue
57 vals[m.group(1)] = m.group(2)
58 return vals
59
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 def frob_metadata(file, pkg, pattern, format, basename):
61 vals = extract_modinfo(file)
62
63 dvar = d.getVar('PKGD', True)
64
65 # If autoloading is requested, output /etc/modules-load.d/<name>.conf and append
66 # appropriate modprobe commands to the postinst
67 autoloadlist = (d.getVar("KERNEL_MODULE_AUTOLOAD", True) or "").split()
68 autoload = d.getVar('module_autoload_%s' % basename, True)
69 if autoload and autoload == basename:
70 bb.warn("module_autoload_%s was replaced by KERNEL_MODULE_AUTOLOAD for cases where basename == module name, please drop it" % basename)
71 if autoload and basename not in autoloadlist:
72 bb.warn("module_autoload_%s is defined but '%s' isn't included in KERNEL_MODULE_AUTOLOAD, please add it there" % (basename, basename))
73 if basename in autoloadlist:
74 name = '%s/etc/modules-load.d/%s.conf' % (dvar, basename)
75 f = open(name, 'w')
76 if autoload:
77 for m in autoload.split():
78 f.write('%s\n' % m)
79 else:
80 f.write('%s\n' % basename)
81 f.close()
82 postinst = d.getVar('pkg_postinst_%s' % pkg, True)
83 if not postinst:
84 bb.fatal("pkg_postinst_%s not defined" % pkg)
85 postinst += d.getVar('autoload_postinst_fragment', True) % (autoload or basename)
86 d.setVar('pkg_postinst_%s' % pkg, postinst)
87
88 # Write out any modconf fragment
89 modconflist = (d.getVar("KERNEL_MODULE_PROBECONF", True) or "").split()
90 modconf = d.getVar('module_conf_%s' % basename, True)
91 if modconf and basename in modconflist:
92 name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename)
93 f = open(name, 'w')
94 f.write("%s\n" % modconf)
95 f.close()
96 elif modconf:
97 bb.error("Please ensure module %s is listed in KERNEL_MODULE_PROBECONF since module_conf_%s is set" % (basename, basename))
98
99 files = d.getVar('FILES_%s' % pkg, True)
100 files = "%s /etc/modules-load.d/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename)
101 d.setVar('FILES_%s' % pkg, files)
102
103 if "description" in vals:
104 old_desc = d.getVar('DESCRIPTION_' + pkg, True) or ""
105 d.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"])
106
107 rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg, True) or "")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600108 modinfo_deps = []
109 if "depends" in vals and vals["depends"] != "":
110 for dep in vals["depends"].split(","):
111 on = legitimize_package_name(dep)
112 dependency_pkg = format % on
113 modinfo_deps.append(dependency_pkg)
114 for dep in modinfo_deps:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500115 if not dep in rdepends:
116 rdepends[dep] = []
117 d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False))
118
119 # Avoid automatic -dev recommendations for modules ending with -dev.
120 d.setVarFlag('RRECOMMENDS_' + pkg, 'nodeprrecs', 1)
121
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500122 module_regex = '^(.*)\.k?o$'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600123
124 module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX', True)
125 module_pattern = module_pattern_prefix + 'kernel-module-%s'
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126
127 postinst = d.getVar('pkg_postinst_modules', True)
128 postrm = d.getVar('pkg_postrm_modules', True)
129
130 modules = do_split_packages(d, root='/lib/modules', file_regex=module_regex, output_pattern=module_pattern, description='%s kernel module', postinst=postinst, postrm=postrm, recursive=True, hook=frob_metadata, extra_depends='kernel-%s' % (d.getVar("KERNEL_VERSION", True)))
131 if modules:
132 metapkg = d.getVar('KERNEL_MODULES_META_PACKAGE', True)
133 d.appendVar('RDEPENDS_' + metapkg, ' '+' '.join(modules))
134
135 # If modules-load.d and modprobe.d are empty at this point, remove them to
136 # avoid warnings. removedirs only raises an OSError if an empty
137 # directory cannot be removed.
138 dvar = d.getVar('PKGD', True)
139 for dir in ["%s/etc/modprobe.d" % (dvar), "%s/etc/modules-load.d" % (dvar), "%s/etc" % (dvar)]:
140 if len(os.listdir(dir)) == 0:
141 os.rmdir(dir)
142}
143
144do_package[vardeps] += '${@" ".join(map(lambda s: "module_conf_" + s, (d.getVar("KERNEL_MODULE_PROBECONF", True) or "").split()))}'