forked from Re4son/re4son-kernel-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·774 lines (673 loc) · 26.1 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
#!/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="4.9.59"
V6_VERSION="1"
V7_VERSION="1"
## Repos
###################################################
## 4.4.28 ##
##GIT_BRANCH="1423ac8bfbfb2a9d092b604c676e7a58a5fa3367" ## 4.9.28 Commit used for firmware 1.20170515 release
###################################################
## 4.4.24 ##
##GIT_BRANCH="ef3b440e0e4d9ca70060483aa33d5b1201ceceb8" ## 4.9.24 Commit used for firmware 1.20170427 release
###################################################
## 4.9.59-Re4son ##
GIT_REPO="Re4son/re4son-raspberrypi-linux"
GIT_BRANCH="rpi-4.9.59-re4son" ## 4.9.59 Commit used for firmware 1.20171029 release
FW_REPO="Re4son/RPi-Distro-firmware"
FW_BRANCH="4.9.59"
###################################################
## 4.9.41-Re4son ##
##GIT_REPO="Re4son/re4son-raspberrypi-linux"
##GIT_BRANCH="rpi-4.9.41-re4son" ## 4.9.41 Commit used for firmware 1.20170811 release
##FW_REPO="Re4son/RPi-Distro-firmware"
##FW_BRANCH="4.9.41"
###################################################
## 4.9.24-Re4son ##
##GIT_REPO="Re4son/re4son-raspberrypi-linux"
##GIT_BRANCH="rpi-4.9.24-re4son" ## 4.9.24 Commit used for firmware 1.20170427 release
##FW_REPO="Re4son/RPi-Distro-firmware"
##FW_BRANCH="4.9.41"
###################################################
## 4.4.50-Re4son ##
##GIT_REPO="Re4son/re4son-raspberrypi-linux"
##GIT_BRANCH="rpi-4.4.50-re4son"
##FW_REPO="Re4son/RPi-Distro-firmware"
##FW_BRANCH="4.4.50"
###################################################
## 4.4.50-Re4son-Master ##
##GIT_BRANCH="rpi-4.4.50-re4son-master"
###################################################
## 4.4.50 ##
##GIT_BRANCH="e223d71ef728c559aa865d0c5a4cedbdf8789cfd" ## 4.4.50 Commit used for firmware 1.20170405 release
##GIT_BRANCH="rpi-4.4.y-re4son"
## defconfigs:
V6_DEFAULT_CONFIG="arch/arm/configs/re4son_pi1_defconfig"
V7_DEFAULT_CONFIG="arch/arm/configs/re4son_pi2_defconfig"
##V6_DEFAULT_CONFIG="arch/arm/configs/bcmrpi_defconfig"
##V7_DEFAULT_CONFIG="arch/arm/configs/bcm2709_defconfig"
V6_CONFIG=""
v7_CONFIG=""
export DEBFULLNAME=Re4son
export [email protected]
UNAME_STRING="${VERSION}-Re4son+"
UNAME_STRING7="${VERSION}-Re4son-v7+"
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}/raspberrypi-firmware_${NEW_VERSION}"
TOOLS_DIR="/opt/kernel-builder_tools"
FIRMWARE_DIR="/opt/kernel-builder_RPi-Distro-firmware"
#FIRMWARE_DIR="/opt/kernel-builder_firmware"
V6_DIR="${REPO_ROOT}${GIT_REPO}/v6"
V7_DIR="${REPO_ROOT}${GIT_REPO}/v7"
HEAD_SRC_DIR="${REPO_ROOT}${GIT_REPO}/head_src_dir"
PKG_IN="/opt/kernel-builder_pkg_in/"
KERN_MOD_DIR_V6="/opt/kernel-builder_mod_v6" ## Target directory for pi/pi0 modules that can be used for compiling drivers
KERN_MOD_DIR_V7="/opt/kernel-builder_mod_v7" ## Target directory for pi2/pi3 modules that can be used for compiling drivers
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 "REPO_ROOT:\t$REPO_ROOT\n"
printf "V6_DIR:\t\t$V6_DIR\n"
printf "V7_DIR:\t\t$V7_DIR\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 "KERN_MOD_DIR:\t$KERN_MOD_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 Raspberry 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
EOF
}
function clean() {
echo "**** Cleaning up kernel source ****"
if [ -d $V6_DIR ]; then
cd $V6_DIR
git checkout ${GIT_BRANCH}
echo "**** Cleaning ${V6_DIR} ****"
make mrproper
## Overwrite with remote repo - use if mrproper goes too far
git reset --hard HEAD
git pull
if [ "$V6_VERSION" != "" ]; then
echo "**** Setting version to ${V6_VERSION} ****"
((version = $V6_VERSION -1))
echo $version > .version
fi
fi
if [ -d $V7_DIR ]; then
cd $V7_DIR
git checkout ${GIT_BRANCH}
echo "**** Cleaning ${V7_DIR} ****"
make mrproper
## Overwrite with remote repo - use if mrproper goes too far
git reset --hard HEAD
git pull
if [ "$V7_VERSION" != "" ]; then
echo "**** Setting version to ${V7_VERSION} ****"
((version = $V7_VERSION -1))
echo $version > .version
fi
fi
echo "**** Kernel source directories cleaned up ****"
exit 0
}
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} $V6_DIR
cp -r $V6_DIR $V7_DIR
echo "**** COPYING HEADER SOURCE DIRECTORY ****"
cp -r $V6_DIR $HEAD_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 $V6_DIR ]; then
mkdir -p $V6_DIR
clone_source
fi
# if [ ! -d $TOOLS_DIR ]; then
# echo "**** CLONING TOOL REPO ****"
# git clone --depth 1 https://github.com/raspberrypi/tools $TOOLS_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_tools() {
# make sure tools dir is up to date
printf "\n**** UPDATING TOOLS REPOSITORY ****\n"
cd $TOOLS_DIR
git pull
cd -
}
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
rm -r $PKG_DIR/modules/*
}
function setup_native_v6_pkg_dir() {
# Set up the debian package folder
printf "\n**** SETTING UP DEBIAN PACKAGE DIRECTORY ****\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 ****\n"
mkdir -p $PKG_DIR/boot/overlays/
mkdir -p $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7/
}
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"
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
}
function make_v6() {
# RasPi v6 build
printf "\n**** COMPILING V6 KERNEL (ARMEL) ****\n"
cd $V6_DIR
git fetch
git checkout ${GIT_BRANCH}
git pull
git submodule update --init
get_4d_obj
CCPREFIX=${TOOLS_DIR}/arm-bcm2708/arm-bcm2708-linux-gnueabi/bin/arm-bcm2708-linux-gnueabi-
if [ ! -f .config ]; then
if [ "$V6_CONFIG" == "" ]; then
cp ${V6_DEFAULT_CONFIG} .config
else
cp ${V6_CONFIG} .config
fi
fi
ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig
echo "**** SAVING A COPY OF YOUR v6 CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi1_defconfig ****"
cp -f .config $KERNEL_BUILDER_DIR/configs/re4son_pi1_defconfig
echo "**** COMPILING v6 KERNEL ****"
ARCH=arm CROSS_COMPILE=${CCPREFIX} make -j${NUM_CPUS} -k zImage modules dtbs
ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MOD_DIR} make -j${NUM_CPUS} modules_install
## mkknlimg is no longer in tools
## ${TOOLS_DIR}/mkimage/mkknlimg arch/arm/boot/zImage $PKG_DIR/boot/kernel.img
## It is now found in the scripts directory of the Linux tree, where they are covered by the kernel licence
${V6_DIR}/scripts/mkknlimg 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
cp ${V6_DIR}/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING/
}
function make_v7() {
# RasPi v7 build
printf "\n**** COMPILING V7 KERNEL (ARMHF) ****\n"
cd $V7_DIR
git fetch
git checkout ${GIT_BRANCH}
git pull
git submodule update --init
get_4d_obj
CCPREFIX=${TOOLS_DIR}/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/arm-linux-gnueabihf-
if [ ! -f .config ]; then
if [ "$V7_CONFIG" == "" ]; then
cp ${V7_DEFAULT_CONFIG} .config
else
cp ${V7_CONFIG} .config
fi
fi
ARCH=arm CROSS_COMPILE=${CCPREFIX} make menuconfig
echo "**** SAVING A COPY OF YOUR v7 CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi2_defconfig ****"
cp -f .config $KERNEL_BUILDER_DIR/configs/re4son_pi2_defconfig
echo "**** COMPILING v7 KERNEL ****"
ARCH=arm CROSS_COMPILE=${CCPREFIX} make -j${NUM_CPUS} -k zImage modules dtbs
ARCH=arm CROSS_COMPILE=${CCPREFIX} INSTALL_MOD_PATH=${MOD_DIR} make -j${NUM_CPUS} modules_install
cp arch/arm/boot/dts/*.dtb $PKG_DIR/boot/
cp arch/arm/boot/dts/overlays/*.dtb* $PKG_DIR/boot/overlays/
cp arch/arm/boot/dts/overlays/README $PKG_DIR/boot/overlays/
## mkknlimg is no longer in tools
## ${TOOLS_DIR}/mkimage/mkknlimg arch/arm/boot/zImage $PKG_DIR/boot/kernel7.img
## It is now found in the scripts directory of the Linux tree, where they are covered by the kernel licence
${V7_DIR}/scripts/mkknlimg 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
cp -f ${V7_DIR}/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7/
}
function make_native_v6() {
# RasPi v6 build
printf "\n**** COMPILING V6 KERNEL (ARMEL) NATIVELY****\n"
cd $V6_DIR
git fetch
git checkout ${GIT_BRANCH}
git pull
git submodule update --init
get_4d_obj
if [ ! -f .config ]; then
if [ "$V6_CONFIG" == "" ]; then
cp ${V6_DEFAULT_CONFIG} .config
else
cp ${V6_CONFIG} .config
fi
fi
make menuconfig
echo "**** SAVING A COPY OF YOUR v6 CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi1_defconfig ****"
cp -f .config $KERNEL_BUILDER_DIR/configs/re4son_pi1_defconfig
echo "**** COMPILING v6 KERNEL ****"
make -j${NUM_CPUS} -k zImage modules dtbs
INSTALL_MOD_PATH=${MOD_DIR} make -j${NUM_CPUS} modules_install
## mkknlimg is no longer in tools
## ${TOOLS_DIR}/mkimage/mkknlimg arch/arm/boot/zImage $PKG_DIR/boot/kernel.img
## It is now found in tsetup_native_v6_pkg_dir()he scripts directory of the Linux tree, where they are covered by the kernel licence
${V6_DIR}/scripts/mkknlimg 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 cak use it for compiling drivers if we want
cp -r ${MOD_DIR}/lib/modules/*/* ${KERN_MOD_DIR}/
## Copy our Module.symvers across
cp -f ${V6_DIR}/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING/
cp -f ${V6_DIR}/Module.symvers $KERNEL_BUILDER_DIR/extra/
cp -f ${V6_DIR}/System.map $KERNEL_BUILDER_DIR/extra/
}
function make_native_v7() {
# RasPi v7 build
printf "\n**** COMPILING V7 KERNEL (ARMHF) NATIVELY ****\n"
cd $V7_DIR
git fetch
git checkout ${GIT_BRANCH}
git pull
git submodule update --init
get_4d_obj
if [ ! -f .config ]; then
if [ "$V7_CONFIG" == "" ]; then
cp ${V7_DEFAULT_CONFIG} .config
else
cp ${V7_CONFIG} .config
fi
fi
make menuconfig
echo "**** SAVING A COPY OF YOUR v7 CONFIG TO $KERNEL_BUILDER_DIR/configs/re4son_pi2_defconfig ****"
cp -f .config $KERNEL_BUILDER_DIR/configs/re4son_pi2_defconfig
echo "**** COMPILING v7 KERNEL ****"
make -j${NUM_CPUS} -k zImage modules dtbs
INSTALL_MOD_PATH=${MOD_DIR} make -j${NUM_CPUS} modules_install
cp arch/arm/boot/dts/*.dtb $PKG_DIR/boot/
cp arch/arm/boot/dts/overlays/*.dtb* $PKG_DIR/boot/overlays/
cp arch/arm/boot/dts/overlays/README $PKG_DIR/boot/overlays/
## mkknlimg is no longer in tools
## ${TOOLS_DIR}/mkimage/mkknlimg arch/arm/boot/zImage $PKG_DIR/boot/kernel7.img
## It is now found in the scripts directory of the Linux tree, where they are covered by the kernel licence
${V7_DIR}/scripts/mkknlimg 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 away the module dir so we cak use it for compiling drivers if we want
cp -r ${MOD_DIR}/lib/modules/*/* ${KERN_MOD_DIR}/
## Copy our Module.symvers across
cp -f ${V7_DIR}/Module.symvers $PKG_DIR/headers/usr/src/linux-headers-$UNAME_STRING7/
cp -f ${V7_DIR}/Module.symvers $KERNEL_BUILDER_DIR/extra/Module7.symvers
cp -f ${V7_DIR}/System.map $KERNEL_BUILDER_DIR/extra/System7.map
}
function make_headers (){
config=$1
cd $HEAD_SRC_DIR
if [ -d headers ]; then
rm -rf headers
fi
git pull
printf "**** Updating files... ****\n"
echo "+" > .scmversion
make distclean $config modules_prepare
cd -
}
function copy_files (){
ver=$1
destdir=headers/usr/src/linux-headers-$ver
cd $HEAD_SRC_DIR
mkdir -p "$destdir"
mkdir -p headers/lib/modules/$ver
rsync -aHAX \
--files-from=<(cd $HEAD_SRC_DIR; find -name Makefile\* -o -name Kconfig\* -o -name \*.pl) $HEAD_SRC_DIR/ $destdir/
rsync -aHAX \
--files-from=<(cd $HEAD_SRC_DIR; find arch/arm/include include scripts -type f) $HEAD_SRC_DIR/ $destdir/
rsync -aHAX \
--files-from=<(cd $HEAD_SRC_DIR; find arch/arm -name module.lds -o -name Kbuild.platforms -o -name Platform) $HEAD_SRC_DIR/ $destdir/
rsync -aHAX \
--files-from=<(cd $HEAD_SRC_DIR; find `find arch/arm -name include -o -name scripts -type d` -type f) $HEAD_SRC_DIR/ $destdir/
rsync -aHAX \
--files-from=<(cd $HEAD_SRC_DIR; find arch/arm/include Module.symvers .config include scripts -type f) $HEAD_SRC_DIR/ $destdir/
ln -sf "/usr/src/linux-headers-$ver" "headers/lib/modules/$ver/build"
cd -
}
function pkg_headers () {
printf "\n**** Creating $KERNEL_BUILDER_DIR/re4son_headers_${NAT_ARCH}_${NEW_VERSION}.tar.xz ****\n"
cd $HEAD_SRC_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"
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"
cd -
}
function make_nexmon () {
## Compiling nexmon firmware patches for Raspberry Pi 3
cp -r ${MOD_DIR}/lib/modules/*-v7*/* ${KERN_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 overlays
cp -r $KERNEL_BUILDER_DIR/boot/* $PKG_DIR/boot
# tar up firmware
cd $PKG_TMP
tar czf raspberrypi-firmware_${NEW_VERSION}.orig.tar.gz raspberrypi-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 -v ${NEW_VERSION} -D stable --force-distribution "Re4son Kernel source ${GIT_BRANCH}; firmware ${FW_BRANCH}"
debuild --no-lintian -ePATH=${PATH}:${TOOLS_DIR}/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin -b -aarmhf -us -uc
}
function create_tar() {
cd $PKG_TMP
mkdir re4son-kernel_${NEW_VERSION}
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 *.deb re4son-kernel_${NEW_VERSION}
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 re4son:re4son $KERNEL_BUILDER_DIR/re4son-kernel_${NEW_VERSION}.tar.xz*
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:" 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"
;;
\?) 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
breakpoint "020-Repos set up"
## Lets only update the repos when I'm sure they don't break anything.
##pull_tools
##breakpoint "030-Tools repo updated"
pull_firmware
breakpoint "040-Firmware repo updated"
setup_pkg_dir
debug_info
breakpoint "050-Pkg dir set up"
make_v6
breakpoint "060-Kernel v6 compiled"
make_v7
debug_info
breakpoint "070-Kernel v7 compiled"
create_debs
debug_info
breakpoint "080-Debian packages created"
# make_nexmon
# breakpoint "090-Nexmon drivers compiled"
create_tar
debug_info
exit 0
elif [ $NATIVE ]; then
if [ $NAT_ARCH == "armel" ]; then
printf "\n\t**** Compiling natively on: $NAT_ARCH ****\n"
setup_native_v6_pkg_dir
debug_info
breakpoint "150-Pkg dir set up"
make_native_v6
breakpoint "160-Kernel v6 compiled"
pkg_kernel
elif [ $NAT_ARCH == "armhf" ]; then
printf "\n\t**** Compiling natively on: $NAT_ARCH ****\n"
setup_native_v7_pkg_dir
debug_info
breakpoint "150-Pkg dir set up"
make_native_v7
breakpoint "160-Kernel v7 compiled"
pkg_kernel
else
printf"\n\t#### ERROR: Architecture $ARCH not supported. ####\n"
fi
fi
if [ $MAKE_HEADERS ]; then
printf "\n\t**** Building headers for: $NAT_ARCH ****\n"
if [ $NAT_ARCH == "armel" ]; then
debug_info
breakpoint "200-Ready to build headers"
make_headers $(basename $V6_DEFAULT_CONFIG)
if [ -f ${KERNEL_BUILDER_DIR}/extra/Module.symvers ]; then
cp ${KERNEL_BUILDER_DIR}/extra/Module.symvers ${HEAD_SRC_DIR}/Module.symvers
fi
debug_info
breakpoint "210-headers built"
copy_files $UNAME_STRING
debug_info
breakpoint "220-headers copied"
pkg_headers
elif [ $NAT_ARCH == "armhf" ]; then
debug_info
breakpoint "200-Ready to build headers"
make_headers $(basename $V7_DEFAULT_CONFIG)
if [ -f ${KERNEL_BUILDER_DIR}/extra/Module7.symvers ]; then
cp ${KERNEL_BUILDER_DIR}/extra/Module7.symvers ${HEAD_SRC_DIR}/Module.symvers
fi
debug_info
breakpoint "210-headers built"
copy_files $UNAME_STRING7
debug_info
breakpoint "220-headers copied"
pkg_headers
fi
fi
if [ $MAKE_PKG ]; then
debug_info
breakpoint "300-Ready to package"
pull_firmware
setup_pkg_dir
debug_info
breakpoint "310-Pkg dir set up"
ls -l ${PKG_IN}
breakpoint "320-Ready to import archives"
import_archives
breakpoint "330-Archives imported"
create_debs
debug_info
breakpoint "340-Debian packages created"
create_tar
debug_info
fi
exit 0
## ##
################################################
################################################