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