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