blob: e8d3eb51057737382b8a8ac0e6562e483e193901 [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
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025PACKAGE_WRITE_DEPS += "kmod-native depmodwrapper-cross"
26
Patrick Williamsc124f4f2015-09-15 14:41:29 -050027do_install_append() {
28 install -d ${D}${sysconfdir}/modules-load.d/ ${D}${sysconfdir}/modprobe.d/
29}
30
31PACKAGESPLITFUNCS_prepend = "split_kernel_module_packages "
32
Brad Bishop316dfdd2018-06-25 12:45:53 -040033KERNEL_MODULES_META_PACKAGE ?= "${@ d.getVar("KERNEL_PACKAGE_NAME") or "kernel" }-modules"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034
Patrick Williamsc0f7c042017-02-23 20:41:17 -060035KERNEL_MODULE_PACKAGE_PREFIX ?= ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036KERNEL_MODULE_PACKAGE_SUFFIX ?= "-${KERNEL_VERSION}"
37KERNEL_MODULE_PROVIDE_VIRTUAL ?= "1"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060038
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039python split_kernel_module_packages () {
40 import re
41
42 modinfoexp = re.compile("([^=]+)=(.*)")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043
44 def extract_modinfo(file):
45 import tempfile, subprocess
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046 tempfile.tempdir = d.getVar("WORKDIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050047 tf = tempfile.mkstemp()
48 tmpfile = tf[1]
Brad Bishop6e60e8b2018-02-01 10:27:11 -050049 cmd = "%sobjcopy -j .modinfo -O binary %s %s" % (d.getVar("HOST_PREFIX") or "", file, tmpfile)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050050 subprocess.check_call(cmd, shell=True)
Brad Bishop19323692019-04-05 15:28:33 -040051 # errors='replace': Some old kernel versions contain invalid utf-8 characters in mod descriptions (like 0xf6, 'รถ')
52 f = open(tmpfile, errors='replace')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053 l = f.read().split("\000")
54 f.close()
55 os.close(tf[0])
56 os.unlink(tmpfile)
57 vals = {}
58 for i in l:
59 m = modinfoexp.match(i)
60 if not m:
61 continue
62 vals[m.group(1)] = m.group(2)
63 return vals
64
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065 def frob_metadata(file, pkg, pattern, format, basename):
66 vals = extract_modinfo(file)
67
Brad Bishop6e60e8b2018-02-01 10:27:11 -050068 dvar = d.getVar('PKGD')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050069
70 # If autoloading is requested, output /etc/modules-load.d/<name>.conf and append
71 # appropriate modprobe commands to the postinst
Brad Bishop6e60e8b2018-02-01 10:27:11 -050072 autoloadlist = (d.getVar("KERNEL_MODULE_AUTOLOAD") or "").split()
73 autoload = d.getVar('module_autoload_%s' % basename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074 if autoload and autoload == basename:
75 bb.warn("module_autoload_%s was replaced by KERNEL_MODULE_AUTOLOAD for cases where basename == module name, please drop it" % basename)
76 if autoload and basename not in autoloadlist:
77 bb.warn("module_autoload_%s is defined but '%s' isn't included in KERNEL_MODULE_AUTOLOAD, please add it there" % (basename, basename))
78 if basename in autoloadlist:
79 name = '%s/etc/modules-load.d/%s.conf' % (dvar, basename)
80 f = open(name, 'w')
81 if autoload:
82 for m in autoload.split():
83 f.write('%s\n' % m)
84 else:
85 f.write('%s\n' % basename)
86 f.close()
Brad Bishop6e60e8b2018-02-01 10:27:11 -050087 postinst = d.getVar('pkg_postinst_%s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050088 if not postinst:
89 bb.fatal("pkg_postinst_%s not defined" % pkg)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050090 postinst += d.getVar('autoload_postinst_fragment') % (autoload or basename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 d.setVar('pkg_postinst_%s' % pkg, postinst)
92
93 # Write out any modconf fragment
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 modconflist = (d.getVar("KERNEL_MODULE_PROBECONF") or "").split()
95 modconf = d.getVar('module_conf_%s' % basename)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050096 if modconf and basename in modconflist:
97 name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename)
98 f = open(name, 'w')
99 f.write("%s\n" % modconf)
100 f.close()
101 elif modconf:
102 bb.error("Please ensure module %s is listed in KERNEL_MODULE_PROBECONF since module_conf_%s is set" % (basename, basename))
103
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500104 files = d.getVar('FILES_%s' % pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500105 files = "%s /etc/modules-load.d/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename)
106 d.setVar('FILES_%s' % pkg, files)
107
108 if "description" in vals:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109 old_desc = d.getVar('DESCRIPTION_' + pkg) or ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110 d.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"])
111
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500112 rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg) or "")
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600113 modinfo_deps = []
114 if "depends" in vals and vals["depends"] != "":
115 for dep in vals["depends"].split(","):
116 on = legitimize_package_name(dep)
117 dependency_pkg = format % on
118 modinfo_deps.append(dependency_pkg)
119 for dep in modinfo_deps:
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500120 if not dep in rdepends:
121 rdepends[dep] = []
122 d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False))
123
124 # Avoid automatic -dev recommendations for modules ending with -dev.
125 d.setVarFlag('RRECOMMENDS_' + pkg, 'nodeprrecs', 1)
126
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500127 # Provide virtual package without postfix
128 providevirt = d.getVar('KERNEL_MODULE_PROVIDE_VIRTUAL')
129 if providevirt == "1":
130 postfix = format.split('%s')[1]
131 d.setVar('RPROVIDES_' + pkg, pkg.replace(postfix, ''))
132
Brad Bishop316dfdd2018-06-25 12:45:53 -0400133 kernel_package_name = d.getVar("KERNEL_PACKAGE_NAME") or "kernel"
134 kernel_version = d.getVar("KERNEL_VERSION")
135
Brad Bishop19323692019-04-05 15:28:33 -0400136 module_regex = r'^(.*)\.k?o$'
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600137
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500138 module_pattern_prefix = d.getVar('KERNEL_MODULE_PACKAGE_PREFIX')
139 module_pattern_suffix = d.getVar('KERNEL_MODULE_PACKAGE_SUFFIX')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400140 module_pattern = module_pattern_prefix + kernel_package_name + '-module-%s' + module_pattern_suffix
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500142 postinst = d.getVar('pkg_postinst_modules')
143 postrm = d.getVar('pkg_postrm_modules')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144
Brad Bishop316dfdd2018-06-25 12:45:53 -0400145 modules = do_split_packages(d, root='${nonarch_base_libdir}/modules', file_regex=module_regex, output_pattern=module_pattern, description='%s kernel module', postinst=postinst, postrm=postrm, recursive=True, hook=frob_metadata, extra_depends='%s-%s' % (kernel_package_name, kernel_version))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500146 if modules:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500147 metapkg = d.getVar('KERNEL_MODULES_META_PACKAGE')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500148 d.appendVar('RDEPENDS_' + metapkg, ' '+' '.join(modules))
149
150 # If modules-load.d and modprobe.d are empty at this point, remove them to
151 # avoid warnings. removedirs only raises an OSError if an empty
152 # directory cannot be removed.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500153 dvar = d.getVar('PKGD')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 for dir in ["%s/etc/modprobe.d" % (dvar), "%s/etc/modules-load.d" % (dvar), "%s/etc" % (dvar)]:
155 if len(os.listdir(dir)) == 0:
156 os.rmdir(dir)
157}
158
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500159do_package[vardeps] += '${@" ".join(map(lambda s: "module_conf_" + s, (d.getVar("KERNEL_MODULE_PROBECONF") or "").split()))}'