kernel-devsrc.bb 12 KB

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