Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | inherit linux-kernel-base kernel-module-split |
| 2 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 3 | KERNEL_PACKAGE_NAME ??= "kernel" |
| 4 | KERNEL_DEPLOYSUBDIR ??= "${@ "" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else d.getVar("KERNEL_PACKAGE_NAME") }" |
| 5 | |
| 6 | PROVIDES += "${@ "virtual/kernel" if (d.getVar("KERNEL_PACKAGE_NAME") == "kernel") else "" }" |
| 7 | DEPENDS += "virtual/${TARGET_PREFIX}binutils virtual/${TARGET_PREFIX}gcc kmod-native bc-native lzop-native bison-native" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 8 | PACKAGE_WRITE_DEPS += "depmodwrapper-cross" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9 | |
| 10 | do_deploy[depends] += "depmodwrapper-cross:do_populate_sysroot" |
| 11 | |
| 12 | CVE_PRODUCT ?= "linux_kernel" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | |
| 14 | S = "${STAGING_KERNEL_DIR}" |
| 15 | B = "${WORKDIR}/build" |
| 16 | KBUILD_OUTPUT = "${B}" |
| 17 | OE_TERMINAL_EXPORTS += "KBUILD_OUTPUT" |
| 18 | |
| 19 | # we include gcc above, we dont need virtual/libc |
| 20 | INHIBIT_DEFAULT_DEPS = "1" |
| 21 | |
| 22 | KERNEL_IMAGETYPE ?= "zImage" |
| 23 | INITRAMFS_IMAGE ?= "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | INITRAMFS_IMAGE_NAME ?= "${@['${INITRAMFS_IMAGE}-${MACHINE}', ''][d.getVar('INITRAMFS_IMAGE') == '']}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | INITRAMFS_TASK ?= "" |
| 26 | INITRAMFS_IMAGE_BUNDLE ?= "" |
| 27 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 28 | # KERNEL_VERSION is extracted from source code. It is evaluated as |
| 29 | # None for the first parsing, since the code has not been fetched. |
| 30 | # After the code is fetched, it will be evaluated as real version |
| 31 | # number and cause kernel to be rebuilt. To avoid this, make |
| 32 | # KERNEL_VERSION_NAME and KERNEL_VERSION_PKG_NAME depend on |
| 33 | # LINUX_VERSION which is a constant. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 34 | KERNEL_VERSION_NAME = "${@d.getVar('KERNEL_VERSION') or ""}" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 35 | KERNEL_VERSION_NAME[vardepvalue] = "${LINUX_VERSION}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | KERNEL_VERSION_PKG_NAME = "${@legitimize_package_name(d.getVar('KERNEL_VERSION'))}" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 37 | KERNEL_VERSION_PKG_NAME[vardepvalue] = "${LINUX_VERSION}" |
| 38 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 39 | python __anonymous () { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 40 | pn = d.getVar("PN") |
| 41 | kpn = d.getVar("KERNEL_PACKAGE_NAME") |
| 42 | |
| 43 | # XXX Remove this after bug 11905 is resolved |
| 44 | # FILES_${KERNEL_PACKAGE_NAME}-dev doesn't expand correctly |
| 45 | if kpn == pn: |
| 46 | bb.warn("Some packages (E.g. *-dev) might be missing due to " |
| 47 | "bug 11905 (variable KERNEL_PACKAGE_NAME == PN)") |
| 48 | |
| 49 | # The default kernel recipe builds in a shared location defined by |
| 50 | # bitbake/distro confs: STAGING_KERNEL_DIR and STAGING_KERNEL_BUILDDIR. |
| 51 | # Set these variables to directories under ${WORKDIR} in alternate |
| 52 | # kernel recipes (I.e. where KERNEL_PACKAGE_NAME != kernel) so that they |
| 53 | # may build in parallel with the default kernel without clobbering. |
| 54 | if kpn != "kernel": |
| 55 | workdir = d.getVar("WORKDIR") |
| 56 | sourceDir = os.path.join(workdir, 'kernel-source') |
| 57 | artifactsDir = os.path.join(workdir, 'kernel-build-artifacts') |
| 58 | d.setVar("STAGING_KERNEL_DIR", sourceDir) |
| 59 | d.setVar("STAGING_KERNEL_BUILDDIR", artifactsDir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 61 | # Merge KERNEL_IMAGETYPE and KERNEL_ALT_IMAGETYPE into KERNEL_IMAGETYPES |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 62 | type = d.getVar('KERNEL_IMAGETYPE') or "" |
| 63 | alttype = d.getVar('KERNEL_ALT_IMAGETYPE') or "" |
| 64 | types = d.getVar('KERNEL_IMAGETYPES') or "" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 65 | if type not in types.split(): |
| 66 | types = (type + ' ' + types).strip() |
| 67 | if alttype not in types.split(): |
| 68 | types = (alttype + ' ' + types).strip() |
| 69 | d.setVar('KERNEL_IMAGETYPES', types) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 70 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 71 | # KERNEL_IMAGETYPES may contain a mixture of image types supported directly |
| 72 | # by the kernel build system and types which are created by post-processing |
| 73 | # the output of the kernel build system (e.g. compressing vmlinux -> |
| 74 | # vmlinux.gz in kernel_do_compile()). |
| 75 | # KERNEL_IMAGETYPE_FOR_MAKE should contain only image types supported |
| 76 | # directly by the kernel build system. |
| 77 | if not d.getVar('KERNEL_IMAGETYPE_FOR_MAKE'): |
| 78 | typeformake = set() |
| 79 | for type in types.split(): |
| 80 | if type == 'vmlinux.gz': |
| 81 | type = 'vmlinux' |
| 82 | typeformake.add(type) |
| 83 | |
| 84 | d.setVar('KERNEL_IMAGETYPE_FOR_MAKE', ' '.join(sorted(typeformake))) |
| 85 | |
| 86 | kname = d.getVar('KERNEL_PACKAGE_NAME') or "kernel" |
| 87 | imagedest = d.getVar('KERNEL_IMAGEDEST') |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 88 | |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 89 | for type in types.split(): |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 90 | typelower = type.lower() |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 91 | d.appendVar('PACKAGES', ' %s-image-%s' % (kname, typelower)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 92 | d.setVar('FILES_' + kname + '-image-' + typelower, '/' + imagedest + '/' + type + '-${KERNEL_VERSION_NAME}' + ' /' + imagedest + '/' + type) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 93 | d.appendVar('RDEPENDS_%s-image' % kname, ' %s-image-%s' % (kname, typelower)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 94 | d.setVar('PKG_%s-image-%s' % (kname,typelower), '%s-image-%s-${KERNEL_VERSION_PKG_NAME}' % (kname, typelower)) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 95 | d.setVar('ALLOW_EMPTY_%s-image-%s' % (kname, typelower), '1') |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 96 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 97 | image = d.getVar('INITRAMFS_IMAGE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 98 | if image: |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 99 | d.appendVarFlag('do_bundle_initramfs', 'depends', ' ${INITRAMFS_IMAGE}:do_image_complete') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | |
| 101 | # NOTE: setting INITRAMFS_TASK is for backward compatibility |
| 102 | # The preferred method is to set INITRAMFS_IMAGE, because |
| 103 | # this INITRAMFS_TASK has circular dependency problems |
| 104 | # if the initramfs requires kernel modules |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 105 | image_task = d.getVar('INITRAMFS_TASK') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 106 | if image_task: |
| 107 | d.appendVarFlag('do_configure', 'depends', ' ${INITRAMFS_TASK}') |
| 108 | } |
| 109 | |
| 110 | # Here we pull in all various kernel image types which we support. |
| 111 | # |
| 112 | # In case you're wondering why kernel.bbclass inherits the other image |
| 113 | # types instead of the other way around, the reason for that is to |
| 114 | # maintain compatibility with various currently existing meta-layers. |
| 115 | # By pulling in the various kernel image types here, we retain the |
| 116 | # original behavior of kernel.bbclass, so no meta-layers should get |
| 117 | # broken. |
| 118 | # |
| 119 | # KERNEL_CLASSES by default pulls in kernel-uimage.bbclass, since this |
| 120 | # used to be the default behavior when only uImage was supported. This |
| 121 | # variable can be appended by users who implement support for new kernel |
| 122 | # image types. |
| 123 | |
| 124 | KERNEL_CLASSES ?= " kernel-uimage " |
| 125 | inherit ${KERNEL_CLASSES} |
| 126 | |
| 127 | # Old style kernels may set ${S} = ${WORKDIR}/git for example |
| 128 | # We need to move these over to STAGING_KERNEL_DIR. We can't just |
| 129 | # create the symlink in advance as the git fetcher can't cope with |
| 130 | # the symlink. |
| 131 | do_unpack[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}" |
| 132 | do_clean[cleandirs] += " ${S} ${STAGING_KERNEL_DIR} ${B} ${STAGING_KERNEL_BUILDDIR}" |
| 133 | base_do_unpack_append () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 134 | s = d.getVar("S") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | if s[-1] == '/': |
| 136 | # drop trailing slash, so that os.symlink(kernsrc, s) doesn't use s as directory name and fail |
| 137 | s=s[:-1] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 138 | kernsrc = d.getVar("STAGING_KERNEL_DIR") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 139 | if s != kernsrc: |
| 140 | bb.utils.mkdirhier(kernsrc) |
| 141 | bb.utils.remove(kernsrc, recurse=True) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 142 | if d.getVar("EXTERNALSRC"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 143 | # With EXTERNALSRC S will not be wiped so we can symlink to it |
| 144 | os.symlink(s, kernsrc) |
| 145 | else: |
| 146 | import shutil |
| 147 | shutil.move(s, kernsrc) |
| 148 | os.symlink(kernsrc, s) |
| 149 | } |
| 150 | |
| 151 | inherit kernel-arch deploy |
| 152 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 153 | PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-module-.*" |
| 154 | PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-image-.*" |
| 155 | PACKAGES_DYNAMIC += "^${KERNEL_PACKAGE_NAME}-firmware-.*" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 156 | |
| 157 | export OS = "${TARGET_OS}" |
| 158 | export CROSS_COMPILE = "${TARGET_PREFIX}" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 159 | export KBUILD_BUILD_VERSION = "1" |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 160 | export KBUILD_BUILD_USER ?= "oe-user" |
| 161 | export KBUILD_BUILD_HOST ?= "oe-host" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 162 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 163 | KERNEL_RELEASE ?= "${KERNEL_VERSION}" |
| 164 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 165 | # The directory where built kernel lies in the kernel tree |
| 166 | KERNEL_OUTPUT_DIR ?= "arch/${ARCH}/boot" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 167 | KERNEL_IMAGEDEST ?= "boot" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 168 | |
| 169 | # |
| 170 | # configuration |
| 171 | # |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 172 | export CMDLINE_CONSOLE = "console=${@d.getVar("KERNEL_CONSOLE") or "ttyS0"}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 173 | |
| 174 | KERNEL_VERSION = "${@get_kernelversion_headers('${B}')}" |
| 175 | |
| 176 | KERNEL_LOCALVERSION ?= "" |
| 177 | |
| 178 | # kernels are generally machine specific |
| 179 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 180 | |
| 181 | # U-Boot support |
| 182 | UBOOT_ENTRYPOINT ?= "20008000" |
| 183 | UBOOT_LOADADDRESS ?= "${UBOOT_ENTRYPOINT}" |
| 184 | |
| 185 | # Some Linux kernel configurations need additional parameters on the command line |
| 186 | KERNEL_EXTRA_ARGS ?= "" |
| 187 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 188 | EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}"" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 189 | KERNEL_ALT_IMAGETYPE ??= "" |
| 190 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 191 | copy_initramfs() { |
| 192 | echo "Copying initramfs into ./usr ..." |
| 193 | # In case the directory is not created yet from the first pass compile: |
| 194 | mkdir -p ${B}/usr |
| 195 | # Find and use the first initramfs image archive type we find |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 196 | rm -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 197 | for img in cpio cpio.gz cpio.lz4 cpio.lzo cpio.lzma cpio.xz; do |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 198 | if [ -e "${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img" ]; then |
| 199 | cp ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.$img ${B}/usr/. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 200 | case $img in |
| 201 | *gz) |
| 202 | echo "gzip decompressing image" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 203 | gunzip -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 204 | break |
| 205 | ;; |
| 206 | *lz4) |
| 207 | echo "lz4 decompressing image" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 208 | lz4 -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 209 | break |
| 210 | ;; |
| 211 | *lzo) |
| 212 | echo "lzo decompressing image" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 213 | lzop -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | break |
| 215 | ;; |
| 216 | *lzma) |
| 217 | echo "lzma decompressing image" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 218 | lzma -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 219 | break |
| 220 | ;; |
| 221 | *xz) |
| 222 | echo "xz decompressing image" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 223 | xz -df ${B}/usr/${INITRAMFS_IMAGE_NAME}.$img |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 224 | break |
| 225 | ;; |
| 226 | esac |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 227 | break |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 228 | fi |
| 229 | done |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 230 | # Verify that the above loop found a initramfs, fail otherwise |
| 231 | [ -f ${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio ] && echo "Finished copy of initramfs into ./usr" || die "Could not find any ${DEPLOY_DIR_IMAGE}/${INITRAMFS_IMAGE_NAME}.cpio{.gz|.lz4|.lzo|.lzma|.xz) for bundling; INITRAMFS_IMAGE_NAME might be wrong." |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 232 | } |
| 233 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 234 | do_bundle_initramfs () { |
| 235 | if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then |
| 236 | echo "Creating a kernel image with a bundled initramfs..." |
| 237 | copy_initramfs |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 238 | # Backing up kernel image relies on its type(regular file or symbolic link) |
| 239 | tmp_path="" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 240 | for imageType in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do |
| 241 | if [ -h ${KERNEL_OUTPUT_DIR}/$imageType ] ; then |
| 242 | linkpath=`readlink -n ${KERNEL_OUTPUT_DIR}/$imageType` |
| 243 | realpath=`readlink -fn ${KERNEL_OUTPUT_DIR}/$imageType` |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 244 | mv -f $realpath $realpath.bak |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 245 | tmp_path=$tmp_path" "$imageType"#"$linkpath"#"$realpath |
| 246 | elif [ -f ${KERNEL_OUTPUT_DIR}/$imageType ]; then |
| 247 | mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.bak |
| 248 | tmp_path=$tmp_path" "$imageType"##" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 249 | fi |
| 250 | done |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 251 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 252 | kernel_do_compile |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 253 | # Restoring kernel image |
| 254 | for tp in $tmp_path ; do |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 255 | imageType=`echo $tp|cut -d "#" -f 1` |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 256 | linkpath=`echo $tp|cut -d "#" -f 2` |
| 257 | realpath=`echo $tp|cut -d "#" -f 3` |
| 258 | if [ -n "$realpath" ]; then |
| 259 | mv -f $realpath $realpath.initramfs |
| 260 | mv -f $realpath.bak $realpath |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 261 | ln -sf $linkpath.initramfs ${B}/${KERNEL_OUTPUT_DIR}/$imageType.initramfs |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 262 | else |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 263 | mv -f ${KERNEL_OUTPUT_DIR}/$imageType ${KERNEL_OUTPUT_DIR}/$imageType.initramfs |
| 264 | mv -f ${KERNEL_OUTPUT_DIR}/$imageType.bak ${KERNEL_OUTPUT_DIR}/$imageType |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 265 | fi |
| 266 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 267 | fi |
| 268 | } |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 269 | do_bundle_initramfs[dirs] = "${B}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 270 | |
| 271 | python do_devshell_prepend () { |
| 272 | os.environ["LDFLAGS"] = '' |
| 273 | } |
| 274 | |
| 275 | addtask bundle_initramfs after do_install before do_deploy |
| 276 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 277 | get_cc_option () { |
| 278 | # Check if KERNEL_CC supports the option "file-prefix-map". |
| 279 | # This option allows us to build images with __FILE__ values that do not |
| 280 | # contain the host build path. |
| 281 | if ${KERNEL_CC} -Q --help=joined | grep -q "\-ffile-prefix-map=<old=new>"; then |
| 282 | echo "-ffile-prefix-map=${S}=/kernel-source/" |
| 283 | fi |
| 284 | } |
| 285 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 286 | kernel_do_compile() { |
| 287 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 288 | if [ "${BUILD_REPRODUCIBLE_BINARIES}" = "1" ]; then |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 289 | # kernel sources do not use do_unpack, so SOURCE_DATE_EPOCH may not |
| 290 | # be set.... |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 291 | if [ "${SOURCE_DATE_EPOCH}" = "" -o "${SOURCE_DATE_EPOCH}" = "0" ]; then |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 292 | olddir=`pwd` |
| 293 | cd ${S} |
| 294 | SOURCE_DATE_EPOCH=`git log -1 --pretty=%ct` |
| 295 | # git repo not guaranteed, so fall back to REPRODUCIBLE_TIMESTAMP_ROOTFS |
| 296 | if [ $? -ne 0 ]; then |
| 297 | SOURCE_DATE_EPOCH=${REPRODUCIBLE_TIMESTAMP_ROOTFS} |
| 298 | fi |
| 299 | cd $olddir |
| 300 | fi |
| 301 | |
| 302 | ts=`LC_ALL=C date -d @$SOURCE_DATE_EPOCH` |
| 303 | export KBUILD_BUILD_TIMESTAMP="$ts" |
| 304 | export KCONFIG_NOTIMESTAMP=1 |
| 305 | bbnote "KBUILD_BUILD_TIMESTAMP: $ts" |
| 306 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 307 | # The $use_alternate_initrd is only set from |
| 308 | # do_bundle_initramfs() This variable is specifically for the |
| 309 | # case where we are making a second pass at the kernel |
| 310 | # compilation and we want to force the kernel build to use a |
| 311 | # different initramfs image. The way to do that in the kernel |
| 312 | # is to specify: |
| 313 | # make ...args... CONFIG_INITRAMFS_SOURCE=some_other_initramfs.cpio |
| 314 | if [ "$use_alternate_initrd" = "" ] && [ "${INITRAMFS_TASK}" != "" ] ; then |
| 315 | # The old style way of copying an prebuilt image and building it |
| 316 | # is turned on via INTIRAMFS_TASK != "" |
| 317 | copy_initramfs |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 318 | use_alternate_initrd=CONFIG_INITRAMFS_SOURCE=${B}/usr/${INITRAMFS_IMAGE_NAME}.cpio |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 319 | fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 320 | cc_extra=$(get_cc_option) |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 321 | for typeformake in ${KERNEL_IMAGETYPE_FOR_MAKE} ; do |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 322 | oe_runmake ${typeformake} CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} $use_alternate_initrd |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 323 | done |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 324 | # vmlinux.gz is not built by kernel |
| 325 | if (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux\.gz"); then |
| 326 | mkdir -p "${KERNEL_OUTPUT_DIR}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 327 | gzip -9cn < ${B}/vmlinux > "${KERNEL_OUTPUT_DIR}/vmlinux.gz" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 328 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | do_compile_kernelmodules() { |
| 332 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
| 333 | if (grep -q -i -e '^CONFIG_MODULES=y$' ${B}/.config); then |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 334 | cc_extra=$(get_cc_option) |
| 335 | oe_runmake -C ${B} ${PARALLEL_MAKE} modules CC="${KERNEL_CC} $cc_extra " LD="${KERNEL_LD}" ${KERNEL_EXTRA_ARGS} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 336 | |
| 337 | # Module.symvers gets updated during the |
| 338 | # building of the kernel modules. We need to |
| 339 | # update this in the shared workdir since some |
| 340 | # external kernel modules has a dependency on |
| 341 | # other kernel modules and will look at this |
| 342 | # file to do symbol lookups |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 343 | cp ${B}/Module.symvers ${STAGING_KERNEL_BUILDDIR}/ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 344 | else |
| 345 | bbnote "no modules to compile" |
| 346 | fi |
| 347 | } |
| 348 | addtask compile_kernelmodules after do_compile before do_strip |
| 349 | |
| 350 | kernel_do_install() { |
| 351 | # |
| 352 | # First install the modules |
| 353 | # |
| 354 | unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE |
| 355 | if (grep -q -i -e '^CONFIG_MODULES=y$' .config); then |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 356 | oe_runmake DEPMOD=echo MODLIB=${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION} INSTALL_FW_PATH=${D}${nonarch_base_libdir}/firmware modules_install |
| 357 | rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build" |
| 358 | rm "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/source" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 359 | # If the kernel/ directory is empty remove it to prevent QA issues |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 360 | rmdir --ignore-fail-on-non-empty "${D}${nonarch_base_libdir}/modules/${KERNEL_VERSION}/kernel" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 361 | else |
| 362 | bbnote "no modules to install" |
| 363 | fi |
| 364 | |
| 365 | # |
| 366 | # Install various kernel output (zImage, map file, config, module support files) |
| 367 | # |
| 368 | install -d ${D}/${KERNEL_IMAGEDEST} |
| 369 | install -d ${D}/boot |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 370 | for imageType in ${KERNEL_IMAGETYPES} ; do |
| 371 | install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} ${D}/${KERNEL_IMAGEDEST}/${imageType}-${KERNEL_VERSION} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 372 | if [ "${KERNEL_PACKAGE_NAME}" = "kernel" ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 373 | ln -sf ${imageType}-${KERNEL_VERSION} ${D}/${KERNEL_IMAGEDEST}/${imageType} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 374 | fi |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 375 | done |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 376 | install -m 0644 System.map ${D}/boot/System.map-${KERNEL_VERSION} |
| 377 | install -m 0644 .config ${D}/boot/config-${KERNEL_VERSION} |
| 378 | install -m 0644 vmlinux ${D}/boot/vmlinux-${KERNEL_VERSION} |
| 379 | [ -e Module.symvers ] && install -m 0644 Module.symvers ${D}/boot/Module.symvers-${KERNEL_VERSION} |
| 380 | install -d ${D}${sysconfdir}/modules-load.d |
| 381 | install -d ${D}${sysconfdir}/modprobe.d |
| 382 | } |
| 383 | do_install[prefuncs] += "package_get_auto_pr" |
| 384 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 385 | # Must be ran no earlier than after do_kernel_checkout or else Makefile won't be in ${S}/Makefile |
| 386 | do_kernel_version_sanity_check() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 387 | if [ "x${KERNEL_VERSION_SANITY_SKIP}" = "x1" ]; then |
| 388 | exit 0 |
| 389 | fi |
| 390 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 391 | # The Makefile determines the kernel version shown at runtime |
| 392 | # Don't use KERNEL_VERSION because the headers it grabs the version from aren't generated until do_compile |
| 393 | VERSION=$(grep "^VERSION =" ${S}/Makefile | sed s/.*=\ *//) |
| 394 | PATCHLEVEL=$(grep "^PATCHLEVEL =" ${S}/Makefile | sed s/.*=\ *//) |
| 395 | SUBLEVEL=$(grep "^SUBLEVEL =" ${S}/Makefile | sed s/.*=\ *//) |
| 396 | EXTRAVERSION=$(grep "^EXTRAVERSION =" ${S}/Makefile | sed s/.*=\ *//) |
| 397 | |
| 398 | # Build a string for regex and a plain version string |
| 399 | reg="^${VERSION}\.${PATCHLEVEL}" |
| 400 | vers="${VERSION}.${PATCHLEVEL}" |
| 401 | if [ -n "${SUBLEVEL}" ]; then |
| 402 | # Ignoring a SUBLEVEL of zero is fine |
| 403 | if [ "${SUBLEVEL}" = "0" ]; then |
| 404 | reg="${reg}(\.${SUBLEVEL})?" |
| 405 | else |
| 406 | reg="${reg}\.${SUBLEVEL}" |
| 407 | vers="${vers}.${SUBLEVEL}" |
| 408 | fi |
| 409 | fi |
| 410 | vers="${vers}${EXTRAVERSION}" |
| 411 | reg="${reg}${EXTRAVERSION}" |
| 412 | |
| 413 | if [ -z `echo ${PV} | grep -E "${reg}"` ]; then |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 414 | bbfatal "Package Version (${PV}) does not match of kernel being built (${vers}). Please update the PV variable to match the kernel source or set KERNEL_VERSION_SANITY_SKIP=\"1\" in your recipe." |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 415 | fi |
| 416 | exit 0 |
| 417 | } |
| 418 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 419 | addtask shared_workdir after do_compile before do_compile_kernelmodules |
| 420 | addtask shared_workdir_setscene |
| 421 | |
| 422 | do_shared_workdir_setscene () { |
| 423 | exit 1 |
| 424 | } |
| 425 | |
| 426 | emit_depmod_pkgdata() { |
| 427 | # Stash data for depmod |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 428 | install -d ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/ |
| 429 | echo "${KERNEL_VERSION}" > ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/${KERNEL_PACKAGE_NAME}-abiversion |
| 430 | cp ${B}/System.map ${PKGDESTWORK}/${KERNEL_PACKAGE_NAME}-depmod/System.map-${KERNEL_VERSION} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | PACKAGEFUNCS += "emit_depmod_pkgdata" |
| 434 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 435 | do_shared_workdir[cleandirs] += " ${STAGING_KERNEL_BUILDDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 436 | do_shared_workdir () { |
| 437 | cd ${B} |
| 438 | |
| 439 | kerneldir=${STAGING_KERNEL_BUILDDIR} |
| 440 | install -d $kerneldir |
| 441 | |
| 442 | # |
| 443 | # Store the kernel version in sysroots for module-base.bbclass |
| 444 | # |
| 445 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 446 | echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 447 | |
| 448 | # Copy files required for module builds |
| 449 | cp System.map $kerneldir/System.map-${KERNEL_VERSION} |
| 450 | cp Module.symvers $kerneldir/ |
| 451 | cp .config $kerneldir/ |
| 452 | mkdir -p $kerneldir/include/config |
| 453 | cp include/config/kernel.release $kerneldir/include/config/kernel.release |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 454 | if [ -e certs/signing_key.pem ]; then |
| 455 | # The signing_key.* files are stored in the certs/ dir in |
| 456 | # newer Linux kernels |
| 457 | mkdir -p $kerneldir/certs |
| 458 | cp certs/signing_key.* $kerneldir/certs/ |
| 459 | elif [ -e signing_key.priv ]; then |
| 460 | cp signing_key.* $kerneldir/ |
| 461 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 462 | |
| 463 | # We can also copy over all the generated files and avoid special cases |
| 464 | # like version.h, but we've opted to keep this small until file creep starts |
| 465 | # to happen |
| 466 | if [ -e include/linux/version.h ]; then |
| 467 | mkdir -p $kerneldir/include/linux |
| 468 | cp include/linux/version.h $kerneldir/include/linux/version.h |
| 469 | fi |
| 470 | |
| 471 | # As of Linux kernel version 3.0.1, the clean target removes |
| 472 | # arch/powerpc/lib/crtsavres.o which is present in |
| 473 | # KBUILD_LDFLAGS_MODULE, making it required to build external modules. |
| 474 | if [ ${ARCH} = "powerpc" ]; then |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 475 | if [ -e arch/powerpc/lib/crtsavres.o ]; then |
| 476 | mkdir -p $kerneldir/arch/powerpc/lib/ |
| 477 | cp arch/powerpc/lib/crtsavres.o $kerneldir/arch/powerpc/lib/crtsavres.o |
| 478 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 479 | fi |
| 480 | |
| 481 | if [ -d include/generated ]; then |
| 482 | mkdir -p $kerneldir/include/generated/ |
| 483 | cp -fR include/generated/* $kerneldir/include/generated/ |
| 484 | fi |
| 485 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 486 | if [ -d arch/${ARCH}/include/generated ]; then |
| 487 | mkdir -p $kerneldir/arch/${ARCH}/include/generated/ |
| 488 | cp -fR arch/${ARCH}/include/generated/* $kerneldir/arch/${ARCH}/include/generated/ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 489 | fi |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 490 | |
| 491 | if (grep -q -i -e '^CONFIG_UNWINDER_ORC=y$' $kerneldir/.config); then |
| 492 | # With CONFIG_UNWINDER_ORC (the default in 4.14), objtool is required for |
| 493 | # out-of-tree modules to be able to generate object files. |
| 494 | if [ -x tools/objtool/objtool ]; then |
| 495 | mkdir -p ${kerneldir}/tools/objtool |
| 496 | cp tools/objtool/objtool ${kerneldir}/tools/objtool/ |
| 497 | fi |
| 498 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 499 | } |
| 500 | |
| 501 | # We don't need to stage anything, not the modules/firmware since those would clash with linux-firmware |
| 502 | sysroot_stage_all () { |
| 503 | : |
| 504 | } |
| 505 | |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 506 | KERNEL_CONFIG_COMMAND ?= "oe_runmake_call -C ${S} CC="${KERNEL_CC}" O=${B} olddefconfig || oe_runmake -C ${S} O=${B} CC="${KERNEL_CC}" oldnoconfig" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 507 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 508 | python check_oldest_kernel() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 509 | oldest_kernel = d.getVar('OLDEST_KERNEL') |
| 510 | kernel_version = d.getVar('KERNEL_VERSION') |
| 511 | tclibc = d.getVar('TCLIBC') |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 512 | if tclibc == 'glibc': |
| 513 | kernel_version = kernel_version.split('-', 1)[0] |
| 514 | if oldest_kernel and kernel_version: |
| 515 | if bb.utils.vercmp_string(kernel_version, oldest_kernel) < 0: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 516 | 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'), oldest_kernel, kernel_version, tclibc)) |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION" |
| 520 | do_configure[prefuncs] += "check_oldest_kernel" |
| 521 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 522 | kernel_do_configure() { |
| 523 | # fixes extra + in /lib/modules/2.6.37+ |
| 524 | # $ scripts/setlocalversion . => + |
| 525 | # $ make kernelversion => 2.6.37 |
| 526 | # $ make kernelrelease => 2.6.37+ |
| 527 | touch ${B}/.scmversion ${S}/.scmversion |
| 528 | |
| 529 | if [ "${S}" != "${B}" ] && [ -f "${S}/.config" ] && [ ! -f "${B}/.config" ]; then |
| 530 | mv "${S}/.config" "${B}/.config" |
| 531 | fi |
| 532 | |
| 533 | # Copy defconfig to .config if .config does not exist. This allows |
| 534 | # recipes to manage the .config themselves in do_configure_prepend(). |
| 535 | if [ -f "${WORKDIR}/defconfig" ] && [ ! -f "${B}/.config" ]; then |
| 536 | cp "${WORKDIR}/defconfig" "${B}/.config" |
| 537 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 538 | |
| 539 | ${KERNEL_CONFIG_COMMAND} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | do_savedefconfig() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 543 | bbplain "Saving defconfig to:\n${B}/defconfig" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 544 | oe_runmake -C ${B} savedefconfig |
| 545 | } |
| 546 | do_savedefconfig[nostamp] = "1" |
| 547 | addtask savedefconfig after do_configure |
| 548 | |
| 549 | inherit cml1 |
| 550 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 551 | KCONFIG_CONFIG_COMMAND_append = " HOSTLDFLAGS='${BUILD_LDFLAGS}'" |
| 552 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 553 | EXPORT_FUNCTIONS do_compile do_install do_configure |
| 554 | |
| 555 | # kernel-base becomes kernel-${KERNEL_VERSION} |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 556 | # kernel-image becomes kernel-image-${KERNEL_VERSION} |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 557 | PACKAGES = "${KERNEL_PACKAGE_NAME} ${KERNEL_PACKAGE_NAME}-base ${KERNEL_PACKAGE_NAME}-vmlinux ${KERNEL_PACKAGE_NAME}-image ${KERNEL_PACKAGE_NAME}-dev ${KERNEL_PACKAGE_NAME}-modules" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 558 | FILES_${PN} = "" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 559 | FILES_${KERNEL_PACKAGE_NAME}-base = "${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.order ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/modules.builtin" |
| 560 | FILES_${KERNEL_PACKAGE_NAME}-image = "" |
| 561 | FILES_${KERNEL_PACKAGE_NAME}-dev = "/boot/System.map* /boot/Module.symvers* /boot/config* ${KERNEL_SRC_PATH} ${nonarch_base_libdir}/modules/${KERNEL_VERSION}/build" |
| 562 | FILES_${KERNEL_PACKAGE_NAME}-vmlinux = "/boot/vmlinux-${KERNEL_VERSION_NAME}" |
| 563 | FILES_${KERNEL_PACKAGE_NAME}-modules = "" |
| 564 | RDEPENDS_${KERNEL_PACKAGE_NAME} = "${KERNEL_PACKAGE_NAME}-base" |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 565 | # Allow machines to override this dependency if kernel image files are |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 566 | # not wanted in images as standard |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 567 | RDEPENDS_${KERNEL_PACKAGE_NAME}-base ?= "${KERNEL_PACKAGE_NAME}-image" |
| 568 | PKG_${KERNEL_PACKAGE_NAME}-image = "${KERNEL_PACKAGE_NAME}-image-${@legitimize_package_name('${KERNEL_VERSION}')}" |
| 569 | RDEPENDS_${KERNEL_PACKAGE_NAME}-image += "${@oe.utils.conditional('KERNEL_IMAGETYPE', 'vmlinux', '${KERNEL_PACKAGE_NAME}-vmlinux', '', d)}" |
| 570 | PKG_${KERNEL_PACKAGE_NAME}-base = "${KERNEL_PACKAGE_NAME}-${@legitimize_package_name('${KERNEL_VERSION}')}" |
| 571 | RPROVIDES_${KERNEL_PACKAGE_NAME}-base += "${KERNEL_PACKAGE_NAME}-${KERNEL_VERSION}" |
| 572 | ALLOW_EMPTY_${KERNEL_PACKAGE_NAME} = "1" |
| 573 | ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-base = "1" |
| 574 | ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-image = "1" |
| 575 | ALLOW_EMPTY_${KERNEL_PACKAGE_NAME}-modules = "1" |
| 576 | DESCRIPTION_${KERNEL_PACKAGE_NAME}-modules = "Kernel modules meta package" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 577 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 578 | pkg_postinst_${KERNEL_PACKAGE_NAME}-base () { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 579 | if [ ! -e "$D/lib/modules/${KERNEL_VERSION}" ]; then |
| 580 | mkdir -p $D/lib/modules/${KERNEL_VERSION} |
| 581 | fi |
| 582 | if [ -n "$D" ]; then |
| 583 | depmodwrapper -a -b $D ${KERNEL_VERSION} |
| 584 | else |
| 585 | depmod -a ${KERNEL_VERSION} |
| 586 | fi |
| 587 | } |
| 588 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 589 | PACKAGESPLITFUNCS_prepend = "split_kernel_packages " |
| 590 | |
| 591 | python split_kernel_packages () { |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 592 | do_split_packages(d, root='${nonarch_base_libdir}/firmware', file_regex=r'^(.*)\.(bin|fw|cis|csp|dsp)$', output_pattern='${KERNEL_PACKAGE_NAME}-firmware-%s', description='Firmware for %s', recursive=True, extra_depends='') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | # Many scripts want to look in arch/$arch/boot for the bootable |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 596 | # image. This poses a problem for vmlinux and vmlinuz based |
| 597 | # booting. This task arranges to have vmlinux and vmlinuz appear |
| 598 | # in the normalized directory location. |
| 599 | do_kernel_link_images() { |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 600 | if [ ! -d "${B}/arch/${ARCH}/boot" ]; then |
| 601 | mkdir ${B}/arch/${ARCH}/boot |
| 602 | fi |
| 603 | cd ${B}/arch/${ARCH}/boot |
| 604 | ln -sf ../../../vmlinux |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 605 | if [ -f ../../../vmlinuz ]; then |
| 606 | ln -sf ../../../vmlinuz |
| 607 | fi |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 608 | if [ -f ../../../vmlinuz.bin ]; then |
| 609 | ln -sf ../../../vmlinuz.bin |
| 610 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 611 | } |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 612 | addtask kernel_link_images after do_compile before do_strip |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 613 | |
| 614 | do_strip() { |
| 615 | if [ -n "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" ]; then |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 616 | if ! (echo "${KERNEL_IMAGETYPES}" | grep -wq "vmlinux"); then |
| 617 | bbwarn "image type(s) will not be stripped (not supported): ${KERNEL_IMAGETYPES}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 618 | return |
| 619 | fi |
| 620 | |
| 621 | cd ${B} |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 622 | headers=`"$CROSS_COMPILE"readelf -S ${KERNEL_OUTPUT_DIR}/vmlinux | \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 623 | grep "^ \{1,\}\[[0-9 ]\{1,\}\] [^ ]" | \ |
| 624 | sed "s/^ \{1,\}\[[0-9 ]\{1,\}\] //" | \ |
| 625 | gawk '{print $1}'` |
| 626 | |
| 627 | for str in ${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}; do { |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 628 | if ! (echo "$headers" | grep -q "^$str$"); then |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 629 | bbwarn "Section not found: $str"; |
| 630 | fi |
| 631 | |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 632 | "$CROSS_COMPILE"strip -s -R $str ${KERNEL_OUTPUT_DIR}/vmlinux |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 633 | }; done |
| 634 | |
| 635 | bbnote "KERNEL_IMAGE_STRIP_EXTRA_SECTIONS is set, stripping sections:" \ |
| 636 | "${KERNEL_IMAGE_STRIP_EXTRA_SECTIONS}" |
| 637 | fi; |
| 638 | } |
| 639 | do_strip[dirs] = "${B}" |
| 640 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 641 | addtask strip before do_sizecheck after do_kernel_link_images |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 642 | |
| 643 | # Support checking the kernel size since some kernels need to reside in partitions |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 644 | # with a fixed length or there is a limit in transferring the kernel to memory. |
| 645 | # If more than one image type is enabled, warn on any that don't fit but only fail |
| 646 | # if none fit. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 647 | do_sizecheck() { |
| 648 | if [ ! -z "${KERNEL_IMAGE_MAXSIZE}" ]; then |
| 649 | invalid=`echo ${KERNEL_IMAGE_MAXSIZE} | sed 's/[0-9]//g'` |
| 650 | if [ -n "$invalid" ]; then |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 651 | die "Invalid KERNEL_IMAGE_MAXSIZE: ${KERNEL_IMAGE_MAXSIZE}, should be an integer (The unit is Kbytes)" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 652 | fi |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 653 | at_least_one_fits= |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 654 | for imageType in ${KERNEL_IMAGETYPES} ; do |
| 655 | size=`du -ks ${B}/${KERNEL_OUTPUT_DIR}/$imageType | awk '{print $1}'` |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 656 | if [ $size -ge ${KERNEL_IMAGE_MAXSIZE} ]; then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 657 | bbwarn "This kernel $imageType (size=$size(K) > ${KERNEL_IMAGE_MAXSIZE}(K)) is too big for your device." |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 658 | else |
| 659 | at_least_one_fits=y |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 660 | fi |
| 661 | done |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 662 | if [ -z "$at_least_one_fits" ]; then |
| 663 | die "All kernel images are too big for your device. Please reduce the size of the kernel by making more of it modular." |
| 664 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 665 | fi |
| 666 | } |
| 667 | do_sizecheck[dirs] = "${B}" |
| 668 | |
| 669 | addtask sizecheck before do_install after do_strip |
| 670 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 671 | inherit kernel-artifact-names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 672 | |
| 673 | kernel_do_deploy() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 674 | deployDir="${DEPLOYDIR}" |
| 675 | if [ -n "${KERNEL_DEPLOYSUBDIR}" ]; then |
| 676 | deployDir="${DEPLOYDIR}/${KERNEL_DEPLOYSUBDIR}" |
| 677 | mkdir "$deployDir" |
| 678 | fi |
| 679 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 680 | for imageType in ${KERNEL_IMAGETYPES} ; do |
| 681 | base_name=${imageType}-${KERNEL_IMAGE_NAME} |
| 682 | install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType} $deployDir/${base_name}.bin |
| 683 | symlink_name=${imageType}-${KERNEL_IMAGE_LINK_NAME} |
| 684 | ln -sf ${base_name}.bin $deployDir/${symlink_name}.bin |
| 685 | ln -sf ${base_name}.bin $deployDir/${imageType} |
He Zhe | fe76b1e | 2016-05-25 04:47:16 -0400 | [diff] [blame] | 686 | done |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 687 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 688 | if [ ${MODULE_TARBALL_DEPLOY} = "1" ] && (grep -q -i -e '^CONFIG_MODULES=y$' .config); then |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 689 | mkdir -p ${D}${root_prefix}/lib |
| 690 | tar -cvzf $deployDir/modules-${MODULE_TARBALL_NAME}.tgz -C ${D}${root_prefix} lib |
| 691 | ln -sf modules-${MODULE_TARBALL_NAME}.tgz $deployDir/modules-${MODULE_TARBALL_LINK_NAME}.tgz |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 692 | fi |
| 693 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 694 | if [ ! -z "${INITRAMFS_IMAGE}" -a x"${INITRAMFS_IMAGE_BUNDLE}" = x1 ]; then |
| 695 | for imageType in ${KERNEL_IMAGETYPES} ; do |
Brad Bishop | 977dc1a | 2019-02-06 16:01:43 -0500 | [diff] [blame] | 696 | if [ "$imageType" = "fitImage" ] ; then |
| 697 | continue |
| 698 | fi |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 699 | initramfs_base_name=${imageType}-${INITRAMFS_NAME} |
| 700 | initramfs_symlink_name=${imageType}-${INITRAMFS_LINK_NAME} |
| 701 | install -m 0644 ${KERNEL_OUTPUT_DIR}/${imageType}.initramfs $deployDir/${initramfs_base_name}.bin |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 702 | ln -sf ${initramfs_base_name}.bin $deployDir/${initramfs_symlink_name}.bin |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 703 | done |
| 704 | fi |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 705 | } |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 706 | do_deploy[cleandirs] = "${DEPLOYDIR}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 707 | do_deploy[dirs] = "${DEPLOYDIR} ${B}" |
| 708 | do_deploy[prefuncs] += "package_get_auto_pr" |
| 709 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 710 | addtask deploy after do_populate_sysroot do_packagedata |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 711 | |
| 712 | EXPORT_FUNCTIONS do_deploy |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 713 | |
| 714 | # Add using Device Tree support |
| 715 | inherit kernel-devicetree |