blob: eefe574a60cbeedc2fdabff5b7ed911c5efc85ba [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit linux-kernel-base kernel-module-split
2
3PROVIDES += "virtual/kernel"
Patrick Williamsc0f7c042017-02-23 20:41:17 -06004DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native depmodwrapper-cross bc-native lzop-native"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05005
6S = "${STAGING_KERNEL_DIR}"
7B = "${WORKDIR}/build"
8KBUILD_OUTPUT = "${B}"
9OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT"
10
11# we include gcc above, we dont need virtual/libc
12INHIBIT_DEFAULT_DEPS = "1"
13
14KERNEL_IMAGETYPE ?= "zImage"
15INITRAMFS_IMAGE ?= ""
16INITRAMFS_TASK ?= ""
17INITRAMFS_IMAGE_BUNDLE ?= ""
18
He Zhefe76b1e2016-05-25 04:47:16 -040019# KERNEL_VERSION is extracted from source code. It is evaluated as
20# None for the first parsing, since the code has not been fetched.
21# After the code is fetched, it will be evaluated as real version
22# number and cause kernel to be rebuilt. To avoid this, make
23# KERNEL_VERSION_NAME and KERNEL_VERSION_PKG_NAME depend on
24# LINUX_VERSION which is a constant.
25KERNEL_VERSION_NAME = "${@d.getVar('KERNEL_VERSION', True) or ""}"
26KERNEL_VERSION_NAME[vardepvalue] = "${LINUX_VERSION}"
27KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION', True))}"
28KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}"
29
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030python __anonymous () {
31 import re
32
He Zhefe76b1e2016-05-25 04:47:16 -040033 # Merge KERNEL_IMAGETYPE and KERNEL_ALT_IMAGETYPE into KERNEL_IMAGETYPES
34 type = d.getVar('KERNEL_IMAGETYPE', True) or ""
35 alttype = d.getVar('KERNEL_ALT_IMAGETYPE', True) or ""
36 types = d.getVar('KERNEL_IMAGETYPES', True) or ""
37 if type not in types.split():
38 types = (type + ' ' + types).strip()
39 if alttype not in types.split():
40 types = (alttype + ' ' + types).strip()
41 d.setVar('KERNEL_IMAGETYPES', types)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042
He Zhefe76b1e2016-05-25 04:47:16 -040043 typeformake = re.sub(r'\.gz', '', types)
44 d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', typeformake)
45
Brad Bishop37a0e4d2017-12-04 01:01:44 -050046 for type in types.split():
He Zhefe76b1e2016-05-25 04:47:16 -040047 typelower = type.lower()
48
49 d.appendVar('PACKAGES', ' ' + 'kernel-image-' + typelower)
50
Brad Bishop37a0e4d2017-12-04 01:01:44 -050051 d.setVar('FILES_kernel-image-' + typelower, '/boot/' + type + '-${KERNEL_VERSION_NAME}')
He Zhefe76b1e2016-05-25 04:47:16 -040052
53 d.appendVar('RDEPENDS_kernel-image', ' ' + 'kernel-image-' + typelower)
54
55 d.setVar('PKG_kernel-image-' + typelower, 'kernel-image-' + typelower + '-${KERNEL_VERSION_PKG_NAME}')
56
57 d.setVar('ALLOW_EMPTY_kernel-image-' + typelower, '1')
58
59 imagedest = d.getVar('KERNEL_IMAGEDEST', True)
60 priority = d.getVar('KERNEL_PRIORITY', True)
61 postinst = '#!/bin/sh\n' + 'update-alternatives --install /' + imagedest + '/' + type + ' ' + type + ' ' + '/' + imagedest + '/' + type + '-${KERNEL_VERSION_NAME} ' + priority + ' || true' + '\n'
62 d.setVar('pkg_postinst_kernel-image-' + typelower, postinst)
63
64 postrm = '#!/bin/sh\n' + 'update-alternatives --remove' + ' ' + type + ' ' + type + '-${KERNEL_VERSION_NAME} || true' + '\n'
65 d.setVar('pkg_postrm_kernel-image-' + typelower, postrm)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066
67 image = d.getVar('INITRAMFS_IMAGE', True)
68 if image:
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050069 d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050070
71 # NOTE: setting INITRAMFS_TASK is for backward compatibility
72 # The preferred method is to set INITRAMFS_IMAGE, because
73 # this INITRAMFS_TASK has circular dependency problems
74 # if the initramfs requires kernel modules
75 image_task = d.getVar('INITRAMFS_TASK', True)
76 if image_task:
77 d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}')
78}
79
80# Here we pull in all various kernel image types which we support.
81#
82# In case you're wondering why kernel.bbclass inherits the other image
83# types instead of the other way around, the reason for that is to
84# maintain compatibility with various currently existing meta-layers.
85# By pulling in the various kernel image types here, we retain the
86# original behavior of kernel.bbclass, so no meta-layers should get
87# broken.
88#
89# KERNEL_CLASSES by default pulls in kernel-uimage.bbclass, since this
90# used to be the default behavior when only uImage was supported. This
91# variable can be appended by users who implement support for new kernel
92# image types.
93
94KERNEL_CLASSES ?= " kernel-uimage "
95inherit ${KERNEL_CLASSES}
96
97# Old style kernels may set ${S} = ${WORKDIR}/git for example
98# We need to move these over to STAGING_KERNEL_DIR. We can't just
99# create the symlink in advance as the git fetcher can't cope with
100# the symlink.
101do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
102do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}"
103base_do_unpack_append () {
104 s = d.getVar("S", True)
105 if s[-1] == '/':
106 # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as directory name and fail
107 s=s[:-1]
108 kernsrc = d.getVar("STAGING_KERNEL_DIR", True)
109 if s != kernsrc:
110 bb.utils.mkdirhier(kernsrc)
111 bb.utils.remove(kernsrc, recurse=True)
112 if d.getVar("EXTERNALSRC", True):
113 # With EXTERNALSRC S will not be wiped so we can symlink to it
114 os.symlink(s, kernsrc)
115 else:
116 import shutil
117 shutil.move(s, kernsrc)
118 os.symlink(kernsrc, s)
119}
120
121inherit kernel-arch deploy
122
123PACKAGES_DYNAMIC += "^kernel-module-.*"
124PACKAGES_DYNAMIC += "^kernel-image-.*"
125PACKAGES_DYNAMIC += "^kernel-firmware-.*"
126
127export OS = "${TARGET_OS}"
128export CROSS_COMPILE = "${TARGET_PREFIX}"
129
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600130KERNEL_PRIORITY ?= "${@int(d.getVar('PV', True).split('-')[0].split('+')[0].split('.')[0]) * 10000 + \
131 int(d.getVar('PV', True).split('-')[0].split('+')[0].split('.')[1]) * 100 + \
132 int(d.getVar('PV', True).split('-')[0].split('+')[0].split('.')[-1])}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500133
134KERNEL_RELEASE ?= "${KERNEL_VERSION}"
135
He Zhefe76b1e2016-05-25 04:47:16 -0400136# The directory where built kernel lies in the kernel tree
137KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500138KERNEL_IMAGEDEST = "boot"
139
140#
141# configuration
142#
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600143export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE", True) or "ttyS0"}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144
145KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}"
146
147KERNEL_LOCALVERSION ?= ""
148
149# kernels are generally machine specific
150PACKAGE_ARCH = "${MACHINE_ARCH}"
151
152# U-Boot support
153UBOOT_ENTRYPOINT ?= "20008000"
154UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}"
155
156# Some Linux kernel configurations need additional parameters on the command line
157KERNEL_EXTRA_ARGS ?= ""
158
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600159EXTRA_OEMAKE = " HOSTCC="${BUILD_CC}" HOSTCPP="${BUILD_CPP}""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160KERNEL_ALT_IMAGETYPE ??= ""
161
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500162copy_initramfs() {
163 echo "Copying initramfs into ./usr ..."
164 # In case the directory is not created yet from the first pass compile:
165 mkdir -p ${B}/usr
166 # Find and use the first initramfs image archive type we find
167 rm -f ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500168 for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz; do
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500169 if [ -e "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.$img" ]; then
170 cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.$img ${B}/usr/.
171 case $img in
172 *gz)
173 echo "gzip decompressing image"
174 gunzip -f ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img
175 break
176 ;;
177 *lz4)
178 echo "lz4 decompressing image"
179 lz4 -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img
180 break
181 ;;
182 *lzo)
183 echo "lzo decompressing image"
184 lzop -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img
185 break
186 ;;
187 *lzma)
188 echo "lzma decompressing image"
189 lzma -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img
190 break
191 ;;
192 *xz)
193 echo "xz decompressing image"
194 xz -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img
195 break
196 ;;
197 esac
198 fi
199 done
200 echo "Finished copy of initramfs into ./usr"
201}
202
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600203INITRAMFS_BASE_NAME ?= "initramfs-${PV}-${PR}-${MACHINE}-${DATETIME}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500204INITRAMFS_BASE_NAME[vardepsexclude] = "DATETIME"
205do_bundle_initramfs () {
206 if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then
207 echo "Creating a kernel image with a bundled initramfs..."
208 copy_initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400209 # Backing up kernel image relies on its type(regular file or symbolic link)
210 tmp_path=""
211 for type in ${KERNEL_IMAGETYPES} ; do
212 if [ -h ${KERNEL_OUTPUT_DIR}/$type ] ; then
213 linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$type`
214 realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$type`
215 mv -f $realpath $realpath.bak
216 tmp_path=$tmp_path" "$type"#"$linkpath"#"$realpath
217 elif [ -f ${KERNEL_OUTPUT_DIR}/$type ]; then
218 mv -f ${KERNEL_OUTPUT_DIR}/$type ${KERNEL_OUTPUT_DIR}/$type.bak
219 tmp_path=$tmp_path" "$type"##"
220 fi
221 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500222 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio
223 kernel_do_compile
He Zhefe76b1e2016-05-25 04:47:16 -0400224 # Restoring kernel image
225 for tp in $tmp_path ; do
226 type=`echo $tp|cut -d "#" -f 1`
227 linkpath=`echo $tp|cut -d "#" -f 2`
228 realpath=`echo $tp|cut -d "#" -f 3`
229 if [ -n "$realpath" ]; then
230 mv -f $realpath $realpath.initramfs
231 mv -f $realpath.bak $realpath
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600232 ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$type.initramfs
He Zhefe76b1e2016-05-25 04:47:16 -0400233 else
234 mv -f ${KERNEL_OUTPUT_DIR}/$type ${KERNEL_OUTPUT_DIR}/$type.initramfs
235 mv -f ${KERNEL_OUTPUT_DIR}/$type.bak ${KERNEL_OUTPUT_DIR}/$type
236 fi
237 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500238 fi
239}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600240do_bundle_initramfs[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500241
242python do_devshell_prepend () {
243 os.environ["LDFLAGS"] = ''
244}
245
246addtask bundle_initramfs after do_install before do_deploy
247
248kernel_do_compile() {
249 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
250 # The $use_alternate_initrd is only set from
251 # do_bundle_initramfs() This variable is specifically for the
252 # case where we are making a second pass at the kernel
253 # compilation and we want to force the kernel build to use a
254 # different initramfs image. The way to do that in the kernel
255 # is to specify:
256 # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio
257 if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then
258 # The old style way of copying an prebuilt image and building it
259 # is turned on via INTIRAMFS_TASK != ""
260 copy_initramfs
261 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio
262 fi
He Zhefe76b1e2016-05-25 04:47:16 -0400263 for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
264 oe_runmake ${typeformake} CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd
265 for type in ${KERNEL_IMAGETYPES} ; do
266 if test "${typeformake}.gz" = "${type}"; then
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500267 mkdir -p "${KERNEL_OUTPUT_DIR}"
He Zhefe76b1e2016-05-25 04:47:16 -0400268 gzip -9c < "${typeformake}" > "${KERNEL_OUTPUT_DIR}/${type}"
269 break;
270 fi
271 done
272 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500273}
274
275do_compile_kernelmodules() {
276 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
277 if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
278 oe_runmake -C ${B} ${PARALLEL_MAKE} modules CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500279
280 # Module.symvers gets updated during the
281 # building of the kernel modules. We need to
282 # update this in the shared workdir since some
283 # external kernel modules has a dependency on
284 # other kernel modules and will look at this
285 # file to do symbol lookups
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600286 cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500287 else
288 bbnote "no modules to compile"
289 fi
290}
291addtask compile_kernelmodules after do_compile before do_strip
292
293kernel_do_install() {
294 #
295 # First install the modules
296 #
297 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
298 if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
299 oe_runmake DEPMOD=echo INSTALL_MOD_PATH="${D}" modules_install
300 rm "${D}/lib/modules/${KERNEL_VERSION}/build"
301 rm "${D}/lib/modules/${KERNEL_VERSION}/source"
302 # If the kernel/ directory is empty remove it to prevent QA issues
303 rmdir --ignore-fail-on-non-empty "${D}/lib/modules/${KERNEL_VERSION}/kernel"
304 else
305 bbnote "no modules to install"
306 fi
307
308 #
309 # Install various kernel output (zImage, map file, config, module support files)
310 #
311 install -d ${D}/${KERNEL_IMAGEDEST}
312 install -d ${D}/boot
He Zhefe76b1e2016-05-25 04:47:16 -0400313 for type in ${KERNEL_IMAGETYPES} ; do
314 install -m 0644 ${KERNEL_OUTPUT_DIR}/${type} ${D}/${KERNEL_IMAGEDEST}/${type}-${KERNEL_VERSION}
315 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500316 install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION}
317 install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION}
318 install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION}
319 [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION}
320 install -d ${D}${sysconfdir}/modules-load.d
321 install -d ${D}${sysconfdir}/modprobe.d
322}
323do_install[prefuncs] += "package_get_auto_pr"
324
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600325# Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile
326do_kernel_version_sanity_check() {
327 # The Makefile determines the kernel version shown at runtime
328 # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile
329 VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//)
330 PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
331 SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
332 EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//)
333
334 # Build a string for regex and a plain version string
335 reg="^${VERSION}\.${PATCHLEVEL}"
336 vers="${VERSION}.${PATCHLEVEL}"
337 if [ -n "${SUBLEVEL}" ]; then
338 # Ignoring a SUBLEVEL of zero is fine
339 if [ "${SUBLEVEL}" = "0" ]; then
340 reg="${reg}(\.${SUBLEVEL})?"
341 else
342 reg="${reg}\.${SUBLEVEL}"
343 vers="${vers}.${SUBLEVEL}"
344 fi
345 fi
346 vers="${vers}${EXTRAVERSION}"
347 reg="${reg}${EXTRAVERSION}"
348
349 if [ -z `echo ${PV} | grep -E "${reg}"` ]; then
350 bbfatal "Package Version (${PV}) does not match of kernel being built (${vers}). Please update the PV variable to match the kernel source."
351 fi
352 exit 0
353}
354
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500355addtask shared_workdir after do_compile before do_compile_kernelmodules
356addtask shared_workdir_setscene
357
358do_shared_workdir_setscene () {
359 exit 1
360}
361
362emit_depmod_pkgdata() {
363 # Stash data for depmod
364 install -d ${PKGDESTWORK}/kernel-depmod/
365 echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/kernel-depmod/kernel-abiversion
366 cp ${B}/System.map ${PKGDESTWORK}/kernel-depmod/System.map-${KERNEL_VERSION}
367}
368
369PACKAGEFUNCS += "emit_depmod_pkgdata"
370
371do_shared_workdir () {
372 cd ${B}
373
374 kerneldir=${STAGING_KERNEL_BUILDDIR}
375 install -d $kerneldir
376
377 #
378 # Store the kernel version in sysroots for module-base.bbclass
379 #
380
381 echo "${KERNEL_VERSION}" > $kerneldir/kernel-abiversion
382
383 # Copy files required for module builds
384 cp System.map $kerneldir/System.map-${KERNEL_VERSION}
385 cp Module.symvers $kerneldir/
386 cp .config $kerneldir/
387 mkdir -p $kerneldir/include/config
388 cp include/config/kernel.release $kerneldir/include/config/kernel.release
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600389 if [ -e certs/signing_key.pem ]; then
390 # The signing_key.* files are stored in the certs/ dir in
391 # newer Linux kernels
392 mkdir -p $kerneldir/certs
393 cp certs/signing_key.* $kerneldir/certs/
394 elif [ -e signing_key.priv ]; then
395 cp signing_key.* $kerneldir/
396 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500397
398 # We can also copy over all the generated files and avoid special cases
399 # like version.h, but we've opted to keep this small until file creep starts
400 # to happen
401 if [ -e include/linux/version.h ]; then
402 mkdir -p $kerneldir/include/linux
403 cp include/linux/version.h $kerneldir/include/linux/version.h
404 fi
405
406 # As of Linux kernel version 3.0.1, the clean target removes
407 # arch/powerpc/lib/crtsavres.o which is present in
408 # KBUILD_LDFLAGS_MODULE, making it required to build external modules.
409 if [ ${ARCH} = "powerpc" ]; then
410 mkdir -p $kerneldir/arch/powerpc/lib/
411 cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o
412 fi
413
414 if [ -d include/generated ]; then
415 mkdir -p $kerneldir/include/generated/
416 cp -fR include/generated/* $kerneldir/include/generated/
417 fi
418
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500419 if [ -d arch/${ARCH}/include/generated ]; then
420 mkdir -p $kerneldir/arch/${ARCH}/include/generated/
421 cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500422 fi
423}
424
425# We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware
426sysroot_stage_all () {
427 :
428}
429
430KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} O=${B} oldnoconfig || yes '' | oe_runmake -C ${S} O=${B} oldconfig"
431
He Zhefe76b1e2016-05-25 04:47:16 -0400432python check_oldest_kernel() {
433 oldest_kernel = d.getVar('OLDEST_KERNEL', True)
434 kernel_version = d.getVar('KERNEL_VERSION', True)
435 tclibc = d.getVar('TCLIBC', True)
436 if tclibc == 'glibc':
437 kernel_version = kernel_version.split('-', 1)[0]
438 if oldest_kernel and kernel_version:
439 if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0:
440 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', True), oldest_kernel, kernel_version, tclibc))
441}
442
443check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION"
444do_configure[prefuncs] += "check_oldest_kernel"
445
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500446kernel_do_configure() {
447 # fixes extra + in /lib/modules/2.6.37+
448 # $ scripts/setlocalversion . => +
449 # $ make kernelversion => 2.6.37
450 # $ make kernelrelease => 2.6.37+
451 touch ${B}/.scmversion ${S}/.scmversion
452
453 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
454 mv "${S}/.config" "${B}/.config"
455 fi
456
457 # Copy defconfig to .config if .config does not exist. This allows
458 # recipes to manage the .config themselves in do_configure_prepend().
459 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
460 cp "${WORKDIR}/defconfig" "${B}/.config"
461 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500462
463 ${KERNEL_CONFIG_COMMAND}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500464}
465
466do_savedefconfig() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600467 bbplain "Saving defconfig to:\n${B}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500468 oe_runmake -C ${B} savedefconfig
469}
470do_savedefconfig[nostamp] = "1"
471addtask savedefconfig after do_configure
472
473inherit cml1
474
475EXPORT_FUNCTIONS do_compile do_install do_configure
476
477# kernel-base becomes kernel-${KERNEL_VERSION}
He Zhefe76b1e2016-05-25 04:47:16 -0400478# kernel-image becomes kernel-image-${KERNEL_VERSION}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500479PACKAGES = "kernel kernel-base kernel-vmlinux kernel-image kernel-dev kernel-modules"
480FILES_${PN} = ""
481FILES_kernel-base = "/lib/modules/${KERNEL_VERSION}/modules.order /lib/modules/${KERNEL_VERSION}/modules.builtin"
He Zhefe76b1e2016-05-25 04:47:16 -0400482FILES_kernel-image = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500483FILES_kernel-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} /lib/modules/${KERNEL_VERSION}/build"
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500484FILES_kernel-vmlinux = "/boot/vmlinux-${KERNEL_VERSION_NAME}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500485FILES_kernel-modules = ""
486RDEPENDS_kernel = "kernel-base"
He Zhefe76b1e2016-05-25 04:47:16 -0400487# Allow machines to override this dependency if kernel image files are
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500488# not wanted in images as standard
489RDEPENDS_kernel-base ?= "kernel-image"
490PKG_kernel-image = "kernel-image-${@legitimize_package_name('${KERNEL_VERSION}')}"
491RDEPENDS_kernel-image += "${@base_conditional('KERNEL_IMAGETYPE', 'vmlinux', 'kernel-vmlinux', '', d)}"
492PKG_kernel-base = "kernel-${@legitimize_package_name('${KERNEL_VERSION}')}"
493RPROVIDES_kernel-base += "kernel-${KERNEL_VERSION}"
494ALLOW_EMPTY_kernel = "1"
495ALLOW_EMPTY_kernel-base = "1"
496ALLOW_EMPTY_kernel-image = "1"
497ALLOW_EMPTY_kernel-modules = "1"
498DESCRIPTION_kernel-modules = "Kernel modules meta package"
499
500pkg_postinst_kernel-base () {
501 if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
502 mkdir -p $D/lib/modules/${KERNEL_VERSION}
503 fi
504 if [ -n "$D" ]; then
505 depmodwrapper -a -b $D ${KERNEL_VERSION}
506 else
507 depmod -a ${KERNEL_VERSION}
508 fi
509}
510
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500511PACKAGESPLITFUNCS_prepend = "split_kernel_packages "
512
513python split_kernel_packages () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500514 do_split_packages(d, root='/lib/firmware', file_regex='^(.*)\.(bin|fw|cis|csp|dsp)$', output_pattern='kernel-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='')
515}
516
517# Many scripts want to look in arch/$arch/boot for the bootable
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600518# image. This poses a problem for vmlinux and vmlinuz based
519# booting. This task arranges to have vmlinux and vmlinuz appear
520# in the normalized directory location.
521do_kernel_link_images() {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500522 if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
523 mkdir ${B}/arch/${ARCH}/boot
524 fi
525 cd ${B}/arch/${ARCH}/boot
526 ln -sf ../../../vmlinux
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600527 if [ -f ../../../vmlinuz ]; then
528 ln -sf ../../../vmlinuz
529 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500530}
531
532do_strip() {
533 if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then
He Zhefe76b1e2016-05-25 04:47:16 -0400534 if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then
535 bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500536 return
537 fi
538
539 cd ${B}
He Zhefe76b1e2016-05-25 04:47:16 -0400540 headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500541 grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \
542 sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \
543 gawk '{print $1}'`
544
545 for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500546 if ! (echo "$headers" | grep -q "^$str$"); then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500547 bbwarn "Section not found: $str";
548 fi
549
He Zhefe76b1e2016-05-25 04:47:16 -0400550 "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500551 }; done
552
553 bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \
554 "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}"
555 fi;
556}
557do_strip[dirs] = "${B}"
558
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600559addtask do_strip before do_sizecheck after do_kernel_link_images
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500560
561# Support checking the kernel size since some kernels need to reside in partitions
562# with a fixed length or there is a limit in transferring the kernel to memory
563do_sizecheck() {
564 if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then
565 invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'`
566 if [ -n "$invalid" ]; then
567 die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integerx (The unit is Kbytes)"
568 fi
He Zhefe76b1e2016-05-25 04:47:16 -0400569 for type in ${KERNEL_IMAGETYPES} ; do
570 size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$type | awk '{print $1}'`
571 if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then
572 warn "This kernel $type (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device. Please reduce the size of the kernel by making more of it modular."
573 fi
574 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500575 fi
576}
577do_sizecheck[dirs] = "${B}"
578
579addtask sizecheck before do_install after do_strip
580
He Zhefe76b1e2016-05-25 04:47:16 -0400581KERNEL_IMAGE_BASE_NAME ?= "${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500582# Don't include the DATETIME variable in the sstate package signatures
583KERNEL_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME"
He Zhefe76b1e2016-05-25 04:47:16 -0400584KERNEL_IMAGE_SYMLINK_NAME ?= "${MACHINE}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500585MODULE_IMAGE_BASE_NAME ?= "modules-${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}"
586MODULE_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME"
587MODULE_TARBALL_BASE_NAME ?= "${MODULE_IMAGE_BASE_NAME}.tgz"
588# Don't include the DATETIME variable in the sstate package signatures
589MODULE_TARBALL_SYMLINK_NAME ?= "modules-${MACHINE}.tgz"
590MODULE_TARBALL_DEPLOY ?= "1"
591
592kernel_do_deploy() {
He Zhefe76b1e2016-05-25 04:47:16 -0400593 for type in ${KERNEL_IMAGETYPES} ; do
594 base_name=${type}-${KERNEL_IMAGE_BASE_NAME}
595 install -m 0644 ${KERNEL_OUTPUT_DIR}/${type} ${DEPLOYDIR}/${base_name}.bin
596 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500597 if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
598 mkdir -p ${D}/lib
599 tar -cvzf ${DEPLOYDIR}/${MODULE_TARBALL_BASE_NAME} -C ${D} lib
600 ln -sf ${MODULE_TARBALL_BASE_NAME} ${DEPLOYDIR}/${MODULE_TARBALL_SYMLINK_NAME}
601 fi
602
He Zhefe76b1e2016-05-25 04:47:16 -0400603 for type in ${KERNEL_IMAGETYPES} ; do
604 base_name=${type}-${KERNEL_IMAGE_BASE_NAME}
605 symlink_name=${type}-${KERNEL_IMAGE_SYMLINK_NAME}
606 ln -sf ${base_name}.bin ${DEPLOYDIR}/${symlink_name}.bin
607 ln -sf ${base_name}.bin ${DEPLOYDIR}/${type}
608 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500609
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500610 cd ${B}
611 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400612 for type in ${KERNEL_IMAGETYPES} ; do
613 if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then
614 echo "Copying deploy ${type} kernel-initramfs image and setting up links..."
615 initramfs_base_name=${type}-${INITRAMFS_BASE_NAME}
616 initramfs_symlink_name=${type}-initramfs-${MACHINE}
617 install -m 0644 ${KERNEL_OUTPUT_DIR}/${type}.initramfs ${DEPLOYDIR}/${initramfs_base_name}.bin
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600618 ln -sf ${initramfs_base_name}.bin ${DEPLOYDIR}/${initramfs_symlink_name}.bin
He Zhefe76b1e2016-05-25 04:47:16 -0400619 fi
620 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500621}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500622do_deploy[cleandirs] = "${DEPLOYDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500623do_deploy[dirs] = "${DEPLOYDIR} ${B}"
624do_deploy[prefuncs] += "package_get_auto_pr"
625
626addtask deploy after do_populate_sysroot
627
628EXPORT_FUNCTIONS do_deploy