-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild-kernel-deb
More file actions
executable file
·837 lines (785 loc) · 11.9 KB
/
build-kernel-deb
File metadata and controls
executable file
·837 lines (785 loc) · 11.9 KB
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
#!/bin/bash -eu
#
# Build kernel Debian packages
#
function pr_error() { echo -e "\033[31mEE: ${*}\033[0m" >&2 ; }
function pr_info() { echo -e "\033[33mII: ${*}\033[0m" ; }
function run_chroot()
{
if ischroot ; then
pr_info "Run:"
pr_info "+ ${*}"
"${@}"
return
fi
pr_info "Run in chroot (${CHROOT}):"
pr_info "+ ${*}"
if schroot --list --all-sessions | grep -q "session:${CHROOT}" ; then
schroot -p -r -c "${CHROOT}" -- "${@}"
else
schroot -p -c "${CHROOT}" -- "${@}"
fi
}
function modules_laptop()
{
cat <<EOF
8250_dw
ac97_bus
acpi_thermal_rel
aesni_intel
af_alg
algif_hash
algif_skcipher
asus_nb_wmi
asus_wireless
asus_wmi
autofs4
binfmt_misc
bluetooth
bnep
btbcm
btintel
btmtk
btrtl
btusb
ccm
cec
cfg80211
cmac
coretemp
cqhci
crc32_pclmul
crct10dif_pclmul
cryptd
crypto_simd
dm_crypt
drm
drm_buddy
drm_display_helper
drm_kms_helper
ecc
ecdh_generic
efi_pstore
ghash_clmulni_intel
hid
hid_generic
hid_multitouch
i2c_algo_bit
i2c_hid
i2c_hid_acpi
i2c_i801
i2c_smbus
i915
idma64
input_leds
int3400_thermal
int3403_thermal
int340x_thermal_zone
intel_cstate
intel_lpss
intel_lpss_pci
intel_pmc_bxt
intel_powerclamp
intel_punit_ipc
intel_rapl_common
intel_rapl_msr
intel_soc_dts_iosf
intel_telemetry_core
intel_telemetry_pltdrv
ip_tables
irqbypass
iwlmvm
iwlwifi
joydev
kvm
kvm_intel
ledtrig_audio
libarc4
lp
mac80211
mac_hid
mc
mei
mei_hdcp
mei_me
mei_pxp
mfd_aaeon
mmc_block
nls_iso8859_1
parport
parport_pc
pinctrl_geminilake
platform_profile
polyval_generic
ppdev
processor_thermal_device
processor_thermal_device_pci_legacy
processor_thermal_mbox
processor_thermal_rapl
processor_thermal_rfim
rapl
rc_core
rfcomm
sch_fq_codel
sdhci
sdhci_pci
serio_raw
sha1_ssse3
sha256_ssse3
snd
snd_compress
snd_hda_codec
snd_hda_codec_generic
snd_hda_codec_hdmi
snd_hda_codec_realtek
snd_hda_core
snd_hda_ext_core
snd_hda_intel
snd_hwdep
snd_intel_dspcfg
snd_intel_sdw_acpi
snd_pcm
snd_pcm_dmaengine
snd_rawmidi
snd_seq
snd_seq_device
snd_seq_midi
snd_seq_midi_event
snd_soc_acpi
snd_soc_acpi_intel_match
snd_soc_avs
snd_soc_core
snd_soc_hda_codec
snd_soc_hdac_hda
snd_soc_skl
snd_soc_sst_dsp
snd_soc_sst_ipc
snd_sof
snd_sof_intel_hda
snd_sof_intel_hda_common
snd_sof_intel_hda_mlink
snd_sof_pci
snd_sof_pci_intel_apl
snd_sof_utils
snd_sof_xtensa_dsp
snd_timer
soundcore
soundwire_bus
soundwire_cadence
soundwire_generic_allocation
soundwire_intel
sparse_keymap
ttm
uvc
uvcvideo
video
videobuf2_common
videobuf2_memops
videobuf2_v4l2
videobuf2_vmalloc
videodev
wmi
wmi_bmof
x86_pkg_temp_thermal
x_tables
xhci_pci
xhci_pci_renesas
EOF
}
function modules_libvirt()
{
# Stamdard modules
cat <<EOF
aes_x86_64
aesni_intel
async_memcpy
async_pq
async_raid6_recov
async_tx
async_xor
autofs4
binfmt_misc
btrfs
cirrus
crc32_pclmul
crct10dif_pclmul
cryptd
crypto_simd
drm
drm_kms_helper
fb_sys_fops
floppy
ghash_clmulni_intel
glue_helper
i2c_piix4
ib_cm
ib_core
ib_iser
input_leds
ip_tables
irqbypass
iscsi_tcp
isofs
iw_cm
joydev
kvm
kvm_amd
kvm_intel
libcrc32c
libiscsi
libiscsi_tcp
linear
mac_hid
multipath
nls_iso8859_1
pata_acpi
pcbc
psmouse
qemu_fw_cfg
raid0
raid1
raid10
raid456
raid6_pq
rdma_cm
sch_fq_codel
scsi_transport_iscsi
serio_raw
syscopyarea
sysfillrect
sysimgblt
ttm
virtio_blk
virtio_net
x_tables
xor
zstd_compress
EOF
# Manually loaded by kernel selftests
cat <<EOF
act_bpf
act_connmark
act_csum
act_ct
act_ctinfo
act_gact
act_gate
act_mirred
act_mpls
act_nat
act_pedit
act_police
act_sample
act_simple
act_skbedit
act_skbmod
act_tunnel_key
act_vlan
adi
amd-pstate-ut
br_netfilter
cls_basic
cls_bpf
cls_cgroup
cls_flow
cls_flower
cls_fw
cls_matchall
cls_route
cls_u32
configs
dummy
em_canid
em_cmp
em_ipset
em_ipt
em_meta
em_nbyte
em_text
em_u32
fou
fou6
ftrace-direct
ftrace-direct-too
geneve
gpio-sim
i915
ifb
intel_sdsi
ip6_tunnel
ip6table_filter
ip_vs
ipip
lkdtm
memory-notifier-error-inject
mpls_gso
mpls_iptunnel
netdevsim
nf_conntrack
nf_conntrack_ipv6
nf_defrag_ipv6
ntb_msi_test
ntb_perf
ntb_pingpong
ntb_tool
ntb_transport
rc-loopback
sch_cake
sch_cbs
sch_choke
sch_codel
sch_drr
sch_etf
sch_ets
sch_fq
sch_fq_codel
sch_fq_pie
sch_gred
sch_hfsc
sch_hhf
sch_htb
sch_teql
sctp
sctp_diag
test-drm_mm
test-ww_mutex
test_blackhole_dev
test_bpf
test_firmware
test_fpu
test_module
test_static_key_base
test_static_keys
test_user_copy
trace-printk
tun
udp_tunnel
usbip_host
vhci_hcd
vrf
vxlan
zram
EOF
}
function modules_raspi()
{
cat <<EOF
8021q
8250_bcm7271
ac97_bus
aes_arm64
aes_ce_blk
aes_ce_cipher
aes_neon_blk
aes_neon_bs
af_alg
algif_hash
algif_skcipher
async_memcpy
async_pq
async_raid6_recov
async_tx
async_xor
autofs4
backlight
bcm2835_codec
bcm2835_isp
bcm2835_mmal_vchiq
bcm2835_mmc
bcm2835_v4l2
binfmt_misc
blake2b_generic
bluetooth
bnep
brcmfmac
brcmfmac_cyw
brcmfmac_wcc
brcmutil
btbcm
btintel
btqca
btrfs
btrtl
btsdio
cec
cfg80211
cqhci
crct10dif_ce
dax
dm_mod
dm_multipath
drm_client_lib
drm_display_helper
drm_dma_helper
drm_exec
drm_kms_helper
drm_shmem_helper
dw_axi_dmac_platform
dwc2
dwc3
ecc
ecdh_generic
efi_pstore
efivarfs
fuse
garp
gf128mul
ghash_ce
gpio_brcmstb
gpio_generic
gpio_keys
gpu_sched
hci_uart
hid_generic
i2c_bcm2835
i2c_brcmstb
i2c_designware_core
i2c_designware_platform
input_leds
ip_tables
joydev
libblake2b
libcrc32c
linear
llc
macb
mc
md_mod
mmc_block
mrp
nfnetlink
nvmem_rmem
phy_generic
phylink
pisp_be
polyval_ce
polyval_generic
pwm_brcmstb
pwm_fan
pwm_rp1
pwrseq_core
qrtr
raid0
raid1
raid10
raid456
raid6_pq
raspberrypi_gpiomem
raspberrypi_hwmon
reset_brcmstb
reset_brcmstb_rescal
rfcomm
rfkill
roles
rp1_adc
rp1_fw
rp1_mailbox
rp1_pci
rp1_pio
rpi_hevc_dec
rpivid_hevc
rpmb_core
rtc_rpi
sch_fq_codel
sdhci_brcmstb
sha1_ce
sha256_arm64
sha2_ce
sm4
snd
snd_bcm2835
snd_compress
snd_hrtimer
snd_pcm
snd_pcm_dmaengine
snd_rawmidi
snd_seq
snd_seq_device
snd_seq_dummy
snd_seq_midi
snd_seq_midi_event
snd_soc_core
snd_soc_hdmi_codec
snd_timer
spi_bcm2835
spi_dw
spi_dw_mmio
spidev
stp
tls
uas
udc_core
uio
uio_pdrv_genirq
ulpi
usb_storage
usbhid
v3d
v4l2_mem2mem
vc4
vc_sm_cma
videobuf2_common
videobuf2_dma_contig
videobuf2_memops
videobuf2_v4l2
videobuf2_vmalloc
videodev
x_tables
xhci_pci
xhci_pci_renesas
xhci_plat_hcd
xor
xor_neon
z3fold
zstd
EOF
}
function syz_configs()
{
# Configs required for syzcaller
cat <<EOF
# Coverage collection.
CONFIG_KCOV=y
# Debug info for symbolization.
CONFIG_DEBUG_INFO_DWARF4=y
# Memory bug detector
CONFIG_KASAN=y
CONFIG_KASAN_INLINE=y
# Required for Debian Stretch and later
CONFIG_CONFIGFS_FS=y
CONFIG_SECURITYFS=y
EOF
}
function usage()
{
cat <<EOF
Usage: $(basename "${0}") [-h] CMD [ARGS...]
Build kernel Debian packages.
To build an Ubuntu raspi kernel:
$ build-kernel-deb --arch arm64 config raspi
$ build-kernel-deb --arch arm64 make
To build a generic Ubuntu kernel:
$ build-kernel-deb config generic
$ build-kernel-deb make
Available commands:
config [CONFIG] Create kernel config. Supported <CONFIG> values:
menu: Run config menu.
generic: Use generic Ubuntu configs.
raspi: Use raspi Ubuntu configs.
*config: Use upstream arch/<arch>/configs/*config configs.
make Build kernel Debian packages.
Optional common arguments:
--arch ARCH Debian package architecture.
--buildd BUILDD Use buildd/<BUILDD> as the build output directory.
If not provided, defaults to buildd/<SERIES>.
--chroot CHROOT Use chroot <CHROOT>.
-h, --help Show this help text and exit.
-jX Number of jobs, default one per CPU.
Optional arguments for 'config' command:
--debug-info Enable DEBUG_INFO config option.
--lsmod LSMOD Enable modules listed in <LSMOD>.
--mod-laptop Enable a minimal set of modules for laptops.
--mod-libvirt Enable a minimal set of modules for libvirt.
--mod-raspi Enable a minimal set of modules for raspi.
--syz Enable config options for syzcaller.
EOF
}
arch=
buildd=
chroot=
debug_info=0
jobs=$(getconf _NPROCESSORS_ONLN)
lsmod=
cmd=
flavor=
mod_laptop=0
mod_libvirt=0
mod_raspi=0
syz=0
module_subset=0
while [ ${#} -gt 0 ] ; do
case "${1}" in
--arch)
shift
arch=${1}
;;
--buildd)
shift
buildd=${1}
;;
--chroot)
shift
chroot=${1}
;;
--debug-info)
debug_info=1
;;
-h|--help)
usage
exit
;;
-j[1-9]*)
jobs=${1#-j}
if [ -z "${jobs}" ] ; then
shift
jobs=${1}
fi
;;
--lsmod)
shift
lsmod=${1}
module_subset=1
;;
--mod-laptop)
mod_laptop=1
module_subset=1
;;
--mod-libvirt)
mod_libvirt=1
module_subset=1
;;
--mod-raspi)
mod_raspi=1
module_subset=1
;;
--syz)
syz=1
;;
config)
cmd=${1}
shift
flavor=${1}
;;
make)
cmd=${1}
;;
*)
break
;;
esac
shift
done
if [ -z "${cmd}" ] ; then
usage
exit 2
fi
#
# Determine architecture and cross-compilation
#
if [ -z "${arch}" ] ; then
arch=$(dpkg-architecture -q DEB_BUILD_ARCH)
fi
if [ "${arch}" != "$(dpkg-architecture -q DEB_BUILD_ARCH)" ] ; then
ARCH=$(dpkg-architecture -a "${arch}" -q DEB_HOST_ARCH_CPU 2>/dev/null)
CROSS_COMPILE=$(dpkg-architecture -a "${arch}" -q DEB_HOST_GNU_TYPE 2>/dev/null)-
pr_info "Cross-compilation for: ${ARCH}"
export ARCH CROSS_COMPILE
# FIXME: Cross-builds of newer kernels fail because of libssl-dev
export DEB_BUILD_PROFILES=pkg.linux-upstream.nokernelheaders
fi
#
# Determine the chroot and series
#
if [ -n "${chroot}" ] ; then
CHROOT=${chroot}
series=$(run_chroot cat /etc/lsb-release | sed -n 's/DISTRIB_CODENAME=//p')
else
# shellcheck disable=SC1091
if [ -e debian/debian.env ] ; then
. debian/debian.env
series=$(dpkg-parsechangelog -l "${DEBIAN}"/changelog -S Distribution)
else
series=$(lsb_release -c -s 2>/dev/null)
fi
CHROOT=cranky--${series}-${arch}
fi
#
# Build directory
#
if [ -n "${buildd}" ] ; then
KBUILD_OUTPUT=buildd/${buildd}
else
KBUILD_OUTPUT=buildd/${series}
fi
mkdir -p "${KBUILD_OUTPUT}"
export KBUILD_OUTPUT
#
# Print exports
#
pr_info "Exported build variables:"
for var in KERNELRELEASE ARCH CROSS_COMPILE DEB_BUILD_PROFILES KBUILD_OUTPUT ; do
pr_info " ${var}=${!var:-}"
done
#
# Process the command
#
case "${cmd}" in
config)
case "${flavor}" in
menu)
run_chroot make menuconfig
;;
generic|raspi|*config)
case "${flavor}" in
generic|raspi)
pr_info "Generate Ubuntu config (${arch}, ${flavor})"
rm -rf CONFIGS
run_chroot fakeroot debian/rules clean
run_chroot debian/rules genconfigs || true
cp CONFIGS/"${arch}"-config.flavour."${flavor}" "${KBUILD_OUTPUT}"/.config
;;
*)
pr_info "Generate kernel config (${arch}, ${flavor})"
run_chroot make "${flavor}"
;;
esac
if [ ${module_subset} -eq 1 ] ; then
pr_info "Enable only a subset of modules"
if [ -z "${lsmod}" ] ; then
lsmod=${KBUILD_OUTPUT}/bkd.modules
echo "Module" > "${lsmod}"
fi
if [ ${mod_laptop} -eq 1 ] ; then
modules_laptop >> "${lsmod}"
fi
if [ ${mod_libvirt} -eq 1 ] ; then
modules_libvirt >> "${lsmod}"
fi
if [ ${mod_raspi} -eq 1 ] ; then
modules_raspi >> "${lsmod}"
fi
run_chroot make LSMOD="$(realpath -e "${lsmod}")" localmodconfig
fi
if [ ${syz} -eq 1 ] ; then
pr_info "Set syzcaller configs"
syz_configs >> "${KBUILD_OUTPUT}"/.config
fi
if [ ${debug_info} -eq 1 ] ; then
pr_info "Not disable debug info"
else
pr_info "Disable CONFIG_DEBUG_INFO"
sed -i '/CONFIG_DEBUG_INFO/d' "${KBUILD_OUTPUT}"/.config
echo "# CONFIG_DEBUG_INFO is not set" >> "${KBUILD_OUTPUT}"/.config
fi
if true ; then
pr_info "Disable CONFIG_RUST"
echo "# CONFIG_RUST is not set" >> "${KBUILD_OUTPUT}"/.config
fi
run_chroot make olddefconfig
;;
*)
pr_error "Invalid config option: ${flavor}"
exit 1
;;
esac
;;
make)
# FIXME: Disable the build of the dbg package
#sed -i -e 's/ CONFIG_DEBUG_INFO/ __BOGUS_CONFIG__/' scripts/package/mkdebian
run_chroot make -j"${jobs}" "${@:-bindeb-pkg}"
;;
*)
pr_error "Invalid command: ${1}"
exit 1
;;
esac