blob: 6846d6040df6ac4380468cfa83d924b6b7f91736 [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 "" }"
7DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native bc-native lzop-native bison-native"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008PACKAGE_WRITE_DEPS += "depmodwrapper-cross"
Brad Bishop6e60e8b2018-02-01 10:27:11 -05009
10do_deploy[depends] += "depmodwrapper-cross:do_populate_sysroot"
Brad Bishop15ae2502019-06-18 21:44:24 -040011do_clean[depends] += "make-mod-scripts:do_clean"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050012
13CVE_PRODUCT ?= "linux_kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050014
15S = "${STAGING_KERNEL_DIR}"
16B = "${WORKDIR}/build"
17KBUILD_OUTPUT = "${B}"
18OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
19
20# we include gcc above, we dont need virtual/libc
21INHIBIT_DEFAULT_DEPS = "1"
22
23KERNEL_IMAGETYPE ?= "zImage"
24INITRAMFS_IMAGE ?= ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025INITRAMFS_IMAGE_NAME ?= "${@['${INITRAMFS_IMAGE}-${MACHINE}', ''][d.getVar('INITRAMFS_IMAGE') == '']}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026INITRAMFS_TASK ?= ""
27INITRAMFS_IMAGE_BUNDLE ?= ""
28
He Zhefe76b1e2016-05-25 04:47:16 -040029# KERNEL_VERSION is extracted from source code. It is evaluated as
30# None for the first parsing, since the code has not been fetched.
31# After the code is fetched, it will be evaluated as real version
32# number and cause kernel to be rebuilt. To avoid this, make
33# KERNEL_VERSION_NAME and KERNEL_VERSION_PKG_NAME depend on
34# LINUX_VERSION which is a constant.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035KERNEL_VERSION_NAME = "${@d.getVar('KERNEL_VERSION') or ""}"
He Zhefe76b1e2016-05-25 04:47:16 -040036KERNEL_VERSION_NAME[vardepvalue] = "${LINUX_VERSION}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050037KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
He Zhefe76b1e2016-05-25 04:47:16 -040038KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}"
39
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040python __anonymous () {
Brad Bishop316dfdd2018-06-25 12:45:53 -040041 pn = d.getVar("PN")
42 kpn = d.getVar("KERNEL_PACKAGE_NAME")
43
44 # XXX Remove this after bug 11905 is resolved
45 # FILES_${KERNEL_PACKAGE_NAME}-dev doesn't expand correctly
46 if kpn == pn:
47 bb.warn("Some packages (E.g. *-dev) might be missing due to "
48 "bug 11905 (variable KERNEL_PACKAGE_NAME == PN)")
49
50 # The default kernel recipe builds in a shared location defined by
51 # bitbake/distro confs: STAGING_KERNEL_DIR and STAGING_KERNEL_BUILDDIR.
52 # Set these variables to directories under ${WORKDIR} in alternate
53 # kernel recipes (I.e. where KERNEL_PACKAGE_NAME != kernel) so that they
54 # may build in parallel with the default kernel without clobbering.
55 if kpn != "kernel":
56 workdir = d.getVar("WORKDIR")
57 sourceDir = os.path.join(workdir, 'kernel-source')
58 artifactsDir = os.path.join(workdir, 'kernel-build-artifacts')
59 d.setVar("STAGING_KERNEL_DIR", sourceDir)
60 d.setVar("STAGING_KERNEL_BUILDDIR", artifactsDir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061
He Zhefe76b1e2016-05-25 04:47:16 -040062 # Merge KERNEL_IMAGETYPE and KERNEL_ALT_IMAGETYPE into KERNEL_IMAGETYPES
Brad Bishop6e60e8b2018-02-01 10:27:11 -050063 type = d.getVar('KERNEL_IMAGETYPE') or ""
64 alttype = d.getVar('KERNEL_ALT_IMAGETYPE') or ""
65 types = d.getVar('KERNEL_IMAGETYPES') or ""
He Zhefe76b1e2016-05-25 04:47:16 -040066 if type not in types.split():
67 types = (type + ' ' + types).strip()
68 if alttype not in types.split():
69 types = (alttype + ' ' + types).strip()
70 d.setVar('KERNEL_IMAGETYPES', types)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050071
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080072 # KERNEL_IMAGETYPES may contain a mixture of image types supported directly
73 # by the kernel build system and types which are created by post-processing
74 # the output of the kernel build system (e.g. compressing vmlinux ->
75 # vmlinux.gz in kernel_do_compile()).
76 # KERNEL_IMAGETYPE_FOR_MAKE should contain only image types supported
77 # directly by the kernel build system.
78 if not d.getVar('KERNEL_IMAGETYPE_FOR_MAKE'):
79 typeformake = set()
80 for type in types.split():
81 if type == 'vmlinux.gz':
82 type = 'vmlinux'
83 typeformake.add(type)
84
85 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', ' '.join(sorted(typeformake)))
86
87 kname = d.getVar('KERNEL_PACKAGE_NAME') or "kernel"
88 imagedest = d.getVar('KERNEL_IMAGEDEST')
He Zhefe76b1e2016-05-25 04:47:16 -040089
Brad Bishop37a0e4d2017-12-04 01:01:44 -050090 for type in types.split():
He Zhefe76b1e2016-05-25 04:47:16 -040091 typelower = type.lower()
Brad Bishop316dfdd2018-06-25 12:45:53 -040092 d.appendVar('PACKAGES', ' %s-image-%s' % (kname, typelower))
Brad Bishop316dfdd2018-06-25 12:45:53 -040093 d.setVar('FILES_' + kname + '-image-' + typelower, '/' + imagedest + '/' + type + '-${KERNEL_VERSION_NAME}' + ' /' + imagedest + '/' + type)
Brad Bishop316dfdd2018-06-25 12:45:53 -040094 d.appendVar('RDEPENDS_%s-image' % kname, ' %s-image-%s' % (kname, typelower))
Brad Bishop316dfdd2018-06-25 12:45:53 -040095 d.setVar('PKG_%s-image-%s' % (kname,typelower), '%s-image-%s-${KERNEL_VERSION_PKG_NAME}' % (kname, typelower))
Brad Bishop316dfdd2018-06-25 12:45:53 -040096 d.setVar('ALLOW_EMPTY_%s-image-%s' % (kname, typelower), '1')
He Zhefe76b1e2016-05-25 04:47:16 -040097
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 image = d.getVar('INITRAMFS_IMAGE')
Brad Bishop79641f22019-09-10 07:20:22 -040099 # If the INTIRAMFS_IMAGE is set but the INITRAMFS_IMAGE_BUNDLE is set to 0,
100 # the do_bundle_initramfs does nothing, but the INITRAMFS_IMAGE is built
101 # standalone for use by wic and other tools.
102 if image:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500103 d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500104
105 # NOTE: setting INITRAMFS_TASK is for backward compatibility
106 # The preferred method is to set INITRAMFS_IMAGE, because
107 # this INITRAMFS_TASK has circular dependency problems
108 # if the initramfs requires kernel modules
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500109 image_task = d.getVar('INITRAMFS_TASK')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500110 if image_task:
111 d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}')
112}
113
114# Here we pull in all various kernel image types which we support.
115#
116# In case you're wondering why kernel.bbclass inherits the other image
117# types instead of the other way around, the reason for that is to
118# maintain compatibility with various currently existing meta-layers.
119# By pulling in the various kernel image types here, we retain the
120# original behavior of kernel.bbclass, so no meta-layers should get
121# broken.
122#
123# KERNEL_CLASSES by default pulls in kernel-uimage.bbclass, since this
124# used to be the default behavior when only uImage was supported. This
125# variable can be appended by users who implement support for new kernel
126# image types.
127
128KERNEL_CLASSES ?= " kernel-uimage "
129inherit ${KERNEL_CLASSES}
130
131# Old style kernels may set ${S} = ${WORKDIR}/git for example
132# We need to move these over to STAGING_KERNEL_DIR. We can't just
133# create the symlink in advance as the git fetcher can't cope with
134# the symlink.
135do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
136do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
Brad Bishopc342db32019-05-15 21:57:59 -0400137python do_symlink_kernsrc () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500138 s = d.getVar("S")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500139 if s[-1] == '/':
140 # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as directory name and fail
141 s=s[:-1]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500142 kernsrc = d.getVar("STAGING_KERNEL_DIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500143 if s != kernsrc:
144 bb.utils.mkdirhier(kernsrc)
145 bb.utils.remove(kernsrc, recurse=True)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500146 if d.getVar("EXTERNALSRC"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500147 # With EXTERNALSRC S will not be wiped so we can symlink to it
148 os.symlink(s, kernsrc)
149 else:
150 import shutil
151 shutil.move(s, kernsrc)
152 os.symlink(kernsrc, s)
153}
Brad Bishopc342db32019-05-15 21:57:59 -0400154addtask symlink_kernsrc before do_configure after do_unpack
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500155
156inherit kernel-arch deploy
157
Brad Bishop316dfdd2018-06-25 12:45:53 -0400158PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
159PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-image-.*"
160PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-firmware-.*"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500161
162export OS = "${TARGET_OS}"
163export CROSS_COMPILE = "${TARGET_PREFIX}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400164export KBUILD_BUILD_VERSION = "1"
Brad Bishop977dc1a2019-02-06 16:01:43 -0500165export KBUILD_BUILD_USER ?= "oe-user"
166export KBUILD_BUILD_HOST ?= "oe-host"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500168KERNEL_RELEASE ?= "${KERNEL_VERSION}"
169
He Zhefe76b1e2016-05-25 04:47:16 -0400170# The directory where built kernel lies in the kernel tree
171KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800172KERNEL_IMAGEDEST ?= "boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500173
174#
175# configuration
176#
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500177export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE") or "ttyS0"}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178
179KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}"
180
181KERNEL_LOCALVERSION ?= ""
182
183# kernels are generally machine specific
184PACKAGE_ARCH = "${MACHINE_ARCH}"
185
186# U-Boot support
187UBOOT_ENTRYPOINT ?= "20008000"
188UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}"
189
190# Some Linux kernel configurations need additional parameters on the command line
191KERNEL_EXTRA_ARGS ?= ""
192
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500193EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500194KERNEL_ALT_IMAGETYPE ??= ""
195
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196copy_initramfs() {
197 echo "Copying initramfs into ./usr ..."
198 # In case the directory is not created yet from the first pass compile:
199 mkdir -p ${B}/usr
200 # Find and use the first initramfs image archive type we find
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500201 rm -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500202 for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz; do
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500203 if [ -e "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" ]; then
204 cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500205 case $img in
206 *gz)
207 echo "gzip decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500208 gunzip -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500209 break
210 ;;
211 *lz4)
212 echo "lz4 decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500213 lz4 -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500214 break
215 ;;
216 *lzo)
217 echo "lzo decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500218 lzop -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500219 break
220 ;;
221 *lzma)
222 echo "lzma decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500223 lzma -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500224 break
225 ;;
226 *xz)
227 echo "xz decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500228 xz -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500229 break
230 ;;
231 esac
Brad Bishopf8caae32019-03-25 13:13:56 -0400232 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500233 fi
234 done
Brad Bishopf8caae32019-03-25 13:13:56 -0400235 # Verify that the above loop found a initramfs, fail otherwise
236 [ -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 -0500237}
238
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500239do_bundle_initramfs () {
240 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
241 echo "Creating a kernel image with a bundled initramfs..."
242 copy_initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400243 # Backing up kernel image relies on its type(regular file or symbolic link)
244 tmp_path=""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800245 for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
246 if [ -h ${KERNEL_OUTPUT_DIR}/$imageType ] ; then
247 linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$imageType`
248 realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$imageType`
He Zhefe76b1e2016-05-25 04:47:16 -0400249 mv -f $realpath $realpath.bak
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800250 tmp_path=$tmp_path" "$imageType"#"$linkpath"#"$realpath
251 elif [ -f ${KERNEL_OUTPUT_DIR}/$imageType ]; then
252 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.bak
253 tmp_path=$tmp_path" "$imageType"##"
He Zhefe76b1e2016-05-25 04:47:16 -0400254 fi
255 done
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500256 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500257 kernel_do_compile
He Zhefe76b1e2016-05-25 04:47:16 -0400258 # Restoring kernel image
259 for tp in $tmp_path ; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800260 imageType=`echo $tp|cut -d "#" -f 1`
He Zhefe76b1e2016-05-25 04:47:16 -0400261 linkpath=`echo $tp|cut -d "#" -f 2`
262 realpath=`echo $tp|cut -d "#" -f 3`
263 if [ -n "$realpath" ]; then
264 mv -f $realpath $realpath.initramfs
265 mv -f $realpath.bak $realpath
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800266 ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$imageType.initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400267 else
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800268 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.initramfs
269 mv -f ${KERNEL_OUTPUT_DIR}/$imageType.bak ${KERNEL_OUTPUT_DIR}/$imageType
He Zhefe76b1e2016-05-25 04:47:16 -0400270 fi
271 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500272 fi
273}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600274do_bundle_initramfs[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500275
276python do_devshell_prepend () {
277 os.environ["LDFLAGS"] = ''
278}
279
280addtask bundle_initramfs after do_install before do_deploy
281
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500282get_cc_option () {
283 # Check if KERNEL_CC supports the option "file-prefix-map".
284 # This option allows us to build images with __FILE__ values that do not
285 # contain the host build path.
286 if ${KERNEL_CC} -Q --help=joined | grep -q "\-ffile-prefix-map=<old=new>"; then
287 echo "-ffile-prefix-map=${S}=/kernel-source/"
288 fi
289}
290
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500291kernel_do_compile() {
292 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
Brad Bishop316dfdd2018-06-25 12:45:53 -0400293 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500294 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
295 # be set....
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800296 if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
Andrew Geissler82c905d2020-04-13 13:39:40 -0500297 # The source directory is not necessarily a git repository, so we
298 # specify the git-dir to ensure that git does not query a
299 # repository in any parent directory.
300 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 -0500301 fi
302
303 ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
304 export KBUILD_BUILD_TIMESTAMP="$ts"
305 export KCONFIG_NOTIMESTAMP=1
306 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
307 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500308 # The $use_alternate_initrd is only set from
309 # do_bundle_initramfs() This variable is specifically for the
310 # case where we are making a second pass at the kernel
311 # compilation and we want to force the kernel build to use a
312 # different initramfs image. The way to do that in the kernel
313 # is to specify:
314 # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio
315 if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then
316 # The old style way of copying an prebuilt image and building it
317 # is turned on via INTIRAMFS_TASK != ""
318 copy_initramfs
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500319 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500320 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500321 cc_extra=$(get_cc_option)
He Zhefe76b1e2016-05-25 04:47:16 -0400322 for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500323 oe_runmake ${typeformake} CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd
He Zhefe76b1e2016-05-25 04:47:16 -0400324 done
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500325 # vmlinux.gz is not built by kernel
326 if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then
327 mkdir -p "${KERNEL_OUTPUT_DIR}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500328 gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500329 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500330}
331
332do_compile_kernelmodules() {
333 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
334 if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500335 cc_extra=$(get_cc_option)
336 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 -0500337
338 # Module.symvers gets updated during the
339 # building of the kernel modules. We need to
340 # update this in the shared workdir since some
341 # external kernel modules has a dependency on
342 # other kernel modules and will look at this
343 # file to do symbol lookups
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600344 cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500345 else
346 bbnote "no modules to compile"
347 fi
348}
349addtask compile_kernelmodules after do_compile before do_strip
350
351kernel_do_install() {
352 #
353 # First install the modules
354 #
355 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
356 if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500357 oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
358 rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
359 rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500360 # If the kernel/ directory is empty remove it to prevent QA issues
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500361 rmdir --ignore-fail-on-non-empty "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500362 else
363 bbnote "no modules to install"
364 fi
365
366 #
367 # Install various kernel output (zImage, map file, config, module support files)
368 #
369 install -d ${D}/${KERNEL_IMAGEDEST}
370 install -d ${D}/boot
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800371 for imageType in ${KERNEL_IMAGETYPES} ; do
372 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} ${D}/${KERNEL_IMAGEDEST}/${imageType}-${KERNEL_VERSION}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400373 if [ "${KERNEL_PACKAGE_NAME}" = "kernel" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800374 ln -sf ${imageType}-${KERNEL_VERSION} ${D}/${KERNEL_IMAGEDEST}/${imageType}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400375 fi
He Zhefe76b1e2016-05-25 04:47:16 -0400376 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500377 install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION}
378 install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION}
379 install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION}
380 [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION}
381 install -d ${D}${sysconfdir}/modules-load.d
382 install -d ${D}${sysconfdir}/modprobe.d
383}
384do_install[prefuncs] += "package_get_auto_pr"
385
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600386# Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile
387do_kernel_version_sanity_check() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500388 if [ "x${KERNEL_VERSION_SANITY_SKIP}" = "x1" ]; then
389 exit 0
390 fi
391
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600392 # The Makefile determines the kernel version shown at runtime
393 # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile
394 VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//)
395 PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
396 SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
397 EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//)
398
399 # Build a string for regex and a plain version string
400 reg="^${VERSION}\.${PATCHLEVEL}"
401 vers="${VERSION}.${PATCHLEVEL}"
402 if [ -n "${SUBLEVEL}" ]; then
403 # Ignoring a SUBLEVEL of zero is fine
404 if [ "${SUBLEVEL}" = "0" ]; then
405 reg="${reg}(\.${SUBLEVEL})?"
406 else
407 reg="${reg}\.${SUBLEVEL}"
408 vers="${vers}.${SUBLEVEL}"
409 fi
410 fi
411 vers="${vers}${EXTRAVERSION}"
412 reg="${reg}${EXTRAVERSION}"
413
414 if [ -z `echo ${PV} | grep -E "${reg}"` ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500415 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 -0600416 fi
417 exit 0
418}
419
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500420addtask shared_workdir after do_compile before do_compile_kernelmodules
421addtask shared_workdir_setscene
422
423do_shared_workdir_setscene () {
424 exit 1
425}
426
427emit_depmod_pkgdata() {
428 # Stash data for depmod
Brad Bishop316dfdd2018-06-25 12:45:53 -0400429 install -d ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/
430 echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/${KERNEL_PACKAGE_NAME}-abiversion
431 cp ${B}/System.map ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/System.map-${KERNEL_VERSION}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500432}
433
434PACKAGEFUNCS += "emit_depmod_pkgdata"
435
Brad Bishop316dfdd2018-06-25 12:45:53 -0400436do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500437do_shared_workdir () {
438 cd ${B}
439
440 kerneldir=${STAGING_KERNEL_BUILDDIR}
441 install -d $kerneldir
442
443 #
444 # Store the kernel version in sysroots for module-base.bbclass
445 #
446
Brad Bishop316dfdd2018-06-25 12:45:53 -0400447 echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500448
449 # Copy files required for module builds
450 cp System.map $kerneldir/System.map-${KERNEL_VERSION}
451 cp Module.symvers $kerneldir/
452 cp .config $kerneldir/
453 mkdir -p $kerneldir/include/config
454 cp include/config/kernel.release $kerneldir/include/config/kernel.release
Brad Bishop08902b02019-08-20 09:16:51 -0400455 if [ -e certs/signing_key.x509 ]; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600456 # The signing_key.* files are stored in the certs/ dir in
457 # newer Linux kernels
458 mkdir -p $kerneldir/certs
459 cp certs/signing_key.* $kerneldir/certs/
460 elif [ -e signing_key.priv ]; then
461 cp signing_key.* $kerneldir/
462 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500463
464 # We can also copy over all the generated files and avoid special cases
465 # like version.h, but we've opted to keep this small until file creep starts
466 # to happen
467 if [ -e include/linux/version.h ]; then
468 mkdir -p $kerneldir/include/linux
469 cp include/linux/version.h $kerneldir/include/linux/version.h
470 fi
471
472 # As of Linux kernel version 3.0.1, the clean target removes
473 # arch/powerpc/lib/crtsavres.o which is present in
474 # KBUILD_LDFLAGS_MODULE, making it required to build external modules.
475 if [ ${ARCH} = "powerpc" ]; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400476 if [ -e arch/powerpc/lib/crtsavres.o ]; then
477 mkdir -p $kerneldir/arch/powerpc/lib/
478 cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o
479 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500480 fi
481
482 if [ -d include/generated ]; then
483 mkdir -p $kerneldir/include/generated/
484 cp -fR include/generated/* $kerneldir/include/generated/
485 fi
486
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500487 if [ -d arch/${ARCH}/include/generated ]; then
488 mkdir -p $kerneldir/arch/${ARCH}/include/generated/
489 cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500490 fi
Brad Bishop19323692019-04-05 15:28:33 -0400491
492 if (grep -q -i -e '^CONFIG_UNWINDER_ORC=y$' $kerneldir/.config); then
493 # With CONFIG_UNWINDER_ORC (the default in 4.14), objtool is required for
494 # out-of-tree modules to be able to generate object files.
495 if [ -x tools/objtool/objtool ]; then
496 mkdir -p ${kerneldir}/tools/objtool
497 cp tools/objtool/objtool ${kerneldir}/tools/objtool/
498 fi
499 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500500}
501
502# We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware
503sysroot_stage_all () {
504 :
505}
506
Andrew Geissler82c905d2020-04-13 13:39:40 -0500507KERNEL_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 -0500508
He Zhefe76b1e2016-05-25 04:47:16 -0400509python check_oldest_kernel() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500510 oldest_kernel = d.getVar('OLDEST_KERNEL')
511 kernel_version = d.getVar('KERNEL_VERSION')
512 tclibc = d.getVar('TCLIBC')
He Zhefe76b1e2016-05-25 04:47:16 -0400513 if tclibc == 'glibc':
514 kernel_version = kernel_version.split('-', 1)[0]
515 if oldest_kernel and kernel_version:
516 if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500517 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 -0400518}
519
520check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION"
521do_configure[prefuncs] += "check_oldest_kernel"
522
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500523kernel_do_configure() {
524 # fixes extra + in /lib/modules/2.6.37+
525 # $ scripts/setlocalversion . => +
526 # $ make kernelversion => 2.6.37
527 # $ make kernelrelease => 2.6.37+
528 touch ${B}/.scmversion ${S}/.scmversion
529
530 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
531 mv "${S}/.config" "${B}/.config"
532 fi
533
534 # Copy defconfig to .config if .config does not exist. This allows
535 # recipes to manage the .config themselves in do_configure_prepend().
536 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
537 cp "${WORKDIR}/defconfig" "${B}/.config"
538 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500539
540 ${KERNEL_CONFIG_COMMAND}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500541}
542
543do_savedefconfig() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600544 bbplain "Saving defconfig to:\n${B}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500545 oe_runmake -C ${B} savedefconfig
546}
547do_savedefconfig[nostamp] = "1"
548addtask savedefconfig after do_configure
549
550inherit cml1
551
Brad Bishop316dfdd2018-06-25 12:45:53 -0400552KCONFIG_CONFIG_COMMAND_append = " HOSTLDFLAGS='${BUILD_LDFLAGS}'"
553
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500554EXPORT_FUNCTIONS do_compile do_install do_configure
555
556# kernel-base becomes kernel-${KERNEL_VERSION}
He Zhefe76b1e2016-05-25 04:47:16 -0400557# kernel-image becomes kernel-image-${KERNEL_VERSION}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400558PACKAGES = "${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 -0500559FILES_${PN} = ""
Brad Bishop15ae2502019-06-18 21:44:24 -0400560FILES_${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 -0400561FILES_${KERNEL_PACKAGE_NAME}-image = ""
562FILES_${KERNEL_PACKAGE_NAME}-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
563FILES_${KERNEL_PACKAGE_NAME}-vmlinux = "/boot/vmlinux-${KERNEL_VERSION_NAME}"
564FILES_${KERNEL_PACKAGE_NAME}-modules = ""
565RDEPENDS_${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base"
He Zhefe76b1e2016-05-25 04:47:16 -0400566# Allow machines to override this dependency if kernel image files are
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500567# not wanted in images as standard
Brad Bishop316dfdd2018-06-25 12:45:53 -0400568RDEPENDS_${KERNEL_PACKAGE_NAME}-base ?= "${KERNEL_PACKAGE_NAME}-image"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500569PKG_${KERNEL_PACKAGE_NAME}-image = "${KERNEL_PACKAGE_NAME}-image-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400570RDEPENDS_${KERNEL_PACKAGE_NAME}-image += "${@oe.utils.conditional('KERNEL_IMAGETYPE', 'vmlinux', '${KERNEL_PACKAGE_NAME}-vmlinux', '', d)}"
Andrew Geissler82c905d2020-04-13 13:39:40 -0500571PKG_${KERNEL_PACKAGE_NAME}-base = "${KERNEL_PACKAGE_NAME}-${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400572RPROVIDES_${KERNEL_PACKAGE_NAME}-base += "${KERNEL_PACKAGE_NAME}-${KERNEL_VERSION}"
573ALLOW_EMPTY_${KERNEL_PACKAGE_NAME} = "1"
574ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-base = "1"
575ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-image = "1"
576ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-modules = "1"
577DESCRIPTION_${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta package"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500578
Brad Bishop316dfdd2018-06-25 12:45:53 -0400579pkg_postinst_${KERNEL_PACKAGE_NAME}-base () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500580 if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
581 mkdir -p $D/lib/modules/${KERNEL_VERSION}
582 fi
583 if [ -n "$D" ]; then
584 depmodwrapper -a -b $D ${KERNEL_VERSION}
585 else
586 depmod -a ${KERNEL_VERSION}
587 fi
588}
589
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500590PACKAGESPLITFUNCS_prepend = "split_kernel_packages "
591
592python split_kernel_packages () {
Brad Bishop19323692019-04-05 15:28:33 -0400593 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 -0500594}
595
596# Many scripts want to look in arch/$arch/boot for the bootable
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600597# image. This poses a problem for vmlinux and vmlinuz based
598# booting. This task arranges to have vmlinux and vmlinuz appear
599# in the normalized directory location.
600do_kernel_link_images() {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500601 if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
602 mkdir ${B}/arch/${ARCH}/boot
603 fi
604 cd ${B}/arch/${ARCH}/boot
605 ln -sf ../../../vmlinux
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600606 if [ -f ../../../vmlinuz ]; then
607 ln -sf ../../../vmlinuz
608 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500609 if [ -f ../../../vmlinuz.bin ]; then
610 ln -sf ../../../vmlinuz.bin
611 fi
Andrew Geissler82c905d2020-04-13 13:39:40 -0500612 if [ -f ../../../vmlinux.64 ]; then
613 ln -sf ../../../vmlinux.64
614 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500615}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500616addtask kernel_link_images after do_compile before do_strip
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500617
618do_strip() {
619 if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then
He Zhefe76b1e2016-05-25 04:47:16 -0400620 if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then
621 bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500622 return
623 fi
624
625 cd ${B}
He Zhefe76b1e2016-05-25 04:47:16 -0400626 headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500627 grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \
628 sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \
629 gawk '{print $1}'`
630
631 for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500632 if ! (echo "$headers" | grep -q "^$str$"); then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500633 bbwarn "Section not found: $str";
634 fi
635
He Zhefe76b1e2016-05-25 04:47:16 -0400636 "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500637 }; done
638
639 bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \
640 "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}"
641 fi;
642}
643do_strip[dirs] = "${B}"
644
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500645addtask strip before do_sizecheck after do_kernel_link_images
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500646
647# Support checking the kernel size since some kernels need to reside in partitions
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500648# with a fixed length or there is a limit in transferring the kernel to memory.
649# If more than one image type is enabled, warn on any that don't fit but only fail
650# if none fit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500651do_sizecheck() {
652 if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then
653 invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'`
654 if [ -n "$invalid" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500655 die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integer (The unit is Kbytes)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500656 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500657 at_least_one_fits=
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800658 for imageType in ${KERNEL_IMAGETYPES} ; do
659 size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$imageType | awk '{print $1}'`
He Zhefe76b1e2016-05-25 04:47:16 -0400660 if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800661 bbwarn "This kernel $imageType (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device."
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500662 else
663 at_least_one_fits=y
He Zhefe76b1e2016-05-25 04:47:16 -0400664 fi
665 done
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500666 if [ -z "$at_least_one_fits" ]; then
667 die "All kernel images are too big for your device. Please reduce the size of the kernel by making more of it modular."
668 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500669 fi
670}
671do_sizecheck[dirs] = "${B}"
672
673addtask sizecheck before do_install after do_strip
674
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800675inherit kernel-artifact-names
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500676
677kernel_do_deploy() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400678 deployDir="${DEPLOYDIR}"
679 if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then
680 deployDir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}"
681 mkdir "$deployDir"
682 fi
683
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800684 for imageType in ${KERNEL_IMAGETYPES} ; do
685 base_name=${imageType}-${KERNEL_IMAGE_NAME}
686 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} $deployDir/${base_name}.bin
687 symlink_name=${imageType}-${KERNEL_IMAGE_LINK_NAME}
688 ln -sf ${base_name}.bin $deployDir/${symlink_name}.bin
689 ln -sf ${base_name}.bin $deployDir/${imageType}
He Zhefe76b1e2016-05-25 04:47:16 -0400690 done
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800691
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500692 if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800693 mkdir -p ${D}${root_prefix}/lib
Andrew Geisslerc182c622020-05-15 14:13:32 -0500694 if [ -n "${SOURCE_DATE_EPOCH}" ]; then
695 TAR_ARGS="--sort=name --clamp-mtime --mtime=@${SOURCE_DATE_EPOCH}"
696 else
697 TAR_ARGS=""
698 fi
699 tar $TAR_ARGS -cv -C ${D}${root_prefix} lib | gzip -9n > $deployDir/modules-${MODULE_TARBALL_NAME}.tgz
700
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800701 ln -sf modules-${MODULE_TARBALL_NAME}.tgz $deployDir/modules-${MODULE_TARBALL_LINK_NAME}.tgz
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500702 fi
703
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800704 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
705 for imageType in ${KERNEL_IMAGETYPES} ; do
Brad Bishop977dc1a2019-02-06 16:01:43 -0500706 if [ "$imageType" = "fitImage" ] ; then
707 continue
708 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800709 initramfs_base_name=${imageType}-${INITRAMFS_NAME}
710 initramfs_symlink_name=${imageType}-${INITRAMFS_LINK_NAME}
711 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType}.initramfs $deployDir/${initramfs_base_name}.bin
Brad Bishop316dfdd2018-06-25 12:45:53 -0400712 ln -sf ${initramfs_base_name}.bin $deployDir/${initramfs_symlink_name}.bin
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800713 done
714 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500715}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500716do_deploy[cleandirs] = "${DEPLOYDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500717do_deploy[dirs] = "${DEPLOYDIR} ${B}"
718do_deploy[prefuncs] += "package_get_auto_pr"
719
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500720addtask deploy after do_populate_sysroot do_packagedata
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500721
722EXPORT_FUNCTIONS do_deploy
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500723
724# Add using Device Tree support
725inherit kernel-devicetree