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