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 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 46 | for type in types.split(): |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 47 | typelower = type.lower() |
| 48 | |
| 49 | d.appendVar('PACKAGES', ' ' + 'kernel-image-' + typelower) |
| 50 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 51 | d.setVar('FILES_kernel-image-' + typelower, '/boot/' + type + '-${KERNEL_VERSION_NAME}') |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 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 |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 168 | for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz; do |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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 | fi |
| 239 | } |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 240 | do_bundle_initramfs[dirs] = "${B}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 241 | |
| 242 | python do_devshell_prepend () { |
| 243 | os.environ["LDFLAGS"] = '' |
| 244 | } |
| 245 | |
| 246 | addtask bundle_initramfs after do_install before do_deploy |
| 247 | |
| 248 | kernel_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 Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 263 | 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 Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 267 | mkdir -p "${KERNEL_OUTPUT_DIR}" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 268 | gzip -9c < "${typeformake}" > "${KERNEL_OUTPUT_DIR}/${type}" |
| 269 | break; |
| 270 | fi |
| 271 | done |
| 272 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | do_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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 279 | |
| 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 286 | cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 287 | else |
| 288 | bbnote "no modules to compile" |
| 289 | fi |
| 290 | } |
| 291 | addtask compile_kernelmodules after do_compile before do_strip |
| 292 | |
| 293 | kernel_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 Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 313 | for type in ${KERNEL_IMAGETYPES} ; do |
| 314 | install -m 0644 ${KERNEL_OUTPUT_DIR}/${type} ${D}/${KERNEL_IMAGEDEST}/${type}-${KERNEL_VERSION} |
| 315 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 316 | 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 | } |
| 323 | do_install[prefuncs] += "package_get_auto_pr" |
| 324 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 325 | # Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile |
| 326 | do_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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 355 | addtask shared_workdir after do_compile before do_compile_kernelmodules |
| 356 | addtask shared_workdir_setscene |
| 357 | |
| 358 | do_shared_workdir_setscene () { |
| 359 | exit 1 |
| 360 | } |
| 361 | |
| 362 | emit_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 | |
| 369 | PACKAGEFUNCS += "emit_depmod_pkgdata" |
| 370 | |
| 371 | do_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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 389 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 397 | |
| 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 419 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 422 | fi |
| 423 | } |
| 424 | |
| 425 | # We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware |
| 426 | sysroot_stage_all () { |
| 427 | : |
| 428 | } |
| 429 | |
| 430 | KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} O=${B} oldnoconfig || yes '' | oe_runmake -C ${S} O=${B} oldconfig" |
| 431 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 432 | python 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 | |
| 443 | check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION" |
| 444 | do_configure[prefuncs] += "check_oldest_kernel" |
| 445 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 446 | kernel_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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 462 | |
| 463 | ${KERNEL_CONFIG_COMMAND} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | do_savedefconfig() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 467 | bbplain "Saving defconfig to:\n${B}/defconfig" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 468 | oe_runmake -C ${B} savedefconfig |
| 469 | } |
| 470 | do_savedefconfig[nostamp] = "1" |
| 471 | addtask savedefconfig after do_configure |
| 472 | |
| 473 | inherit cml1 |
| 474 | |
| 475 | EXPORT_FUNCTIONS do_compile do_install do_configure |
| 476 | |
| 477 | # kernel-base becomes kernel-${KERNEL_VERSION} |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 478 | # kernel-image becomes kernel-image-${KERNEL_VERSION} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 479 | PACKAGES = "kernel kernel-base kernel-vmlinux kernel-image kernel-dev kernel-modules" |
| 480 | FILES_${PN} = "" |
| 481 | 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] | 482 | FILES_kernel-image = "" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 483 | FILES_kernel-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} /lib/modules/${KERNEL_VERSION}/build" |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame^] | 484 | FILES_kernel-vmlinux = "/boot/vmlinux-${KERNEL_VERSION_NAME}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 485 | FILES_kernel-modules = "" |
| 486 | RDEPENDS_kernel = "kernel-base" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 487 | # Allow machines to override this dependency if kernel image files are |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 488 | # not wanted in images as standard |
| 489 | RDEPENDS_kernel-base ?= "kernel-image" |
| 490 | PKG_kernel-image = "kernel-image-${@legitimize_package_name('${KERNEL_VERSION}')}" |
| 491 | RDEPENDS_kernel-image += "${@base_conditional('KERNEL_IMAGETYPE', 'vmlinux', 'kernel-vmlinux', '', d)}" |
| 492 | PKG_kernel-base = "kernel-${@legitimize_package_name('${KERNEL_VERSION}')}" |
| 493 | RPROVIDES_kernel-base += "kernel-${KERNEL_VERSION}" |
| 494 | ALLOW_EMPTY_kernel = "1" |
| 495 | ALLOW_EMPTY_kernel-base = "1" |
| 496 | ALLOW_EMPTY_kernel-image = "1" |
| 497 | ALLOW_EMPTY_kernel-modules = "1" |
| 498 | DESCRIPTION_kernel-modules = "Kernel modules meta package" |
| 499 | |
| 500 | pkg_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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 511 | PACKAGESPLITFUNCS_prepend = "split_kernel_packages " |
| 512 | |
| 513 | python split_kernel_packages () { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 514 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 518 | # 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. |
| 521 | do_kernel_link_images() { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 522 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 527 | if [ -f ../../../vmlinuz ]; then |
| 528 | ln -sf ../../../vmlinuz |
| 529 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | do_strip() { |
| 533 | if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 534 | if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then |
| 535 | bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 536 | return |
| 537 | fi |
| 538 | |
| 539 | cd ${B} |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 540 | headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 541 | 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 Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 546 | if ! (echo "$headers" | grep -q "^$str$"); then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 547 | bbwarn "Section not found: $str"; |
| 548 | fi |
| 549 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 550 | "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 551 | }; done |
| 552 | |
| 553 | bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \ |
| 554 | "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" |
| 555 | fi; |
| 556 | } |
| 557 | do_strip[dirs] = "${B}" |
| 558 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 559 | addtask do_strip before do_sizecheck after do_kernel_link_images |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 560 | |
| 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 |
| 563 | do_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 Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 569 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 575 | fi |
| 576 | } |
| 577 | do_sizecheck[dirs] = "${B}" |
| 578 | |
| 579 | addtask sizecheck before do_install after do_strip |
| 580 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 581 | KERNEL_IMAGE_BASE_NAME ?= "${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 582 | # Don't include the DATETIME variable in the sstate package signatures |
| 583 | KERNEL_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 584 | KERNEL_IMAGE_SYMLINK_NAME ?= "${MACHINE}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 585 | MODULE_IMAGE_BASE_NAME ?= "modules-${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}" |
| 586 | MODULE_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME" |
| 587 | MODULE_TARBALL_BASE_NAME ?= "${MODULE_IMAGE_BASE_NAME}.tgz" |
| 588 | # Don't include the DATETIME variable in the sstate package signatures |
| 589 | MODULE_TARBALL_SYMLINK_NAME ?= "modules-${MACHINE}.tgz" |
| 590 | MODULE_TARBALL_DEPLOY ?= "1" |
| 591 | |
| 592 | kernel_do_deploy() { |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 593 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 597 | 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 Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 603 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 609 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 610 | cd ${B} |
| 611 | # Update deploy directory |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 612 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 618 | ln -sf ${initramfs_base_name}.bin ${DEPLOYDIR}/${initramfs_symlink_name}.bin |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 619 | fi |
| 620 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 621 | } |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 622 | do_deploy[cleandirs] = "${DEPLOYDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 623 | do_deploy[dirs] = "${DEPLOYDIR} ${B}" |
| 624 | do_deploy[prefuncs] += "package_get_auto_pr" |
| 625 | |
| 626 | addtask deploy after do_populate_sysroot |
| 627 | |
| 628 | EXPORT_FUNCTIONS do_deploy |