blob: 437b8c7671e5388378870088df5b8ea23c286872 [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"
11
12CVE_PRODUCT ?= "linux_kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013
14S = "${STAGING_KERNEL_DIR}"
15B = "${WORKDIR}/build"
16KBUILD_OUTPUT = "${B}"
17OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
18
19# we include gcc above, we dont need virtual/libc
20INHIBIT_DEFAULT_DEPS = "1"
21
22KERNEL_IMAGETYPE ?= "zImage"
23INITRAMFS_IMAGE ?= ""
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024INITRAMFS_IMAGE_NAME ?= "${@['${INITRAMFS_IMAGE}-${MACHINE}', ''][d.getVar('INITRAMFS_IMAGE') == '']}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050025INITRAMFS_TASK ?= ""
26INITRAMFS_IMAGE_BUNDLE ?= ""
27
He Zhefe76b1e2016-05-25 04:47:16 -040028# KERNEL_VERSION is extracted from source code. It is evaluated as
29# None for the first parsing, since the code has not been fetched.
30# After the code is fetched, it will be evaluated as real version
31# number and cause kernel to be rebuilt. To avoid this, make
32# KERNEL_VERSION_NAME and KERNEL_VERSION_PKG_NAME depend on
33# LINUX_VERSION which is a constant.
Brad Bishop6e60e8b2018-02-01 10:27:11 -050034KERNEL_VERSION_NAME = "${@d.getVar('KERNEL_VERSION') or ""}"
He Zhefe76b1e2016-05-25 04:47:16 -040035KERNEL_VERSION_NAME[vardepvalue] = "${LINUX_VERSION}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}"
He Zhefe76b1e2016-05-25 04:47:16 -040037KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}"
38
Patrick Williamsc124f4f2015-09-15 14:41:29 -050039python __anonymous () {
Brad Bishop316dfdd2018-06-25 12:45:53 -040040 pn = d.getVar("PN")
41 kpn = d.getVar("KERNEL_PACKAGE_NAME")
42
43 # XXX Remove this after bug 11905 is resolved
44 # FILES_${KERNEL_PACKAGE_NAME}-dev doesn't expand correctly
45 if kpn == pn:
46 bb.warn("Some packages (E.g. *-dev) might be missing due to "
47 "bug 11905 (variable KERNEL_PACKAGE_NAME == PN)")
48
49 # The default kernel recipe builds in a shared location defined by
50 # bitbake/distro confs: STAGING_KERNEL_DIR and STAGING_KERNEL_BUILDDIR.
51 # Set these variables to directories under ${WORKDIR} in alternate
52 # kernel recipes (I.e. where KERNEL_PACKAGE_NAME != kernel) so that they
53 # may build in parallel with the default kernel without clobbering.
54 if kpn != "kernel":
55 workdir = d.getVar("WORKDIR")
56 sourceDir = os.path.join(workdir, 'kernel-source')
57 artifactsDir = os.path.join(workdir, 'kernel-build-artifacts')
58 d.setVar("STAGING_KERNEL_DIR", sourceDir)
59 d.setVar("STAGING_KERNEL_BUILDDIR", artifactsDir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060
He Zhefe76b1e2016-05-25 04:47:16 -040061 # Merge KERNEL_IMAGETYPE and KERNEL_ALT_IMAGETYPE into KERNEL_IMAGETYPES
Brad Bishop6e60e8b2018-02-01 10:27:11 -050062 type = d.getVar('KERNEL_IMAGETYPE') or ""
63 alttype = d.getVar('KERNEL_ALT_IMAGETYPE') or ""
64 types = d.getVar('KERNEL_IMAGETYPES') or ""
He Zhefe76b1e2016-05-25 04:47:16 -040065 if type not in types.split():
66 types = (type + ' ' + types).strip()
67 if alttype not in types.split():
68 types = (alttype + ' ' + types).strip()
69 d.setVar('KERNEL_IMAGETYPES', types)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080071 # KERNEL_IMAGETYPES may contain a mixture of image types supported directly
72 # by the kernel build system and types which are created by post-processing
73 # the output of the kernel build system (e.g. compressing vmlinux ->
74 # vmlinux.gz in kernel_do_compile()).
75 # KERNEL_IMAGETYPE_FOR_MAKE should contain only image types supported
76 # directly by the kernel build system.
77 if not d.getVar('KERNEL_IMAGETYPE_FOR_MAKE'):
78 typeformake = set()
79 for type in types.split():
80 if type == 'vmlinux.gz':
81 type = 'vmlinux'
82 typeformake.add(type)
83
84 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', ' '.join(sorted(typeformake)))
85
86 kname = d.getVar('KERNEL_PACKAGE_NAME') or "kernel"
87 imagedest = d.getVar('KERNEL_IMAGEDEST')
He Zhefe76b1e2016-05-25 04:47:16 -040088
Brad Bishop37a0e4d2017-12-04 01:01:44 -050089 for type in types.split():
He Zhefe76b1e2016-05-25 04:47:16 -040090 typelower = type.lower()
Brad Bishop316dfdd2018-06-25 12:45:53 -040091 d.appendVar('PACKAGES', ' %s-image-%s' % (kname, typelower))
Brad Bishop316dfdd2018-06-25 12:45:53 -040092 d.setVar('FILES_' + kname + '-image-' + typelower, '/' + imagedest + '/' + type + '-${KERNEL_VERSION_NAME}' + ' /' + imagedest + '/' + type)
Brad Bishop316dfdd2018-06-25 12:45:53 -040093 d.appendVar('RDEPENDS_%s-image' % kname, ' %s-image-%s' % (kname, typelower))
Brad Bishop316dfdd2018-06-25 12:45:53 -040094 d.setVar('PKG_%s-image-%s' % (kname,typelower), '%s-image-%s-${KERNEL_VERSION_PKG_NAME}' % (kname, typelower))
Brad Bishop316dfdd2018-06-25 12:45:53 -040095 d.setVar('ALLOW_EMPTY_%s-image-%s' % (kname, typelower), '1')
He Zhefe76b1e2016-05-25 04:47:16 -040096
Brad Bishop6e60e8b2018-02-01 10:27:11 -050097 image = d.getVar('INITRAMFS_IMAGE')
Brad Bishop393846f2019-05-20 12:24:11 -040098 image_bundle = d.getVar('INITRAMFS_IMAGE_BUNDLE')
99 if image and bb.utils.to_boolean(image_bundle, False):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500100 d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500101
102 # NOTE: setting INITRAMFS_TASK is for backward compatibility
103 # The preferred method is to set INITRAMFS_IMAGE, because
104 # this INITRAMFS_TASK has circular dependency problems
105 # if the initramfs requires kernel modules
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500106 image_task = d.getVar('INITRAMFS_TASK')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107 if image_task:
108 d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}')
109}
110
111# Here we pull in all various kernel image types which we support.
112#
113# In case you're wondering why kernel.bbclass inherits the other image
114# types instead of the other way around, the reason for that is to
115# maintain compatibility with various currently existing meta-layers.
116# By pulling in the various kernel image types here, we retain the
117# original behavior of kernel.bbclass, so no meta-layers should get
118# broken.
119#
120# KERNEL_CLASSES by default pulls in kernel-uimage.bbclass, since this
121# used to be the default behavior when only uImage was supported. This
122# variable can be appended by users who implement support for new kernel
123# image types.
124
125KERNEL_CLASSES ?= " kernel-uimage "
126inherit ${KERNEL_CLASSES}
127
128# Old style kernels may set ${S} = ${WORKDIR}/git for example
129# We need to move these over to STAGING_KERNEL_DIR. We can't just
130# create the symlink in advance as the git fetcher can't cope with
131# the symlink.
132do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
133do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
Brad Bishopc342db32019-05-15 21:57:59 -0400134python do_symlink_kernsrc () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500135 s = d.getVar("S")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500136 if s[-1] == '/':
137 # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as directory name and fail
138 s=s[:-1]
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500139 kernsrc = d.getVar("STAGING_KERNEL_DIR")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500140 if s != kernsrc:
141 bb.utils.mkdirhier(kernsrc)
142 bb.utils.remove(kernsrc, recurse=True)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500143 if d.getVar("EXTERNALSRC"):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144 # With EXTERNALSRC S will not be wiped so we can symlink to it
145 os.symlink(s, kernsrc)
146 else:
147 import shutil
148 shutil.move(s, kernsrc)
149 os.symlink(kernsrc, s)
150}
Brad Bishopc342db32019-05-15 21:57:59 -0400151addtask symlink_kernsrc before do_configure after do_unpack
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500152
153inherit kernel-arch deploy
154
Brad Bishop316dfdd2018-06-25 12:45:53 -0400155PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*"
156PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-image-.*"
157PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-firmware-.*"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500158
159export OS = "${TARGET_OS}"
160export CROSS_COMPILE = "${TARGET_PREFIX}"
Brad Bishop316dfdd2018-06-25 12:45:53 -0400161export KBUILD_BUILD_VERSION = "1"
Brad Bishop977dc1a2019-02-06 16:01:43 -0500162export KBUILD_BUILD_USER ?= "oe-user"
163export KBUILD_BUILD_HOST ?= "oe-host"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500164
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165KERNEL_RELEASE ?= "${KERNEL_VERSION}"
166
He Zhefe76b1e2016-05-25 04:47:16 -0400167# The directory where built kernel lies in the kernel tree
168KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800169KERNEL_IMAGEDEST ?= "boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500170
171#
172# configuration
173#
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500174export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE") or "ttyS0"}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175
176KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}"
177
178KERNEL_LOCALVERSION ?= ""
179
180# kernels are generally machine specific
181PACKAGE_ARCH = "${MACHINE_ARCH}"
182
183# U-Boot support
184UBOOT_ENTRYPOINT ?= "20008000"
185UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}"
186
187# Some Linux kernel configurations need additional parameters on the command line
188KERNEL_EXTRA_ARGS ?= ""
189
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500190EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500191KERNEL_ALT_IMAGETYPE ??= ""
192
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500193copy_initramfs() {
194 echo "Copying initramfs into ./usr ..."
195 # In case the directory is not created yet from the first pass compile:
196 mkdir -p ${B}/usr
197 # Find and use the first initramfs image archive type we find
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500198 rm -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500199 for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz; do
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500200 if [ -e "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" ]; then
201 cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 case $img in
203 *gz)
204 echo "gzip decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500205 gunzip -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206 break
207 ;;
208 *lz4)
209 echo "lz4 decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500210 lz4 -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500211 break
212 ;;
213 *lzo)
214 echo "lzo decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500215 lzop -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500216 break
217 ;;
218 *lzma)
219 echo "lzma decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500220 lzma -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500221 break
222 ;;
223 *xz)
224 echo "xz decompressing image"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500225 xz -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500226 break
227 ;;
228 esac
Brad Bishopf8caae32019-03-25 13:13:56 -0400229 break
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500230 fi
231 done
Brad Bishopf8caae32019-03-25 13:13:56 -0400232 # Verify that the above loop found a initramfs, fail otherwise
233 [ -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 -0500234}
235
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500236do_bundle_initramfs () {
237 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
238 echo "Creating a kernel image with a bundled initramfs..."
239 copy_initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400240 # Backing up kernel image relies on its type(regular file or symbolic link)
241 tmp_path=""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800242 for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
243 if [ -h ${KERNEL_OUTPUT_DIR}/$imageType ] ; then
244 linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$imageType`
245 realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$imageType`
He Zhefe76b1e2016-05-25 04:47:16 -0400246 mv -f $realpath $realpath.bak
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800247 tmp_path=$tmp_path" "$imageType"#"$linkpath"#"$realpath
248 elif [ -f ${KERNEL_OUTPUT_DIR}/$imageType ]; then
249 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.bak
250 tmp_path=$tmp_path" "$imageType"##"
He Zhefe76b1e2016-05-25 04:47:16 -0400251 fi
252 done
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500253 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500254 kernel_do_compile
He Zhefe76b1e2016-05-25 04:47:16 -0400255 # Restoring kernel image
256 for tp in $tmp_path ; do
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800257 imageType=`echo $tp|cut -d "#" -f 1`
He Zhefe76b1e2016-05-25 04:47:16 -0400258 linkpath=`echo $tp|cut -d "#" -f 2`
259 realpath=`echo $tp|cut -d "#" -f 3`
260 if [ -n "$realpath" ]; then
261 mv -f $realpath $realpath.initramfs
262 mv -f $realpath.bak $realpath
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800263 ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$imageType.initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400264 else
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800265 mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.initramfs
266 mv -f ${KERNEL_OUTPUT_DIR}/$imageType.bak ${KERNEL_OUTPUT_DIR}/$imageType
He Zhefe76b1e2016-05-25 04:47:16 -0400267 fi
268 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500269 fi
270}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600271do_bundle_initramfs[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500272
273python do_devshell_prepend () {
274 os.environ["LDFLAGS"] = ''
275}
276
277addtask bundle_initramfs after do_install before do_deploy
278
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500279get_cc_option () {
280 # Check if KERNEL_CC supports the option "file-prefix-map".
281 # This option allows us to build images with __FILE__ values that do not
282 # contain the host build path.
283 if ${KERNEL_CC} -Q --help=joined | grep -q "\-ffile-prefix-map=<old=new>"; then
284 echo "-ffile-prefix-map=${S}=/kernel-source/"
285 fi
286}
287
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288kernel_do_compile() {
289 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
Brad Bishop316dfdd2018-06-25 12:45:53 -0400290 if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500291 # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not
292 # be set....
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800293 if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500294 olddir=`pwd`
295 cd ${S}
296 SOURCE_DATE_EPOCH=`git log -1 --pretty=%ct`
297 # git repo not guaranteed, so fall back to REPRODUCIBLE_TIMESTAMP_ROOTFS
298 if [ $? -ne 0 ]; then
299 SOURCE_DATE_EPOCH=${REPRODUCIBLE_TIMESTAMP_ROOTFS}
300 fi
301 cd $olddir
302 fi
303
304 ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH`
305 export KBUILD_BUILD_TIMESTAMP="$ts"
306 export KCONFIG_NOTIMESTAMP=1
307 bbnote "KBUILD_BUILD_TIMESTAMP: $ts"
308 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500309 # The $use_alternate_initrd is only set from
310 # do_bundle_initramfs() This variable is specifically for the
311 # case where we are making a second pass at the kernel
312 # compilation and we want to force the kernel build to use a
313 # different initramfs image. The way to do that in the kernel
314 # is to specify:
315 # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio
316 if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then
317 # The old style way of copying an prebuilt image and building it
318 # is turned on via INTIRAMFS_TASK != ""
319 copy_initramfs
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500320 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500321 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500322 cc_extra=$(get_cc_option)
He Zhefe76b1e2016-05-25 04:47:16 -0400323 for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500324 oe_runmake ${typeformake} CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd
He Zhefe76b1e2016-05-25 04:47:16 -0400325 done
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500326 # vmlinux.gz is not built by kernel
327 if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then
328 mkdir -p "${KERNEL_OUTPUT_DIR}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500329 gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500330 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500331}
332
333do_compile_kernelmodules() {
334 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
335 if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500336 cc_extra=$(get_cc_option)
337 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 -0500338
339 # Module.symvers gets updated during the
340 # building of the kernel modules. We need to
341 # update this in the shared workdir since some
342 # external kernel modules has a dependency on
343 # other kernel modules and will look at this
344 # file to do symbol lookups
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600345 cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500346 else
347 bbnote "no modules to compile"
348 fi
349}
350addtask compile_kernelmodules after do_compile before do_strip
351
352kernel_do_install() {
353 #
354 # First install the modules
355 #
356 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
357 if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500358 oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install
359 rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
360 rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500361 # If the kernel/ directory is empty remove it to prevent QA issues
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500362 rmdir --ignore-fail-on-non-empty "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500363 else
364 bbnote "no modules to install"
365 fi
366
367 #
368 # Install various kernel output (zImage, map file, config, module support files)
369 #
370 install -d ${D}/${KERNEL_IMAGEDEST}
371 install -d ${D}/boot
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800372 for imageType in ${KERNEL_IMAGETYPES} ; do
373 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} ${D}/${KERNEL_IMAGEDEST}/${imageType}-${KERNEL_VERSION}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400374 if [ "${KERNEL_PACKAGE_NAME}" = "kernel" ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800375 ln -sf ${imageType}-${KERNEL_VERSION} ${D}/${KERNEL_IMAGEDEST}/${imageType}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400376 fi
He Zhefe76b1e2016-05-25 04:47:16 -0400377 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500378 install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION}
379 install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION}
380 install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION}
381 [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION}
382 install -d ${D}${sysconfdir}/modules-load.d
383 install -d ${D}${sysconfdir}/modprobe.d
384}
385do_install[prefuncs] += "package_get_auto_pr"
386
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600387# Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile
388do_kernel_version_sanity_check() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500389 if [ "x${KERNEL_VERSION_SANITY_SKIP}" = "x1" ]; then
390 exit 0
391 fi
392
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600393 # The Makefile determines the kernel version shown at runtime
394 # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile
395 VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//)
396 PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
397 SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
398 EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//)
399
400 # Build a string for regex and a plain version string
401 reg="^${VERSION}\.${PATCHLEVEL}"
402 vers="${VERSION}.${PATCHLEVEL}"
403 if [ -n "${SUBLEVEL}" ]; then
404 # Ignoring a SUBLEVEL of zero is fine
405 if [ "${SUBLEVEL}" = "0" ]; then
406 reg="${reg}(\.${SUBLEVEL})?"
407 else
408 reg="${reg}\.${SUBLEVEL}"
409 vers="${vers}.${SUBLEVEL}"
410 fi
411 fi
412 vers="${vers}${EXTRAVERSION}"
413 reg="${reg}${EXTRAVERSION}"
414
415 if [ -z `echo ${PV} | grep -E "${reg}"` ]; then
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500416 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 -0600417 fi
418 exit 0
419}
420
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500421addtask shared_workdir after do_compile before do_compile_kernelmodules
422addtask shared_workdir_setscene
423
424do_shared_workdir_setscene () {
425 exit 1
426}
427
428emit_depmod_pkgdata() {
429 # Stash data for depmod
Brad Bishop316dfdd2018-06-25 12:45:53 -0400430 install -d ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/
431 echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/${KERNEL_PACKAGE_NAME}-abiversion
432 cp ${B}/System.map ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/System.map-${KERNEL_VERSION}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500433}
434
435PACKAGEFUNCS += "emit_depmod_pkgdata"
436
Brad Bishop316dfdd2018-06-25 12:45:53 -0400437do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500438do_shared_workdir () {
439 cd ${B}
440
441 kerneldir=${STAGING_KERNEL_BUILDDIR}
442 install -d $kerneldir
443
444 #
445 # Store the kernel version in sysroots for module-base.bbclass
446 #
447
Brad Bishop316dfdd2018-06-25 12:45:53 -0400448 echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500449
450 # Copy files required for module builds
451 cp System.map $kerneldir/System.map-${KERNEL_VERSION}
452 cp Module.symvers $kerneldir/
453 cp .config $kerneldir/
454 mkdir -p $kerneldir/include/config
455 cp include/config/kernel.release $kerneldir/include/config/kernel.release
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600456 if [ -e certs/signing_key.pem ]; then
457 # The signing_key.* files are stored in the certs/ dir in
458 # newer Linux kernels
459 mkdir -p $kerneldir/certs
460 cp certs/signing_key.* $kerneldir/certs/
461 elif [ -e signing_key.priv ]; then
462 cp signing_key.* $kerneldir/
463 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500464
465 # We can also copy over all the generated files and avoid special cases
466 # like version.h, but we've opted to keep this small until file creep starts
467 # to happen
468 if [ -e include/linux/version.h ]; then
469 mkdir -p $kerneldir/include/linux
470 cp include/linux/version.h $kerneldir/include/linux/version.h
471 fi
472
473 # As of Linux kernel version 3.0.1, the clean target removes
474 # arch/powerpc/lib/crtsavres.o which is present in
475 # KBUILD_LDFLAGS_MODULE, making it required to build external modules.
476 if [ ${ARCH} = "powerpc" ]; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400477 if [ -e arch/powerpc/lib/crtsavres.o ]; then
478 mkdir -p $kerneldir/arch/powerpc/lib/
479 cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o
480 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500481 fi
482
483 if [ -d include/generated ]; then
484 mkdir -p $kerneldir/include/generated/
485 cp -fR include/generated/* $kerneldir/include/generated/
486 fi
487
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500488 if [ -d arch/${ARCH}/include/generated ]; then
489 mkdir -p $kerneldir/arch/${ARCH}/include/generated/
490 cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500491 fi
Brad Bishop19323692019-04-05 15:28:33 -0400492
493 if (grep -q -i -e '^CONFIG_UNWINDER_ORC=y$' $kerneldir/.config); then
494 # With CONFIG_UNWINDER_ORC (the default in 4.14), objtool is required for
495 # out-of-tree modules to be able to generate object files.
496 if [ -x tools/objtool/objtool ]; then
497 mkdir -p ${kerneldir}/tools/objtool
498 cp tools/objtool/objtool ${kerneldir}/tools/objtool/
499 fi
500 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500501}
502
503# We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware
504sysroot_stage_all () {
505 :
506}
507
Brad Bishop977dc1a2019-02-06 16:01:43 -0500508KERNEL_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 -0500509
He Zhefe76b1e2016-05-25 04:47:16 -0400510python check_oldest_kernel() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500511 oldest_kernel = d.getVar('OLDEST_KERNEL')
512 kernel_version = d.getVar('KERNEL_VERSION')
513 tclibc = d.getVar('TCLIBC')
He Zhefe76b1e2016-05-25 04:47:16 -0400514 if tclibc == 'glibc':
515 kernel_version = kernel_version.split('-', 1)[0]
516 if oldest_kernel and kernel_version:
517 if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500518 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 -0400519}
520
521check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION"
522do_configure[prefuncs] += "check_oldest_kernel"
523
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500524kernel_do_configure() {
525 # fixes extra + in /lib/modules/2.6.37+
526 # $ scripts/setlocalversion . => +
527 # $ make kernelversion => 2.6.37
528 # $ make kernelrelease => 2.6.37+
529 touch ${B}/.scmversion ${S}/.scmversion
530
531 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
532 mv "${S}/.config" "${B}/.config"
533 fi
534
535 # Copy defconfig to .config if .config does not exist. This allows
536 # recipes to manage the .config themselves in do_configure_prepend().
537 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
538 cp "${WORKDIR}/defconfig" "${B}/.config"
539 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500540
541 ${KERNEL_CONFIG_COMMAND}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500542}
543
544do_savedefconfig() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600545 bbplain "Saving defconfig to:\n${B}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500546 oe_runmake -C ${B} savedefconfig
547}
548do_savedefconfig[nostamp] = "1"
549addtask savedefconfig after do_configure
550
551inherit cml1
552
Brad Bishop316dfdd2018-06-25 12:45:53 -0400553KCONFIG_CONFIG_COMMAND_append = " HOSTLDFLAGS='${BUILD_LDFLAGS}'"
554
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500555EXPORT_FUNCTIONS do_compile do_install do_configure
556
557# kernel-base becomes kernel-${KERNEL_VERSION}
He Zhefe76b1e2016-05-25 04:47:16 -0400558# kernel-image becomes kernel-image-${KERNEL_VERSION}
Brad Bishop316dfdd2018-06-25 12:45:53 -0400559PACKAGES = "${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 -0500560FILES_${PN} = ""
Brad Bishop316dfdd2018-06-25 12:45:53 -0400561FILES_${KERNEL_PACKAGE_NAME}-base = "${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.order ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.builtin"
562FILES_${KERNEL_PACKAGE_NAME}-image = ""
563FILES_${KERNEL_PACKAGE_NAME}-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build"
564FILES_${KERNEL_PACKAGE_NAME}-vmlinux = "/boot/vmlinux-${KERNEL_VERSION_NAME}"
565FILES_${KERNEL_PACKAGE_NAME}-modules = ""
566RDEPENDS_${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base"
He Zhefe76b1e2016-05-25 04:47:16 -0400567# Allow machines to override this dependency if kernel image files are
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500568# not wanted in images as standard
Brad Bishop316dfdd2018-06-25 12:45:53 -0400569RDEPENDS_${KERNEL_PACKAGE_NAME}-base ?= "${KERNEL_PACKAGE_NAME}-image"
570PKG_${KERNEL_PACKAGE_NAME}-image = "${KERNEL_PACKAGE_NAME}-image-${@legitimize_package_name('${KERNEL_VERSION}')}"
571RDEPENDS_${KERNEL_PACKAGE_NAME}-image += "${@oe.utils.conditional('KERNEL_IMAGETYPE', 'vmlinux', '${KERNEL_PACKAGE_NAME}-vmlinux', '', d)}"
572PKG_${KERNEL_PACKAGE_NAME}-base = "${KERNEL_PACKAGE_NAME}-${@legitimize_package_name('${KERNEL_VERSION}')}"
573RPROVIDES_${KERNEL_PACKAGE_NAME}-base += "${KERNEL_PACKAGE_NAME}-${KERNEL_VERSION}"
574ALLOW_EMPTY_${KERNEL_PACKAGE_NAME} = "1"
575ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-base = "1"
576ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-image = "1"
577ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-modules = "1"
578DESCRIPTION_${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta package"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500579
Brad Bishop316dfdd2018-06-25 12:45:53 -0400580pkg_postinst_${KERNEL_PACKAGE_NAME}-base () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500581 if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
582 mkdir -p $D/lib/modules/${KERNEL_VERSION}
583 fi
584 if [ -n "$D" ]; then
585 depmodwrapper -a -b $D ${KERNEL_VERSION}
586 else
587 depmod -a ${KERNEL_VERSION}
588 fi
589}
590
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500591PACKAGESPLITFUNCS_prepend = "split_kernel_packages "
592
593python split_kernel_packages () {
Brad Bishop19323692019-04-05 15:28:33 -0400594 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 -0500595}
596
597# Many scripts want to look in arch/$arch/boot for the bootable
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600598# image. This poses a problem for vmlinux and vmlinuz based
599# booting. This task arranges to have vmlinux and vmlinuz appear
600# in the normalized directory location.
601do_kernel_link_images() {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500602 if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
603 mkdir ${B}/arch/${ARCH}/boot
604 fi
605 cd ${B}/arch/${ARCH}/boot
606 ln -sf ../../../vmlinux
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600607 if [ -f ../../../vmlinuz ]; then
608 ln -sf ../../../vmlinuz
609 fi
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500610 if [ -f ../../../vmlinuz.bin ]; then
611 ln -sf ../../../vmlinuz.bin
612 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500613}
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500614addtask kernel_link_images after do_compile before do_strip
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500615
616do_strip() {
617 if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then
He Zhefe76b1e2016-05-25 04:47:16 -0400618 if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then
619 bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500620 return
621 fi
622
623 cd ${B}
He Zhefe76b1e2016-05-25 04:47:16 -0400624 headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500625 grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \
626 sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \
627 gawk '{print $1}'`
628
629 for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500630 if ! (echo "$headers" | grep -q "^$str$"); then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500631 bbwarn "Section not found: $str";
632 fi
633
He Zhefe76b1e2016-05-25 04:47:16 -0400634 "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500635 }; done
636
637 bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \
638 "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}"
639 fi;
640}
641do_strip[dirs] = "${B}"
642
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500643addtask strip before do_sizecheck after do_kernel_link_images
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500644
645# Support checking the kernel size since some kernels need to reside in partitions
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500646# with a fixed length or there is a limit in transferring the kernel to memory.
647# If more than one image type is enabled, warn on any that don't fit but only fail
648# if none fit.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500649do_sizecheck() {
650 if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then
651 invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'`
652 if [ -n "$invalid" ]; then
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500653 die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integer (The unit is Kbytes)"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500654 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500655 at_least_one_fits=
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800656 for imageType in ${KERNEL_IMAGETYPES} ; do
657 size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$imageType | awk '{print $1}'`
He Zhefe76b1e2016-05-25 04:47:16 -0400658 if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800659 bbwarn "This kernel $imageType (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device."
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500660 else
661 at_least_one_fits=y
He Zhefe76b1e2016-05-25 04:47:16 -0400662 fi
663 done
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500664 if [ -z "$at_least_one_fits" ]; then
665 die "All kernel images are too big for your device. Please reduce the size of the kernel by making more of it modular."
666 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500667 fi
668}
669do_sizecheck[dirs] = "${B}"
670
671addtask sizecheck before do_install after do_strip
672
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800673inherit kernel-artifact-names
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500674
675kernel_do_deploy() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400676 deployDir="${DEPLOYDIR}"
677 if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then
678 deployDir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}"
679 mkdir "$deployDir"
680 fi
681
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800682 for imageType in ${KERNEL_IMAGETYPES} ; do
683 base_name=${imageType}-${KERNEL_IMAGE_NAME}
684 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} $deployDir/${base_name}.bin
685 symlink_name=${imageType}-${KERNEL_IMAGE_LINK_NAME}
686 ln -sf ${base_name}.bin $deployDir/${symlink_name}.bin
687 ln -sf ${base_name}.bin $deployDir/${imageType}
He Zhefe76b1e2016-05-25 04:47:16 -0400688 done
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800689
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500690 if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800691 mkdir -p ${D}${root_prefix}/lib
692 tar -cvzf $deployDir/modules-${MODULE_TARBALL_NAME}.tgz -C ${D}${root_prefix} lib
693 ln -sf modules-${MODULE_TARBALL_NAME}.tgz $deployDir/modules-${MODULE_TARBALL_LINK_NAME}.tgz
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500694 fi
695
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800696 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
697 for imageType in ${KERNEL_IMAGETYPES} ; do
Brad Bishop977dc1a2019-02-06 16:01:43 -0500698 if [ "$imageType" = "fitImage" ] ; then
699 continue
700 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800701 initramfs_base_name=${imageType}-${INITRAMFS_NAME}
702 initramfs_symlink_name=${imageType}-${INITRAMFS_LINK_NAME}
703 install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType}.initramfs $deployDir/${initramfs_base_name}.bin
Brad Bishop316dfdd2018-06-25 12:45:53 -0400704 ln -sf ${initramfs_base_name}.bin $deployDir/${initramfs_symlink_name}.bin
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800705 done
706 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500707}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500708do_deploy[cleandirs] = "${DEPLOYDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500709do_deploy[dirs] = "${DEPLOYDIR} ${B}"
710do_deploy[prefuncs] += "package_get_auto_pr"
711
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500712addtask deploy after do_populate_sysroot do_packagedata
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500713
714EXPORT_FUNCTIONS do_deploy
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500715
716# Add using Device Tree support
717inherit kernel-devicetree