Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | SUMMARY = "Linux kernel Development Source" |
| 2 | DESCRIPTION = "Development source linux kernel. When built, this recipe packages the \ |
| 3 | source of the preferred virtual/kernel provider and makes it available for full kernel \ |
| 4 | development or external module builds" |
| 5 | |
| 6 | SECTION = "kernel" |
| 7 | |
| 8 | LICENSE = "GPLv2" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | |
| 10 | inherit linux-kernel-base |
| 11 | |
| 12 | # Whilst not a module, this ensures we don't get multilib extended (which would make no sense) |
| 13 | inherit module-base |
| 14 | |
| 15 | # We need the kernel to be staged (unpacked, patched and configured) before |
| 16 | # we can grab the source and make the source package. We also need the bits from |
| 17 | # ${B} not to change while we install, so virtual/kernel must finish do_compile. |
| 18 | do_install[depends] += "virtual/kernel:do_shared_workdir" |
| 19 | # Need the source, not just the output of populate_sysroot |
| 20 | do_install[depends] += "virtual/kernel:do_install" |
| 21 | |
| 22 | # There's nothing to do here, except install the source where we can package it |
| 23 | do_fetch[noexec] = "1" |
| 24 | do_unpack[noexec] = "1" |
| 25 | do_patch[noexec] = "1" |
| 26 | do_configure[noexec] = "1" |
| 27 | do_compile[noexec] = "1" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 28 | deltask do_populate_sysroot |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 30 | S = "${STAGING_KERNEL_DIR}" |
| 31 | B = "${STAGING_KERNEL_BUILDDIR}" |
| 32 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | PACKAGE_ARCH = "${MACHINE_ARCH}" |
| 34 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 35 | KERNEL_BUILD_ROOT="${nonarch_base_libdir}/modules/" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 36 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | do_install() { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 38 | kerneldir=${D}${KERNEL_BUILD_ROOT}${KERNEL_VERSION} |
| 39 | install -d $kerneldir |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 41 | # create the directory structure |
| 42 | rm -f $kerneldir/build |
| 43 | rm -f $kerneldir/source |
| 44 | mkdir -p $kerneldir/build |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 46 | # for compatibility with some older variants of this package, we |
| 47 | # create a /usr/src/kernel symlink to /lib/modules/<version>/source |
| 48 | mkdir -p ${D}/usr/src |
| 49 | ( |
| 50 | cd ${D}/usr/src |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 51 | lnr ${D}${KERNEL_BUILD_ROOT}${KERNEL_VERSION}/source kernel |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 52 | ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 54 | # for on target purposes, we unify build and source |
| 55 | ( |
| 56 | cd $kerneldir |
| 57 | ln -s build source |
| 58 | ) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 60 | # first copy everything |
| 61 | ( |
| 62 | cd ${S} |
| 63 | cp --parents $(find -type f -name "Makefile*" -o -name "Kconfig*") $kerneldir/build |
| 64 | cp --parents $(find -type f -name "Build" -o -name "Build.include") $kerneldir/build |
| 65 | ) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 66 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 67 | # then drop all but the needed Makefiles/Kconfig files |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 68 | rm -rf $kerneldir/build/scripts |
| 69 | rm -rf $kerneldir/build/include |
| 70 | |
| 71 | # now copy in parts from the build that we'll need later |
| 72 | ( |
| 73 | cd ${B} |
| 74 | |
| 75 | cp Module.symvers $kerneldir/build |
| 76 | cp System.map* $kerneldir/build |
| 77 | if [ -s Module.markers ]; then |
| 78 | cp Module.markers $kerneldir/build |
| 79 | fi |
| 80 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 81 | cp -a .config $kerneldir/build |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 82 | |
| 83 | # This scripts copy blow up QA, so for now, we require a more |
| 84 | # complex 'make scripts' to restore these, versus copying them |
| 85 | # here. Left as a reference to indicate that we know the scripts must |
| 86 | # be dealt with. |
| 87 | # cp -a scripts $kerneldir/build |
| 88 | |
| 89 | if [ -d arch/${ARCH}/scripts ]; then |
| 90 | cp -a arch/${ARCH}/scripts $kerneldir/build/arch/${ARCH} |
| 91 | fi |
| 92 | if [ -f arch/${ARCH}/*lds ]; then |
| 93 | cp -a arch/${ARCH}/*lds $kerneldir/build/arch/${ARCH} |
| 94 | fi |
| 95 | |
| 96 | rm -f $kerneldir/build/scripts/*.o |
| 97 | rm -f $kerneldir/build/scripts/*/*.o |
| 98 | |
| 99 | if [ "${ARCH}" = "powerpc" ]; then |
| 100 | if [ -e arch/powerpc/lib/crtsavres.S ] || |
| 101 | [ -e arch/powerpc/lib/crtsavres.o ]; then |
| 102 | cp -a --parents arch/powerpc/lib/crtsavres.[So] $kerneldir/build/ |
| 103 | fi |
| 104 | fi |
| 105 | |
| 106 | if [ "${ARCH}" = "arm64" ]; then |
| 107 | cp -a --parents arch/arm64/kernel/vdso/vdso.lds $kerneldir/build/ |
| 108 | fi |
| 109 | |
| 110 | cp -a include $kerneldir/build/include |
| 111 | ) |
| 112 | |
| 113 | # now grab the chunks from the source tree that we need |
| 114 | ( |
| 115 | cd ${S} |
| 116 | |
| 117 | cp -a scripts $kerneldir/build |
| 118 | |
| 119 | # if our build dir had objtool, it will also be rebuilt on target, so |
| 120 | # we copy what is required for that build |
| 121 | if [ -f ${B}/tools/objtool/objtool ]; then |
| 122 | # these are a few files associated with objtool, since we'll need to |
| 123 | # rebuild it |
| 124 | cp -a --parents tools/build/Build.include $kerneldir/build/ |
| 125 | cp -a --parents tools/build/Build $kerneldir/build/ |
| 126 | cp -a --parents tools/build/fixdep.c $kerneldir/build/ |
| 127 | cp -a --parents tools/scripts/utilities.mak $kerneldir/build/ |
| 128 | |
| 129 | # extra files, just in case |
| 130 | cp -a --parents tools/objtool/* $kerneldir/build/ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 131 | cp -a --parents tools/lib/* $kerneldir/build/ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 132 | cp -a --parents tools/lib/subcmd/* $kerneldir/build/ |
| 133 | |
| 134 | cp -a --parents tools/include/* $kerneldir/build/ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 135 | |
| 136 | cp -a --parents $(find tools/arch/${ARCH}/ -type f) $kerneldir/build/ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 137 | fi |
| 138 | |
| 139 | if [ "${ARCH}" = "arm64" ]; then |
| 140 | # arch/arm64/include/asm/xen references arch/arm |
| 141 | cp -a --parents arch/arm/include/asm/xen $kerneldir/build/ |
| 142 | # arch/arm64/include/asm/opcodes.h references arch/arm |
| 143 | cp -a --parents arch/arm/include/asm/opcodes.h $kerneldir/build/ |
| 144 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 145 | cp -a --parents arch/arm64/kernel/vdso/*gettimeofday.* $kerneldir/build/ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 146 | cp -a --parents arch/arm64/kernel/vdso/sigreturn.S $kerneldir/build/ |
| 147 | cp -a --parents arch/arm64/kernel/vdso/note.S $kerneldir/build/ |
| 148 | cp -a --parents arch/arm64/kernel/vdso/gen_vdso_offsets.sh $kerneldir/build/ |
| 149 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 150 | cp -a --parents arch/arm64/kernel/module.lds $kerneldir/build/ 2>/dev/null || : |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 151 | fi |
| 152 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 153 | if [ "${ARCH}" = "powerpc" ]; then |
| 154 | # 5.0 needs these files, but don't error if they aren't present in the source |
| 155 | cp -a --parents arch/${ARCH}/kernel/syscalls/syscall.tbl $kerneldir/build/ 2>/dev/null || : |
| 156 | cp -a --parents arch/${ARCH}/kernel/syscalls/syscalltbl.sh $kerneldir/build/ 2>/dev/null || : |
| 157 | cp -a --parents arch/${ARCH}/kernel/syscalls/syscallhdr.sh $kerneldir/build/ 2>/dev/null || : |
| 158 | fi |
| 159 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 160 | # include the machine specific headers for ARM variants, if available. |
| 161 | if [ "${ARCH}" = "arm" ]; then |
| 162 | cp -a --parents arch/${ARCH}/mach-*/include $kerneldir/build/ |
| 163 | |
| 164 | # include a few files for 'make prepare' |
| 165 | cp -a --parents arch/arm/tools/gen-mach-types $kerneldir/build/ |
| 166 | cp -a --parents arch/arm/tools/mach-types $kerneldir/build/ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 167 | |
| 168 | # ARM syscall table tools only exist for kernels v4.10 or later |
| 169 | SYSCALL_TOOLS=$(find arch/arm/tools -name "syscall*") |
| 170 | if [ -n "$SYSCALL_TOOLS" ] ; then |
| 171 | cp -a --parents $SYSCALL_TOOLS $kerneldir/build/ |
| 172 | fi |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 173 | |
| 174 | cp -a --parents arch/arm/kernel/module.lds $kerneldir/build/ |
| 175 | fi |
| 176 | |
| 177 | if [ -d arch/${ARCH}/include ]; then |
| 178 | cp -a --parents arch/${ARCH}/include $kerneldir/build/ |
| 179 | fi |
| 180 | |
| 181 | cp -a include $kerneldir/build |
| 182 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 183 | cp -a --parents lib/vdso/* $kerneldir/build/ 2>/dev/null || : |
| 184 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 185 | cp -a --parents tools/include/tools/le_byteshift.h $kerneldir/build/ |
| 186 | cp -a --parents tools/include/tools/be_byteshift.h $kerneldir/build/ |
| 187 | |
| 188 | # required for generate missing syscalls prepare phase |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 189 | cp -a --parents $(find arch/x86 -type f -name "syscall_32.tbl") $kerneldir/build |
| 190 | cp -a --parents $(find arch/arm -type f -name "*.tbl") $kerneldir/build 2>/dev/null || : |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 191 | |
| 192 | if [ "${ARCH}" = "x86" ]; then |
| 193 | # files for 'make prepare' to succeed with kernel-devel |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 194 | cp -a --parents $(find arch/x86 -type f -name "syscall_32.tbl") $kerneldir/build/ |
| 195 | cp -a --parents $(find arch/x86 -type f -name "syscalltbl.sh") $kerneldir/build/ |
| 196 | cp -a --parents $(find arch/x86 -type f -name "syscallhdr.sh") $kerneldir/build/ |
| 197 | cp -a --parents $(find arch/x86 -type f -name "syscall_64.tbl") $kerneldir/build/ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 198 | cp -a --parents arch/x86/tools/relocs_32.c $kerneldir/build/ |
| 199 | cp -a --parents arch/x86/tools/relocs_64.c $kerneldir/build/ |
| 200 | cp -a --parents arch/x86/tools/relocs.c $kerneldir/build/ |
| 201 | cp -a --parents arch/x86/tools/relocs_common.c $kerneldir/build/ |
| 202 | cp -a --parents arch/x86/tools/relocs.h $kerneldir/build/ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 203 | cp -a --parents arch/x86/tools/gen-insn-attr-x86.awk $kerneldir/build/ 2>/dev/null || : |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 204 | cp -a --parents arch/x86/purgatory/purgatory.c $kerneldir/build/ |
| 205 | |
| 206 | # 4.18 + have unified the purgatory files, so we ignore any errors if |
| 207 | # these files are not present |
| 208 | cp -a --parents arch/x86/purgatory/sha256.h $kerneldir/build/ 2>/dev/null || : |
| 209 | cp -a --parents arch/x86/purgatory/sha256.c $kerneldir/build/ 2>/dev/null || : |
| 210 | |
| 211 | cp -a --parents arch/x86/purgatory/stack.S $kerneldir/build/ |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 212 | cp -a --parents arch/x86/purgatory/string.c $kerneldir/build/ 2>/dev/null || : |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 213 | cp -a --parents arch/x86/purgatory/setup-x86_64.S $kerneldir/build/ |
| 214 | cp -a --parents arch/x86/purgatory/entry64.S $kerneldir/build/ |
| 215 | cp -a --parents arch/x86/boot/string.h $kerneldir/build/ |
| 216 | cp -a --parents arch/x86/boot/string.c $kerneldir/build/ |
Brad Bishop | c68388fc | 2019-08-26 01:33:31 -0400 | [diff] [blame] | 217 | cp -a --parents arch/x86/boot/compressed/string.c $kerneldir/build/ 2>/dev/null || : |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 218 | cp -a --parents arch/x86/boot/ctype.h $kerneldir/build/ |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 219 | |
| 220 | # objtool requires these files |
| 221 | cp -a --parents arch/x86/lib/inat.c $kerneldir/build/ 2>/dev/null || : |
| 222 | cp -a --parents arch/x86/lib/insn.c $kerneldir/build/ 2>/dev/null || : |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 223 | fi |
| 224 | |
| 225 | if [ "${ARCH}" = "mips" ]; then |
| 226 | cp -a --parents arch/mips/Kbuild.platforms $kerneldir/build/ |
| 227 | cp --parents $(find -type f -name "Platform") $kerneldir/build |
| 228 | cp --parents arch/mips/boot/tools/relocs* $kerneldir/build |
| 229 | cp -a --parents arch/mips/kernel/asm-offsets.c $kerneldir/build |
| 230 | cp -a --parents kernel/time/timeconst.bc $kerneldir/build |
| 231 | cp -a --parents kernel/bounds.c $kerneldir/build |
| 232 | cp -a --parents Kbuild $kerneldir/build |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 233 | cp -a --parents arch/mips/kernel/syscalls/*.sh $kerneldir/build 2>/dev/null || : |
| 234 | cp -a --parents arch/mips/kernel/syscalls/*.tbl $kerneldir/build 2>/dev/null || : |
| 235 | cp -a --parents arch/mips/tools/elf-entry.c $kerneldir/build 2>/dev/null || : |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 236 | fi |
| 237 | |
| 238 | # required to build scripts/selinux/genheaders/genheaders |
| 239 | cp -a --parents security/selinux/include/* $kerneldir/build/ |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 240 | |
| 241 | # copy any localversion files |
| 242 | cp -a localversion* $kerneldir/build/ 2>/dev/null || : |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 243 | ) |
| 244 | |
| 245 | # Make sure the Makefile and version.h have a matching timestamp so that |
| 246 | # external modules can be built |
| 247 | touch -r $kerneldir/build/Makefile $kerneldir/build/include/generated/uapi/linux/version.h |
| 248 | |
| 249 | # Copy .config to include/config/auto.conf so "make prepare" is unnecessary. |
| 250 | cp $kerneldir/build/.config $kerneldir/build/include/config/auto.conf |
| 251 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 252 | # make the scripts python3 safe. We won't be running these, and if they are |
| 253 | # left as /usr/bin/python rootfs assembly will fail, since we only have python3 |
| 254 | # in the RDEPENDS (and the python3 package does not include /usr/bin/python) |
| 255 | for ss in $(find $kerneldir/build/scripts -type f -name '*'); do |
| 256 | sed -i 's,/usr/bin/python2,/usr/bin/env python3,' "$ss" |
| 257 | sed -i 's,/usr/bin/env python2,/usr/bin/env python3,' "$ss" |
| 258 | sed -i 's,/usr/bin/python,/usr/bin/env python3,' "$ss" |
| 259 | done |
| 260 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 261 | chown -R root:root ${D} |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | } |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 263 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 264 | # Ensure we don't race against "make scripts" during cpio |
| 265 | do_install[lockfiles] = "${TMPDIR}/kernel-scripts.lock" |
| 266 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 267 | FILES_${PN} = "${KERNEL_BUILD_ROOT} ${KERNEL_SRC_PATH}" |
| 268 | FILES_${PN}-dbg += "${KERNEL_BUILD_ROOT}*/build/scripts/*/.debug/*" |
| 269 | |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 270 | RDEPENDS_${PN} = "bc python3 flex bison ${TCLIBC}-utils" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 271 | # 4.15+ needs these next two RDEPENDS |
| 272 | RDEPENDS_${PN} += "openssl-dev util-linux" |
| 273 | # and x86 needs a bit more for 4.15+ |
| 274 | RDEPENDS_${PN} += "${@bb.utils.contains('ARCH', 'x86', 'elfutils', '', d)}" |