blob: e2ceb6a333bb25265b6c9ab197b4703dfffe9159 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit linux-kernel-base kernel-module-split
2
Brad Bishop316dfdd2018-06-25 12:45:53 -04003KERNEL_PACKAGE_NAME ??= "kernel"
4KERNEL_DEPLOYSUBDIR ??= "${@ "" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else d.getVar("KERNEL_PACKAGE_NAME") }"
5
6PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }"
Andrew Geissler475cb722020-07-10 16:00:51 -05007DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native bc-native bison-native"
8DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.lzo", "lzop-native", "", d)}"
9DEPENDS += "${@bb.utils.contains("INITRAMFS_FSTYPES", "cpio.lz4", "lz4-native", "", d)}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010PACKAGE_WRITE_DEPS += "depmodwrapper-cross"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011
Andrew Geissler475cb722020-07-10 16:00:51 -050012do_deploy[depends] += "depmodwrapper-cross:do_populate_sysroot gzip-native:do_populate_sysroot"
Brad Bishop15ae2502019-06-18 21:44:24 -040013do_clean[depends] += "make-mod-scripts:do_clean"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050014
15CVE_PRODUCT ?= "linux_kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016
17S = "${STAGING_KERNEL_DIR}"
18B = "${WORKDIR}/build"
19KBUILD_OUTPUT = "${B}"
20OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
21
22# we include gcc above, we dont need virtual/libc
23INHIBIT_DEFAULT_DEPS = "1"
24
25KERNEL_IMAGETYPE ?= "zImage"
26INITRAMFS_IMAGE ?= ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050027INITRAMFS_IMAGE_NAME ?= "${@['${INITRAMFS_IMAGE}-${MACHINE}', ''][d.getVar('INITRAMFS_IMAGE') == '']}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028INITRAMFS_TASK ?= ""
29INITRAMFS_IMAGE_BUNDLE ?= ""
30
He Zhefe76b1e2016-05-25 04:47:16 -040031# KERNEL_VERSION is extracted from source code. It is evaluated as
32# None for the first parsing, since the code has not been fetched.
33# After the code is fetched, it will be evaluated as real version
34# number and cause kernel to be rebuilt. To avoid this, make
35# KERNEL_VERSION_NAME and KERNEL_VERSION_PKG_NAME depend on
36# LINUX_VERSION which is a constant.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050037KERNEL_VERSION_NAME = "${@d.getVar('KERNEL_VERSION') or ""}"
He Zhefe76b1e2016-05-25 04:47:16 -040038KERNEL_VERSION_NAME[vardepvalue] = "${LINUX_VERSION}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050039KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
He Zhefe76b1e2016-05-25 04:47:16 -040040KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}"
41
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042python __anonymous () {
Brad Bishop316dfdd2018-06-25 12:45:53 -040043 pn = d.getVar("PN")
44 kpn = d.getVar("KERNEL_PACKAGE_NAME")
45
46 # XXX Remove this after bug 11905 is resolved
47 # FILES_${KERNEL_PACKAGE_NAME}-dev doesn't expand correctly
48 if kpn == pn:
49 bb.warn("Some packages (E.g. *-dev) might be missing due to "
50 "bug 11905 (variable KERNEL_PACKAGE_NAME == PN)")
51
52 # The default kernel recipe builds in a shared location defined by
53 # bitbake/distro confs: STAGING_KERNEL_DIR and STAGING_KERNEL_BUILDDIR.
54 # Set these variables to directories under ${WORKDIR} in alternate
55 # kernel recipes (I.e. where KERNEL_PACKAGE_NAME != kernel) so that they
56 # may build in parallel with the default kernel without clobbering.
57 if kpn != "kernel":
58 workdir = d.getVar("WORKDIR")
59 sourceDir = os.path.join(workdir, 'kernel-source')
60 artifactsDir = os.path.join(workdir, 'kernel-build-artifacts')
61 d.setVar("STAGING_KERNEL_DIR", sourceDir)
62 d.setVar("STAGING_KERNEL_BUILDDIR", artifactsDir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063
He Zhefe76b1e2016-05-25 04:47:16 -040064 # Merge KERNEL_IMAGETYPE and KERNEL_ALT_IMAGETYPE into KERNEL_IMAGETYPES
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065 type = d.getVar('KERNEL_IMAGETYPE') or ""
66 alttype = d.getVar('KERNEL_ALT_IMAGETYPE') or ""
67 types = d.getVar('KERNEL_IMAGETYPES') or ""
He Zhefe76b1e2016-05-25 04:47:16 -040068 if type not in types.split():
69 types = (type + ' ' + types).strip()
70 if alttype not in types.split():
71 types = (alttype + ' ' + types).strip()
72 d.setVar('KERNEL_IMAGETYPES', types)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080074 # KERNEL_IMAGETYPES may contain a mixture of image types supported directly
75 # by the kernel build system and types which are created by post-processing
76 # the output of the kernel build system (e.g. compressing vmlinux ->
77 # vmlinux.gz in kernel_do_compile()).
78 # KERNEL_IMAGETYPE_FOR_MAKE should contain only image types supported
79 # directly by the kernel build system.
80 if not d.getVar('KERNEL_IMAGETYPE_FOR_MAKE'):
81 typeformake = set()
82 for type in types.split():
83 if type == 'vmlinux.gz':
84 type = 'vmlinux'
85 typeformake.add(type)
86
87 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', ' '.join(sorted(typeformake)))
88
89 kname = d.getVar('KERNEL_PACKAGE_NAME') or "kernel"
90 imagedest = d.getVar('KERNEL_IMAGEDEST')
He Zhefe76b1e2016-05-25 04:47:16 -040091
Brad Bishop37a0e4d2017-12-04 01:01:44 -050092 for type in types.split():
He Zhefe76b1e2016-05-25 04:47:16 -040093 typelower = type.lower()
Brad Bishop316dfdd2018-06-25 12:45:53 -040094 d.appendVar('PACKAGES', ' %s-image-%s' % (kname, typelower))
Brad Bishop316dfdd2018-06-25 12:45:53 -040095 d.setVar('FILES_' + kname + '-image-' + typelower, '/' + imagedest + '/' + type + '-${KERNEL_VERSION_NAME}' + ' /' + imagedest + '/' + type)
Brad Bishop316dfdd2018-06-25 12:45:53 -040096 d.appendVar('RDEPENDS_%s-image' % kname, ' %s-image-%s' % (kname, typelower))
Brad Bishop316dfdd2018-06-25 12:45:53 -040097 d.setVar('PKG_%s-image-%s' % (kname,typelower), '%s-image-%s-${KERNEL_VERSION_PKG_NAME}' % (kname, typelower))
Brad Bishop316dfdd2018-06-25 12:45:53 -040098 d.setVar('ALLOW_EMPTY_%s-image-%s' % (kname, typelower), '1')
Andrew Geissler475cb722020-07-10 16:00:51 -050099 d.setVar('pkg_postinst_%s-image-%s' % (kname,typelower), """set +e
100if [ -n "$D" ]; then
101 ln -sf %s-${KERNEL_VERSION} $D/${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
102else
103 ln -sf %s-${KERNEL_VERSION} ${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
104 if [ $? -ne 0 ]; then
105 echo "Filesystem on ${KERNEL_IMAGEDEST}/ doesn't support symlinks, falling back to copied image (%s)."
106 install -m 0644 ${KERNEL_IMAGEDEST}/%s-${KERNEL_VERSION} ${KERNEL_IMAGEDEST}/%s
107 fi
108fi
109set -e
110""" % (type, type, type, type, type, type, type))
111 d.setVar('pkg_postrm_%s-image-%s' % (kname,typelower), """set +e
112if [ -f "${KERNEL_IMAGEDEST}/%s" -o -L "${KERNEL_IMAGEDEST}/%s" ]; then
113 rm -f ${KERNEL_IMAGEDEST}/%s > /dev/null 2>&1
114fi
115set -e
116""" % (type, type, type))
117
He Zhefe76b1e2016-05-25 04:47:16 -0400118
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500119 image = d.getVar('INITRAMFS_IMAGE')
Brad Bishop79641f22019-09-10 07:20:22 -0400120 # If the INTIRAMFS_IMAGE is set but the INITRAMFS_IMAGE_BUNDLE is set to 0,
121 # the do_bundle_initramfs does nothing, but the INITRAMFS_IMAGE is built
122 # standalone for use by wic and other tools.
123 if image:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500124 d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500125
126 # NOTE: setting INITRAMFS_TASK is for backward compatibility
127 # The preferred method is to set INITRAMFS_IMAGE, because
128 # this INITRAMFS_TASK has circular dependency problems
129 # if the initramfs requires kernel modules
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500130 image_task = d.getVar('INITRAMFS_TASK')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500131 if image_task:
132 d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}')
133}
134
135# Here we pull in all various kernel image types which we support.
136#
137# In case you're wondering why kernel.bbclass inherits the other image
138# types instead of the other way around, the reason for that is to
139# maintain compatibility with various currently existing meta-layers.
140# By pulling in the various kernel image types here, we retain the
141# original behavior of kernel.bbclass, so no meta-layers should get
142# broken.
143#
144# KERNEL_CLASSES by default pulls in kernel-uimage.bbclass, since this
145# used to be the default behavior when only uImage was supported. This
146# variable can be appended by users who implement support for new kernel
147# image types.
148
149KERNEL_CLASSES ?= " kernel-uimage "
150inherit ${KERNEL_CLASSES}
151
152# Old style kernels may set ${S} = ${WORKDIR}/git for example
153# We need to move these over to STAGING_KERNEL_DIR. We can't just
154# create the symlink in advance as the git fetcher can't cope with
155# the symlink.
156do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
157do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
Brad Bishopc342db32019-05-15 21:57:59 -0400158python do_symlink_kernsrc () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500159 s = d.getVar("S")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160 if s[-1] == '/':
161 # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as directory name and fail
162 s=s[:-1]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500163 kernsrc = d.getVar("STAGING_KERNEL_DIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164 if s != kernsrc:
165 bb.utils.mkdirhier(kernsrc)
166 bb.utils.remove(kernsrc, recurse=True)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500167 if d.getVar("EXTERNALSRC"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168 # With EXTERNALSRC S will not be wiped so we can symlink to it
169 os.symlink(s, kernsrc)
170 else:
171 import shutil
172 shutil.move(s, kernsrc)
173 os.symlink(kernsrc, s)
174}
Brad Bishopc342db32019-05-15 21:57:59 -0400175addtask symlink_kernsrc before do_configure after do_unpack
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176
177inherit kernel-arch deploy
178
Brad Bishop316dfdd2018-06-25 12:45:53 -0400179PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
180PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-image-.*"
181PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-firmware-.*"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182
183export OS = "${TARGET_OS}"
184export CROSS_COMPILE = "${TARGET_PREFIX}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400185export KBUILD_BUILD_VERSION = "1"
Brad Bishop977dc1a2019-02-06 16:01:43 -0500186export KBUILD_BUILD_USER ?= "oe-user"
187export KBUILD_BUILD_HOST ?= "oe-host"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500188
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500189KERNEL_RELEASE ?= "${KERNEL_VERSION}"
190
He Zhefe76b1e2016-05-25 04:47:16 -0400191# The directory where built kernel lies in the kernel tree
192KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800193KERNEL_IMAGEDEST ?= "boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500194
195#
196# configuration
197#
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500198export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE") or "ttyS0"}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500199
200KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}"
201
202KERNEL_LOCALVERSION ?= ""
203
204# kernels are generally machine specific
205PACKAGE_ARCH = "${MACHINE_ARCH}"
206
207# U-Boot support
208UBOOT_ENTRYPOINT ?= "20008000"
209UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}"
210
211# Some Linux kernel configurations need additional parameters on the command line
212KERNEL_EXTRA_ARGS ?= ""
213
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500214EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}""
Andrew Geissler635e0e42020-08-21 15:58:33 -0500215EXTRA_OEMAKE += " HOSTCXX="${BUILD_CXX} ${BUILD_CXXFLAGS} ${BUILD_LDFLAGS}""
216
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217KERNEL_ALT_IMAGETYPE ??= ""
218
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500219copy_initramfs() {
220 echo "Copying initramfs into ./usr ..."
221 # In case the directory is not created yet from the first pass compile:
222 mkdir -p ${B}/usr
223 # Find and use the first initramfs image archive type we find
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500224 rm -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500225 for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz; do
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500226 if [ -e "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" ]; then
227 cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500228 case $img in
229 *gz)
230 echo "gzip decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500231 gunzip -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500232 break
233 ;;
234 *lz4)
235 echo "lz4 decompressing image"
Andrew Geissler475cb722020-07-10 16:00:51 -0500236 lz4 -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237 break
238 ;;
239 *lzo)
240 echo "lzo decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500241 lzop -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500242 break
243 ;;
244 *lzma)
245 echo "lzma decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500246 lzma -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247 break
248 ;;
249 *xz)
250 echo "xz decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500251 xz -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500252 break
253 ;;
254 esac
Brad Bishopf8caae32019-03-25 13:13:56 -0400255 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500256 fi
257 done
Brad Bishopf8caae32019-03-25 13:13:56 -0400258 # Verify that the above loop found a initramfs, fail otherwise
259 [ -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) for bundling; INITRAMFS_IMAGE_NAME might be wrong."
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500260}
261
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262do_bundle_initramfs () {
263 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
264 echo "Creating a kernel image with a bundled initramfs..."
265 copy_initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400266 # Backing up kernel image relies on its type(regular file or symbolic link)
267 tmp_path=""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800268 for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
269 if [ -h ${KERNEL_OUTPUT_DIR}/$imageType ] ; then
270 linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$imageType`
271 realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$imageType`
He Zhefe76b1e2016-05-25 04:47:16 -0400272 mv -f $realpath $realpath.bak
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800273 tmp_path=$tmp_path" "$imageType"#"$linkpath"#"$realpath
274 elif [ -f ${KERNEL_OUTPUT_DIR}/$imageType ]; then
275 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.bak
276 tmp_path=$tmp_path" "$imageType"##"
He Zhefe76b1e2016-05-25 04:47:16 -0400277 fi
278 done
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500279 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500280 kernel_do_compile
He Zhefe76b1e2016-05-25 04:47:16 -0400281 # Restoring kernel image
282 for tp in $tmp_path ; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800283 imageType=`echo $tp|cut -d "#" -f 1`
He Zhefe76b1e2016-05-25 04:47:16 -0400284 linkpath=`echo $tp|cut -d "#" -f 2`
285 realpath=`echo $tp|cut -d "#" -f 3`
286 if [ -n "$realpath" ]; then
287 mv -f $realpath $realpath.initramfs
288 mv -f $realpath.bak $realpath
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800289 ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$imageType.initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400290 else
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800291 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.initramfs
292 mv -f ${KERNEL_OUTPUT_DIR}/$imageType.bak ${KERNEL_OUTPUT_DIR}/$imageType
He Zhefe76b1e2016-05-25 04:47:16 -0400293 fi
294 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500295 fi
296}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600297do_bundle_initramfs[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298
299python do_devshell_prepend () {
300 os.environ["LDFLAGS"] = ''
301}
302
303addtask bundle_initramfs after do_install before do_deploy
304
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500305get_cc_option () {
306 # Check if KERNEL_CC supports the option "file-prefix-map".
307 # This option allows us to build images with __FILE__ values that do not
308 # contain the host build path.
309 if ${KERNEL_CC} -Q --help=joined | grep -q "\-ffile-prefix-map=<old=new>"; then
310 echo "-ffile-prefix-map=${S}=/kernel-source/"
311 fi
312}
313
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500314kernel_do_compile() {
315 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
Brad Bishop316dfdd2018-06-25 12:45:53 -0400316 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500317 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
318 # be set....
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800319 if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
Andrew Geissler82c905d2020-04-13 13:39:40 -0500320 # The source directory is not necessarily a git repository, so we
321 # specify the git-dir to ensure that git does not query a
322 # repository in any parent directory.
323 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 -0500324 fi
325
326 ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
327 export KBUILD_BUILD_TIMESTAMP="$ts"
328 export KCONFIG_NOTIMESTAMP=1
329 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
330 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331 # The $use_alternate_initrd is only set from
332 # do_bundle_initramfs() This variable is specifically for the
333 # case where we are making a second pass at the kernel
334 # compilation and we want to force the kernel build to use a
335 # different initramfs image. The way to do that in the kernel
336 # is to specify:
337 # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio
338 if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then
339 # The old style way of copying an prebuilt image and building it
340 # is turned on via INTIRAMFS_TASK != ""
341 copy_initramfs
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500342 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500343 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500344 cc_extra=$(get_cc_option)
He Zhefe76b1e2016-05-25 04:47:16 -0400345 for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500346 oe_runmake ${typeformake} CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd
He Zhefe76b1e2016-05-25 04:47:16 -0400347 done
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500348 # vmlinux.gz is not built by kernel
349 if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then
350 mkdir -p "${KERNEL_OUTPUT_DIR}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500351 gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500352 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500353}
354
355do_compile_kernelmodules() {
356 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500357 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
358 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
359 # be set....
360 if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
361 # The source directory is not necessarily a git repository, so we
362 # specify the git-dir to ensure that git does not query a
363 # repository in any parent directory.
364 SOURCE_DATE_EPOCH=`git --git-dir="${S}/.git" log -1 --pretty=%ct 2>/dev/null || echo "${REPRODUCIBLE_TIMESTAMP_ROOTFS}"`
365 fi
366
367 ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
368 export KBUILD_BUILD_TIMESTAMP="$ts"
369 export KCONFIG_NOTIMESTAMP=1
370 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
371 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500372 if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500373 cc_extra=$(get_cc_option)
374 oe_runmake -C ${B} ${PARALLEL_MAKE} modules CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500375
376 # Module.symvers gets updated during the
377 # building of the kernel modules. We need to
378 # update this in the shared workdir since some
379 # external kernel modules has a dependency on
380 # other kernel modules and will look at this
381 # file to do symbol lookups
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600382 cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500383 else
384 bbnote "no modules to compile"
385 fi
386}
387addtask compile_kernelmodules after do_compile before do_strip
388
389kernel_do_install() {
390 #
391 # First install the modules
392 #
393 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
394 if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500395 oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
396 rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
397 rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500398 # If the kernel/ directory is empty remove it to prevent QA issues
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500399 rmdir --ignore-fail-on-non-empty "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500400 else
401 bbnote "no modules to install"
402 fi
403
404 #
405 # Install various kernel output (zImage, map file, config, module support files)
406 #
407 install -d ${D}/${KERNEL_IMAGEDEST}
408 install -d ${D}/boot
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800409 for imageType in ${KERNEL_IMAGETYPES} ; do
410 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} ${D}/${KERNEL_IMAGEDEST}/${imageType}-${KERNEL_VERSION}
He Zhefe76b1e2016-05-25 04:47:16 -0400411 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500412 install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION}
413 install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION}
414 install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION}
415 [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION}
416 install -d ${D}${sysconfdir}/modules-load.d
417 install -d ${D}${sysconfdir}/modprobe.d
418}
419do_install[prefuncs] += "package_get_auto_pr"
420
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600421# Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile
422do_kernel_version_sanity_check() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500423 if [ "x${KERNEL_VERSION_SANITY_SKIP}" = "x1" ]; then
424 exit 0
425 fi
426
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600427 # The Makefile determines the kernel version shown at runtime
428 # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile
429 VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//)
430 PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
431 SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
432 EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//)
433
434 # Build a string for regex and a plain version string
435 reg="^${VERSION}\.${PATCHLEVEL}"
436 vers="${VERSION}.${PATCHLEVEL}"
437 if [ -n "${SUBLEVEL}" ]; then
438 # Ignoring a SUBLEVEL of zero is fine
439 if [ "${SUBLEVEL}" = "0" ]; then
440 reg="${reg}(\.${SUBLEVEL})?"
441 else
442 reg="${reg}\.${SUBLEVEL}"
443 vers="${vers}.${SUBLEVEL}"
444 fi
445 fi
446 vers="${vers}${EXTRAVERSION}"
447 reg="${reg}${EXTRAVERSION}"
448
449 if [ -z `echo ${PV} | grep -E "${reg}"` ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500450 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 -0600451 fi
452 exit 0
453}
454
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500455addtask shared_workdir after do_compile before do_compile_kernelmodules
456addtask shared_workdir_setscene
457
458do_shared_workdir_setscene () {
459 exit 1
460}
461
462emit_depmod_pkgdata() {
463 # Stash data for depmod
Brad Bishop316dfdd2018-06-25 12:45:53 -0400464 install -d ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/
465 echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/${KERNEL_PACKAGE_NAME}-abiversion
466 cp ${B}/System.map ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/System.map-${KERNEL_VERSION}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500467}
468
469PACKAGEFUNCS += "emit_depmod_pkgdata"
470
Brad Bishop316dfdd2018-06-25 12:45:53 -0400471do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500472do_shared_workdir () {
473 cd ${B}
474
475 kerneldir=${STAGING_KERNEL_BUILDDIR}
476 install -d $kerneldir
477
478 #
479 # Store the kernel version in sysroots for module-base.bbclass
480 #
481
Brad Bishop316dfdd2018-06-25 12:45:53 -0400482 echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500483
484 # Copy files required for module builds
485 cp System.map $kerneldir/System.map-${KERNEL_VERSION}
Andrew Geissler475cb722020-07-10 16:00:51 -0500486 [ -e Module.symvers ] && cp Module.symvers $kerneldir/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500487 cp .config $kerneldir/
488 mkdir -p $kerneldir/include/config
489 cp include/config/kernel.release $kerneldir/include/config/kernel.release
Brad Bishop08902b02019-08-20 09:16:51 -0400490 if [ -e certs/signing_key.x509 ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600491 # The signing_key.* files are stored in the certs/ dir in
492 # newer Linux kernels
493 mkdir -p $kerneldir/certs
494 cp certs/signing_key.* $kerneldir/certs/
495 elif [ -e signing_key.priv ]; then
496 cp signing_key.* $kerneldir/
497 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500498
499 # We can also copy over all the generated files and avoid special cases
500 # like version.h, but we've opted to keep this small until file creep starts
501 # to happen
502 if [ -e include/linux/version.h ]; then
503 mkdir -p $kerneldir/include/linux
504 cp include/linux/version.h $kerneldir/include/linux/version.h
505 fi
506
507 # As of Linux kernel version 3.0.1, the clean target removes
508 # arch/powerpc/lib/crtsavres.o which is present in
509 # KBUILD_LDFLAGS_MODULE, making it required to build external modules.
510 if [ ${ARCH} = "powerpc" ]; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400511 if [ -e arch/powerpc/lib/crtsavres.o ]; then
512 mkdir -p $kerneldir/arch/powerpc/lib/
513 cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o
514 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500515 fi
516
517 if [ -d include/generated ]; then
518 mkdir -p $kerneldir/include/generated/
519 cp -fR include/generated/* $kerneldir/include/generated/
520 fi
521
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500522 if [ -d arch/${ARCH}/include/generated ]; then
523 mkdir -p $kerneldir/arch/${ARCH}/include/generated/
524 cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500525 fi
Brad Bishop19323692019-04-05 15:28:33 -0400526
527 if (grep -q -i -e '^CONFIG_UNWINDER_ORC=y$' $kerneldir/.config); then
528 # With CONFIG_UNWINDER_ORC (the default in 4.14), objtool is required for
529 # out-of-tree modules to be able to generate object files.
530 if [ -x tools/objtool/objtool ]; then
531 mkdir -p ${kerneldir}/tools/objtool
532 cp tools/objtool/objtool ${kerneldir}/tools/objtool/
533 fi
534 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500535}
536
537# We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware
538sysroot_stage_all () {
539 :
540}
541
Andrew Geissler82c905d2020-04-13 13:39:40 -0500542KERNEL_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 -0500543
He Zhefe76b1e2016-05-25 04:47:16 -0400544python check_oldest_kernel() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500545 oldest_kernel = d.getVar('OLDEST_KERNEL')
546 kernel_version = d.getVar('KERNEL_VERSION')
547 tclibc = d.getVar('TCLIBC')
He Zhefe76b1e2016-05-25 04:47:16 -0400548 if tclibc == 'glibc':
549 kernel_version = kernel_version.split('-', 1)[0]
550 if oldest_kernel and kernel_version:
551 if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500552 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 -0400553}
554
555check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION"
556do_configure[prefuncs] += "check_oldest_kernel"
557
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500558kernel_do_configure() {
559 # fixes extra + in /lib/modules/2.6.37+
560 # $ scripts/setlocalversion . => +
561 # $ make kernelversion => 2.6.37
562 # $ make kernelrelease => 2.6.37+
563 touch ${B}/.scmversion ${S}/.scmversion
564
565 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
566 mv "${S}/.config" "${B}/.config"
567 fi
568
569 # Copy defconfig to .config if .config does not exist. This allows
570 # recipes to manage the .config themselves in do_configure_prepend().
571 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
572 cp "${WORKDIR}/defconfig" "${B}/.config"
573 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500574
575 ${KERNEL_CONFIG_COMMAND}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500576}
577
578do_savedefconfig() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600579 bbplain "Saving defconfig to:\n${B}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500580 oe_runmake -C ${B} savedefconfig
581}
582do_savedefconfig[nostamp] = "1"
583addtask savedefconfig after do_configure
584
585inherit cml1
586
Brad Bishop316dfdd2018-06-25 12:45:53 -0400587KCONFIG_CONFIG_COMMAND_append = " HOSTLDFLAGS='${BUILD_LDFLAGS}'"
588
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500589EXPORT_FUNCTIONS do_compile do_install do_configure
590
591# kernel-base becomes kernel-${KERNEL_VERSION}
He Zhefe76b1e2016-05-25 04:47:16 -0400592# kernel-image becomes kernel-image-${KERNEL_VERSION}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400593PACKAGES = "${KERNEL_PACKAGE_NAME} ${KERNEL_PACKAGE_NAME}-base ${KERNEL_PACKAGE_NAME}-vmlinux ${KERNEL_PACKAGE_NAME}-image ${KERNEL_PACKAGE_NAME}-dev ${KERNEL_PACKAGE_NAME}-modules"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500594FILES_${PN} = ""
Brad Bishop15ae2502019-06-18 21:44:24 -0400595FILES_${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"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400596FILES_${KERNEL_PACKAGE_NAME}-image = ""
597FILES_${KERNEL_PACKAGE_NAME}-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
598FILES_${KERNEL_PACKAGE_NAME}-vmlinux = "/boot/vmlinux-${KERNEL_VERSION_NAME}"
599FILES_${KERNEL_PACKAGE_NAME}-modules = ""
600RDEPENDS_${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base"
He Zhefe76b1e2016-05-25 04:47:16 -0400601# Allow machines to override this dependency if kernel image files are
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500602# not wanted in images as standard
Brad Bishop316dfdd2018-06-25 12:45:53 -0400603RDEPENDS_${KERNEL_PACKAGE_NAME}-base ?= "${KERNEL_PACKAGE_NAME}-image"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500604PKG_${KERNEL_PACKAGE_NAME}-image = "${KERNEL_PACKAGE_NAME}-image-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400605RDEPENDS_${KERNEL_PACKAGE_NAME}-image += "${@oe.utils.conditional('KERNEL_IMAGETYPE', 'vmlinux', '${KERNEL_PACKAGE_NAME}-vmlinux', '', d)}"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500606PKG_${KERNEL_PACKAGE_NAME}-base = "${KERNEL_PACKAGE_NAME}-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400607RPROVIDES_${KERNEL_PACKAGE_NAME}-base += "${KERNEL_PACKAGE_NAME}-${KERNEL_VERSION}"
608ALLOW_EMPTY_${KERNEL_PACKAGE_NAME} = "1"
609ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-base = "1"
610ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-image = "1"
611ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-modules = "1"
612DESCRIPTION_${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta package"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500613
Brad Bishop316dfdd2018-06-25 12:45:53 -0400614pkg_postinst_${KERNEL_PACKAGE_NAME}-base () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500615 if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
616 mkdir -p $D/lib/modules/${KERNEL_VERSION}
617 fi
618 if [ -n "$D" ]; then
619 depmodwrapper -a -b $D ${KERNEL_VERSION}
620 else
621 depmod -a ${KERNEL_VERSION}
622 fi
623}
624
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500625PACKAGESPLITFUNCS_prepend = "split_kernel_packages "
626
627python split_kernel_packages () {
Brad Bishop19323692019-04-05 15:28:33 -0400628 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 -0500629}
630
631# Many scripts want to look in arch/$arch/boot for the bootable
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600632# image. This poses a problem for vmlinux and vmlinuz based
633# booting. This task arranges to have vmlinux and vmlinuz appear
634# in the normalized directory location.
635do_kernel_link_images() {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500636 if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
637 mkdir ${B}/arch/${ARCH}/boot
638 fi
639 cd ${B}/arch/${ARCH}/boot
640 ln -sf ../../../vmlinux
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600641 if [ -f ../../../vmlinuz ]; then
642 ln -sf ../../../vmlinuz
643 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500644 if [ -f ../../../vmlinuz.bin ]; then
645 ln -sf ../../../vmlinuz.bin
646 fi
Andrew Geissler82c905d2020-04-13 13:39:40 -0500647 if [ -f ../../../vmlinux.64 ]; then
648 ln -sf ../../../vmlinux.64
649 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500650}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500651addtask kernel_link_images after do_compile before do_strip
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500652
653do_strip() {
654 if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then
He Zhefe76b1e2016-05-25 04:47:16 -0400655 if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then
656 bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500657 return
658 fi
659
660 cd ${B}
He Zhefe76b1e2016-05-25 04:47:16 -0400661 headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500662 grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \
663 sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \
664 gawk '{print $1}'`
665
666 for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500667 if ! (echo "$headers" | grep -q "^$str$"); then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500668 bbwarn "Section not found: $str";
669 fi
670
He Zhefe76b1e2016-05-25 04:47:16 -0400671 "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500672 }; done
673
674 bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \
675 "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}"
676 fi;
677}
678do_strip[dirs] = "${B}"
679
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500680addtask strip before do_sizecheck after do_kernel_link_images
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500681
682# Support checking the kernel size since some kernels need to reside in partitions
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500683# with a fixed length or there is a limit in transferring the kernel to memory.
684# If more than one image type is enabled, warn on any that don't fit but only fail
685# if none fit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500686do_sizecheck() {
687 if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then
688 invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'`
689 if [ -n "$invalid" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500690 die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integer (The unit is Kbytes)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500691 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500692 at_least_one_fits=
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800693 for imageType in ${KERNEL_IMAGETYPES} ; do
694 size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$imageType | awk '{print $1}'`
He Zhefe76b1e2016-05-25 04:47:16 -0400695 if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800696 bbwarn "This kernel $imageType (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device."
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500697 else
698 at_least_one_fits=y
He Zhefe76b1e2016-05-25 04:47:16 -0400699 fi
700 done
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500701 if [ -z "$at_least_one_fits" ]; then
702 die "All kernel images are too big for your device. Please reduce the size of the kernel by making more of it modular."
703 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500704 fi
705}
706do_sizecheck[dirs] = "${B}"
707
708addtask sizecheck before do_install after do_strip
709
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800710inherit kernel-artifact-names
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500711
712kernel_do_deploy() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400713 deployDir="${DEPLOYDIR}"
714 if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then
715 deployDir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}"
716 mkdir "$deployDir"
717 fi
718
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800719 for imageType in ${KERNEL_IMAGETYPES} ; do
720 base_name=${imageType}-${KERNEL_IMAGE_NAME}
721 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} $deployDir/${base_name}.bin
722 symlink_name=${imageType}-${KERNEL_IMAGE_LINK_NAME}
723 ln -sf ${base_name}.bin $deployDir/${symlink_name}.bin
724 ln -sf ${base_name}.bin $deployDir/${imageType}
He Zhefe76b1e2016-05-25 04:47:16 -0400725 done
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800726
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500727 if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800728 mkdir -p ${D}${root_prefix}/lib
Andrew Geisslerc182c622020-05-15 14:13:32 -0500729 if [ -n "${SOURCE_DATE_EPOCH}" ]; then
730 TAR_ARGS="--sort=name --clamp-mtime --mtime=@${SOURCE_DATE_EPOCH}"
731 else
732 TAR_ARGS=""
733 fi
Andrew Geissler1e34c2d2020-05-29 16:02:59 -0500734 TAR_ARGS="$TAR_ARGS --owner=0 --group=0"
Andrew Geisslerc182c622020-05-15 14:13:32 -0500735 tar $TAR_ARGS -cv -C ${D}${root_prefix} lib | gzip -9n > $deployDir/modules-${MODULE_TARBALL_NAME}.tgz
736
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800737 ln -sf modules-${MODULE_TARBALL_NAME}.tgz $deployDir/modules-${MODULE_TARBALL_LINK_NAME}.tgz
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500738 fi
739
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800740 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
741 for imageType in ${KERNEL_IMAGETYPES} ; do
Brad Bishop977dc1a2019-02-06 16:01:43 -0500742 if [ "$imageType" = "fitImage" ] ; then
743 continue
744 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800745 initramfs_base_name=${imageType}-${INITRAMFS_NAME}
746 initramfs_symlink_name=${imageType}-${INITRAMFS_LINK_NAME}
747 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType}.initramfs $deployDir/${initramfs_base_name}.bin
Brad Bishop316dfdd2018-06-25 12:45:53 -0400748 ln -sf ${initramfs_base_name}.bin $deployDir/${initramfs_symlink_name}.bin
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800749 done
750 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500751}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500752do_deploy[prefuncs] += "package_get_auto_pr"
753
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500754addtask deploy after do_populate_sysroot do_packagedata
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500755
756EXPORT_FUNCTIONS do_deploy
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500757
758# Add using Device Tree support
759inherit kernel-devicetree