]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/blob - meta/recipes-kernel/linux/kernel-devsrc.bb
kernel-devsrc: fix x86 (32bit) on target module build
[thirdparty/openembedded/openembedded-core.git] / meta / recipes-kernel / linux / kernel-devsrc.bb
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"
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"
28 deltask do_populate_sysroot
29
30 S = "${STAGING_KERNEL_DIR}"
31 B = "${STAGING_KERNEL_BUILDDIR}"
32
33 PACKAGE_ARCH = "${MACHINE_ARCH}"
34
35 KERNEL_BUILD_ROOT="${nonarch_base_libdir}/modules/"
36
37 do_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 lnr ${D}${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/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
81 cp -a .config $kerneldir/build
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 # we don't usually copy generated files, since they can be rebuilt on the target,
113 # but without this file, we get a forced syncconfig run in v5.8+, which prompts and
114 # breaks workflows.
115 cp -a --parents include/generated/autoconf.h $kerneldir/build 2>/dev/null || :
116 )
117
118 # now grab the chunks from the source tree that we need
119 (
120 cd ${S}
121
122 cp -a scripts $kerneldir/build
123
124 # if our build dir had objtool, it will also be rebuilt on target, so
125 # we copy what is required for that build
126 if [ -f ${B}/tools/objtool/objtool ]; then
127 # these are a few files associated with objtool, since we'll need to
128 # rebuild it
129 cp -a --parents tools/build/Build.include $kerneldir/build/
130 cp -a --parents tools/build/Build $kerneldir/build/
131 cp -a --parents tools/build/fixdep.c $kerneldir/build/
132 cp -a --parents tools/scripts/utilities.mak $kerneldir/build/
133
134 # extra files, just in case
135 cp -a --parents tools/objtool/* $kerneldir/build/
136 cp -a --parents tools/lib/* $kerneldir/build/
137 cp -a --parents tools/lib/subcmd/* $kerneldir/build/
138
139 cp -a --parents tools/include/* $kerneldir/build/
140
141 cp -a --parents $(find tools/arch/${ARCH}/ -type f) $kerneldir/build/
142 fi
143
144 if [ "${ARCH}" = "arm64" ]; then
145 # arch/arm64/include/asm/xen references arch/arm
146 cp -a --parents arch/arm/include/asm/xen $kerneldir/build/
147 # arch/arm64/include/asm/opcodes.h references arch/arm
148 cp -a --parents arch/arm/include/asm/opcodes.h $kerneldir/build/
149
150 cp -a --parents arch/arm64/kernel/vdso/*gettimeofday.* $kerneldir/build/
151 cp -a --parents arch/arm64/kernel/vdso/sigreturn.S $kerneldir/build/
152 cp -a --parents arch/arm64/kernel/vdso/note.S $kerneldir/build/
153 cp -a --parents arch/arm64/kernel/vdso/gen_vdso_offsets.sh $kerneldir/build/
154
155 cp -a --parents arch/arm64/kernel/module.lds $kerneldir/build/ 2>/dev/null || :
156 fi
157
158 if [ "${ARCH}" = "powerpc" ]; then
159 # 5.0 needs these files, but don't error if they aren't present in the source
160 cp -a --parents arch/${ARCH}/kernel/syscalls/syscall.tbl $kerneldir/build/ 2>/dev/null || :
161 cp -a --parents arch/${ARCH}/kernel/syscalls/syscalltbl.sh $kerneldir/build/ 2>/dev/null || :
162 cp -a --parents arch/${ARCH}/kernel/syscalls/syscallhdr.sh $kerneldir/build/ 2>/dev/null || :
163 fi
164
165 # include the machine specific headers for ARM variants, if available.
166 if [ "${ARCH}" = "arm" ]; then
167 cp -a --parents arch/${ARCH}/mach-*/include $kerneldir/build/
168
169 # include a few files for 'make prepare'
170 cp -a --parents arch/arm/tools/gen-mach-types $kerneldir/build/
171 cp -a --parents arch/arm/tools/mach-types $kerneldir/build/
172
173 # ARM syscall table tools only exist for kernels v4.10 or later
174 SYSCALL_TOOLS=$(find arch/arm/tools -name "syscall*")
175 if [ -n "$SYSCALL_TOOLS" ] ; then
176 cp -a --parents $SYSCALL_TOOLS $kerneldir/build/
177 fi
178
179 cp -a --parents arch/arm/kernel/module.lds $kerneldir/build/
180 fi
181
182 if [ -d arch/${ARCH}/include ]; then
183 cp -a --parents arch/${ARCH}/include $kerneldir/build/
184 fi
185
186 cp -a include $kerneldir/build
187
188 cp -a --parents lib/vdso/* $kerneldir/build/ 2>/dev/null || :
189
190 cp -a --parents tools/include/tools/le_byteshift.h $kerneldir/build/
191 cp -a --parents tools/include/tools/be_byteshift.h $kerneldir/build/
192
193 # required for generate missing syscalls prepare phase
194 cp -a --parents $(find arch/x86 -type f -name "syscall_32.tbl") $kerneldir/build
195 cp -a --parents $(find arch/arm -type f -name "*.tbl") $kerneldir/build 2>/dev/null || :
196
197 if [ "${ARCH}" = "x86" ]; then
198 # files for 'make prepare' to succeed with kernel-devel
199 cp -a --parents $(find arch/x86 -type f -name "syscall_32.tbl") $kerneldir/build/
200 cp -a --parents $(find arch/x86 -type f -name "syscalltbl.sh") $kerneldir/build/
201 cp -a --parents $(find arch/x86 -type f -name "syscallhdr.sh") $kerneldir/build/
202 cp -a --parents $(find arch/x86 -type f -name "syscall_64.tbl") $kerneldir/build/
203 cp -a --parents arch/x86/tools/relocs_32.c $kerneldir/build/
204 cp -a --parents arch/x86/tools/relocs_64.c $kerneldir/build/
205 cp -a --parents arch/x86/tools/relocs.c $kerneldir/build/
206 cp -a --parents arch/x86/tools/relocs_common.c $kerneldir/build/
207 cp -a --parents arch/x86/tools/relocs.h $kerneldir/build/
208 cp -a --parents arch/x86/tools/gen-insn-attr-x86.awk $kerneldir/build/ 2>/dev/null || :
209 cp -a --parents arch/x86/purgatory/purgatory.c $kerneldir/build/
210
211 # 4.18 + have unified the purgatory files, so we ignore any errors if
212 # these files are not present
213 cp -a --parents arch/x86/purgatory/sha256.h $kerneldir/build/ 2>/dev/null || :
214 cp -a --parents arch/x86/purgatory/sha256.c $kerneldir/build/ 2>/dev/null || :
215
216 cp -a --parents arch/x86/purgatory/stack.S $kerneldir/build/
217 cp -a --parents arch/x86/purgatory/string.c $kerneldir/build/ 2>/dev/null || :
218 cp -a --parents arch/x86/purgatory/setup-x86_64.S $kerneldir/build/
219 cp -a --parents arch/x86/purgatory/entry64.S $kerneldir/build/
220 cp -a --parents arch/x86/boot/string.h $kerneldir/build/
221 cp -a --parents arch/x86/boot/string.c $kerneldir/build/
222 cp -a --parents arch/x86/boot/compressed/string.c $kerneldir/build/ 2>/dev/null || :
223 cp -a --parents arch/x86/boot/ctype.h $kerneldir/build/
224
225 # objtool requires these files
226 cp -a --parents arch/x86/lib/inat.c $kerneldir/build/ 2>/dev/null || :
227 cp -a --parents arch/x86/lib/insn.c $kerneldir/build/ 2>/dev/null || :
228 fi
229
230 if [ "${ARCH}" = "mips" ]; then
231 cp -a --parents arch/mips/Kbuild.platforms $kerneldir/build/
232 cp --parents $(find -type f -name "Platform") $kerneldir/build
233 cp --parents arch/mips/boot/tools/relocs* $kerneldir/build
234 cp -a --parents arch/mips/kernel/asm-offsets.c $kerneldir/build
235 cp -a --parents kernel/time/timeconst.bc $kerneldir/build
236 cp -a --parents kernel/bounds.c $kerneldir/build
237 cp -a --parents Kbuild $kerneldir/build
238 cp -a --parents arch/mips/kernel/syscalls/*.sh $kerneldir/build 2>/dev/null || :
239 cp -a --parents arch/mips/kernel/syscalls/*.tbl $kerneldir/build 2>/dev/null || :
240 cp -a --parents arch/mips/tools/elf-entry.c $kerneldir/build 2>/dev/null || :
241 fi
242
243 # required to build scripts/selinux/genheaders/genheaders
244 cp -a --parents security/selinux/include/* $kerneldir/build/
245
246 # copy any localversion files
247 cp -a localversion* $kerneldir/build/ 2>/dev/null || :
248 )
249
250 # Make sure the Makefile and version.h have a matching timestamp so that
251 # external modules can be built
252 touch -r $kerneldir/build/Makefile $kerneldir/build/include/generated/uapi/linux/version.h
253
254 # Copy .config to include/config/auto.conf so "make prepare" is unnecessary.
255 cp $kerneldir/build/.config $kerneldir/build/include/config/auto.conf
256
257 # make sure these are at least as old as the .config, or rebuilds will trigger
258 touch -r $kerneldir/build/.config $kerneldir/build/include/generated/autoconf.h 2>/dev/null || :
259 touch -r $kerneldir/build/.config $kerneldir/build/include/config/auto.conf* 2>/dev/null || :
260
261 if [ -e "$kerneldir/build/include/config/auto.conf.cmd" ]; then
262 sed -i 's/ifneq "$(CC)" ".*-linux-gcc.*$/ifneq "$(CC)" "gcc"/' "$kerneldir/build/include/config/auto.conf.cmd"
263 sed -i 's/ifneq "$(LD)" ".*-linux-ld.bfd.*$/ifneq "$(LD)" "ld"/' "$kerneldir/build/include/config/auto.conf.cmd"
264 sed -i 's/ifneq "$(CC_VERSION_TEXT)".*\(gcc.*\)"/ifneq "$(CC_VERSION_TEXT)" "\1"/' "$kerneldir/build/include/config/auto.conf.cmd"
265 sed -i 's/ifneq "$(srctree)" ".*"/ifneq "$(srctree)" "."/' "$kerneldir/build/include/config/auto.conf.cmd"
266 # we don't build against the defconfig, so make sure it isn't the trigger for syncconfig
267 sed -i 's/ifneq "$(KBUILD_DEFCONFIG)".*"\(.*\)"/ifneq "\1" "\1"/' "$kerneldir/build/include/config/auto.conf.cmd"
268 fi
269
270 # make the scripts python3 safe. We won't be running these, and if they are
271 # left as /usr/bin/python rootfs assembly will fail, since we only have python3
272 # in the RDEPENDS (and the python3 package does not include /usr/bin/python)
273 for ss in $(find $kerneldir/build/scripts -type f -name '*'); do
274 sed -i 's,/usr/bin/python2,/usr/bin/env python3,' "$ss"
275 sed -i 's,/usr/bin/env python2,/usr/bin/env python3,' "$ss"
276 sed -i 's,/usr/bin/python,/usr/bin/env python3,' "$ss"
277 done
278
279 chown -R root:root ${D}
280 }
281
282 # Ensure we don't race against "make scripts" during cpio
283 do_install[lockfiles] = "${TMPDIR}/kernel-scripts.lock"
284
285 FILES_${PN} = "${KERNEL_BUILD_ROOT} ${KERNEL_SRC_PATH}"
286 FILES_${PN}-dbg += "${KERNEL_BUILD_ROOT}*/build/scripts/*/.debug/*"
287
288 RDEPENDS_${PN} = "bc python3 flex bison ${TCLIBC}-utils"
289 # 4.15+ needs these next two RDEPENDS
290 RDEPENDS_${PN} += "openssl-dev util-linux"
291 # and x86 needs a bit more for 4.15+
292 RDEPENDS_${PN} += "${@bb.utils.contains('ARCH', 'x86', 'elfutils', '', d)}"