forked from bottlerocket-os/bottlerocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkernel-5.10.spec
274 lines (225 loc) · 8.59 KB
/
kernel-5.10.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
%global debug_package %{nil}
Name: %{_cross_os}kernel-5.10
Version: 5.10.178
Release: 1%{?dist}
Summary: The Linux kernel
License: GPL-2.0 WITH Linux-syscall-note
URL: https://www.kernel.org/
# Use latest-srpm-url.sh to get this.
Source0: https://cdn.amazonlinux.com/blobstore/13be720c0258208a986213f02d549940509f5125eac626729bc5dd3612bef2f8/kernel-5.10.178-162.673.amzn2.src.rpm
Source100: config-bottlerocket
Source101: config-bottlerocket-aws
Source102: config-bottlerocket-metal
Source103: config-bottlerocket-vmware
# Help out-of-tree module builds run `make prepare` automatically.
Patch1001: 1001-Makefile-add-prepare-target-for-external-modules.patch
# Enable INITRAMFS_FORCE config option for our use case.
Patch1002: 1002-initramfs-unlink-INITRAMFS_FORCE-from-CMDLINE_-EXTEN.patch
# Add zstd support for compressed kernel modules
Patch2000: 2000-kbuild-move-module-strip-compression-code-into-scrip.patch
Patch2001: 2001-kbuild-add-support-for-zstd-compressed-modules.patch
BuildRequires: bc
BuildRequires: elfutils-devel
BuildRequires: hostname
BuildRequires: kmod
BuildRequires: openssl-devel
# CPU microcode updates are included as "extra firmware" so the files don't
# need to be installed on the root filesystem. However, we want the license and
# attribution files to be available in the usual place.
%if "%{_cross_arch}" == "x86_64"
BuildRequires: %{_cross_os}microcode
Requires: %{_cross_os}microcode-licenses
%endif
# Pull in expected modules and development files.
Requires: %{name}-modules = %{version}-%{release}
Requires: %{name}-devel = %{version}-%{release}
%global kernel_sourcedir %{_cross_usrsrc}/kernels
%global kernel_libdir %{_cross_libdir}/modules/%{version}
%description
%{summary}.
%package devel
Summary: Configured Linux kernel source for module building
%description devel
%{summary}.
%package archive
Summary: Archived Linux kernel source for module building
%description archive
%{summary}.
%package modules
Summary: Modules for the Linux kernel
%description modules
%{summary}.
%package headers
Summary: Header files for the Linux kernel for use by glibc
%description headers
%{summary}.
%prep
rpm2cpio %{SOURCE0} | cpio -iu linux-%{version}.tar config-%{_cross_arch} "*.patch"
tar -xof linux-%{version}.tar; rm linux-%{version}.tar
%setup -TDn linux-%{version}
# Patches from the Source0 SRPM
for patch in ../*.patch; do
patch -p1 <"$patch"
done
# Patches listed in this spec (Patch0001...)
%autopatch -p1
%if "%{_cross_arch}" == "x86_64"
microcode="$(find %{_cross_libdir}/firmware -type f -path '*/*-ucode/*' -printf '%%P ')"
cat <<EOF > ../config-microcode
CONFIG_EXTRA_FIRMWARE="${microcode}"
CONFIG_EXTRA_FIRMWARE_DIR="%{_cross_libdir}/firmware"
EOF
%endif
export ARCH="%{_cross_karch}"
export CROSS_COMPILE="%{_cross_target}-"
KCONFIG_CONFIG="arch/%{_cross_karch}/configs/%{_cross_vendor}_defconfig" \
scripts/kconfig/merge_config.sh \
../config-%{_cross_arch} \
%if "%{_cross_arch}" == "x86_64"
../config-microcode \
%endif
%{SOURCE100} \
%{_sourcedir}/config-bottlerocket-%{_cross_variant_platform}
rm -f ../config-* ../*.patch
%global kmake \
make -s\\\
ARCH="%{_cross_karch}"\\\
CROSS_COMPILE="%{_cross_target}-"\\\
INSTALL_HDR_PATH="%{buildroot}%{_cross_prefix}"\\\
INSTALL_MOD_PATH="%{buildroot}%{_cross_prefix}"\\\
INSTALL_MOD_STRIP=1\\\
%{nil}
%build
%kmake mrproper
%kmake %{_cross_vendor}_defconfig
%kmake %{?_smp_mflags} %{_cross_kimage}
%kmake %{?_smp_mflags} modules
%install
%kmake %{?_smp_mflags} headers_install
%kmake %{?_smp_mflags} modules_install
install -d %{buildroot}/boot
install -T -m 0755 arch/%{_cross_karch}/boot/%{_cross_kimage} %{buildroot}/boot/vmlinuz
install -m 0644 .config %{buildroot}/boot/config
find %{buildroot}%{_cross_prefix} \
\( -name .install -o -name .check -o \
-name ..install.cmd -o -name ..check.cmd \) -delete
# For out-of-tree kmod builds, we need to support the following targets:
# make scripts -> make prepare -> make modules
#
# This requires enough of the kernel tree to build host programs under the
# "scripts" and "tools" directories.
# Any existing ELF objects will not work properly if we're cross-compiling for
# a different architecture, so get rid of them to avoid confusing errors.
find arch scripts tools -type f -executable \
-exec sh -c "head -c4 {} | grep -q ELF && rm {}" \;
# We don't need to include these files.
find -type f \( -name \*.cmd -o -name \*.gitignore \) -delete
# Avoid an OpenSSL dependency by stubbing out options for module signing and
# trusted keyrings, so `sign-file` and `extract-cert` won't be built. External
# kernel modules do not have access to the keys they would need to make use of
# these tools.
sed -i \
-e 's,$(CONFIG_MODULE_SIG_FORMAT),n,g' \
-e 's,$(CONFIG_SYSTEM_TRUSTED_KEYRING),n,g' \
scripts/Makefile
# Restrict permissions on System.map.
chmod 600 System.map
(
find * \
-type f \
\( -name Build\* -o -name Kbuild\* -o -name Kconfig\* -o -name Makefile\* \) \
-print
find arch/%{_cross_karch}/ \
-type f \
\( -name module.lds -o -name vmlinux.lds.S -o -name Platform -o -name \*.tbl \) \
-print
find arch/%{_cross_karch}/{include,lib}/ -type f ! -name \*.o ! -name \*.o.d -print
echo arch/%{_cross_karch}/kernel/asm-offsets.s
echo lib/vdso/gettimeofday.c
for d in \
arch/%{_cross_karch}/tools \
arch/%{_cross_karch}/kernel/vdso ; do
[ -d "${d}" ] && find "${d}/" -type f -print
done
find include -type f -print
find scripts -type f ! -name \*.l ! -name \*.y ! -name \*.o -print
find tools/{arch/%{_cross_karch},include,objtool,scripts}/ -type f ! -name \*.o -print
echo tools/build/fixdep.c
find tools/lib/subcmd -type f -print
find tools/lib/{ctype,hweight,rbtree,string,str_error_r}.c
echo kernel/bounds.c
echo kernel/time/timeconst.bc
echo security/selinux/include/classmap.h
echo security/selinux/include/initial_sid_to_string.h
echo security/selinux/include/policycap.h
echo security/selinux/include/policycap_names.h
echo .config
echo Module.symvers
echo System.map
) | sort -u > kernel_devel_files
# Create squashfs of kernel-devel files (ie. /usr/src/kernels/<version>).
#
# -no-exports:
# The filesystem does not need to be exported via NFS.
#
# -all-root:
# Make all files owned by root rather than the build user.
#
# -comp zstd:
# zstd offers compression ratios like xz and decompression speeds like lz4.
SQUASHFS_OPTS="-no-exports -all-root -comp zstd"
mkdir -p src_squashfs/%{version}
tar c -T kernel_devel_files | tar x -C src_squashfs/%{version}
mksquashfs src_squashfs kernel-devel.squashfs ${SQUASHFS_OPTS}
# Create a tarball of the same files, for use outside the running system.
# In theory we could extract these files with `unsquashfs`, but we do not want
# to require it to be installed on the build host, and it errors out when run
# inside Docker unless the limit for open files is lowered.
tar cf kernel-devel.tar src_squashfs/%{version} --transform='s|src_squashfs/%{version}|kernel-devel|'
xz -T0 kernel-devel.tar
install -D kernel-devel.squashfs %{buildroot}%{_cross_datadir}/bottlerocket/kernel-devel.squashfs
install -D kernel-devel.tar.xz %{buildroot}%{_cross_datadir}/bottlerocket/kernel-devel.tar.xz
install -d %{buildroot}%{kernel_sourcedir}
# Replace the incorrect links from modules_install. These will be bound
# into a host container (and unused in the host) so they must not point
# to %{_cross_usrsrc} (eg. /x86_64-bottlerocket-linux-gnu/sys-root/...)
rm -f %{buildroot}%{kernel_libdir}/build %{buildroot}%{kernel_libdir}/source
ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/build
ln -sf %{_usrsrc}/kernels/%{version} %{buildroot}%{kernel_libdir}/source
%files
%license COPYING LICENSES/preferred/GPL-2.0 LICENSES/exceptions/Linux-syscall-note
%{_cross_attribution_file}
/boot/vmlinuz
/boot/config
%files modules
%dir %{_cross_libdir}/modules
%{_cross_libdir}/modules/*
%files headers
%dir %{_cross_includedir}/asm
%dir %{_cross_includedir}/asm-generic
%dir %{_cross_includedir}/drm
%dir %{_cross_includedir}/linux
%dir %{_cross_includedir}/misc
%dir %{_cross_includedir}/mtd
%dir %{_cross_includedir}/rdma
%dir %{_cross_includedir}/scsi
%dir %{_cross_includedir}/sound
%dir %{_cross_includedir}/video
%dir %{_cross_includedir}/xen
%{_cross_includedir}/asm/*
%{_cross_includedir}/asm-generic/*
%{_cross_includedir}/drm/*
%{_cross_includedir}/linux/*
%{_cross_includedir}/misc/*
%{_cross_includedir}/mtd/*
%{_cross_includedir}/rdma/*
%{_cross_includedir}/scsi/*
%{_cross_includedir}/sound/*
%{_cross_includedir}/video/*
%{_cross_includedir}/xen/*
%files devel
%dir %{kernel_sourcedir}
%{_cross_datadir}/bottlerocket/kernel-devel.squashfs
%files archive
%{_cross_datadir}/bottlerocket/kernel-devel.tar.xz
%changelog