blob: 473e28be4774ab6d2f473304fa02facf2952aeb6 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit linux-kernel-base kernel-module-split
2
Andrew Geisslerd1e89492021-02-12 15:35:20 -06003COMPATIBLE_HOST = ".*-linux"
4
Brad Bishop316dfdd2018-06-25 12:45:53 -04005KERNEL_PACKAGE_NAME ??= "kernel"
6KERNEL_DEPLOYSUBDIR ??= "${@ "" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else d.getVar("KERNEL_PACKAGE_NAME") }"
7
Andrew Geissler595f6302022-01-24 19:11:47 +00008PROVIDES += "virtual/kernel"
Andrew Geissler475cb722020-07-10 16:00:51 -05009DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native bc-native bison-native"
10DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.lzo", "lzop-native", "", d)}"
11DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.lz4", "lz4-native", "", d)}"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -050012DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.zst", "zstd-native", "", d)}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050013PACKAGE_WRITE_DEPS += "depmodwrapper-cross"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014
Andrew Geissler475cb722020-07-10 16:00:51 -050015do_deploy[depends] += "depmodwrapper-cross:do_populate_sysroot gzip-native:do_populate_sysroot"
Brad Bishop15ae2502019-06-18 21:44:24 -040016do_clean[depends] += "make-mod-scripts:do_clean"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017
18CVE_PRODUCT ?= "linux_kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019
20S = "${STAGING_KERNEL_DIR}"
21B = "${WORKDIR}/build"
22KBUILD_OUTPUT = "${B}"
23OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
24
25# we include gcc above, we dont need virtual/libc
26INHIBIT_DEFAULT_DEPS = "1"
27
28KERNEL_IMAGETYPE ?= "zImage"
29INITRAMFS_IMAGE ?= ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030INITRAMFS_IMAGE_NAME ?= "${@['${INITRAMFS_IMAGE}-${MACHINE}', ''][d.getVar('INITRAMFS_IMAGE') == '']}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031INITRAMFS_TASK ?= ""
32INITRAMFS_IMAGE_BUNDLE ?= ""
33
He Zhefe76b1e2016-05-25 04:47:16 -040034# KERNEL_VERSION is extracted from source code. It is evaluated as
35# None for the first parsing, since the code has not been fetched.
36# After the code is fetched, it will be evaluated as real version
37# number and cause kernel to be rebuilt. To avoid this, make
38# KERNEL_VERSION_NAME and KERNEL_VERSION_PKG_NAME depend on
39# LINUX_VERSION which is a constant.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040KERNEL_VERSION_NAME = "${@d.getVar('KERNEL_VERSION') or ""}"
He Zhefe76b1e2016-05-25 04:47:16 -040041KERNEL_VERSION_NAME[vardepvalue] = "${LINUX_VERSION}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050042KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
He Zhefe76b1e2016-05-25 04:47:16 -040043KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}"
44
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045python __anonymous () {
Brad Bishop316dfdd2018-06-25 12:45:53 -040046 pn = d.getVar("PN")
47 kpn = d.getVar("KERNEL_PACKAGE_NAME")
48
49 # XXX Remove this after bug 11905 is resolved
Patrick Williams213cb262021-08-07 19:21:33 -050050 # FILES:${KERNEL_PACKAGE_NAME}-dev doesn't expand correctly
Brad Bishop316dfdd2018-06-25 12:45:53 -040051 if kpn == pn:
52 bb.warn("Some packages (E.g. *-dev) might be missing due to "
53 "bug 11905 (variable KERNEL_PACKAGE_NAME == PN)")
54
55 # The default kernel recipe builds in a shared location defined by
56 # bitbake/distro confs: STAGING_KERNEL_DIR and STAGING_KERNEL_BUILDDIR.
57 # Set these variables to directories under ${WORKDIR} in alternate
58 # kernel recipes (I.e. where KERNEL_PACKAGE_NAME != kernel) so that they
59 # may build in parallel with the default kernel without clobbering.
60 if kpn != "kernel":
61 workdir = d.getVar("WORKDIR")
62 sourceDir = os.path.join(workdir, 'kernel-source')
63 artifactsDir = os.path.join(workdir, 'kernel-build-artifacts')
64 d.setVar("STAGING_KERNEL_DIR", sourceDir)
65 d.setVar("STAGING_KERNEL_BUILDDIR", artifactsDir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066
He Zhefe76b1e2016-05-25 04:47:16 -040067 # Merge KERNEL_IMAGETYPE and KERNEL_ALT_IMAGETYPE into KERNEL_IMAGETYPES
Brad Bishop6e60e8b2018-02-01 10:27:11 -050068 type = d.getVar('KERNEL_IMAGETYPE') or ""
69 alttype = d.getVar('KERNEL_ALT_IMAGETYPE') or ""
70 types = d.getVar('KERNEL_IMAGETYPES') or ""
He Zhefe76b1e2016-05-25 04:47:16 -040071 if type not in types.split():
72 types = (type + ' ' + types).strip()
73 if alttype not in types.split():
74 types = (alttype + ' ' + types).strip()
75 d.setVar('KERNEL_IMAGETYPES', types)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050076
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080077 # KERNEL_IMAGETYPES may contain a mixture of image types supported directly
78 # by the kernel build system and types which are created by post-processing
79 # the output of the kernel build system (e.g. compressing vmlinux ->
Andrew Geissler595f6302022-01-24 19:11:47 +000080 # vmlinux.gz in kernel_do_transform_kernel()).
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080081 # KERNEL_IMAGETYPE_FOR_MAKE should contain only image types supported
82 # directly by the kernel build system.
83 if not d.getVar('KERNEL_IMAGETYPE_FOR_MAKE'):
84 typeformake = set()
85 for type in types.split():
86 if type == 'vmlinux.gz':
87 type = 'vmlinux'
88 typeformake.add(type)
89
90 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', ' '.join(sorted(typeformake)))
91
92 kname = d.getVar('KERNEL_PACKAGE_NAME') or "kernel"
93 imagedest = d.getVar('KERNEL_IMAGEDEST')
He Zhefe76b1e2016-05-25 04:47:16 -040094
Brad Bishop37a0e4d2017-12-04 01:01:44 -050095 for type in types.split():
Andrew Geissler5f350902021-07-23 13:09:54 -040096 if bb.data.inherits_class('nopackages', d):
97 continue
He Zhefe76b1e2016-05-25 04:47:16 -040098 typelower = type.lower()
Brad Bishop316dfdd2018-06-25 12:45:53 -040099 d.appendVar('PACKAGES', ' %s-image-%s' % (kname, typelower))
Patrick Williams213cb262021-08-07 19:21:33 -0500100 d.setVar('FILES:' + kname + '-image-' + typelower, '/' + imagedest + '/' + type + '-${KERNEL_VERSION_NAME}' + ' /' + imagedest + '/' + type)
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500101 d.appendVar('RDEPENDS:%s-image' % kname, ' %s-image-%s (= ${EXTENDPKGV})' % (kname, typelower))
102 splitmods = d.getVar("KERNEL_SPLIT_MODULES")
103 if splitmods != '1':
104 d.appendVar('RDEPENDS:%s-image' % kname, ' %s-modules (= ${EXTENDPKGV})' % kname)
105 d.appendVar('RDEPENDS:%s-image-%s' % (kname, typelower), ' %s-modules-${KERNEL_VERSION_PKG_NAME} (= ${EXTENDPKGV})' % kname)
106 d.setVar('PKG:%s-modules' % kname, '%s-modules-${KERNEL_VERSION_PKG_NAME}' % kname)
107 d.appendVar('RPROVIDES:%s-modules' % kname, '%s-modules-${KERNEL_VERSION_PKG_NAME}' % kname)
108
Patrick Williams213cb262021-08-07 19:21:33 -0500109 d.setVar('PKG:%s-image-%s' % (kname,typelower), '%s-image-%s-${KERNEL_VERSION_PKG_NAME}' % (kname, typelower))
110 d.setVar('ALLOW_EMPTY:%s-image-%s' % (kname, typelower), '1')
111 d.setVar('pkg_postinst:%s-image-%s' % (kname,typelower), """set +e
Andrew Geissler475cb722020-07-10 16:00:51 -0500112if [ -n "$D" ]; then
113 ln -sf %s-${KERNEL_VERSION} $D/${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
114else
115 ln -sf %s-${KERNEL_VERSION} ${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
116 if [ $? -ne 0 ]; then
117 echo "Filesystem on ${KERNEL_IMAGEDEST}/ doesn't support symlinks, falling back to copied image (%s)."
118 install -m 0644 ${KERNEL_IMAGEDEST}/%s-${KERNEL_VERSION} ${KERNEL_IMAGEDEST}/%s
119 fi
120fi
121set -e
122""" % (type, type, type, type, type, type, type))
Patrick Williams213cb262021-08-07 19:21:33 -0500123 d.setVar('pkg_postrm:%s-image-%s' % (kname,typelower), """set +e
Andrew Geissler475cb722020-07-10 16:00:51 -0500124if [ -f "${KERNEL_IMAGEDEST}/%s" -o -L "${KERNEL_IMAGEDEST}/%s" ]; then
125 rm -f ${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
126fi
127set -e
128""" % (type, type, type))
129
He Zhefe76b1e2016-05-25 04:47:16 -0400130
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500131 image = d.getVar('INITRAMFS_IMAGE')
Brad Bishop79641f22019-09-10 07:20:22 -0400132 # If the INTIRAMFS_IMAGE is set but the INITRAMFS_IMAGE_BUNDLE is set to 0,
133 # the do_bundle_initramfs does nothing, but the INITRAMFS_IMAGE is built
134 # standalone for use by wic and other tools.
135 if image:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500136 d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
Andrew Geissler595f6302022-01-24 19:11:47 +0000137 if image and bb.utils.to_boolean(d.getVar('INITRAMFS_IMAGE_BUNDLE')):
138 bb.build.addtask('do_transform_bundled_initramfs', 'do_deploy', 'do_bundle_initramfs', d)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139
140 # NOTE: setting INITRAMFS_TASK is for backward compatibility
141 # The preferred method is to set INITRAMFS_IMAGE, because
142 # this INITRAMFS_TASK has circular dependency problems
143 # if the initramfs requires kernel modules
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500144 image_task = d.getVar('INITRAMFS_TASK')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500145 if image_task:
146 d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}')
147}
148
149# Here we pull in all various kernel image types which we support.
150#
151# In case you're wondering why kernel.bbclass inherits the other image
152# types instead of the other way around, the reason for that is to
153# maintain compatibility with various currently existing meta-layers.
154# By pulling in the various kernel image types here, we retain the
155# original behavior of kernel.bbclass, so no meta-layers should get
156# broken.
157#
158# KERNEL_CLASSES by default pulls in kernel-uimage.bbclass, since this
159# used to be the default behavior when only uImage was supported. This
160# variable can be appended by users who implement support for new kernel
161# image types.
162
163KERNEL_CLASSES ?= " kernel-uimage "
164inherit ${KERNEL_CLASSES}
165
166# Old style kernels may set ${S} = ${WORKDIR}/git for example
167# We need to move these over to STAGING_KERNEL_DIR. We can't just
168# create the symlink in advance as the git fetcher can't cope with
169# the symlink.
170do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
171do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
Brad Bishopc342db32019-05-15 21:57:59 -0400172python do_symlink_kernsrc () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500173 s = d.getVar("S")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500174 if s[-1] == '/':
175 # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as directory name and fail
176 s=s[:-1]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500177 kernsrc = d.getVar("STAGING_KERNEL_DIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178 if s != kernsrc:
179 bb.utils.mkdirhier(kernsrc)
180 bb.utils.remove(kernsrc, recurse=True)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500181 if d.getVar("EXTERNALSRC"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182 # With EXTERNALSRC S will not be wiped so we can symlink to it
183 os.symlink(s, kernsrc)
184 else:
185 import shutil
186 shutil.move(s, kernsrc)
187 os.symlink(kernsrc, s)
188}
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500189# do_patch is normally ordered before do_configure, but
190# externalsrc.bbclass deletes do_patch, breaking the dependency of
191# do_configure on do_symlink_kernsrc.
192addtask symlink_kernsrc before do_patch do_configure after do_unpack
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193
194inherit kernel-arch deploy
195
Brad Bishop316dfdd2018-06-25 12:45:53 -0400196PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
197PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-image-.*"
198PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-firmware-.*"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500199
200export OS = "${TARGET_OS}"
201export CROSS_COMPILE = "${TARGET_PREFIX}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400202export KBUILD_BUILD_VERSION = "1"
Brad Bishop977dc1a2019-02-06 16:01:43 -0500203export KBUILD_BUILD_USER ?= "oe-user"
204export KBUILD_BUILD_HOST ?= "oe-host"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500205
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206KERNEL_RELEASE ?= "${KERNEL_VERSION}"
207
He Zhefe76b1e2016-05-25 04:47:16 -0400208# The directory where built kernel lies in the kernel tree
209KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800210KERNEL_IMAGEDEST ?= "boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500211
212#
213# configuration
214#
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500215export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE") or "ttyS0"}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500216
217KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}"
218
219KERNEL_LOCALVERSION ?= ""
220
221# kernels are generally machine specific
222PACKAGE_ARCH = "${MACHINE_ARCH}"
223
224# U-Boot support
225UBOOT_ENTRYPOINT ?= "20008000"
226UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}"
227
228# Some Linux kernel configurations need additional parameters on the command line
229KERNEL_EXTRA_ARGS ?= ""
230
Andrew Geisslereff27472021-10-29 15:35:00 -0500231EXTRA_OEMAKE = " HOSTCC="${BUILD_CC}" HOSTCFLAGS="${BUILD_CFLAGS}" HOSTLDFLAGS="${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}""
232EXTRA_OEMAKE += " HOSTCXX="${BUILD_CXX}" HOSTCXXFLAGS="${BUILD_CXXFLAGS}""
Andrew Geissler635e0e42020-08-21 15:58:33 -0500233
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500234KERNEL_ALT_IMAGETYPE ??= ""
235
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500236copy_initramfs() {
237 echo "Copying initramfs into ./usr ..."
238 # In case the directory is not created yet from the first pass compile:
239 mkdir -p ${B}/usr
240 # Find and use the first initramfs image archive type we find
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500241 rm -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500242 for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz cpio.zst; do
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500243 if [ -e "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" ]; then
244 cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500245 case $img in
246 *gz)
247 echo "gzip decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500248 gunzip -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500249 break
250 ;;
251 *lz4)
252 echo "lz4 decompressing image"
Andrew Geissler475cb722020-07-10 16:00:51 -0500253 lz4 -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254 break
255 ;;
256 *lzo)
257 echo "lzo decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500258 lzop -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500259 break
260 ;;
261 *lzma)
262 echo "lzma decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500263 lzma -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500264 break
265 ;;
266 *xz)
267 echo "xz decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500268 xz -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500269 break
270 ;;
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500271 *zst)
272 echo "zst decompressing image"
273 zstd -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
274 break
275 ;;
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500276 esac
Brad Bishopf8caae32019-03-25 13:13:56 -0400277 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278 fi
279 done
Brad Bishopf8caae32019-03-25 13:13:56 -0400280 # Verify that the above loop found a initramfs, fail otherwise
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500281 [ -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio ] && echo "Finished copy of initramfs into ./usr" || die "Could not find any ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.cpio{.gz|.lz4|.lzo|.lzma|.xz|.zst) for bundling; INITRAMFS_IMAGE_NAME might be wrong."
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500282}
283
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500284do_bundle_initramfs () {
285 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
286 echo "Creating a kernel image with a bundled initramfs..."
287 copy_initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400288 # Backing up kernel image relies on its type(regular file or symbolic link)
289 tmp_path=""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800290 for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
291 if [ -h ${KERNEL_OUTPUT_DIR}/$imageType ] ; then
292 linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$imageType`
293 realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$imageType`
He Zhefe76b1e2016-05-25 04:47:16 -0400294 mv -f $realpath $realpath.bak
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800295 tmp_path=$tmp_path" "$imageType"#"$linkpath"#"$realpath
296 elif [ -f ${KERNEL_OUTPUT_DIR}/$imageType ]; then
297 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.bak
298 tmp_path=$tmp_path" "$imageType"##"
He Zhefe76b1e2016-05-25 04:47:16 -0400299 fi
300 done
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500301 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500302 kernel_do_compile
He Zhefe76b1e2016-05-25 04:47:16 -0400303 # Restoring kernel image
304 for tp in $tmp_path ; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800305 imageType=`echo $tp|cut -d "#" -f 1`
He Zhefe76b1e2016-05-25 04:47:16 -0400306 linkpath=`echo $tp|cut -d "#" -f 2`
307 realpath=`echo $tp|cut -d "#" -f 3`
308 if [ -n "$realpath" ]; then
309 mv -f $realpath $realpath.initramfs
310 mv -f $realpath.bak $realpath
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800311 ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$imageType.initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400312 else
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800313 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.initramfs
314 mv -f ${KERNEL_OUTPUT_DIR}/$imageType.bak ${KERNEL_OUTPUT_DIR}/$imageType
He Zhefe76b1e2016-05-25 04:47:16 -0400315 fi
316 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500317 fi
318}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600319do_bundle_initramfs[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500320
Andrew Geissler595f6302022-01-24 19:11:47 +0000321kernel_do_transform_bundled_initramfs() {
322 # vmlinux.gz is not built by kernel
323 if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then
324 gzip -9cn < ${KERNEL_OUTPUT_DIR}/vmlinux.initramfs > ${KERNEL_OUTPUT_DIR}/vmlinux.gz.initramfs
325 fi
326}
327do_transform_bundled_initramfs[dirs] = "${B}"
328
Patrick Williams213cb262021-08-07 19:21:33 -0500329python do_devshell:prepend () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500330 os.environ["LDFLAGS"] = ''
331}
332
333addtask bundle_initramfs after do_install before do_deploy
334
Andrew Geisslereff27472021-10-29 15:35:00 -0500335KERNEL_DEBUG_TIMESTAMPS ??= "0"
336
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500337kernel_do_compile() {
338 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
Andrew Geissler595f6302022-01-24 19:11:47 +0000339
340 # setup native pkg-config variables (kconfig scripts call pkg-config directly, cannot generically be overriden to pkg-config-native)
341 export PKG_CONFIG_DIR="${STAGING_DIR_NATIVE}${libdir_native}/pkgconfig"
342 export PKG_CONFIG_PATH="$PKG_CONFIG_DIR:${STAGING_DATADIR_NATIVE}/pkgconfig"
343 export PKG_CONFIG_LIBDIR="$PKG_CONFIG_DIR"
344 export PKG_CONFIG_SYSROOT_DIR=""
345
Andrew Geisslereff27472021-10-29 15:35:00 -0500346 if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500347 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
348 # be set....
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800349 if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
Andrew Geissler82c905d2020-04-13 13:39:40 -0500350 # The source directory is not necessarily a git repository, so we
351 # specify the git-dir to ensure that git does not query a
352 # repository in any parent directory.
353 SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500354 fi
355
356 ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
357 export KBUILD_BUILD_TIMESTAMP="$ts"
358 export KCONFIG_NOTIMESTAMP=1
359 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
360 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500361 # The $use_alternate_initrd is only set from
362 # do_bundle_initramfs() This variable is specifically for the
363 # case where we are making a second pass at the kernel
364 # compilation and we want to force the kernel build to use a
365 # different initramfs image. The way to do that in the kernel
366 # is to specify:
367 # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio
368 if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then
369 # The old style way of copying an prebuilt image and building it
370 # is turned on via INTIRAMFS_TASK != ""
371 copy_initramfs
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500372 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500373 fi
He Zhefe76b1e2016-05-25 04:47:16 -0400374 for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
Patrick Williams93c203f2021-10-06 16:15:23 -0500375 oe_runmake ${typeformake} CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd
He Zhefe76b1e2016-05-25 04:47:16 -0400376 done
Andrew Geissler595f6302022-01-24 19:11:47 +0000377}
378
379kernel_do_transform_kernel() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500380 # vmlinux.gz is not built by kernel
381 if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then
382 mkdir -p "${KERNEL_OUTPUT_DIR}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500383 gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500384 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500385}
Andrew Geissler595f6302022-01-24 19:11:47 +0000386do_transform_kernel[dirs] = "${B}"
387addtask transform_kernel after do_compile before do_install
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500388
389do_compile_kernelmodules() {
390 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
Andrew Geisslereff27472021-10-29 15:35:00 -0500391 if [ "${KERNEL_DEBUG_TIMESTAMPS}" != "1" ]; then
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500392 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
393 # be set....
394 if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
395 # The source directory is not necessarily a git repository, so we
396 # specify the git-dir to ensure that git does not query a
397 # repository in any parent directory.
398 SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
399 fi
400
401 ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
402 export KBUILD_BUILD_TIMESTAMP="$ts"
403 export KCONFIG_NOTIMESTAMP=1
404 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
405 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500406 if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
Patrick Williams93c203f2021-10-06 16:15:23 -0500407 oe_runmake -C ${B} ${PARALLEL_MAKE} modules CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500408
409 # Module.symvers gets updated during the
410 # building of the kernel modules. We need to
411 # update this in the shared workdir since some
412 # external kernel modules has a dependency on
413 # other kernel modules and will look at this
414 # file to do symbol lookups
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600415 cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600416 # 5.10+ kernels have module.lds that we need to copy for external module builds
417 if [ -e "${B}/scripts/module.lds" ]; then
418 install -Dm 0644 ${B}/scripts/module.lds ${STAGING_KERNEL_BUILDDIR}/scripts/module.lds
419 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500420 else
421 bbnote "no modules to compile"
422 fi
423}
424addtask compile_kernelmodules after do_compile before do_strip
425
426kernel_do_install() {
427 #
428 # First install the modules
429 #
430 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
431 if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500432 oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
433 rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
434 rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500435 # If the kernel/ directory is empty remove it to prevent QA issues
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500436 rmdir --ignore-fail-on-non-empty "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500437 else
438 bbnote "no modules to install"
439 fi
440
441 #
442 # Install various kernel output (zImage, map file, config, module support files)
443 #
444 install -d ${D}/${KERNEL_IMAGEDEST}
445 install -d ${D}/boot
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600446
447 #
448 # When including an initramfs bundle inside a FIT image, the fitImage is created after the install task
449 # by do_assemble_fitimage_initramfs.
450 # This happens after the generation of the initramfs bundle (done by do_bundle_initramfs).
451 # So, at the level of the install task we should not try to install the fitImage. fitImage is still not
452 # generated yet.
453 # After the generation of the fitImage, the deploy task copies the fitImage from the build directory to
454 # the deploy folder.
455 #
456
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800457 for imageType in ${KERNEL_IMAGETYPES} ; do
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600458 if [ $imageType != "fitImage" ] || [ "${INITRAMFS_IMAGE_BUNDLE}" != "1" ] ; then
459 install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType ${D}/${KERNEL_IMAGEDEST}/$imageType-${KERNEL_VERSION}
460 fi
He Zhefe76b1e2016-05-25 04:47:16 -0400461 done
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600462
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500463 install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION}
464 install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION}
465 install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION}
466 [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION}
467 install -d ${D}${sysconfdir}/modules-load.d
468 install -d ${D}${sysconfdir}/modprobe.d
469}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500470
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600471# Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile
472do_kernel_version_sanity_check() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500473 if [ "x${KERNEL_VERSION_SANITY_SKIP}" = "x1" ]; then
474 exit 0
475 fi
476
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600477 # The Makefile determines the kernel version shown at runtime
478 # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile
479 VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//)
480 PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
481 SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
482 EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//)
483
484 # Build a string for regex and a plain version string
485 reg="^${VERSION}\.${PATCHLEVEL}"
486 vers="${VERSION}.${PATCHLEVEL}"
487 if [ -n "${SUBLEVEL}" ]; then
488 # Ignoring a SUBLEVEL of zero is fine
489 if [ "${SUBLEVEL}" = "0" ]; then
490 reg="${reg}(\.${SUBLEVEL})?"
491 else
492 reg="${reg}\.${SUBLEVEL}"
493 vers="${vers}.${SUBLEVEL}"
494 fi
495 fi
496 vers="${vers}${EXTRAVERSION}"
497 reg="${reg}${EXTRAVERSION}"
498
499 if [ -z `echo ${PV} | grep -E "${reg}"` ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500500 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."
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600501 fi
502 exit 0
503}
504
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500505addtask shared_workdir after do_compile before do_compile_kernelmodules
506addtask shared_workdir_setscene
507
508do_shared_workdir_setscene () {
509 exit 1
510}
511
512emit_depmod_pkgdata() {
513 # Stash data for depmod
Brad Bishop316dfdd2018-06-25 12:45:53 -0400514 install -d ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/
515 echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/${KERNEL_PACKAGE_NAME}-abiversion
516 cp ${B}/System.map ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/System.map-${KERNEL_VERSION}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500517}
518
519PACKAGEFUNCS += "emit_depmod_pkgdata"
520
Brad Bishop316dfdd2018-06-25 12:45:53 -0400521do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500522do_shared_workdir () {
523 cd ${B}
524
525 kerneldir=${STAGING_KERNEL_BUILDDIR}
526 install -d $kerneldir
527
528 #
529 # Store the kernel version in sysroots for module-base.bbclass
530 #
531
Brad Bishop316dfdd2018-06-25 12:45:53 -0400532 echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500533
534 # Copy files required for module builds
535 cp System.map $kerneldir/System.map-${KERNEL_VERSION}
Andrew Geissler475cb722020-07-10 16:00:51 -0500536 [ -e Module.symvers ] && cp Module.symvers $kerneldir/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500537 cp .config $kerneldir/
538 mkdir -p $kerneldir/include/config
539 cp include/config/kernel.release $kerneldir/include/config/kernel.release
Brad Bishop08902b02019-08-20 09:16:51 -0400540 if [ -e certs/signing_key.x509 ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600541 # The signing_key.* files are stored in the certs/ dir in
542 # newer Linux kernels
543 mkdir -p $kerneldir/certs
544 cp certs/signing_key.* $kerneldir/certs/
545 elif [ -e signing_key.priv ]; then
546 cp signing_key.* $kerneldir/
547 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500548
549 # We can also copy over all the generated files and avoid special cases
550 # like version.h, but we've opted to keep this small until file creep starts
551 # to happen
552 if [ -e include/linux/version.h ]; then
553 mkdir -p $kerneldir/include/linux
554 cp include/linux/version.h $kerneldir/include/linux/version.h
555 fi
556
557 # As of Linux kernel version 3.0.1, the clean target removes
558 # arch/powerpc/lib/crtsavres.o which is present in
559 # KBUILD_LDFLAGS_MODULE, making it required to build external modules.
560 if [ ${ARCH} = "powerpc" ]; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400561 if [ -e arch/powerpc/lib/crtsavres.o ]; then
562 mkdir -p $kerneldir/arch/powerpc/lib/
563 cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o
564 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500565 fi
566
567 if [ -d include/generated ]; then
568 mkdir -p $kerneldir/include/generated/
569 cp -fR include/generated/* $kerneldir/include/generated/
570 fi
571
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500572 if [ -d arch/${ARCH}/include/generated ]; then
573 mkdir -p $kerneldir/arch/${ARCH}/include/generated/
574 cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500575 fi
Brad Bishop19323692019-04-05 15:28:33 -0400576
577 if (grep -q -i -e '^CONFIG_UNWINDER_ORC=y$' $kerneldir/.config); then
578 # With CONFIG_UNWINDER_ORC (the default in 4.14), objtool is required for
579 # out-of-tree modules to be able to generate object files.
580 if [ -x tools/objtool/objtool ]; then
581 mkdir -p ${kerneldir}/tools/objtool
582 cp tools/objtool/objtool ${kerneldir}/tools/objtool/
583 fi
584 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500585}
586
587# We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware
588sysroot_stage_all () {
589 :
590}
591
Andrew Geissler82c905d2020-04-13 13:39:40 -0500592KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} CC="${KERNEL_CC}" LD="${KERNEL_LD}" O=${B} olddefconfig || oe_runmake -C ${S} O=${B} CC="${KERNEL_CC}" LD="${KERNEL_LD}" oldnoconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500593
He Zhefe76b1e2016-05-25 04:47:16 -0400594python check_oldest_kernel() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500595 oldest_kernel = d.getVar('OLDEST_KERNEL')
596 kernel_version = d.getVar('KERNEL_VERSION')
597 tclibc = d.getVar('TCLIBC')
He Zhefe76b1e2016-05-25 04:47:16 -0400598 if tclibc == 'glibc':
599 kernel_version = kernel_version.split('-', 1)[0]
600 if oldest_kernel and kernel_version:
601 if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500602 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))
He Zhefe76b1e2016-05-25 04:47:16 -0400603}
604
605check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION"
606do_configure[prefuncs] += "check_oldest_kernel"
607
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500608kernel_do_configure() {
609 # fixes extra + in /lib/modules/2.6.37+
610 # $ scripts/setlocalversion . => +
611 # $ make kernelversion => 2.6.37
612 # $ make kernelrelease => 2.6.37+
613 touch ${B}/.scmversion ${S}/.scmversion
614
615 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
616 mv "${S}/.config" "${B}/.config"
617 fi
618
619 # Copy defconfig to .config if .config does not exist. This allows
Patrick Williams213cb262021-08-07 19:21:33 -0500620 # recipes to manage the .config themselves in do_configure:prepend().
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
622 cp "${WORKDIR}/defconfig" "${B}/.config"
623 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500624
625 ${KERNEL_CONFIG_COMMAND}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500626}
627
628do_savedefconfig() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600629 bbplain "Saving defconfig to:\n${B}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500630 oe_runmake -C ${B} savedefconfig
631}
632do_savedefconfig[nostamp] = "1"
633addtask savedefconfig after do_configure
634
635inherit cml1
636
Patrick Williams213cb262021-08-07 19:21:33 -0500637KCONFIG_CONFIG_COMMAND:append = " LD='${KERNEL_LD}' HOSTLDFLAGS='${BUILD_LDFLAGS}'"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400638
Andrew Geissler595f6302022-01-24 19:11:47 +0000639EXPORT_FUNCTIONS do_compile do_transform_kernel do_transform_bundled_initramfs do_install do_configure
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500640
641# kernel-base becomes kernel-${KERNEL_VERSION}
He Zhefe76b1e2016-05-25 04:47:16 -0400642# kernel-image becomes kernel-image-${KERNEL_VERSION}
Andrew Geissler595f6302022-01-24 19:11:47 +0000643PACKAGES = "${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"
Patrick Williams213cb262021-08-07 19:21:33 -0500644FILES:${PN} = ""
645FILES:${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"
646FILES:${KERNEL_PACKAGE_NAME}-image = ""
647FILES:${KERNEL_PACKAGE_NAME}-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
648FILES:${KERNEL_PACKAGE_NAME}-vmlinux = "/boot/vmlinux-${KERNEL_VERSION_NAME}"
649FILES:${KERNEL_PACKAGE_NAME}-modules = ""
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500650RDEPENDS:${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base (= ${EXTENDPKGV})"
He Zhefe76b1e2016-05-25 04:47:16 -0400651# Allow machines to override this dependency if kernel image files are
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500652# not wanted in images as standard
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500653RDEPENDS:${KERNEL_PACKAGE_NAME}-base ?= "${KERNEL_PACKAGE_NAME}-image (= ${EXTENDPKGV})"
Patrick Williams213cb262021-08-07 19:21:33 -0500654PKG:${KERNEL_PACKAGE_NAME}-image = "${KERNEL_PACKAGE_NAME}-image-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
Andrew Geisslerd159c7f2021-09-02 21:05:58 -0500655RDEPENDS:${KERNEL_PACKAGE_NAME}-image += "${@oe.utils.conditional('KERNEL_IMAGETYPE', 'vmlinux', '${KERNEL_PACKAGE_NAME}-vmlinux (= ${EXTENDPKGV})', '', d)}"
Patrick Williams213cb262021-08-07 19:21:33 -0500656PKG:${KERNEL_PACKAGE_NAME}-base = "${KERNEL_PACKAGE_NAME}-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
657RPROVIDES:${KERNEL_PACKAGE_NAME}-base += "${KERNEL_PACKAGE_NAME}-${KERNEL_VERSION}"
658ALLOW_EMPTY:${KERNEL_PACKAGE_NAME} = "1"
659ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-base = "1"
660ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-image = "1"
661ALLOW_EMPTY:${KERNEL_PACKAGE_NAME}-modules = "1"
662DESCRIPTION:${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta package"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500663
Patrick Williams213cb262021-08-07 19:21:33 -0500664pkg_postinst:${KERNEL_PACKAGE_NAME}-base () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500665 if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
666 mkdir -p $D/lib/modules/${KERNEL_VERSION}
667 fi
668 if [ -n "$D" ]; then
669 depmodwrapper -a -b $D ${KERNEL_VERSION}
670 else
671 depmod -a ${KERNEL_VERSION}
672 fi
673}
674
Patrick Williams213cb262021-08-07 19:21:33 -0500675PACKAGESPLITFUNCS:prepend = "split_kernel_packages "
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500676
677python split_kernel_packages () {
Brad Bishop19323692019-04-05 15:28:33 -0400678 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='')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500679}
680
681# Many scripts want to look in arch/$arch/boot for the bootable
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600682# image. This poses a problem for vmlinux and vmlinuz based
683# booting. This task arranges to have vmlinux and vmlinuz appear
684# in the normalized directory location.
685do_kernel_link_images() {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500686 if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
687 mkdir ${B}/arch/${ARCH}/boot
688 fi
689 cd ${B}/arch/${ARCH}/boot
690 ln -sf ../../../vmlinux
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600691 if [ -f ../../../vmlinuz ]; then
692 ln -sf ../../../vmlinuz
693 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500694 if [ -f ../../../vmlinuz.bin ]; then
695 ln -sf ../../../vmlinuz.bin
696 fi
Andrew Geissler82c905d2020-04-13 13:39:40 -0500697 if [ -f ../../../vmlinux.64 ]; then
698 ln -sf ../../../vmlinux.64
699 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500700}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500701addtask kernel_link_images after do_compile before do_strip
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500702
Andrew Geissler595f6302022-01-24 19:11:47 +0000703python do_strip() {
704 import shutil
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500705
Andrew Geissler595f6302022-01-24 19:11:47 +0000706 strip = d.getVar('STRIP')
707 extra_sections = d.getVar('KERNEL_IMAGE_STRIP_EXTRA_SECTIONS')
708 kernel_image = d.getVar('B') + "/" + d.getVar('KERNEL_OUTPUT_DIR') + "/vmlinux"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500709
Andrew Geissler595f6302022-01-24 19:11:47 +0000710 if (extra_sections and kernel_image.find('boot/vmlinux') != -1):
711 kernel_image_stripped = kernel_image + ".stripped"
712 shutil.copy2(kernel_image, kernel_image_stripped)
713 oe.package.runstrip((kernel_image_stripped, 8, strip, extra_sections))
714 bb.debug(1, "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections: " + \
715 extra_sections)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500716}
717do_strip[dirs] = "${B}"
718
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500719addtask strip before do_sizecheck after do_kernel_link_images
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500720
721# Support checking the kernel size since some kernels need to reside in partitions
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500722# with a fixed length or there is a limit in transferring the kernel to memory.
723# If more than one image type is enabled, warn on any that don't fit but only fail
724# if none fit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500725do_sizecheck() {
726 if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then
727 invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'`
728 if [ -n "$invalid" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500729 die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integer (The unit is Kbytes)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500730 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500731 at_least_one_fits=
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800732 for imageType in ${KERNEL_IMAGETYPES} ; do
733 size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$imageType | awk '{print $1}'`
Andrew Geissler09036742021-06-25 14:25:14 -0500734 if [ $size -gt ${KERNEL_IMAGE_MAXSIZE} ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800735 bbwarn "This kernel $imageType (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device."
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500736 else
737 at_least_one_fits=y
He Zhefe76b1e2016-05-25 04:47:16 -0400738 fi
739 done
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500740 if [ -z "$at_least_one_fits" ]; then
741 die "All kernel images are too big for your device. Please reduce the size of the kernel by making more of it modular."
742 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500743 fi
744}
745do_sizecheck[dirs] = "${B}"
746
747addtask sizecheck before do_install after do_strip
748
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800749inherit kernel-artifact-names
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500750
751kernel_do_deploy() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400752 deployDir="${DEPLOYDIR}"
753 if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then
754 deployDir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}"
755 mkdir "$deployDir"
756 fi
757
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800758 for imageType in ${KERNEL_IMAGETYPES} ; do
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500759 baseName=$imageType-${KERNEL_IMAGE_NAME}
Andrew Geissler595f6302022-01-24 19:11:47 +0000760
761 if [ -s ${KERNEL_OUTPUT_DIR}/$imageType.stripped ] ; then
762 install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.stripped $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
763 else
764 install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType $deployDir/$baseName${KERNEL_IMAGE_BIN_EXT}
765 fi
766 if [ -n "${KERNEL_IMAGE_LINK_NAME}" ] ; then
767 ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${KERNEL_IMAGE_LINK_NAME}${KERNEL_IMAGE_BIN_EXT}
768 fi
769 if [ "${KERNEL_IMAGETYPE_SYMLINK}" = "1" ] ; then
770 ln -sf $baseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType
771 fi
He Zhefe76b1e2016-05-25 04:47:16 -0400772 done
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800773
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500774 if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800775 mkdir -p ${D}${root_prefix}/lib
Andrew Geisslerc182c622020-05-15 14:13:32 -0500776 if [ -n "${SOURCE_DATE_EPOCH}" ]; then
777 TAR_ARGS="--sort=name --clamp-mtime --mtime=@${SOURCE_DATE_EPOCH}"
778 else
779 TAR_ARGS=""
780 fi
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500781 TAR_ARGS="$TAR_ARGS --owner=0 --group=0"
Andrew Geisslerc182c622020-05-15 14:13:32 -0500782 tar $TAR_ARGS -cv -C ${D}${root_prefix} lib | gzip -9n > $deployDir/modules-${MODULE_TARBALL_NAME}.tgz
783
Andrew Geissler595f6302022-01-24 19:11:47 +0000784 if [ -n "${MODULE_TARBALL_LINK_NAME}" ] ; then
785 ln -sf modules-${MODULE_TARBALL_NAME}.tgz $deployDir/modules-${MODULE_TARBALL_LINK_NAME}.tgz
786 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500787 fi
788
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800789 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
Andrew Geissler595f6302022-01-24 19:11:47 +0000790 for imageType in ${KERNEL_IMAGETYPES} ; do
Brad Bishop977dc1a2019-02-06 16:01:43 -0500791 if [ "$imageType" = "fitImage" ] ; then
792 continue
793 fi
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500794 initramfsBaseName=$imageType-${INITRAMFS_NAME}
Andrew Geissler595f6302022-01-24 19:11:47 +0000795 install -m 0644 ${KERNEL_OUTPUT_DIR}/$imageType.initramfs $deployDir/$initramfsBaseName${KERNEL_IMAGE_BIN_EXT}
796 if [ -n "${INITRAMFS_LINK_NAME}" ] ; then
797 ln -sf $initramfsBaseName${KERNEL_IMAGE_BIN_EXT} $deployDir/$imageType-${INITRAMFS_LINK_NAME}${KERNEL_IMAGE_BIN_EXT}
798 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800799 done
800 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500801}
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500802
803# We deploy to filenames that include PKGV and PKGR, read the saved data to
804# ensure we get the right values for both
805do_deploy[prefuncs] += "read_subpackage_metadata"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500806
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500807addtask deploy after do_populate_sysroot do_packagedata
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500808
809EXPORT_FUNCTIONS do_deploy
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500810
811# Add using Device Tree support
812inherit kernel-devicetree