-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmxubuild.sh
executable file
·868 lines (729 loc) · 23.7 KB
/
mxubuild.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
#!/bin/bash
export CCACHE_DIR="$HOME/.ccache"
export USE_CCACHE="1"
export CCACHE_NLEVELS="8"
#env KCONFIG_NOTIMESTAMP=true &>/dev/null
warnandfailearly() {
echo -n "MX ERROR on Line ${BASH_LINENO[0]}"
echo "!!!"
local ISTRING
ISTRING="$1"
if [ -n "$ISTRING" ]
then
printf "%s\n" "$ISTRING"
fi
exit 1
}
if [ ! -d "/home/rob/mx_toolchains" ]
then
warnandfailearly "/home/rob/mx_toolchains folder does not exist!"
fi
RDIR="/home/rob/mn3lite"
BUILDIR="$RDIR/build"
LOGDIR="$RDIR/buildlogs"
KDIR="$BUILDIR/arch/arm/boot"
OLDVERFILE="$RDIR/.oldversion"
OLDVER="$(cat $OLDVERFILE)"
LASTZIPFILE="$RDIR/.lastzip"
LASTZIP="$(cat $LASTZIPFILE)"
ENDFILE="$RDIR/.endtime"
STARTFILE="$RDIR/.starttime"
RAMDISKFOLDER="$RDIR/mxramdisk"
ZIPFOLDER="$RDIR/mxzip"
MXCONFIG="$RDIR/arch/arm/configs/mxconfig"
MXNEWCFG="$MXCONFIG.new"
DTCDIR="$BUILDIR/scripts/dtc"
DTIMG="$KDIR/dt.img"
MXDT="$MXRD/split_img/boot.img-dt"
NEWZMG="$KDIR/zImage"
FZMG="$NEWZMG-fixup"
MXZMG="$MXRD/split_img/boot.img-kernel"
DTBTOOL="$RDIR/tools/dtbTool"
MKBOOTIMG="/usr/bin/mkbootimg"
OLDCFG="/home/rob/mn3-oldconfigs"
QUICKHOUR="$(date +%l | cut -d " " -f2)"
QUICKMIN="$(date +%S)"
QUICKAMPM="$(date +%p)"
QUICKDMY="$(date +%d-%m-%Y)"
QUICKYMD="$(date +%Y-%m-%d)"
QUICKTIME="$QUICKHOUR_$QUICKMIN-${QUICKAMPM}"
QUICKDATE="$QUICKYMD-$QUICKTIME"
#CORECOUNT="$(grep processor /proc/cpuinfo | wc -l)"
#TOOLCHAIN="/home/rob/mx_toolchains/arm-cortex_a15-linux-gnueabihf_5.3/bin/arm-cortex_a15-linux-gnueabihf-"
#TOOLCHAIN="/home/rob/mx_toolchains/gcc-linaro-7.5.0-2019.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-"
#TOOLCHAIN="/home/rob/mx_toolchains/arm-cortex_a15-linux-gnueabihf-linaro_4.9.4-2015.06/bin/arm-cortex_a15-linux-gnueabihf-"
#TOOLCHAIN="/home/rob/mx_toolchains/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-"
#TOOLCHAIN="/home/rob/mx_toolchains/gcc-linaro-6.5.0-2018.12-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-"
#TOOLCHAIN="/home/rob/mx_toolchains/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf-"
#TOOLCHAIN="/home/rob/mx_toolchains/gcc-arm-8.2-2019.01-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf-"
TOOLCHAIN="/home/rob/mx_toolchains/arm-cortex_a15-linux-gnueabihf-linaro_4.9.4-2015.06/bin/arm-cortex_a15-linux-gnueabihf-"
export ARCH="arm"
export SUBARCH="arm"
export CROSS_COMPILE="$TOOLCHAIN"
if [ "$2" = "noreboot" ] || [ "$1" = "-anr" ] || [ "$1" = "--allnoreboot" ]
then
NOREBOOT="true"
echo "Script will not reboot after recovery install!"
else
NOREBOOT="false"
fi
if [ "$1" = "-d" ] || [ "$1" = "--debug" ]
then
CLEANONFAIL="no"
else
CLEANONFAIL="yes"
fi
if [ ! -d "$RDIR/buildlogs" ]
then
mkdir "$RDIR/buildlogs"
fi
if [ ! -d "$OLDCFG" ]
then
mkdir -p "$OLDCFG"
fi
stop_build_timer() {
echo "Stopping MXBuild Timer."
[ -f "$ENDFILE" ] && rm "$ENDFILE"
printf "%s" "$(date +%s)" > "$ENDFILE"
}
start_build_timer() {
echo "Starting MXBuild Timer."
[ -f "$STARTFILE" ] && rm "$STARTFILE"
printf "%s" "$(date +%s)" > "$STARTFILE"
}
timerprint() {
local DIFFMINS
local DIFFSECS
local ENDTIME
local STARTTIME
local DIFFTIME
if [ ! -f "$ENDFILE" ]
then
echo "Looks like you forgot to start the timer. I will do it for you."
start_build_timer
fi
ENDTIME="$(cat $ENDFILE)"
STARTTIME="$(cat $STARTFILE)"
DIFFTIME=$(( ENDTIME - STARTTIME ))
if [ -z "$DIFFTIME" ]
then
printf "%s\n" "MXBUILD Completed!"
else
DIFFMINS=$(bc <<< "(${DIFFTIME}%3600)/60")
DIFFSECS=$(bc <<< "${DIFFTIME}%60")
printf "%s" "Build completed in: "
printf "%d" "$DIFFMINS"
if [ "$DIFFMINS" = "1" ]
then
printf "%s" " Minute and "
else
printf "%s" " Minutes and "
fi
printf "%d" "$DIFFSECS"
if [ "$DIFFSECS" = "1" ]
then
printf "%s\n" " Second."
else
printf "%s\n" " Seconds."
fi
rm $STARTFILE &> /dev/null
rm $ENDFILE &> /dev/null
printf "%s\n" "MXBUILD is Finished!"
fi
}
takeouttrash() {
rm "$RDIR/localversion" &> /dev/null
rm "$STARTFILE" &> /dev/null
rm "$ENDFILE" &> /dev/null
rm "$RDIR/mxtempusb" &> /dev/null
find . -type f \( -iname \*.rej \
-o -iname \*.orig \
-o -iname \*.bkp \
-o -iname \*.ko \) \
| parallel rm -fv {};
}
getmxrecent() {
local NEEDCOMMIT;
if [ -f "$BUILDIR/.config" ]
then
cp "$BUILDIR/.config" "$MXNEWCFG"
diff "$MXCONFIG" "$MXNEWCFG"
if [ "$?" -eq "1" ]
then
NEEDCOMMIT="true"
fi
[ -f "$MXCONFIG" ] && rm "$MXCONFIG"
mv "$MXNEWCFG" "$MXCONFIG"
if [ "$NEEDCOMMIT" = "true" ]
then
git add "$MXCONFIG"
git commit -a -m 'mxconfig updated from build'
fi
fi
}
clean_build() {
cd "$RDIR" || warnandfailearly "Failed to cd to $RDIR!"
getmxrecent
if [ "$1" = "standalone" ]
then
echo -ne "Cleaning build \r"; \
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -j16 clean
echo -ne "Cleaning build. \r"; \
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -j16 distclean
echo -ne "Cleaning build.. \r"; \
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -j16 mrproper
else
echo -ne "Cleaning build \r"; \
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -j16 clean &>/dev/null
echo -ne "Cleaning build. \r"; \
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -j16 distclean &>/dev/null
echo -ne "Cleaning build.. \r"; \
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -j16 mrproper &>/dev/null
fi
echo -ne "Cleaning build... \r"; \
takeouttrash &>/dev/null
echo -ne "Cleaning build.... \r"; \
rm -rf "$BUILDIR" &>/dev/null
echo -ne "Cleaning build..... \r"; \
rm "$ZIPFOLDER/boot.img" &>/dev/null
echo -ne "Cleaning build...... \r"; \
# [ -f "$MXRD/image-new.img" ] && rm "$MXRD/image-new.img"
[ -f "$KDIR/ramdisk.cpio.gz" ] && rm "$KDIR/ramdisk.cpio.gz"
echo -ne "Cleaning build....... \r"; \
# rm -rf "$RDIR/scripts/mkqcdtbootimg/mkqcdtbootimg" &>/dev/null
echo -ne "Cleaning build........ \r"; \
echo -ne " \r"; \
echo -ne "Cleaned \r"; \
echo -e "\n"
}
warnandfail() {
echo -n "MX ERROR on Line ${BASH_LINENO[0]}"
echo "!!!"
local ISTRING
ISTRING="$1"
if [ -n "$ISTRING" ]
then
printf "%s\n" "$ISTRING"
fi
if [ "$CLEANONFAIL" = "yes" ]
then
clean_build
fi
exit 1
}
_quote() {
echo $1 | sed 's/[]\/()$*.^|[]/\\&/g'
}
# This function looks for a string, and inserts a specified string after it inside a given file
# $1: the line to locate, $2: the line to insert, $3: Config file where to insert
pc_insert() {
local PATTERN;
local CONTENT;
PATTERN=$(_quote "$1")
CONTENT=$(_quote "$2")
sed -i "/$PATTERN/a$CONTENT" $3
}
# This function looks for a string, and replace it with a different string inside a given file
# $1: the line to locate, $2: the line to replace with, $3: Config file where to insert
pc_replace() {
local PATTERN;
local CONTENT;
PATTERN=$(_quote "$1")
CONTENT=$(_quote "$2")
sed -i "s/$PATTERN/$CONTENT/" $3
}
# This function will append a given string at the end of a given file
# $1 The line to append at the end, $2: Config file where to append
pc_append() {
echo "$1" >> $2
}
# This function will delete a line containing a given string inside a given file
# $1 The line to locate, $2: Config file where to delete
pc_delete() {
local PATTERN;
PATTERN=$(_quote "$1")
sed -i "/$PATTERN/d" $2
}
if [ "$1" != "-nc" ] && [ "$1" != "--newconfig" ]
then
if [ ! -f "$MXCONFIG" ]
then
warnandfail "$MXCONFIG not found in arm configs!"
fi
fi
if [ ! -d "$RAMDISKFOLDER" ]
then
warnandfail "$RAMDISKFOLDER not found!"
fi
shortprog() {
printf "%s\r" "-----------------------------------"; \
sleep 0.4; \
printf "%s\r" "----------------- -----------------"; \
sleep 0.4; \
printf "%s\r" "--------------- ---------------"; \
sleep 0.4; \
printf "%s\r" "---------- ----------"; \
sleep 0.4; \
printf "%s\r" "------- -------"; \
sleep 0.4; \
printf "%s\r" "----- -----"; \
sleep 0.4; \
printf "%s\r" "--- ---"; \
sleep 0.4; \
printf "%s\r" "- -"; \
sleep 0.4; \
printf "%s\r" "--- ---"; \
sleep 0.4; \
printf "%s\r" "----- -----"; \
sleep 0.4; \
printf "%s\r" "------- -------"; \
sleep 0.4; \
printf "%s\r" "---------- ----------"; \
sleep 0.4; \
printf "%s\r" "--------------- ---------------"; \
sleep 0.4; \
printf "%s\r" "----------------- -----------------"; \
sleep 0.4; \
printf "%s\r" "-----------------------------------"; \
sleep 0.4; \
printf "%s\r" " "; \
printf "%s\n"
#echo -ne "\n"
}
test_funcs() {
echo "This is a test of the emergency broadcast system."
echo "This is only a test."
shortprog
echo "This has been a test of the emergency broadcast system."
echo "This was only a test"
}
checkrecov() {
lsusb > "$RDIR/mxtempusb"
if grep -q '04e8:6860' mxtempusb;
then
echo "Ensuring System is ready for operations"
adb "wait-for-device";
echo "System is Ready"
echo -n "Reboot into Recovery? [y|n]: "
read -r RECREBOOT
if [ "$RECREBOOT" = "y" ]
then
echo "Rebooting into TWRP Recovery"
adb shell sync
adb reboot recovery
fi
fi
rm $RDIR/mxtempusb &> /dev/null
}
handle_existing() {
if [ -z "$OLDVER" ]
then
warnandfail "FATAL ERROR! Failed to read version from .oldversion"
fi
if [ ! -f "$RDIR/machinexlite-Mark$OLDVER-hltetmo.zip" ]
then
echo "Version Override!"
echo "Previous version was not completed!"
echo "Rebuilding old version"
MX_KERNEL_VERSION="machinexlite-Mark$OLDVER-hltetmo"
elif [ "$LASTZIP" = "machinexlite-Mark$OLDVER-hltetmo.zip" ]
then
echo "Version Override"
echo "Previous version completed successfully!"
echo "Building new version!"
NEWVER="$(echo $(( OLDVER + 1 )))"
if [ -z "$NEWVER" ]
then
warnandfail "FATAL ERROR! Failed to raise version number by one!"
fi
MX_KERNEL_VERSION="machinexlite-Mark$NEWVER-hltetmo"
echo -n "$NEWVER" > "$OLDVERFILE"
else
echo -n "Rebuilding (o)ld version? Or building (n)ew version? Please specify [o|n]: "
read -r WHICHVERSION
if [ "$WHICHVERSION" = "n" ]
then
CURVER="new"
elif [ "$WHICHVERSION" = "o" ]
then
CURVER="old"
else
CURVER="invalid"
fi
if [ -z "$CURVER" ]
then
warnandfail "You MUST choose a version for the kernel"
elif [ "$CURVER" = "invalid" ]
then
warnandfail "versioning failed. please fix"
elif [ "$CURVER" = "old" ]
then
echo "Rebulding old version has been selected"
echo "Removing old zip files..."
MX_KERNEL_VERSION="machinexlite-Mark$OLDVER-hltetmo"
rm -f "$RDIR/$MX_KERNEL_VERSION.zip"
elif [ "$CURVER" = "new" ]
then
echo "Building new version has been selected"
NEWVER="$(echo $(( OLDVER + 1 )))"
if [ -z "$NEWVER" ]
then
warnandfail "FATAL ERROR! Failed to raise version number by one!"
fi
MX_KERNEL_VERSION="machinexlite-Mark$NEWVER-hltetmo"
echo -n "$NEWVER" > "$OLDVERFILE"
fi
fi
echo "Kernel version is: $MX_KERNEL_VERSION"
echo "--------------------------------"
echo "$MX_KERNEL_VERSION" > "$RDIR/localversion"
}
rebuild() {
echo "Using last version. Mark$OLDVER will be removed."
MX_KERNEL_VERSION="machinexlite-Mark$OLDVER-hltetmo"
rm "$RDIR/localversion" &> /dev/null
echo "$MX_KERNEL_VERSION" > "$RDIR/localversion"
echo "Removing old zip files..."
rm -f "$RDIR/$MX_KERNEL_VERSION.zip"
echo "Kernel version is: $MX_KERNEL_VERSION"
echo "--------------------------------"
}
build_new_config() {
echo "Creating kernel config..."
cd "$RDIR" || warnandfail "Failed to cd to $RDIR!"
mkdir -p "$BUILDIR" || warnandfail "Failed to make $BUILDIR directory!"
cat "$RDIR/arch/arm/configs/msm8974_sec_hlte_tmo_defconfig" "$RDIR/arch/arm/configs/msm8974_sec_defconfig" "$RDIR/arch/arm/configs/selinux_defconfig" > "$RDIR/arch/arm/configs/mxconfig"
cp "$MXCONFIG" "$BUILDIR/.config" || warnandfail "Config Copy Error!"
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -C "$RDIR" O="$BUILDIR" menuconfig
}
build_menuconfig() {
echo "Creating kernel config..."
cd "$RDIR" || warnandfail "Failed to cd to $RDIR!"
mkdir -p "$BUILDIR" || warnandfail "Failed to make $BUILDIR directory!"
cp "$MXCONFIG" "$BUILDIR/.config" || warnandfail "Config Copy Error!"
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -C "$RDIR" O="$BUILDIR" menuconfig
}
build_single_config() {
echo "Creating kernel config..."
cd "$RDIR" || warnandfail "Failed to cd to $RDIR!"
mkdir -p "$BUILDIR" || warnandfail "Failed to make $BUILDIR directory!"
cp "$MXCONFIG" "$BUILDIR/.config" || warnandfail "Config Copy Error!"
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -C "$RDIR" O="$BUILDIR" oldconfig || warnandfail "make oldconfig Failed!"
}
build_kernel_config() {
echo "Creating kernel config..."
cd "$RDIR" || warnandfail "Failed to cd to $RDIR!"
mkdir -p "$BUILDIR" || warnandfail "Failed to make $BUILDIR directory!"
cp "$MXCONFIG" "$BUILDIR/.config" || warnandfail "Config Copy Error!"
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -C "$RDIR" O="$BUILDIR" oldconfig || warnandfail "make oldconfig Failed!"
getmxrecent
}
build_single_driver() {
echo "Building Single Driver..."
make -Wa ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -C "$RDIR" -S -s -j16 O="$BUILDIR" "$1"
}
build_kernel() {
echo "Backing up .config to $OLDCFG/config.$QUICKDATE"
cp "$BUILDIR/.config" "$OLDCFG/config.$QUICKDATE" || warnandfail "Config Copy Error!"
#echo "Snapshot of current environment variables:"
#env
start_build_timer
echo "Starting build..."
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -S -s -j16 -C "$RDIR" O="$BUILDIR" 2>&1 | tee -a "$LOGDIR/$QUICKDATE.Mark$(cat $RDIR/.oldversion).log" \
|| warnandfail "Kernel Build failed!"
}
build_kernel_debug() {
echo "Backing up .config to $OLDCFG/config.$QUICKDATE"
cp "$BUILDIR/.config" "$OLDCFG/config.$QUICKDATE" || warnandfail "Config Copy Error!"
#echo "Snapshot of current environment variables:"
#env
start_build_timer
echo "Starting build..."
make ARCH="arm" SUBARCH="arm" CROSS_COMPILE="$TOOLCHAIN" -S -s -j16 -C "$RDIR" O="$BUILDIR" 2>&1 | tee -a "$LOGDIR/$QUICKDATE.Mark$(cat $RDIR/.oldversion).log" \
|| warnandfail "Kernel Build failed!"
stop_build_timer
timerprint
}
build_ramdisk() {
echo "Building ramdisk structure..."
cd "$RDIR" || warnandfail "Failed to cd to $RDIR"
rm -rf "$BUILDIR/ramdisk" &>/dev/null
cp -par "$RAMDISKFOLDER" "$BUILDIR/ramdisk" || warnandfail "Failed to create $BUILDIR/ramdisk!"
cd "$BUILDIR/ramdisk" || warnandfail "Failed to cd to $BUILDIR/ramdisk!"
mkdir -pm 755 dev proc sys system
mkdir -pm 771 data
if [ -f "$KDIR/ramdisk.cpio.gz" ]
then
rm "$KDIR/ramdisk.cpio.gz"
fi
# find | fakeroot cpio -v -H newc -o | lzop -9 > "$KDIR/ramdisk.cpio.gz"
echo "Building ramdisk img"
find | fakeroot cpio -v -o -H newc | gzip -v -9 > "$KDIR/ramdisk.cpio.gz"
[ ! -f "$KDIR/ramdisk.cpio.gz" ] && warnandfail "NO ramdisk!"
cd "$RDIR" || warnandfail "Failed to cd to $RDIR"
}
build_boot_img() {
echo "Generating boot.img..."
[ -f "$ZIPFOLDER/boot.img" ] && rm -f "$ZIPFOLDER/boot.img"
$RDIR/tools/dtbTool -s 2048 -o "$DTIMG" -p "$DTCDIR" "$KDIR" 2>&1 | \
tee -a "$LOGDIR/$QUICKDATE.Mark$(cat $RDIR/.oldversion).log" || warnandfail "dtbTool failed to build $DTIMG!"
$RDIR/tools/mkbootimg --kernel "$NEWZMG" \
--dt "$DTIMG" \
--ramdisk "$KDIR/ramdisk.cpio.gz" \
--cmdline "console=null androidboot.hardware=qcom user_debug=23 msm_rtb.filter=0x37 ehci-hcd.park=3 enforcing=0" \
--base "0x00000000" \
--pagesize "2048" \
--kernel_offset "0x00008000" \
--ramdisk_offset "0x02000000" \
--tags_offset "0x01e00000" \
--second_offset "0x00f00000" \
--output "$ZIPFOLDER/boot.img" 2>&1 | tee -a "$LOGDIR/$QUICKDATE.Mark$(cat $RDIR/.oldversion).log" \
|| warnandfail "mkbootimg failed to build boot.img!"
[ -f "$ZIPFOLDER/boot.img" ] || warnandfail "$ZIPFOLDER/boot.img does not exist!"
echo -n "SEANDROIDENFORCE" >> "$ZIPFOLDER/boot.img"
}
ADBPUSHLOCATION="/sdcard/Download"
MAGISKFILE="Magisk-v23.0.zip"
create_zip() {
echo "Compressing to TWRP flashable zip file..."
cd "$ZIPFOLDER" || warnandfail "Failed to cd to $ZIPFOLDER"
#[ -d "$ZIPFOLDER/system/lib/modules" ] && rm -rf "$ZIPFOLDER/system/lib/modules"
#for MXMODS in $(find "$BUILDIR/" -iname '*.ko')
#do
# if [ -f "$MXMODS" ]
# then
# echo "Copying $MXMODS to zip"
# cp -pa "$MXMODS" "$ZIPFOLDER/system/lib/modules/" || warnandfail "Failed to copy new modules to zip!"
# fi
#done
zip -r -9 - * > "$RDIR/$MX_KERNEL_VERSION.zip"
if [ ! -f "$RDIR/$MX_KERNEL_VERSION.zip" ]
then
warnandfail "$RDIR/$MX_KERNEL_VERSION.zip does not exist!"
fi
echo "Kernel $MX_KERNEL_VERSION.zip finished"
echo "Filepath: "
echo "$RDIR/$MX_KERNEL_VERSION.zip"
stop_build_timer
if [ -s "$RDIR/$MX_KERNEL_VERSION.zip" ]
then
echo -n "$MX_KERNEL_VERSION.zip" > "$RDIR/.lastzip"
echo "Starting ADB as root."
adb root
echo "Checking if Device is Connected..."
local SAMSTRING
SAMSTRING="$(lsusb | grep '04e8:6860')"
RECOVSTRING="$(lsusb | grep '18d1:4ee2')"
if [ -n "$SAMSTRING" ]
then
echo "Device is Connected via Usb in System Mode!"
echo "$SAMSTRING"
echo "Ensuring System is ready for operations"
adb "wait-for-device";
echo "System is Ready"
adb shell input keyevent KEYCODE_WAKEUP
#adb shell input touchscreen swipe 930 880 930 380
echo "Transferring via adb to $ADBPUSHLOCATION/$MX_KERNEL_VERSION.zip"
adb push "$RDIR/$MX_KERNEL_VERSION.zip" "$ADBPUSHLOCATION"
if [ "$?" -eq "0" ]
then
echo "Successfully pushed $RDIR/$MX_KERNEL_VERSION.zip to $ADBPUSHLOCATION over ADB!"
#echo "Rebooting Device into Recovery"
#adb reboot recovery
else
echo "Failed to push $RDIR/$MX_KERNEL_VERSION.zip to $ADBPUSHLOCATION over ADB!"
fi
elif [ -n "$RECOVSTRING" ]
then
echo "Device is Connected via Usb in Recovery Mode!"
echo "$RECOVSTRING"
#adb shell input keyevent KEYCODE_WAKEUP
#adb shell input touchscreen swipe 930 880 930 380
echo "Ensuring Recovery is ready for operations"
adb "wait-for-recovery";
echo "Recovery is Ready"
echo "Transferring installer via adb to $ADBPUSHLOCATION/$MX_KERNEL_VERSION.zip"
adb push "$RDIR/$MX_KERNEL_VERSION.zip" "$ADBPUSHLOCATION"
if [ "$?" -eq "0" ]
then
echo "Successfully pushed $RDIR/$MX_KERNEL_VERSION.zip to $ADBPUSHLOCATION/$MX_KERNEL_VERSION.zip over ADB!"
echo "Installing $ADBPUSHLOCATION/$MX_KERNEL_VERSION.zip via open recovery script"
adb shell twrp install "$ADBPUSHLOCATION/$MX_KERNEL_VERSION.zip"
echo "Pushing Magisk to $ADBPUSHLOCATION/$MAGISKFILE"
adb push "$RDIR/$MAGISKFILE" "$ADBPUSHLOCATION"
echo "Installing $ADBPUSHLOCATION/$MAGISKFILE via open recovery script"
adb shell twrp install "$ADBPUSHLOCATION/$MAGISKFILE"
echo "Removing leftovers"
adb shell rm "/data/dalvik-cache/arm/dev@tmp@install@common@magisk.apk@classes.dex" &> /dev/null
adb shell rm "/data/dalvik-cache/arm/data@app@com.topjohnwu.magisk-1@base.apk@classes.dex" &> /dev/null
adb shell rm "/data/dalvik-cache/profiles/com.topjohnwu.magisk" &> /dev/null
if [ "$NOREBOOT" = "false" ]
then
echo "Rebooting Device"
adb shell sync
adb reboot
else
echo "Skipping Reboot due to command line option!"
fi
else
echo "FAILED to push $RDIR/$MX_KERNEL_VERSION.zip to $ADBPUSHLOCATION/$MX_KERNEL_VERSION.zip over ADB!"
fi
else
echo "Device not Connected. Skipping adb transfer."
#echo "Uploading $MX_KERNEL_VERSION.zip to Google Drive Instead."
#/bin/bash /home/rob/google-drive-upload/upload.sh "$RDIR/$MX_KERNEL_VERSION.zip"
#if [ "$?" -eq "0" ]
#then
# echo "$RDIR/$MX_KERNEL_VERSION.zip upload SUCCESS!"
#else
# echo "$RDIR/$MX_KERNEL_VERSION.zip upload FAILED!"
#fi
fi
else
warnandfail "$RDIR/$MX_KERNEL_VERSION.zip is 0 bytes, something is wrong!"
fi
adb kill-server || echo "Failed to kill ADB server!"
cd "$RDIR" || warnandfail "Failed to cd to $RDIR"
timerprint
}
#CREATE_TAR()
#{
# if [ $MAKE_TAR != 1 ]; then return; fi-d|--debug
#
# echo "Compressing to Odin flashable tar.md5 file..."
# cd $RDIR/$ZIPFOLDER
# tar -H ustar -c boot.img > $RDIR/$MX_KERNEL_VERSION.tar
# cd $RDIR
# md5sum -t $MX_KERNEL_VERSION.tar >> $MX_KERNEL_VERSION.tar
# mv $MX_KERNEL_VERSION.tar $MX_KERNEL_VERSION.tar.md5
# cd $RDIR
#}
show_help() {
cat << EOF
Machinexlite kernel by robcore
Script written by jcadduono, frequentc & robcore
usage: ./mxbuild.sh [OPTION]
Common options:
-a|--all Do a complete build (starting at the beginning)
-anr|--allnoreboot Do a complete build (starting at the beginning), do not reboot
-d|--debug Similiar to --all but no img, zip or cleanup. Not for production.
-r|--rebuildme Same as --all but defaults to rebuilding previous version
-b|--bsd Build single driver (path/to/folder/ | path/to/file.o)
-c|--clean Remove everything this build script has done
-nc|--newconfig Concatecate samsung defconfigs & enter menuconfig
-m|--menuconfig Setup an environment for and enter menuconfig
-k|--kernel Try the build again starting at compiling the kernel
-o|--kernel-only Recompile only the kernel, nothing else
-rd|--ramdisk Try the build again starting at the ramdisk
-t|--tests Testing playground
Extra command line options are possible, with more to be added in the future:
Currently, it is just the one.
Appending "noreboot" as the second option will keep the device from rebooting.
Or, just use the -anr option that is the same as -a to build all,
but skips the reboot.
EOF
exit 1
}
#package_ramdisk_and_zip() {
#
# build_ramdisk && build_boot_img && create_zip
#
#}
package_ramdisk_and_zip() {
build_ramdisk && build_boot_img && create_zip
}
build_kernel_and_package() {
build_kernel && package_ramdisk_and_zip
}
build_all() {
clean_build && build_kernel_config && build_kernel_and_package && clean_build
}
build_debug() {
clean_build && build_kernel_config && build_kernel_debug
}
bsdwrapper() {
[ -z "$1" ] && warnandfail "Build Single Driver: Missing path/to/folder/ or path/to/file.o"
clean_build && build_single_config && build_single_driver "$1"
clean_build
}
runtest() {
test_funcs && exit 0
}
if [ $# = 0 ] ; then
show_help
fi
while [[ $# -gt 0 ]]
do
extrargs="$2"
case "$1" in
-a|--all)
checkrecov
handle_existing
build_all
break
;;
-anr|--allnoreboot)
checkrecov
handle_existing
build_all
break
;;
-d|--debug)
handle_existing
build_debug
break
;;
-r|--rebuildme)
checkrecov
handle_existing
rebuild
build_all
break
;;
-b|--bsd)
handle_existing
bsdwrapper "$extrargs"
break
;;
-c|--clean)
clean_build "standalone"
break
;;
-nc|--newconfig)
handle_existing
build_new_config
break
;;
-m|--menuconfig)
handle_existing
build_menuconfig
break
;;
-k|--kernel)
checkrecov
handle_existing
build_kernel_and_package
break
;;
-o|--kernel-only)
checkrecov
handle_existing
build_kernel
break
;;
-rd|--ramdisk)
handle_existing
package_ramdisk_and_zip
break
;;
-t|--tests)
runtest
break
;;
*)
show_help
break;
;;
esac
shift # past argument or value
done