blob: 8a900ed18298b0c770e2bfd47651f4bb8bf10dd3 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001SUMMARY = "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"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05009
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"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080028deltask do_populate_sysroot
Patrick Williamsc124f4f2015-09-15 14:41:29 -050029
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030S = "${STAGING_KERNEL_DIR}"
31B = "${STAGING_KERNEL_BUILDDIR}"
32
Patrick Williamsc124f4f2015-09-15 14:41:29 -050033PACKAGE_ARCH = "${MACHINE_ARCH}"
34
Brad Bishop19323692019-04-05 15:28:33 -040035KERNEL_BUILD_ROOT="${nonarch_base_libdir}/modules/"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080036
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037do_install() {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080038 kerneldir=${D}${KERNEL_BUILD_ROOT}${KERNEL_VERSION}
39 install -d $kerneldir
Patrick Williamsc124f4f2015-09-15 14:41:29 -050040
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080041 # create the directory structure
42 rm -f $kerneldir/build
43 rm -f $kerneldir/source
44 mkdir -p $kerneldir/build
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080046 # 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 Bishop19323692019-04-05 15:28:33 -040051 lnr ${D}${KERNEL_BUILD_ROOT}${KERNEL_VERSION}/source kernel
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080052 )
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080054 # for on target purposes, we unify build and source
55 (
56 cd $kerneldir
57 ln -s build source
58 )
Patrick Williamsc124f4f2015-09-15 14:41:29 -050059
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080060 # 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 Bishop316dfdd2018-06-25 12:45:53 -040066
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080067 # then drop all but the needed Makefiles/Kconfig files
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080068 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 Geissler82c905d2020-04-13 13:39:40 -050081 cp -a .config $kerneldir/build
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080082
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
Andrew Geissler6ce62a22020-11-30 19:58:47 -060089 # although module.lds can be regenerated on target via 'make modules_prepare'
90 # there are several places where 'makes scripts prepare' is done, and that won't
91 # regenerate the file. So we copy it onto the target as a migration to using
92 # modules_prepare
93 cp -a --parents scripts/module.lds $kerneldir/build/ 2>/dev/null || :
94
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080095 if [ -d arch/${ARCH}/scripts ]; then
96 cp -a arch/${ARCH}/scripts $kerneldir/build/arch/${ARCH}
97 fi
98 if [ -f arch/${ARCH}/*lds ]; then
99 cp -a arch/${ARCH}/*lds $kerneldir/build/arch/${ARCH}
100 fi
101
102 rm -f $kerneldir/build/scripts/*.o
103 rm -f $kerneldir/build/scripts/*/*.o
104
105 if [ "${ARCH}" = "powerpc" ]; then
106 if [ -e arch/powerpc/lib/crtsavres.S ] ||
107 [ -e arch/powerpc/lib/crtsavres.o ]; then
108 cp -a --parents arch/powerpc/lib/crtsavres.[So] $kerneldir/build/
109 fi
110 fi
111
112 if [ "${ARCH}" = "arm64" ]; then
113 cp -a --parents arch/arm64/kernel/vdso/vdso.lds $kerneldir/build/
114 fi
115
116 cp -a include $kerneldir/build/include
Andrew Geisslerb7d28612020-07-24 16:15:54 -0500117
118 # we don't usually copy generated files, since they can be rebuilt on the target,
119 # but without this file, we get a forced syncconfig run in v5.8+, which prompts and
120 # breaks workflows.
121 cp -a --parents include/generated/autoconf.h $kerneldir/build 2>/dev/null || :
Andrew Geissler6ce62a22020-11-30 19:58:47 -0600122
123 if [ -e $kerneldir/include/generated/.vdso-offsets.h.cmd ]; then
124 rm $kerneldir/include/generated/.vdso-offsets.h.cmd
125 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800126 )
127
128 # now grab the chunks from the source tree that we need
129 (
130 cd ${S}
131
132 cp -a scripts $kerneldir/build
133
134 # if our build dir had objtool, it will also be rebuilt on target, so
135 # we copy what is required for that build
136 if [ -f ${B}/tools/objtool/objtool ]; then
137 # these are a few files associated with objtool, since we'll need to
138 # rebuild it
139 cp -a --parents tools/build/Build.include $kerneldir/build/
140 cp -a --parents tools/build/Build $kerneldir/build/
141 cp -a --parents tools/build/fixdep.c $kerneldir/build/
142 cp -a --parents tools/scripts/utilities.mak $kerneldir/build/
143
144 # extra files, just in case
145 cp -a --parents tools/objtool/* $kerneldir/build/
Andrew Geissler82c905d2020-04-13 13:39:40 -0500146 cp -a --parents tools/lib/* $kerneldir/build/
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800147 cp -a --parents tools/lib/subcmd/* $kerneldir/build/
148
149 cp -a --parents tools/include/* $kerneldir/build/
Andrew Geissler82c905d2020-04-13 13:39:40 -0500150
151 cp -a --parents $(find tools/arch/${ARCH}/ -type f) $kerneldir/build/
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800152 fi
153
154 if [ "${ARCH}" = "arm64" ]; then
155 # arch/arm64/include/asm/xen references arch/arm
156 cp -a --parents arch/arm/include/asm/xen $kerneldir/build/
157 # arch/arm64/include/asm/opcodes.h references arch/arm
158 cp -a --parents arch/arm/include/asm/opcodes.h $kerneldir/build/
159
Brad Bishop79641f22019-09-10 07:20:22 -0400160 cp -a --parents arch/arm64/kernel/vdso/*gettimeofday.* $kerneldir/build/
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800161 cp -a --parents arch/arm64/kernel/vdso/sigreturn.S $kerneldir/build/
162 cp -a --parents arch/arm64/kernel/vdso/note.S $kerneldir/build/
163 cp -a --parents arch/arm64/kernel/vdso/gen_vdso_offsets.sh $kerneldir/build/
164
Andrew Geissler82c905d2020-04-13 13:39:40 -0500165 cp -a --parents arch/arm64/kernel/module.lds $kerneldir/build/ 2>/dev/null || :
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800166 fi
167
Brad Bishop19323692019-04-05 15:28:33 -0400168 if [ "${ARCH}" = "powerpc" ]; then
169 # 5.0 needs these files, but don't error if they aren't present in the source
170 cp -a --parents arch/${ARCH}/kernel/syscalls/syscall.tbl $kerneldir/build/ 2>/dev/null || :
171 cp -a --parents arch/${ARCH}/kernel/syscalls/syscalltbl.sh $kerneldir/build/ 2>/dev/null || :
172 cp -a --parents arch/${ARCH}/kernel/syscalls/syscallhdr.sh $kerneldir/build/ 2>/dev/null || :
173 fi
174
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800175 # include the machine specific headers for ARM variants, if available.
176 if [ "${ARCH}" = "arm" ]; then
177 cp -a --parents arch/${ARCH}/mach-*/include $kerneldir/build/
178
179 # include a few files for 'make prepare'
180 cp -a --parents arch/arm/tools/gen-mach-types $kerneldir/build/
181 cp -a --parents arch/arm/tools/mach-types $kerneldir/build/
Brad Bishop19323692019-04-05 15:28:33 -0400182
183 # ARM syscall table tools only exist for kernels v4.10 or later
184 SYSCALL_TOOLS=$(find arch/arm/tools -name "syscall*")
185 if [ -n "$SYSCALL_TOOLS" ] ; then
186 cp -a --parents $SYSCALL_TOOLS $kerneldir/build/
187 fi
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800188
Andrew Geissler706d5aa2021-02-12 15:55:30 -0600189 cp -a --parents arch/arm/kernel/module.lds $kerneldir/build/
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800190 fi
191
192 if [ -d arch/${ARCH}/include ]; then
193 cp -a --parents arch/${ARCH}/include $kerneldir/build/
194 fi
195
196 cp -a include $kerneldir/build
197
Brad Bishop79641f22019-09-10 07:20:22 -0400198 cp -a --parents lib/vdso/* $kerneldir/build/ 2>/dev/null || :
199
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800200 cp -a --parents tools/include/tools/le_byteshift.h $kerneldir/build/
201 cp -a --parents tools/include/tools/be_byteshift.h $kerneldir/build/
202
203 # required for generate missing syscalls prepare phase
Andrew Geissler82c905d2020-04-13 13:39:40 -0500204 cp -a --parents $(find arch/x86 -type f -name "syscall_32.tbl") $kerneldir/build
205 cp -a --parents $(find arch/arm -type f -name "*.tbl") $kerneldir/build 2>/dev/null || :
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800206
207 if [ "${ARCH}" = "x86" ]; then
208 # files for 'make prepare' to succeed with kernel-devel
Andrew Geissler82c905d2020-04-13 13:39:40 -0500209 cp -a --parents $(find arch/x86 -type f -name "syscall_32.tbl") $kerneldir/build/
210 cp -a --parents $(find arch/x86 -type f -name "syscalltbl.sh") $kerneldir/build/
211 cp -a --parents $(find arch/x86 -type f -name "syscallhdr.sh") $kerneldir/build/
212 cp -a --parents $(find arch/x86 -type f -name "syscall_64.tbl") $kerneldir/build/
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800213 cp -a --parents arch/x86/tools/relocs_32.c $kerneldir/build/
214 cp -a --parents arch/x86/tools/relocs_64.c $kerneldir/build/
215 cp -a --parents arch/x86/tools/relocs.c $kerneldir/build/
216 cp -a --parents arch/x86/tools/relocs_common.c $kerneldir/build/
217 cp -a --parents arch/x86/tools/relocs.h $kerneldir/build/
Andrew Geissler82c905d2020-04-13 13:39:40 -0500218 cp -a --parents arch/x86/tools/gen-insn-attr-x86.awk $kerneldir/build/ 2>/dev/null || :
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800219 cp -a --parents arch/x86/purgatory/purgatory.c $kerneldir/build/
220
221 # 4.18 + have unified the purgatory files, so we ignore any errors if
222 # these files are not present
223 cp -a --parents arch/x86/purgatory/sha256.h $kerneldir/build/ 2>/dev/null || :
224 cp -a --parents arch/x86/purgatory/sha256.c $kerneldir/build/ 2>/dev/null || :
225
226 cp -a --parents arch/x86/purgatory/stack.S $kerneldir/build/
Brad Bishopc68388fc2019-08-26 01:33:31 -0400227 cp -a --parents arch/x86/purgatory/string.c $kerneldir/build/ 2>/dev/null || :
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800228 cp -a --parents arch/x86/purgatory/setup-x86_64.S $kerneldir/build/
229 cp -a --parents arch/x86/purgatory/entry64.S $kerneldir/build/
230 cp -a --parents arch/x86/boot/string.h $kerneldir/build/
231 cp -a --parents arch/x86/boot/string.c $kerneldir/build/
Brad Bishopc68388fc2019-08-26 01:33:31 -0400232 cp -a --parents arch/x86/boot/compressed/string.c $kerneldir/build/ 2>/dev/null || :
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800233 cp -a --parents arch/x86/boot/ctype.h $kerneldir/build/
Andrew Geissler82c905d2020-04-13 13:39:40 -0500234
235 # objtool requires these files
236 cp -a --parents arch/x86/lib/inat.c $kerneldir/build/ 2>/dev/null || :
237 cp -a --parents arch/x86/lib/insn.c $kerneldir/build/ 2>/dev/null || :
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800238 fi
239
240 if [ "${ARCH}" = "mips" ]; then
241 cp -a --parents arch/mips/Kbuild.platforms $kerneldir/build/
242 cp --parents $(find -type f -name "Platform") $kerneldir/build
243 cp --parents arch/mips/boot/tools/relocs* $kerneldir/build
244 cp -a --parents arch/mips/kernel/asm-offsets.c $kerneldir/build
245 cp -a --parents kernel/time/timeconst.bc $kerneldir/build
246 cp -a --parents kernel/bounds.c $kerneldir/build
247 cp -a --parents Kbuild $kerneldir/build
Brad Bishop19323692019-04-05 15:28:33 -0400248 cp -a --parents arch/mips/kernel/syscalls/*.sh $kerneldir/build 2>/dev/null || :
249 cp -a --parents arch/mips/kernel/syscalls/*.tbl $kerneldir/build 2>/dev/null || :
250 cp -a --parents arch/mips/tools/elf-entry.c $kerneldir/build 2>/dev/null || :
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800251 fi
252
253 # required to build scripts/selinux/genheaders/genheaders
254 cp -a --parents security/selinux/include/* $kerneldir/build/
Brad Bishopc342db32019-05-15 21:57:59 -0400255
256 # copy any localversion files
257 cp -a localversion* $kerneldir/build/ 2>/dev/null || :
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800258 )
259
260 # Make sure the Makefile and version.h have a matching timestamp so that
261 # external modules can be built
262 touch -r $kerneldir/build/Makefile $kerneldir/build/include/generated/uapi/linux/version.h
263
264 # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
265 cp $kerneldir/build/.config $kerneldir/build/include/config/auto.conf
266
Andrew Geisslerb7d28612020-07-24 16:15:54 -0500267 # make sure these are at least as old as the .config, or rebuilds will trigger
268 touch -r $kerneldir/build/.config $kerneldir/build/include/generated/autoconf.h 2>/dev/null || :
269 touch -r $kerneldir/build/.config $kerneldir/build/include/config/auto.conf* 2>/dev/null || :
270
271 if [ -e "$kerneldir/build/include/config/auto.conf.cmd" ]; then
Andrew Geissler635e0e42020-08-21 15:58:33 -0500272 sed -i 's/ifneq "$(CC)" ".*-linux-.*gcc.*$/ifneq "$(CC)" "gcc"/' "$kerneldir/build/include/config/auto.conf.cmd"
273 sed -i 's/ifneq "$(LD)" ".*-linux-.*ld.bfd.*$/ifneq "$(LD)" "ld"/' "$kerneldir/build/include/config/auto.conf.cmd"
Andrew Geisslerc9f78652020-09-18 14:11:35 -0500274 sed -i 's/ifneq "$(HOSTCXX)" ".*$/ifneq "$(HOSTCXX)" "g++"/' "$kerneldir/build/include/config/auto.conf.cmd"
275 sed -i 's/ifneq "$(HOSTCC)" ".*$/ifneq "$(HOSTCC)" "gcc"/' "$kerneldir/build/include/config/auto.conf.cmd"
Andrew Geisslerb7d28612020-07-24 16:15:54 -0500276 sed -i 's/ifneq "$(CC_VERSION_TEXT)".*\(gcc.*\)"/ifneq "$(CC_VERSION_TEXT)" "\1"/' "$kerneldir/build/include/config/auto.conf.cmd"
277 sed -i 's/ifneq "$(srctree)" ".*"/ifneq "$(srctree)" "."/' "$kerneldir/build/include/config/auto.conf.cmd"
Andrew Geissler635e0e42020-08-21 15:58:33 -0500278 # we don't build against the defconfig, so make sure it isn't the trigger for syncconfig
279 sed -i 's/ifneq "$(KBUILD_DEFCONFIG)".*"\(.*\)"/ifneq "\1" "\1"/' "$kerneldir/build/include/config/auto.conf.cmd"
Andrew Geisslerb7d28612020-07-24 16:15:54 -0500280 fi
281
Brad Bishop79641f22019-09-10 07:20:22 -0400282 # make the scripts python3 safe. We won't be running these, and if they are
283 # left as /usr/bin/python rootfs assembly will fail, since we only have python3
284 # in the RDEPENDS (and the python3 package does not include /usr/bin/python)
285 for ss in $(find $kerneldir/build/scripts -type f -name '*'); do
286 sed -i 's,/usr/bin/python2,/usr/bin/env python3,' "$ss"
287 sed -i 's,/usr/bin/env python2,/usr/bin/env python3,' "$ss"
288 sed -i 's,/usr/bin/python,/usr/bin/env python3,' "$ss"
289 done
290
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800291 chown -R root:root ${D}
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292}
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800293
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500294# Ensure we don't race against "make scripts" during cpio
295do_install[lockfiles] = "${TMPDIR}/kernel-scripts.lock"
296
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800297FILES_${PN} = "${KERNEL_BUILD_ROOT} ${KERNEL_SRC_PATH}"
298FILES_${PN}-dbg += "${KERNEL_BUILD_ROOT}*/build/scripts/*/.debug/*"
299
Brad Bishop79641f22019-09-10 07:20:22 -0400300RDEPENDS_${PN} = "bc python3 flex bison ${TCLIBC}-utils"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800301# 4.15+ needs these next two RDEPENDS
302RDEPENDS_${PN} += "openssl-dev util-linux"
303# and x86 needs a bit more for 4.15+
304RDEPENDS_${PN} += "${@bb.utils.contains('ARCH', 'x86', 'elfutils', '', d)}"
Andrew Geissler635e0e42020-08-21 15:58:33 -0500305# 5.8+ needs gcc-plugins libmpc-dev
306RDEPENDS_${PN} += "gcc-plugins libmpc-dev"