Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | inherit linux-kernel-base kernel-module-split |
| 8 | |
| 9 | COMPATIBLE_HOST = ".*-linux" |
| 10 | |
| 11 | KERNEL_PACKAGE_NAME ??= "kernel" |
| 12 | KERNEL_DEPLOYSUBDIR ??= "${@ "" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else d.getVar("KERNEL_PACKAGE_NAME") }" |
| 13 | |
| 14 | PROVIDES += "virtual/kernel" |
| 15 | DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native bc-native bison-native" |
| 16 | DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.lzo", "lzop-native", "", d)}" |
| 17 | DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.lz4", "lz4-native", "", d)}" |
| 18 | DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.zst", "zstd-native", "", d)}" |
| 19 | PACKAGE_WRITE_DEPS += "depmodwrapper-cross" |
| 20 | |
| 21 | do_deploy[depends] += "depmodwrapper-cross:do_populate_sysroot gzip-native:do_populate_sysroot" |
| 22 | do_clean[depends] += "make-mod-scripts:do_clean" |
| 23 | |
| 24 | CVE_PRODUCT ?= "linux_kernel" |
| 25 | |
| 26 | S = "${STAGING_KERNEL_DIR}" |
| 27 | B = "${WORKDIR}/build" |
| 28 | KBUILD_OUTPUT = "${B}" |
| 29 | OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT" |
| 30 | |
| 31 | # we include gcc above, we dont need virtual/libc |
| 32 | INHIBIT_DEFAULT_DEPS = "1" |
| 33 | |
| 34 | KERNEL_IMAGETYPE ?= "zImage" |
| 35 | INITRAMFS_IMAGE ?= "" |
| 36 | INITRAMFS_IMAGE_NAME ?= "${@['${INITRAMFS_IMAGE}-${MACHINE}', ''][d.getVar('INITRAMFS_IMAGE') == '']}" |
| 37 | INITRAMFS_TASK ?= "" |
| 38 | INITRAMFS_IMAGE_BUNDLE ?= "" |
| 39 | INITRAMFS_DEPLOY_DIR_IMAGE ?= "${DEPLOY_DIR_IMAGE}" |
| 40 | INITRAMFS_MULTICONFIG ?= "" |
| 41 | |
| 42 | # KERNEL_VERSION is extracted from source code. It is evaluated as |
| 43 | # None for the first parsing, since the code has not been fetched. |
| 44 | # After the code is fetched, it will be evaluated as real version |
| 45 | # number and cause kernel to be rebuilt. To avoid this, make |
| 46 | # KERNEL_VERSION_NAME and KERNEL_VERSION_PKG_NAME depend on |
| 47 | # LINUX_VERSION which is a constant. |
| 48 | KERNEL_VERSION_NAME = "${@d.getVar('KERNEL_VERSION') or ""}" |
| 49 | KERNEL_VERSION_NAME[vardepvalue] = "${LINUX_VERSION}" |
| 50 | KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}" |
| 51 | KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}" |
| 52 | |
| 53 | python __anonymous () { |
| 54 | pn = d.getVar("PN") |
| 55 | kpn = d.getVar("KERNEL_PACKAGE_NAME") |
| 56 | |
| 57 | # XXX Remove this after bug 11905 is resolved |
| 58 | # FILES:${KERNEL_PACKAGE_NAME}-dev doesn't expand correctly |
| 59 | if kpn == pn: |
| 60 | bb.warn("Some packages (E.g. *-dev) might be missing due to " |
| 61 | "bug 11905 (variable KERNEL_PACKAGE_NAME == PN)") |
| 62 | |
| 63 | # The default kernel recipe builds in a shared location defined by |
| 64 | # bitbake/distro confs: STAGING_KERNEL_DIR and STAGING_KERNEL_BUILDDIR. |
| 65 | # Set these variables to directories under ${WORKDIR} in alternate |
| 66 | # kernel recipes (I.e. where KERNEL_PACKAGE_NAME != kernel) so that they |
| 67 | # may build in parallel with the default kernel without clobbering. |
| 68 | if kpn != "kernel": |
| 69 | workdir = d.getVar("WORKDIR") |
| 70 | sourceDir = os.path.join(workdir, 'kernel-source') |
| 71 | artifactsDir = os.path.join(workdir, 'kernel-build-artifacts') |
| 72 | d.setVar("STAGING_KERNEL_DIR", sourceDir) |
| 73 | d.setVar("STAGING_KERNEL_BUILDDIR", artifactsDir) |
| 74 | |
| 75 | # Merge KERNEL_IMAGETYPE and KERNEL_ALT_IMAGETYPE into KERNEL_IMAGETYPES |
| 76 | type = d.getVar('KERNEL_IMAGETYPE') or "" |
| 77 | alttype = d.getVar('KERNEL_ALT_IMAGETYPE') or "" |
| 78 | types = d.getVar('KERNEL_IMAGETYPES') or "" |
| 79 | if type not in types.split(): |
| 80 | types = (type + ' ' + types).strip() |
| 81 | if alttype not in types.split(): |
| 82 | types = (alttype + ' ' + types).strip() |
| 83 | d.setVar('KERNEL_IMAGETYPES', types) |
| 84 | |
| 85 | # KERNEL_IMAGETYPES may contain a mixture of image types supported directly |
| 86 | # by the kernel build system and types which are created by post-processing |
| 87 | # the output of the kernel build system (e.g. compressing vmlinux -> |
| 88 | # vmlinux.gz in kernel_do_transform_kernel()). |
| 89 | # KERNEL_IMAGETYPE_FOR_MAKE should contain only image types supported |
| 90 | # directly by the kernel build system. |
| 91 | if not d.getVar('KERNEL_IMAGETYPE_FOR_MAKE'): |
| 92 | typeformake = set() |
| 93 | for type in types.split(): |
| 94 | if type == 'vmlinux.gz': |
| 95 | type = 'vmlinux' |
| 96 | typeformake.add(type) |
| 97 | |
| 98 | d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', ' '.join(sorted(typeformake))) |
| 99 | |
| 100 | kname = d.getVar('KERNEL_PACKAGE_NAME') or "kernel" |
| 101 | imagedest = d.getVar('KERNEL_IMAGEDEST') |
| 102 | |
| 103 | for type in types.split(): |
| 104 | if bb.data.inherits_class('nopackages', d): |
| 105 | continue |
| 106 | typelower = type.lower() |
| 107 | d.appendVar('PACKAGES', ' %s-image-%s' % (kname, typelower)) |
| 108 | d.setVar('FILES:' + kname + '-image-' + typelower, '/' + imagedest + '/' + type + '-${KERNEL_VERSION_NAME}' + ' /' + imagedest + '/' + type) |
| 109 | d.appendVar('RDEPENDS:%s-image' % kname, ' %s-image-%s (= ${EXTENDPKGV})' % (kname, typelower)) |
| 110 | splitmods = d.getVar("KERNEL_SPLIT_MODULES") |
| 111 | if splitmods != '1': |
| 112 | d.appendVar('RDEPENDS:%s-image' % kname, ' %s-modules (= ${EXTENDPKGV})' % kname) |
| 113 | d.appendVar('RDEPENDS:%s-image-%s' % (kname, typelower), ' %s-modules-${KERNEL_VERSION_PKG_NAME} (= ${EXTENDPKGV})' % kname) |
| 114 | d.setVar('PKG:%s-modules' % kname, '%s-modules-${KERNEL_VERSION_PKG_NAME}' % kname) |
| 115 | d.appendVar('RPROVIDES:%s-modules' % kname, '%s-modules-${KERNEL_VERSION_PKG_NAME}' % kname) |
| 116 | |
| 117 | d.setVar('PKG:%s-image-%s' % (kname,typelower), '%s-image-%s-${KERNEL_VERSION_PKG_NAME}' % (kname, typelower)) |
| 118 | d.setVar('ALLOW_EMPTY:%s-image-%s' % (kname, typelower), '1') |
| 119 | d.prependVar('pkg_postinst:%s-image-%s' % (kname,typelower), """set +e |
| 120 | if [ -n "$D" ]; then |
| 121 | ln -sf %s-${KERNEL_VERSION} $D/${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1 |
| 122 | else |
| 123 | ln -sf %s-${KERNEL_VERSION} ${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1 |
| 124 | if [ $? -ne 0 ]; then |
| 125 | echo "Filesystem on ${KERNEL_IMAGEDEST}/ doesn't support symlinks, falling back to copied image (%s)." |
| 126 | install -m 0644 ${KERNEL_IMAGEDEST}/%s-${KERNEL_VERSION} ${KERNEL_IMAGEDEST}/%s |
| 127 | fi |
| 128 | fi |
| 129 | set -e |
| 130 | """ % (type, type, type, type, type, type, type)) |
| 131 | d.setVar('pkg_postrm:%s-image-%s' % (kname,typelower), """set +e |
| 132 | if [ -f "${KERNEL_IMAGEDEST}/%s" -o -L "${KERNEL_IMAGEDEST}/%s" ]; then |
| 133 | rm -f ${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1 |
| 134 | fi |
| 135 | set -e |
| 136 | """ % (type, type, type)) |
| 137 | |
| 138 | |
| 139 | image = d.getVar('INITRAMFS_IMAGE') |
| 140 | # If the INTIRAMFS_IMAGE is set but the INITRAMFS_IMAGE_BUNDLE is set to 0, |
| 141 | # the do_bundle_initramfs does nothing, but the INITRAMFS_IMAGE is built |
| 142 | # standalone for use by wic and other tools. |
| 143 | if image: |
| 144 | if d.getVar('INITRAMFS_MULTICONFIG'): |
| 145 | d.appendVarFlag('do_bundle_initramfs', 'mcdepends', ' mc::${INITRAMFS_MULTICONFIG}:${INITRAMFS_IMAGE}:do_image_complete') |
| 146 | else: |
| 147 | d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') |
| 148 | if image and bb.utils.to_boolean(d.getVar('INITRAMFS_IMAGE_BUNDLE')): |
| 149 | bb.build.addtask('do_transform_bundled_initramfs', 'do_deploy', 'do_bundle_initramfs', d) |
| 150 | |
| 151 | # NOTE: setting INITRAMFS_TASK is for backward compatibility |
| 152 | # The preferred method is to set INITRAMFS_IMAGE, because |
| 153 | # this INITRAMFS_TASK has circular dependency problems |
| 154 | # if the initramfs requires kernel modules |
| 155 | image_task = d.getVar('INITRAMFS_TASK') |
| 156 | if image_task: |
| 157 | d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}') |
| 158 | } |
| 159 | |
| 160 | # Here we pull in all various kernel image types which we support. |
| 161 | # |
| 162 | # In case you're wondering why kernel.bbclass inherits the other image |
| 163 | # types instead of the other way around, the reason for that is to |
| 164 | # maintain compatibility with various currently existing meta-layers. |
| 165 | # By pulling in the various kernel image types here, we retain the |
| 166 | # original behavior of kernel.bbclass, so no meta-layers should get |
| 167 | # broken. |
| 168 | # |
| 169 | # KERNEL_CLASSES by default pulls in kernel-uimage.bbclass, since this |
| 170 | # used to be the default behavior when only uImage was supported. This |
| 171 | # variable can be appended by users who implement support for new kernel |
| 172 | # image types. |
| 173 | |
| 174 | KERNEL_CLASSES ?= " kernel-uimage " |
| 175 | inherit ${KERNEL_CLASSES} |
| 176 | |
| 177 | # Old style kernels may set ${S} = ${WORKDIR}/git for example |
| 178 | # We need to move these over to STAGING_KERNEL_DIR. We can't just |
| 179 | # create the symlink in advance as the git fetcher can't cope with |
| 180 | # the symlink. |
| 181 | do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}" |
| 182 | do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}" |
| 183 | python do_symlink_kernsrc () { |
| 184 | s = d.getVar("S") |
| 185 | if s[-1] == '/': |
| 186 | # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as directory name and fail |
| 187 | s=s[:-1] |
| 188 | kernsrc = d.getVar("STAGING_KERNEL_DIR") |
| 189 | if s != kernsrc: |
| 190 | bb.utils.mkdirhier(kernsrc) |
| 191 | bb.utils.remove(kernsrc, recurse=True) |
| 192 | if d.getVar("EXTERNALSRC"): |
| 193 | # With EXTERNALSRC S will not be wiped so we can symlink to it |
| 194 | os.symlink(s, kernsrc) |
| 195 | else: |
| 196 | import shutil |
| 197 | shutil.move(s, kernsrc) |
| 198 | os.symlink(kernsrc, s) |
| 199 | } |
| 200 | # do_patch is normally ordered before do_configure, but |
| 201 | # externalsrc.bbclass deletes do_patch, breaking the dependency of |
| 202 | # do_configure on do_symlink_kernsrc. |
| 203 | addtask symlink_kernsrc before do_patch do_configure after do_unpack |
| 204 | |
| 205 | inherit kernel-arch deploy |
| 206 | |
| 207 | PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*" |
| 208 | PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-image-.*" |
| 209 | PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-firmware-.*" |
| 210 | |
| 211 | export OS = "${TARGET_OS}" |
| 212 | export CROSS_COMPILE = "${TARGET_PREFIX}" |
| 213 | export KBUILD_BUILD_VERSION = "1" |
| 214 | export KBUILD_BUILD_USER ?= "oe-user" |
| 215 | export KBUILD_BUILD_HOST ?= "oe-host" |
| 216 | |
| 217 | KERNEL_RELEASE ?= "${KERNEL_VERSION}" |
| 218 | |
| 219 | # The directory where built kernel lies in the kernel tree |
| 220 | KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot" |
| 221 | KERNEL_IMAGEDEST ?= "boot" |
| 222 | |
| 223 | # |
| 224 | # configuration |
| 225 | # |
| 226 | export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE") or "ttyS0"}" |
| 227 | |
| 228 | KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}" |
| 229 | |
| 230 | # kernels are generally machine specific |
| 231 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 232 | |
| 233 | # U-Boot support |
| 234 | UBOOT_ENTRYPOINT ?= "20008000" |
| 235 | UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}" |
| 236 | |
| 237 | # Some Linux kernel configurations need additional parameters on the command line |
| 238 | KERNEL_EXTRA_ARGS ?= "" |
| 239 | |
| 240 | EXTRA_OEMAKE += ' CC="${KERNEL_CC}" LD="${KERNEL_LD}"' |
| 241 | EXTRA_OEMAKE += ' HOSTCC="${BUILD_CC}" HOSTCFLAGS="${BUILD_CFLAGS}" HOSTLDFLAGS="${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}"' |
| 242 | EXTRA_OEMAKE += ' HOSTCXX="${BUILD_CXX}" HOSTCXXFLAGS="${BUILD_CXXFLAGS}" PAHOLE=false' |
| 243 | |
| 244 | KERNEL_ALT_IMAGETYPE ??= "" |
| 245 | |
| 246 | copy_initramfs() { |
| 247 | echo "Copying initramfs into ./usr ..." |
| 248 | # In case the directory is not created yet from the first pass compile: |
| 249 | mkdir -p ${B}/usr |
| 250 | # Find and use the first initramfs image archive type we find |
| 251 | rm -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio |
| 252 | for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.zst; do |
| 253 | if [ -e "${INITRAMFS_DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" ]; then |
| 254 | cp ${INITRAMFS_DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/. |
| 255 | case $img in |
| 256 | *gz) |
| 257 | echo "gzip decompressing image" |
| 258 | gunzip -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img |
| 259 | break |
| 260 | ;; |
| 261 | *lz4) |
| 262 | echo "lz4 decompressing image" |
| 263 | lz4 -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio |
| 264 | break |
| 265 | ;; |
| 266 | *lzo) |
| 267 | echo "lzo decompressing image" |
| 268 | lzop -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img |
| 269 | break |
| 270 | ;; |
| 271 | *lzma) |
| 272 | echo "lzma decompressing image" |
| 273 | lzma -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img |
| 274 | break |
| 275 | ;; |
| 276 | *xz) |
| 277 | echo "xz decompressing image" |
| 278 | xz -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img |
| 279 | break |
| 280 | ;; |
| 281 | *zst) |
| 282 | echo "zst decompressing image" |
| 283 | zstd -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img |
| 284 | break |
| 285 | ;; |
| 286 | esac |
| 287 | break |
| 288 | fi |
| 289 | done |
| 290 | # Verify that the above loop found a initramfs, fail otherwise |
| 291 | [ -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio ] && echo "Finished copy of initramfs into ./usr" || die "Could not find any ${INITRAMFS_DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.cpio{.gz|.lz4|.lzo|.lzma|.xz|.zst) for bundling; INITRAMFS_IMAGE_NAME might be wrong." |
| 292 | } |
| 293 | |
| 294 | do_bundle_initramfs () { |
| 295 | if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then |
| 296 | echo "Creating a kernel image with a bundled initramfs..." |
| 297 | copy_initramfs |
| 298 | # Backing up kernel image relies on its type(regular file or symbolic link) |
| 299 | tmp_path="" |
| 300 | for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do |
| 301 | if [ -h ${KERNEL_OUTPUT_DIR}/$imageType ] ; then |
| 302 | linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$imageType` |
| 303 | realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$imageType` |
| 304 | mv -f $realpath $realpath.bak |
| 305 | tmp_path=$tmp_path" "$imageType"#"$linkpath"#"$realpath |
| 306 | elif [ -f ${KERNEL_OUTPUT_DIR}/$imageType ]; then |
| 307 | mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.bak |
| 308 | tmp_path=$tmp_path" "$imageType"##" |
| 309 | fi |
| 310 | done |
| 311 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio |
| 312 | kernel_do_compile |
| 313 | # Restoring kernel image |
| 314 | for tp in $tmp_path ; do |
| 315 | imageType=`echo $tp|cut -d "#" -f 1` |
| 316 | linkpath=`echo $tp|cut -d "#" -f 2` |
| 317 | realpath=`echo $tp|cut -d "#" -f 3` |
| 318 | if [ -n "$realpath" ]; then |
| 319 | mv -f $realpath $realpath.initramfs |
| 320 | mv -f $realpath.bak $realpath |
| 321 | ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$imageType.initramfs |
| 322 | else |
| 323 | mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.initramfs |
| 324 | mv -f ${KERNEL_OUTPUT_DIR}/$imageType.bak ${KERNEL_OUTPUT_DIR}/$imageType |
| 325 | fi |
| 326 | done |
| 327 | fi |
| 328 | } |
| 329 | do_bundle_initramfs[dirs] = "${B}" |
| 330 | |
| 331 | kernel_do_transform_bundled_initramfs() { |
| 332 | # vmlinux.gz is not built by kernel |
| 333 | if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then |
| 334 | gzip -9cn < ${KERNEL_OUTPUT_DIR}/vmlinux.initramfs > ${KERNEL_OUTPUT_DIR}/vmlinux.gz.initramfs |
| 335 | fi |
| 336 | } |
| 337 | do_transform_bundled_initramfs[dirs] = "${B}" |
| 338 | |
| 339 | python do_devshell:prepend () { |
| 340 | os.environ["LDFLAGS"] = '' |
| 341 | } |
| 342 | |
| 343 | addtask bundle_initramfs after do_install before do_deploy |
| 344 | |
| 345 | KERNEL_DEBUG_TIMESTAMPS ??= "0" |
| 346 | |
| 347 | kernel_do_compile() { |
| 348 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
| 349 | |
| 350 | # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native) |
| 351 | export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig" |
| 352 | export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig" |
| 353 | export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR" |
| 354 | export PKG_CONFIG_SYSROOT_DIR="" |
| 355 | |
| 356 | if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then |
| 357 | # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not |
| 358 | # be set.... |
| 359 | if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then |
| 360 | # The source directory is not necessarily a git repository, so we |
| 361 | # specify the git-dir to ensure that git does not query a |
| 362 | # repository in any parent directory. |
| 363 | SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"` |
| 364 | fi |
| 365 | |
| 366 | ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH` |
| 367 | export KBUILD_BUILD_TIMESTAMP="$ts" |
| 368 | export KCONFIG_NOTIMESTAMP=1 |
| 369 | bbnote "KBUILD_BUILD_TIMESTAMP: $ts" |
| 370 | fi |
| 371 | # The $use_alternate_initrd is only set from |
| 372 | # do_bundle_initramfs() This variable is specifically for the |
| 373 | # case where we are making a second pass at the kernel |
| 374 | # compilation and we want to force the kernel build to use a |
| 375 | # different initramfs image. The way to do that in the kernel |
| 376 | # is to specify: |
| 377 | # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio |
| 378 | if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then |
| 379 | # The old style way of copying an prebuilt image and building it |
| 380 | # is turned on via INTIRAMFS_TASK != "" |
| 381 | copy_initramfs |
| 382 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio |
| 383 | fi |
| 384 | for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do |
| 385 | oe_runmake ${typeformake} ${KERNEL_EXTRA_ARGS} $use_alternate_initrd |
| 386 | done |
| 387 | } |
| 388 | |
| 389 | kernel_do_transform_kernel() { |
| 390 | # vmlinux.gz is not built by kernel |
| 391 | if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then |
| 392 | mkdir -p "${KERNEL_OUTPUT_DIR}" |
| 393 | gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz" |
| 394 | fi |
| 395 | } |
| 396 | do_transform_kernel[dirs] = "${B}" |
| 397 | addtask transform_kernel after do_compile before do_install |
| 398 | |
| 399 | do_compile_kernelmodules() { |
| 400 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
| 401 | if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then |
| 402 | # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not |
| 403 | # be set.... |
| 404 | if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then |
| 405 | # The source directory is not necessarily a git repository, so we |
| 406 | # specify the git-dir to ensure that git does not query a |
| 407 | # repository in any parent directory. |
| 408 | SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"` |
| 409 | fi |
| 410 | |
| 411 | ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH` |
| 412 | export KBUILD_BUILD_TIMESTAMP="$ts" |
| 413 | export KCONFIG_NOTIMESTAMP=1 |
| 414 | bbnote "KBUILD_BUILD_TIMESTAMP: $ts" |
| 415 | fi |
| 416 | if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then |
| 417 | oe_runmake -C ${B} ${PARALLEL_MAKE} modules ${KERNEL_EXTRA_ARGS} |
| 418 | |
| 419 | # Module.symvers gets updated during the |
| 420 | # building of the kernel modules. We need to |
| 421 | # update this in the shared workdir since some |
| 422 | # external kernel modules has a dependency on |
| 423 | # other kernel modules and will look at this |
| 424 | # file to do symbol lookups |
| 425 | cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/ |
| 426 | # 5.10+ kernels have module.lds that we need to copy for external module builds |
| 427 | if [ -e "${B}/scripts/module.lds" ]; then |
| 428 | install -Dm 0644 ${B}/scripts/module.lds ${STAGING_KERNEL_BUILDDIR}/scripts/module.lds |
| 429 | fi |
| 430 | else |
| 431 | bbnote "no modules to compile" |
| 432 | fi |
| 433 | } |
| 434 | addtask compile_kernelmodules after do_compile before do_strip |
| 435 | |
| 436 | kernel_do_install() { |
| 437 | # |
| 438 | # First install the modules |
| 439 | # |
| 440 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
| 441 | if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then |
| 442 | oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install |
| 443 | rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build" |
| 444 | rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source" |
| 445 | # If the kernel/ directory is empty remove it to prevent QA issues |
| 446 | rmdir --ignore-fail-on-non-empty "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel" |
| 447 | else |
| 448 | bbnote "no modules to install" |
| 449 | fi |
| 450 | |
| 451 | # |
| 452 | # Install various kernel output (zImage, map file, config, module support files) |
| 453 | # |
| 454 | install -d ${D}/${KERNEL_IMAGEDEST} |
| 455 | |
| 456 | # |
| 457 | # When including an initramfs bundle inside a FIT image, the fitImage is created after the install task |
| 458 | # by do_assemble_fitimage_initramfs. |
| 459 | # This happens after the generation of the initramfs bundle (done by do_bundle_initramfs). |
| 460 | # So, at the level of the install task we should not try to install the fitImage. fitImage is still not |
| 461 | # generated yet. |
| 462 | # After the generation of the fitImage, the deploy task copies the fitImage from the build directory to |
| 463 | # the deploy folder. |
| 464 | # |
| 465 | |
| 466 | for imageType in ${KERNEL_IMAGETYPES} ; do |
| 467 | if [ $imageType != "fitImage" ] || [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ] ; then |
| 468 | install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType ${D}/${KERNEL_IMAGEDEST}/$imageType-${KERNEL_VERSION} |
| 469 | fi |
| 470 | done |
| 471 | |
| 472 | install -m 0644 System.map ${D}/${KERNEL_IMAGEDEST}/System.map-${KERNEL_VERSION} |
| 473 | install -m 0644 .config ${D}/${KERNEL_IMAGEDEST}/config-${KERNEL_VERSION} |
| 474 | install -m 0644 vmlinux ${D}/${KERNEL_IMAGEDEST}/vmlinux-${KERNEL_VERSION} |
| 475 | [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/${KERNEL_IMAGEDEST}/Module.symvers-${KERNEL_VERSION} |
| 476 | install -d ${D}${sysconfdir}/modules-load.d |
| 477 | install -d ${D}${sysconfdir}/modprobe.d |
| 478 | } |
| 479 | |
| 480 | # Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile |
| 481 | do_kernel_version_sanity_check() { |
| 482 | if [ "x${KERNEL_VERSION_SANITY_SKIP}" = "x1" ]; then |
| 483 | exit 0 |
| 484 | fi |
| 485 | |
| 486 | # The Makefile determines the kernel version shown at runtime |
| 487 | # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile |
| 488 | VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//) |
| 489 | PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//) |
| 490 | SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//) |
| 491 | EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//) |
| 492 | |
| 493 | # Build a string for regex and a plain version string |
| 494 | reg="^${VERSION}\.${PATCHLEVEL}" |
| 495 | vers="${VERSION}.${PATCHLEVEL}" |
| 496 | if [ -n "${SUBLEVEL}" ]; then |
| 497 | # Ignoring a SUBLEVEL of zero is fine |
| 498 | if [ "${SUBLEVEL}" = "0" ]; then |
| 499 | reg="${reg}(\.${SUBLEVEL})?" |
| 500 | else |
| 501 | reg="${reg}\.${SUBLEVEL}" |
| 502 | vers="${vers}.${SUBLEVEL}" |
| 503 | fi |
| 504 | fi |
| 505 | vers="${vers}${EXTRAVERSION}" |
| 506 | reg="${reg}${EXTRAVERSION}" |
| 507 | |
| 508 | if [ -z `echo ${PV} | grep -E "${reg}"` ]; then |
| 509 | bbfatal "Package Version (${PV}) does not match of kernel being built (${vers}). Please update the PV variable to match the kernel source or set KERNEL_VERSION_SANITY_SKIP=\"1\" in your recipe." |
| 510 | fi |
| 511 | exit 0 |
| 512 | } |
| 513 | |
| 514 | addtask shared_workdir after do_compile before do_compile_kernelmodules |
| 515 | addtask shared_workdir_setscene |
| 516 | |
| 517 | do_shared_workdir_setscene () { |
| 518 | exit 1 |
| 519 | } |
| 520 | |
| 521 | emit_depmod_pkgdata() { |
| 522 | # Stash data for depmod |
| 523 | install -d ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/ |
| 524 | echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/${KERNEL_PACKAGE_NAME}-abiversion |
| 525 | cp ${B}/System.map ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/System.map-${KERNEL_VERSION} |
| 526 | } |
| 527 | |
| 528 | PACKAGEFUNCS += "emit_depmod_pkgdata" |
| 529 | |
| 530 | do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}" |
| 531 | do_shared_workdir () { |
| 532 | cd ${B} |
| 533 | |
| 534 | kerneldir=${STAGING_KERNEL_BUILDDIR} |
| 535 | install -d $kerneldir |
| 536 | |
| 537 | # |
| 538 | # Store the kernel version in sysroots for module-base.bbclass |
| 539 | # |
| 540 | |
| 541 | echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion |
| 542 | |
| 543 | # Copy files required for module builds |
| 544 | cp System.map $kerneldir/System.map-${KERNEL_VERSION} |
| 545 | [ -e Module.symvers ] && cp Module.symvers $kerneldir/ |
| 546 | cp .config $kerneldir/ |
| 547 | mkdir -p $kerneldir/include/config |
| 548 | cp include/config/kernel.release $kerneldir/include/config/kernel.release |
| 549 | if [ -e certs/signing_key.x509 ]; then |
| 550 | # The signing_key.* files are stored in the certs/ dir in |
| 551 | # newer Linux kernels |
| 552 | mkdir -p $kerneldir/certs |
| 553 | cp certs/signing_key.* $kerneldir/certs/ |
| 554 | elif [ -e signing_key.priv ]; then |
| 555 | cp signing_key.* $kerneldir/ |
| 556 | fi |
| 557 | |
| 558 | # We can also copy over all the generated files and avoid special cases |
| 559 | # like version.h, but we've opted to keep this small until file creep starts |
| 560 | # to happen |
| 561 | if [ -e include/linux/version.h ]; then |
| 562 | mkdir -p $kerneldir/include/linux |
| 563 | cp include/linux/version.h $kerneldir/include/linux/version.h |
| 564 | fi |
| 565 | |
| 566 | # As of Linux kernel version 3.0.1, the clean target removes |
| 567 | # arch/powerpc/lib/crtsavres.o which is present in |
| 568 | # KBUILD_LDFLAGS_MODULE, making it required to build external modules. |
| 569 | if [ ${ARCH} = "powerpc" ]; then |
| 570 | if [ -e arch/powerpc/lib/crtsavres.o ]; then |
| 571 | mkdir -p $kerneldir/arch/powerpc/lib/ |
| 572 | cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o |
| 573 | fi |
| 574 | fi |
| 575 | |
| 576 | if [ -d include/generated ]; then |
| 577 | mkdir -p $kerneldir/include/generated/ |
| 578 | cp -fR include/generated/* $kerneldir/include/generated/ |
| 579 | fi |
| 580 | |
| 581 | if [ -d arch/${ARCH}/include/generated ]; then |
| 582 | mkdir -p $kerneldir/arch/${ARCH}/include/generated/ |
| 583 | cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/ |
| 584 | fi |
| 585 | |
| 586 | if (grep -q -i -e '^CONFIG_UNWINDER_ORC=y$' $kerneldir/.config); then |
| 587 | # With CONFIG_UNWINDER_ORC (the default in 4.14), objtool is required for |
| 588 | # out-of-tree modules to be able to generate object files. |
| 589 | if [ -x tools/objtool/objtool ]; then |
| 590 | mkdir -p ${kerneldir}/tools/objtool |
| 591 | cp tools/objtool/objtool ${kerneldir}/tools/objtool/ |
| 592 | fi |
| 593 | fi |
| 594 | } |
| 595 | |
| 596 | # We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware |
| 597 | sysroot_stage_all () { |
| 598 | : |
| 599 | } |
| 600 | |
| 601 | KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} O=${B} olddefconfig || oe_runmake -C ${S} O=${B} oldnoconfig" |
| 602 | |
| 603 | python check_oldest_kernel() { |
| 604 | oldest_kernel = d.getVar('OLDEST_KERNEL') |
| 605 | kernel_version = d.getVar('KERNEL_VERSION') |
| 606 | tclibc = d.getVar('TCLIBC') |
| 607 | if tclibc == 'glibc': |
| 608 | kernel_version = kernel_version.split('-', 1)[0] |
| 609 | if oldest_kernel and kernel_version: |
| 610 | if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0: |
| 611 | bb.warn('%s: OLDEST_KERNEL is "%s" but the version of the kernel you are building is "%s" - therefore %s as built may not be compatible with this kernel. Either set OLDEST_KERNEL to an older version, or build a newer kernel.' % (d.getVar('PN'), oldest_kernel, kernel_version, tclibc)) |
| 612 | } |
| 613 | |
| 614 | check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION" |
| 615 | do_configure[prefuncs] += "check_oldest_kernel" |
| 616 | |
| 617 | kernel_do_configure() { |
| 618 | # fixes extra + in /lib/modules/2.6.37+ |
| 619 | # $ scripts/setlocalversion . => + |
| 620 | # $ make kernelversion => 2.6.37 |
| 621 | # $ make kernelrelease => 2.6.37+ |
| 622 | touch ${B}/.scmversion ${S}/.scmversion |
| 623 | |
| 624 | if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then |
| 625 | mv "${S}/.config" "${B}/.config" |
| 626 | fi |
| 627 | |
| 628 | # Copy defconfig to .config if .config does not exist. This allows |
| 629 | # recipes to manage the .config themselves in do_configure:prepend(). |
| 630 | if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then |
| 631 | cp "${WORKDIR}/defconfig" "${B}/.config" |
| 632 | fi |
| 633 | |
| 634 | ${KERNEL_CONFIG_COMMAND} |
| 635 | } |
| 636 | |
| 637 | do_savedefconfig() { |
| 638 | bbplain "Saving defconfig to:\n${B}/defconfig" |
| 639 | oe_runmake -C ${B} savedefconfig |
| 640 | } |
| 641 | do_savedefconfig[nostamp] = "1" |
| 642 | addtask savedefconfig after do_configure |
| 643 | |
| 644 | inherit cml1 |
| 645 | |
| 646 | # Need LD, HOSTLDFLAGS and more for config operations |
| 647 | KCONFIG_CONFIG_COMMAND:append = " ${EXTRA_OEMAKE}" |
| 648 | |
| 649 | EXPORT_FUNCTIONS do_compile do_transform_kernel do_transform_bundled_initramfs do_install do_configure |
| 650 | |
| 651 | # kernel-base becomes kernel-${KERNEL_VERSION} |
| 652 | # kernel-image becomes kernel-image-${KERNEL_VERSION} |
| 653 | PACKAGES = "${KERNEL_PACKAGE_NAME} ${KERNEL_PACKAGE_NAME}-base ${KERNEL_PACKAGE_NAME}-vmlinux ${KERNEL_PACKAGE_NAME}-image ${KERNEL_PACKAGE_NAME}-dev ${KERNEL_PACKAGE_NAME}-modules ${KERNEL_PACKAGE_NAME}-dbg" |
| 654 | FILES:${PN} = "" |
| 655 | FILES:${KERNEL_PACKAGE_NAME}-base = "${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.order ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.builtin ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.builtin.modinfo" |
| 656 | FILES:${KERNEL_PACKAGE_NAME}-image = "" |
| 657 | FILES:${KERNEL_PACKAGE_NAME}-dev = "/${KERNEL_IMAGEDEST}/System.map* /${KERNEL_IMAGEDEST}/Module.symvers* /${KERNEL_IMAGEDEST}/config* ${KERNEL_SRC_PATH} ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build" |
| 658 | FILES:${KERNEL_PACKAGE_NAME}-vmlinux = "/${KERNEL_IMAGEDEST}/vmlinux-${KERNEL_VERSION_NAME}" |
| 659 | FILES:${KERNEL_PACKAGE_NAME}-modules = "" |
| 660 | FILES:${KERNEL_PACKAGE_NAME}-dbg = "/usr/lib/debug /usr/src/debug" |
| 661 | RDEPENDS:${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base (= ${EXTENDPKGV})" |
| 662 | # Allow machines to override this dependency if kernel image files are |
| 663 | # not wanted in images as standard |
| 664 | RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base ?= "${KERNEL_PACKAGE_NAME}-image (= ${EXTENDPKGV})" |
| 665 | PKG:${KERNEL_PACKAGE_NAME}-image = "${KERNEL_PACKAGE_NAME}-image-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}" |
| 666 | RDEPENDS:${KERNEL_PACKAGE_NAME}-image += "${@oe.utils.conditional('KERNEL_IMAGETYPE', 'vmlinux', '${KERNEL_PACKAGE_NAME}-vmlinux (= ${EXTENDPKGV})', '', d)}" |
| 667 | PKG:${KERNEL_PACKAGE_NAME}-base = "${KERNEL_PACKAGE_NAME}-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}" |
| 668 | RPROVIDES:${KERNEL_PACKAGE_NAME}-base += "${KERNEL_PACKAGE_NAME}-${KERNEL_VERSION}" |
| 669 | ALLOW_EMPTY:${KERNEL_PACKAGE_NAME} = "1" |
| 670 | ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-base = "1" |
| 671 | ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-image = "1" |
| 672 | ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-modules = "1" |
| 673 | DESCRIPTION:${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta package" |
| 674 | |
| 675 | pkg_postinst:${KERNEL_PACKAGE_NAME}-base () { |
| 676 | if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then |
| 677 | mkdir -p $D/lib/modules/${KERNEL_VERSION} |
| 678 | fi |
| 679 | if [ -n "$D" ]; then |
Andrew Geissler | 87f5cff | 2022-09-30 13:13:31 -0500 | [diff] [blame] | 680 | depmodwrapper -a -b $D ${KERNEL_VERSION} ${KERNEL_PACKAGE_NAME} |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 681 | else |
| 682 | depmod -a ${KERNEL_VERSION} |
| 683 | fi |
| 684 | } |
| 685 | |
| 686 | PACKAGESPLITFUNCS:prepend = "split_kernel_packages " |
| 687 | |
| 688 | python split_kernel_packages () { |
| 689 | do_split_packages(d, root='${nonarch_base_libdir}/firmware', file_regex=r'^(.*)\.(bin|fw|cis|csp|dsp)$', output_pattern='${KERNEL_PACKAGE_NAME}-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') |
| 690 | } |
| 691 | |
| 692 | # Many scripts want to look in arch/$arch/boot for the bootable |
| 693 | # image. This poses a problem for vmlinux and vmlinuz based |
| 694 | # booting. This task arranges to have vmlinux and vmlinuz appear |
| 695 | # in the normalized directory location. |
| 696 | do_kernel_link_images() { |
| 697 | if [ ! -d "${B}/arch/${ARCH}/boot" ]; then |
| 698 | mkdir ${B}/arch/${ARCH}/boot |
| 699 | fi |
| 700 | cd ${B}/arch/${ARCH}/boot |
| 701 | ln -sf ../../../vmlinux |
| 702 | if [ -f ../../../vmlinuz ]; then |
| 703 | ln -sf ../../../vmlinuz |
| 704 | fi |
| 705 | if [ -f ../../../vmlinuz.bin ]; then |
| 706 | ln -sf ../../../vmlinuz.bin |
| 707 | fi |
| 708 | if [ -f ../../../vmlinux.64 ]; then |
| 709 | ln -sf ../../../vmlinux.64 |
| 710 | fi |
| 711 | } |
| 712 | addtask kernel_link_images after do_compile before do_strip |
| 713 | |
| 714 | python do_strip() { |
| 715 | import shutil |
| 716 | |
| 717 | strip = d.getVar('STRIP') |
| 718 | extra_sections = d.getVar('KERNEL_IMAGE_STRIP_EXTRA_SECTIONS') |
| 719 | kernel_image = d.getVar('B') + "/" + d.getVar('KERNEL_OUTPUT_DIR') + "/vmlinux" |
| 720 | |
| 721 | if (extra_sections and kernel_image.find(d.getVar('KERNEL_IMAGEDEST') + '/vmlinux') != -1): |
| 722 | kernel_image_stripped = kernel_image + ".stripped" |
| 723 | shutil.copy2(kernel_image, kernel_image_stripped) |
| 724 | oe.package.runstrip((kernel_image_stripped, 8, strip, extra_sections)) |
| 725 | bb.debug(1, "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections: " + \ |
| 726 | extra_sections) |
| 727 | } |
| 728 | do_strip[dirs] = "${B}" |
| 729 | |
| 730 | addtask strip before do_sizecheck after do_kernel_link_images |
| 731 | |
| 732 | # Support checking the kernel size since some kernels need to reside in partitions |
| 733 | # with a fixed length or there is a limit in transferring the kernel to memory. |
| 734 | # If more than one image type is enabled, warn on any that don't fit but only fail |
| 735 | # if none fit. |
| 736 | do_sizecheck() { |
| 737 | if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then |
| 738 | invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'` |
| 739 | if [ -n "$invalid" ]; then |
| 740 | die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integer (The unit is Kbytes)" |
| 741 | fi |
| 742 | at_least_one_fits= |
| 743 | for imageType in ${KERNEL_IMAGETYPES} ; do |
| 744 | size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$imageType | awk '{print $1}'` |
| 745 | if [ $size -gt ${KERNEL_IMAGE_MAXSIZE} ]; then |
| 746 | bbwarn "This kernel $imageType (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device." |
| 747 | else |
| 748 | at_least_one_fits=y |
| 749 | fi |
| 750 | done |
| 751 | if [ -z "$at_least_one_fits" ]; then |
| 752 | die "All kernel images are too big for your device. Please reduce the size of the kernel by making more of it modular." |
| 753 | fi |
| 754 | fi |
| 755 | } |
| 756 | do_sizecheck[dirs] = "${B}" |
| 757 | |
| 758 | addtask sizecheck before do_install after do_strip |
| 759 | |
| 760 | inherit kernel-artifact-names |
| 761 | |
| 762 | kernel_do_deploy() { |
| 763 | deployDir="${DEPLOYDIR}" |
| 764 | if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then |
| 765 | deployDir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}" |
| 766 | mkdir "$deployDir" |
| 767 | fi |
| 768 | |
| 769 | for imageType in ${KERNEL_IMAGETYPES} ; do |
| 770 | baseName=$imageType-${KERNEL_IMAGE_NAME} |
| 771 | |
| 772 | if [ -s ${KERNEL_OUTPUT_DIR}/$imageType.stripped ] ; then |
| 773 | install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.stripped $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT} |
| 774 | else |
| 775 | install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT} |
| 776 | fi |
| 777 | if [ -n "${KERNEL_IMAGE_LINK_NAME}" ] ; then |
| 778 | ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${KERNEL_IMAGE_LINK_NAME}${KERNEL_IMAGE_BIN_EXT} |
| 779 | fi |
| 780 | if [ "${KERNEL_IMAGETYPE_SYMLINK}" = "1" ] ; then |
| 781 | ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType |
| 782 | fi |
| 783 | done |
| 784 | |
| 785 | if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then |
| 786 | mkdir -p ${D}${root_prefix}/lib |
| 787 | if [ -n "${SOURCE_DATE_EPOCH}" ]; then |
| 788 | TAR_ARGS="--sort=name --clamp-mtime --mtime=@${SOURCE_DATE_EPOCH}" |
| 789 | else |
| 790 | TAR_ARGS="" |
| 791 | fi |
| 792 | TAR_ARGS="$TAR_ARGS --owner=0 --group=0" |
| 793 | tar $TAR_ARGS -cv -C ${D}${root_prefix} lib | gzip -9n > $deployDir/modules-${MODULE_TARBALL_NAME}.tgz |
| 794 | |
| 795 | if [ -n "${MODULE_TARBALL_LINK_NAME}" ] ; then |
| 796 | ln -sf modules-${MODULE_TARBALL_NAME}.tgz $deployDir/modules-${MODULE_TARBALL_LINK_NAME}.tgz |
| 797 | fi |
| 798 | fi |
| 799 | |
| 800 | if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then |
| 801 | for imageType in ${KERNEL_IMAGETYPES} ; do |
| 802 | if [ "$imageType" = "fitImage" ] ; then |
| 803 | continue |
| 804 | fi |
| 805 | initramfsBaseName=$imageType-${INITRAMFS_NAME} |
| 806 | install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.initramfs $deployDir/$initramfsBaseName${KERNEL_IMAGE_BIN_EXT} |
| 807 | if [ -n "${INITRAMFS_LINK_NAME}" ] ; then |
| 808 | ln -sf $initramfsBaseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${INITRAMFS_LINK_NAME}${KERNEL_IMAGE_BIN_EXT} |
| 809 | fi |
| 810 | done |
| 811 | fi |
| 812 | } |
| 813 | |
| 814 | # We deploy to filenames that include PKGV and PKGR, read the saved data to |
| 815 | # ensure we get the right values for both |
| 816 | do_deploy[prefuncs] += "read_subpackage_metadata" |
| 817 | |
| 818 | addtask deploy after do_populate_sysroot do_packagedata |
| 819 | |
| 820 | EXPORT_FUNCTIONS do_deploy |
| 821 | |
| 822 | # Add using Device Tree support |
| 823 | inherit kernel-devicetree |