1SUMMARY = "Linux kernel Development Source" 2DESCRIPTION = "Development source linux kernel. When built, this recipe packages the \ 3source of the preferred virtual/kernel provider and makes it available for full kernel \ 4development or external module builds" 5 6SECTION = "kernel" 7 8LICENSE = "GPLv2" 9 10inherit linux-kernel-base 11 12# Whilst not a module, this ensures we don't get multilib extended (which would make no sense) 13inherit 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. 18do_install[depends] += "virtual/kernel:do_shared_workdir" 19# Need the source, not just the output of populate_sysroot 20do_install[depends] += "virtual/kernel:do_install" 21 22# There's nothing to do here, except install the source where we can package it 23do_fetch[noexec] = "1" 24do_unpack[noexec] = "1" 25do_patch[noexec] = "1" 26do_configure[noexec] = "1" 27do_compile[noexec] = "1" 28deltask do_populate_sysroot 29 30S = "${STAGING_KERNEL_DIR}" 31B = "${STAGING_KERNEL_BUILDDIR}" 32 33PACKAGE_ARCH = "${MACHINE_ARCH}" 34 35KERNEL_BUILD_ROOT="/lib/modules/" 36 37do_install() { 38 kerneldir=${D}${KERNEL_BUILD_ROOT}${KERNEL_VERSION} 39 install -d $kerneldir 40 41 # create the directory structure 42 rm -f $kerneldir/build 43 rm -f $kerneldir/source 44 mkdir -p $kerneldir/build 45 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 51 ln -s ${KERNEL_BUILD_ROOT}${KERNEL_VERSION}/source kernel 52 ) 53 54 # for on target purposes, we unify build and source 55 ( 56 cd $kerneldir 57 ln -s build source 58 ) 59 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 ) 66 67 # then drop all but the needed Makefiles/Kconfig files 68 rm -rf $kerneldir/build/Documentation 69 rm -rf $kerneldir/build/scripts 70 rm -rf $kerneldir/build/include 71 72 # now copy in parts from the build that we'll need later 73 ( 74 cd ${B} 75 76 cp Module.symvers $kerneldir/build 77 cp System.map* $kerneldir/build 78 if [ -s Module.markers ]; then 79 cp Module.markers $kerneldir/build 80 fi 81 82 cp .config $kerneldir/build 83 84 # This scripts copy blow up QA, so for now, we require a more 85 # complex 'make scripts' to restore these, versus copying them 86 # here. Left as a reference to indicate that we know the scripts must 87 # be dealt with. 88 # cp -a scripts $kerneldir/build 89 90 if [ -d arch/${ARCH}/scripts ]; then 91 cp -a arch/${ARCH}/scripts $kerneldir/build/arch/${ARCH} 92 fi 93 if [ -f arch/${ARCH}/*lds ]; then 94 cp -a arch/${ARCH}/*lds $kerneldir/build/arch/${ARCH} 95 fi 96 97 rm -f $kerneldir/build/scripts/*.o 98 rm -f $kerneldir/build/scripts/*/*.o 99 100 if [ "${ARCH}" = "powerpc" ]; then 101 if [ -e arch/powerpc/lib/crtsavres.S ] || 102 [ -e arch/powerpc/lib/crtsavres.o ]; then 103 cp -a --parents arch/powerpc/lib/crtsavres.[So] $kerneldir/build/ 104 fi 105 fi 106 107 if [ "${ARCH}" = "arm64" ]; then 108 cp -a --parents arch/arm64/kernel/vdso/vdso.lds $kerneldir/build/ 109 fi 110 111 cp -a include $kerneldir/build/include 112 ) 113 114 # now grab the chunks from the source tree that we need 115 ( 116 cd ${S} 117 118 cp -a scripts $kerneldir/build 119 120 # if our build dir had objtool, it will also be rebuilt on target, so 121 # we copy what is required for that build 122 if [ -f ${B}/tools/objtool/objtool ]; then 123 # these are a few files associated with objtool, since we'll need to 124 # rebuild it 125 cp -a --parents tools/build/Build.include $kerneldir/build/ 126 cp -a --parents tools/build/Build $kerneldir/build/ 127 cp -a --parents tools/build/fixdep.c $kerneldir/build/ 128 cp -a --parents tools/scripts/utilities.mak $kerneldir/build/ 129 130 # extra files, just in case 131 cp -a --parents tools/objtool/* $kerneldir/build/ 132 cp -a --parents tools/lib/str_error_r.c $kerneldir/build/ 133 cp -a --parents tools/lib/string.c $kerneldir/build/ 134 cp -a --parents tools/lib/subcmd/* $kerneldir/build/ 135 136 cp -a --parents tools/include/* $kerneldir/build/ 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 145 cp -a --parents arch/arm64/kernel/vdso/gettimeofday.S $kerneldir/build/ 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 150 cp -a --parents arch/arm64/kernel/module.lds $kerneldir/build/ 151 fi 152 153 # include the machine specific headers for ARM variants, if available. 154 if [ "${ARCH}" = "arm" ]; then 155 cp -a --parents arch/${ARCH}/mach-*/include $kerneldir/build/ 156 157 # include a few files for 'make prepare' 158 cp -a --parents arch/arm/tools/gen-mach-types $kerneldir/build/ 159 cp -a --parents arch/arm/tools/mach-types $kerneldir/build/ 160 cp -a --parents arch/arm/tools/syscall* $kerneldir/build/ 161 162 cp -a --parents arch/arm/kernel/module.lds $kerneldir/build/ 163 fi 164 165 if [ -d arch/${ARCH}/include ]; then 166 cp -a --parents arch/${ARCH}/include $kerneldir/build/ 167 fi 168 169 cp -a include $kerneldir/build 170 171 cp -a --parents tools/include/tools/le_byteshift.h $kerneldir/build/ 172 cp -a --parents tools/include/tools/be_byteshift.h $kerneldir/build/ 173 174 # required for generate missing syscalls prepare phase 175 cp -a --parents arch/x86/entry/syscalls/syscall_32.tbl $kerneldir/build 176 177 if [ "${ARCH}" = "x86" ]; then 178 # files for 'make prepare' to succeed with kernel-devel 179 cp -a --parents arch/x86/entry/syscalls/syscall_32.tbl $kerneldir/build/ 180 cp -a --parents arch/x86/entry/syscalls/syscalltbl.sh $kerneldir/build/ 181 cp -a --parents arch/x86/entry/syscalls/syscallhdr.sh $kerneldir/build/ 182 cp -a --parents arch/x86/entry/syscalls/syscall_64.tbl $kerneldir/build/ 183 cp -a --parents arch/x86/tools/relocs_32.c $kerneldir/build/ 184 cp -a --parents arch/x86/tools/relocs_64.c $kerneldir/build/ 185 cp -a --parents arch/x86/tools/relocs.c $kerneldir/build/ 186 cp -a --parents arch/x86/tools/relocs_common.c $kerneldir/build/ 187 cp -a --parents arch/x86/tools/relocs.h $kerneldir/build/ 188 cp -a --parents arch/x86/purgatory/purgatory.c $kerneldir/build/ 189 190 # 4.18 + have unified the purgatory files, so we ignore any errors if 191 # these files are not present 192 cp -a --parents arch/x86/purgatory/sha256.h $kerneldir/build/ 2>/dev/null || : 193 cp -a --parents arch/x86/purgatory/sha256.c $kerneldir/build/ 2>/dev/null || : 194 195 cp -a --parents arch/x86/purgatory/stack.S $kerneldir/build/ 196 cp -a --parents arch/x86/purgatory/string.c $kerneldir/build/ 197 cp -a --parents arch/x86/purgatory/setup-x86_64.S $kerneldir/build/ 198 cp -a --parents arch/x86/purgatory/entry64.S $kerneldir/build/ 199 cp -a --parents arch/x86/boot/string.h $kerneldir/build/ 200 cp -a --parents arch/x86/boot/string.c $kerneldir/build/ 201 cp -a --parents arch/x86/boot/ctype.h $kerneldir/build/ 202 fi 203 204 if [ "${ARCH}" = "mips" ]; then 205 cp -a --parents arch/mips/Kbuild.platforms $kerneldir/build/ 206 cp --parents $(find -type f -name "Platform") $kerneldir/build 207 cp --parents arch/mips/boot/tools/relocs* $kerneldir/build 208 cp -a --parents arch/mips/kernel/asm-offsets.c $kerneldir/build 209 cp -a --parents kernel/time/timeconst.bc $kerneldir/build 210 cp -a --parents kernel/bounds.c $kerneldir/build 211 cp -a --parents Kbuild $kerneldir/build 212 fi 213 214 # required to build scripts/selinux/genheaders/genheaders 215 cp -a --parents security/selinux/include/* $kerneldir/build/ 216 ) 217 218 # Make sure the Makefile and version.h have a matching timestamp so that 219 # external modules can be built 220 touch -r $kerneldir/build/Makefile $kerneldir/build/include/generated/uapi/linux/version.h 221 222 # Copy .config to include/config/auto.conf so "make prepare" is unnecessary. 223 cp $kerneldir/build/.config $kerneldir/build/include/config/auto.conf 224 225 chown -R root:root ${D} 226} 227 228# Ensure we don't race against "make scripts" during cpio 229do_install[lockfiles] = "${TMPDIR}/kernel-scripts.lock" 230 231FILES_${PN} = "${KERNEL_BUILD_ROOT} ${KERNEL_SRC_PATH}" 232FILES_${PN}-dbg += "${KERNEL_BUILD_ROOT}*/build/scripts/*/.debug/*" 233 234RDEPENDS_${PN} = "bc python flex bison ${TCLIBC}-utils" 235# 4.15+ needs these next two RDEPENDS 236RDEPENDS_${PN} += "openssl-dev util-linux" 237# and x86 needs a bit more for 4.15+ 238RDEPENDS_${PN} += "${@bb.utils.contains('ARCH', 'x86', 'elfutils', '', d)}" 239