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