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