summaryrefslogtreecommitdiffstats
path: root/meta/classes/kernel.bbclass
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2006-07-21 10:10:31 +0000
committerRichard Purdie <richard@openedhand.com>2006-07-21 10:10:31 +0000
commitb2f192faabe412adce79534e22efe9fb69ee40e2 (patch)
tree7076c49d4286f8a1733650bd8fbc7161af200d57 /meta/classes/kernel.bbclass
parent2cf0eadf9f730027833af802d7e6c90b44248f80 (diff)
downloadpoky-b2f192faabe412adce79534e22efe9fb69ee40e2.tar.gz
Rename /openembedded/ -> /meta/
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@530 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'meta/classes/kernel.bbclass')
-rw-r--r--meta/classes/kernel.bbclass435
1 files changed, 435 insertions, 0 deletions
diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass
new file mode 100644
index 0000000000..ad51c4e035
--- /dev/null
+++ b/meta/classes/kernel.bbclass
@@ -0,0 +1,435 @@
1inherit module_strip
2
3PROVIDES += "virtual/kernel"
4DEPENDS += "virtual/${TARGET_PREFIX}depmod-${@get_kernelmajorversion('${PV}')} virtual/${TARGET_PREFIX}gcc${KERNEL_CCSUFFIX} update-modules"
5
6inherit kernel-arch
7
8PACKAGES_DYNAMIC += "kernel-module-*"
9PACKAGES_DYNAMIC += "kernel-image-*"
10
11export OS = "${TARGET_OS}"
12export CROSS_COMPILE = "${TARGET_PREFIX}"
13KERNEL_IMAGETYPE = "zImage"
14
15KERNEL_PRIORITY = "${@bb.data.getVar('PV',d,1).split('-')[0].split('.')[-1]}"
16
17# [jbowler 20051109] ${PV}${KERNEL_LOCALVERSION} is used throughout this
18# .bbclass to (apparently) find the full 'uname -r' kernel version, this
19# should be the same as UTS_RELEASE or (in this file) KERNEL_VERSION:
20# KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)$(LOCALVERSION)
21# but since this is not certain this overridable setting is used here:
22KERNEL_RELEASE ?= "${PV}${KERNEL_LOCALVERSION}"
23
24KERNEL_CCSUFFIX ?= ""
25KERNEL_LDSUFFIX ?= ""
26
27# Set TARGET_??_KERNEL_ARCH in the machine .conf to set architecture
28# specific options necessary for building the kernel and modules.
29#FIXME: should be this: TARGET_CC_KERNEL_ARCH ?= "${TARGET_CC_ARCH}"
30TARGET_CC_KERNEL_ARCH ?= ""
31HOST_CC_KERNEL_ARCH ?= "${TARGET_CC_KERNEL_ARCH}"
32TARGET_LD_KERNEL_ARCH ?= ""
33HOST_LD_KERNEL_ARCH ?= "${TARGET_LD_KERNEL_ARCH}"
34
35KERNEL_CC = "${CCACHE}${HOST_PREFIX}gcc${KERNEL_CCSUFFIX} ${HOST_CC_KERNEL_ARCH}"
36KERNEL_LD = "${LD}${KERNEL_LDSUFFIX} ${HOST_LD_KERNEL_ARCH}"
37
38KERNEL_OUTPUT = "arch/${ARCH}/boot/${KERNEL_IMAGETYPE}"
39KERNEL_IMAGEDEST = "boot"
40
41#
42# configuration
43#
44export CMDLINE_CONSOLE = "console=${@bb.data.getVar("KERNEL_CONSOLE",d,1) or "ttyS0"}"
45
46# parse kernel ABI version out of <linux/version.h>
47def get_kernelversion(p):
48 import re
49 try:
50 f = open(p, 'r')
51 except IOError:
52 return None
53 l = f.readlines()
54 f.close()
55 r = re.compile("#define UTS_RELEASE \"(.*)\"")
56 for s in l:
57 m = r.match(s)
58 if m:
59 return m.group(1)
60 return None
61
62def get_kernelmajorversion(p):
63 import re
64 r = re.compile("([0-9]+\.[0-9]+).*")
65 m = r.match(p);
66 if m:
67 return m.group(1)
68 return None
69
70KERNEL_VERSION = "${@get_kernelversion('${S}/include/linux/version.h')}"
71KERNEL_MAJOR_VERSION = "${@get_kernelmajorversion('${KERNEL_VERSION}')}"
72
73KERNEL_LOCALVERSION ?= ""
74
75# kernels are generally machine specific
76PACKAGE_ARCH = "${MACHINE_ARCH}"
77
78kernel_do_compile() {
79 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
80 oe_runmake include/linux/version.h CC="${KERNEL_CC}" LD="${KERNEL_LD}"
81 if [ "${KERNEL_MAJOR_VERSION}" != "2.6" ]; then
82 oe_runmake dep CC="${KERNEL_CC}" LD="${KERNEL_LD}"
83 fi
84 oe_runmake ${KERNEL_IMAGETYPE} CC="${KERNEL_CC}" LD="${KERNEL_LD}"
85 if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
86 oe_runmake modules CC="${KERNEL_CC}" LD="${KERNEL_LD}"
87 else
88 oenote "no modules to compile"
89 fi
90}
91
92kernel_do_stage() {
93 ASMDIR=`readlink include/asm`
94
95 mkdir -p ${STAGING_KERNEL_DIR}/include/$ASMDIR
96 cp -fR include/$ASMDIR/* ${STAGING_KERNEL_DIR}/include/$ASMDIR/
97 rm -f $ASMDIR ${STAGING_KERNEL_DIR}/include/asm
98 ln -sf $ASMDIR ${STAGING_KERNEL_DIR}/include/asm
99
100 mkdir -p ${STAGING_KERNEL_DIR}/include/asm-generic
101 cp -fR include/asm-generic/* ${STAGING_KERNEL_DIR}/include/asm-generic/
102
103 mkdir -p ${STAGING_KERNEL_DIR}/include/linux
104 cp -fR include/linux/* ${STAGING_KERNEL_DIR}/include/linux/
105
106 mkdir -p ${STAGING_KERNEL_DIR}/include/net
107 cp -fR include/net/* ${STAGING_KERNEL_DIR}/include/net/
108
109 mkdir -p ${STAGING_KERNEL_DIR}/include/pcmcia
110 cp -fR include/pcmcia/* ${STAGING_KERNEL_DIR}/include/pcmcia/
111
112 if [ -d include/sound ]; then
113 mkdir -p ${STAGING_KERNEL_DIR}/include/sound
114 cp -fR include/sound/* ${STAGING_KERNEL_DIR}/include/sound/
115 fi
116
117 if [ -d drivers/sound ]; then
118 # 2.4 alsa needs some headers from this directory
119 mkdir -p ${STAGING_KERNEL_DIR}/include/drivers/sound
120 cp -fR drivers/sound/*.h ${STAGING_KERNEL_DIR}/include/drivers/sound/
121 fi
122
123 install -m 0644 .config ${STAGING_KERNEL_DIR}/config-${KERNEL_RELEASE}
124 ln -sf config-${KERNEL_RELEASE} ${STAGING_KERNEL_DIR}/.config
125 ln -sf config-${KERNEL_RELEASE} ${STAGING_KERNEL_DIR}/kernel-config
126 echo "${KERNEL_VERSION}" >${STAGING_KERNEL_DIR}/kernel-abiversion
127 echo "${S}" >${STAGING_KERNEL_DIR}/kernel-source
128 echo "${KERNEL_CCSUFFIX}" >${STAGING_KERNEL_DIR}/kernel-ccsuffix
129 echo "${KERNEL_LDSUFFIX}" >${STAGING_KERNEL_DIR}/kernel-ldsuffix
130 [ -e Rules.make ] && install -m 0644 Rules.make ${STAGING_KERNEL_DIR}/
131 [ -e Makefile ] && install -m 0644 Makefile ${STAGING_KERNEL_DIR}/
132
133 # Check if arch/${ARCH}/Makefile exists and install it
134 if [ -e arch/${ARCH}/Makefile ]; then
135 install -d ${STAGING_KERNEL_DIR}/arch/${ARCH}
136 install -m 0644 arch/${ARCH}/Makefile ${STAGING_KERNEL_DIR}/arch/${ARCH}
137 fi
138 cp -fR include/config* ${STAGING_KERNEL_DIR}/include/
139 install -m 0644 ${KERNEL_OUTPUT} ${STAGING_KERNEL_DIR}/${KERNEL_IMAGETYPE}
140 install -m 0644 System.map ${STAGING_KERNEL_DIR}/System.map-${KERNEL_RELEASE}
141 [ -e Module.symvers ] && install -m 0644 Module.symvers ${STAGING_KERNEL_DIR}/
142
143 cp -fR scripts ${STAGING_KERNEL_DIR}/
144}
145
146kernel_do_install() {
147 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS
148 if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
149 oe_runmake DEPMOD=echo INSTALL_MOD_PATH="${D}" modules_install
150 else
151 oenote "no modules to install"
152 fi
153
154 install -d ${D}/${KERNEL_IMAGEDEST}
155 install -d ${D}/boot
156 install -m 0644 ${KERNEL_OUTPUT} ${D}/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-${KERNEL_RELEASE}
157 install -m 0644 System.map ${D}/boot/System.map-${KERNEL_RELEASE}
158 install -m 0644 .config ${D}/boot/config-${KERNEL_RELEASE}
159 install -d ${D}/etc/modutils
160
161 # Check if scripts/genksyms exists and if so, build it
162 if [ -e scripts/genksyms/ ]; then
163 oe_runmake SUBDIRS="scripts/genksyms"
164 fi
165
166 install -d ${STAGING_KERNEL_DIR}
167 cp -fR scripts ${STAGING_KERNEL_DIR}/
168}
169
170kernel_do_configure() {
171 yes '' | oe_runmake oldconfig
172}
173
174pkg_postinst_kernel () {
175 update-alternatives --install /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-${KERNEL_RELEASE} ${KERNEL_PRIORITY} || true
176}
177
178pkg_postrm_kernel () {
179 update-alternatives --remove ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-${KERNEL_RELEASE} || true
180}
181
182inherit cml1
183
184EXPORT_FUNCTIONS do_compile do_install do_stage do_configure
185
186PACKAGES = "kernel kernel-image kernel-dev"
187FILES = ""
188FILES_kernel-image = "/boot/${KERNEL_IMAGETYPE}*"
189FILES_kernel-dev = "/boot/System.map* /boot/config*"
190RDEPENDS_kernel = "kernel-image-${KERNEL_VERSION}"
191PKG_kernel-image = "kernel-image-${KERNEL_VERSION}"
192ALLOW_EMPTY_kernel = "1"
193ALLOW_EMPTY_kernel-image = "1"
194
195pkg_postinst_kernel-image () {
196if [ ! -e "$D/lib/modules/${KERNEL_RELEASE}" ]; then
197 mkdir -p $D/lib/modules/${KERNEL_RELEASE}
198fi
199if [ -n "$D" ]; then
200 ${HOST_PREFIX}depmod-${KERNEL_MAJOR_VERSION} -A -b $D -F ${STAGING_KERNEL_DIR}/System.map-${KERNEL_RELEASE} ${KERNEL_VERSION}
201else
202 depmod -A
203fi
204}
205
206pkg_postinst_modules () {
207if [ -n "$D" ]; then
208 ${HOST_PREFIX}depmod-${KERNEL_MAJOR_VERSION} -A -b $D -F ${STAGING_KERNEL_DIR}/System.map-${KERNEL_RELEASE} ${KERNEL_VERSION}
209else
210 depmod -A
211 update-modules || true
212fi
213}
214
215pkg_postrm_modules () {
216update-modules || true
217}
218
219autoload_postinst_fragment() {
220if [ x"$D" = "x" ]; then
221 modprobe %s || true
222fi
223}
224
225# autoload defaults (alphabetically sorted)
226module_autoload_hidp = "hidp"
227module_autoload_ipv6 = "ipv6"
228module_autoload_ipsec = "ipsec"
229module_autoload_ircomm-tty = "ircomm-tty"
230module_autoload_rfcomm = "rfcomm"
231module_autoload_sa1100-rtc = "sa1100-rtc"
232
233# alias defaults (alphabetically sorted)
234module_conf_af_packet = "alias net-pf-17 af_packet"
235module_conf_bluez = "alias net-pf-31 bluez"
236module_conf_bnep = "alias bt-proto-4 bnep"
237module_conf_hci_uart = "alias tty-ldisc-15 hci_uart"
238module_conf_l2cap = "alias bt-proto-0 l2cap"
239module_conf_sco = "alias bt-proto-2 sco"
240module_conf_rfcomm = "alias bt-proto-3 rfcomm"
241
242python populate_packages_prepend () {
243 def extract_modinfo(file):
244 import os, re
245 tmpfile = os.tmpnam()
246 cmd = "PATH=\"%s\" %sobjcopy -j .modinfo -O binary %s %s" % (bb.data.getVar("PATH", d, 1), bb.data.getVar("HOST_PREFIX", d, 1) or "", file, tmpfile)
247 os.system(cmd)
248 f = open(tmpfile)
249 l = f.read().split("\000")
250 f.close()
251 os.unlink(tmpfile)
252 exp = re.compile("([^=]+)=(.*)")
253 vals = {}
254 for i in l:
255 m = exp.match(i)
256 if not m:
257 continue
258 vals[m.group(1)] = m.group(2)
259 return vals
260
261 def parse_depmod():
262 import os, re
263
264 dvar = bb.data.getVar('D', d, 1)
265 if not dvar:
266 bb.error("D not defined")
267 return
268
269 kernelver = bb.data.getVar('KERNEL_RELEASE', d, 1)
270 kernelver_stripped = kernelver
271 m = re.match('^(.*-hh.*)[\.\+].*$', kernelver)
272 if m:
273 kernelver_stripped = m.group(1)
274 path = bb.data.getVar("PATH", d, 1)
275 host_prefix = bb.data.getVar("HOST_PREFIX", d, 1) or ""
276 major_version = bb.data.getVar('KERNEL_MAJOR_VERSION', d, 1)
277
278 cmd = "PATH=\"%s\" %sdepmod-%s -n -a -r -b %s -F %s/boot/System.map-%s %s" % (path, host_prefix, major_version, dvar, dvar, kernelver, kernelver_stripped)
279 f = os.popen(cmd, 'r')
280
281 deps = {}
282 pattern0 = "^(.*\.k?o):..*$"
283 pattern1 = "^(.*\.k?o):\s*(.*\.k?o)\s*$"
284 pattern2 = "^(.*\.k?o):\s*(.*\.k?o)\s*\\\$"
285 pattern3 = "^\t(.*\.k?o)\s*\\\$"
286 pattern4 = "^\t(.*\.k?o)\s*$"
287
288 line = f.readline()
289 while line:
290 if not re.match(pattern0, line):
291 line = f.readline()
292 continue
293 m1 = re.match(pattern1, line)
294 if m1:
295 deps[m1.group(1)] = m1.group(2).split()
296 else:
297 m2 = re.match(pattern2, line)
298 if m2:
299 deps[m2.group(1)] = m2.group(2).split()
300 line = f.readline()
301 m3 = re.match(pattern3, line)
302 while m3:
303 deps[m2.group(1)].extend(m3.group(1).split())
304 line = f.readline()
305 m3 = re.match(pattern3, line)
306 m4 = re.match(pattern4, line)
307 deps[m2.group(1)].extend(m4.group(1).split())
308 line = f.readline()
309 f.close()
310 return deps
311
312 def get_dependencies(file, pattern, format):
313 file = file.replace(bb.data.getVar('D', d, 1) or '', '', 1)
314
315 if module_deps.has_key(file):
316 import os.path, re
317 dependencies = []
318 for i in module_deps[file]:
319 m = re.match(pattern, os.path.basename(i))
320 if not m:
321 continue
322 on = legitimize_package_name(m.group(1))
323 dependency_pkg = format % on
324 v = bb.data.getVar("PARALLEL_INSTALL_MODULES", d, 1) or "0"
325 if v == "1":
326 kv = bb.data.getVar("KERNEL_MAJOR_VERSION", d, 1)
327 dependency_pkg = "%s-%s" % (dependency_pkg, kv)
328 dependencies.append(dependency_pkg)
329 return dependencies
330 return []
331
332 def frob_metadata(file, pkg, pattern, format, basename):
333 import re
334 vals = extract_modinfo(file)
335
336 dvar = bb.data.getVar('D', d, 1)
337
338 # If autoloading is requested, output /etc/modutils/<name> and append
339 # appropriate modprobe commands to the postinst
340 autoload = bb.data.getVar('module_autoload_%s' % basename, d, 1)
341 if autoload:
342 name = '%s/etc/modutils/%s' % (dvar, basename)
343 f = open(name, 'w')
344 for m in autoload.split():
345 f.write('%s\n' % m)
346 f.close()
347 postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1)
348 if not postinst:
349 bb.fatal("pkg_postinst_%s not defined" % pkg)
350 postinst += bb.data.getVar('autoload_postinst_fragment', d, 1) % autoload
351 bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d)
352
353 # Write out any modconf fragment
354 modconf = bb.data.getVar('module_conf_%s' % basename, d, 1)
355 if modconf:
356 name = '%s/etc/modutils/%s.conf' % (dvar, basename)
357 f = open(name, 'w')
358 f.write("%s\n" % modconf)
359 f.close()
360
361 files = bb.data.getVar('FILES_%s' % pkg, d, 1)
362 files = "%s /etc/modutils/%s /etc/modutils/%s.conf" % (files, basename, basename)
363 bb.data.setVar('FILES_%s' % pkg, files, d)
364
365 if vals.has_key("description"):
366 old_desc = bb.data.getVar('DESCRIPTION_' + pkg, d, 1) or ""
367 bb.data.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"], d)
368
369 rdepends_str = bb.data.getVar('RDEPENDS_' + pkg, d, 1)
370 if rdepends_str:
371 rdepends = rdepends_str.split()
372 else:
373 rdepends = []
374 rdepends.extend(get_dependencies(file, pattern, format))
375 bb.data.setVar('RDEPENDS_' + pkg, ' '.join(rdepends), d)
376
377 module_deps = parse_depmod()
378 module_regex = '^(.*)\.k?o$'
379 module_pattern = 'kernel-module-%s'
380
381 postinst = bb.data.getVar('pkg_postinst_modules', d, 1)
382 postrm = bb.data.getVar('pkg_postrm_modules', d, 1)
383 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='update-modules kernel-image-%s' % bb.data.getVar("KERNEL_VERSION", d, 1))
384
385 import re, os
386 metapkg = "kernel-modules"
387 bb.data.setVar('ALLOW_EMPTY_' + metapkg, "1", d)
388 bb.data.setVar('FILES_' + metapkg, "", d)
389 blacklist = [ 'kernel-dev', 'kernel-image' ]
390 for l in module_deps.values():
391 for i in l:
392 pkg = module_pattern % legitimize_package_name(re.match(module_regex, os.path.basename(i)).group(1))
393 blacklist.append(pkg)
394 metapkg_rdepends = []
395 packages = bb.data.getVar('PACKAGES', d, 1).split()
396 for pkg in packages[1:]:
397 if not pkg in blacklist and not pkg in metapkg_rdepends:
398 metapkg_rdepends.append(pkg)
399 bb.data.setVar('RDEPENDS_' + metapkg, ' '.join(metapkg_rdepends), d)
400 bb.data.setVar('DESCRIPTION_' + metapkg, 'Kernel modules meta package', d)
401 packages.append(metapkg)
402 bb.data.setVar('PACKAGES', ' '.join(packages), d)
403
404 v = bb.data.getVar("PARALLEL_INSTALL_MODULES", d, 1) or "0"
405 if v == "1":
406 kv = bb.data.getVar("KERNEL_MAJOR_VERSION", d, 1)
407 packages = bb.data.getVar("PACKAGES", d, 1).split()
408 module_re = re.compile("^kernel-module-")
409
410 newmetapkg = "kernel-modules-%s" % kv
411 bb.data.setVar('ALLOW_EMPTY_' + newmetapkg, "1", d)
412 bb.data.setVar('FILES_' + newmetapkg, "", d)
413
414 newmetapkg_rdepends = []
415
416 for p in packages:
417 if not module_re.match(p):
418 continue
419 pkg = bb.data.getVar("PKG_%s" % p, d, 1) or p
420 newpkg = "%s-%s" % (pkg, kv)
421 bb.data.setVar("PKG_%s" % p, newpkg, d)
422 rprovides = bb.data.getVar("RPROVIDES_%s" % p, d, 1)
423 if rprovides:
424 rprovides = "%s %s" % (rprovides, pkg)
425 else:
426 rprovides = pkg
427 bb.data.setVar("RPROVIDES_%s" % p, rprovides, d)
428 newmetapkg_rdepends.append(newpkg)
429
430 bb.data.setVar('RDEPENDS_' + newmetapkg, ' '.join(newmetapkg_rdepends), d)
431 bb.data.setVar('DESCRIPTION_' + newmetapkg, 'Kernel modules meta package', d)
432 packages.append(newmetapkg)
433 bb.data.setVar('PACKAGES', ' '.join(packages), d)
434
435}