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