diff options
Diffstat (limited to 'classes/kernel.bbclass')
| -rw-r--r-- | classes/kernel.bbclass | 513 |
1 files changed, 513 insertions, 0 deletions
diff --git a/classes/kernel.bbclass b/classes/kernel.bbclass new file mode 100644 index 0000000000..d710db874b --- /dev/null +++ b/classes/kernel.bbclass | |||
| @@ -0,0 +1,513 @@ | |||
| 1 | inherit linux-kernel-base module_strip | ||
| 2 | |||
| 3 | PROVIDES += "virtual/kernel" | ||
| 4 | DEPENDS += "virtual/${TARGET_PREFIX}gcc virtual/${TARGET_PREFIX}depmod-${@get_kernelmajorversion('${PV}')} virtual/${TARGET_PREFIX}gcc${KERNEL_CCSUFFIX} update-modules" | ||
| 5 | |||
| 6 | # we include gcc above, we dont need virtual/libc | ||
| 7 | INHIBIT_DEFAULT_DEPS = "1" | ||
| 8 | |||
| 9 | KERNEL_IMAGETYPE ?= "zImage" | ||
| 10 | |||
| 11 | python __anonymous () { | ||
| 12 | kerneltype = bb.data.getVar('KERNEL_IMAGETYPE', d, 1) or '' | ||
| 13 | if kerneltype == 'uImage': | ||
| 14 | depends = bb.data.getVar("DEPENDS", d, 1) | ||
| 15 | depends = "%s u-boot-mkimage-native" % depends | ||
| 16 | bb.data.setVar("DEPENDS", depends, d) | ||
| 17 | } | ||
| 18 | |||
| 19 | inherit kernel-arch deploy | ||
| 20 | |||
| 21 | PACKAGES_DYNAMIC += "kernel-module-*" | ||
| 22 | PACKAGES_DYNAMIC += "kernel-image-*" | ||
| 23 | PACKAGES_DYNAMIC += "kernel-firmware-*" | ||
| 24 | |||
| 25 | export OS = "${TARGET_OS}" | ||
| 26 | export CROSS_COMPILE = "${TARGET_PREFIX}" | ||
| 27 | |||
| 28 | KERNEL_PRIORITY = "${@bb.data.getVar('PV',d,1).split('-')[0].split('.')[-1]}" | ||
| 29 | |||
| 30 | KERNEL_RELEASE ?= "${KERNEL_VERSION}" | ||
| 31 | |||
| 32 | KERNEL_CCSUFFIX ?= "" | ||
| 33 | KERNEL_LDSUFFIX ?= "" | ||
| 34 | |||
| 35 | # Set TARGET_??_KERNEL_ARCH in the machine .conf to set architecture | ||
| 36 | # specific options necessary for building the kernel and modules. | ||
| 37 | #FIXME: should be this: TARGET_CC_KERNEL_ARCH ?= "${TARGET_CC_ARCH}" | ||
| 38 | TARGET_CC_KERNEL_ARCH ?= "" | ||
| 39 | HOST_CC_KERNEL_ARCH ?= "${TARGET_CC_KERNEL_ARCH}" | ||
| 40 | TARGET_LD_KERNEL_ARCH ?= "" | ||
| 41 | HOST_LD_KERNEL_ARCH ?= "${TARGET_LD_KERNEL_ARCH}" | ||
| 42 | |||
| 43 | KERNEL_CC = "${CCACHE}${HOST_PREFIX}gcc${KERNEL_CCSUFFIX} ${HOST_CC_KERNEL_ARCH}" | ||
| 44 | KERNEL_LD = "${LD}${KERNEL_LDSUFFIX} ${HOST_LD_KERNEL_ARCH}" | ||
| 45 | |||
| 46 | # Where built kernel lies in the kernel tree | ||
| 47 | KERNEL_OUTPUT ?= "arch/${ARCH}/boot/${KERNEL_IMAGETYPE}" | ||
| 48 | KERNEL_IMAGEDEST = "boot" | ||
| 49 | |||
| 50 | # | ||
| 51 | # configuration | ||
| 52 | # | ||
| 53 | export CMDLINE_CONSOLE = "console=${@bb.data.getVar("KERNEL_CONSOLE",d,1) or "ttyS0"}" | ||
| 54 | |||
| 55 | KERNEL_VERSION = "${@get_kernelversion('${B}')}" | ||
| 56 | KERNEL_MAJOR_VERSION = "${@get_kernelmajorversion('${KERNEL_VERSION}')}" | ||
| 57 | |||
| 58 | KERNEL_LOCALVERSION ?= "" | ||
| 59 | |||
| 60 | # kernels are generally machine specific | ||
| 61 | PACKAGE_ARCH = "${MACHINE_ARCH}" | ||
| 62 | |||
| 63 | # U-Boot support | ||
| 64 | UBOOT_ENTRYPOINT ?= "20008000" | ||
| 65 | UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}" | ||
| 66 | |||
| 67 | # For the kernel, we don't want the '-e MAKEFLAGS=' in EXTRA_OEMAKE. | ||
| 68 | # We don't want to override kernel Makefile variables from the environment | ||
| 69 | EXTRA_OEMAKE = "" | ||
| 70 | |||
| 71 | KERNEL_ALT_IMAGETYPE ??= "" | ||
| 72 | |||
| 73 | kernel_do_compile() { | ||
| 74 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE | ||
| 75 | oe_runmake include/linux/version.h CC="${KERNEL_CC}" LD="${KERNEL_LD}" | ||
| 76 | if [ "${KERNEL_MAJOR_VERSION}" != "2.6" ]; then | ||
| 77 | oe_runmake dep CC="${KERNEL_CC}" LD="${KERNEL_LD}" | ||
| 78 | fi | ||
| 79 | oe_runmake ${KERNEL_IMAGETYPE} ${KERNEL_ALT_IMAGETYPE} CC="${KERNEL_CC}" LD="${KERNEL_LD}" | ||
| 80 | } | ||
| 81 | |||
| 82 | do_compile_kernelmodules() { | ||
| 83 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE | ||
| 84 | if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then | ||
| 85 | oe_runmake modules CC="${KERNEL_CC}" LD="${KERNEL_LD}" | ||
| 86 | else | ||
| 87 | oenote "no modules to compile" | ||
| 88 | fi | ||
| 89 | } | ||
| 90 | addtask compile_kernelmodules after do_compile before do_install | ||
| 91 | |||
| 92 | kernel_do_install() { | ||
| 93 | # | ||
| 94 | # First install the modules | ||
| 95 | # | ||
| 96 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE | ||
| 97 | if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then | ||
| 98 | oe_runmake DEPMOD=echo INSTALL_MOD_PATH="${D}" modules_install | ||
| 99 | else | ||
| 100 | oenote "no modules to install" | ||
| 101 | fi | ||
| 102 | |||
| 103 | # | ||
| 104 | # Install various kernel output (zImage, map file, config, module support files) | ||
| 105 | # | ||
| 106 | install -d ${D}/${KERNEL_IMAGEDEST} | ||
| 107 | install -d ${D}/boot | ||
| 108 | install -m 0644 ${KERNEL_OUTPUT} ${D}/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-${KERNEL_VERSION} | ||
| 109 | install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION} | ||
| 110 | install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION} | ||
| 111 | install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION} | ||
| 112 | [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION} | ||
| 113 | install -d ${D}/etc/modutils | ||
| 114 | if [ "${KERNEL_MAJOR_VERSION}" = "2.6" ]; then | ||
| 115 | install -d ${D}/etc/modprobe.d | ||
| 116 | fi | ||
| 117 | |||
| 118 | |||
| 119 | |||
| 120 | # | ||
| 121 | # Support for external module building - create a minimal copy of the kernel source tree | ||
| 122 | # | ||
| 123 | kerneldir=${D}/kernel/ | ||
| 124 | |||
| 125 | # Take care of arch specific headers | ||
| 126 | # Kernel 2.6.27 moved headers from includes/asm-${ARCH} to arch/${ARCH}/include/asm | ||
| 127 | if [ -e arch/${ARCH}/include/asm/ ] ; then | ||
| 128 | install -d $kerneldir/arch/${ARCH}/ | ||
| 129 | cp -fR arch/${ARCH}/* $kerneldir/arch/${ARCH}/ | ||
| 130 | |||
| 131 | # Check for arch/x86 on i386 | ||
| 132 | elif [ -d arch/x86/include/asm/ ]; then | ||
| 133 | if [ -e include/asm ] ; then | ||
| 134 | install -d $kerneldir/include/asm/ | ||
| 135 | cp -fR arch/x86/include/asm/* $kerneldir/include/asm/ | ||
| 136 | fi | ||
| 137 | install -d $kerneldir/arch/x86/include | ||
| 138 | cp -fR arch/x86/* $kerneldir/arch/x86/ | ||
| 139 | fi | ||
| 140 | |||
| 141 | # Take care of the rest of the main directories we need | ||
| 142 | for entry in drivers/crypto drivers/media include scripts; do | ||
| 143 | if [ -d $entry ]; then | ||
| 144 | mkdir -p $kerneldir/$entry | ||
| 145 | cp -fR $entry/* $kerneldir/$entry/ | ||
| 146 | fi | ||
| 147 | done | ||
| 148 | |||
| 149 | install -m 0644 .config $kerneldir/config-${KERNEL_VERSION} | ||
| 150 | ln -sf config-${KERNEL_VERSION} $kerneldir/.config | ||
| 151 | ln -sf config-${KERNEL_VERSION} $kerneldir/kernel-config | ||
| 152 | echo "${KERNEL_VERSION}" >$kerneldir/kernel-abiversion | ||
| 153 | echo "${S}" >$kerneldir/kernel-source | ||
| 154 | echo "${KERNEL_CCSUFFIX}" >$kerneldir/kernel-ccsuffix | ||
| 155 | echo "${KERNEL_LDSUFFIX}" >$kerneldir/kernel-ldsuffix | ||
| 156 | [ -e vmlinux ] && install -m 0644 vmlinux $kerneldir/ | ||
| 157 | install -m 0644 ${KERNEL_OUTPUT} $kerneldir/${KERNEL_IMAGETYPE} | ||
| 158 | install -m 0644 System.map $kerneldir/System.map-${KERNEL_VERSION} | ||
| 159 | [ -e Module.symvers ] && install -m 0644 Module.symvers $kerneldir/ | ||
| 160 | |||
| 161 | # Copy over the main Makefiles | ||
| 162 | [ -e Rules.make ] && install -m 0644 Rules.make $kerneldir/ | ||
| 163 | [ -e Makefile ] && install -m 0644 Makefile $kerneldir/ | ||
| 164 | # Check if arch/${ARCH}/Makefile exists and install it | ||
| 165 | if [ -e arch/${ARCH}/Makefile ]; then | ||
| 166 | install -d $kerneldir/arch/${ARCH} | ||
| 167 | install -m 0644 arch/${ARCH}/Makefile* $kerneldir/arch/${ARCH} | ||
| 168 | # Otherwise check arch/x86/Makefile for i386 and x86_64 on kernels >= 2.6.24 | ||
| 169 | elif [ -e arch/x86/Makefile ]; then | ||
| 170 | install -d $kerneldir/arch/x86 | ||
| 171 | install -m 0644 arch/x86/Makefile* $kerneldir/arch/x86 | ||
| 172 | fi | ||
| 173 | |||
| 174 | # Remove the following binaries which cause strip errors | ||
| 175 | # during do_package for cross-compiled platforms | ||
| 176 | bin_files="arch/powerpc/boot/addnote arch/powerpc/boot/hack-coff \ | ||
| 177 | arch/powerpc/boot/mktree scripts/bin2c scripts/conmakehash \ | ||
| 178 | scripts/ihex2fw scripts/kallsyms scripts/pnmtologo scripts/basic/docproc \ | ||
| 179 | scripts/basic/fixdep scripts/basic/hash scripts/dtc/dtc \ | ||
| 180 | scripts/genksyms/genksyms scripts/kconfig/conf scripts/mod/mk_elfconfig \ | ||
| 181 | scripts/mod/modpost" | ||
| 182 | rm -rf $kerneldir/scripts/*.o | ||
| 183 | rm -rf $kerneldir/scripts/basic/*.o | ||
| 184 | rm -rf $kerneldir/scripts/kconfig/*.o | ||
| 185 | rm -rf $kerneldir/scripts/mod/*.o | ||
| 186 | rm -rf $kerneldir/scripts/dtc/*.o | ||
| 187 | for entry in $bin_files; do | ||
| 188 | rm -f $kerneldir/$entry | ||
| 189 | done | ||
| 190 | } | ||
| 191 | |||
| 192 | sysroot_stage_all_append() { | ||
| 193 | sysroot_stage_dir ${D}/kernel ${SYSROOT_DESTDIR}${STAGING_KERNEL_DIR} | ||
| 194 | } | ||
| 195 | |||
| 196 | |||
| 197 | kernel_do_configure() { | ||
| 198 | yes '' | oe_runmake oldconfig | ||
| 199 | } | ||
| 200 | |||
| 201 | do_menuconfig() { | ||
| 202 | export TERMWINDOWTITLE="${PN} Kernel Configuration" | ||
| 203 | export SHELLCMDS="make menuconfig" | ||
| 204 | ${TERMCMDRUN} | ||
| 205 | if [ $? -ne 0 ]; then | ||
| 206 | echo "Fatal: '${TERMCMD}' not found. Check TERMCMD variable." | ||
| 207 | exit 1 | ||
| 208 | fi | ||
| 209 | } | ||
| 210 | do_menuconfig[nostamp] = "1" | ||
| 211 | addtask menuconfig after do_patch | ||
| 212 | |||
| 213 | pkg_postinst_kernel () { | ||
| 214 | cd /${KERNEL_IMAGEDEST}; update-alternatives --install /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE}-${KERNEL_VERSION} ${KERNEL_PRIORITY} || true | ||
| 215 | } | ||
| 216 | |||
| 217 | pkg_postrm_kernel () { | ||
| 218 | cd /${KERNEL_IMAGEDEST}; update-alternatives --remove ${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE}-${KERNEL_VERSION} || true | ||
| 219 | } | ||
| 220 | |||
| 221 | inherit cml1 | ||
| 222 | |||
| 223 | EXPORT_FUNCTIONS do_compile do_install do_configure | ||
| 224 | |||
| 225 | # kernel-base becomes kernel-${KERNEL_VERSION} | ||
| 226 | # kernel-image becomes kernel-image-${KERNEL_VERISON} | ||
| 227 | PACKAGES = "kernel kernel-base kernel-image kernel-dev kernel-vmlinux kernel-misc" | ||
| 228 | FILES = "" | ||
| 229 | FILES_kernel-image = "/boot/${KERNEL_IMAGETYPE}*" | ||
| 230 | FILES_kernel-dev = "/boot/System.map* /boot/Module.symvers* /boot/config*" | ||
| 231 | FILES_kernel-vmlinux = "/boot/vmlinux*" | ||
| 232 | # misc is a package to contain files we need in staging | ||
| 233 | FILES_kernel-misc = "/kernel/include/config /kernel/scripts /kernel/drivers/crypto /kernel/drivers/media" | ||
| 234 | RDEPENDS_kernel = "kernel-base" | ||
| 235 | # Allow machines to override this dependency if kernel image files are | ||
| 236 | # not wanted in images as standard | ||
| 237 | RDEPENDS_kernel-base ?= "kernel-image" | ||
| 238 | PKG_kernel-image = "kernel-image-${KERNEL_VERSION}" | ||
| 239 | PKG_kernel-base = "kernel-${KERNEL_VERSION}" | ||
| 240 | ALLOW_EMPTY_kernel = "1" | ||
| 241 | ALLOW_EMPTY_kernel-base = "1" | ||
| 242 | ALLOW_EMPTY_kernel-image = "1" | ||
| 243 | |||
| 244 | # Userspace workarounds for kernel modules issues | ||
| 245 | # This is shame, fix the kernel instead! | ||
| 246 | DEPENDS_kernel-module-dtl1-cs = "bluez-dtl1-workaround" | ||
| 247 | RDEPENDS_kernel-module-dtl1-cs = "bluez-dtl1-workaround" | ||
| 248 | |||
| 249 | pkg_postinst_kernel-image () { | ||
| 250 | if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then | ||
| 251 | mkdir -p $D/lib/modules/${KERNEL_VERSION} | ||
| 252 | fi | ||
| 253 | if [ -n "$D" ]; then | ||
| 254 | ${HOST_PREFIX}depmod-${KERNEL_MAJOR_VERSION} -A -b $D -F ${STAGING_KERNEL_DIR}/System.map-${KERNEL_VERSION} ${KERNEL_VERSION} | ||
| 255 | else | ||
| 256 | depmod -a | ||
| 257 | fi | ||
| 258 | } | ||
| 259 | |||
| 260 | pkg_postinst_modules () { | ||
| 261 | if [ -n "$D" ]; then | ||
| 262 | ${HOST_PREFIX}depmod-${KERNEL_MAJOR_VERSION} -A -b $D -F ${STAGING_KERNEL_DIR}/System.map-${KERNEL_VERSION} ${KERNEL_VERSION} | ||
| 263 | else | ||
| 264 | depmod -a | ||
| 265 | update-modules || true | ||
| 266 | fi | ||
| 267 | } | ||
| 268 | |||
| 269 | pkg_postrm_modules () { | ||
| 270 | update-modules || true | ||
| 271 | } | ||
| 272 | |||
| 273 | autoload_postinst_fragment() { | ||
| 274 | if [ x"$D" = "x" ]; then | ||
| 275 | modprobe %s || true | ||
| 276 | fi | ||
| 277 | } | ||
| 278 | |||
| 279 | # autoload defaults (alphabetically sorted) | ||
| 280 | module_autoload_hidp = "hidp" | ||
| 281 | module_autoload_ipv6 = "ipv6" | ||
| 282 | module_autoload_ipsec = "ipsec" | ||
| 283 | module_autoload_ircomm-tty = "ircomm-tty" | ||
| 284 | module_autoload_rfcomm = "rfcomm" | ||
| 285 | module_autoload_sa1100-rtc = "sa1100-rtc" | ||
| 286 | # sa1100-rtc was renamed in 2.6.23 onwards | ||
| 287 | module_autoload_rtc-sa1100 = "rtc-sa1100" | ||
| 288 | |||
| 289 | # alias defaults (alphabetically sorted) | ||
| 290 | module_conf_af_packet = "alias net-pf-17 af_packet" | ||
| 291 | module_conf_bluez = "alias net-pf-31 bluez" | ||
| 292 | module_conf_bnep = "alias bt-proto-4 bnep" | ||
| 293 | module_conf_hci_uart = "alias tty-ldisc-15 hci_uart" | ||
| 294 | module_conf_l2cap = "alias bt-proto-0 l2cap" | ||
| 295 | module_conf_sco = "alias bt-proto-2 sco" | ||
| 296 | module_conf_rfcomm = "alias bt-proto-3 rfcomm" | ||
| 297 | |||
| 298 | python populate_packages_prepend () { | ||
| 299 | def extract_modinfo(file): | ||
| 300 | import re | ||
| 301 | tmpfile = os.tmpnam() | ||
| 302 | 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) | ||
| 303 | os.system(cmd) | ||
| 304 | f = open(tmpfile) | ||
| 305 | l = f.read().split("\000") | ||
| 306 | f.close() | ||
| 307 | os.unlink(tmpfile) | ||
| 308 | exp = re.compile("([^=]+)=(.*)") | ||
| 309 | vals = {} | ||
| 310 | for i in l: | ||
| 311 | m = exp.match(i) | ||
| 312 | if not m: | ||
| 313 | continue | ||
| 314 | vals[m.group(1)] = m.group(2) | ||
| 315 | return vals | ||
| 316 | |||
| 317 | def parse_depmod(): | ||
| 318 | import re | ||
| 319 | |||
| 320 | dvar = bb.data.getVar('PKGD', d, 1) | ||
| 321 | if not dvar: | ||
| 322 | bb.error("PKGD not defined") | ||
| 323 | return | ||
| 324 | |||
| 325 | kernelver = bb.data.getVar('KERNEL_VERSION', d, 1) | ||
| 326 | kernelver_stripped = kernelver | ||
| 327 | m = re.match('^(.*-hh.*)[\.\+].*$', kernelver) | ||
| 328 | if m: | ||
| 329 | kernelver_stripped = m.group(1) | ||
| 330 | path = bb.data.getVar("PATH", d, 1) | ||
| 331 | host_prefix = bb.data.getVar("HOST_PREFIX", d, 1) or "" | ||
| 332 | major_version = bb.data.getVar('KERNEL_MAJOR_VERSION', d, 1) | ||
| 333 | |||
| 334 | 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) | ||
| 335 | f = os.popen(cmd, 'r') | ||
| 336 | |||
| 337 | deps = {} | ||
| 338 | pattern0 = "^(.*\.k?o):..*$" | ||
| 339 | pattern1 = "^(.*\.k?o):\s*(.*\.k?o)\s*$" | ||
| 340 | pattern2 = "^(.*\.k?o):\s*(.*\.k?o)\s*\\\$" | ||
| 341 | pattern3 = "^\t(.*\.k?o)\s*\\\$" | ||
| 342 | pattern4 = "^\t(.*\.k?o)\s*$" | ||
| 343 | |||
| 344 | line = f.readline() | ||
| 345 | while line: | ||
| 346 | if not re.match(pattern0, line): | ||
| 347 | line = f.readline() | ||
| 348 | continue | ||
| 349 | m1 = re.match(pattern1, line) | ||
| 350 | if m1: | ||
| 351 | deps[m1.group(1)] = m1.group(2).split() | ||
| 352 | else: | ||
| 353 | m2 = re.match(pattern2, line) | ||
| 354 | if m2: | ||
| 355 | deps[m2.group(1)] = m2.group(2).split() | ||
| 356 | line = f.readline() | ||
| 357 | m3 = re.match(pattern3, line) | ||
| 358 | while m3: | ||
| 359 | deps[m2.group(1)].extend(m3.group(1).split()) | ||
| 360 | line = f.readline() | ||
| 361 | m3 = re.match(pattern3, line) | ||
| 362 | m4 = re.match(pattern4, line) | ||
| 363 | deps[m2.group(1)].extend(m4.group(1).split()) | ||
| 364 | line = f.readline() | ||
| 365 | f.close() | ||
| 366 | return deps | ||
| 367 | |||
| 368 | def get_dependencies(file, pattern, format): | ||
| 369 | # file no longer includes PKGD | ||
| 370 | file = file.replace(bb.data.getVar('PKGD', d, 1) or '', '', 1) | ||
| 371 | # instead is prefixed with /lib/modules/${KERNEL_VERSION} | ||
| 372 | file = file.replace("/lib/modules/%s/" % bb.data.getVar('KERNEL_VERSION', d, 1) or '', '', 1) | ||
| 373 | |||
| 374 | if module_deps.has_key(file): | ||
| 375 | import re | ||
| 376 | dependencies = [] | ||
| 377 | for i in module_deps[file]: | ||
| 378 | m = re.match(pattern, os.path.basename(i)) | ||
| 379 | if not m: | ||
| 380 | continue | ||
| 381 | on = legitimize_package_name(m.group(1)) | ||
| 382 | dependency_pkg = format % on | ||
| 383 | dependencies.append(dependency_pkg) | ||
| 384 | return dependencies | ||
| 385 | return [] | ||
| 386 | |||
| 387 | def frob_metadata(file, pkg, pattern, format, basename): | ||
| 388 | import re | ||
| 389 | vals = extract_modinfo(file) | ||
| 390 | |||
| 391 | dvar = bb.data.getVar('PKGD', d, 1) | ||
| 392 | |||
| 393 | # If autoloading is requested, output /etc/modutils/<name> and append | ||
| 394 | # appropriate modprobe commands to the postinst | ||
| 395 | autoload = bb.data.getVar('module_autoload_%s' % basename, d, 1) | ||
| 396 | if autoload: | ||
| 397 | name = '%s/etc/modutils/%s' % (dvar, basename) | ||
| 398 | f = open(name, 'w') | ||
| 399 | for m in autoload.split(): | ||
| 400 | f.write('%s\n' % m) | ||
| 401 | f.close() | ||
| 402 | postinst = bb.data.getVar('pkg_postinst_%s' % pkg, d, 1) | ||
| 403 | if not postinst: | ||
| 404 | bb.fatal("pkg_postinst_%s not defined" % pkg) | ||
| 405 | postinst += bb.data.getVar('autoload_postinst_fragment', d, 1) % autoload | ||
| 406 | bb.data.setVar('pkg_postinst_%s' % pkg, postinst, d) | ||
| 407 | |||
| 408 | # Write out any modconf fragment | ||
| 409 | modconf = bb.data.getVar('module_conf_%s' % basename, d, 1) | ||
| 410 | if modconf: | ||
| 411 | if bb.data.getVar("KERNEL_MAJOR_VERSION", d, 1) == "2.6": | ||
| 412 | name = '%s/etc/modprobe.d/%s.conf' % (dvar, basename) | ||
| 413 | else: | ||
| 414 | name = '%s/etc/modutils/%s.conf' % (dvar, basename) | ||
| 415 | f = open(name, 'w') | ||
| 416 | f.write("%s\n" % modconf) | ||
| 417 | f.close() | ||
| 418 | |||
| 419 | files = bb.data.getVar('FILES_%s' % pkg, d, 1) | ||
| 420 | files = "%s /etc/modutils/%s /etc/modutils/%s.conf /etc/modprobe.d/%s.conf" % (files, basename, basename, basename) | ||
| 421 | bb.data.setVar('FILES_%s' % pkg, files, d) | ||
| 422 | |||
| 423 | if vals.has_key("description"): | ||
| 424 | old_desc = bb.data.getVar('DESCRIPTION_' + pkg, d, 1) or "" | ||
| 425 | bb.data.setVar('DESCRIPTION_' + pkg, old_desc + "; " + vals["description"], d) | ||
| 426 | |||
| 427 | rdepends_str = bb.data.getVar('RDEPENDS_' + pkg, d, 1) | ||
| 428 | if rdepends_str: | ||
| 429 | rdepends = rdepends_str.split() | ||
| 430 | else: | ||
| 431 | rdepends = [] | ||
| 432 | rdepends.extend(get_dependencies(file, pattern, format)) | ||
| 433 | bb.data.setVar('RDEPENDS_' + pkg, ' '.join(rdepends), d) | ||
| 434 | |||
| 435 | module_deps = parse_depmod() | ||
| 436 | module_regex = '^(.*)\.k?o$' | ||
| 437 | module_pattern = 'kernel-module-%s' | ||
| 438 | |||
| 439 | postinst = bb.data.getVar('pkg_postinst_modules', d, 1) | ||
| 440 | postrm = bb.data.getVar('pkg_postrm_modules', d, 1) | ||
| 441 | do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.bin$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') | ||
| 442 | do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.fw$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') | ||
| 443 | 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-%s' % bb.data.getVar("KERNEL_VERSION", d, 1)) | ||
| 444 | |||
| 445 | import re | ||
| 446 | metapkg = "kernel-modules" | ||
| 447 | bb.data.setVar('ALLOW_EMPTY_' + metapkg, "1", d) | ||
| 448 | bb.data.setVar('FILES_' + metapkg, "", d) | ||
| 449 | blacklist = [ 'kernel-dev', 'kernel-image', 'kernel-base', 'kernel-vmlinux' ] | ||
| 450 | for l in module_deps.values(): | ||
| 451 | for i in l: | ||
| 452 | pkg = module_pattern % legitimize_package_name(re.match(module_regex, os.path.basename(i)).group(1)) | ||
| 453 | blacklist.append(pkg) | ||
| 454 | metapkg_rdepends = [] | ||
| 455 | packages = bb.data.getVar('PACKAGES', d, 1).split() | ||
| 456 | for pkg in packages[1:]: | ||
| 457 | if not pkg in blacklist and not pkg in metapkg_rdepends: | ||
| 458 | metapkg_rdepends.append(pkg) | ||
| 459 | bb.data.setVar('RDEPENDS_' + metapkg, ' '.join(metapkg_rdepends), d) | ||
| 460 | bb.data.setVar('DESCRIPTION_' + metapkg, 'Kernel modules meta package', d) | ||
| 461 | packages.append(metapkg) | ||
| 462 | bb.data.setVar('PACKAGES', ' '.join(packages), d) | ||
| 463 | } | ||
| 464 | |||
| 465 | # Support checking the kernel size since some kernels need to reside in partitions | ||
| 466 | # with a fixed length or there is a limit in transferring the kernel to memory | ||
| 467 | do_sizecheck() { | ||
| 468 | if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then | ||
| 469 | size=`ls -l arch/${ARCH}/boot/${KERNEL_IMAGETYPE} | awk '{ print $5}'` | ||
| 470 | if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then | ||
| 471 | rm arch/${ARCH}/boot/${KERNEL_IMAGETYPE} | ||
| 472 | die "This kernel (size=$size > ${KERNEL_IMAGE_MAXSIZE}) is too big for your device. Please reduce the size of the kernel by making more of it modular." | ||
| 473 | fi | ||
| 474 | fi | ||
| 475 | } | ||
| 476 | |||
| 477 | addtask sizecheck before do_install after do_compile | ||
| 478 | |||
| 479 | KERNEL_IMAGE_BASE_NAME ?= "${KERNEL_IMAGETYPE}-${PV}-${PR}-${MACHINE}-${DATETIME}" | ||
| 480 | KERNEL_IMAGE_SYMLINK_NAME ?= "${KERNEL_IMAGETYPE}-${MACHINE}" | ||
| 481 | |||
| 482 | do_deploy() { | ||
| 483 | install -m 0644 arch/${ARCH}/boot/${KERNEL_IMAGETYPE} ${DEPLOYDIR}/${KERNEL_IMAGE_BASE_NAME}.bin | ||
| 484 | if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then | ||
| 485 | tar -cvzf ${DEPLOYDIR}/modules-${KERNEL_VERSION}-${PR}-${MACHINE}.tgz -C ${D} lib | ||
| 486 | fi | ||
| 487 | |||
| 488 | if test "x${KERNEL_IMAGETYPE}" = "xuImage" ; then | ||
| 489 | if test -e arch/${ARCH}/boot/compressed/vmlinux ; then | ||
| 490 | ${OBJCOPY} -O binary -R .note -R .comment -S arch/${ARCH}/boot/compressed/vmlinux linux.bin | ||
| 491 | uboot-mkimage -A ${ARCH} -O linux -T kernel -C none -a ${UBOOT_ENTRYPOINT} -e ${UBOOT_ENTRYPOINT} -n "${DISTRO_NAME}/${PV}/${MACHINE}" -d linux.bin ${DEPLOYDIR}/uImage-${PV}-${PR}-${MACHINE}-${DATETIME}.bin | ||
| 492 | rm -f linux.bin | ||
| 493 | else | ||
| 494 | ${OBJCOPY} -O binary -R .note -R .comment -S vmlinux linux.bin | ||
| 495 | rm -f linux.bin.gz | ||
| 496 | gzip -9 linux.bin | ||
| 497 | uboot-mkimage -A ${ARCH} -O linux -T kernel -C gzip -a ${UBOOT_ENTRYPOINT} -e ${UBOOT_ENTRYPOINT} -n "${DISTRO_NAME}/${PV}/${MACHINE}" -d linux.bin.gz ${DEPLOYDIR}/uImage-${PV}-${PR}-${MACHINE}-${DATETIME}.bin | ||
| 498 | rm -f linux.bin.gz | ||
| 499 | fi | ||
| 500 | fi | ||
| 501 | |||
| 502 | cd ${DEPLOYDIR} | ||
| 503 | rm -f ${KERNEL_IMAGE_SYMLINK_NAME}.bin | ||
| 504 | ln -sf ${KERNEL_IMAGE_BASE_NAME}.bin ${KERNEL_IMAGE_SYMLINK_NAME}.bin | ||
| 505 | } | ||
| 506 | do_deploy[dirs] = "${DEPLOYDIR} ${B}" | ||
| 507 | |||
| 508 | addtask deploy before do_package after do_install | ||
| 509 | |||
| 510 | # perf must be enabled in individual kernel recipes | ||
| 511 | PACKAGES =+ "perf" | ||
| 512 | FILES_perf = "${bindir}/* \ | ||
| 513 | ${libexecdir}" | ||
