blob: 25a153cd2042d3a4b21d78efd921a8fccfd7914c [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
46 for type in typeformake.split():
47 typelower = type.lower()
48
49 d.appendVar('PACKAGES', ' ' + 'kernel-image-' + typelower)
50
51 d.setVar('FILES_kernel-image-' + typelower, '/boot/' + type + '*')
52
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
168 for img in cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz; do
169 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 # Update install area
He Zhefe76b1e2016-05-25 04:47:16 -0400239 for type in ${KERNEL_IMAGETYPES} ; do
240 echo "There is kernel image bundled with initramfs: ${B}/${KERNEL_OUTPUT_DIR}/$type.initramfs"
241 install -m 0644 ${B}/${KERNEL_OUTPUT_DIR}/$type.initramfs ${D}/boot/$type-initramfs-${MACHINE}.bin
242 echo "${B}/${KERNEL_OUTPUT_DIR}/$type.initramfs"
243 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 fi
245}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600246do_bundle_initramfs[dirs] = "${B}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247
248python do_devshell_prepend () {
249 os.environ["LDFLAGS"] = ''
250}
251
252addtask bundle_initramfs after do_install before do_deploy
253
254kernel_do_compile() {
255 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
256 # The $use_alternate_initrd is only set from
257 # do_bundle_initramfs() This variable is specifically for the
258 # case where we are making a second pass at the kernel
259 # compilation and we want to force the kernel build to use a
260 # different initramfs image. The way to do that in the kernel
261 # is to specify:
262 # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio
263 if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then
264 # The old style way of copying an prebuilt image and building it
265 # is turned on via INTIRAMFS_TASK != ""
266 copy_initramfs
267 use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio
268 fi
He Zhefe76b1e2016-05-25 04:47:16 -0400269 for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do
270 oe_runmake ${typeformake} CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd
271 for type in ${KERNEL_IMAGETYPES} ; do
272 if test "${typeformake}.gz" = "${type}"; then
273 gzip -9c < "${typeformake}" > "${KERNEL_OUTPUT_DIR}/${type}"
274 break;
275 fi
276 done
277 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500278}
279
280do_compile_kernelmodules() {
281 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
282 if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then
283 oe_runmake -C ${B} ${PARALLEL_MAKE} modules CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500284
285 # Module.symvers gets updated during the
286 # building of the kernel modules. We need to
287 # update this in the shared workdir since some
288 # external kernel modules has a dependency on
289 # other kernel modules and will look at this
290 # file to do symbol lookups
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600291 cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292 else
293 bbnote "no modules to compile"
294 fi
295}
296addtask compile_kernelmodules after do_compile before do_strip
297
298kernel_do_install() {
299 #
300 # First install the modules
301 #
302 unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
303 if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
304 oe_runmake DEPMOD=echo INSTALL_MOD_PATH="${D}" modules_install
305 rm "${D}/lib/modules/${KERNEL_VERSION}/build"
306 rm "${D}/lib/modules/${KERNEL_VERSION}/source"
307 # If the kernel/ directory is empty remove it to prevent QA issues
308 rmdir --ignore-fail-on-non-empty "${D}/lib/modules/${KERNEL_VERSION}/kernel"
309 else
310 bbnote "no modules to install"
311 fi
312
313 #
314 # Install various kernel output (zImage, map file, config, module support files)
315 #
316 install -d ${D}/${KERNEL_IMAGEDEST}
317 install -d ${D}/boot
He Zhefe76b1e2016-05-25 04:47:16 -0400318 for type in ${KERNEL_IMAGETYPES} ; do
319 install -m 0644 ${KERNEL_OUTPUT_DIR}/${type} ${D}/${KERNEL_IMAGEDEST}/${type}-${KERNEL_VERSION}
320 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500321 install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION}
322 install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION}
323 install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION}
324 [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION}
325 install -d ${D}${sysconfdir}/modules-load.d
326 install -d ${D}${sysconfdir}/modprobe.d
327}
328do_install[prefuncs] += "package_get_auto_pr"
329
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600330# Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile
331do_kernel_version_sanity_check() {
332 # The Makefile determines the kernel version shown at runtime
333 # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile
334 VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//)
335 PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
336 SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//)
337 EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//)
338
339 # Build a string for regex and a plain version string
340 reg="^${VERSION}\.${PATCHLEVEL}"
341 vers="${VERSION}.${PATCHLEVEL}"
342 if [ -n "${SUBLEVEL}" ]; then
343 # Ignoring a SUBLEVEL of zero is fine
344 if [ "${SUBLEVEL}" = "0" ]; then
345 reg="${reg}(\.${SUBLEVEL})?"
346 else
347 reg="${reg}\.${SUBLEVEL}"
348 vers="${vers}.${SUBLEVEL}"
349 fi
350 fi
351 vers="${vers}${EXTRAVERSION}"
352 reg="${reg}${EXTRAVERSION}"
353
354 if [ -z `echo ${PV} | grep -E "${reg}"` ]; then
355 bbfatal "Package Version (${PV}) does not match of kernel being built (${vers}). Please update the PV variable to match the kernel source."
356 fi
357 exit 0
358}
359
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500360addtask shared_workdir after do_compile before do_compile_kernelmodules
361addtask shared_workdir_setscene
362
363do_shared_workdir_setscene () {
364 exit 1
365}
366
367emit_depmod_pkgdata() {
368 # Stash data for depmod
369 install -d ${PKGDESTWORK}/kernel-depmod/
370 echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/kernel-depmod/kernel-abiversion
371 cp ${B}/System.map ${PKGDESTWORK}/kernel-depmod/System.map-${KERNEL_VERSION}
372}
373
374PACKAGEFUNCS += "emit_depmod_pkgdata"
375
376do_shared_workdir () {
377 cd ${B}
378
379 kerneldir=${STAGING_KERNEL_BUILDDIR}
380 install -d $kerneldir
381
382 #
383 # Store the kernel version in sysroots for module-base.bbclass
384 #
385
386 echo "${KERNEL_VERSION}" > $kerneldir/kernel-abiversion
387
388 # Copy files required for module builds
389 cp System.map $kerneldir/System.map-${KERNEL_VERSION}
390 cp Module.symvers $kerneldir/
391 cp .config $kerneldir/
392 mkdir -p $kerneldir/include/config
393 cp include/config/kernel.release $kerneldir/include/config/kernel.release
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600394 if [ -e certs/signing_key.pem ]; then
395 # The signing_key.* files are stored in the certs/ dir in
396 # newer Linux kernels
397 mkdir -p $kerneldir/certs
398 cp certs/signing_key.* $kerneldir/certs/
399 elif [ -e signing_key.priv ]; then
400 cp signing_key.* $kerneldir/
401 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500402
403 # We can also copy over all the generated files and avoid special cases
404 # like version.h, but we've opted to keep this small until file creep starts
405 # to happen
406 if [ -e include/linux/version.h ]; then
407 mkdir -p $kerneldir/include/linux
408 cp include/linux/version.h $kerneldir/include/linux/version.h
409 fi
410
411 # As of Linux kernel version 3.0.1, the clean target removes
412 # arch/powerpc/lib/crtsavres.o which is present in
413 # KBUILD_LDFLAGS_MODULE, making it required to build external modules.
414 if [ ${ARCH} = "powerpc" ]; then
415 mkdir -p $kerneldir/arch/powerpc/lib/
416 cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o
417 fi
418
419 if [ -d include/generated ]; then
420 mkdir -p $kerneldir/include/generated/
421 cp -fR include/generated/* $kerneldir/include/generated/
422 fi
423
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500424 if [ -d arch/${ARCH}/include/generated ]; then
425 mkdir -p $kerneldir/arch/${ARCH}/include/generated/
426 cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500427 fi
428}
429
430# We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware
431sysroot_stage_all () {
432 :
433}
434
435KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} O=${B} oldnoconfig || yes '' | oe_runmake -C ${S} O=${B} oldconfig"
436
He Zhefe76b1e2016-05-25 04:47:16 -0400437python check_oldest_kernel() {
438 oldest_kernel = d.getVar('OLDEST_KERNEL', True)
439 kernel_version = d.getVar('KERNEL_VERSION', True)
440 tclibc = d.getVar('TCLIBC', True)
441 if tclibc == 'glibc':
442 kernel_version = kernel_version.split('-', 1)[0]
443 if oldest_kernel and kernel_version:
444 if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0:
445 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))
446}
447
448check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION"
449do_configure[prefuncs] += "check_oldest_kernel"
450
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500451kernel_do_configure() {
452 # fixes extra + in /lib/modules/2.6.37+
453 # $ scripts/setlocalversion . => +
454 # $ make kernelversion => 2.6.37
455 # $ make kernelrelease => 2.6.37+
456 touch ${B}/.scmversion ${S}/.scmversion
457
458 if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then
459 mv "${S}/.config" "${B}/.config"
460 fi
461
462 # Copy defconfig to .config if .config does not exist. This allows
463 # recipes to manage the .config themselves in do_configure_prepend().
464 if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then
465 cp "${WORKDIR}/defconfig" "${B}/.config"
466 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500467
468 ${KERNEL_CONFIG_COMMAND}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500469}
470
471do_savedefconfig() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600472 bbplain "Saving defconfig to:\n${B}/defconfig"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500473 oe_runmake -C ${B} savedefconfig
474}
475do_savedefconfig[nostamp] = "1"
476addtask savedefconfig after do_configure
477
478inherit cml1
479
480EXPORT_FUNCTIONS do_compile do_install do_configure
481
482# kernel-base becomes kernel-${KERNEL_VERSION}
He Zhefe76b1e2016-05-25 04:47:16 -0400483# kernel-image becomes kernel-image-${KERNEL_VERSION}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500484PACKAGES = "kernel kernel-base kernel-vmlinux kernel-image kernel-dev kernel-modules"
485FILES_${PN} = ""
486FILES_kernel-base = "/lib/modules/${KERNEL_VERSION}/modules.order /lib/modules/${KERNEL_VERSION}/modules.builtin"
He Zhefe76b1e2016-05-25 04:47:16 -0400487FILES_kernel-image = ""
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500488FILES_kernel-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} /lib/modules/${KERNEL_VERSION}/build"
489FILES_kernel-vmlinux = "/boot/vmlinux*"
490FILES_kernel-modules = ""
491RDEPENDS_kernel = "kernel-base"
He Zhefe76b1e2016-05-25 04:47:16 -0400492# Allow machines to override this dependency if kernel image files are
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500493# not wanted in images as standard
494RDEPENDS_kernel-base ?= "kernel-image"
495PKG_kernel-image = "kernel-image-${@legitimize_package_name('${KERNEL_VERSION}')}"
496RDEPENDS_kernel-image += "${@base_conditional('KERNEL_IMAGETYPE', 'vmlinux', 'kernel-vmlinux', '', d)}"
497PKG_kernel-base = "kernel-${@legitimize_package_name('${KERNEL_VERSION}')}"
498RPROVIDES_kernel-base += "kernel-${KERNEL_VERSION}"
499ALLOW_EMPTY_kernel = "1"
500ALLOW_EMPTY_kernel-base = "1"
501ALLOW_EMPTY_kernel-image = "1"
502ALLOW_EMPTY_kernel-modules = "1"
503DESCRIPTION_kernel-modules = "Kernel modules meta package"
504
505pkg_postinst_kernel-base () {
506 if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then
507 mkdir -p $D/lib/modules/${KERNEL_VERSION}
508 fi
509 if [ -n "$D" ]; then
510 depmodwrapper -a -b $D ${KERNEL_VERSION}
511 else
512 depmod -a ${KERNEL_VERSION}
513 fi
514}
515
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500516PACKAGESPLITFUNCS_prepend = "split_kernel_packages "
517
518python split_kernel_packages () {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500519 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='')
520}
521
522# Many scripts want to look in arch/$arch/boot for the bootable
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600523# image. This poses a problem for vmlinux and vmlinuz based
524# booting. This task arranges to have vmlinux and vmlinuz appear
525# in the normalized directory location.
526do_kernel_link_images() {
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500527 if [ ! -d "${B}/arch/${ARCH}/boot" ]; then
528 mkdir ${B}/arch/${ARCH}/boot
529 fi
530 cd ${B}/arch/${ARCH}/boot
531 ln -sf ../../../vmlinux
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600532 if [ -f ../../../vmlinuz ]; then
533 ln -sf ../../../vmlinuz
534 fi
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500535}
536
537do_strip() {
538 if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then
He Zhefe76b1e2016-05-25 04:47:16 -0400539 if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then
540 bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500541 return
542 fi
543
544 cd ${B}
He Zhefe76b1e2016-05-25 04:47:16 -0400545 headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500546 grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \
547 sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \
548 gawk '{print $1}'`
549
550 for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do {
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500551 if ! (echo "$headers" | grep -q "^$str$"); then
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500552 bbwarn "Section not found: $str";
553 fi
554
He Zhefe76b1e2016-05-25 04:47:16 -0400555 "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500556 }; done
557
558 bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \
559 "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}"
560 fi;
561}
562do_strip[dirs] = "${B}"
563
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600564addtask do_strip before do_sizecheck after do_kernel_link_images
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500565
566# Support checking the kernel size since some kernels need to reside in partitions
567# with a fixed length or there is a limit in transferring the kernel to memory
568do_sizecheck() {
569 if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then
570 invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'`
571 if [ -n "$invalid" ]; then
572 die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integerx (The unit is Kbytes)"
573 fi
He Zhefe76b1e2016-05-25 04:47:16 -0400574 for type in ${KERNEL_IMAGETYPES} ; do
575 size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$type | awk '{print $1}'`
576 if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then
577 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."
578 fi
579 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500580 fi
581}
582do_sizecheck[dirs] = "${B}"
583
584addtask sizecheck before do_install after do_strip
585
He Zhefe76b1e2016-05-25 04:47:16 -0400586KERNEL_IMAGE_BASE_NAME ?= "${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500587# Don't include the DATETIME variable in the sstate package signatures
588KERNEL_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME"
He Zhefe76b1e2016-05-25 04:47:16 -0400589KERNEL_IMAGE_SYMLINK_NAME ?= "${MACHINE}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500590MODULE_IMAGE_BASE_NAME ?= "modules-${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}"
591MODULE_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME"
592MODULE_TARBALL_BASE_NAME ?= "${MODULE_IMAGE_BASE_NAME}.tgz"
593# Don't include the DATETIME variable in the sstate package signatures
594MODULE_TARBALL_SYMLINK_NAME ?= "modules-${MACHINE}.tgz"
595MODULE_TARBALL_DEPLOY ?= "1"
596
597kernel_do_deploy() {
He Zhefe76b1e2016-05-25 04:47:16 -0400598 for type in ${KERNEL_IMAGETYPES} ; do
599 base_name=${type}-${KERNEL_IMAGE_BASE_NAME}
600 install -m 0644 ${KERNEL_OUTPUT_DIR}/${type} ${DEPLOYDIR}/${base_name}.bin
601 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500602 if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then
603 mkdir -p ${D}/lib
604 tar -cvzf ${DEPLOYDIR}/${MODULE_TARBALL_BASE_NAME} -C ${D} lib
605 ln -sf ${MODULE_TARBALL_BASE_NAME} ${DEPLOYDIR}/${MODULE_TARBALL_SYMLINK_NAME}
606 fi
607
He Zhefe76b1e2016-05-25 04:47:16 -0400608 for type in ${KERNEL_IMAGETYPES} ; do
609 base_name=${type}-${KERNEL_IMAGE_BASE_NAME}
610 symlink_name=${type}-${KERNEL_IMAGE_SYMLINK_NAME}
611 ln -sf ${base_name}.bin ${DEPLOYDIR}/${symlink_name}.bin
612 ln -sf ${base_name}.bin ${DEPLOYDIR}/${type}
613 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500614
615 cp ${COREBASE}/meta/files/deploydir_readme.txt ${DEPLOYDIR}/README_-_DO_NOT_DELETE_FILES_IN_THIS_DIRECTORY.txt
616
617 cd ${B}
618 # Update deploy directory
He Zhefe76b1e2016-05-25 04:47:16 -0400619 for type in ${KERNEL_IMAGETYPES} ; do
620 if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then
621 echo "Copying deploy ${type} kernel-initramfs image and setting up links..."
622 initramfs_base_name=${type}-${INITRAMFS_BASE_NAME}
623 initramfs_symlink_name=${type}-initramfs-${MACHINE}
624 install -m 0644 ${KERNEL_OUTPUT_DIR}/${type}.initramfs ${DEPLOYDIR}/${initramfs_base_name}.bin
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600625 ln -sf ${initramfs_base_name}.bin ${DEPLOYDIR}/${initramfs_symlink_name}.bin
He Zhefe76b1e2016-05-25 04:47:16 -0400626 fi
627 done
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500628}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500629do_deploy[cleandirs] = "${DEPLOYDIR}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500630do_deploy[dirs] = "${DEPLOYDIR} ${B}"
631do_deploy[prefuncs] += "package_get_auto_pr"
632
633addtask deploy after do_populate_sysroot
634
635EXPORT_FUNCTIONS do_deploy