diff options
Diffstat (limited to 'meta/classes/kernel.bbclass')
| -rw-r--r-- | meta/classes/kernel.bbclass | 821 |
1 files changed, 0 insertions, 821 deletions
diff --git a/meta/classes/kernel.bbclass b/meta/classes/kernel.bbclass deleted file mode 100644 index 3463179395..0000000000 --- a/meta/classes/kernel.bbclass +++ /dev/null | |||
| @@ -1,821 +0,0 @@ | |||
| 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 = " HOSTCC="${BUILD_CC}" HOSTCFLAGS="${BUILD_CFLAGS}" HOSTLDFLAGS="${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}"" | ||
| 241 | EXTRA_OEMAKE += " HOSTCXX="${BUILD_CXX}" HOSTCXXFLAGS="${BUILD_CXXFLAGS}" PAHOLE=false" | ||
| 242 | |||
| 243 | KERNEL_ALT_IMAGETYPE ??= "" | ||
| 244 | |||
| 245 | copy_initramfs() { | ||
| 246 | echo "Copying initramfs into ./usr ..." | ||
| 247 | # In case the directory is not created yet from the first pass compile: | ||
| 248 | mkdir -p ${B}/usr | ||
| 249 | # Find and use the first initramfs image archive type we find | ||
| 250 | rm -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio | ||
| 251 | for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.zst; do | ||
| 252 | if [ -e "${INITRAMFS_DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" ]; then | ||
| 253 | cp ${INITRAMFS_DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/. | ||
| 254 | case $img in | ||
| 255 | *gz) | ||
| 256 | echo "gzip decompressing image" | ||
| 257 | gunzip -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img | ||
| 258 | break | ||
| 259 | ;; | ||
| 260 | *lz4) | ||
| 261 | echo "lz4 decompressing image" | ||
| 262 | lz4 -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio | ||
| 263 | break | ||
| 264 | ;; | ||
| 265 | *lzo) | ||
| 266 | echo "lzo decompressing image" | ||
| 267 | lzop -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img | ||
| 268 | break | ||
| 269 | ;; | ||
| 270 | *lzma) | ||
| 271 | echo "lzma decompressing image" | ||
| 272 | lzma -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img | ||
| 273 | break | ||
| 274 | ;; | ||
| 275 | *xz) | ||
| 276 | echo "xz decompressing image" | ||
| 277 | xz -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img | ||
| 278 | break | ||
| 279 | ;; | ||
| 280 | *zst) | ||
| 281 | echo "zst decompressing image" | ||
| 282 | zstd -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img | ||
| 283 | break | ||
| 284 | ;; | ||
| 285 | esac | ||
| 286 | break | ||
| 287 | fi | ||
| 288 | done | ||
| 289 | # Verify that the above loop found a initramfs, fail otherwise | ||
| 290 | [ -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." | ||
| 291 | } | ||
| 292 | |||
| 293 | do_bundle_initramfs () { | ||
| 294 | if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then | ||
| 295 | echo "Creating a kernel image with a bundled initramfs..." | ||
| 296 | copy_initramfs | ||
| 297 | # Backing up kernel image relies on its type(regular file or symbolic link) | ||
| 298 | tmp_path="" | ||
| 299 | for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do | ||
| 300 | if [ -h ${KERNEL_OUTPUT_DIR}/$imageType ] ; then | ||
| 301 | linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$imageType` | ||
| 302 | realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$imageType` | ||
| 303 | mv -f $realpath $realpath.bak | ||
| 304 | tmp_path=$tmp_path" "$imageType"#"$linkpath"#"$realpath | ||
| 305 | elif [ -f ${KERNEL_OUTPUT_DIR}/$imageType ]; then | ||
| 306 | mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.bak | ||
| 307 | tmp_path=$tmp_path" "$imageType"##" | ||
| 308 | fi | ||
| 309 | done | ||
| 310 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio | ||
| 311 | kernel_do_compile | ||
| 312 | # Restoring kernel image | ||
| 313 | for tp in $tmp_path ; do | ||
| 314 | imageType=`echo $tp|cut -d "#" -f 1` | ||
| 315 | linkpath=`echo $tp|cut -d "#" -f 2` | ||
| 316 | realpath=`echo $tp|cut -d "#" -f 3` | ||
| 317 | if [ -n "$realpath" ]; then | ||
| 318 | mv -f $realpath $realpath.initramfs | ||
| 319 | mv -f $realpath.bak $realpath | ||
| 320 | ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$imageType.initramfs | ||
| 321 | else | ||
| 322 | mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.initramfs | ||
| 323 | mv -f ${KERNEL_OUTPUT_DIR}/$imageType.bak ${KERNEL_OUTPUT_DIR}/$imageType | ||
| 324 | fi | ||
| 325 | done | ||
| 326 | fi | ||
| 327 | } | ||
| 328 | do_bundle_initramfs[dirs] = "${B}" | ||
| 329 | |||
| 330 | kernel_do_transform_bundled_initramfs() { | ||
| 331 | # vmlinux.gz is not built by kernel | ||
| 332 | if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then | ||
| 333 | gzip -9cn < ${KERNEL_OUTPUT_DIR}/vmlinux.initramfs > ${KERNEL_OUTPUT_DIR}/vmlinux.gz.initramfs | ||
| 334 | fi | ||
| 335 | } | ||
| 336 | do_transform_bundled_initramfs[dirs] = "${B}" | ||
| 337 | |||
| 338 | python do_devshell:prepend () { | ||
| 339 | os.environ["LDFLAGS"] = '' | ||
| 340 | } | ||
| 341 | |||
| 342 | addtask bundle_initramfs after do_install before do_deploy | ||
| 343 | |||
| 344 | KERNEL_DEBUG_TIMESTAMPS ??= "0" | ||
| 345 | |||
| 346 | kernel_do_compile() { | ||
| 347 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE | ||
| 348 | |||
| 349 | # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native) | ||
| 350 | export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig" | ||
| 351 | export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig" | ||
| 352 | export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR" | ||
| 353 | export PKG_CONFIG_SYSROOT_DIR="" | ||
| 354 | |||
| 355 | if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then | ||
| 356 | # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not | ||
| 357 | # be set.... | ||
| 358 | if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then | ||
| 359 | # The source directory is not necessarily a git repository, so we | ||
| 360 | # specify the git-dir to ensure that git does not query a | ||
| 361 | # repository in any parent directory. | ||
| 362 | SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"` | ||
| 363 | fi | ||
| 364 | |||
| 365 | ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH` | ||
| 366 | export KBUILD_BUILD_TIMESTAMP="$ts" | ||
| 367 | export KCONFIG_NOTIMESTAMP=1 | ||
| 368 | bbnote "KBUILD_BUILD_TIMESTAMP: $ts" | ||
| 369 | fi | ||
| 370 | # The $use_alternate_initrd is only set from | ||
| 371 | # do_bundle_initramfs() This variable is specifically for the | ||
| 372 | # case where we are making a second pass at the kernel | ||
| 373 | # compilation and we want to force the kernel build to use a | ||
| 374 | # different initramfs image. The way to do that in the kernel | ||
| 375 | # is to specify: | ||
| 376 | # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio | ||
| 377 | if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then | ||
| 378 | # The old style way of copying an prebuilt image and building it | ||
| 379 | # is turned on via INTIRAMFS_TASK != "" | ||
| 380 | copy_initramfs | ||
| 381 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio | ||
| 382 | fi | ||
| 383 | for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do | ||
| 384 | oe_runmake ${typeformake} CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd | ||
| 385 | done | ||
| 386 | } | ||
| 387 | |||
| 388 | kernel_do_transform_kernel() { | ||
| 389 | # vmlinux.gz is not built by kernel | ||
| 390 | if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then | ||
| 391 | mkdir -p "${KERNEL_OUTPUT_DIR}" | ||
| 392 | gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz" | ||
| 393 | fi | ||
| 394 | } | ||
| 395 | do_transform_kernel[dirs] = "${B}" | ||
| 396 | addtask transform_kernel after do_compile before do_install | ||
| 397 | |||
| 398 | do_compile_kernelmodules() { | ||
| 399 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE | ||
| 400 | if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then | ||
| 401 | # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not | ||
| 402 | # be set.... | ||
| 403 | if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then | ||
| 404 | # The source directory is not necessarily a git repository, so we | ||
| 405 | # specify the git-dir to ensure that git does not query a | ||
| 406 | # repository in any parent directory. | ||
| 407 | SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"` | ||
| 408 | fi | ||
| 409 | |||
| 410 | ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH` | ||
| 411 | export KBUILD_BUILD_TIMESTAMP="$ts" | ||
| 412 | export KCONFIG_NOTIMESTAMP=1 | ||
| 413 | bbnote "KBUILD_BUILD_TIMESTAMP: $ts" | ||
| 414 | fi | ||
| 415 | if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then | ||
| 416 | oe_runmake -C ${B} ${PARALLEL_MAKE} modules CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} | ||
| 417 | |||
| 418 | # Module.symvers gets updated during the | ||
| 419 | # building of the kernel modules. We need to | ||
| 420 | # update this in the shared workdir since some | ||
| 421 | # external kernel modules has a dependency on | ||
| 422 | # other kernel modules and will look at this | ||
| 423 | # file to do symbol lookups | ||
| 424 | cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/ | ||
| 425 | # 5.10+ kernels have module.lds that we need to copy for external module builds | ||
| 426 | if [ -e "${B}/scripts/module.lds" ]; then | ||
| 427 | install -Dm 0644 ${B}/scripts/module.lds ${STAGING_KERNEL_BUILDDIR}/scripts/module.lds | ||
| 428 | fi | ||
| 429 | else | ||
| 430 | bbnote "no modules to compile" | ||
| 431 | fi | ||
| 432 | } | ||
| 433 | addtask compile_kernelmodules after do_compile before do_strip | ||
| 434 | |||
| 435 | kernel_do_install() { | ||
| 436 | # | ||
| 437 | # First install the modules | ||
| 438 | # | ||
| 439 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE | ||
| 440 | if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then | ||
| 441 | oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install | ||
| 442 | rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build" | ||
| 443 | rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source" | ||
| 444 | # If the kernel/ directory is empty remove it to prevent QA issues | ||
| 445 | rmdir --ignore-fail-on-non-empty "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel" | ||
| 446 | else | ||
| 447 | bbnote "no modules to install" | ||
| 448 | fi | ||
| 449 | |||
| 450 | # | ||
| 451 | # Install various kernel output (zImage, map file, config, module support files) | ||
| 452 | # | ||
| 453 | install -d ${D}/${KERNEL_IMAGEDEST} | ||
| 454 | |||
| 455 | # | ||
| 456 | # When including an initramfs bundle inside a FIT image, the fitImage is created after the install task | ||
| 457 | # by do_assemble_fitimage_initramfs. | ||
| 458 | # This happens after the generation of the initramfs bundle (done by do_bundle_initramfs). | ||
| 459 | # So, at the level of the install task we should not try to install the fitImage. fitImage is still not | ||
| 460 | # generated yet. | ||
| 461 | # After the generation of the fitImage, the deploy task copies the fitImage from the build directory to | ||
| 462 | # the deploy folder. | ||
| 463 | # | ||
| 464 | |||
| 465 | for imageType in ${KERNEL_IMAGETYPES} ; do | ||
| 466 | if [ $imageType != "fitImage" ] || [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ] ; then | ||
| 467 | install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType ${D}/${KERNEL_IMAGEDEST}/$imageType-${KERNEL_VERSION} | ||
| 468 | fi | ||
| 469 | done | ||
| 470 | |||
| 471 | install -m 0644 System.map ${D}/${KERNEL_IMAGEDEST}/System.map-${KERNEL_VERSION} | ||
| 472 | install -m 0644 .config ${D}/${KERNEL_IMAGEDEST}/config-${KERNEL_VERSION} | ||
| 473 | install -m 0644 vmlinux ${D}/${KERNEL_IMAGEDEST}/vmlinux-${KERNEL_VERSION} | ||
| 474 | [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/${KERNEL_IMAGEDEST}/Module.symvers-${KERNEL_VERSION} | ||
| 475 | install -d ${D}${sysconfdir}/modules-load.d | ||
| 476 | install -d ${D}${sysconfdir}/modprobe.d | ||
| 477 | } | ||
| 478 | |||
| 479 | # Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile | ||
| 480 | do_kernel_version_sanity_check() { | ||
| 481 | if [ "x${KERNEL_VERSION_SANITY_SKIP}" = "x1" ]; then | ||
| 482 | exit 0 | ||
| 483 | fi | ||
| 484 | |||
| 485 | # The Makefile determines the kernel version shown at runtime | ||
| 486 | # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile | ||
| 487 | VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//) | ||
| 488 | PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//) | ||
| 489 | SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//) | ||
| 490 | EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//) | ||
| 491 | |||
| 492 | # Build a string for regex and a plain version string | ||
| 493 | reg="^${VERSION}\.${PATCHLEVEL}" | ||
| 494 | vers="${VERSION}.${PATCHLEVEL}" | ||
| 495 | if [ -n "${SUBLEVEL}" ]; then | ||
| 496 | # Ignoring a SUBLEVEL of zero is fine | ||
| 497 | if [ "${SUBLEVEL}" = "0" ]; then | ||
| 498 | reg="${reg}(\.${SUBLEVEL})?" | ||
| 499 | else | ||
| 500 | reg="${reg}\.${SUBLEVEL}" | ||
| 501 | vers="${vers}.${SUBLEVEL}" | ||
| 502 | fi | ||
| 503 | fi | ||
| 504 | vers="${vers}${EXTRAVERSION}" | ||
| 505 | reg="${reg}${EXTRAVERSION}" | ||
| 506 | |||
| 507 | if [ -z `echo ${PV} | grep -E "${reg}"` ]; then | ||
| 508 | 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." | ||
| 509 | fi | ||
| 510 | exit 0 | ||
| 511 | } | ||
| 512 | |||
| 513 | addtask shared_workdir after do_compile before do_compile_kernelmodules | ||
| 514 | addtask shared_workdir_setscene | ||
| 515 | |||
| 516 | do_shared_workdir_setscene () { | ||
| 517 | exit 1 | ||
| 518 | } | ||
| 519 | |||
| 520 | emit_depmod_pkgdata() { | ||
| 521 | # Stash data for depmod | ||
| 522 | install -d ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/ | ||
| 523 | echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/${KERNEL_PACKAGE_NAME}-abiversion | ||
| 524 | cp ${B}/System.map ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/System.map-${KERNEL_VERSION} | ||
| 525 | } | ||
| 526 | |||
| 527 | PACKAGEFUNCS += "emit_depmod_pkgdata" | ||
| 528 | |||
| 529 | do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}" | ||
| 530 | do_shared_workdir () { | ||
| 531 | cd ${B} | ||
| 532 | |||
| 533 | kerneldir=${STAGING_KERNEL_BUILDDIR} | ||
| 534 | install -d $kerneldir | ||
| 535 | |||
| 536 | # | ||
| 537 | # Store the kernel version in sysroots for module-base.bbclass | ||
| 538 | # | ||
| 539 | |||
| 540 | echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion | ||
| 541 | |||
| 542 | # Copy files required for module builds | ||
| 543 | cp System.map $kerneldir/System.map-${KERNEL_VERSION} | ||
| 544 | [ -e Module.symvers ] && cp Module.symvers $kerneldir/ | ||
| 545 | cp .config $kerneldir/ | ||
| 546 | mkdir -p $kerneldir/include/config | ||
| 547 | cp include/config/kernel.release $kerneldir/include/config/kernel.release | ||
| 548 | if [ -e certs/signing_key.x509 ]; then | ||
| 549 | # The signing_key.* files are stored in the certs/ dir in | ||
| 550 | # newer Linux kernels | ||
| 551 | mkdir -p $kerneldir/certs | ||
| 552 | cp certs/signing_key.* $kerneldir/certs/ | ||
| 553 | elif [ -e signing_key.priv ]; then | ||
| 554 | cp signing_key.* $kerneldir/ | ||
| 555 | fi | ||
| 556 | |||
| 557 | # We can also copy over all the generated files and avoid special cases | ||
| 558 | # like version.h, but we've opted to keep this small until file creep starts | ||
| 559 | # to happen | ||
| 560 | if [ -e include/linux/version.h ]; then | ||
| 561 | mkdir -p $kerneldir/include/linux | ||
| 562 | cp include/linux/version.h $kerneldir/include/linux/version.h | ||
| 563 | fi | ||
| 564 | |||
| 565 | # As of Linux kernel version 3.0.1, the clean target removes | ||
| 566 | # arch/powerpc/lib/crtsavres.o which is present in | ||
| 567 | # KBUILD_LDFLAGS_MODULE, making it required to build external modules. | ||
| 568 | if [ ${ARCH} = "powerpc" ]; then | ||
| 569 | if [ -e arch/powerpc/lib/crtsavres.o ]; then | ||
| 570 | mkdir -p $kerneldir/arch/powerpc/lib/ | ||
| 571 | cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o | ||
| 572 | fi | ||
| 573 | fi | ||
| 574 | |||
| 575 | if [ -d include/generated ]; then | ||
| 576 | mkdir -p $kerneldir/include/generated/ | ||
| 577 | cp -fR include/generated/* $kerneldir/include/generated/ | ||
| 578 | fi | ||
| 579 | |||
| 580 | if [ -d arch/${ARCH}/include/generated ]; then | ||
| 581 | mkdir -p $kerneldir/arch/${ARCH}/include/generated/ | ||
| 582 | cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/ | ||
| 583 | fi | ||
| 584 | |||
| 585 | if (grep -q -i -e '^CONFIG_UNWINDER_ORC=y$' $kerneldir/.config); then | ||
| 586 | # With CONFIG_UNWINDER_ORC (the default in 4.14), objtool is required for | ||
| 587 | # out-of-tree modules to be able to generate object files. | ||
| 588 | if [ -x tools/objtool/objtool ]; then | ||
| 589 | mkdir -p ${kerneldir}/tools/objtool | ||
| 590 | cp tools/objtool/objtool ${kerneldir}/tools/objtool/ | ||
| 591 | fi | ||
| 592 | fi | ||
| 593 | } | ||
| 594 | |||
| 595 | # We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware | ||
| 596 | sysroot_stage_all () { | ||
| 597 | : | ||
| 598 | } | ||
| 599 | |||
| 600 | KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} CC="${KERNEL_CC}" LD="${KERNEL_LD}" O=${B} olddefconfig || oe_runmake -C ${S} O=${B} CC="${KERNEL_CC}" LD="${KERNEL_LD}" oldnoconfig" | ||
| 601 | |||
| 602 | python check_oldest_kernel() { | ||
| 603 | oldest_kernel = d.getVar('OLDEST_KERNEL') | ||
| 604 | kernel_version = d.getVar('KERNEL_VERSION') | ||
| 605 | tclibc = d.getVar('TCLIBC') | ||
| 606 | if tclibc == 'glibc': | ||
| 607 | kernel_version = kernel_version.split('-', 1)[0] | ||
| 608 | if oldest_kernel and kernel_version: | ||
| 609 | if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0: | ||
| 610 | 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)) | ||
| 611 | } | ||
| 612 | |||
| 613 | check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION" | ||
| 614 | do_configure[prefuncs] += "check_oldest_kernel" | ||
| 615 | |||
| 616 | kernel_do_configure() { | ||
| 617 | # fixes extra + in /lib/modules/2.6.37+ | ||
| 618 | # $ scripts/setlocalversion . => + | ||
| 619 | # $ make kernelversion => 2.6.37 | ||
| 620 | # $ make kernelrelease => 2.6.37+ | ||
| 621 | touch ${B}/.scmversion ${S}/.scmversion | ||
| 622 | |||
| 623 | if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then | ||
| 624 | mv "${S}/.config" "${B}/.config" | ||
| 625 | fi | ||
| 626 | |||
| 627 | # Copy defconfig to .config if .config does not exist. This allows | ||
| 628 | # recipes to manage the .config themselves in do_configure:prepend(). | ||
| 629 | if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then | ||
| 630 | cp "${WORKDIR}/defconfig" "${B}/.config" | ||
| 631 | fi | ||
| 632 | |||
| 633 | ${KERNEL_CONFIG_COMMAND} | ||
| 634 | } | ||
| 635 | |||
| 636 | do_savedefconfig() { | ||
| 637 | bbplain "Saving defconfig to:\n${B}/defconfig" | ||
| 638 | oe_runmake -C ${B} LD='${KERNEL_LD}' savedefconfig | ||
| 639 | } | ||
| 640 | do_savedefconfig[nostamp] = "1" | ||
| 641 | addtask savedefconfig after do_configure | ||
| 642 | |||
| 643 | inherit cml1 | ||
| 644 | |||
| 645 | KCONFIG_CONFIG_COMMAND:append = " PAHOLE=false LD='${KERNEL_LD}' HOSTLDFLAGS='${BUILD_LDFLAGS}'" | ||
| 646 | |||
| 647 | EXPORT_FUNCTIONS do_compile do_transform_kernel do_transform_bundled_initramfs do_install do_configure | ||
| 648 | |||
| 649 | # kernel-base becomes kernel-${KERNEL_VERSION} | ||
| 650 | # kernel-image becomes kernel-image-${KERNEL_VERSION} | ||
| 651 | 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" | ||
| 652 | FILES:${PN} = "" | ||
| 653 | 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" | ||
| 654 | FILES:${KERNEL_PACKAGE_NAME}-image = "" | ||
| 655 | 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" | ||
| 656 | FILES:${KERNEL_PACKAGE_NAME}-vmlinux = "/${KERNEL_IMAGEDEST}/vmlinux-${KERNEL_VERSION_NAME}" | ||
| 657 | FILES:${KERNEL_PACKAGE_NAME}-modules = "" | ||
| 658 | FILES:${KERNEL_PACKAGE_NAME}-dbg = "/usr/lib/debug /usr/src/debug" | ||
| 659 | RDEPENDS:${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base (= ${EXTENDPKGV})" | ||
| 660 | # Allow machines to override this dependency if kernel image files are | ||
| 661 | # not wanted in images as standard | ||
| 662 | RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base ?= "${KERNEL_PACKAGE_NAME}-image (= ${EXTENDPKGV})" | ||
| 663 | PKG:${KERNEL_PACKAGE_NAME}-image = "${KERNEL_PACKAGE_NAME}-image-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}" | ||
| 664 | RDEPENDS:${KERNEL_PACKAGE_NAME}-image += "${@oe.utils.conditional('KERNEL_IMAGETYPE', 'vmlinux', '${KERNEL_PACKAGE_NAME}-vmlinux (= ${EXTENDPKGV})', '', d)}" | ||
| 665 | PKG:${KERNEL_PACKAGE_NAME}-base = "${KERNEL_PACKAGE_NAME}-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}" | ||
| 666 | RPROVIDES:${KERNEL_PACKAGE_NAME}-base += "${KERNEL_PACKAGE_NAME}-${KERNEL_VERSION}" | ||
| 667 | ALLOW_EMPTY:${KERNEL_PACKAGE_NAME} = "1" | ||
| 668 | ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-base = "1" | ||
| 669 | ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-image = "1" | ||
| 670 | ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-modules = "1" | ||
| 671 | DESCRIPTION:${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta package" | ||
| 672 | |||
| 673 | pkg_postinst:${KERNEL_PACKAGE_NAME}-base () { | ||
| 674 | if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then | ||
| 675 | mkdir -p $D/lib/modules/${KERNEL_VERSION} | ||
| 676 | fi | ||
| 677 | if [ -n "$D" ]; then | ||
| 678 | depmodwrapper -a -b $D ${KERNEL_VERSION} | ||
| 679 | else | ||
| 680 | depmod -a ${KERNEL_VERSION} | ||
| 681 | fi | ||
| 682 | } | ||
| 683 | |||
| 684 | PACKAGESPLITFUNCS:prepend = "split_kernel_packages " | ||
| 685 | |||
| 686 | python split_kernel_packages () { | ||
| 687 | 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='') | ||
| 688 | } | ||
| 689 | |||
| 690 | # Many scripts want to look in arch/$arch/boot for the bootable | ||
| 691 | # image. This poses a problem for vmlinux and vmlinuz based | ||
| 692 | # booting. This task arranges to have vmlinux and vmlinuz appear | ||
| 693 | # in the normalized directory location. | ||
| 694 | do_kernel_link_images() { | ||
| 695 | if [ ! -d "${B}/arch/${ARCH}/boot" ]; then | ||
| 696 | mkdir ${B}/arch/${ARCH}/boot | ||
| 697 | fi | ||
| 698 | cd ${B}/arch/${ARCH}/boot | ||
| 699 | ln -sf ../../../vmlinux | ||
| 700 | if [ -f ../../../vmlinuz ]; then | ||
| 701 | ln -sf ../../../vmlinuz | ||
| 702 | fi | ||
| 703 | if [ -f ../../../vmlinuz.bin ]; then | ||
| 704 | ln -sf ../../../vmlinuz.bin | ||
| 705 | fi | ||
| 706 | if [ -f ../../../vmlinux.64 ]; then | ||
| 707 | ln -sf ../../../vmlinux.64 | ||
| 708 | fi | ||
| 709 | } | ||
| 710 | addtask kernel_link_images after do_compile before do_strip | ||
| 711 | |||
| 712 | python do_strip() { | ||
| 713 | import shutil | ||
| 714 | |||
| 715 | strip = d.getVar('STRIP') | ||
| 716 | extra_sections = d.getVar('KERNEL_IMAGE_STRIP_EXTRA_SECTIONS') | ||
| 717 | kernel_image = d.getVar('B') + "/" + d.getVar('KERNEL_OUTPUT_DIR') + "/vmlinux" | ||
| 718 | |||
| 719 | if (extra_sections and kernel_image.find(d.getVar('KERNEL_IMAGEDEST') + '/vmlinux') != -1): | ||
| 720 | kernel_image_stripped = kernel_image + ".stripped" | ||
| 721 | shutil.copy2(kernel_image, kernel_image_stripped) | ||
| 722 | oe.package.runstrip((kernel_image_stripped, 8, strip, extra_sections)) | ||
| 723 | bb.debug(1, "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections: " + \ | ||
| 724 | extra_sections) | ||
| 725 | } | ||
| 726 | do_strip[dirs] = "${B}" | ||
| 727 | |||
| 728 | addtask strip before do_sizecheck after do_kernel_link_images | ||
| 729 | |||
| 730 | # Support checking the kernel size since some kernels need to reside in partitions | ||
| 731 | # with a fixed length or there is a limit in transferring the kernel to memory. | ||
| 732 | # If more than one image type is enabled, warn on any that don't fit but only fail | ||
| 733 | # if none fit. | ||
| 734 | do_sizecheck() { | ||
| 735 | if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then | ||
| 736 | invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'` | ||
| 737 | if [ -n "$invalid" ]; then | ||
| 738 | die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integer (The unit is Kbytes)" | ||
| 739 | fi | ||
| 740 | at_least_one_fits= | ||
| 741 | for imageType in ${KERNEL_IMAGETYPES} ; do | ||
| 742 | size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$imageType | awk '{print $1}'` | ||
| 743 | if [ $size -gt ${KERNEL_IMAGE_MAXSIZE} ]; then | ||
| 744 | bbwarn "This kernel $imageType (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device." | ||
| 745 | else | ||
| 746 | at_least_one_fits=y | ||
| 747 | fi | ||
| 748 | done | ||
| 749 | if [ -z "$at_least_one_fits" ]; then | ||
| 750 | die "All kernel images are too big for your device. Please reduce the size of the kernel by making more of it modular." | ||
| 751 | fi | ||
| 752 | fi | ||
| 753 | } | ||
| 754 | do_sizecheck[dirs] = "${B}" | ||
| 755 | |||
| 756 | addtask sizecheck before do_install after do_strip | ||
| 757 | |||
| 758 | inherit kernel-artifact-names | ||
| 759 | |||
| 760 | kernel_do_deploy() { | ||
| 761 | deployDir="${DEPLOYDIR}" | ||
| 762 | if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then | ||
| 763 | deployDir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}" | ||
| 764 | mkdir "$deployDir" | ||
| 765 | fi | ||
| 766 | |||
| 767 | for imageType in ${KERNEL_IMAGETYPES} ; do | ||
| 768 | baseName=$imageType-${KERNEL_IMAGE_NAME} | ||
| 769 | |||
| 770 | if [ -s ${KERNEL_OUTPUT_DIR}/$imageType.stripped ] ; then | ||
| 771 | install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.stripped $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT} | ||
| 772 | else | ||
| 773 | install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT} | ||
| 774 | fi | ||
| 775 | if [ -n "${KERNEL_IMAGE_LINK_NAME}" ] ; then | ||
| 776 | ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${KERNEL_IMAGE_LINK_NAME}${KERNEL_IMAGE_BIN_EXT} | ||
| 777 | fi | ||
| 778 | if [ "${KERNEL_IMAGETYPE_SYMLINK}" = "1" ] ; then | ||
| 779 | ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType | ||
| 780 | fi | ||
| 781 | done | ||
| 782 | |||
| 783 | if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then | ||
| 784 | mkdir -p ${D}${root_prefix}/lib | ||
| 785 | if [ -n "${SOURCE_DATE_EPOCH}" ]; then | ||
| 786 | TAR_ARGS="--sort=name --clamp-mtime --mtime=@${SOURCE_DATE_EPOCH}" | ||
| 787 | else | ||
| 788 | TAR_ARGS="" | ||
| 789 | fi | ||
| 790 | TAR_ARGS="$TAR_ARGS --owner=0 --group=0" | ||
| 791 | tar $TAR_ARGS -cv -C ${D}${root_prefix} lib | gzip -9n > $deployDir/modules-${MODULE_TARBALL_NAME}.tgz | ||
| 792 | |||
| 793 | if [ -n "${MODULE_TARBALL_LINK_NAME}" ] ; then | ||
| 794 | ln -sf modules-${MODULE_TARBALL_NAME}.tgz $deployDir/modules-${MODULE_TARBALL_LINK_NAME}.tgz | ||
| 795 | fi | ||
| 796 | fi | ||
| 797 | |||
| 798 | if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then | ||
| 799 | for imageType in ${KERNEL_IMAGETYPES} ; do | ||
| 800 | if [ "$imageType" = "fitImage" ] ; then | ||
| 801 | continue | ||
| 802 | fi | ||
| 803 | initramfsBaseName=$imageType-${INITRAMFS_NAME} | ||
| 804 | install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.initramfs $deployDir/$initramfsBaseName${KERNEL_IMAGE_BIN_EXT} | ||
| 805 | if [ -n "${INITRAMFS_LINK_NAME}" ] ; then | ||
| 806 | ln -sf $initramfsBaseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${INITRAMFS_LINK_NAME}${KERNEL_IMAGE_BIN_EXT} | ||
| 807 | fi | ||
| 808 | done | ||
| 809 | fi | ||
| 810 | } | ||
| 811 | |||
| 812 | # We deploy to filenames that include PKGV and PKGR, read the saved data to | ||
| 813 | # ensure we get the right values for both | ||
| 814 | do_deploy[prefuncs] += "read_subpackage_metadata" | ||
| 815 | |||
| 816 | addtask deploy after do_populate_sysroot do_packagedata | ||
| 817 | |||
| 818 | EXPORT_FUNCTIONS do_deploy | ||
| 819 | |||
| 820 | # Add using Device Tree support | ||
| 821 | inherit kernel-devicetree | ||
