blob: a60e15b578143786fbb01b0b47312d62da4af2a9 [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 Bishop393846f2019-05-20 12:24:11 -040099 image_bundle = d.getVar('INITRAMFS_IMAGE_BUNDLE')
100 if image and bb.utils.to_boolean(image_bundle, False):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500101 d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102
103 # NOTE: setting INITRAMFS_TASK is for backward compatibility
104 # The preferred method is to set INITRAMFS_IMAGE, because
105 # this INITRAMFS_TASK has circular dependency problems
106 # if the initramfs requires kernel modules
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500107 image_task = d.getVar('INITRAMFS_TASK')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500108 if image_task:
109 d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}')
110}
111
112# Here we pull in all various kernel image types which we support.
113#
114# In case you're wondering why kernel.bbclass inherits the other image
115# types instead of the other way around, the reason for that is to
116# maintain compatibility with various currently existing meta-layers.
117# By pulling in the various kernel image types here, we retain the
118# original behavior of kernel.bbclass, so no meta-layers should get
119# broken.
120#
121# KERNEL_CLASSES by default pulls in kernel-uimage.bbclass, since this
122# used to be the default behavior when only uImage was supported. This
123# variable can be appended by users who implement support for new kernel
124# image types.
125
126KERNEL_CLASSES ?= " kernel-uimage "
127inherit ${KERNEL_CLASSES}
128
129# Old style kernels may set ${S} = ${WORKDIR}/git for example
130# We need to move these over to STAGING_KERNEL_DIR. We can't just
131# create the symlink in advance as the git fetcher can't cope with
132# the symlink.
133do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
134do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
Brad Bishopc342db32019-05-15 21:57:59 -0400135python do_symlink_kernsrc () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500136 s = d.getVar("S")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500137 if s[-1] == '/':
138 # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as directory name and fail
139 s=s[:-1]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500140 kernsrc = d.getVar("STAGING_KERNEL_DIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500141 if s != kernsrc:
142 bb.utils.mkdirhier(kernsrc)
143 bb.utils.remove(kernsrc, recurse=True)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500144 if d.getVar("EXTERNALSRC"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500145 # With EXTERNALSRC S will not be wiped so we can symlink to it
146 os.symlink(s, kernsrc)
147 else:
148 import shutil
149 shutil.move(s, kernsrc)
150 os.symlink(kernsrc, s)
151}
Brad Bishopc342db32019-05-15 21:57:59 -0400152addtask symlink_kernsrc before do_configure after do_unpack
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500153
154inherit kernel-arch deploy
155
Brad Bishop316dfdd2018-06-25 12:45:53 -0400156PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
157PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-image-.*"
158PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-firmware-.*"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500159
160export OS = "${TARGET_OS}"
161export CROSS_COMPILE = "${TARGET_PREFIX}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400162export KBUILD_BUILD_VERSION = "1"
Brad Bishop977dc1a2019-02-06 16:01:43 -0500163export KBUILD_BUILD_USER ?= "oe-user"
164export KBUILD_BUILD_HOST ?= "oe-host"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500166KERNEL_RELEASE ?= "${KERNEL_VERSION}"
167
He Zhefe76b1e2016-05-25 04:47:16 -0400168# The directory where built kernel lies in the kernel tree
169KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800170KERNEL_IMAGEDEST ?= "boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500171
172#
173# configuration
174#
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500175export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE") or "ttyS0"}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176
177KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}"
178
179KERNEL_LOCALVERSION ?= ""
180
181# kernels are generally machine specific
182PACKAGE_ARCH = "${MACHINE_ARCH}"
183
184# U-Boot support
185UBOOT_ENTRYPOINT ?= "20008000"
186UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}"
187
188# Some Linux kernel configurations need additional parameters on the command line
189KERNEL_EXTRA_ARGS ?= ""
190
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500191EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500192KERNEL_ALT_IMAGETYPE ??= ""
193
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500194copy_initramfs() {
195 echo "Copying initramfs into ./usr ..."
196 # In case the directory is not created yet from the first pass compile:
197 mkdir -p ${B}/usr
198 # Find and use the first initramfs image archive type we find
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500199 rm -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500200 for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz; do
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500201 if [ -e "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" ]; then
202 cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500203 case $img in
204 *gz)
205 echo "gzip decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500206 gunzip -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500207 break
208 ;;
209 *lz4)
210 echo "lz4 decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500211 lz4 -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500212 break
213 ;;
214 *lzo)
215 echo "lzo decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500216 lzop -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500217 break
218 ;;
219 *lzma)
220 echo "lzma decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500221 lzma -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500222 break
223 ;;
224 *xz)
225 echo "xz decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500226 xz -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500227 break
228 ;;
229 esac
Brad Bishopf8caae32019-03-25 13:13:56 -0400230 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500231 fi
232 done
Brad Bishopf8caae32019-03-25 13:13:56 -0400233 # Verify that the above loop found a initramfs, fail otherwise
234 [ -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 -0500235}
236
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237do_bundle_initramfs () {
238 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
239 echo "Creating a kernel image with a bundled initramfs..."
240 copy_initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400241 # Backing up kernel image relies on its type(regular file or symbolic link)
242 tmp_path=""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800243 for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
244 if [ -h ${KERNEL_OUTPUT_DIR}/$imageType ] ; then
245 linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$imageType`
246 realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$imageType`
He Zhefe76b1e2016-05-25 04:47:16 -0400247 mv -f $realpath $realpath.bak
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800248 tmp_path=$tmp_path" "$imageType"#"$linkpath"#"$realpath
249 elif [ -f ${KERNEL_OUTPUT_DIR}/$imageType ]; then
250 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.bak
251 tmp_path=$tmp_path" "$imageType"##"
He Zhefe76b1e2016-05-25 04:47:16 -0400252 fi
253 done
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500254 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500255 kernel_do_compile
He Zhefe76b1e2016-05-25 04:47:16 -0400256 # Restoring kernel image
257 for tp in $tmp_path ; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800258 imageType=`echo $tp|cut -d "#" -f 1`
He Zhefe76b1e2016-05-25 04:47:16 -0400259 linkpath=`echo $tp|cut -d "#" -f 2`
260 realpath=`echo $tp|cut -d "#" -f 3`
261 if [ -n "$realpath" ]; then
262 mv -f $realpath $realpath.initramfs
263 mv -f $realpath.bak $realpath
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800264 ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$imageType.initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400265 else
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800266 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.initramfs
267 mv -f ${KERNEL_OUTPUT_DIR}/$imageType.bak ${KERNEL_OUTPUT_DIR}/$imageType
He Zhefe76b1e2016-05-25 04:47:16 -0400268 fi
269 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500270 fi
271}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600272do_bundle_initramfs[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500273
274python do_devshell_prepend () {
275 os.environ["LDFLAGS"] = ''
276}
277
278addtask bundle_initramfs after do_install before do_deploy
279
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500280get_cc_option () {
281 # Check if KERNEL_CC supports the option "file-prefix-map".
282 # This option allows us to build images with __FILE__ values that do not
283 # contain the host build path.
284 if ${KERNEL_CC} -Q --help=joined | grep -q "\-ffile-prefix-map=<old=new>"; then
285 echo "-ffile-prefix-map=${S}=/kernel-source/"
286 fi
287}
288
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500289kernel_do_compile() {
290 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
Brad Bishop316dfdd2018-06-25 12:45:53 -0400291 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500292 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
293 # be set....
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800294 if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500295 olddir=`pwd`
296 cd ${S}
297 SOURCE_DATE_EPOCH=`git log -1 --pretty=%ct`
298 # git repo not guaranteed, so fall back to REPRODUCIBLE_TIMESTAMP_ROOTFS
299 if [ $? -ne 0 ]; then
300 SOURCE_DATE_EPOCH=${REPRODUCIBLE_TIMESTAMP_ROOTFS}
301 fi
302 cd $olddir
303 fi
304
305 ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
306 export KBUILD_BUILD_TIMESTAMP="$ts"
307 export KCONFIG_NOTIMESTAMP=1
308 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
309 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500310 # The $use_alternate_initrd is only set from
311 # do_bundle_initramfs() This variable is specifically for the
312 # case where we are making a second pass at the kernel
313 # compilation and we want to force the kernel build to use a
314 # different initramfs image. The way to do that in the kernel
315 # is to specify:
316 # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio
317 if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then
318 # The old style way of copying an prebuilt image and building it
319 # is turned on via INTIRAMFS_TASK != ""
320 copy_initramfs
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500321 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500322 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500323 cc_extra=$(get_cc_option)
He Zhefe76b1e2016-05-25 04:47:16 -0400324 for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500325 oe_runmake ${typeformake} CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd
He Zhefe76b1e2016-05-25 04:47:16 -0400326 done
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500327 # vmlinux.gz is not built by kernel
328 if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then
329 mkdir -p "${KERNEL_OUTPUT_DIR}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500330 gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500331 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500332}
333
334do_compile_kernelmodules() {
335 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
336 if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500337 cc_extra=$(get_cc_option)
338 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 -0500339
340 # Module.symvers gets updated during the
341 # building of the kernel modules. We need to
342 # update this in the shared workdir since some
343 # external kernel modules has a dependency on
344 # other kernel modules and will look at this
345 # file to do symbol lookups
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600346 cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500347 else
348 bbnote "no modules to compile"
349 fi
350}
351addtask compile_kernelmodules after do_compile before do_strip
352
353kernel_do_install() {
354 #
355 # First install the modules
356 #
357 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
358 if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500359 oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
360 rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
361 rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500362 # If the kernel/ directory is empty remove it to prevent QA issues
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500363 rmdir --ignore-fail-on-non-empty "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500364 else
365 bbnote "no modules to install"
366 fi
367
368 #
369 # Install various kernel output (zImage, map file, config, module support files)
370 #
371 install -d ${D}/${KERNEL_IMAGEDEST}
372 install -d ${D}/boot
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800373 for imageType in ${KERNEL_IMAGETYPES} ; do
374 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} ${D}/${KERNEL_IMAGEDEST}/${imageType}-${KERNEL_VERSION}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400375 if [ "${KERNEL_PACKAGE_NAME}" = "kernel" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800376 ln -sf ${imageType}-${KERNEL_VERSION} ${D}/${KERNEL_IMAGEDEST}/${imageType}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400377 fi
He Zhefe76b1e2016-05-25 04:47:16 -0400378 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500379 install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION}
380 install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION}
381 install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION}
382 [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION}
383 install -d ${D}${sysconfdir}/modules-load.d
384 install -d ${D}${sysconfdir}/modprobe.d
385}
386do_install[prefuncs] += "package_get_auto_pr"
387
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600388# Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile
389do_kernel_version_sanity_check() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500390 if [ "x${KERNEL_VERSION_SANITY_SKIP}" = "x1" ]; then
391 exit 0
392 fi
393
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600394 # The Makefile determines the kernel version shown at runtime
395 # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile
396 VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//)
397 PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
398 SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
399 EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//)
400
401 # Build a string for regex and a plain version string
402 reg="^${VERSION}\.${PATCHLEVEL}"
403 vers="${VERSION}.${PATCHLEVEL}"
404 if [ -n "${SUBLEVEL}" ]; then
405 # Ignoring a SUBLEVEL of zero is fine
406 if [ "${SUBLEVEL}" = "0" ]; then
407 reg="${reg}(\.${SUBLEVEL})?"
408 else
409 reg="${reg}\.${SUBLEVEL}"
410 vers="${vers}.${SUBLEVEL}"
411 fi
412 fi
413 vers="${vers}${EXTRAVERSION}"
414 reg="${reg}${EXTRAVERSION}"
415
416 if [ -z `echo ${PV} | grep -E "${reg}"` ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500417 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 -0600418 fi
419 exit 0
420}
421
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500422addtask shared_workdir after do_compile before do_compile_kernelmodules
423addtask shared_workdir_setscene
424
425do_shared_workdir_setscene () {
426 exit 1
427}
428
429emit_depmod_pkgdata() {
430 # Stash data for depmod
Brad Bishop316dfdd2018-06-25 12:45:53 -0400431 install -d ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/
432 echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/${KERNEL_PACKAGE_NAME}-abiversion
433 cp ${B}/System.map ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/System.map-${KERNEL_VERSION}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500434}
435
436PACKAGEFUNCS += "emit_depmod_pkgdata"
437
Brad Bishop316dfdd2018-06-25 12:45:53 -0400438do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500439do_shared_workdir () {
440 cd ${B}
441
442 kerneldir=${STAGING_KERNEL_BUILDDIR}
443 install -d $kerneldir
444
445 #
446 # Store the kernel version in sysroots for module-base.bbclass
447 #
448
Brad Bishop316dfdd2018-06-25 12:45:53 -0400449 echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500450
451 # Copy files required for module builds
452 cp System.map $kerneldir/System.map-${KERNEL_VERSION}
453 cp Module.symvers $kerneldir/
454 cp .config $kerneldir/
455 mkdir -p $kerneldir/include/config
456 cp include/config/kernel.release $kerneldir/include/config/kernel.release
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600457 if [ -e certs/signing_key.pem ]; then
458 # The signing_key.* files are stored in the certs/ dir in
459 # newer Linux kernels
460 mkdir -p $kerneldir/certs
461 cp certs/signing_key.* $kerneldir/certs/
462 elif [ -e signing_key.priv ]; then
463 cp signing_key.* $kerneldir/
464 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500465
466 # We can also copy over all the generated files and avoid special cases
467 # like version.h, but we've opted to keep this small until file creep starts
468 # to happen
469 if [ -e include/linux/version.h ]; then
470 mkdir -p $kerneldir/include/linux
471 cp include/linux/version.h $kerneldir/include/linux/version.h
472 fi
473
474 # As of Linux kernel version 3.0.1, the clean target removes
475 # arch/powerpc/lib/crtsavres.o which is present in
476 # KBUILD_LDFLAGS_MODULE, making it required to build external modules.
477 if [ ${ARCH} = "powerpc" ]; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400478 if [ -e arch/powerpc/lib/crtsavres.o ]; then
479 mkdir -p $kerneldir/arch/powerpc/lib/
480 cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o
481 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500482 fi
483
484 if [ -d include/generated ]; then
485 mkdir -p $kerneldir/include/generated/
486 cp -fR include/generated/* $kerneldir/include/generated/
487 fi
488
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500489 if [ -d arch/${ARCH}/include/generated ]; then
490 mkdir -p $kerneldir/arch/${ARCH}/include/generated/
491 cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500492 fi
Brad Bishop19323692019-04-05 15:28:33 -0400493
494 if (grep -q -i -e '^CONFIG_UNWINDER_ORC=y$' $kerneldir/.config); then
495 # With CONFIG_UNWINDER_ORC (the default in 4.14), objtool is required for
496 # out-of-tree modules to be able to generate object files.
497 if [ -x tools/objtool/objtool ]; then
498 mkdir -p ${kerneldir}/tools/objtool
499 cp tools/objtool/objtool ${kerneldir}/tools/objtool/
500 fi
501 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500502}
503
504# We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware
505sysroot_stage_all () {
506 :
507}
508
Brad Bishop977dc1a2019-02-06 16:01:43 -0500509KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} CC="${KERNEL_CC}" O=${B} olddefconfig || oe_runmake -C ${S} O=${B} CC="${KERNEL_CC}" oldnoconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500510
He Zhefe76b1e2016-05-25 04:47:16 -0400511python check_oldest_kernel() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500512 oldest_kernel = d.getVar('OLDEST_KERNEL')
513 kernel_version = d.getVar('KERNEL_VERSION')
514 tclibc = d.getVar('TCLIBC')
He Zhefe76b1e2016-05-25 04:47:16 -0400515 if tclibc == 'glibc':
516 kernel_version = kernel_version.split('-', 1)[0]
517 if oldest_kernel and kernel_version:
518 if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500519 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 -0400520}
521
522check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION"
523do_configure[prefuncs] += "check_oldest_kernel"
524
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500525kernel_do_configure() {
526 # fixes extra + in /lib/modules/2.6.37+
527 # $ scripts/setlocalversion . => +
528 # $ make kernelversion => 2.6.37
529 # $ make kernelrelease => 2.6.37+
530 touch ${B}/.scmversion ${S}/.scmversion
531
532 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
533 mv "${S}/.config" "${B}/.config"
534 fi
535
536 # Copy defconfig to .config if .config does not exist. This allows
537 # recipes to manage the .config themselves in do_configure_prepend().
538 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
539 cp "${WORKDIR}/defconfig" "${B}/.config"
540 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500541
542 ${KERNEL_CONFIG_COMMAND}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500543}
544
545do_savedefconfig() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600546 bbplain "Saving defconfig to:\n${B}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500547 oe_runmake -C ${B} savedefconfig
548}
549do_savedefconfig[nostamp] = "1"
550addtask savedefconfig after do_configure
551
552inherit cml1
553
Brad Bishop316dfdd2018-06-25 12:45:53 -0400554KCONFIG_CONFIG_COMMAND_append = " HOSTLDFLAGS='${BUILD_LDFLAGS}'"
555
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500556EXPORT_FUNCTIONS do_compile do_install do_configure
557
558# kernel-base becomes kernel-${KERNEL_VERSION}
He Zhefe76b1e2016-05-25 04:47:16 -0400559# kernel-image becomes kernel-image-${KERNEL_VERSION}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400560PACKAGES = "${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 -0500561FILES_${PN} = ""
Brad Bishop15ae2502019-06-18 21:44:24 -0400562FILES_${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 -0400563FILES_${KERNEL_PACKAGE_NAME}-image = ""
564FILES_${KERNEL_PACKAGE_NAME}-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
565FILES_${KERNEL_PACKAGE_NAME}-vmlinux = "/boot/vmlinux-${KERNEL_VERSION_NAME}"
566FILES_${KERNEL_PACKAGE_NAME}-modules = ""
567RDEPENDS_${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base"
He Zhefe76b1e2016-05-25 04:47:16 -0400568# Allow machines to override this dependency if kernel image files are
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500569# not wanted in images as standard
Brad Bishop316dfdd2018-06-25 12:45:53 -0400570RDEPENDS_${KERNEL_PACKAGE_NAME}-base ?= "${KERNEL_PACKAGE_NAME}-image"
571PKG_${KERNEL_PACKAGE_NAME}-image = "${KERNEL_PACKAGE_NAME}-image-${@legitimize_package_name('${KERNEL_VERSION}')}"
572RDEPENDS_${KERNEL_PACKAGE_NAME}-image += "${@oe.utils.conditional('KERNEL_IMAGETYPE', 'vmlinux', '${KERNEL_PACKAGE_NAME}-vmlinux', '', d)}"
573PKG_${KERNEL_PACKAGE_NAME}-base = "${KERNEL_PACKAGE_NAME}-${@legitimize_package_name('${KERNEL_VERSION}')}"
574RPROVIDES_${KERNEL_PACKAGE_NAME}-base += "${KERNEL_PACKAGE_NAME}-${KERNEL_VERSION}"
575ALLOW_EMPTY_${KERNEL_PACKAGE_NAME} = "1"
576ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-base = "1"
577ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-image = "1"
578ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-modules = "1"
579DESCRIPTION_${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta package"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500580
Brad Bishop316dfdd2018-06-25 12:45:53 -0400581pkg_postinst_${KERNEL_PACKAGE_NAME}-base () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500582 if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
583 mkdir -p $D/lib/modules/${KERNEL_VERSION}
584 fi
585 if [ -n "$D" ]; then
586 depmodwrapper -a -b $D ${KERNEL_VERSION}
587 else
588 depmod -a ${KERNEL_VERSION}
589 fi
590}
591
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500592PACKAGESPLITFUNCS_prepend = "split_kernel_packages "
593
594python split_kernel_packages () {
Brad Bishop19323692019-04-05 15:28:33 -0400595 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 -0500596}
597
598# Many scripts want to look in arch/$arch/boot for the bootable
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600599# image. This poses a problem for vmlinux and vmlinuz based
600# booting. This task arranges to have vmlinux and vmlinuz appear
601# in the normalized directory location.
602do_kernel_link_images() {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500603 if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
604 mkdir ${B}/arch/${ARCH}/boot
605 fi
606 cd ${B}/arch/${ARCH}/boot
607 ln -sf ../../../vmlinux
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600608 if [ -f ../../../vmlinuz ]; then
609 ln -sf ../../../vmlinuz
610 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500611 if [ -f ../../../vmlinuz.bin ]; then
612 ln -sf ../../../vmlinuz.bin
613 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500614}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500615addtask kernel_link_images after do_compile before do_strip
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500616
617do_strip() {
618 if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then
He Zhefe76b1e2016-05-25 04:47:16 -0400619 if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then
620 bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621 return
622 fi
623
624 cd ${B}
He Zhefe76b1e2016-05-25 04:47:16 -0400625 headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500626 grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \
627 sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \
628 gawk '{print $1}'`
629
630 for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500631 if ! (echo "$headers" | grep -q "^$str$"); then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500632 bbwarn "Section not found: $str";
633 fi
634
He Zhefe76b1e2016-05-25 04:47:16 -0400635 "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500636 }; done
637
638 bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \
639 "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}"
640 fi;
641}
642do_strip[dirs] = "${B}"
643
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500644addtask strip before do_sizecheck after do_kernel_link_images
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500645
646# Support checking the kernel size since some kernels need to reside in partitions
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500647# with a fixed length or there is a limit in transferring the kernel to memory.
648# If more than one image type is enabled, warn on any that don't fit but only fail
649# if none fit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500650do_sizecheck() {
651 if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then
652 invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'`
653 if [ -n "$invalid" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500654 die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integer (The unit is Kbytes)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500655 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500656 at_least_one_fits=
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800657 for imageType in ${KERNEL_IMAGETYPES} ; do
658 size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$imageType | awk '{print $1}'`
He Zhefe76b1e2016-05-25 04:47:16 -0400659 if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800660 bbwarn "This kernel $imageType (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device."
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500661 else
662 at_least_one_fits=y
He Zhefe76b1e2016-05-25 04:47:16 -0400663 fi
664 done
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500665 if [ -z "$at_least_one_fits" ]; then
666 die "All kernel images are too big for your device. Please reduce the size of the kernel by making more of it modular."
667 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500668 fi
669}
670do_sizecheck[dirs] = "${B}"
671
672addtask sizecheck before do_install after do_strip
673
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800674inherit kernel-artifact-names
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500675
676kernel_do_deploy() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400677 deployDir="${DEPLOYDIR}"
678 if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then
679 deployDir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}"
680 mkdir "$deployDir"
681 fi
682
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800683 for imageType in ${KERNEL_IMAGETYPES} ; do
684 base_name=${imageType}-${KERNEL_IMAGE_NAME}
685 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} $deployDir/${base_name}.bin
686 symlink_name=${imageType}-${KERNEL_IMAGE_LINK_NAME}
687 ln -sf ${base_name}.bin $deployDir/${symlink_name}.bin
688 ln -sf ${base_name}.bin $deployDir/${imageType}
He Zhefe76b1e2016-05-25 04:47:16 -0400689 done
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800690
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500691 if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800692 mkdir -p ${D}${root_prefix}/lib
693 tar -cvzf $deployDir/modules-${MODULE_TARBALL_NAME}.tgz -C ${D}${root_prefix} lib
694 ln -sf modules-${MODULE_TARBALL_NAME}.tgz $deployDir/modules-${MODULE_TARBALL_LINK_NAME}.tgz
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500695 fi
696
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800697 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
698 for imageType in ${KERNEL_IMAGETYPES} ; do
Brad Bishop977dc1a2019-02-06 16:01:43 -0500699 if [ "$imageType" = "fitImage" ] ; then
700 continue
701 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800702 initramfs_base_name=${imageType}-${INITRAMFS_NAME}
703 initramfs_symlink_name=${imageType}-${INITRAMFS_LINK_NAME}
704 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType}.initramfs $deployDir/${initramfs_base_name}.bin
Brad Bishop316dfdd2018-06-25 12:45:53 -0400705 ln -sf ${initramfs_base_name}.bin $deployDir/${initramfs_symlink_name}.bin
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800706 done
707 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500708}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500709do_deploy[cleandirs] = "${DEPLOYDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500710do_deploy[dirs] = "${DEPLOYDIR} ${B}"
711do_deploy[prefuncs] += "package_get_auto_pr"
712
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500713addtask deploy after do_populate_sysroot do_packagedata
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500714
715EXPORT_FUNCTIONS do_deploy
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500716
717# Add using Device Tree support
718inherit kernel-devicetree