summaryrefslogtreecommitdiffstats
path: root/meta/classes/kernel-module-split.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/kernel-module-split.bbclass')
-rw-r--r--meta/classes/kernel-module-split.bbclass187
1 files changed, 187 insertions, 0 deletions
diff --git a/meta/classes/kernel-module-split.bbclass b/meta/classes/kernel-module-split.bbclass
new file mode 100644
index 0000000..d43f743
--- /dev/null
+++ b/meta/classes/kernel-module-split.bbclass
@@ -0,0 +1,187 @@
1pkg_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
33python split_kernel_module_packages () {
34 import re
35
36 modinfoexp = re.compile("([^=]+)=(.*)")
37 kerverrexp = re.compile('^(.*-hh.*)[\.\+].*$')
38 depmodpat0 = re.compile("^(.*\.k?o):..*$")
39 depmodpat1 = re.compile("^(.*\.k?o):\s*(.*\.k?o)\s*$")
40 depmodpat2 = re.compile("^(.*\.k?o):\s*(.*\.k?o)\s*\\\$")
41 depmodpat3 = re.compile("^\t(.*\.k?o)\s*\\\$")
42 depmodpat4 = re.compile("^\t(.*\.k?o)\s*$")
43
44 def extract_modinfo(file):
45 import tempfile, subprocess
46 tempfile.tempdir = d.getVar("WORKDIR", True)
47 tf = tempfile.mkstemp()
48 tmpfile = tf[1]
49 cmd = "%sobjcopy -j .modinfo -O binary %s %s" % (d.getVar("HOST_PREFIX", True) or "", file, tmpfile)
50 subprocess.call(cmd, shell=True)
51 f = open(tmpfile)
52 l = f.read().split("\000")
53 f.close()
54 os.close(tf[0])
55 os.unlink(tmpfile)
56 vals = {}
57 for i in l:
58 m = modinfoexp.match(i)
59 if not m:
60 continue
61 vals[m.group(1)] = m.group(2)
62 return vals
63
64 def parse_depmod():
65
66 dvar = d.getVar('PKGD', True)
67
68 kernelver = d.getVar('KERNEL_VERSION', True)
69 kernelver_stripped = kernelver
70 m = kerverrexp.match(kernelver)
71 if m:
72 kernelver_stripped = m.group(1)
73 staging_kernel_dir = d.getVar("STAGING_KERNEL_DIR", True)
74 system_map_file = "%s/boot/System.map-%s" % (dvar, kernelver)
75 if not os.path.exists(system_map_file):
76 system_map_file = "%s/System.map-%s" % (staging_kernel_dir, kernelver)
77 if not os.path.exists(system_map_file):
78 bb.fatal("System.map-%s does not exist in '%s/boot' nor STAGING_KERNEL_DIR '%s'" % (kernelver, dvar, staging_kernel_dir))
79
80 cmd = "depmod -n -a -b %s -F %s %s" % (dvar, system_map_file, kernelver_stripped)
81 f = os.popen(cmd, 'r')
82
83 deps = {}
84 line = f.readline()
85 while line:
86 if not depmodpat0.match(line):
87 line = f.readline()
88 continue
89 m1 = depmodpat1.match(line)
90 if m1:
91 deps[m1.group(1)] = m1.group(2).split()
92 else:
93 m2 = depmodpat2.match(line)
94 if m2:
95 deps[m2.group(1)] = m2.group(2).split()
96 line = f.readline()
97 m3 = depmodpat3.match(line)
98 while m3:
99 deps[m2.group(1)].extend(m3.group(1).split())
100 line = f.readline()
101 m3 = depmodpat3.match(line)
102 m4 = depmodpat4.match(line)
103 deps[m2.group(1)].extend(m4.group(1).split())
104 line = f.readline()
105 f.close()
106 return deps
107
108 def get_dependencies(file, pattern, format):
109 # file no longer includes PKGD
110 file = file.replace(d.getVar('PKGD', True) or '', '', 1)
111 # instead is prefixed with /lib/modules/${KERNEL_VERSION}
112 file = file.replace("/lib/modules/%s/" % d.getVar('KERNEL_VERSION', True) or '', '', 1)
113
114 if file in module_deps:
115 dependencies = []
116 for i in module_deps[file]:
117 m = re.match(pattern, os.path.basename(i))
118 if not m:
119 continue
120 on = legitimize_package_name(m.group(1))
121 dependency_pkg = format % on
122 dependencies.append(dependency_pkg)
123 return dependencies
124 return []
125
126 def frob_metadata(file, pkg, pattern, format, basename):
127 vals = extract_modinfo(file)
128
129 dvar = d.getVar('PKGD', True)
130
131 # If autoloading is requested, output /etc/modules-load.d/<name>.conf and append
132 # appropriate modprobe commands to the postinst
133 autoload = d.getVar('module_autoload_%s' % basename, True)
134 if autoload:
135 name = '%s/etc/modules-load.d/%s.conf' % (dvar, basename)
136 f = open(name, 'w')
137 for m in autoload.split():
138 f.write('%s\n' % m)
139 f.close()
140 postinst = d.getVar('pkg_postinst_%s' % pkg, True)
141 if not postinst:
142 bb.fatal("pkg_postinst_%s not defined" % pkg)
143 postinst += d.getVar('autoload_postinst_fragment', True) % autoload
144 d.setVar('pkg_postinst_%s' % pkg, postinst)
145
146 # Write out any modconf fragment
147 modconf = d.getVar('module_conf_%s' % basename, True)
148 if modconf:
149 name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename)
150 f = open(name, 'w')
151 f.write("%s\n" % modconf)
152 f.close()
153
154 files = d.getVar('FILES_%s' % pkg, True)
155 files = "%s /etc/modules-load.d/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename)
156 d.setVar('FILES_%s' % pkg, files)
157
158 if "description" in vals:
159 old_desc = d.getVar('DESCRIPTION_' + pkg, True) or ""
160 d.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"])
161
162 rdepends = bb.utils.explode_dep_versions2(d.getVar('RDEPENDS_' + pkg, True) or "")
163 for dep in get_dependencies(file, pattern, format):
164 if not dep in rdepends:
165 rdepends[dep] = []
166 d.setVar('RDEPENDS_' + pkg, bb.utils.join_deps(rdepends, commasep=False))
167
168 module_deps = parse_depmod()
169 module_regex = '^(.*)\.k?o$'
170 module_pattern = 'kernel-module-%s'
171
172 postinst = d.getVar('pkg_postinst_modules', True)
173 postrm = d.getVar('pkg_postrm_modules', True)
174
175 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)))
176 if modules:
177 metapkg = d.getVar('KERNEL_MODULES_META_PACKAGE', True)
178 d.appendVar('RDEPENDS_' + metapkg, ' '+' '.join(modules))
179
180 # If modules-load.d and modprobe.d are empty at this point, remove them to
181 # avoid warnings. removedirs only raises an OSError if an empty
182 # directory cannot be removed.
183 dvar = d.getVar('PKGD', True)
184 for dir in ["%s/etc/modprobe.d" % (dvar), "%s/etc/modules-load.d" % (dvar), "%s/etc" % (dvar)]:
185 if len(os.listdir(dir)) == 0:
186 os.rmdir(dir)
187}