Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | inherit linux-kernel-base kernel-module-split |
| 2 | |
| 3 | PROVIDES += "virtual/kernel" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 4 | DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native depmodwrapper-cross bc-native lzop-native" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | |
| 6 | S = "${STAGING_KERNEL_DIR}" |
| 7 | B = "${WORKDIR}/build" |
| 8 | KBUILD_OUTPUT = "${B}" |
| 9 | OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT" |
| 10 | |
| 11 | # we include gcc above, we dont need virtual/libc |
| 12 | INHIBIT_DEFAULT_DEPS = "1" |
| 13 | |
| 14 | KERNEL_IMAGETYPE ?= "zImage" |
| 15 | INITRAMFS_IMAGE ?= "" |
| 16 | INITRAMFS_TASK ?= "" |
| 17 | INITRAMFS_IMAGE_BUNDLE ?= "" |
| 18 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 19 | # 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. |
| 25 | KERNEL_VERSION_NAME = "${@d.getVar('KERNEL_VERSION', True) or ""}" |
| 26 | KERNEL_VERSION_NAME[vardepvalue] = "${LINUX_VERSION}" |
| 27 | KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION', True))}" |
| 28 | KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}" |
| 29 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | python __anonymous () { |
| 31 | import re |
| 32 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 33 | # 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 43 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | |
| 67 | image = d.getVar('INITRAMFS_IMAGE', True) |
| 68 | if image: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 69 | d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | |
| 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 | |
| 94 | KERNEL_CLASSES ?= " kernel-uimage " |
| 95 | inherit ${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. |
| 101 | do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}" |
| 102 | do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}" |
| 103 | base_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 | |
| 121 | inherit kernel-arch deploy |
| 122 | |
| 123 | PACKAGES_DYNAMIC += "^kernel-module-.*" |
| 124 | PACKAGES_DYNAMIC += "^kernel-image-.*" |
| 125 | PACKAGES_DYNAMIC += "^kernel-firmware-.*" |
| 126 | |
| 127 | export OS = "${TARGET_OS}" |
| 128 | export CROSS_COMPILE = "${TARGET_PREFIX}" |
| 129 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 130 | KERNEL_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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 133 | |
| 134 | KERNEL_RELEASE ?= "${KERNEL_VERSION}" |
| 135 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 136 | # The directory where built kernel lies in the kernel tree |
| 137 | KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | KERNEL_IMAGEDEST = "boot" |
| 139 | |
| 140 | # |
| 141 | # configuration |
| 142 | # |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 143 | export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE", True) or "ttyS0"}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 144 | |
| 145 | KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}" |
| 146 | |
| 147 | KERNEL_LOCALVERSION ?= "" |
| 148 | |
| 149 | # kernels are generally machine specific |
| 150 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 151 | |
| 152 | # U-Boot support |
| 153 | UBOOT_ENTRYPOINT ?= "20008000" |
| 154 | UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}" |
| 155 | |
| 156 | # Some Linux kernel configurations need additional parameters on the command line |
| 157 | KERNEL_EXTRA_ARGS ?= "" |
| 158 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 159 | EXTRA_OEMAKE = " HOSTCC="${BUILD_CC}" HOSTCPP="${BUILD_CPP}"" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 160 | KERNEL_ALT_IMAGETYPE ??= "" |
| 161 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 162 | copy_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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 203 | INITRAMFS_BASE_NAME ?= "initramfs-${PV}-${PR}-${MACHINE}-${DATETIME}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 204 | INITRAMFS_BASE_NAME[vardepsexclude] = "DATETIME" |
| 205 | do_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 Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 209 | # 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 222 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio |
| 223 | kernel_do_compile |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 224 | # 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 232 | ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$type.initramfs |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 233 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 238 | # Update install area |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 239 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 244 | fi |
| 245 | } |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 246 | do_bundle_initramfs[dirs] = "${B}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 247 | |
| 248 | python do_devshell_prepend () { |
| 249 | os.environ["LDFLAGS"] = '' |
| 250 | } |
| 251 | |
| 252 | addtask bundle_initramfs after do_install before do_deploy |
| 253 | |
| 254 | kernel_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 Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 269 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | do_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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 284 | |
| 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 291 | cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 292 | else |
| 293 | bbnote "no modules to compile" |
| 294 | fi |
| 295 | } |
| 296 | addtask compile_kernelmodules after do_compile before do_strip |
| 297 | |
| 298 | kernel_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 Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 318 | for type in ${KERNEL_IMAGETYPES} ; do |
| 319 | install -m 0644 ${KERNEL_OUTPUT_DIR}/${type} ${D}/${KERNEL_IMAGEDEST}/${type}-${KERNEL_VERSION} |
| 320 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 321 | 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 | } |
| 328 | do_install[prefuncs] += "package_get_auto_pr" |
| 329 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 330 | # Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile |
| 331 | do_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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 360 | addtask shared_workdir after do_compile before do_compile_kernelmodules |
| 361 | addtask shared_workdir_setscene |
| 362 | |
| 363 | do_shared_workdir_setscene () { |
| 364 | exit 1 |
| 365 | } |
| 366 | |
| 367 | emit_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 | |
| 374 | PACKAGEFUNCS += "emit_depmod_pkgdata" |
| 375 | |
| 376 | do_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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 394 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 402 | |
| 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 424 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 427 | fi |
| 428 | } |
| 429 | |
| 430 | # We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware |
| 431 | sysroot_stage_all () { |
| 432 | : |
| 433 | } |
| 434 | |
| 435 | KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} O=${B} oldnoconfig || yes '' | oe_runmake -C ${S} O=${B} oldconfig" |
| 436 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 437 | python 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 | |
| 448 | check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION" |
| 449 | do_configure[prefuncs] += "check_oldest_kernel" |
| 450 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 451 | kernel_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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 467 | |
| 468 | ${KERNEL_CONFIG_COMMAND} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | do_savedefconfig() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 472 | bbplain "Saving defconfig to:\n${B}/defconfig" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 473 | oe_runmake -C ${B} savedefconfig |
| 474 | } |
| 475 | do_savedefconfig[nostamp] = "1" |
| 476 | addtask savedefconfig after do_configure |
| 477 | |
| 478 | inherit cml1 |
| 479 | |
| 480 | EXPORT_FUNCTIONS do_compile do_install do_configure |
| 481 | |
| 482 | # kernel-base becomes kernel-${KERNEL_VERSION} |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 483 | # kernel-image becomes kernel-image-${KERNEL_VERSION} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 484 | PACKAGES = "kernel kernel-base kernel-vmlinux kernel-image kernel-dev kernel-modules" |
| 485 | FILES_${PN} = "" |
| 486 | FILES_kernel-base = "/lib/modules/${KERNEL_VERSION}/modules.order /lib/modules/${KERNEL_VERSION}/modules.builtin" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 487 | FILES_kernel-image = "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 488 | FILES_kernel-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} /lib/modules/${KERNEL_VERSION}/build" |
| 489 | FILES_kernel-vmlinux = "/boot/vmlinux*" |
| 490 | FILES_kernel-modules = "" |
| 491 | RDEPENDS_kernel = "kernel-base" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 492 | # Allow machines to override this dependency if kernel image files are |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 493 | # not wanted in images as standard |
| 494 | RDEPENDS_kernel-base ?= "kernel-image" |
| 495 | PKG_kernel-image = "kernel-image-${@legitimize_package_name('${KERNEL_VERSION}')}" |
| 496 | RDEPENDS_kernel-image += "${@base_conditional('KERNEL_IMAGETYPE', 'vmlinux', 'kernel-vmlinux', '', d)}" |
| 497 | PKG_kernel-base = "kernel-${@legitimize_package_name('${KERNEL_VERSION}')}" |
| 498 | RPROVIDES_kernel-base += "kernel-${KERNEL_VERSION}" |
| 499 | ALLOW_EMPTY_kernel = "1" |
| 500 | ALLOW_EMPTY_kernel-base = "1" |
| 501 | ALLOW_EMPTY_kernel-image = "1" |
| 502 | ALLOW_EMPTY_kernel-modules = "1" |
| 503 | DESCRIPTION_kernel-modules = "Kernel modules meta package" |
| 504 | |
| 505 | pkg_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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 516 | PACKAGESPLITFUNCS_prepend = "split_kernel_packages " |
| 517 | |
| 518 | python split_kernel_packages () { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 519 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 523 | # 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. |
| 526 | do_kernel_link_images() { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 527 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 532 | if [ -f ../../../vmlinuz ]; then |
| 533 | ln -sf ../../../vmlinuz |
| 534 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | do_strip() { |
| 538 | if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 539 | if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then |
| 540 | bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 541 | return |
| 542 | fi |
| 543 | |
| 544 | cd ${B} |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 545 | headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 546 | 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 Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 551 | if ! (echo "$headers" | grep -q "^$str$"); then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 552 | bbwarn "Section not found: $str"; |
| 553 | fi |
| 554 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 555 | "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 556 | }; done |
| 557 | |
| 558 | bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \ |
| 559 | "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" |
| 560 | fi; |
| 561 | } |
| 562 | do_strip[dirs] = "${B}" |
| 563 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 564 | addtask do_strip before do_sizecheck after do_kernel_link_images |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 565 | |
| 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 |
| 568 | do_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 Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 574 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 580 | fi |
| 581 | } |
| 582 | do_sizecheck[dirs] = "${B}" |
| 583 | |
| 584 | addtask sizecheck before do_install after do_strip |
| 585 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 586 | KERNEL_IMAGE_BASE_NAME ?= "${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 587 | # Don't include the DATETIME variable in the sstate package signatures |
| 588 | KERNEL_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 589 | KERNEL_IMAGE_SYMLINK_NAME ?= "${MACHINE}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 590 | MODULE_IMAGE_BASE_NAME ?= "modules-${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}" |
| 591 | MODULE_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME" |
| 592 | MODULE_TARBALL_BASE_NAME ?= "${MODULE_IMAGE_BASE_NAME}.tgz" |
| 593 | # Don't include the DATETIME variable in the sstate package signatures |
| 594 | MODULE_TARBALL_SYMLINK_NAME ?= "modules-${MACHINE}.tgz" |
| 595 | MODULE_TARBALL_DEPLOY ?= "1" |
| 596 | |
| 597 | kernel_do_deploy() { |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 598 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 602 | 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 Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 608 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 614 | |
| 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 Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 619 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 625 | ln -sf ${initramfs_base_name}.bin ${DEPLOYDIR}/${initramfs_symlink_name}.bin |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 626 | fi |
| 627 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 628 | } |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 629 | do_deploy[cleandirs] = "${DEPLOYDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 630 | do_deploy[dirs] = "${DEPLOYDIR} ${B}" |
| 631 | do_deploy[prefuncs] += "package_get_auto_pr" |
| 632 | |
| 633 | addtask deploy after do_populate_sysroot |
| 634 | |
| 635 | EXPORT_FUNCTIONS do_deploy |