-
Notifications
You must be signed in to change notification settings - Fork 9
/
kernel.spec
2687 lines (2188 loc) · 95.7 KB
/
kernel.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# We have to override the new %%install behavior because, well... the kernel is special.
%global __spec_install_pre %{___build_pre}
# For Fedora >=33 to disable LTO optimization of perf tools
%define _lto_cflags %{nil}
# What parts do we want to build? We must build at least one kernel.
# These are the kernels that are built IF the architecture allows it.
# All should default to 1 (enabled) and be flipped to 0 (disabled)
# by later arch-specific checks.
# The following build options are enabled by default.
# Use either --without <opt> in your rpmbuild command or force values
# to 0 in here to disable them.
#
# kernel-headers
%define with_headers %{?_without_headers: 0} %{?!_without_headers: 1}
# perf
%define with_perf %{?_without_perf: 1} %{?!_without_perf: 0}
# tools
%define with_tools %{?_without_tools: 1} %{?!_without_tools: 0}
# kernel-debuginfo
%define with_debuginfo %{?_without_debuginfo: 1} %{?!_without_debuginfo: 0}
#
# Additional options for user-friendly one-off kernel building:
#
# Only build the base kernel (--with baseonly):
%define with_baseonly %{?_with_baseonly: 1} %{?!_with_baseonly: 0}
#
# Cross compile requested?
%define with_cross %{?_with_cross: 1} %{?!_with_cross: 0}
#
# build a release kernel on rawhide
%define with_release %{?_with_release: 1} %{?!_with_release: 0}
# Want to build a vanilla kernel build without any non-upstream patches?
%define with_vanilla %{?_with_vanilla: 1} %{?!_with_vanilla: 0}
# Build the RPi bcm270x linux kernel port
%define with_bcm270x %{?_without_bcm270x: 0} %{?!_without_bcm270x: 1}
# By default build without rt-preempt version
%define with_rt_preempt %{?_with_rt_preempt: 1} %{?!_with_rt_preempt: 0}
# Enable Large Physical Address Extension support
%define with_lpae %{?_with_lpae: 1} %{?!_with_lpae: 0}
# Build a bcm2711 (RPi4) kernel
%define with_rpi4 %{?_with_rpi4: 1} %{?!_with_rpi4: 0}
# For a stable, released kernel, released_kernel should be 1. For rawhide
# and/or a kernel built from an rc or git snapshot, released_kernel should
# be 0.
%global released_kernel 1
# baserelease defines which build revision of this kernel version we're
# building. Use: rpmdev-bumpspec -c 'comment for changelog'
# When changing base_sublevel below or going from rc to a final kernel,
# reset this by hand to 1 (or to 0 and then use rpmdev-bumpspec).
# scripts/rebase.sh should be made to do that for you, actually.
#
# NOTE: baserelease must be > 0 or bad things will happen if you switch
# to a released kernel (released version will be < rc version)
#
# For non-released -rc kernels, this will be appended after the rcX and
# gitX tags, so a 3 here would become part of release "0.rcX.gitX.3"
#
%global baserelease 1
# RaspberryPi foundation git snapshot (short)
%global rpi_gitshort 84db2c69d
%global build_release %{baserelease}
%global zipmodules 1
# Enable rt preempt build support
# Only enable with a useable upstream patch
%global enable_preempt 0
%if %{enable_preempt}
# Real-Time kernel defines
%global rtgitsnap a4b8f1f27
%global rtrelease 29
%if %{with_rt_preempt}
%global build_release %{baserelease}.rt%{rtrelease}
%endif
%endif
%if %{with_lpae}
%global variant -lpae
%global build_release %{baserelease}.lpae
%global with_tools 0
%global with_perf 0
%endif
%if %{with_rpi4}
%global variant -rpi4
%global with_tools 0
%global with_perf 0
%global with_lpae 0
%endif
# base_sublevel is the kernel version we're starting with and patching
# on top of -- for example, 3.1-rc7-git1 starts with a 3.0 base,
# which yields a base_sublevel of 0.
%define base_sublevel 10
## If this is a released kernel ##
%if 0%{?released_kernel}
# Do we have a -stable update to apply?
%define stable_update 94
# Set rpm version accordingly
%if 0%{?stable_update}
%define stablerev %{stable_update}
%define stable_base %{stable_update}
%endif
%define rpmversion 5.%{base_sublevel}.%{stable_update}
## The not-released-kernel case ##
%else
# The next upstream release sublevel (base_sublevel+1)
%define upstream_sublevel %(echo $((%{base_sublevel} + 1)))
# The rc snapshot level
%define rcrev 0
# The git snapshot level
%define gitrev 0
# Set rpm version accordingly
%define rpmversion 5.%{upstream_sublevel}.0
%endif
# Nb: The above rcrev and gitrev values automagically define Source1 and Source2 below.
%if 0%{!?nopatches:1}
%define nopatches 0
%endif
%if %{with_vanilla}
%define nopatches 1
%endif
%if %{nopatches}
%define variant -vanilla
%endif
%if !%{with_debuginfo}
%define _enable_debug_packages 0
%endif
%define debuginfodir /usr/lib/debug
# Needed because we override almost everything involving build-ids
# and debuginfo generation. Currently we rely on the old alldebug setting.
%global _build_id_links alldebug
%if %{with_bcm270x}
%define bcm270x 1
%if %{with_rpi4}
%define Flavour rpi4
%else
%define Flavour rpi
%endif
%define buildid .%{Flavour}
%else
%define bcm270x 0
%endif
# pkg_release is what we'll fill in for the rpm Release: field
%define pkg_release %{build_release}%{?buildid}%{?dist}
%if %{zipmodules}
%global zipsed -e 's/\.ko$/\.ko.xz/'
%endif
# The kernel tarball/base version
%define kversion 5.%{base_sublevel}
# Default kernel image name (compressed)
%define install_name vmlinuz
%ifarch armv7hl
%define make_target bzImage
%define kernel_image arch/arm/boot/zImage
%define asmarch arm
%define hdrarch arm
%endif
%ifarch aarch64
%define make_target Image
%define kernel_image arch/arm64/boot/Image
%define install_name vmlinux
%define asmarch arm64
%define hdrarch arm64
%endif
%define KVERREL %{version}-%{release}.%{_target_cpu}
%define image_install_path boot
# http://lists.infradead.org/pipermail/linux-arm-kernel/2012-March/091404.html
%define kernel_mflags KALLSYMS_EXTRA_PASS=1
# Overrides for generic default options
# don't build noarch kernels or headers (duh)
%ifarch noarch
%define with_headers 0
%define with_tools 0
%define with_perf 0
%endif
# Should make listnewconfig fail if there's config options
# printed out?
%if %{nopatches}
%define listnewconfig_fail 0
%else
%define listnewconfig_fail 1
%endif
#
# Packages that need to be installed before the kernel is, because the %%post
# scripts use them.
#
%define kernel_prereq coreutils, systemd, grubby
%define initrd_prereq dracut
Name: kernel%{?variant}
License: GPLv2 and Redistributable, no modification permitted
%if !%{bcm270x}
Summary: The Linux kernel for the Raspberry Pi (BCM283x)
URL: http://www.kernel.org
%else
%if "%{_target_cpu}" != "armv6hl"
%if %{with_rpi4}
Summary: The BCM2711 Linux kernel port for the Raspberry Pi 4 Model B
%else
Summary: The BCM2709 Linux kernel port for the Raspberry Pi 2 and 3 Model B
%endif
%else
Summary: The BCM2708 Linux kernel port for the Raspberry Pi Model A, B and Zero
%endif
URL: https://github.com/raspberrypi/linux
%endif
Version: %{rpmversion}
Release: %{pkg_release}
ExclusiveArch: %{arm} aarch64
Requires: kernel-core-uname-r = %{KVERREL}
Requires: kernel-modules-uname-r = %{KVERREL}
BuildRequires: bash
BuildRequires: bc
BuildRequires: binutils
BuildRequires: bison
BuildRequires: bzip2
BuildRequires: diffutils
BuildRequires: findutils
BuildRequires: flex
BuildRequires: gawk
BuildRequires: gcc
BuildRequires: gzip
BuildRequires: hmaccalc
BuildRequires: hostname
BuildRequires: kmod
BuildRequires: m4
BuildRequires: make
BuildRequires: net-tools
BuildRequires: openssl-devel
BuildRequires: patch
BuildRequires: perl-interpreter
BuildRequires: perl-Carp
BuildRequires: perl-devel
BuildRequires: perl-generators
BuildRequires: redhat-rpm-config
BuildRequires: tar
BuildRequires: xz
%if %{with_headers}
BuildRequires: rsync
%endif
%if %{with_perf}
BuildRequires: elfutils-devel
BuildRequires: zlib-devel
BuildRequires: binutils-devel
BuildRequires: newt-devel
BuildRequires: python3-devel
BuildRequires: perl(ExtUtils::Embed)
BuildRequires: audit-libs-devel
BuildRequires: xmlto
%endif
%if %{with_tools}
BuildRequires: pciutils-devel
BuildRequires: gettext
BuildRequires: ncurses-devel
BuildRequires: asciidoc
%endif
%if %{with_debuginfo}
BuildRequires: rpm-build, elfutils
BuildConflicts: rpm < 4.13.0.1-19
# Most of these should be enabled after more investigation
%undefine _include_minidebuginfo
%undefine _find_debuginfo_dwz_opts
%undefine _unique_build_ids
%undefine _unique_debug_names
%undefine _unique_debug_srcs
%undefine _debugsource_packages
%undefine _debuginfo_subpackages
%undefine _include_gdb_index
%global _find_debuginfo_opts -r
%global _missing_build_ids_terminate_build 1
%global _no_recompute_build_ids 1
%endif
%if %{with_cross}
BuildRequires: binutils-%{_build_arch}-linux-gnu
BuildRequires: gcc-%{_build_arch}-linux-gnu
%define cross_opts CROSS_COMPILE=%{_build_arch}-linux-gnu-
%endif
Source0: https://www.kernel.org/pub/linux/kernel/v5.x/linux-%{kversion}.tar.xz
Source16: mod-extra.list
Source17: mod-extra.sh
Source99: filter-modules.sh
# kernel config modifications
Source1000: config-bcm27xx.cfg
Source1100: config-bcm283x.cfg
Source1200: config-lpae.cfg
# rt kernel patch
%if %{enable_preempt}
Source1500: linux-rpi-5.%{base_sublevel}.y-rt%{rtrelease}-%{rtgitsnap}.patch.xz
%endif
# rt kernel config modification
Source1501: config-rt.cfg
# Sources for kernel-tools
Source2000: cpupower.service
Source2001: cpupower.config
# For a stable release kernel
%if 0%{?stable_update}
%if 0%{?stable_base}
Source1: https://www.kernel.org/pub/linux/kernel/v5.x/patch-5.%{base_sublevel}.%{stable_base}.xz
%endif
# non-released_kernel case
# These are automagically defined by the rcrev and gitrev values set up
# near the top of this spec file.
%else
%if 0%{?rcrev}
Source1: https://www.kernel.org/pub/linux/kernel/v5.x/patch-5.%{upstream_sublevel}-rc%{rcrev}.xz
%if 0%{?gitrev}
Source2: https://www.kernel.org/pub/linux/kernel/v5.x/patch-5.%{upstream_sublevel}-rc%{rcrev}-git%{gitrev}.xz
%endif
%else
# pre-{base_sublevel+1}-rc1 case
%if 0%{?gitrev}
Source1: https://www.kernel.org/pub/linux/kernel/v5.x/patch-5.%{base_sublevel}-git%{gitrev}.xz
%endif
%endif
%endif
%if !%{nopatches}
## Patches for bcm270x builds (append patches with bcm270x)
#RasperryPi patch
Patch100: bcm270x-linux-rpi-5.%{base_sublevel}.y-%{rpi_gitshort}.patch.xz
## Patches for both builds (bcm270x & bcm283x)
Patch150: 0001-perf-build-fix-epel8.patch
# Custom bootup logo
Patch200: bootup-logo.patch
# END OF PATCH DEFINITIONS
%endif
BuildRoot: %{_tmppath}/kernel-%{KVERREL}-root
%description
The kernel meta package
#
# This macro does requires, provides, conflicts, obsoletes for a kernel package.
# %%kernel_reqprovconf <subpackage>
# It uses any kernel_<subpackage>_conflicts and kernel_<subpackage>_obsoletes
# macros defined above.
#
%define kernel_reqprovconf \
Provides: kernel = %{rpmversion}-%{pkg_release}\
Provides: kernel-%{_target_cpu} = %{rpmversion}-%{pkg_release}%{?1:+%{1}}\
Provides: kernel-drm-nouveau = 16\
Provides: kernel-uname-r = %{KVERREL}%{?1:+%{1}}\
Requires(pre): %{kernel_prereq}\
Requires(pre): %{initrd_prereq}\
Suggests: linux-firmware\
Requires(pre): bcm283x-firmware\
Requires(preun): systemd\
Conflicts: xorg-x11-drv-vmmouse\
%{expand:%%{?kernel%{?1:_%{1}}_conflicts:Conflicts: %%{kernel%{?1:_%{1}}_conflicts}}}\
%{expand:%%{?kernel%{?1:_%{1}}_obsoletes:Obsoletes: %%{kernel%{?1:_%{1}}_obsoletes}}}\
%{expand:%%{?kernel%{?1:_%{1}}_provides:Provides: %%{kernel%{?1:_%{1}}_provides}}}\
# We can't let RPM do the dependencies automatic because it'll then pick up\
# a correct but undesirable perl dependency from the module headers which\
# isn't required for the kernel proper to function\
AutoReq: no\
AutoProv: yes\
%{nil}
%package headers
Summary: Header files for the Linux kernel for use by glibc
Obsoletes: glibc-kernheaders < 3.0-46
Provides: glibc-kernheaders = 3.0-46
%if "0%{?variant}"
Obsoletes: kernel-headers < %{rpmversion}-%{pkg_release}
Provides: kernel-headers = %{rpmversion}-%{pkg_release}
%endif
%description headers
Kernel-headers includes the C header files that specify the interface
between the Linux kernel and userspace libraries and programs. The
header files define structures and constants that are needed for
building most standard programs and are also needed for rebuilding the
glibc package.
%package debuginfo-common-%{_target_cpu}
Summary: Kernel source files used by %{name}-debuginfo packages
%description debuginfo-common-%{_target_cpu}
This package is required by %{name}-debuginfo subpackages.
It provides the kernel source files common to all builds.
%if %{with_perf}
%package -n perf
Summary: Performance monitoring for the Linux kernel
License: GPLv2
%description -n perf
This package contains the perf tool, which enables performance monitoring
of the Linux kernel.
%package -n perf-debuginfo
Summary: Debug information for package perf
Requires: %{name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}
AutoReqProv: no
%description -n perf-debuginfo
This package provides debug information for the perf package.
# Note that this pattern only works right to match the .build-id
# symlinks because of the trailing nonmatching alternation and
# the leading .*, because of find-debuginfo.sh's buggy handling
# of matching the pattern against the symlinks file.
%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%%{_bindir}/perf(\.debug)?|.*%%{_libexecdir}/perf-core/.*|.*%%{_libdir}/traceevent/plugins/.*|XXX' -o perf-debuginfo.list}
%package -n python3-perf
Summary: Python bindings for apps which will manipulate perf events
%description -n python3-perf
The python3-perf package contains a module that permits applications
written in the Python programming language to use the interface
to manipulate perf events.
# the python_sitearch macro should already be defined from above
%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%%{python3_sitearch}/perf.so(\.debug)?|XXX' -o python3-perf-debuginfo.list}
%endif
%if %{with_tools}
%package -n kernel-tools
Summary: Assortment of tools for the Linux kernel
License: GPLv2
Provides: cpupowerutils = 1:009-0.6.p1
Obsoletes: cpupowerutils < 1:009-0.6.p1
Provides: cpufreq-utils = 1:009-0.6.p1
Provides: cpufrequtils = 1:009-0.6.p1
Obsoletes: cpufreq-utils < 1:009-0.6.p1
Obsoletes: cpufrequtils < 1:009-0.6.p1
Obsoletes: cpuspeed < 1:1.5-16
Requires: kernel-tools-libs = %{version}-%{release}
%description -n kernel-tools
This package contains the tools/ directory from the kernel source
and the supporting documentation.
%package -n kernel-tools-libs
Summary: Libraries for the kernels-tools
License: GPLv2
%description -n kernel-tools-libs
This package contains the libraries built from the tools/ directory
from the kernel source.
%package -n kernel-tools-libs-devel
Summary: Assortment of tools for the Linux kernel
License: GPLv2
Requires: kernel-tools = %{version}-%{release}
Provides: cpupowerutils-devel = 1:009-0.6.p1
Obsoletes: cpupowerutils-devel < 1:009-0.6.p1
Requires: kernel-tools-libs = %{version}-%{release}
Provides: kernel-tools-devel
%description -n kernel-tools-libs-devel
This package contains the development files for the tools/ directory from
the kernel source.
%package -n kernel-tools-debuginfo
Summary: Debug information for package kernel-tools
Requires: %{name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}
AutoReqProv: no
%description -n kernel-tools-debuginfo
This package provides debug information for package kernel-tools.
# Note that this pattern only works right to match the .build-id
# symlinks because of the trailing nonmatching alternation and
# the leading .*, because of find-debuginfo.sh's buggy handling
# of matching the pattern against the symlinks file.
%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '.*%%{_bindir}/cpupower(\.debug)?|.*%%{_libdir}/libcpupower.*|.*%%{_bindir}/turbostat(\.debug)?|.*%%{_bindir}/tmon(\.debug)?|.*%%{_bindir}/lsgpio(\.debug)?|.*%%{_bindir}/gpio-hammer(\.debug)?|.*%%{_bindir}/gpio-event-mon(\.debug)?|.*%%{_bindir}/iio_event_monitor(\.debug)?|.*%%{_bindir}/iio_generic_buffer(\.debug)?|.*%%{_bindir}/lsiio(\.debug)?|XXX' -o kernel-tools-debuginfo.list}
%endif
#
# This macro creates a kernel-<subpackage>-debuginfo package.
# %%kernel_debuginfo_package <subpackage>
#
%define kernel_debuginfo_package() \
%package %{?1:%{1}-}debuginfo\
Summary: Debug information for package %{name}%{?1:-%{1}}\
Requires: %{name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}\
Provides: %{name}%{?1:-%{1}}-debuginfo-%{_target_cpu} = %{version}-%{release}\
AutoReqProv: no\
%description %{?1:%{1}-}debuginfo\
This package provides debug information for package %{name}%{?1:-%{1}}.\
This is required to use SystemTap with %{name}%{?1:-%{1}}-%{KVERREL}.\
%{expand:%%global _find_debuginfo_opts %{?_find_debuginfo_opts} -p '/.*/%%{KVERREL}%{?1:[+]%{1}}/.*|/.*%%{KVERREL}%{?1:\+%{1}}(\.debug)?' -o debuginfo%{?1}.list}\
%{nil}
#
# This macro creates a kernel-<subpackage>-devel package.
# %%kernel_devel_package <subpackage> <pretty-name>
#
%define kernel_devel_package() \
%package %{?1:%{1}-}devel\
Summary: Development package for building kernel modules to match the %{?2:%{2} }kernel\
Provides: kernel%{?1:-%{1}}-devel-%{_target_cpu} = %{version}-%{release}\
Provides: kernel-devel-%{_target_cpu} = %{version}-%{release}%{?1:+%{1}}\
Provides: kernel-devel = %{version}-%{release}%{?1:+%{1}}\
Provides: kernel-devel-uname-r = %{KVERREL}%{?1:+%{1}}\
Provides: installonlypkg(kernel)\
AutoReqProv: no\
Requires(pre): /usr/bin/find\
Requires: perl\
%description %{?1:%{1}-}devel\
This package provides kernel headers and makefiles sufficient to build modules\
against the %{?2:%{2} }kernel package.\
%{nil}
#
# This macro creates a kernel-<subpackage>-modules-extra package.
# %%kernel_modules_extra_package <subpackage> <pretty-name>
#
%define kernel_modules_extra_package() \
%package %{?1:%{1}-}modules-extra\
Summary: Extra kernel modules to match the %{?2:%{2} }kernel\
Provides: kernel%{?1:-%{1}}-modules-extra-%{_target_cpu} = %{version}-%{release}\
Provides: kernel%{?1:-%{1}}-modules-extra-%{_target_cpu} = %{version}-%{release}%{?1:+%{1}}\
Provides: kernel%{?1:-%{1}}-modules-extra = %{version}-%{release}%{?1:+%{1}}\
Provides: installonlypkg(kernel-module)\
Provides: kernel%{?1:-%{1}}-modules-extra-uname-r = %{KVERREL}%{?1:+%{1}}\
Requires: kernel-uname-r = %{KVERREL}%{?1:+%{1}}\
Requires: kernel%{?1:-%{1}}-modules-uname-r = %{KVERREL}%{?1:+%{1}}\
AutoReq: no\
AutoProv: yes\
%description %{?1:%{1}-}modules-extra\
This package provides less commonly used kernel modules for the %{?2:%{2} }kernel package.\
%{nil}
#
# This macro creates a kernel-<subpackage>-modules package.
# %%kernel_modules_package <subpackage> <pretty-name>
#
%define kernel_modules_package() \
%package %{?1:%{1}-}modules\
Summary: kernel modules to match the %{?2:%{2}-}core kernel\
Provides: kernel%{?1:-%{1}}-modules-%{_target_cpu} = %{version}-%{release}\
Provides: kernel-modules-%{_target_cpu} = %{version}-%{release}%{?1:+%{1}}\
Provides: kernel-modules = %{version}-%{release}%{?1:+%{1}}\
Provides: installonlypkg(kernel-module)\
Provides: kernel%{?1:-%{1}}-modules-uname-r = %{KVERREL}%{?1:+%{1}}\
Requires(pre): kernel-uname-r = %{KVERREL}%{?1:+%{1}}\
AutoReq: no\
AutoProv: yes\
%description %{?1:%{1}-}modules\
This package provides commonly used kernel modules for the %{?2:%{2}-}core kernel package.\
%{nil}
#
# this macro creates a kernel-<subpackage> meta package.
# %%kernel_meta_package <subpackage>
#
%define kernel_meta_package() \
%package %{1}\
summary: kernel meta-package for the %{1} kernel\
Requires: kernel-%{1}-core-uname-r = %{KVERREL}+%{1}\
Requires: kernel-%{1}-modules-uname-r = %{KVERREL}+%{1}\
Provides: installonlypkg(kernel)\
%description %{1}\
The meta-package for the %{1} kernel\
%{nil}
#
# This macro creates a kernel-<subpackage> and its -devel and -debuginfo too.
# %%define variant_summary The Linux kernel compiled for <configuration>
# %%kernel_variant_package [-n <pretty-name>] <subpackage>
#
%define kernel_variant_package(n:) \
%package %{?1:%{1}-}core\
Summary: %{variant_summary}\
Provides: kernel-%{?1:%{1}-}core-uname-r = %{KVERREL}%{?1:+%{1}}\
Provides: installonlypkg(kernel)\
%{expand:%%kernel_reqprovconf}\
%if %{?1:1} %{!?1:0} \
%{expand:%%kernel_meta_package %{?1:%{1}}}\
%endif\
%{expand:%%kernel_devel_package %{?1:%{1}} %{!?{-n}:%{1}}%{?{-n}:%{-n*}}}\
%{expand:%%kernel_modules_package %{?1:%{1}} %{!?{-n}:%{1}}%{?{-n}:%{-n*}}}\
%{expand:%%kernel_modules_extra_package %{?1:%{1}} %{!?{-n}:%{1}}%{?{-n}:%{-n*}}}\
%{expand:%%kernel_debuginfo_package %{?1:%{1}}}\
%{nil}
# The main -core package
%if %{bcm270x}
%if "%{_target_cpu}" == "armv7hl"
%if %{with_rpi4}
%define variant_summary The Linux kernel for the Raspberry Pi 4 Model B
%else
%define variant_summary The Linux kernel for the Raspberry Pi 2/3 Model B
%endif
%else
%define variant_summary The Linux kernel for the Raspberry Pi Model A, B & Zero
%endif
%kernel_variant_package
%description core
This package includes a patched version of the Linux kernel built for
Raspberry Pi devices that use the Broadcom BCM27XX SOC. The
kernel package contains the Linux kernel, the core of any
Linux operating system. The kernel handles the basic functions
of the operating system: memory allocation, process allocation, device
input and output, etc.
%else
%define variant_summary The Linux kernel
%kernel_variant_package
%description core
The kernel package contains the Linux kernel, the core of any
Linux operating system. The kernel handles the basic functions
of the operating system: memory allocation, process allocation, device
input and output, etc.
%endif
###
### prep
###
%prep
%if "%{baserelease}" == "0"
echo "baserelease must be greater than zero"
exit 1
%endif
# more sanity checking; do it quietly
if [ "%{patches}" != "%%{patches}" ] ; then
for patch in %{patches} ; do
if [ ! -f $patch ] ; then
echo "ERROR: Patch ${patch##/*/} listed in specfile but is missing"
exit 1
fi
done
fi 2>/dev/null
patch_command='patch -p1 -F1 -s'
ApplyPatch()
{
local patch=$1
shift
if [ ! -f $patch ]; then
exit 1
fi
case "$patch" in
*.bz2) bunzip2 < "$patch" | $patch_command ${1+"$@"} ;;
*.gz) gunzip < "$patch" | $patch_command ${1+"$@"} ;;
*.xz) unxz < "$patch" | $patch_command ${1+"$@"} ;;
*) $patch_command ${1+"$@"} < "$patch" ;;
esac
}
# don't apply patch if it's empty
ApplyOptionalPatch()
{
local patch=$1
shift
if [ ! -f $patch ]; then
exit 1
fi
local C=$(wc -l $patch | awk '{print $1}')
if [ "$C" -gt 9 ]; then
ApplyPatch $patch ${1+"$@"}
fi
}
# First we unpack the kernel tarball.
# If this isn't the first make prep, we use links to the existing clean tarball
# which speeds things up quite a bit.
# Update to latest upstream.
%if 0%{?released_kernel}
%define vanillaversion 5.%{base_sublevel}
# non-released_kernel case
%else
%if 0%{?rcrev}
%define vanillaversion 5.%{upstream_sublevel}-rc%{rcrev}
%if 0%{?gitrev}
%define vanillaversion 5.%{upstream_sublevel}-rc%{rcrev}-git%{gitrev}
%endif
%else
# pre-{base_sublevel+1}-rc1 case
%if 0%{?gitrev}
%define vanillaversion 5.%{base_sublevel}-git%{gitrev}
%else
%define vanillaversion 5.%{base_sublevel}
%endif
%endif
%endif
# %%{vanillaversion} : the full version name, e.g. 2.6.35-rc6-git3
# %%{kversion} : the base version, e.g. 2.6.34
# Use kernel-%%{kversion}%%{?dist} as the top-level directory name
# so we can prep different trees within a single git directory.
# Build a list of the other top-level kernel tree directories.
# This will be used to hardlink identical vanilla subdirs.
sharedirs=$(find "$PWD" -maxdepth 1 -type d -name 'kernel-5.*' \
| grep -x -v "$PWD"/kernel-%{kversion}%{?dist}) ||:
# Delete all old stale trees.
if [ -d kernel-%{kversion}%{?dist} ]; then
cd kernel-%{kversion}%{?dist}
for i in linux-*
do
if [ -d $i ]; then
# Just in case we ctrl-c'd a prep already
rm -rf deleteme.%{_target_cpu}
# Move away the stale away, and delete in background.
mv $i deleteme-$i
rm -rf deleteme* &
fi
done
cd ..
fi
# Generate new tree
if [ ! -d kernel-%{kversion}%{?dist}/vanilla-%{vanillaversion} ]; then
if [ -d kernel-%{kversion}%{?dist}/vanilla-%{kversion} ]; then
# The base vanilla version already exists.
cd kernel-%{kversion}%{?dist}
# Any vanilla-* directories other than the base one are stale.
for dir in vanilla-*; do
[ "$dir" = vanilla-%{kversion} ] || rm -rf $dir &
done
else
rm -f pax_global_header
# Look for an identical base vanilla dir that can be hardlinked.
for sharedir in $sharedirs ; do
if [[ ! -z $sharedir && -d $sharedir/vanilla-%{kversion} ]] ; then
break
fi
done
if [[ ! -z $sharedir && -d $sharedir/vanilla-%{kversion} ]] ; then
%setup -q -n kernel-%{kversion}%{?dist} -c -T
cp -al $sharedir/vanilla-%{kversion} .
else
%setup -q -n kernel-%{kversion}%{?dist} -c
mv linux-%{kversion} vanilla-%{kversion}
fi
fi
%if "%{kversion}" != "%{vanillaversion}"
for sharedir in $sharedirs ; do
if [[ ! -z $sharedir && -d $sharedir/vanilla-%{vanillaversion} ]] ; then
break
fi
done
if [[ ! -z $sharedir && -d $sharedir/vanilla-%{vanillaversion} ]] ; then
cp -al $sharedir/vanilla-%{vanillaversion} .
else
# Need to apply patches to the base vanilla version.
cp -al vanilla-%{kversion} vanilla-%{vanillaversion}
cd vanilla-%{vanillaversion}
# Update vanilla to the latest upstream.
# (non-released_kernel case only)
%if 0%{?rcrev}
xzcat %{SOURCE1} | patch -p1 -F1 -s
%if 0%{?gitrev}
xzcat %{SOURCE2} | patch -p1 -F1 -s
%endif
%else
# pre-{base_sublevel+1}-rc1 case
%if 0%{?gitrev}
xzcat %{SOURCE1} | patch -p1 -F1 -s
%endif
%endif
cd ..
fi
%endif
else
# We already have all vanilla dirs, just change to the top-level directory.
cd kernel-%{kversion}%{?dist}
fi
# Now build the kernel tree.
cp -al vanilla-%{vanillaversion} linux-%{KVERREL}
cd linux-%{KVERREL}
# released_kernel with possible stable updates
%if 0%{?stable_base}
# This is special because the kernel spec is HELL and nothing is consistent
xzcat %{SOURCE1} | patch -p1 -F1 -s
%endif
#
# misc small stuff to make things compile
#
#ApplyOptionalPatch compile-fixes.patch
%if !%{nopatches}
for i in %{patches}; do
%if !%{bcm270x}
if [ ! $(echo $i |grep "/bcm270x") ]; then
ApplyPatch $i
fi
%endif
%if %{bcm270x}
if [ ! $(echo $i |grep "/bcm283x") ]; then
ApplyPatch $i
fi
%endif
done
%if %{with_rt_preempt}
# apply rt kernel patches
xzcat %{SOURCE1500} | patch -p1 -F1 -s
%endif
# END OF PATCH APPLICATIONS
%endif
# Any further pre-build tree manipulations happen here.
chmod +x scripts/checkpatch.pl
mv COPYING COPYING-%{version}
# This Prevents scripts/setlocalversion from mucking with our version numbers.
touch .scmversion
%define make make %{?cross_opts}
# get rid of unwanted files resulting from patch fuzz
find . \( -name "*.orig" -o -name "*~" \) -exec rm -f {} \; >/dev/null
# remove unnecessary SCM files
find . -name .gitignore -exec rm -f {} \; >/dev/null
# Ensure all python shebangs in 'tools' & 'scripts' directory are using python3
find scripts tools -type f -exec sed -i '1s=^#! */usr/bin/\(python\|env python\)[23]\?=#!%{__python3}=' '{}' ';'
%if %{with_rt_preempt}
# remove append on rt kernels
rm -f localversion-rt
%endif
cd ..
###
### build
###
%build
%ifnarch %{arm} aarch64
echo "This build is for arm archiecture only"
exit 1
%endif
cp_vmlinux()
{
eu-strip --remove-comment -o "$2" "$1"
}
BuildKernel() {
MakeTarget=$1
KernelImage=$2
Flavour=$3
Arch=%{asmarch}
Flav=${Flavour:++${Flavour}}
InstallName=${4:-%{install_name}}
DevelDir=/usr/src/kernels/%{KVERREL}
# When the bootable image is just the ELF kernel, strip it.
# We already copy the unstripped file into the debuginfo package.
if [ "$KernelImage" = vmlinux ]; then
CopyKernel=cp_vmlinux
else
CopyKernel=cp
fi
#KernelVer=%{version}-%{release}.%{_target_cpu}${Flav}
KernelVer=%{version}-%{release}.%{_target_cpu}
echo BUILDING A KERNEL FOR ${Flavour} %{_target_cpu}...
%if 0%{?stable_update}
# make sure SUBLEVEL is incremented on a stable release.
perl -p -i -e "s/^SUBLEVEL.*/SUBLEVEL = %{?stablerev}/" Makefile
%endif
# make sure EXTRAVERSION says what we want it to say
perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = -%{release}.%{_target_cpu}/" Makefile
# if pre-rc1 devel kernel, must fix up PATCHLEVEL for our versioning scheme
%if !0%{?rcrev}
%if 0%{?gitrev}
perl -p -i -e 's/^PATCHLEVEL.*/PATCHLEVEL = %{upstream_sublevel}/' Makefile
%endif
%endif
# and now to start the build process
make -s mrproper
%if !%{bcm270x}
make multi_v7_defconfig
# merge kernel config fragments
scripts/kconfig/merge_config.sh -m -r .config %{SOURCE1100}
%endif
%if %{bcm270x}
%if "%{_target_cpu}" != "armv6hl"
%if %{with_rpi4}
make bcm2711_defconfig
%else
%ifarch aarch64
make bcmrpi3_defconfig
%else
make bcm2709_defconfig
%endif
%endif
%else
make bcmrpi_defconfig
%endif
# merge kernel config fragments
scripts/kconfig/merge_config.sh -m -r .config %{SOURCE1000}
%endif
%if %{with_rt_preempt}
# merge rt-preempt kernel config changes
scripts/kconfig/merge_config.sh -m -r .config %{SOURCE1501}
%endif
%if %{with_lpae}
# merge lpae kernel config changes
scripts/kconfig/merge_config.sh -m -r .config %{SOURCE1200}
%endif
echo USING ARCH=$Arch
#make ARCH=$Arch oldnoconfig >/dev/null
make ARCH=$Arch oldconfig