| 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" | 
|  | 4 | DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native depmodwrapper-cross bc-native" | 
|  | 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 |  | 
|  | 130 | KERNEL_PRIORITY ?= "${@int(d.getVar('PV',1).split('-')[0].split('+')[0].split('.')[0]) * 10000 + \ | 
|  | 131 | int(d.getVar('PV',1).split('-')[0].split('+')[0].split('.')[1]) * 100 + \ | 
|  | 132 | int(d.getVar('PV',1).split('-')[0].split('+')[0].split('.')[-1])}" | 
|  | 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 | # | 
|  | 143 | export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE",1) or "ttyS0"}" | 
|  | 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 |  | 
|  | 159 | # For the kernel, we don't want the '-e MAKEFLAGS=' in EXTRA_OEMAKE. | 
|  | 160 | # We don't want to override kernel Makefile variables from the environment | 
|  | 161 | EXTRA_OEMAKE = "" | 
|  | 162 |  | 
|  | 163 | KERNEL_ALT_IMAGETYPE ??= "" | 
|  | 164 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 165 | copy_initramfs() { | 
|  | 166 | echo "Copying initramfs into ./usr ..." | 
|  | 167 | # In case the directory is not created yet from the first pass compile: | 
|  | 168 | mkdir -p ${B}/usr | 
|  | 169 | # Find and use the first initramfs image archive type we find | 
|  | 170 | rm -f ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio | 
|  | 171 | for img in cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz; do | 
|  | 172 | if [ -e "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.$img" ]; then | 
|  | 173 | cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE}-${MACHINE}.$img ${B}/usr/. | 
|  | 174 | case $img in | 
|  | 175 | *gz) | 
|  | 176 | echo "gzip decompressing image" | 
|  | 177 | gunzip -f ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img | 
|  | 178 | break | 
|  | 179 | ;; | 
|  | 180 | *lz4) | 
|  | 181 | echo "lz4 decompressing image" | 
|  | 182 | lz4 -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img | 
|  | 183 | break | 
|  | 184 | ;; | 
|  | 185 | *lzo) | 
|  | 186 | echo "lzo decompressing image" | 
|  | 187 | lzop -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img | 
|  | 188 | break | 
|  | 189 | ;; | 
|  | 190 | *lzma) | 
|  | 191 | echo "lzma decompressing image" | 
|  | 192 | lzma -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img | 
|  | 193 | break | 
|  | 194 | ;; | 
|  | 195 | *xz) | 
|  | 196 | echo "xz decompressing image" | 
|  | 197 | xz -df ${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.$img | 
|  | 198 | break | 
|  | 199 | ;; | 
|  | 200 | esac | 
|  | 201 | fi | 
|  | 202 | done | 
|  | 203 | echo "Finished copy of initramfs into ./usr" | 
|  | 204 | } | 
|  | 205 |  | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 206 | INITRAMFS_BASE_NAME = "initramfs-${PV}-${PR}-${MACHINE}-${DATETIME}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 207 | INITRAMFS_BASE_NAME[vardepsexclude] = "DATETIME" | 
|  | 208 | do_bundle_initramfs () { | 
|  | 209 | if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then | 
|  | 210 | echo "Creating a kernel image with a bundled initramfs..." | 
|  | 211 | copy_initramfs | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 212 | # Backing up kernel image relies on its type(regular file or symbolic link) | 
|  | 213 | tmp_path="" | 
|  | 214 | for type in ${KERNEL_IMAGETYPES} ; do | 
|  | 215 | if [ -h ${KERNEL_OUTPUT_DIR}/$type ] ; then | 
|  | 216 | linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$type` | 
|  | 217 | realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$type` | 
|  | 218 | mv -f $realpath $realpath.bak | 
|  | 219 | tmp_path=$tmp_path" "$type"#"$linkpath"#"$realpath | 
|  | 220 | elif [ -f ${KERNEL_OUTPUT_DIR}/$type ]; then | 
|  | 221 | mv -f ${KERNEL_OUTPUT_DIR}/$type ${KERNEL_OUTPUT_DIR}/$type.bak | 
|  | 222 | tmp_path=$tmp_path" "$type"##" | 
|  | 223 | fi | 
|  | 224 | done | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 225 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio | 
|  | 226 | kernel_do_compile | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 227 | # Restoring kernel image | 
|  | 228 | for tp in $tmp_path ; do | 
|  | 229 | type=`echo $tp|cut -d "#" -f 1` | 
|  | 230 | linkpath=`echo $tp|cut -d "#" -f 2` | 
|  | 231 | realpath=`echo $tp|cut -d "#" -f 3` | 
|  | 232 | if [ -n "$realpath" ]; then | 
|  | 233 | mv -f $realpath $realpath.initramfs | 
|  | 234 | mv -f $realpath.bak $realpath | 
|  | 235 | cd ${B}/${KERNEL_OUTPUT_DIR} | 
|  | 236 | ln -sf $linkpath.initramfs | 
|  | 237 | else | 
|  | 238 | mv -f ${KERNEL_OUTPUT_DIR}/$type ${KERNEL_OUTPUT_DIR}/$type.initramfs | 
|  | 239 | mv -f ${KERNEL_OUTPUT_DIR}/$type.bak ${KERNEL_OUTPUT_DIR}/$type | 
|  | 240 | fi | 
|  | 241 | done | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 242 | # Update install area | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 243 | for type in ${KERNEL_IMAGETYPES} ; do | 
|  | 244 | echo "There is kernel image bundled with initramfs: ${B}/${KERNEL_OUTPUT_DIR}/$type.initramfs" | 
|  | 245 | install -m 0644 ${B}/${KERNEL_OUTPUT_DIR}/$type.initramfs ${D}/boot/$type-initramfs-${MACHINE}.bin | 
|  | 246 | echo "${B}/${KERNEL_OUTPUT_DIR}/$type.initramfs" | 
|  | 247 | done | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 248 | fi | 
|  | 249 | } | 
|  | 250 |  | 
|  | 251 | python do_devshell_prepend () { | 
|  | 252 | os.environ["LDFLAGS"] = '' | 
|  | 253 | } | 
|  | 254 |  | 
|  | 255 | addtask bundle_initramfs after do_install before do_deploy | 
|  | 256 |  | 
|  | 257 | kernel_do_compile() { | 
|  | 258 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE | 
|  | 259 | # The $use_alternate_initrd is only set from | 
|  | 260 | # do_bundle_initramfs() This variable is specifically for the | 
|  | 261 | # case where we are making a second pass at the kernel | 
|  | 262 | # compilation and we want to force the kernel build to use a | 
|  | 263 | # different initramfs image.  The way to do that in the kernel | 
|  | 264 | # is to specify: | 
|  | 265 | # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio | 
|  | 266 | if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then | 
|  | 267 | # The old style way of copying an prebuilt image and building it | 
|  | 268 | # is turned on via INTIRAMFS_TASK != "" | 
|  | 269 | copy_initramfs | 
|  | 270 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE}-${MACHINE}.cpio | 
|  | 271 | fi | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 272 | for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do | 
|  | 273 | oe_runmake ${typeformake} CC="${KERNEL_CC}" LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd | 
|  | 274 | for type in ${KERNEL_IMAGETYPES} ; do | 
|  | 275 | if test "${typeformake}.gz" = "${type}"; then | 
|  | 276 | gzip -9c < "${typeformake}" > "${KERNEL_OUTPUT_DIR}/${type}" | 
|  | 277 | break; | 
|  | 278 | fi | 
|  | 279 | done | 
|  | 280 | done | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | } | 
|  | 282 |  | 
|  | 283 | do_compile_kernelmodules() { | 
|  | 284 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE | 
|  | 285 | if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then | 
|  | 286 | 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] | 287 |  | 
|  | 288 | # Module.symvers gets updated during the | 
|  | 289 | # building of the kernel modules. We need to | 
|  | 290 | # update this in the shared workdir since some | 
|  | 291 | # external kernel modules has a dependency on | 
|  | 292 | # other kernel modules and will look at this | 
|  | 293 | # file to do symbol lookups | 
|  | 294 | cp Module.symvers ${STAGING_KERNEL_BUILDDIR}/ | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 295 | else | 
|  | 296 | bbnote "no modules to compile" | 
|  | 297 | fi | 
|  | 298 | } | 
|  | 299 | addtask compile_kernelmodules after do_compile before do_strip | 
|  | 300 |  | 
|  | 301 | kernel_do_install() { | 
|  | 302 | # | 
|  | 303 | # First install the modules | 
|  | 304 | # | 
|  | 305 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE | 
|  | 306 | if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then | 
|  | 307 | oe_runmake DEPMOD=echo INSTALL_MOD_PATH="${D}" modules_install | 
|  | 308 | rm "${D}/lib/modules/${KERNEL_VERSION}/build" | 
|  | 309 | rm "${D}/lib/modules/${KERNEL_VERSION}/source" | 
|  | 310 | # If the kernel/ directory is empty remove it to prevent QA issues | 
|  | 311 | rmdir --ignore-fail-on-non-empty "${D}/lib/modules/${KERNEL_VERSION}/kernel" | 
|  | 312 | else | 
|  | 313 | bbnote "no modules to install" | 
|  | 314 | fi | 
|  | 315 |  | 
|  | 316 | # | 
|  | 317 | # Install various kernel output (zImage, map file, config, module support files) | 
|  | 318 | # | 
|  | 319 | install -d ${D}/${KERNEL_IMAGEDEST} | 
|  | 320 | install -d ${D}/boot | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 321 | for type in ${KERNEL_IMAGETYPES} ; do | 
|  | 322 | install -m 0644 ${KERNEL_OUTPUT_DIR}/${type} ${D}/${KERNEL_IMAGEDEST}/${type}-${KERNEL_VERSION} | 
|  | 323 | done | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 324 | install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION} | 
|  | 325 | install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION} | 
|  | 326 | install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION} | 
|  | 327 | [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION} | 
|  | 328 | install -d ${D}${sysconfdir}/modules-load.d | 
|  | 329 | install -d ${D}${sysconfdir}/modprobe.d | 
|  | 330 | } | 
|  | 331 | do_install[prefuncs] += "package_get_auto_pr" | 
|  | 332 |  | 
|  | 333 | addtask shared_workdir after do_compile before do_compile_kernelmodules | 
|  | 334 | addtask shared_workdir_setscene | 
|  | 335 |  | 
|  | 336 | do_shared_workdir_setscene () { | 
|  | 337 | exit 1 | 
|  | 338 | } | 
|  | 339 |  | 
|  | 340 | emit_depmod_pkgdata() { | 
|  | 341 | # Stash data for depmod | 
|  | 342 | install -d ${PKGDESTWORK}/kernel-depmod/ | 
|  | 343 | echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/kernel-depmod/kernel-abiversion | 
|  | 344 | cp ${B}/System.map ${PKGDESTWORK}/kernel-depmod/System.map-${KERNEL_VERSION} | 
|  | 345 | } | 
|  | 346 |  | 
|  | 347 | PACKAGEFUNCS += "emit_depmod_pkgdata" | 
|  | 348 |  | 
|  | 349 | do_shared_workdir () { | 
|  | 350 | cd ${B} | 
|  | 351 |  | 
|  | 352 | kerneldir=${STAGING_KERNEL_BUILDDIR} | 
|  | 353 | install -d $kerneldir | 
|  | 354 |  | 
|  | 355 | # | 
|  | 356 | # Store the kernel version in sysroots for module-base.bbclass | 
|  | 357 | # | 
|  | 358 |  | 
|  | 359 | echo "${KERNEL_VERSION}" > $kerneldir/kernel-abiversion | 
|  | 360 |  | 
|  | 361 | # Copy files required for module builds | 
|  | 362 | cp System.map $kerneldir/System.map-${KERNEL_VERSION} | 
|  | 363 | cp Module.symvers $kerneldir/ | 
|  | 364 | cp .config $kerneldir/ | 
|  | 365 | mkdir -p $kerneldir/include/config | 
|  | 366 | cp include/config/kernel.release $kerneldir/include/config/kernel.release | 
|  | 367 |  | 
|  | 368 | # We can also copy over all the generated files and avoid special cases | 
|  | 369 | # like version.h, but we've opted to keep this small until file creep starts | 
|  | 370 | # to happen | 
|  | 371 | if [ -e include/linux/version.h ]; then | 
|  | 372 | mkdir -p $kerneldir/include/linux | 
|  | 373 | cp include/linux/version.h $kerneldir/include/linux/version.h | 
|  | 374 | fi | 
|  | 375 |  | 
|  | 376 | # As of Linux kernel version 3.0.1, the clean target removes | 
|  | 377 | # arch/powerpc/lib/crtsavres.o which is present in | 
|  | 378 | # KBUILD_LDFLAGS_MODULE, making it required to build external modules. | 
|  | 379 | if [ ${ARCH} = "powerpc" ]; then | 
|  | 380 | mkdir -p $kerneldir/arch/powerpc/lib/ | 
|  | 381 | cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o | 
|  | 382 | fi | 
|  | 383 |  | 
|  | 384 | if [ -d include/generated ]; then | 
|  | 385 | mkdir -p $kerneldir/include/generated/ | 
|  | 386 | cp -fR include/generated/* $kerneldir/include/generated/ | 
|  | 387 | fi | 
|  | 388 |  | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 389 | if [ -d arch/${ARCH}/include/generated ]; then | 
|  | 390 | mkdir -p $kerneldir/arch/${ARCH}/include/generated/ | 
|  | 391 | cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/ | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 392 | fi | 
|  | 393 | } | 
|  | 394 |  | 
|  | 395 | # We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware | 
|  | 396 | sysroot_stage_all () { | 
|  | 397 | : | 
|  | 398 | } | 
|  | 399 |  | 
|  | 400 | KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} O=${B} oldnoconfig || yes '' | oe_runmake -C ${S} O=${B} oldconfig" | 
|  | 401 |  | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 402 | python check_oldest_kernel() { | 
|  | 403 | oldest_kernel = d.getVar('OLDEST_KERNEL', True) | 
|  | 404 | kernel_version = d.getVar('KERNEL_VERSION', True) | 
|  | 405 | tclibc = d.getVar('TCLIBC', True) | 
|  | 406 | if tclibc == 'glibc': | 
|  | 407 | kernel_version = kernel_version.split('-', 1)[0] | 
|  | 408 | if oldest_kernel and kernel_version: | 
|  | 409 | if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0: | 
|  | 410 | 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)) | 
|  | 411 | } | 
|  | 412 |  | 
|  | 413 | check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION" | 
|  | 414 | do_configure[prefuncs] += "check_oldest_kernel" | 
|  | 415 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 416 | kernel_do_configure() { | 
|  | 417 | # fixes extra + in /lib/modules/2.6.37+ | 
|  | 418 | # $ scripts/setlocalversion . => + | 
|  | 419 | # $ make kernelversion => 2.6.37 | 
|  | 420 | # $ make kernelrelease => 2.6.37+ | 
|  | 421 | touch ${B}/.scmversion ${S}/.scmversion | 
|  | 422 |  | 
|  | 423 | if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then | 
|  | 424 | mv "${S}/.config" "${B}/.config" | 
|  | 425 | fi | 
|  | 426 |  | 
|  | 427 | # Copy defconfig to .config if .config does not exist. This allows | 
|  | 428 | # recipes to manage the .config themselves in do_configure_prepend(). | 
|  | 429 | if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then | 
|  | 430 | cp "${WORKDIR}/defconfig" "${B}/.config" | 
|  | 431 | fi | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 432 |  | 
|  | 433 | ${KERNEL_CONFIG_COMMAND} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 434 | } | 
|  | 435 |  | 
|  | 436 | do_savedefconfig() { | 
|  | 437 | oe_runmake -C ${B} savedefconfig | 
|  | 438 | } | 
|  | 439 | do_savedefconfig[nostamp] = "1" | 
|  | 440 | addtask savedefconfig after do_configure | 
|  | 441 |  | 
|  | 442 | inherit cml1 | 
|  | 443 |  | 
|  | 444 | EXPORT_FUNCTIONS do_compile do_install do_configure | 
|  | 445 |  | 
|  | 446 | # kernel-base becomes kernel-${KERNEL_VERSION} | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 447 | # kernel-image becomes kernel-image-${KERNEL_VERSION} | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 448 | PACKAGES = "kernel kernel-base kernel-vmlinux kernel-image kernel-dev kernel-modules" | 
|  | 449 | FILES_${PN} = "" | 
|  | 450 | 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^] | 451 | FILES_kernel-image = "" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 452 | FILES_kernel-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} /lib/modules/${KERNEL_VERSION}/build" | 
|  | 453 | FILES_kernel-vmlinux = "/boot/vmlinux*" | 
|  | 454 | FILES_kernel-modules = "" | 
|  | 455 | RDEPENDS_kernel = "kernel-base" | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 456 | # Allow machines to override this dependency if kernel image files are | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 457 | # not wanted in images as standard | 
|  | 458 | RDEPENDS_kernel-base ?= "kernel-image" | 
|  | 459 | PKG_kernel-image = "kernel-image-${@legitimize_package_name('${KERNEL_VERSION}')}" | 
|  | 460 | RDEPENDS_kernel-image += "${@base_conditional('KERNEL_IMAGETYPE', 'vmlinux', 'kernel-vmlinux', '', d)}" | 
|  | 461 | PKG_kernel-base = "kernel-${@legitimize_package_name('${KERNEL_VERSION}')}" | 
|  | 462 | RPROVIDES_kernel-base += "kernel-${KERNEL_VERSION}" | 
|  | 463 | ALLOW_EMPTY_kernel = "1" | 
|  | 464 | ALLOW_EMPTY_kernel-base = "1" | 
|  | 465 | ALLOW_EMPTY_kernel-image = "1" | 
|  | 466 | ALLOW_EMPTY_kernel-modules = "1" | 
|  | 467 | DESCRIPTION_kernel-modules = "Kernel modules meta package" | 
|  | 468 |  | 
|  | 469 | pkg_postinst_kernel-base () { | 
|  | 470 | if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then | 
|  | 471 | mkdir -p $D/lib/modules/${KERNEL_VERSION} | 
|  | 472 | fi | 
|  | 473 | if [ -n "$D" ]; then | 
|  | 474 | depmodwrapper -a -b $D ${KERNEL_VERSION} | 
|  | 475 | else | 
|  | 476 | depmod -a ${KERNEL_VERSION} | 
|  | 477 | fi | 
|  | 478 | } | 
|  | 479 |  | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 480 | PACKAGESPLITFUNCS_prepend = "split_kernel_packages " | 
|  | 481 |  | 
|  | 482 | python split_kernel_packages () { | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 483 | 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='') | 
|  | 484 | } | 
|  | 485 |  | 
|  | 486 | # Many scripts want to look in arch/$arch/boot for the bootable | 
|  | 487 | # image. This poses a problem for vmlinux based booting. This | 
|  | 488 | # task arranges to have vmlinux appear in the normalized directory | 
|  | 489 | # location. | 
|  | 490 | do_kernel_link_vmlinux() { | 
|  | 491 | if [ ! -d "${B}/arch/${ARCH}/boot" ]; then | 
|  | 492 | mkdir ${B}/arch/${ARCH}/boot | 
|  | 493 | fi | 
|  | 494 | cd ${B}/arch/${ARCH}/boot | 
|  | 495 | ln -sf ../../../vmlinux | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 496 | } | 
|  | 497 |  | 
|  | 498 | do_strip() { | 
|  | 499 | if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 500 | if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then | 
|  | 501 | bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 502 | return | 
|  | 503 | fi | 
|  | 504 |  | 
|  | 505 | cd ${B} | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 506 | headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \ | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 507 | grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \ | 
|  | 508 | sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \ | 
|  | 509 | gawk '{print $1}'` | 
|  | 510 |  | 
|  | 511 | for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do { | 
| Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 512 | if ! (echo "$headers" | grep -q "^$str$"); then | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 513 | bbwarn "Section not found: $str"; | 
|  | 514 | fi | 
|  | 515 |  | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 516 | "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 517 | }; done | 
|  | 518 |  | 
|  | 519 | bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \ | 
|  | 520 | "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" | 
|  | 521 | fi; | 
|  | 522 | } | 
|  | 523 | do_strip[dirs] = "${B}" | 
|  | 524 |  | 
|  | 525 | addtask do_strip before do_sizecheck after do_kernel_link_vmlinux | 
|  | 526 |  | 
|  | 527 | # Support checking the kernel size since some kernels need to reside in partitions | 
|  | 528 | # with a fixed length or there is a limit in transferring the kernel to memory | 
|  | 529 | do_sizecheck() { | 
|  | 530 | if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then | 
|  | 531 | invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'` | 
|  | 532 | if [ -n "$invalid" ]; then | 
|  | 533 | die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integerx (The unit is Kbytes)" | 
|  | 534 | fi | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 535 | for type in ${KERNEL_IMAGETYPES} ; do | 
|  | 536 | size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$type | awk '{print $1}'` | 
|  | 537 | if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then | 
|  | 538 | 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." | 
|  | 539 | fi | 
|  | 540 | done | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 541 | fi | 
|  | 542 | } | 
|  | 543 | do_sizecheck[dirs] = "${B}" | 
|  | 544 |  | 
|  | 545 | addtask sizecheck before do_install after do_strip | 
|  | 546 |  | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 547 | KERNEL_IMAGE_BASE_NAME ?= "${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 548 | # Don't include the DATETIME variable in the sstate package signatures | 
|  | 549 | KERNEL_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME" | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 550 | KERNEL_IMAGE_SYMLINK_NAME ?= "${MACHINE}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 551 | MODULE_IMAGE_BASE_NAME ?= "modules-${PKGE}-${PKGV}-${PKGR}-${MACHINE}-${DATETIME}" | 
|  | 552 | MODULE_IMAGE_BASE_NAME[vardepsexclude] = "DATETIME" | 
|  | 553 | MODULE_TARBALL_BASE_NAME ?= "${MODULE_IMAGE_BASE_NAME}.tgz" | 
|  | 554 | # Don't include the DATETIME variable in the sstate package signatures | 
|  | 555 | MODULE_TARBALL_SYMLINK_NAME ?= "modules-${MACHINE}.tgz" | 
|  | 556 | MODULE_TARBALL_DEPLOY ?= "1" | 
|  | 557 |  | 
|  | 558 | kernel_do_deploy() { | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 559 | for type in ${KERNEL_IMAGETYPES} ; do | 
|  | 560 | base_name=${type}-${KERNEL_IMAGE_BASE_NAME} | 
|  | 561 | install -m 0644 ${KERNEL_OUTPUT_DIR}/${type} ${DEPLOYDIR}/${base_name}.bin | 
|  | 562 | done | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 563 | if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then | 
|  | 564 | mkdir -p ${D}/lib | 
|  | 565 | tar -cvzf ${DEPLOYDIR}/${MODULE_TARBALL_BASE_NAME} -C ${D} lib | 
|  | 566 | ln -sf ${MODULE_TARBALL_BASE_NAME} ${DEPLOYDIR}/${MODULE_TARBALL_SYMLINK_NAME} | 
|  | 567 | fi | 
|  | 568 |  | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 569 | for type in ${KERNEL_IMAGETYPES} ; do | 
|  | 570 | base_name=${type}-${KERNEL_IMAGE_BASE_NAME} | 
|  | 571 | symlink_name=${type}-${KERNEL_IMAGE_SYMLINK_NAME} | 
|  | 572 | ln -sf ${base_name}.bin ${DEPLOYDIR}/${symlink_name}.bin | 
|  | 573 | ln -sf ${base_name}.bin ${DEPLOYDIR}/${type} | 
|  | 574 | done | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 575 |  | 
|  | 576 | cp ${COREBASE}/meta/files/deploydir_readme.txt ${DEPLOYDIR}/README_-_DO_NOT_DELETE_FILES_IN_THIS_DIRECTORY.txt | 
|  | 577 |  | 
|  | 578 | cd ${B} | 
|  | 579 | # Update deploy directory | 
| He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame^] | 580 | for type in ${KERNEL_IMAGETYPES} ; do | 
|  | 581 | if [ -e "${KERNEL_OUTPUT_DIR}/${type}.initramfs" ]; then | 
|  | 582 | echo "Copying deploy ${type} kernel-initramfs image and setting up links..." | 
|  | 583 | initramfs_base_name=${type}-${INITRAMFS_BASE_NAME} | 
|  | 584 | initramfs_symlink_name=${type}-initramfs-${MACHINE} | 
|  | 585 | install -m 0644 ${KERNEL_OUTPUT_DIR}/${type}.initramfs ${DEPLOYDIR}/${initramfs_base_name}.bin | 
|  | 586 | cd ${DEPLOYDIR} | 
|  | 587 | ln -sf ${initramfs_base_name}.bin ${initramfs_symlink_name}.bin | 
|  | 588 | fi | 
|  | 589 | done | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 590 | } | 
| Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 591 | do_deploy[cleandirs] = "${DEPLOYDIR}" | 
| Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 592 | do_deploy[dirs] = "${DEPLOYDIR} ${B}" | 
|  | 593 | do_deploy[prefuncs] += "package_get_auto_pr" | 
|  | 594 |  | 
|  | 595 | addtask deploy after do_populate_sysroot | 
|  | 596 |  | 
|  | 597 | EXPORT_FUNCTIONS do_deploy | 
|  | 598 |  |