blob: b084d6d69dc15116f5c78e543b13b2672c9331e6 [file] [log] [blame]
Patrick Williams92b42cb2022-09-03 06:53:57 -05001#
2# Copyright OpenEmbedded Contributors
3#
4# SPDX-License-Identifier: MIT
5#
6
7inherit linux-kernel-base kernel-module-split
8
9COMPATIBLE_HOST = ".*-linux"
10
11KERNEL_PACKAGE_NAME ??= "kernel"
12KERNEL_DEPLOYSUBDIR ??= "${@ "" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else d.getVar("KERNEL_PACKAGE_NAME") }"
13
14PROVIDES += "virtual/kernel"
15DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native bc-native bison-native"
16DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.lzo", "lzop-native", "", d)}"
17DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.lz4", "lz4-native", "", d)}"
18DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.zst", "zstd-native", "", d)}"
19PACKAGE_WRITE_DEPS += "depmodwrapper-cross"
20
21do_deploy[depends] += "depmodwrapper-cross:do_populate_sysroot gzip-native:do_populate_sysroot"
22do_clean[depends] += "make-mod-scripts:do_clean"
23
24CVE_PRODUCT ?= "linux_kernel"
25
26S = "${STAGING_KERNEL_DIR}"
27B = "${WORKDIR}/build"
28KBUILD_OUTPUT = "${B}"
29OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
30
31# we include gcc above, we dont need virtual/libc
32INHIBIT_DEFAULT_DEPS = "1"
33
34KERNEL_IMAGETYPE ?= "zImage"
35INITRAMFS_IMAGE ?= ""
Patrick Williams92b42cb2022-09-03 06:53:57 -050036INITRAMFS_TASK ?= ""
37INITRAMFS_IMAGE_BUNDLE ?= ""
38INITRAMFS_DEPLOY_DIR_IMAGE ?= "${DEPLOY_DIR_IMAGE}"
39INITRAMFS_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.
47KERNEL_VERSION_NAME = "${@d.getVar('KERNEL_VERSION') or ""}"
48KERNEL_VERSION_NAME[vardepvalue] = "${LINUX_VERSION}"
49KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
50KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}"
51
52python __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)
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600114 d.appendVar('RPROVIDES:%s-modules' % kname, ' %s-modules-${KERNEL_VERSION_PKG_NAME}' % kname)
Patrick Williams92b42cb2022-09-03 06:53:57 -0500115
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
119if [ -n "$D" ]; then
120 ln -sf %s-${KERNEL_VERSION} $D/${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
121else
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
127fi
128set -e
129""" % (type, type, type, type, type, type, type))
130 d.setVar('pkg_postrm:%s-image-%s' % (kname,typelower), """set +e
131if [ -f "${KERNEL_IMAGEDEST}/%s" -o -L "${KERNEL_IMAGEDEST}/%s" ]; then
132 rm -f ${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
133fi
134set -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
173KERNEL_CLASSES ?= " kernel-uimage "
Patrick Williams56b44a92024-01-19 08:49:29 -0600174inherit_defer ${KERNEL_CLASSES}
Patrick Williams92b42cb2022-09-03 06:53:57 -0500175
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.
180do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
181do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
182python do_symlink_kernsrc () {
183 s = d.getVar("S")
Patrick Williams92b42cb2022-09-03 06:53:57 -0500184 kernsrc = d.getVar("STAGING_KERNEL_DIR")
185 if s != kernsrc:
186 bb.utils.mkdirhier(kernsrc)
187 bb.utils.remove(kernsrc, recurse=True)
Andrew Geissler8f840682023-07-21 09:09:43 -0500188 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 Williams92b42cb2022-09-03 06:53:57 -0500192 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.
203addtask symlink_kernsrc before do_patch do_configure after do_unpack
204
205inherit kernel-arch deploy
206
207PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
208PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-image-.*"
209PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-firmware-.*"
210
211export OS = "${TARGET_OS}"
212export CROSS_COMPILE = "${TARGET_PREFIX}"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500213
214KERNEL_RELEASE ?= "${KERNEL_VERSION}"
215
216# The directory where built kernel lies in the kernel tree
217KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot"
218KERNEL_IMAGEDEST ?= "boot"
Andrew Geissler028142b2023-05-05 11:29:21 -0500219KERNEL_DTBDEST ?= "${KERNEL_IMAGEDEST}"
Patrick Williamse760df82023-05-26 11:10:49 -0500220KERNEL_DTBVENDORED ?= "0"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500221
222#
223# configuration
224#
225export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE") or "ttyS0"}"
226
227KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}"
228
229# kernels are generally machine specific
230PACKAGE_ARCH = "${MACHINE_ARCH}"
231
232# U-Boot support
233UBOOT_ENTRYPOINT ?= "20008000"
234UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}"
235
236# Some Linux kernel configurations need additional parameters on the command line
237KERNEL_EXTRA_ARGS ?= ""
238
Patrick Williams520786c2023-06-25 16:20:36 -0500239EXTRA_OEMAKE += ' CC="${KERNEL_CC}" LD="${KERNEL_LD}" OBJCOPY="${KERNEL_OBJCOPY}" STRIP="${KERNEL_STRIP}"'
Patrick Williams92b42cb2022-09-03 06:53:57 -0500240EXTRA_OEMAKE += ' HOSTCC="${BUILD_CC}" HOSTCFLAGS="${BUILD_CFLAGS}" HOSTLDFLAGS="${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}"'
Patrick Williamsb542dec2023-06-09 01:26:37 -0500241EXTRA_OEMAKE += ' HOSTCXX="${BUILD_CXX}" HOSTCXXFLAGS="${BUILD_CXXFLAGS}"'
Patrick Williams39653562024-03-01 08:54:02 -0600242# Only for newer kernels (5.19+), native pkg-config variables are set for older kernels when building kernel and modules
243EXTRA_OEMAKE += ' HOSTPKG_CONFIG="pkg-config-native"'
Patrick Williams92b42cb2022-09-03 06:53:57 -0500244
245KERNEL_ALT_IMAGETYPE ??= ""
246
247copy_initramfs() {
248 echo "Copying initramfs into ./usr ..."
249 # In case the directory is not created yet from the first pass compile:
250 mkdir -p ${B}/usr
251 # Find and use the first initramfs image archive type we find
252 rm -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
253 for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.zst; do
254 if [ -e "${INITRAMFS_DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" ]; then
255 cp ${INITRAMFS_DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/.
256 case $img in
257 *gz)
258 echo "gzip decompressing image"
259 gunzip -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
260 break
261 ;;
262 *lz4)
263 echo "lz4 decompressing image"
264 lz4 -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
265 break
266 ;;
267 *lzo)
268 echo "lzo decompressing image"
269 lzop -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
270 break
271 ;;
272 *lzma)
273 echo "lzma decompressing image"
274 lzma -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
275 break
276 ;;
277 *xz)
278 echo "xz decompressing image"
279 xz -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
280 break
281 ;;
282 *zst)
283 echo "zst decompressing image"
284 zstd -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
285 break
286 ;;
287 esac
288 break
289 fi
290 done
291 # Verify that the above loop found a initramfs, fail otherwise
292 [ -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."
293}
294
295do_bundle_initramfs () {
296 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
297 echo "Creating a kernel image with a bundled initramfs..."
298 copy_initramfs
299 # Backing up kernel image relies on its type(regular file or symbolic link)
300 tmp_path=""
301 for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
302 if [ -h ${KERNEL_OUTPUT_DIR}/$imageType ] ; then
303 linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$imageType`
304 realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$imageType`
305 mv -f $realpath $realpath.bak
306 tmp_path=$tmp_path" "$imageType"#"$linkpath"#"$realpath
307 elif [ -f ${KERNEL_OUTPUT_DIR}/$imageType ]; then
308 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.bak
309 tmp_path=$tmp_path" "$imageType"##"
310 fi
311 done
312 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
313 kernel_do_compile
314 # Restoring kernel image
315 for tp in $tmp_path ; do
316 imageType=`echo $tp|cut -d "#" -f 1`
317 linkpath=`echo $tp|cut -d "#" -f 2`
318 realpath=`echo $tp|cut -d "#" -f 3`
319 if [ -n "$realpath" ]; then
320 mv -f $realpath $realpath.initramfs
321 mv -f $realpath.bak $realpath
322 ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$imageType.initramfs
323 else
324 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.initramfs
325 mv -f ${KERNEL_OUTPUT_DIR}/$imageType.bak ${KERNEL_OUTPUT_DIR}/$imageType
326 fi
327 done
328 fi
329}
330do_bundle_initramfs[dirs] = "${B}"
331
332kernel_do_transform_bundled_initramfs() {
333 # vmlinux.gz is not built by kernel
334 if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then
335 gzip -9cn < ${KERNEL_OUTPUT_DIR}/vmlinux.initramfs > ${KERNEL_OUTPUT_DIR}/vmlinux.gz.initramfs
336 fi
337}
338do_transform_bundled_initramfs[dirs] = "${B}"
339
Patrick Williams520786c2023-06-25 16:20:36 -0500340python do_package:prepend () {
Patrick Williamsac13d5f2023-11-24 18:59:46 -0600341 d.setVar('STRIP', d.getVar('KERNEL_STRIP').strip())
Patrick Williams520786c2023-06-25 16:20:36 -0500342}
343
Patrick Williams92b42cb2022-09-03 06:53:57 -0500344python do_devshell:prepend () {
345 os.environ["LDFLAGS"] = ''
346}
347
348addtask bundle_initramfs after do_install before do_deploy
349
350KERNEL_DEBUG_TIMESTAMPS ??= "0"
351
352kernel_do_compile() {
353 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
354
355 # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
356 export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig"
357 export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig"
358 export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
359 export PKG_CONFIG_SYSROOT_DIR=""
360
361 if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
362 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
363 # be set....
364 if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
365 # The source directory is not necessarily a git repository, so we
366 # specify the git-dir to ensure that git does not query a
367 # repository in any parent directory.
368 SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
369 fi
370
371 ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
372 export KBUILD_BUILD_TIMESTAMP="$ts"
373 export KCONFIG_NOTIMESTAMP=1
374 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
Andrew Geissler517393d2023-01-13 08:55:19 -0600375 else
376 ts=`LC_ALL=C date`
377 export KBUILD_BUILD_TIMESTAMP="$ts"
378 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500379 fi
380 # The $use_alternate_initrd is only set from
381 # do_bundle_initramfs() This variable is specifically for the
382 # case where we are making a second pass at the kernel
383 # compilation and we want to force the kernel build to use a
384 # different initramfs image. The way to do that in the kernel
385 # is to specify:
386 # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio
387 if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then
388 # The old style way of copying an prebuilt image and building it
389 # is turned on via INTIRAMFS_TASK != ""
390 copy_initramfs
391 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
392 fi
393 for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
Patrick Williams8e7b46e2023-05-01 14:19:06 -0500394 oe_runmake ${PARALLEL_MAKE} ${typeformake} ${KERNEL_EXTRA_ARGS} $use_alternate_initrd
Patrick Williams92b42cb2022-09-03 06:53:57 -0500395 done
396}
397
398kernel_do_transform_kernel() {
399 # vmlinux.gz is not built by kernel
400 if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then
401 mkdir -p "${KERNEL_OUTPUT_DIR}"
402 gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz"
403 fi
404}
405do_transform_kernel[dirs] = "${B}"
406addtask transform_kernel after do_compile before do_install
407
408do_compile_kernelmodules() {
409 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
Patrick Williams39653562024-03-01 08:54:02 -0600410
411 # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
412 export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig"
413 export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig"
414 export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
415 export PKG_CONFIG_SYSROOT_DIR=""
416
Patrick Williams92b42cb2022-09-03 06:53:57 -0500417 if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
418 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
419 # be set....
420 if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
421 # The source directory is not necessarily a git repository, so we
422 # specify the git-dir to ensure that git does not query a
423 # repository in any parent directory.
424 SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
425 fi
426
427 ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
428 export KBUILD_BUILD_TIMESTAMP="$ts"
429 export KCONFIG_NOTIMESTAMP=1
430 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
Andrew Geissler517393d2023-01-13 08:55:19 -0600431 else
432 ts=`LC_ALL=C date`
433 export KBUILD_BUILD_TIMESTAMP="$ts"
434 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500435 fi
436 if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
437 oe_runmake -C ${B} ${PARALLEL_MAKE} modules ${KERNEL_EXTRA_ARGS}
438
Andrew Geissler8f840682023-07-21 09:09:43 -0500439 # Module.symvers gets updated during the
Patrick Williams92b42cb2022-09-03 06:53:57 -0500440 # building of the kernel modules. We need to
441 # update this in the shared workdir since some
442 # external kernel modules has a dependency on
443 # other kernel modules and will look at this
444 # file to do symbol lookups
445 cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/
446 # 5.10+ kernels have module.lds that we need to copy for external module builds
447 if [ -e "${B}/scripts/module.lds" ]; then
448 install -Dm 0644 ${B}/scripts/module.lds ${STAGING_KERNEL_BUILDDIR}/scripts/module.lds
449 fi
450 else
451 bbnote "no modules to compile"
452 fi
453}
454addtask compile_kernelmodules after do_compile before do_strip
455
456kernel_do_install() {
457 #
458 # First install the modules
459 #
460 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
461 if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
462 oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
Andrew Geissler5082cc72023-09-11 08:41:39 -0400463 rm -f "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
464 rm -f "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
Andrew Geissler517393d2023-01-13 08:55:19 -0600465 # Remove empty module directories to prevent QA issues
466 find "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel" -type d -empty -delete
Patrick Williams92b42cb2022-09-03 06:53:57 -0500467 else
468 bbnote "no modules to install"
469 fi
470
471 #
472 # Install various kernel output (zImage, map file, config, module support files)
473 #
474 install -d ${D}/${KERNEL_IMAGEDEST}
475
476 #
477 # When including an initramfs bundle inside a FIT image, the fitImage is created after the install task
478 # by do_assemble_fitimage_initramfs.
479 # This happens after the generation of the initramfs bundle (done by do_bundle_initramfs).
480 # So, at the level of the install task we should not try to install the fitImage. fitImage is still not
481 # generated yet.
482 # After the generation of the fitImage, the deploy task copies the fitImage from the build directory to
483 # the deploy folder.
484 #
485
486 for imageType in ${KERNEL_IMAGETYPES} ; do
487 if [ $imageType != "fitImage" ] || [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ] ; then
488 install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType ${D}/${KERNEL_IMAGEDEST}/$imageType-${KERNEL_VERSION}
489 fi
490 done
491
492 install -m 0644 System.map ${D}/${KERNEL_IMAGEDEST}/System.map-${KERNEL_VERSION}
493 install -m 0644 .config ${D}/${KERNEL_IMAGEDEST}/config-${KERNEL_VERSION}
494 install -m 0644 vmlinux ${D}/${KERNEL_IMAGEDEST}/vmlinux-${KERNEL_VERSION}
Joel Stanleybed4be12023-08-02 21:17:05 +0930495 ! [ -e Module.symvers ] || install -m 0644 Module.symvers ${D}/${KERNEL_IMAGEDEST}/Module.symvers-${KERNEL_VERSION}
Patrick Williams92b42cb2022-09-03 06:53:57 -0500496}
497
498# Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile
499do_kernel_version_sanity_check() {
500 if [ "x${KERNEL_VERSION_SANITY_SKIP}" = "x1" ]; then
501 exit 0
502 fi
503
504 # The Makefile determines the kernel version shown at runtime
505 # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile
506 VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//)
507 PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
508 SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
509 EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//)
510
511 # Build a string for regex and a plain version string
512 reg="^${VERSION}\.${PATCHLEVEL}"
513 vers="${VERSION}.${PATCHLEVEL}"
514 if [ -n "${SUBLEVEL}" ]; then
515 # Ignoring a SUBLEVEL of zero is fine
516 if [ "${SUBLEVEL}" = "0" ]; then
517 reg="${reg}(\.${SUBLEVEL})?"
518 else
519 reg="${reg}\.${SUBLEVEL}"
520 vers="${vers}.${SUBLEVEL}"
521 fi
522 fi
523 vers="${vers}${EXTRAVERSION}"
524 reg="${reg}${EXTRAVERSION}"
525
526 if [ -z `echo ${PV} | grep -E "${reg}"` ]; then
527 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."
528 fi
529 exit 0
530}
531
532addtask shared_workdir after do_compile before do_compile_kernelmodules
533addtask shared_workdir_setscene
534
535do_shared_workdir_setscene () {
536 exit 1
537}
538
539emit_depmod_pkgdata() {
540 # Stash data for depmod
541 install -d ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/
542 echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/${KERNEL_PACKAGE_NAME}-abiversion
543 cp ${B}/System.map ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/System.map-${KERNEL_VERSION}
544}
545
546PACKAGEFUNCS += "emit_depmod_pkgdata"
547
548do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}"
549do_shared_workdir () {
550 cd ${B}
551
552 kerneldir=${STAGING_KERNEL_BUILDDIR}
553 install -d $kerneldir
554
555 #
556 # Store the kernel version in sysroots for module-base.bbclass
557 #
558
559 echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion
Patrick Williams2a254922023-08-11 09:48:11 -0500560 echo "${KERNEL_LOCALVERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-localversion
Patrick Williams92b42cb2022-09-03 06:53:57 -0500561
562 # Copy files required for module builds
563 cp System.map $kerneldir/System.map-${KERNEL_VERSION}
Joel Stanleybed4be12023-08-02 21:17:05 +0930564 ! [ -e Module.symvers ] || cp Module.symvers $kerneldir/
Patrick Williams92b42cb2022-09-03 06:53:57 -0500565 cp .config $kerneldir/
566 mkdir -p $kerneldir/include/config
567 cp include/config/kernel.release $kerneldir/include/config/kernel.release
568 if [ -e certs/signing_key.x509 ]; then
569 # The signing_key.* files are stored in the certs/ dir in
570 # newer Linux kernels
571 mkdir -p $kerneldir/certs
572 cp certs/signing_key.* $kerneldir/certs/
573 elif [ -e signing_key.priv ]; then
574 cp signing_key.* $kerneldir/
575 fi
576
577 # We can also copy over all the generated files and avoid special cases
578 # like version.h, but we've opted to keep this small until file creep starts
579 # to happen
580 if [ -e include/linux/version.h ]; then
581 mkdir -p $kerneldir/include/linux
582 cp include/linux/version.h $kerneldir/include/linux/version.h
583 fi
584
585 # As of Linux kernel version 3.0.1, the clean target removes
586 # arch/powerpc/lib/crtsavres.o which is present in
587 # KBUILD_LDFLAGS_MODULE, making it required to build external modules.
588 if [ ${ARCH} = "powerpc" ]; then
589 if [ -e arch/powerpc/lib/crtsavres.o ]; then
590 mkdir -p $kerneldir/arch/powerpc/lib/
591 cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o
592 fi
593 fi
594
595 if [ -d include/generated ]; then
596 mkdir -p $kerneldir/include/generated/
597 cp -fR include/generated/* $kerneldir/include/generated/
598 fi
599
600 if [ -d arch/${ARCH}/include/generated ]; then
601 mkdir -p $kerneldir/arch/${ARCH}/include/generated/
602 cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/
603 fi
604
605 if (grep -q -i -e '^CONFIG_UNWINDER_ORC=y$' $kerneldir/.config); then
606 # With CONFIG_UNWINDER_ORC (the default in 4.14), objtool is required for
607 # out-of-tree modules to be able to generate object files.
608 if [ -x tools/objtool/objtool ]; then
609 mkdir -p ${kerneldir}/tools/objtool
610 cp tools/objtool/objtool ${kerneldir}/tools/objtool/
611 fi
612 fi
Patrick Williams7784c422022-11-17 07:29:11 -0600613
614 # When building with CONFIG_MODVERSIONS=y and CONFIG_RANDSTRUCT=y we need
615 # to copy the build assets generated for the randstruct seed to
616 # STAGING_KERNEL_BUILDDIR, otherwise the out-of-tree modules build will
617 # generate those assets which will result in a different
618 # RANDSTRUCT_HASHED_SEED
619 if [ -d scripts/basic ]; then
620 mkdir -p ${kerneldir}/scripts
621 cp -r scripts/basic ${kerneldir}/scripts
622 fi
623
624 if [ -d scripts/gcc-plugins ]; then
625 mkdir -p ${kerneldir}/scripts
626 cp -r scripts/gcc-plugins ${kerneldir}/scripts
627 fi
628
Patrick Williams92b42cb2022-09-03 06:53:57 -0500629}
630
631# We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware
Patrick Williams2390b1b2022-11-03 13:47:49 -0500632SYSROOT_DIRS = ""
Patrick Williams92b42cb2022-09-03 06:53:57 -0500633
634KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} O=${B} olddefconfig || oe_runmake -C ${S} O=${B} oldnoconfig"
635
636python check_oldest_kernel() {
637 oldest_kernel = d.getVar('OLDEST_KERNEL')
638 kernel_version = d.getVar('KERNEL_VERSION')
639 tclibc = d.getVar('TCLIBC')
640 if tclibc == 'glibc':
641 kernel_version = kernel_version.split('-', 1)[0]
642 if oldest_kernel and kernel_version:
643 if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0:
644 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))
645}
646
647check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION"
Patrick Williams03514f12024-04-05 07:04:11 -0500648do_compile[postfuncs] += "check_oldest_kernel"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500649
Patrick Williams2a254922023-08-11 09:48:11 -0500650KERNEL_LOCALVERSION ??= ""
651
652# 6.3+ requires the variable LOCALVERSION to be set to not get a "+" in
653# the local version. Having it empty means nothing will be added, and any
654# value will be appended to the local kernel version. This replaces the
655# use of .scmversion file for setting a localversion without using
656# the CONFIG_LOCALVERSION option.
657#
658# Note: This class saves the value of localversion to a file
659# so other recipes like make-mod-scripts can restore it via the
660# helper function get_kernellocalversion_file
661export LOCALVERSION="${KERNEL_LOCALVERSION}"
662
Patrick Williams92b42cb2022-09-03 06:53:57 -0500663kernel_do_configure() {
664 # fixes extra + in /lib/modules/2.6.37+
665 # $ scripts/setlocalversion . => +
666 # $ make kernelversion => 2.6.37
667 # $ make kernelrelease => 2.6.37+
Andrew Geissler8f840682023-07-21 09:09:43 -0500668 # See kernel-arch.bbclass for post v6.3 removal of the extra
669 # + in localversion. .scmversion is no longer used, and the
670 # variable LOCALVERSION must be used
Patrick Williamsb542dec2023-06-09 01:26:37 -0500671 if [ ! -e ${B}/.scmversion -a ! -e ${S}/.scmversion ]; then
672 echo ${KERNEL_LOCALVERSION} > ${B}/.scmversion
673 echo ${KERNEL_LOCALVERSION} > ${S}/.scmversion
674 fi
Patrick Williams92b42cb2022-09-03 06:53:57 -0500675
676 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
677 mv "${S}/.config" "${B}/.config"
678 fi
679
680 # Copy defconfig to .config if .config does not exist. This allows
681 # recipes to manage the .config themselves in do_configure:prepend().
682 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
683 cp "${WORKDIR}/defconfig" "${B}/.config"
684 fi
685
686 ${KERNEL_CONFIG_COMMAND}
687}
688
689do_savedefconfig() {
690 bbplain "Saving defconfig to:\n${B}/defconfig"
691 oe_runmake -C ${B} savedefconfig
692}
693do_savedefconfig[nostamp] = "1"
694addtask savedefconfig after do_configure
695
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500696inherit cml1 pkgconfig
Patrick Williams92b42cb2022-09-03 06:53:57 -0500697
698# Need LD, HOSTLDFLAGS and more for config operations
699KCONFIG_CONFIG_COMMAND:append = " ${EXTRA_OEMAKE}"
700
701EXPORT_FUNCTIONS do_compile do_transform_kernel do_transform_bundled_initramfs do_install do_configure
702
703# kernel-base becomes kernel-${KERNEL_VERSION}
704# kernel-image becomes kernel-image-${KERNEL_VERSION}
705PACKAGES = "${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"
706FILES:${PN} = ""
707FILES:${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"
708FILES:${KERNEL_PACKAGE_NAME}-image = ""
709FILES:${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"
710FILES:${KERNEL_PACKAGE_NAME}-vmlinux = "/${KERNEL_IMAGEDEST}/vmlinux-${KERNEL_VERSION_NAME}"
711FILES:${KERNEL_PACKAGE_NAME}-modules = ""
712FILES:${KERNEL_PACKAGE_NAME}-dbg = "/usr/lib/debug /usr/src/debug"
713RDEPENDS:${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base (= ${EXTENDPKGV})"
714# Allow machines to override this dependency if kernel image files are
715# not wanted in images as standard
716RRECOMMENDS:${KERNEL_PACKAGE_NAME}-base ?= "${KERNEL_PACKAGE_NAME}-image (= ${EXTENDPKGV})"
717PKG:${KERNEL_PACKAGE_NAME}-image = "${KERNEL_PACKAGE_NAME}-image-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
718RDEPENDS:${KERNEL_PACKAGE_NAME}-image += "${@oe.utils.conditional('KERNEL_IMAGETYPE', 'vmlinux', '${KERNEL_PACKAGE_NAME}-vmlinux (= ${EXTENDPKGV})', '', d)}"
719PKG:${KERNEL_PACKAGE_NAME}-base = "${KERNEL_PACKAGE_NAME}-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
720RPROVIDES:${KERNEL_PACKAGE_NAME}-base += "${KERNEL_PACKAGE_NAME}-${KERNEL_VERSION}"
721ALLOW_EMPTY:${KERNEL_PACKAGE_NAME} = "1"
722ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-base = "1"
723ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-image = "1"
724ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-modules = "1"
725DESCRIPTION:${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta package"
726
727pkg_postinst:${KERNEL_PACKAGE_NAME}-base () {
728 if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
729 mkdir -p $D/lib/modules/${KERNEL_VERSION}
730 fi
731 if [ -n "$D" ]; then
Andrew Geissler87f5cff2022-09-30 13:13:31 -0500732 depmodwrapper -a -b $D ${KERNEL_VERSION} ${KERNEL_PACKAGE_NAME}
Patrick Williams92b42cb2022-09-03 06:53:57 -0500733 else
734 depmod -a ${KERNEL_VERSION}
735 fi
736}
737
Andrew Geissler517393d2023-01-13 08:55:19 -0600738PACKAGESPLITFUNCS =+ "split_kernel_packages"
Patrick Williams92b42cb2022-09-03 06:53:57 -0500739
740python split_kernel_packages () {
741 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='')
742}
743
744# Many scripts want to look in arch/$arch/boot for the bootable
745# image. This poses a problem for vmlinux and vmlinuz based
746# booting. This task arranges to have vmlinux and vmlinuz appear
747# in the normalized directory location.
748do_kernel_link_images() {
749 if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
750 mkdir ${B}/arch/${ARCH}/boot
751 fi
752 cd ${B}/arch/${ARCH}/boot
753 ln -sf ../../../vmlinux
754 if [ -f ../../../vmlinuz ]; then
755 ln -sf ../../../vmlinuz
756 fi
757 if [ -f ../../../vmlinuz.bin ]; then
758 ln -sf ../../../vmlinuz.bin
759 fi
760 if [ -f ../../../vmlinux.64 ]; then
761 ln -sf ../../../vmlinux.64
762 fi
763}
764addtask kernel_link_images after do_compile before do_strip
765
766python do_strip() {
767 import shutil
768
Andrew Geissler5082cc72023-09-11 08:41:39 -0400769 strip = d.getVar('KERNEL_STRIP')
Patrick Williams92b42cb2022-09-03 06:53:57 -0500770 extra_sections = d.getVar('KERNEL_IMAGE_STRIP_EXTRA_SECTIONS')
771 kernel_image = d.getVar('B') + "/" + d.getVar('KERNEL_OUTPUT_DIR') + "/vmlinux"
772
773 if (extra_sections and kernel_image.find(d.getVar('KERNEL_IMAGEDEST') + '/vmlinux') != -1):
774 kernel_image_stripped = kernel_image + ".stripped"
775 shutil.copy2(kernel_image, kernel_image_stripped)
776 oe.package.runstrip((kernel_image_stripped, 8, strip, extra_sections))
777 bb.debug(1, "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections: " + \
778 extra_sections)
779}
780do_strip[dirs] = "${B}"
781
782addtask strip before do_sizecheck after do_kernel_link_images
783
784# Support checking the kernel size since some kernels need to reside in partitions
785# with a fixed length or there is a limit in transferring the kernel to memory.
786# If more than one image type is enabled, warn on any that don't fit but only fail
787# if none fit.
788do_sizecheck() {
789 if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then
790 invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'`
791 if [ -n "$invalid" ]; then
792 die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integer (The unit is Kbytes)"
793 fi
794 at_least_one_fits=
795 for imageType in ${KERNEL_IMAGETYPES} ; do
796 size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$imageType | awk '{print $1}'`
797 if [ $size -gt ${KERNEL_IMAGE_MAXSIZE} ]; then
798 bbwarn "This kernel $imageType (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device."
799 else
800 at_least_one_fits=y
801 fi
802 done
803 if [ -z "$at_least_one_fits" ]; then
804 die "All kernel images are too big for your device. Please reduce the size of the kernel by making more of it modular."
805 fi
806 fi
807}
808do_sizecheck[dirs] = "${B}"
809
810addtask sizecheck before do_install after do_strip
811
812inherit kernel-artifact-names
813
814kernel_do_deploy() {
815 deployDir="${DEPLOYDIR}"
816 if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then
817 deployDir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}"
818 mkdir "$deployDir"
819 fi
820
821 for imageType in ${KERNEL_IMAGETYPES} ; do
822 baseName=$imageType-${KERNEL_IMAGE_NAME}
823
824 if [ -s ${KERNEL_OUTPUT_DIR}/$imageType.stripped ] ; then
825 install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.stripped $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
826 else
827 install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
828 fi
829 if [ -n "${KERNEL_IMAGE_LINK_NAME}" ] ; then
830 ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${KERNEL_IMAGE_LINK_NAME}${KERNEL_IMAGE_BIN_EXT}
831 fi
832 if [ "${KERNEL_IMAGETYPE_SYMLINK}" = "1" ] ; then
833 ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType
834 fi
835 done
836
837 if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
838 mkdir -p ${D}${root_prefix}/lib
839 if [ -n "${SOURCE_DATE_EPOCH}" ]; then
840 TAR_ARGS="--sort=name --clamp-mtime --mtime=@${SOURCE_DATE_EPOCH}"
841 else
842 TAR_ARGS=""
843 fi
844 TAR_ARGS="$TAR_ARGS --owner=0 --group=0"
845 tar $TAR_ARGS -cv -C ${D}${root_prefix} lib | gzip -9n > $deployDir/modules-${MODULE_TARBALL_NAME}.tgz
846
847 if [ -n "${MODULE_TARBALL_LINK_NAME}" ] ; then
848 ln -sf modules-${MODULE_TARBALL_NAME}.tgz $deployDir/modules-${MODULE_TARBALL_LINK_NAME}.tgz
849 fi
850 fi
851
852 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
853 for imageType in ${KERNEL_IMAGETYPES} ; do
854 if [ "$imageType" = "fitImage" ] ; then
855 continue
856 fi
857 initramfsBaseName=$imageType-${INITRAMFS_NAME}
858 install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.initramfs $deployDir/$initramfsBaseName${KERNEL_IMAGE_BIN_EXT}
859 if [ -n "${INITRAMFS_LINK_NAME}" ] ; then
860 ln -sf $initramfsBaseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${INITRAMFS_LINK_NAME}${KERNEL_IMAGE_BIN_EXT}
861 fi
862 done
863 fi
864}
865
866# We deploy to filenames that include PKGV and PKGR, read the saved data to
867# ensure we get the right values for both
868do_deploy[prefuncs] += "read_subpackage_metadata"
869
870addtask deploy after do_populate_sysroot do_packagedata
871
872EXPORT_FUNCTIONS do_deploy
873
874# Add using Device Tree support
875inherit kernel-devicetree