Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | inherit linux-kernel-base kernel-module-split |
| 2 | |
| 3 | PROVIDES += "virtual/kernel" |
| 4 | DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native depmodwrapper-cross bc-native" |
| 5 | |
| 6 | S = "${STAGING_KERNEL_DIR}" |
| 7 | B = "${WORKDIR}/build" |
| 8 | KBUILD_OUTPUT = "${B}" |
| 9 | OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT" |
| 10 | |
| 11 | # we include gcc above, we dont need virtual/libc |
| 12 | INHIBIT_DEFAULT_DEPS = "1" |
| 13 | |
| 14 | KERNEL_IMAGETYPE ?= "zImage" |
| 15 | INITRAMFS_IMAGE ?= "" |
| 16 | INITRAMFS_TASK ?= "" |
| 17 | INITRAMFS_IMAGE_BUNDLE ?= "" |
| 18 | |
| 19 | python __anonymous () { |
| 20 | import re |
| 21 | |
| 22 | kerneltype = d.getVar('KERNEL_IMAGETYPE', True) |
| 23 | |
| 24 | d.setVar("KERNEL_IMAGETYPE_FOR_MAKE", re.sub(r'\.gz$', '', kerneltype)) |
| 25 | |
| 26 | image = d.getVar('INITRAMFS_IMAGE', True) |
| 27 | if image: |
| 28 | d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_rootfs') |
| 29 | |
| 30 | # NOTE: setting INITRAMFS_TASK is for backward compatibility |
| 31 | # The preferred method is to set INITRAMFS_IMAGE, because |
| 32 | # this INITRAMFS_TASK has circular dependency problems |
| 33 | # if the initramfs requires kernel modules |
| 34 | image_task = d.getVar('INITRAMFS_TASK', True) |
| 35 | if image_task: |
| 36 | d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}') |
| 37 | } |
| 38 | |
| 39 | # Here we pull in all various kernel image types which we support. |
| 40 | # |
| 41 | # In case you're wondering why kernel.bbclass inherits the other image |
| 42 | # types instead of the other way around, the reason for that is to |
| 43 | # maintain compatibility with various currently existing meta-layers. |
| 44 | # By pulling in the various kernel image types here, we retain the |
| 45 | # original behavior of kernel.bbclass, so no meta-layers should get |
| 46 | # broken. |
| 47 | # |
| 48 | # KERNEL_CLASSES by default pulls in kernel-uimage.bbclass, since this |
| 49 | # used to be the default behavior when only uImage was supported. This |
| 50 | # variable can be appended by users who implement support for new kernel |
| 51 | # image types. |
| 52 | |
| 53 | KERNEL_CLASSES ?= " kernel-uimage " |
| 54 | inherit ${KERNEL_CLASSES} |
| 55 | |
| 56 | # Old style kernels may set ${S} = ${WORKDIR}/git for example |
| 57 | # We need to move these over to STAGING_KERNEL_DIR. We can't just |
| 58 | # create the symlink in advance as the git fetcher can't cope with |
| 59 | # the symlink. |
| 60 | do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}" |
| 61 | do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}" |
| 62 | base_do_unpack_append () { |
| 63 | s = d.getVar("S", True) |
| 64 | if s[-1] == '/': |
| 65 | # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as directory name and fail |
| 66 | s=s[:-1] |
| 67 | kernsrc = d.getVar("STAGING_KERNEL_DIR", True) |
| 68 | if s != kernsrc: |
| 69 | bb.utils.mkdirhier(kernsrc) |
| 70 | bb.utils.remove(kernsrc, recurse=True) |
| 71 | if d.getVar("EXTERNALSRC", True): |
| 72 | # With EXTERNALSRC S will not be wiped so we can symlink to it |
| 73 | os.symlink(s, kernsrc) |
| 74 | else: |
| 75 | import shutil |
| 76 | shutil.move(s, kernsrc) |
| 77 | os.symlink(kernsrc, s) |
| 78 | } |
| 79 | |
| 80 | inherit kernel-arch deploy |
| 81 | |
| 82 | PACKAGES_DYNAMIC += "^kernel-module-.*" |
| 83 | PACKAGES_DYNAMIC += "^kernel-image-.*" |
| 84 | PACKAGES_DYNAMIC += "^kernel-firmware-.*" |
| 85 | |
| 86 | export OS = "${TARGET_OS}" |
| 87 | export CROSS_COMPILE = "${TARGET_PREFIX}" |
| 88 | |
| 89 | KERNEL_PRIORITY ?= "${@int(d.getVar('PV',1).split('-')[0].split('+')[0].split('.')[0]) * 10000 + \ |
| 90 | int(d.getVar('PV',1).split('-')[0].split('+')[0].split('.')[1]) * 100 + \ |
| 91 | int(d.getVar('PV',1).split('-')[0].split('+')[0].split('.')[-1])}" |
| 92 | |
| 93 | KERNEL_RELEASE ?= "${KERNEL_VERSION}" |
| 94 | |
| 95 | # Where built kernel lies in the kernel tree |
| 96 | KERNEL_OUTPUT ?= "arch/${ARCH}/boot/${KERNEL_IMAGETYPE}" |
| 97 | KERNEL_IMAGEDEST = "boot" |
| 98 | |
| 99 | # |
| 100 | # configuration |
| 101 | # |
| 102 | export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE",1) or "ttyS0"}" |
| 103 | |
| 104 | KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}" |
| 105 | |
| 106 | KERNEL_LOCALVERSION ?= "" |
| 107 | |
| 108 | # kernels are generally machine specific |
| 109 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 110 | |
| 111 | # U-Boot support |
| 112 | UBOOT_ENTRYPOINT ?= "20008000" |
| 113 | UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}" |
| 114 | |
| 115 | # Some Linux kernel configurations need additional parameters on the command line |
| 116 | KERNEL_EXTRA_ARGS ?= "" |
| 117 | |
| 118 | # For the kernel, we don't want the '-e MAKEFLAGS=' in EXTRA_OEMAKE. |
| 119 | # We don't want to override kernel Makefile variables from the environment |
| 120 | EXTRA_OEMAKE = "" |
| 121 | |
| 122 | KERNEL_ALT_IMAGETYPE ??= "" |
| 123 | |
| 124 | # Define where the kernel headers are installed on the target as well as where |
| 125 | # they are staged. |
| 126 | KERNEL_SRC_PATH = "/usr/src/kernel" |
| 127 | |
| 128 | copy_initramfs() { |
| 129 | echo "Copying initramfs into ./usr ..." |
| 130 | # In case the directory is not created yet from the first pass compile: |
| 131 | mkdir -p ${B}/usr |
| 132 | # Find and use the first initramfs image archive type we find |
| 133 | rm -f ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio |
| 134 | for img in cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz; do |
| 135 | if [ -e "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.$img" ]; then |
| 136 | cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.$img ${B}/usr/. |
| 137 | case $img in |
| 138 | *gz) |
| 139 | echo "gzip decompressing image" |
| 140 | gunzip -f ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img |
| 141 | break |
| 142 | ;; |
| 143 | *lz4) |
| 144 | echo "lz4 decompressing image" |
| 145 | lz4 -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img |
| 146 | break |
| 147 | ;; |
| 148 | *lzo) |
| 149 | echo "lzo decompressing image" |
| 150 | lzop -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img |
| 151 | break |
| 152 | ;; |
| 153 | *lzma) |
| 154 | echo "lzma decompressing image" |
| 155 | lzma -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img |
| 156 | break |
| 157 | ;; |
| 158 | *xz) |
| 159 | echo "xz decompressing image" |
| 160 | xz -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img |
| 161 | break |
| 162 | ;; |
| 163 | esac |
| 164 | fi |
| 165 | done |
| 166 | echo "Finished copy of initramfs into ./usr" |
| 167 | } |
| 168 | |
| 169 | INITRAMFS_BASE_NAME = "${KERNEL_IMAGETYPE}-initramfs-${PV}-${PR}-${MACHINE}-${DATETIME}" |
| 170 | INITRAMFS_BASE_NAME[vardepsexclude] = "DATETIME" |
| 171 | do_bundle_initramfs () { |
| 172 | if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then |
| 173 | echo "Creating a kernel image with a bundled initramfs..." |
| 174 | copy_initramfs |
| 175 | if [ -e ${KERNEL_OUTPUT} ] ; then |
| 176 | mv -f ${KERNEL_OUTPUT} ${KERNEL_OUTPUT}.bak |
| 177 | fi |
| 178 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio |
| 179 | kernel_do_compile |
| 180 | mv -f ${KERNEL_OUTPUT} ${KERNEL_OUTPUT}.initramfs |
| 181 | mv -f ${KERNEL_OUTPUT}.bak ${KERNEL_OUTPUT} |
| 182 | # Update install area |
| 183 | echo "There is kernel image bundled with initramfs: ${B}/${KERNEL_OUTPUT}.initramfs" |
| 184 | install -m 0644 ${B}/${KERNEL_OUTPUT}.initramfs ${D}/boot/${KERNEL_IMAGETYPE}-initramfs-${MACHINE}.bin |
| 185 | echo "${B}/${KERNEL_OUTPUT}.initramfs" |
| 186 | fi |
| 187 | } |
| 188 | |
| 189 | python do_devshell_prepend () { |
| 190 | os.environ["LDFLAGS"] = '' |
| 191 | } |
| 192 | |
| 193 | addtask bundle_initramfs after do_install before do_deploy |
| 194 | |
| 195 | kernel_do_compile() { |
| 196 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
| 197 | # The $use_alternate_initrd is only set from |
| 198 | # do_bundle_initramfs() This variable is specifically for the |
| 199 | # case where we are making a second pass at the kernel |
| 200 | # compilation and we want to force the kernel build to use a |
| 201 | # different initramfs image. The way to do that in the kernel |
| 202 | # is to specify: |
| 203 | # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio |
| 204 | if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then |
| 205 | # The old style way of copying an prebuilt image and building it |
| 206 | # is turned on via INTIRAMFS_TASK != "" |
| 207 | copy_initramfs |
| 208 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio |
| 209 | fi |
| 210 | oe_runmake ${KERNEL_IMAGETYPE_FOR_MAKE} ${KERNEL_ALT_IMAGETYPE} CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd |
| 211 | if test "${KERNEL_IMAGETYPE_FOR_MAKE}.gz" = "${KERNEL_IMAGETYPE}"; then |
| 212 | gzip -9c < "${KERNEL_IMAGETYPE_FOR_MAKE}" > "${KERNEL_OUTPUT}" |
| 213 | fi |
| 214 | } |
| 215 | |
| 216 | do_compile_kernelmodules() { |
| 217 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
| 218 | if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then |
| 219 | oe_runmake -C ${B} ${PARALLEL_MAKE} modules CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} |
| 220 | else |
| 221 | bbnote "no modules to compile" |
| 222 | fi |
| 223 | } |
| 224 | addtask compile_kernelmodules after do_compile before do_strip |
| 225 | |
| 226 | kernel_do_install() { |
| 227 | # |
| 228 | # First install the modules |
| 229 | # |
| 230 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
| 231 | if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then |
| 232 | oe_runmake DEPMOD=echo INSTALL_MOD_PATH="${D}" modules_install |
| 233 | rm "${D}/lib/modules/${KERNEL_VERSION}/build" |
| 234 | rm "${D}/lib/modules/${KERNEL_VERSION}/source" |
| 235 | # If the kernel/ directory is empty remove it to prevent QA issues |
| 236 | rmdir --ignore-fail-on-non-empty "${D}/lib/modules/${KERNEL_VERSION}/kernel" |
| 237 | else |
| 238 | bbnote "no modules to install" |
| 239 | fi |
| 240 | |
| 241 | # |
| 242 | # Install various kernel output (zImage, map file, config, module support files) |
| 243 | # |
| 244 | install -d ${D}/${KERNEL_IMAGEDEST} |
| 245 | install -d ${D}/boot |
| 246 | install -m 0644 ${KERNEL_OUTPUT} ${D}/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-${KERNEL_VERSION} |
| 247 | install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION} |
| 248 | install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION} |
| 249 | install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION} |
| 250 | [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION} |
| 251 | install -d ${D}${sysconfdir}/modules-load.d |
| 252 | install -d ${D}${sysconfdir}/modprobe.d |
| 253 | } |
| 254 | do_install[prefuncs] += "package_get_auto_pr" |
| 255 | |
| 256 | addtask shared_workdir after do_compile before do_compile_kernelmodules |
| 257 | addtask shared_workdir_setscene |
| 258 | |
| 259 | do_shared_workdir_setscene () { |
| 260 | exit 1 |
| 261 | } |
| 262 | |
| 263 | emit_depmod_pkgdata() { |
| 264 | # Stash data for depmod |
| 265 | install -d ${PKGDESTWORK}/kernel-depmod/ |
| 266 | echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/kernel-depmod/kernel-abiversion |
| 267 | cp ${B}/System.map ${PKGDESTWORK}/kernel-depmod/System.map-${KERNEL_VERSION} |
| 268 | } |
| 269 | |
| 270 | PACKAGEFUNCS += "emit_depmod_pkgdata" |
| 271 | |
| 272 | do_shared_workdir () { |
| 273 | cd ${B} |
| 274 | |
| 275 | kerneldir=${STAGING_KERNEL_BUILDDIR} |
| 276 | install -d $kerneldir |
| 277 | |
| 278 | # |
| 279 | # Store the kernel version in sysroots for module-base.bbclass |
| 280 | # |
| 281 | |
| 282 | echo "${KERNEL_VERSION}" > $kerneldir/kernel-abiversion |
| 283 | |
| 284 | # Copy files required for module builds |
| 285 | cp System.map $kerneldir/System.map-${KERNEL_VERSION} |
| 286 | cp Module.symvers $kerneldir/ |
| 287 | cp .config $kerneldir/ |
| 288 | mkdir -p $kerneldir/include/config |
| 289 | cp include/config/kernel.release $kerneldir/include/config/kernel.release |
| 290 | |
| 291 | # We can also copy over all the generated files and avoid special cases |
| 292 | # like version.h, but we've opted to keep this small until file creep starts |
| 293 | # to happen |
| 294 | if [ -e include/linux/version.h ]; then |
| 295 | mkdir -p $kerneldir/include/linux |
| 296 | cp include/linux/version.h $kerneldir/include/linux/version.h |
| 297 | fi |
| 298 | |
| 299 | # As of Linux kernel version 3.0.1, the clean target removes |
| 300 | # arch/powerpc/lib/crtsavres.o which is present in |
| 301 | # KBUILD_LDFLAGS_MODULE, making it required to build external modules. |
| 302 | if [ ${ARCH} = "powerpc" ]; then |
| 303 | mkdir -p $kerneldir/arch/powerpc/lib/ |
| 304 | cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o |
| 305 | fi |
| 306 | |
| 307 | if [ -d include/generated ]; then |
| 308 | mkdir -p $kerneldir/include/generated/ |
| 309 | cp -fR include/generated/* $kerneldir/include/generated/ |
| 310 | fi |
| 311 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 312 | # When ARCH is set to i386 or x86_64, we need to map ARCH to the real name of src |
| 313 | # dir (x86) under arch/ of kenrel tree, so that we can find correct source to copy. |
| 314 | |
| 315 | if [ "${ARCH}" = "i386" ] || [ "${ARCH}" = "x86_64" ]; then |
| 316 | KERNEL_SRCARCH=x86 |
| 317 | else |
| 318 | KERNEL_SRCARCH=${ARCH} |
| 319 | fi |
| 320 | |
| 321 | if [ -d arch/${KERNEL_SRCARCH}/include/generated ]; then |
| 322 | mkdir -p $kerneldir/arch/${KERNEL_SRCARCH}/include/generated/ |
| 323 | cp -fR arch/${KERNEL_SRCARCH}/include/generated/* $kerneldir/arch/${KERNEL_SRCARCH}/include/generated/ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 324 | fi |
| 325 | } |
| 326 | |
| 327 | # We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware |
| 328 | sysroot_stage_all () { |
| 329 | : |
| 330 | } |
| 331 | |
| 332 | KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} O=${B} oldnoconfig || yes '' | oe_runmake -C ${S} O=${B} oldconfig" |
| 333 | |
| 334 | kernel_do_configure() { |
| 335 | # fixes extra + in /lib/modules/2.6.37+ |
| 336 | # $ scripts/setlocalversion . => + |
| 337 | # $ make kernelversion => 2.6.37 |
| 338 | # $ make kernelrelease => 2.6.37+ |
| 339 | touch ${B}/.scmversion ${S}/.scmversion |
| 340 | |
| 341 | if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then |
| 342 | mv "${S}/.config" "${B}/.config" |
| 343 | fi |
| 344 | |
| 345 | # Copy defconfig to .config if .config does not exist. This allows |
| 346 | # recipes to manage the .config themselves in do_configure_prepend(). |
| 347 | if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then |
| 348 | cp "${WORKDIR}/defconfig" "${B}/.config" |
| 349 | fi |
| 350 | eval ${KERNEL_CONFIG_COMMAND} |
| 351 | } |
| 352 | |
| 353 | do_savedefconfig() { |
| 354 | oe_runmake -C ${B} savedefconfig |
| 355 | } |
| 356 | do_savedefconfig[nostamp] = "1" |
| 357 | addtask savedefconfig after do_configure |
| 358 | |
| 359 | inherit cml1 |
| 360 | |
| 361 | EXPORT_FUNCTIONS do_compile do_install do_configure |
| 362 | |
| 363 | # kernel-base becomes kernel-${KERNEL_VERSION} |
| 364 | # kernel-image becomes kernel-image-${KERNEL_VERISON} |
| 365 | PACKAGES = "kernel kernel-base kernel-vmlinux kernel-image kernel-dev kernel-modules" |
| 366 | FILES_${PN} = "" |
| 367 | FILES_kernel-base = "/lib/modules/${KERNEL_VERSION}/modules.order /lib/modules/${KERNEL_VERSION}/modules.builtin" |
| 368 | FILES_kernel-image = "/boot/${KERNEL_IMAGETYPE}*" |
| 369 | FILES_kernel-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} /lib/modules/${KERNEL_VERSION}/build" |
| 370 | FILES_kernel-vmlinux = "/boot/vmlinux*" |
| 371 | FILES_kernel-modules = "" |
| 372 | RDEPENDS_kernel = "kernel-base" |
| 373 | # Allow machines to override this dependency if kernel image files are |
| 374 | # not wanted in images as standard |
| 375 | RDEPENDS_kernel-base ?= "kernel-image" |
| 376 | PKG_kernel-image = "kernel-image-${@legitimize_package_name('${KERNEL_VERSION}')}" |
| 377 | RDEPENDS_kernel-image += "${@base_conditional('KERNEL_IMAGETYPE', 'vmlinux', 'kernel-vmlinux', '', d)}" |
| 378 | PKG_kernel-base = "kernel-${@legitimize_package_name('${KERNEL_VERSION}')}" |
| 379 | RPROVIDES_kernel-base += "kernel-${KERNEL_VERSION}" |
| 380 | ALLOW_EMPTY_kernel = "1" |
| 381 | ALLOW_EMPTY_kernel-base = "1" |
| 382 | ALLOW_EMPTY_kernel-image = "1" |
| 383 | ALLOW_EMPTY_kernel-modules = "1" |
| 384 | DESCRIPTION_kernel-modules = "Kernel modules meta package" |
| 385 | |
| 386 | pkg_postinst_kernel-base () { |
| 387 | if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then |
| 388 | mkdir -p $D/lib/modules/${KERNEL_VERSION} |
| 389 | fi |
| 390 | if [ -n "$D" ]; then |
| 391 | depmodwrapper -a -b $D ${KERNEL_VERSION} |
| 392 | else |
| 393 | depmod -a ${KERNEL_VERSION} |
| 394 | fi |
| 395 | } |
| 396 | |
| 397 | pkg_postinst_kernel-image () { |
| 398 | update-alternatives --install /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE} /${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-${KERNEL_VERSION} ${KERNEL_PRIORITY} || true |
| 399 | } |
| 400 | |
| 401 | pkg_postrm_kernel-image () { |
| 402 | update-alternatives --remove ${KERNEL_IMAGETYPE} ${KERNEL_IMAGETYPE}-${KERNEL_VERSION} || true |
| 403 | } |
| 404 | |
| 405 | PACKAGESPLITFUNCS_prepend = "split_kernel_packages " |
| 406 | |
| 407 | python split_kernel_packages () { |
| 408 | do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.(bin|fw|cis|dsp)$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') |
| 409 | } |
| 410 | |
| 411 | do_strip() { |
| 412 | if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then |
| 413 | if [ "${KERNEL_IMAGETYPE}" != "vmlinux" ]; then |
| 414 | bbwarn "image type will not be stripped (not supported): ${KERNEL_IMAGETYPE}" |
| 415 | return |
| 416 | fi |
| 417 | |
| 418 | cd ${B} |
| 419 | headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT} | \ |
| 420 | grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \ |
| 421 | sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \ |
| 422 | gawk '{print $1}'` |
| 423 | |
| 424 | for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do { |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 425 | if ! (echo "$headers" | grep -q "^$str$"); then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 426 | bbwarn "Section not found: $str"; |
| 427 | fi |
| 428 | |
| 429 | "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT} |
| 430 | }; done |
| 431 | |
| 432 | bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \ |
| 433 | "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" |
| 434 | fi; |
| 435 | } |
| 436 | do_strip[dirs] = "${B}" |
| 437 | |
| 438 | addtask do_strip before do_sizecheck after do_kernel_link_vmlinux |
| 439 | |
| 440 | # Support checking the kernel size since some kernels need to reside in partitions |
| 441 | # with a fixed length or there is a limit in transferring the kernel to memory |
| 442 | do_sizecheck() { |
| 443 | if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then |
| 444 | invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'` |
| 445 | if [ -n "$invalid" ]; then |
| 446 | die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integerx (The unit is Kbytes)" |
| 447 | fi |
| 448 | size=`du -ks ${B}/${KERNEL_OUTPUT} | awk '{ print $1}'` |
| 449 | if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then |
| 450 | die "This kernel (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device. Please reduce the size of the kernel by making more of it modular." |
| 451 | fi |
| 452 | fi |
| 453 | } |
| 454 | do_sizecheck[dirs] = "${B}" |
| 455 | |
| 456 | addtask sizecheck before do_install after do_strip |
| 457 | |
| 458 | KERNEL_IMAGE_BASE_NAME ?= "${KERNEL_IMAGETYPE}-${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}" |
| 459 | # Don't include the DATETIME variable in the sstate package signatures |
| 460 | KERNEL_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME" |
| 461 | KERNEL_IMAGE_SYMLINK_NAME ?= "${KERNEL_IMAGETYPE}-${MACHINE}" |
| 462 | MODULE_IMAGE_BASE_NAME ?= "modules-${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}" |
| 463 | MODULE_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME" |
| 464 | MODULE_TARBALL_BASE_NAME ?= "${MODULE_IMAGE_BASE_NAME}.tgz" |
| 465 | # Don't include the DATETIME variable in the sstate package signatures |
| 466 | MODULE_TARBALL_SYMLINK_NAME ?= "modules-${MACHINE}.tgz" |
| 467 | MODULE_TARBALL_DEPLOY ?= "1" |
| 468 | |
| 469 | kernel_do_deploy() { |
| 470 | install -m 0644 ${KERNEL_OUTPUT} ${DEPLOYDIR}/${KERNEL_IMAGE_BASE_NAME}.bin |
| 471 | if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then |
| 472 | mkdir -p ${D}/lib |
| 473 | tar -cvzf ${DEPLOYDIR}/${MODULE_TARBALL_BASE_NAME} -C ${D} lib |
| 474 | ln -sf ${MODULE_TARBALL_BASE_NAME} ${DEPLOYDIR}/${MODULE_TARBALL_SYMLINK_NAME} |
| 475 | fi |
| 476 | |
| 477 | ln -sf ${KERNEL_IMAGE_BASE_NAME}.bin ${DEPLOYDIR}/${KERNEL_IMAGE_SYMLINK_NAME}.bin |
| 478 | ln -sf ${KERNEL_IMAGE_BASE_NAME}.bin ${DEPLOYDIR}/${KERNEL_IMAGETYPE} |
| 479 | |
| 480 | cp ${COREBASE}/meta/files/deploydir_readme.txt ${DEPLOYDIR}/README_-_DO_NOT_DELETE_FILES_IN_THIS_DIRECTORY.txt |
| 481 | |
| 482 | cd ${B} |
| 483 | # Update deploy directory |
| 484 | if [ -e "${KERNEL_OUTPUT}.initramfs" ]; then |
| 485 | echo "Copying deploy kernel-initramfs image and setting up links..." |
| 486 | initramfs_base_name=${INITRAMFS_BASE_NAME} |
| 487 | initramfs_symlink_name=${KERNEL_IMAGETYPE}-initramfs-${MACHINE} |
| 488 | install -m 0644 ${KERNEL_OUTPUT}.initramfs ${DEPLOYDIR}/${initramfs_base_name}.bin |
| 489 | cd ${DEPLOYDIR} |
| 490 | ln -sf ${initramfs_base_name}.bin ${initramfs_symlink_name}.bin |
| 491 | fi |
| 492 | } |
| 493 | do_deploy[dirs] = "${DEPLOYDIR} ${B}" |
| 494 | do_deploy[prefuncs] += "package_get_auto_pr" |
| 495 | |
| 496 | addtask deploy after do_populate_sysroot |
| 497 | |
| 498 | EXPORT_FUNCTIONS do_deploy |
| 499 | |