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