-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathbuild.sh
executable file
·1154 lines (1059 loc) · 45.8 KB
/
build.sh
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
#!/usr/bin/env bash
################################################
##++++++++++++++++++++++++++++++++++++++++++++##
##++ RPi Kernel Compilation Script ++##
##++ ++##
################################################
################################################
## ##
## VARIABLES ##
## SET THESE: ##
## Debug - set to "1" to enable debugging
## (mainly breakpoints)
DEBUG="0"
## Version strings:
VERSION="5.10.103"
BUILD="1"
unset V6_VERSION V7_VERSION V7L_VERSION V8_VERSION V8L_VERSION
## Comment out those you don't want to build
V6_VERSION=$BUILD
V7_VERSION=$BUILD
V7L_VERSION=$BUILD
V8_VERSION=$BUILD
V8L_VERSION=$BUILD
## Repos
###################################################
## 5.10.103-Re4son ##
GIT_REPO="Re4son/re4son-raspberrypi-linux"
GIT_BRANCH="rpi-5.10.103-re4son" ## 5.10.103 kernel commit: dc6771425e9604650d1d57f7c69948be405f59a5
FW_REPO="Re4son/RPi-Distro-firmware"
FW_BRANCH="5.10.103"
## defconfigs:
V6_DEFAULT_CONFIG="arch/arm/configs/re4son_pi6_defconfig"
V7_DEFAULT_CONFIG="arch/arm/configs/re4son_pi7_defconfig"
V7L_DEFAULT_CONFIG="arch/arm/configs/re4son_pi7l_defconfig"
V8_DEFAULT_CONFIG="arch/arm64/configs/re4son_pi8_defconfig"
V8L_DEFAULT_CONFIG="arch/arm64/configs/re4son_pi8l_defconfig"
##V6_DEFAULT_CONFIG="arch/arm/configs/bcmrpi_defconfig"
##V7_DEFAULT_CONFIG="arch/arm/configs/bcm2709_defconfig"
V6_CONFIG=""
V7_CONFIG=""
V7L_CONFIG=""
V8_CONFIG=""
export DEBFULLNAME=Re4son
export [email protected]
export KBUILD_BUILD_TIMESTAMP="Debian kali-pi (`date +%Y-%m-%d`)"
UNAME_STRING="${VERSION}-Re4son+"
UNAME_STRING7="${VERSION}-Re4son-v7+"
UNAME_STRING7L="${VERSION}-Re4son-v7l+"
UNAME_STRING8="${VERSION}-Re4son-v8+"
UNAME_STRING8L="${VERSION}-Re4son-v8l+"
CURRENT_DATE=`date +%Y%m%d`
NEW_VERSION="${VERSION}-${CURRENT_DATE}"
# Directories
KERNEL_BUILDER_DIR="/opt/re4son-kernel-builder"
REPO_ROOT="/opt/kernel-builder_repos/"
MOD_DIR=`mktemp -d`
PKG_TMP=`mktemp -d`
PKG_DIR="${PKG_TMP}/kalipi-firmware_${NEW_VERSION}"
FIRMWARE_DIR="/opt/kernel-builder_RPi-Distro-firmware"
KERNEL_SRC_DIR="${REPO_ROOT}${GIT_REPO}/all"
KERNEL_OUT_DIR_V6=/opt/kernel-builder_kernel_out/v6
KERNEL_OUT_DIR_V7=/opt/kernel-builder_kernel_out/v7
KERNEL_OUT_DIR_V7L=/opt/kernel-builder_kernel_out/v7l
KERNEL_OUT_DIR_V8=/opt/kernel-builder_kernel_out/v8
KERNEL_OUT_DIR_V8L=/opt/kernel-builder_kernel_out/v8l
KERNEL_MOD_DIR=/opt/kernel-builder_mod
KERNEL_HEADERS_OUT_DIR=/opt/kernel-builder_headers_out
PKG_IN="/opt/kernel-builder_pkg_in/"
NEXMON_DIR="/opt/re4son-nexmon"
NUM_CPUS=`nproc`
## ##
################################################
################################################
################################################
################################################
## ##
## FUNCTIONS ##
function check_root(){
if [[ $EUID -ne 0 ]]; then
printf "\n\t\t$(basename $0) must be run as root.\n\t\ttry: sudo $(basename $0)\n\n"
exit 1
fi
}
function breakpoint() {
# Set a breakpoint
if [ $DEBUG == "1" ]; then
read -n1 -r -p "========> Breakpoint #$1: Press any key to continue..."
printf "\n"
fi
}
function debug_info() {
if [ $DEBUG == "1" ]; then
printf "\nDEBUG INFO:\n\n"
printf "NAT_ARCH:\t$NAT_ARCH\n"
printf "MAKE_HEADERS:\t$MAKE_HEADERS\n"
printf "MAKE_PKG:\t$MAKE_PKG\n"
printf "MAKE_NEXMON:\t$MAKE_NEXMON\n"
printf "UNAME_STRING:\t$UNAME_STRING\n"
printf "UNAME_STRING7:\t$UNAME_STRING7\n"
printf "UNAME_STRING7L:\t$UNAME_STRING7L\n"
printf "UNAME_STRING8:\t$UNAME_STRING8\n"
printf "UNAME_STRING8L:\t$UNAME_STRING8\n"
printf "REPO_ROOT:\t$REPO_ROOT\n"
printf "KERNEL_SRC_DIR:\t&KERNEL_SRC_DIR\n"
printf "KERNEL_OUT_DIR_V6:\t\t$KERNEL_OUT_DIR_V6\n"
printf "KERNEL_OUT_DIR_V7:\t\t$KERNEL_OUT_DIR_V7\n"
printf "KERNEL_OUT_DIR_V7L:\t\t$KERNEL_OUT_DIR_V7L\n"
printf "KERNEL_OUT_DIR_V8:\t\t$KERNEL_OUT_DIR_V8\n"
printf "KERNEL_OUT_DIR_V8L:\t\t$KERNEL_OUT_DIR_V8L\n"
printf "HEAD_SRC_DIR:\t$HEAD_SRC_DIR\n"
printf "GIT_BRANCH:\t$GIT_BRANCH\n"
printf "PKG_TMP:\t$PKG_TMP\n"
printf "PKG_DIR:\t$PKG_DIR\n"
printf "MOD_DIR:\t$MOD_DIR\n"
printf "FIRMWARE_DIR:\t$FIRMWARE_DIR\n"
printf "NEXMON_DIR:\t$NEXMON_DIR\n"
printf "NEW_VERSION:\t$NEW_VERSION\n"
printf "\nFIRMWARE INFO:\n\n"
if [ -f ${FIRMWARE_DIR}/extra/git_hash ]; then
FW_GIT_HASH=`cat ${FIRMWARE_DIR}/extra/git_hash`
fi
printf "FW_GIT_HASH:\t$FW_GIT_HASH\n"
fi
}
function usage() {
cat << EOF
usage: re4sonbuild [options]
This will build the Kali-Pi Kernel.
OPTIONS:
-h Show this message
-c Clean source directories (i.e. make mrproper - run this before compiling new kernels)
-e Build headers for architecture reasonbuild is currently running on(only for native compilation)
-n Build kernel natively for architecture reasonbuild is currently running on
-r The remote github repo to clone in user/repo format
Default: $GIT_REPO
-p Create packages only (no compilation - expects tar.xz input files in package directory)
-b The git branch to use
Default: Default git branch of repo
-6 The config file to use when compiling for Raspi v6
Default: $V6_DEFAULT_CONFIG
-7 The config file to use when compiling for Raspi v7
Default: $V7_DEFAULT_CONFIG
-8 The config file to use when compiling for Raspi v8
Default: $V8_DEFAULT_CONFIG
EOF
}
function clean() {
if [ ! -d $KERNEL_SRC_DIR ]; then
setup_repos
fi
clean_kernel_src_dir
echo "**** Cleaning up kernel working dirs ****"
if [ -d $KERNEL_OUT_DIR_V6 ]; then
rm -rf $KERNEL_OUT_DIR_V6
mkdir $KERNEL_OUT_DIR_V6
chown $SUDO_USER:$SUDO_USER $KERNEL_OUT_DIR_V6
echo "**** Cleaning ${KERNEL_OUT_DIR_V6} ****"
if [ "$V6_VERSION" != "" ]; then
echo "**** Setting version to ${V6_VERSION} ****"
((version = $V6_VERSION -1))
echo $version > $KERNEL_OUT_DIR_V6\/\.version
fi
fi
if [ -d $KERNEL_OUT_DIR_V7 ]; then
rm -rf $KERNEL_OUT_DIR_V7
mkdir $KERNEL_OUT_DIR_V7
chown $SUDO_USER:$SUDO_USER $KERNEL_OUT_DIR_V7
echo "**** Cleaning ${KERNEL_OUT_DIR_V7} ****"
if [ "$V7_VERSION" != "" ]; then
echo "**** Setting version to ${V7_VERSION} ****"
((version = $V7_VERSION -1))
echo $version > $KERNEL_OUT_DIR_V7\/\.version
fi
fi
if [ -d $KERNEL_OUT_DIR_V7L ]; then
rm -rf $KERNEL_OUT_DIR_V7L
mkdir $KERNEL_OUT_DIR_V7L
chown $SUDO_USER:$SUDO_USER $KERNEL_OUT_DIR_V7L
echo "**** Cleaning ${KERNEL_OUT_DIR_V7L} ****"
if [ "$V7L_VERSION" != "" ]; then
echo "**** Setting version to ${V7L_VERSION} ****"
((version = $V7L_VERSION -1))
echo $version > $KERNEL_OUT_DIR_V7L\/\.version
fi
fi
if [ -d $KERNEL_OUT_DIR_V8 ]; then
rm -rf $KERNEL_OUT_DIR_V8
mkdir $KERNEL_OUT_DIR_V8
chown $SUDO_USER:$SUDO_USER $KERNEL_OUT_DIR_V8
echo "**** Cleaning ${KERNEL_OUT_DIR_V8} ****"
if [ "$V8_VERSION" != "" ]; then
echo "**** Setting version to ${V8_VERSION} ****"
((version = $V8_VERSION -1))
echo $version > $KERNEL_OUT_DIR_V8\/\.version
fi
fi
if [ -d $KERNEL_OUT_DIR_V8L ]; then
rm -rf $KERNEL_OUT_DIR_V8L
mkdir $KERNEL_OUT_DIR_V8L
chown $SUDO_USER:$SUDO_USER $KERNEL_OUT_DIR_V8L
echo "**** Cleaning ${KERNEL_OUT_DIR_V8L} ****"
if [ "$V8L_VERSION" != "" ]; then
echo "**** Setting version to ${V8L_VERSION} ****"
((version = $V8L_VERSION -1))
echo $version > $KERNEL_OUT_DIR_V8L\/\.version
fi
fi
if [ -d $KERNEL_HEADERS_OUT_DIR ]; then
rm -rf $KERNEL_HEADERS_OUT_DIR
mkdir -p $KERNEL_HEADERS_OUT_DIR
chown $SUDO_USER:$SUDO_USER $KERNEL_HEADERS_OUT_DIR
fi
if [ -d $KERNEL_MOD_DIR ]; then
rm -rf $KERNEL_MOD_DIR
mkdir -p $KERNEL_MOD_DIR
chown $SUDO_USER:$SUDO_USER $KERNEL_MOD_DIR
fi
echo "**** Kernel working directories cleaned up ****"
cd -
}
function clean_kernel_src_dir (){
echo "**** Cleaning up kernel source ****"
cd $KERNEL_SRC_DIR
make ARCH=arm mrproper
make ARCH=arm64 mrproper
git checkout ${GIT_BRANCH}
##get_4d_obj
cd -
}
function clone_source() {
echo "**** CLONING to ${REPO_ROOT}${GIT_REPO} ****"
echo "REPO: ${GIT_REPO}"
echo "BRANCH: ${GIT_BRANCH}"
git clone --recursive https://github.com/${GIT_REPO} $KERNEL_SRC_DIR
}
function setup_repos(){
printf "\n**** SETTING UP REPOSITORIES ****\n"
if [ ! -d $REPO_ROOT ]; then
mkdir $REPO_ROOT
fi
if [ "$GIT_REPO" != "raspberrypi/linux" ]; then
if [[ "$GIT_REPO" =~ "http" ]]; then
echo "please provide a valid githubuser/repo path"
usage
exit 1
fi
fi
if [ ! -d $KERNEL_SRC_DIR ]; then
mkdir -p $KERNEL_SRC_DIR
clone_source
fi
if [ ! -d ${MOD_DIR} ]; then
mkdir -p ${MOD_DIR}
fi
if [ ! -d $HEAD_SRC_DIR ]; then
mkdir -p $HEAD_SRC_DIR
fi
if [ ! -d $FIRMWARE_DIR ]; then
echo "**** CLONING RPI-DISTRO-FIRMWARE REPO ****"
git clone --depth 1 https://github.com/${FW_REPO} $FIRMWARE_DIR
fi
}
function pull_firmware() {
# make sure firmware dir is up to date
printf "\n**** UPDATING FIRMWARE REPOSITORY ****\n"
cd $FIRMWARE_DIR
git checkout $FW_BRANCH
git pull
cd -
}
function setup_pkg_dir() {
# Set up the debian package folder
printf "\n**** SETTING UP DEBIAN PACKAGE DIRECTORY ****\n"
mkdir $PKG_DIR
cp -r $FIRMWARE_DIR/* $PKG_DIR
# Remove the pre-compiled modules - we'll compile them ourselves
if [ -d $PKG_DIR/modules ]; then
rm -r $PKG_DIR/modules/*
fi
mkdir -p $PKG_DIR/headers/usr/src/
}
function setup_native_v6_pkg_dir() {
# Set up the debian package folder
printf "\n**** SETTING UP DEBIAN PACKAGE DIRECTORY v6 ****\n"
mkdir -p $PKG_DIR/boot/overlays/
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING/
}
function setup_native_v7_pkg_dir() {
# Set up the debian package folder
printf "\n**** SETTING UP DEBIAN PACKAGE DIRECTORY v7 ****\n"
mkdir -p $PKG_DIR/boot/overlays/
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7/
}
function setup_native_v7l_pkg_dir() {
# Set up the debian package folder
printf "\n**** SETTING UP DEBIAN PACKAGE DIRECTORY v7l ****\n"
mkdir -p $PKG_DIR/boot/overlays/
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7L/
}
function setup_native_v8_pkg_dir() {
# Set up the debian package folder
printf "\n**** SETTING UP DEBIAN PACKAGE DIRECTORY v8 ****\n"
mkdir -p $PKG_DIR/boot/overlays/
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING8/
}
function setup_native_v8l_pkg_dir() {
# Set up the debian package folder
printf "\n**** SETTING UP DEBIAN PACKAGE DIRECTORY v8l ****\n"
mkdir -p $PKG_DIR/boot/overlays/
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING8L/
}
function get_4d_obj() {
## Get the object files back for the 4D-Hat drivers after a clean
printf "\n**** RESTORING 4D-HAT OBJECT FILES ****\n"
cd $KERNEL_SRC_DIR
if [ ! -f compress-v6.o ]; then
git checkout drivers/video/4d-hats/compress-v6.o
fi
if [ ! -f compress-v7.o ]; then
git checkout drivers/video/4d-hats/compress-v7.o
fi
cd -
}
function update_kernel_source(){
cd $KERNEL_SRC_DIR
git fetch
git checkout ${GIT_BRANCH}
git pull
git submodule update --init
##get_4d_obj
cd -
}
function prep_kernel_out_dir() {
kernel_out_dir=$1
printf "\n**** PREPARING WORKING DIRECTORY $kernel_out_dir ****\n"
if [ ! -d $kernel_out_dir ]; then
mkdir -p $kernel_out_dir
fi
}
function make_v6() {
# RasPi v6 build
printf "\n**** COMPILING V6 KERNEL (ARMEL) ****\n"
prep_kernel_out_dir $KERNEL_OUT_DIR_V6
CCPREFIX=arm-linux-gnueabi-
if [ ! -f .config ]; then
if [ "$V6_CONFIG" == "" ]; then
cp $KERNEL_SRC_DIR/${V6_DEFAULT_CONFIG} $KERNEL_OUT_DIR_V6/.config
else
cp ${V6_CONFIG} $KERNEL_OUT_DIR_V6/.config
fi
fi
##make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V6 -C $KERNEL_SRC_DIR menuconfig
make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V6 -C $KERNEL_SRC_DIR olddefconfig
echo "**** SAVING A COPY OF YOUR v6 CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi1_defconfig ****"
cp -f $KERNEL_OUT_DIR_V6/.config $KERNEL_BUILDER_DIR/configs/re4son_pi1_defconfig
echo "**** COMPILING v6 KERNEL ****"
make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V6 -C $KERNEL_SRC_DIR -j${NUM_CPUS} -k zImage modules dtbs
make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V6 -C $KERNEL_SRC_DIR INSTALL_MOD_PATH=${MOD_DIR} -j${NUM_CPUS} modules_install
## Apparently we don't use mkknlimg anymore:
## https://github.com/raspberrypi/linux/issues/3249#issuecomment-534134438
cp -f $KERNEL_OUT_DIR_V6/arch/arm/boot/zImage $PKG_DIR/boot/kernel.img
## Remove symbolic links to non-existent headers and sources
rm -f ${MOD_DIR}/lib/modules/*/build
rm -f ${MOD_DIR}/lib/modules/*/source
## Copy our modules across
cp -r ${MOD_DIR}/lib/* ${PKG_DIR}
## Copy our Module.symvers across
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING/
cp $KERNEL_OUT_DIR_V6/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING/
}
function make_v7() {
# RasPi v7 build
printf "\n**** COMPILING V7 KERNEL (ARMHF) ****\n"
prep_kernel_out_dir $KERNEL_OUT_DIR_V7
CCPREFIX=arm-linux-gnueabihf-
if [ ! -f .config ]; then
if [ "$V7_CONFIG" == "" ]; then
cp $KERNEL_SRC_DIR/${V7_DEFAULT_CONFIG} $KERNEL_OUT_DIR_V7/.config
else
cp ${V7_CONFIG} $KERNEL_OUT_DIR_V7/.config
fi
fi
##make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V7 -C $KERNEL_SRC_DIR menuconfig
make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V7 -C $KERNEL_SRC_DIR olddefconfig
echo "**** SAVING A COPY OF YOUR v7 CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi2_defconfig ****"
cp -f $KERNEL_OUT_DIR_V7/.config $KERNEL_BUILDER_DIR/configs/re4son_pi2_defconfig
echo "**** COMPILING v7 KERNEL ****"
make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V7 -C $KERNEL_SRC_DIR -j${NUM_CPUS} -k zImage modules dtbs
make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V7 -C $KERNEL_SRC_DIR INSTALL_MOD_PATH=${MOD_DIR} -j${NUM_CPUS} modules_install
## Apparently we don't use mkknlimg anymore:
## https://github.com/raspberrypi/linux/issues/3249#issuecomment-534134438
cp -f $KERNEL_OUT_DIR_V7/arch/arm/boot/zImage $PKG_DIR/boot/kernel7.img
## Remove symbolic links to non-existent headers and sources
rm -f ${MOD_DIR}/lib/modules/*-v7+/build
rm -f ${MOD_DIR}/lib/modules/*-v7+/source
## Copy our modules across
cp -r ${MOD_DIR}/lib/* ${PKG_DIR}
## Copy our Module.symvers across
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7/
cp $KERNEL_OUT_DIR_V7/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7/
}
function make_v7l() {
# RasPi vl7 build
printf "\n**** COMPILING V7L KERNEL (ARMHF) ****\n"
prep_kernel_out_dir $KERNEL_OUT_DIR_V7L
CCPREFIX=arm-linux-gnueabihf-
if [ ! -f .config ]; then
if [ "$V7L_CONFIG" == "" ]; then
cp $KERNEL_SRC_DIR/${V7L_DEFAULT_CONFIG} $KERNEL_OUT_DIR_V7L/.config
else
cp ${V7L_CONFIG} $KERNEL_OUT_DIR_V7L/.config
fi
fi
##make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V7L -C $KERNEL_SRC_DIR menuconfig
make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V7L -C $KERNEL_SRC_DIR olddefconfig
echo "**** SAVING A COPY OF YOUR v7l CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi7l_defconfig ****"
cp -f $KERNEL_OUT_DIR_V7L/.config $KERNEL_BUILDER_DIR/configs/re4son_pi7l_defconfig
echo "**** COMPILING v7l KERNEL ****"
make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V7L -C $KERNEL_SRC_DIR -j${NUM_CPUS} -k zImage modules dtbs
make ARCH=arm CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V7L -C $KERNEL_SRC_DIR INSTALL_MOD_PATH=${MOD_DIR} -j${NUM_CPUS} modules_install
## Apparently we don't use mkknlimg anymore:
## https://github.com/raspberrypi/linux/issues/3249#issuecomment-534134438
cp -f $KERNEL_OUT_DIR_V7L/arch/arm/boot/zImage $PKG_DIR/boot/kernel7l.img
## Remove symbolic links to non-existent headers and sources
rm -f ${MOD_DIR}/lib/modules/*-v7l+/build
rm -f ${MOD_DIR}/lib/modules/*-v7l+/source
## Copy our modules across
cp -r ${MOD_DIR}/lib/* ${PKG_DIR}
## Copy our Module.symvers across
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7L/
cp $KERNEL_OUT_DIR_V7L/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7L/
}
function make_v8() {
# RasPi v8 build
printf "\n**** COMPILING V8 KERNEL (ARM64) ****\n"
prep_kernel_out_dir $KERNEL_OUT_DIR_V8
CCPREFIX=aarch64-linux-gnu-
if [ ! -f .config ]; then
if [ "$V8_CONFIG" == "" ]; then
cp $KERNEL_SRC_DIR/${V8_DEFAULT_CONFIG} $KERNEL_OUT_DIR_V8/.config
else
cp ${V8_CONFIG} $KERNEL_OUT_DIR_V8/.config
fi
fi
##make ARCH=arm64 CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V8 -C $KERNEL_SRC_DIR menuconfig
make ARCH=arm64 CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V8 -C $KERNEL_SRC_DIR olddefconfig
echo "**** SAVING A COPY OF YOUR v8 CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi8_defconfig ****"
cp -f $KERNEL_OUT_DIR_V8/.config $KERNEL_BUILDER_DIR/configs/re4son_pi8_defconfig
echo "**** COMPILING v8 KERNEL ****"
## zImage is not supported for 64bit architecture so we build Image
make ARCH=arm64 CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V8 -C $KERNEL_SRC_DIR -j${NUM_CPUS} Image modules dtbs
make ARCH=arm64 CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V8 -C $KERNEL_SRC_DIR INSTALL_MOD_PATH=${MOD_DIR} -j${NUM_CPUS} modules_install
## Name the kernel "kernel8-alt.img" for now to prevent it from automatically being loaded
## To use it, just rename it to kernel8.img on the device
## Apparently we don't use mkknlimg anymore:
## https://github.com/raspberrypi/linux/issues/3249#issuecomment-534134438
cp -f $KERNEL_OUT_DIR_V8/arch/arm64/boot/Image $PKG_DIR/boot/kernel8-alt.img
## Remove symbolic links to non-existent headers and sources
rm -f ${MOD_DIR}/lib/modules/*-v8+/build
rm -f ${MOD_DIR}/lib/modules/*-v8+/source
## Copy our modules across
cp -r ${MOD_DIR}/lib/* ${PKG_DIR}
## Copy our Module.symvers across
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING8/
cp $KERNEL_OUT_DIR_V8/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING8/
}
function make_v8l() {
# RasPi v8l build
printf "\n**** COMPILING V8L KERNEL (ARM64) ****\n"
prep_kernel_out_dir $KERNEL_OUT_DIR_V8L
CCPREFIX=aarch64-linux-gnu-
if [ ! -f .config ]; then
if [ "$V8L_CONFIG" == "" ]; then
cp $KERNEL_SRC_DIR/${V8L_DEFAULT_CONFIG} $KERNEL_OUT_DIR_V8L/.config
else
cp ${V8L_CONFIG} $KERNEL_OUT_DIR_V8L/.config
fi
fi
##make ARCH=arm64 CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V8L -C $KERNEL_SRC_DIR menuconfig
make ARCH=arm64 CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V8L -C $KERNEL_SRC_DIR olddefconfig
echo "**** SAVING A COPY OF YOUR v8l CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi8l_defconfig ****"
cp -f $KERNEL_OUT_DIR_V8L/.config $KERNEL_BUILDER_DIR/configs/re4son_pi8l_defconfig
echo "**** COMPILING v8l KERNEL ****"
## zImage is not supported for 64bit architecture so we build Image
make ARCH=arm64 CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V8L -C $KERNEL_SRC_DIR -j${NUM_CPUS} Image modules dtbs
make ARCH=arm64 CROSS_COMPILE=${CCPREFIX} O=$KERNEL_OUT_DIR_V8L -C $KERNEL_SRC_DIR INSTALL_MOD_PATH=${MOD_DIR} -j${NUM_CPUS} modules_install
## Name the kernel "kernel8-alt.img" for now to prevent it from automatically being loaded
## To use it, just rename it to kernel8.img on the device
## Apparently we don't use mkknlimg anymore:
## https://github.com/raspberrypi/linux/issues/3249#issuecomment-534134438
cp -f $KERNEL_OUT_DIR_V8L/arch/arm64/boot/Image $PKG_DIR/boot/kernel8l-alt.img
## Remove symbolic links to non-existent headers and sources
rm -f ${MOD_DIR}/lib/modules/*-v8l+/build
rm -f ${MOD_DIR}/lib/modules/*-v8l+/source
## Copy our modules across
cp -r ${MOD_DIR}/lib/* ${PKG_DIR}
## Copy our Module.symvers across
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING8L/
cp $KERNEL_OUT_DIR_V8L/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING8L/
}
function make_native_v6() {
# RasPi v6 build
printf "\n**** COMPILING V6 KERNEL (ARMEL) NATIVELY****\n"
prep_kernel_out_dir $KERNEL_OUT_DIR_V6
if [ ! -f .config ]; then
if [ "$V6_CONFIG" == "" ]; then
cp $KERNEL_SRC_DIR/${V6_DEFAULT_CONFIG} $KERNEL_OUT_DIR_V6/.config
else
cp ${V6_CONFIG} $KERNEL_OUT_DIR_V6/.config
fi
fi
make O=$KERNEL_OUT_DIR_V6 -C $KERNEL_SRC_DIR menuconfig
echo "**** SAVING A COPY OF YOUR v6 CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi6_defconfig ****"
cp -f $KERNEL_OUT_DIR_V6/.config $KERNEL_BUILDER_DIR/configs/re4son_pi6_defconfig
echo "**** COMPILING v6 KERNEL ****"
make O=$KERNEL_OUT_DIR_V6 -C $KERNEL_SRC_DIR -j${NUM_CPUS} -k zImage modules dtbs
make O=$KERNEL_OUT_DIR_V6 -C $KERNEL_SRC_DIR INSTALL_MOD_PATH=${MOD_DIR} -j${NUM_CPUS} modules_install
## Apparently we don't use mkknlimg anymore:
## https://github.com/raspberrypi/linux/issues/3249#issuecomment-534134438
cp -f $KERNEL_OUT_DIR_V6/arch/arm/boot/zImage $PKG_DIR/boot/kernel.img
## Remove symbolic links to non-existent headers and sources
rm -f ${MOD_DIR}/lib/modules/*/build
rm -f ${MOD_DIR}/lib/modules/*/source
## Copy our modules across
cp -r ${MOD_DIR}/lib/* ${PKG_DIR}
## Copy away the module dir so we can use it for compiling drivers if we want
if [ ! -d ${KERNEL_MOD_DIR}/v6 ]; then
mkdir -p ${KERNEL_MOD_DIR}/v6
fi
cp -r ${MOD_DIR}/lib/modules/*Re4son+/* ${KERNEL_MOD_DIR}/v6/
## Copy our Module.symvers across
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING/
cp $KERNEL_OUT_DIR_V6/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING/
cp -f $KERNEL_OUT_DIR_V6/Module.symvers $KERNEL_BUILDER_DIR/extra/
cp -f $KERNEL_OUT_DIR_V6/System.map $KERNEL_BUILDER_DIR/extra/
}
function make_native_v7() {
# RasPi v7 build
printf "\n**** COMPILING V7 KERNEL (ARMHF) NATIVELY ****\n"
prep_kernel_out_dir $KERNEL_OUT_DIR_V7
if [ ! -f .config ]; then
if [ "$V7_CONFIG" == "" ]; then
cp $KERNEL_SRC_DIR/${V7_DEFAULT_CONFIG} $KERNEL_OUT_DIR_V7/.config
else
cp ${V7_CONFIG} $KERNEL_OUT_DIR_V7/.config
fi
fi
make O=$KERNEL_OUT_DIR_V7 -C $KERNEL_SRC_DIR menuconfig
echo "**** SAVING A COPY OF YOUR v7 CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi7_defconfig ****"
cp -f $KERNEL_OUT_DIR_V7/.config $KERNEL_BUILDER_DIR/configs/re4son_pi7_defconfig
echo "**** COMPILING v7 KERNEL ****"
make O=$KERNEL_OUT_DIR_V7 -C $KERNEL_SRC_DIR -j${NUM_CPUS} -k zImage modules dtbs
make O=$KERNEL_OUT_DIR_V7 -C $KERNEL_SRC_DIR INSTALL_MOD_PATH=${MOD_DIR} -j${NUM_CPUS} modules_install
## Apparently we don't use mkknlimg anymore:
## https://github.com/raspberrypi/linux/issues/3249#issuecomment-534134438
cp -f $KERNEL_OUT_DIR_V7/arch/arm/boot/zImage $PKG_DIR/boot/kernel7.img
echo $KERNEL_OUT_DIR_V7
echo $PKG_DIR
ls $PKG_DIR/boot/
## Remove symbolic links to non-existent headers and sources
rm -f ${MOD_DIR}/lib/modules/*-v7+/build
rm -f ${MOD_DIR}/lib/modules/*-v7+/source
## Copy our modules across
cp -r ${MOD_DIR}/lib/* ${PKG_DIR}
## Copy away the module dir so we can use it for compiling drivers if we want
if [ ! -d ${KERNEL_MOD_DIR}/v7 ]; then
mkdir -p ${KERNEL_MOD_DIR}/v7
fi
cp -r ${MOD_DIR}/lib/modules/*v7+/* ${KERNEL_MOD_DIR}/v7/
## Copy our Module.symvers across
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7/
cp $KERNEL_OUT_DIR_V7/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7/
cp -f $KERNEL_OUT_DIR_V7/Module.symvers $KERNEL_BUILDER_DIR/extra/Module7.symvers
cp -f $KERNEL_OUT_DIR_V7/System.map $KERNEL_BUILDER_DIR/extra/System7.map
}
function make_native_v7l() {
# RasPi v7l build
printf "\n**** COMPILING V7L KERNEL (ARMHF) NATIVELY ****\n"
prep_kernel_out_dir $KERNEL_OUT_DIR_V7L
if [ ! -f .config ]; then
if [ "$V7L_CONFIG" == "" ]; then
cp $KERNEL_SRC_DIR/${V7L_DEFAULT_CONFIG} $KERNEL_OUT_DIR_V7L/.config
else
cp ${V7L_CONFIG} $KERNEL_OUT_DIR_V7L/.config
fi
fi
make O=$KERNEL_OUT_DIR_V7L -C $KERNEL_SRC_DIR menuconfig
echo "**** SAVING A COPY OF YOUR v7l CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi7l_defconfig ****"
cp -f $KERNEL_OUT_DIR_V7L/.config $KERNEL_BUILDER_DIR/configs/re4son_pi7l_defconfig
echo "**** COMPILING v7l KERNEL ****"
make O=$KERNEL_OUT_DIR_V7L -C $KERNEL_SRC_DIR -j${NUM_CPUS} -k zImage modules dtbs
make O=$KERNEL_OUT_DIR_V7L -C $KERNEL_SRC_DIR INSTALL_MOD_PATH=${MOD_DIR} -j${NUM_CPUS} modules_install
## Apparently we don't use mkknlimg anymore:
## https://github.com/raspberrypi/linux/issues/3249#issuecomment-534134438
cp -f $KERNEL_OUT_DIR_V7L/arch/arm/boot/zImage $PKG_DIR/boot/kernel7l.img
## Remove symbolic links to non-existent headers and sources
rm -f ${MOD_DIR}/lib/modules/*-v7l+/build
rm -f ${MOD_DIR}/lib/modules/*-v7l+/source
## Copy our modules across
cp -r ${MOD_DIR}/lib/* ${PKG_DIR}
## Copy away the module dir so we can use it for compiling drivers if we want
if [ ! -d ${KERNEL_MOD_DIR}/v7l ]; then
mkdir -p ${KERNEL_MOD_DIR}/v7l
fi
cp -r ${MOD_DIR}/lib/modules/*v7l+/* ${KERNEL_MOD_DIR}/v7l/
## Copy our Module.symvers across
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7L/
cp $KERNEL_OUT_DIR_V7L/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7L/
cp -f $KERNEL_OUT_DIR_V7L/Module.symvers $KERNEL_BUILDER_DIR/extra/Module7l.symvers
cp -f $KERNEL_OUT_DIR_V7L/System.map $KERNEL_BUILDER_DIR/extra/System7l.map
}
function make_native_v8() {
# RasPi v8 build
printf "\n**** COMPILING V8 KERNEL (ARM64) NATIVELY ****\n"
prep_kernel_out_dir $KERNEL_OUT_DIR_V8
if [ ! -f .config ]; then
if [ "$V8_CONFIG" == "" ]; then
cp $KERNEL_SRC_DIR/${V8_DEFAULT_CONFIG} $KERNEL_OUT_DIR_V8/.config
else
cp ${V8_CONFIG} $KERNEL_OUT_DIR_V8/.config
fi
fi
make O=$KERNEL_OUT_DIR_V8 -C $KERNEL_SRC_DIR menuconfig
echo "**** SAVING A COPY OF YOUR v8 CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi8_defconfig ****"
cp -f $KERNEL_OUT_DIR_V8/.config $KERNEL_BUILDER_DIR/configs/re4son_pi8_defconfig
echo "**** COMPILING v8 KERNEL ****"
## zImage is not supported for 64bit architecture so we build Image
make O=$KERNEL_OUT_DIR_V8 -C $KERNEL_SRC_DIR -j${NUM_CPUS} Image modules dtbs
make O=$KERNEL_OUT_DIR_V8 -C $KERNEL_SRC_DIR INSTALL_MOD_PATH=${MOD_DIR} -j${NUM_CPUS} modules_install
## Name the kernel "kernel8-alt.img" for now to prevent it from automatically being loaded
## To use it, just rename it to kernel8.img on the device
## Apparently we don't use mkknlimg anymore:
## https://github.com/raspberrypi/linux/issues/3249#issuecomment-534134438
cp -f $KERNEL_OUT_DIR_V8/arch/arm64/boot/Image $PKG_DIR/boot/kernel8-alt.img
## Remove symbolic links to non-existent headers and sources
rm -f ${MOD_DIR}/lib/modules/*-v8+/build
rm -f ${MOD_DIR}/lib/modules/*-v8+/source
## Copy our modules across
cp -r ${MOD_DIR}/lib/* ${PKG_DIR}
## Copy away the module dir so we can use it for compiling drivers if we want
if [ ! -d ${KERNEL_MOD_DIR}/v8 ]; then
mkdir -p ${KERNEL_MOD_DIR}/v8
fi
cp -r ${MOD_DIR}/lib/modules/*v8+/* ${KERNEL_MOD_DIR}/v8/
## Copy our Module.symvers across
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING8/
cp $KERNEL_OUT_DIR_V8/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING8/
cp -f $KERNEL_OUT_DIR_V8/Module.symvers $KERNEL_BUILDER_DIR/extra/Module8.symvers
cp -f $KERNEL_OUT_DIR_V8/System.map $KERNEL_BUILDER_DIR/extra/System8.map
}
function make_native_v8l() {
# RasPi v8l build
printf "\n**** COMPILING V8L KERNEL (ARM64) NATIVELY ****\n"
prep_kernel_out_dir $KERNEL_OUT_DIR_V8L
if [ ! -f .config ]; then
if [ "$V8L_CONFIG" == "" ]; then
cp $KERNEL_SRC_DIR/${V8L_DEFAULT_CONFIG} $KERNEL_OUT_DIR_V8L/.config
else
cp ${V8L_CONFIG} $KERNEL_OUT_DIR_V8L/.config
fi
fi
make O=$KERNEL_OUT_DIR_V8L -C $KERNEL_SRC_DIR menuconfig
echo "**** SAVING A COPY OF YOUR v8l CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi8l_defconfig ****"
cp -f $KERNEL_OUT_DIR_V8L/.config $KERNEL_BUILDER_DIR/configs/re4son_pi8l_defconfig
echo "**** COMPILING v8l KERNEL ****"
## zImage is not supported for 64bit architecture so we build Image
make O=$KERNEL_OUT_DIR_V8L -C $KERNEL_SRC_DIR -j${NUM_CPUS} Image modules dtbs
make O=$KERNEL_OUT_DIR_V8L -C $KERNEL_SRC_DIR INSTALL_MOD_PATH=${MOD_DIR} -j${NUM_CPUS} modules_install
## Name the kernel "kernel8l-alt.img" for now to prevent it from automatically being loaded
## To use it, just rename it to kernel8l.img on the device
## Apparently we don't use mkknlimg anymore:
## https://github.com/raspberrypi/linux/issues/3249#issuecomment-534134438
cp -f $KERNEL_OUT_DIR_V8L/arch/arm64/boot/Image $PKG_DIR/boot/kernel8l-alt.img
## Remove symbolic links to non-existent headers and sources
rm -f ${MOD_DIR}/lib/modules/*-v8l+/build
rm -f ${MOD_DIR}/lib/modules/*-v8l+/source
## Copy our modules across
cp -r ${MOD_DIR}/lib/* ${PKG_DIR}
## Copy away the module dir so we can use it for compiling drivers if we want
if [ ! -d ${KERNEL_MOD_DIR}/v8l ]; then
mkdir -p ${KERNEL_MOD_DIR}/v8l
fi
cp -r ${MOD_DIR}/lib/modules/*v8l+/* ${KERNEL_MOD_DIR}/v8l/
## Copy our Module.symvers across
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING8L/
cp $KERNEL_OUT_DIR_V8L/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING8L/
cp -f $KERNEL_OUT_DIR_V8L/Module.symvers $KERNEL_BUILDER_DIR/extra/Module8l.symvers
cp -f $KERNEL_OUT_DIR_V8L/System.map $KERNEL_BUILDER_DIR/extra/System8l.map
}
function make_headers (){
config=$1
ccprefix=$2
echo $config
echo $ccprefix
cd $KERNEL_SRC_DIR
if [ ! $ccprefix ]; then
make distclean $config modules_prepare
elif [ $ccprefix == "aarch64-linux-gnu-" ]; then
make ARCH=arm64 CROSS_COMPILE=${ccprefix} distclean $config modules_prepare
else
make ARCH=arm CROSS_COMPILE=${ccprefix} distclean $config modules_prepare
fi
cd -
}
function copy_files (){
ver=$1
destdir=$KERNEL_HEADERS_OUT_DIR/headers/usr/src/linux-headers-$ver
if [ -d $destdir ]; then
rm -rf $destdir
fi
mkdir -p "$destdir"/tools/include
mkdir -p $KERNEL_HEADERS_OUT_DIR/headers/lib/modules/$ver
rsync -aHAX \
--files-from=<(cd $KERNEL_SRC_DIR; find -name Makefile\* -o -name Kconfig\* -o -name \*.pl) $KERNEL_SRC_DIR/ $destdir/
rsync -aHAX \
--files-from=<(cd $KERNEL_SRC_DIR; find arch/arm*/include tools/include include scripts -type f) $KERNEL_SRC_DIR/ $destdir/
rsync -aHAX \
--files-from=<(cd $KERNEL_SRC_DIR; find arch/arm* -name module.lds -o -name Kbuild.platforms -o -name Platform) $KERNEL_SRC_DIR/ $destdir/
rsync -aHAX \
--files-from=<(cd $KERNEL_SRC_DIR; find `find arch/arm* -name include -o -name scripts -type d` -type f) $KERNEL_SRC_DIR/ $destdir/
rsync -aHAX \
--files-from=<(cd $KERNEL_SRC_DIR; find arch/arm*/include .config tools/include include scripts -type f) $KERNEL_SRC_DIR/ $destdir/
ln -sf "/usr/src/linux-headers-$ver" "$KERNEL_HEADERS_OUT_DIR/headers/lib/modules/$ver/build"
## Module.symvers are going to be provided by the kernel build
}
function pkg_headers () {
printf "\n**** Creating $KERNEL_BUILDER_DIR/re4son_headers_${NAT_ARCH}_${NEW_VERSION}.tar.xz ****\n"
cd $KERNEL_HEADERS_OUT_DIR
XZ_OPT="--threads=0" tar -cJf $KERNEL_BUILDER_DIR/re4son_headers_${NAT_ARCH}_${NEW_VERSION}.tar.xz headers
printf "\n@@@@ The re4son-headers_${NAT_ARCH}_${NEW_VERSION}.tar.xz archive should now be available in ${KERNEL_BUILDER_DIR} @@@@\n\n"
chown $SUDO_UID:$SUDO_GID $KERNEL_BUILDER_DIR/re4son_headers_${NAT_ARCH}_${NEW_VERSION}.tar.xz
cd -
}
function pkg_kernel() {
printf "\n**** Creating $KERNEL_BUILDER_DIR/re4son_kernel_${NAT_ARCH}_${NEW_VERSION}.tar.xz ****\n"
cd $PKG_DIR
XZ_OPT="--threads=0" tar -cJf $KERNEL_BUILDER_DIR/re4son_kernel_${NAT_ARCH}_${NEW_VERSION}.tar.xz *
printf "\n@@@@ The re4son-kernel_${NAT_ARCH}_${NEW_VERSION}.tar.xz archive should now be available in ${KERNEL_BUILDER_DIR} @@@@\n\n"
chown $SUDO_UID:$SUDO_GID $KERNEL_BUILDER_DIR/re4son_kernel_${NAT_ARCH}_${NEW_VERSION}.tar.xz
cd -
}
function make_nexmon () {
## Compiling nexmon firmware patches for Raspberry Pi 3
cp -r ${MOD_DIR}/lib/modules/*-v7+/* ${KERNEL_MOD_DIR}/
cd ${NEXMON_DIR}
source setup_env.sh
cd patches/bcm43438/7_45_41_26/nexmon
make
cd $KERNEL_BUILDER_DIR
}
function make_native_nexmon () {
## Compiling nexmon firmware patches
cd ${NEXMON_DIR}
source setup_env.sh
cd patches/bcm43438/7_45_41_26/nexmon
make
cd $KERNEL_BUILDER_DIR
}
function import_archives() {
rm -rf $PKG_DIR/headers
cd $PKG_IN
for i in *.tar.xz; do printf "\n**** Extracting $i to ${PKG_DIR} ****\n"; tar -xJf $i -C ${PKG_DIR}/; done
cd -
}
function create_debs() {
# copy aftermarket overlays
cp -r $KERNEL_BUILDER_DIR/boot/* $PKG_DIR/boot 2>>/dev/null
# tar up firmware
cd $PKG_TMP
tar czf kalipi-firmware_${NEW_VERSION}.orig.tar.gz kalipi-firmware_${NEW_VERSION}
# copy debian files to package directory
cp -r $FIRMWARE_DIR/debian $PKG_DIR
touch $PKG_DIR/debian/files
##cd $PKG_DIR/debian
##sh ./gen_bootloader_postinst_preinst.sh
cd $PKG_DIR
dch -b -v ${NEW_VERSION} -D stable --force-distribution "Re4son Kernel source ${GIT_BRANCH}; firmware ${FW_BRANCH}"
debuild --no-lintian -b -aarmel -us -uc
##debuild --no-lintian -ePATH=${PATH}:${TOOLS_DIR}/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin -b -aarmhf -us -uc
debuild --no-lintian -b -aarmhf -us -uc
debuild --no-lintian -b -aarm64 -us -uc
}
function create_tar() {
cd $PKG_TMP
mkdir re4son-kernel_${NEW_VERSION}
mkdir re4son-kernel_${NEW_VERSION}_armel
mkdir re4son-kernel_${NEW_VERSION}_armhf
mkdir re4son-kernel_${NEW_VERSION}_arm64
mkdir re4son-kernel_${NEW_VERSION}/docs
mkdir re4son-kernel_${NEW_VERSION}/dts
mkdir re4son-kernel_${NEW_VERSION}/tools
mkdir re4son-kernel_${NEW_VERSION}/firmware
mkdir re4son-kernel_${NEW_VERSION}/repo
mkdir re4son-kernel_${NEW_VERSION}/nexmon
cp *armhf.deb re4son-kernel_${NEW_VERSION}
cp *armel.deb re4son-kernel_${NEW_VERSION}_armel
cp *armhf.deb re4son-kernel_${NEW_VERSION}_armhf
cp *arm64.deb re4son-kernel_${NEW_VERSION}_arm64
cp -r $KERNEL_BUILDER_DIR/nexmon/* re4son-kernel_${NEW_VERSION}/nexmon
cp $KERNEL_BUILDER_DIR/install.sh re4son-kernel_${NEW_VERSION}
cp $KERNEL_BUILDER_DIR/dts/*.dts re4son-kernel_${NEW_VERSION}/dts
cp $KERNEL_BUILDER_DIR/docs/INSTALL re4son-kernel_${NEW_VERSION}
cp $KERNEL_BUILDER_DIR/docs/* re4son-kernel_${NEW_VERSION}/docs
cp $KERNEL_BUILDER_DIR/configs/* re4son-kernel_${NEW_VERSION}/docs
cp $KERNEL_BUILDER_DIR/Re4son-Pi-TFT-Setup/re4son-pi-tft-setup re4son-kernel_${NEW_VERSION}
cp $KERNEL_BUILDER_DIR/Re4son-Pi-TFT-Setup/adafruit-pitft-touch-cal re4son-kernel_${NEW_VERSION}/tools
cp $KERNEL_BUILDER_DIR/tools/* re4son-kernel_${NEW_VERSION}/tools
cp $KERNEL_BUILDER_DIR/firmware/* re4son-kernel_${NEW_VERSION}/firmware
cp $KERNEL_BUILDER_DIR/repo/* re4son-kernel_${NEW_VERSION}/repo
chmod +x re4son-kernel_${NEW_VERSION}/install.sh
chmod +x re4son-kernel_${NEW_VERSION}/re4son-pi-tft-setup
chmod +x re4son-kernel_${NEW_VERSION}/tools/adafruit-pitft-touch-cal
tar cJf re4son-kernel_${NEW_VERSION}.tar.xz re4son-kernel_${NEW_VERSION}
mv -f re4son-kernel_${NEW_VERSION}.tar.xz $KERNEL_BUILDER_DIR
sha256sum $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}.tar.xz > $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}.tar.xz.sha256
chown $SUDO_UID:$SUDO_GID $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}.tar.xz* $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}.tar.xz.sha256
tar cJf re4son-kernel_${NEW_VERSION}_armel.tar.xz re4son-kernel_${NEW_VERSION}_armel
mv -f re4son-kernel_${NEW_VERSION}_armel.tar.xz $KERNEL_BUILDER_DIR
sha256sum $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_armel.tar.xz > $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_armel.tar.xz.sha256
chown $SUDO_UID:$SUDO_GID $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_armel.tar.xz* $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_armel.tar.xz.sha256
tar cJf re4son-kernel_${NEW_VERSION}_armhf.tar.xz re4son-kernel_${NEW_VERSION}_armhf
mv -f re4son-kernel_${NEW_VERSION}_armhf.tar.xz $KERNEL_BUILDER_DIR
sha256sum $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_armhf.tar.xz > $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_armhf.tar.xz.sha256
chown $SUDO_UID:$SUDO_GID $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_armhf.tar.xz* $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_armhf.tar.xz.sha256
tar cJf re4son-kernel_${NEW_VERSION}_arm64.tar.xz re4son-kernel_${NEW_VERSION}_arm64
mv -f re4son-kernel_${NEW_VERSION}_arm64.tar.xz $KERNEL_BUILDER_DIR
sha256sum $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_arm64.tar.xz > $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_arm64.tar.xz.sha256
chown $SUDO_UID:$SUDO_GID $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_arm64.tar.xz* $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}_arm64.tar.xz.sha256
printf "\n@@@@ The re4son-kernel_${NEW_VERSION}.tar.xz archive should now be available in ${KERNEL_BUILDER_DIR} @@@@\n\n"
}
## ##
################################################
################################################
################################################
################################################
## ##
## MAIN ##
check_root
debug_info
breakpoint "010-Root privileges checked"
while getopts "hb:cnpexr:6:7:8:" opt; do
case "$opt" in
h) usage
exit 0
;;
b) GIT_BRANCH="$OPTARG"
;;
c) clean
exit 0
;;
n) NATIVE=true
NAT_ARCH=`dpkg --print-architecture`
;;
p) MAKE_PKG=true
;;
e) MAKE_HEADERS=true
if [ ! $NAT_ARCH ]; then
NAT_ARCH=`dpkg --print-architecture`
fi
;;
x) MAKE_NEXMON=true
if [ ! $NAT_ARCH ]; then
NAT_ARCH=`dpkg --print-architecture`
fi
;;
r) GIT_REPO="$OPTARG"
;;
6) V6_CONFIG="$OPTARG"
;;
7) V7_CONFIG="$OPTARG"
;;
8) V8_CONFIG="$OPTARG"
;;
\?) usage
exit 1
;;
esac
done
printf "\n\t**** USING ${NUM_CPUS} AVAILABLE CORES ****\n"
if [ ! $NATIVE ] && [ ! $MAKE_HEADERS ] && [ ! $MAKE_PKG ] && [ ! $MAKE_NEXMON ]; then
setup_repos
update_kernel_source
breakpoint "020-Repos set up"
pull_firmware
breakpoint "040-Firmware repo updated"
setup_pkg_dir
debug_info
breakpoint "050-Pkg dir set up"
clean_kernel_src_dir
if [ ! -z "$V6_VERSION" ]; then
make_v6
make_headers $(basename $V6_DEFAULT_CONFIG) arm-linux-gnueabi-
copy_files $UNAME_STRING
clean_kernel_src_dir
breakpoint "060-Kernel v6 compiled"
fi
if [ ! -z "$V7_VERSION" ]; then
make_v7
debug_info
make_headers $(basename $V7_DEFAULT_CONFIG) arm-linux-gnueabihf-
copy_files $UNAME_STRING7
clean_kernel_src_dir
breakpoint "070-Kernel v7 compiled"
fi
if [ ! -z "$V7L_VERSION" ]; then
make_v7l
debug_info
make_headers $(basename $V7L_DEFAULT_CONFIG) arm-linux-gnueabihf-
copy_files $UNAME_STRING7L
clean_kernel_src_dir
breakpoint "070-Kernel v7l compiled"
fi
if [ ! -z "$V8_VERSION" ]; then
make_v8
debug_info
make_headers $(basename $V8_DEFAULT_CONFIG) aarch64-linux-gnu-
copy_files $UNAME_STRING8
clean_kernel_src_dir