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: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 28 | d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 220 | |
| 221 | # Module.symvers gets updated during the |
| 222 | # building of the kernel modules. We need to |
| 223 | # update this in the shared workdir since some |
| 224 | # external kernel modules has a dependency on |
| 225 | # other kernel modules and will look at this |
| 226 | # file to do symbol lookups |
| 227 | cp Module.symvers ${STAGING_KERNEL_BUILDDIR}/ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | else |
| 229 | bbnote "no modules to compile" |
| 230 | fi |
| 231 | } |
| 232 | addtask compile_kernelmodules after do_compile before do_strip |
| 233 | |
| 234 | kernel_do_install() { |
| 235 | # |
| 236 | # First install the modules |
| 237 | # |
| 238 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
| 239 | if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then |
| 240 | oe_runmake DEPMOD=echo INSTALL_MOD_PATH="${D}" modules_install |
| 241 | rm "${D}/lib/modules/${KERNEL_VERSION}/build" |
| 242 | rm "${D}/lib/modules/${KERNEL_VERSION}/source" |
| 243 | # If the kernel/ directory is empty remove it to prevent QA issues |
| 244 | rmdir --ignore-fail-on-non-empty "${D}/lib/modules/${KERNEL_VERSION}/kernel" |
| 245 | else |
| 246 | bbnote "no modules to install" |
| 247 | fi |
| 248 | |
| 249 | # |
| 250 | # Install various kernel output (zImage, map file, config, module support files) |
| 251 | # |
| 252 | install -d ${D}/${KERNEL_IMAGEDEST} |
| 253 | install -d ${D}/boot |
| 254 | install -m 0644 ${KERNEL_OUTPUT} ${D}/${KERNEL_IMAGEDEST}/${KERNEL_IMAGETYPE}-${KERNEL_VERSION} |
| 255 | install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION} |
| 256 | install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION} |
| 257 | install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION} |
| 258 | [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION} |
| 259 | install -d ${D}${sysconfdir}/modules-load.d |
| 260 | install -d ${D}${sysconfdir}/modprobe.d |
| 261 | } |
| 262 | do_install[prefuncs] += "package_get_auto_pr" |
| 263 | |
| 264 | addtask shared_workdir after do_compile before do_compile_kernelmodules |
| 265 | addtask shared_workdir_setscene |
| 266 | |
| 267 | do_shared_workdir_setscene () { |
| 268 | exit 1 |
| 269 | } |
| 270 | |
| 271 | emit_depmod_pkgdata() { |
| 272 | # Stash data for depmod |
| 273 | install -d ${PKGDESTWORK}/kernel-depmod/ |
| 274 | echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/kernel-depmod/kernel-abiversion |
| 275 | cp ${B}/System.map ${PKGDESTWORK}/kernel-depmod/System.map-${KERNEL_VERSION} |
| 276 | } |
| 277 | |
| 278 | PACKAGEFUNCS += "emit_depmod_pkgdata" |
| 279 | |
| 280 | do_shared_workdir () { |
| 281 | cd ${B} |
| 282 | |
| 283 | kerneldir=${STAGING_KERNEL_BUILDDIR} |
| 284 | install -d $kerneldir |
| 285 | |
| 286 | # |
| 287 | # Store the kernel version in sysroots for module-base.bbclass |
| 288 | # |
| 289 | |
| 290 | echo "${KERNEL_VERSION}" > $kerneldir/kernel-abiversion |
| 291 | |
| 292 | # Copy files required for module builds |
| 293 | cp System.map $kerneldir/System.map-${KERNEL_VERSION} |
| 294 | cp Module.symvers $kerneldir/ |
| 295 | cp .config $kerneldir/ |
| 296 | mkdir -p $kerneldir/include/config |
| 297 | cp include/config/kernel.release $kerneldir/include/config/kernel.release |
| 298 | |
| 299 | # We can also copy over all the generated files and avoid special cases |
| 300 | # like version.h, but we've opted to keep this small until file creep starts |
| 301 | # to happen |
| 302 | if [ -e include/linux/version.h ]; then |
| 303 | mkdir -p $kerneldir/include/linux |
| 304 | cp include/linux/version.h $kerneldir/include/linux/version.h |
| 305 | fi |
| 306 | |
| 307 | # As of Linux kernel version 3.0.1, the clean target removes |
| 308 | # arch/powerpc/lib/crtsavres.o which is present in |
| 309 | # KBUILD_LDFLAGS_MODULE, making it required to build external modules. |
| 310 | if [ ${ARCH} = "powerpc" ]; then |
| 311 | mkdir -p $kerneldir/arch/powerpc/lib/ |
| 312 | cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o |
| 313 | fi |
| 314 | |
| 315 | if [ -d include/generated ]; then |
| 316 | mkdir -p $kerneldir/include/generated/ |
| 317 | cp -fR include/generated/* $kerneldir/include/generated/ |
| 318 | fi |
| 319 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 320 | if [ -d arch/${ARCH}/include/generated ]; then |
| 321 | mkdir -p $kerneldir/arch/${ARCH}/include/generated/ |
| 322 | cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 323 | fi |
| 324 | } |
| 325 | |
| 326 | # We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware |
| 327 | sysroot_stage_all () { |
| 328 | : |
| 329 | } |
| 330 | |
| 331 | KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} O=${B} oldnoconfig || yes '' | oe_runmake -C ${S} O=${B} oldconfig" |
| 332 | |
| 333 | kernel_do_configure() { |
| 334 | # fixes extra + in /lib/modules/2.6.37+ |
| 335 | # $ scripts/setlocalversion . => + |
| 336 | # $ make kernelversion => 2.6.37 |
| 337 | # $ make kernelrelease => 2.6.37+ |
| 338 | touch ${B}/.scmversion ${S}/.scmversion |
| 339 | |
| 340 | if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then |
| 341 | mv "${S}/.config" "${B}/.config" |
| 342 | fi |
| 343 | |
| 344 | # Copy defconfig to .config if .config does not exist. This allows |
| 345 | # recipes to manage the .config themselves in do_configure_prepend(). |
| 346 | if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then |
| 347 | cp "${WORKDIR}/defconfig" "${B}/.config" |
| 348 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 349 | |
| 350 | ${KERNEL_CONFIG_COMMAND} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 () { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 408 | do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.(bin|fw|cis|csp|dsp)$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') |
| 409 | } |
| 410 | |
| 411 | # Many scripts want to look in arch/$arch/boot for the bootable |
| 412 | # image. This poses a problem for vmlinux based booting. This |
| 413 | # task arranges to have vmlinux appear in the normalized directory |
| 414 | # location. |
| 415 | do_kernel_link_vmlinux() { |
| 416 | if [ ! -d "${B}/arch/${ARCH}/boot" ]; then |
| 417 | mkdir ${B}/arch/${ARCH}/boot |
| 418 | fi |
| 419 | cd ${B}/arch/${ARCH}/boot |
| 420 | ln -sf ../../../vmlinux |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | do_strip() { |
| 424 | if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then |
| 425 | if [ "${KERNEL_IMAGETYPE}" != "vmlinux" ]; then |
| 426 | bbwarn "image type will not be stripped (not supported): ${KERNEL_IMAGETYPE}" |
| 427 | return |
| 428 | fi |
| 429 | |
| 430 | cd ${B} |
| 431 | headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT} | \ |
| 432 | grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \ |
| 433 | sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \ |
| 434 | gawk '{print $1}'` |
| 435 | |
| 436 | for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do { |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 437 | if ! (echo "$headers" | grep -q "^$str$"); then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 438 | bbwarn "Section not found: $str"; |
| 439 | fi |
| 440 | |
| 441 | "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT} |
| 442 | }; done |
| 443 | |
| 444 | bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \ |
| 445 | "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" |
| 446 | fi; |
| 447 | } |
| 448 | do_strip[dirs] = "${B}" |
| 449 | |
| 450 | addtask do_strip before do_sizecheck after do_kernel_link_vmlinux |
| 451 | |
| 452 | # Support checking the kernel size since some kernels need to reside in partitions |
| 453 | # with a fixed length or there is a limit in transferring the kernel to memory |
| 454 | do_sizecheck() { |
| 455 | if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then |
| 456 | invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'` |
| 457 | if [ -n "$invalid" ]; then |
| 458 | die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integerx (The unit is Kbytes)" |
| 459 | fi |
| 460 | size=`du -ks ${B}/${KERNEL_OUTPUT} | awk '{ print $1}'` |
| 461 | if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then |
| 462 | 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." |
| 463 | fi |
| 464 | fi |
| 465 | } |
| 466 | do_sizecheck[dirs] = "${B}" |
| 467 | |
| 468 | addtask sizecheck before do_install after do_strip |
| 469 | |
| 470 | KERNEL_IMAGE_BASE_NAME ?= "${KERNEL_IMAGETYPE}-${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}" |
| 471 | # Don't include the DATETIME variable in the sstate package signatures |
| 472 | KERNEL_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME" |
| 473 | KERNEL_IMAGE_SYMLINK_NAME ?= "${KERNEL_IMAGETYPE}-${MACHINE}" |
| 474 | MODULE_IMAGE_BASE_NAME ?= "modules-${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}" |
| 475 | MODULE_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME" |
| 476 | MODULE_TARBALL_BASE_NAME ?= "${MODULE_IMAGE_BASE_NAME}.tgz" |
| 477 | # Don't include the DATETIME variable in the sstate package signatures |
| 478 | MODULE_TARBALL_SYMLINK_NAME ?= "modules-${MACHINE}.tgz" |
| 479 | MODULE_TARBALL_DEPLOY ?= "1" |
| 480 | |
| 481 | kernel_do_deploy() { |
| 482 | install -m 0644 ${KERNEL_OUTPUT} ${DEPLOYDIR}/${KERNEL_IMAGE_BASE_NAME}.bin |
| 483 | if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then |
| 484 | mkdir -p ${D}/lib |
| 485 | tar -cvzf ${DEPLOYDIR}/${MODULE_TARBALL_BASE_NAME} -C ${D} lib |
| 486 | ln -sf ${MODULE_TARBALL_BASE_NAME} ${DEPLOYDIR}/${MODULE_TARBALL_SYMLINK_NAME} |
| 487 | fi |
| 488 | |
| 489 | ln -sf ${KERNEL_IMAGE_BASE_NAME}.bin ${DEPLOYDIR}/${KERNEL_IMAGE_SYMLINK_NAME}.bin |
| 490 | ln -sf ${KERNEL_IMAGE_BASE_NAME}.bin ${DEPLOYDIR}/${KERNEL_IMAGETYPE} |
| 491 | |
| 492 | cp ${COREBASE}/meta/files/deploydir_readme.txt ${DEPLOYDIR}/README_-_DO_NOT_DELETE_FILES_IN_THIS_DIRECTORY.txt |
| 493 | |
| 494 | cd ${B} |
| 495 | # Update deploy directory |
| 496 | if [ -e "${KERNEL_OUTPUT}.initramfs" ]; then |
| 497 | echo "Copying deploy kernel-initramfs image and setting up links..." |
| 498 | initramfs_base_name=${INITRAMFS_BASE_NAME} |
| 499 | initramfs_symlink_name=${KERNEL_IMAGETYPE}-initramfs-${MACHINE} |
| 500 | install -m 0644 ${KERNEL_OUTPUT}.initramfs ${DEPLOYDIR}/${initramfs_base_name}.bin |
| 501 | cd ${DEPLOYDIR} |
| 502 | ln -sf ${initramfs_base_name}.bin ${initramfs_symlink_name}.bin |
| 503 | fi |
| 504 | } |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 505 | do_deploy[cleandirs] = "${DEPLOYDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 506 | do_deploy[dirs] = "${DEPLOYDIR} ${B}" |
| 507 | do_deploy[prefuncs] += "package_get_auto_pr" |
| 508 | |
| 509 | addtask deploy after do_populate_sysroot |
| 510 | |
| 511 | EXPORT_FUNCTIONS do_deploy |
| 512 | |