-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgadebli
More file actions
1022 lines (915 loc) · 43.2 KB
/
gadebli
File metadata and controls
1022 lines (915 loc) · 43.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
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
#!/bin/bash
if [ "$1" == "-h" ]||[ "$1" == "--help" ]||[ "$1" == "help" ] ; then echo '
########################################################################
# Script to gen armhf debian based linux image for xe303c12 #
# Dev. https://git[hu,la]b.com/quarkscript License GPL #
# Place kernel source file, united patch, config and execute #
# sudo '$0' [ck,bts,bdi] [kali] ["size"] ["patch"] [btrfs,f2fs] #
# ck - compile kernel stage #
# bts - build target system stage #
# bdi - build disk image stage, depends of all previous stages #
# [kali,devuan,devuan-lxqt] - supported distributions #
# size - disk image size, 2-128 (G) or 1882-131092 (M); 7G by default #
# patch - united kernel patch #
# btrfs,f2fs - root part filesystem type, otherwise ext4 will be used #
# Sequence is not important. All params are optional. #
# This script could work on debian based i686 or x86_64 sytems #
# It is better to not mix distro types i.e. gen Kali at x86 Kali.. #
# Deps will be installed automatically, root privileges are required. #
########################################################################
'
exit 0
fi
## def vars
fstype=ext4
disksize=$((7*1024))
patch=''
stages=''
hostpackages='git-core gnupg flex bison gperf build-essential zip curl libncurses5-dev zlib1g-dev gcc g++ parted kpartx debootstrap pixz qemu-user-static abootimg cgpt vboot-kernel-utils vboot-utils u-boot-tools bc lzma lzop automake autoconf m4 dosfstools rsync schedtool git dosfstools e2fsprogs device-tree-compiler libssl-dev qemu-user-static btrfs-progs f2fs-tools binutils binutils-arm-linux-gnueabihf gcc-arm-linux-gnueabihf'
hostpackages_32bit='libstdc++6:i386 libgcc1:i386 zlib1g:i386 libncurses5:i386'
target_hostname=kali
basedir="$(pwd)/$target_hostname-exynos"
mirror=http.kali.org
architecture="armhf"
debootstrap_string="debootstrap --foreign --arch $architecture kali-rolling $target_hostname-$architecture http://$mirror/$target_hostname"
sources_list="deb http://$mirror/$target_hostname kali-rolling main contrib non-free"
targetpackages_2="git-core ca-certificates initramfs-tools"
targetpackages_3="locales console-common less nano git"
targetpackages='adduser alsa-utils alsamixergui apt-transport-https apt-utils apt aptitude base-files base-passwd bash-completion bash binutils bluez bsdutils btrfs-progs ca-certificates cgpt conky console-common console-setup coreutils cpio crda cron curl dash debconf-i18n debconf debian-archive-keyring debianutils dialog diffutils dmidecode dmsetup dpkg e2fsprogs f2fs-tools fdisk findutils firefox-esr git gparted gpgv grep gzip hostname ifupdown init-system-helpers init initramfs-tools iproute2 iputils-ping isc-dhcp-client isc-dhcp-common iw kali-archive-keyring kali-root-login kmod less libacl1 libapparmor1 libapt-pkg6.0 libargon2-1 libattr1 libaudit-common libaudit1 libblkid1 libbpf0 libbsd0 libbz2-1.0 libc-bin libc6 libcap-ng0 libcap2-bin libcap2 libcom-err2 libcrypt1 libcryptsetup12 libdb5.3 libdebconfclient0 libdevmapper1.02.1 libdns-export1110 libedit2 libelf1 libestr0 libext2fs2 libfastjson4 libfdisk1 libffi7 libgcc-s1 libgcrypt20 libgmp10 libgnutls30 libgpg-error0 libgssapi-krb5-2 libhogweed6 libidn2-0 libip4tc2 libisc-export1105 libjansson4 libjson-c5 libk5crypto3 libkeyutils1 libkmod2 libkrb5-3 libkrb5support0 liblocale-gettext-perl liblognorm5 liblz4-1 liblzma5 libmd0 libmnl0 libmount1 libncurses6 libncursesw6 libnettle8 libnewt0.52 libnftables1 libnftnl11 libnsl2 libnss-systemd libp11-kit0 libpam-modules-bin libpam-modules libpam-runtime libpam0g libpcre2-8-0 libpcre3 libpopt0 libprocps8 libreadline8 libseccomp2 libselinux1 libsemanage-common libsemanage1 libsepol1 libslang2 libsmartcols1 libss2 libssl-dev libssl1.1 libstdc++6 libsystemd0 libtasn1-6 libtext-charwidth-perl libtext-iconv-perl libtext-wrapi18n-perl libtinfo6 libtirpc-common libtirpc3 libudev1 libunistring2 libuuid1 libxfce4ui-utils libxtables12 libxxhash0 libzstd1 linux-cpupower locales-all locales login logrotate logsave lsb-base man-db mawk mc mount nano ncurses-base ncurses-bin net-tools netbase network-manager-gnome network-manager nftables ntpdate parole passwd perl-base procps readline-common rfkill rsyslog sed sensible-utils shiki-colors-xfwm-theme systemd-sysv systemd-timesyncd systemd sysvinit-utils tar tmux tumbler-plugins-extra tzdata u-boot-tools udev usbutils util-linux vboot-utils vim-common vim-tiny wget whiptail wpasupplicant xfce4-appmenu-plugin xfce4-battery-plugin xfce4-clipman-plugin xfce4-clipman xfce4-cpufreq-plugin xfce4-cpugraph-plugin xfce4-datetime-plugin xfce4-dict xfce4-diskperf-plugin xfce4-fsguard-plugin xfce4-genmon-plugin xfce4-goodies xfce4-indicator-plugin xfce4-mount-plugin xfce4 xfonts-terminus xinput xserver-xorg-input-libinput xserver-xorg-input-synaptics xserver-xorg-video-fbdev xxd zlib1g nodm'
depends="cgpt"
suggests='vboot-kernel-utils,vboot-utils'
replaces="linux-image-armmp,linux-image-armmp-lpae,linux-headers-armmp,linux-headers-armmp-lpae"
provides="linux-image-generic,linux-headers-generic"
sourcelist='deb http://http.kali.org/kali kali-rolling main contrib non-free
deb-src http://http.kali.org/kali kali-rolling main contrib non-free'
firmware_dir="/usr/lib/firmware"
#nir="--no-install-recommends"
nir=''
## checks
if [ $(whoami) != root ];then echo ''; echo root rights are required, try to run with sudo; echo ''; exit 1; fi
for ((tmpvar=1;tmpvar<=$#;tmpvar++)); do
tmpvalue=$(eval 'echo ${'$tmpvar'}')
if [ $tmpvalue == ck ]||[ $tmpvalue == bts ]||[ $tmpvalue == bdi ];then
stages="$stages $tmpvalue"
elif [ $tmpvalue == kali ];then
echo '"'Kali defauilts'"' will be used
elif [ $tmpvalue == devuan ]||[ $tmpvalue == devuan-lxqt ];then
mirror=deb.devuan.org
sourcelist='deb http://deb.devuan.org/merged chimaera main non-free contrib
deb http://deb.devuan.org/merged chimaera-updates main non-free contrib
deb http://deb.devuan.org/merged chimaera-security main non-free contrib'
target_hostname=devuan
sources_list="$sourcelist"
debootstrap_string="debootstrap --foreign --arch $architecture chimaera $target_hostname-$architecture http://deb.devuan.org/merged"
basedir="$(pwd)/$target_hostname-exynos"
if [ $tmpvalue == devuan-lxqt ];then
targetpackages='adduser alsa-utils apt-transport-https apt-utils apt aptitude base-files base-passwd bash-completion bash bc binutils bison bluez bootlogd bsdutils btrfs-progs ca-certificates conky-std console-common console-setup coreutils cpio crda cron cryptsetup curl dash debconf-i18n debconf debian-archive-keyring debianutils devuan-keyring dialog diffutils dmidecode dpkg e2fsprogs ecryptfs-utils f2fs-tools fdisk ffmpeg findutils fonts-dejavu gcc-10-base gcc-9-base git gnupg2 gpgv grep gzip hostname ifupdown init-system-helpers init initramfs-tools initscripts insserv iproute2 iputils-ping isc-dhcp-client isc-dhcp-common iw kmod less libacl1 libapt-pkg6.0 libattr1 libaudit-common libaudit1 libblkid1 libbpf0 libbsd0 libbz2-1.0 libc-bin libc6 libcap-ng0 libcap2-bin libcap2 libcom-err2 libcrypt1 libdb5.3 libdebconfclient0 libdns-export1110 libedit2 libelf1 libestr0 libeudev1 libext2fs2 libfastjson4 libfdisk1 libffi7 libgcc-s1 libgcrypt20 libgmp10 libgnutls30 libgpg-error0 libgssapi-krb5-2 libhogweed6 libidn2-0 libisc-export1105 libjansson4 libk5crypto3 libkeyutils1 libkmod2 libkrb5-3 libkrb5support0 liblocale-gettext-perl liblognorm5 liblz4-1 liblzma5 libmd0 libmnl0 libmount1 libncurses6 libncursesw6 libnettle8 libnewt0.52 libnftables1 libnftnl11 libnsl2 libp11-kit0 libpam-modules-bin libpam-modules libpam-runtime libpam0g libpcre2-8-0 libpcre3 libpopt0 libprocps8 libreadline8 libseccomp2 libselinux1 libsemanage-common libsemanage1 libsepol1 libslang2 libsmartcols1 libss2 libssl-dev libssl1.1 libstdc++6 libtasn1-6 libtext-charwidth-perl libtext-iconv-perl libtext-wrapi18n-perl libtinfo6 libtirpc-common libtirpc3 libunistring2 libuuid1 libxfce4ui-2-0 libxtables12 libxxhash0 libzstd1 linux-kernel-xe303c12 locales-all locales login logrotate logsave lsb-base lxqt-admin lxqt-archiver lxqt-globalkeys lxqt-openssh-askpass lxqt-panel lxqt-themes man-db mawk mc mlocate mount nano ncurses-base ncurses-bin net-tools netbase netcat-traditional network-manager nftables nm-tray ntpdate openbox parted passwd perl-base procps psmisc readline-common rfkill rsyslog sed sensible-utils startpar sysv-rc sysvinit-core sysvinit-utils sysvinit tar tzdata u-boot-tools unrar usbutils util-linux vim-common vim-tiny wget whiptail wpasupplicant xfonts-100dpi xfonts-75dpi xfonts-scalable xfwm4 xinit xinput xkbset xserver-xorg-input-evdev xserver-xorg-input-kbd xserver-xorg-input-mouse xserver-xorg-input-synaptics xxd zerofree zlib1g nodm'
nir=''
else
targetpackages='adduser alsa-utils apt-transport-https apt-utils apt aptitude base-files base-passwd bash-completion bash bc binutils bison bluez bootlogd bsdutils btrfs-progs ca-certificates conky console-common console-setup coreutils cpio crda cron cryptsetup cups curl dash debconf-i18n debconf debian-archive-keyring debianutils devuan-keyring dialog diffutils dmidecode dpkg e2fsprogs ecryptfs-utils f2fs-tools fbreader fdisk ffmpeg findutils firefox-esr geany-plugin-addons geany-plugin-codenav geany-plugin-commander geany-plugin-ctags geany-plugin-extrasel geany git gnome-icon-theme-gartoon gnome-icon-theme-yasis gnupg2 gpgv grep gvfs-backends gvfs-fuse gzip hostname ifupdown init-system-helpers init initramfs-tools initscripts insserv iproute2 iputils-ping isc-dhcp-client isc-dhcp-common iw kmod less locales-all locales login logrotate logsave lsb-base man-db mawk mc mlocate mount mousepad nano ncurses-base ncurses-bin net-tools netbase netcat-traditional network-manager-gnome network-manager nftables nodm ntpdate parted passwd perl-base potrace printer-driver-cups-pdf printer-driver-foo2zjs procps psmisc readline-common rfkill ristretto rsyslog sed sensible-utils shiki-colors-xfwm-theme startpar sudo sylpheed-plugins sylpheed sysv-rc-conf sysv-rc sysvinit-core sysvinit-utils sysvinit tar thunar-archive-plugin thunar-media-tags-plugin thunar tzdata u-boot-tools unrar usbutils util-linux vim-common vim-tiny wget whiptail wpasupplicant xfce4-appfinder xfce4-appmenu-plugin xfce4-battery-plugin xfce4-clipman-plugin xfce4-clipman xfce4-datetime-plugin xfce4-fsguard-plugin xfce4-indicator-plugin xfce4-mount-plugin xfce4-netload-plugin xfce4-panel xfce4-power-manager xfce4-screenshooter xfce4-sensors-plugin xfce4-session xfce4-settings xfce4-statusnotifier-plugin xfce4-taskmanager xfce4-terminal xfce4-timer-plugin xfce4-weather-plugin xfce4-whiskermenu-plugin xfce4-xkb-plugin xinput xorg xserver-xorg-input-all xserver-xorg-input-evdev xserver-xorg-input-mouse xserver-xorg-input-synaptics xserver-xorg-legacy xsettingsd xxd youtube-dl zathura-cb zathura-djvu zathura-ps zathura'
nir=''
fi
#targetpackages+=" devuan-keyring"
#targetpackages+=" sysv-rc sysvinit sysvinit-core sysvinit-utils"
#targetpackages+=" runit rinit-helper runit-init"
#targetpackages+=" s6"
firmware_dir="/lib/firmware"
elif [ $tmpvalue == btrfs ]||[ $tmpvalue == f2fs ];then
fstype=$tmpvalue
elif $(echo $tmpvalue | grep -q [0-9])&&$(echo $tmpvalue | grep -vq [a-zA-Z,.]);then
if [ "$tmpvalue" -gt "2" ]&&[ "$tmpvalue" -lt "129" ];then
disksize=$(($tmpvalue*1024+0))
elif [ "$tmpvalue" -ge "1882" ]&&[ "$tmpvalue" -lt "131093" ]; then
disksize=$(($tmpvalue+0))
else
echo ''
echo "$tmpvalue out of range"
echo "Disk image size is allowed at 2-128 (G) or 1882-131092 (M)"
echo "or empty '' means default size (7 G). Root partition offset is 20Mb"
echo "to set a disk image size use only numbers from that intervals"
echo ''
exit 1
fi
if [ $disksize -lt 5119 ]; then echo ''; echo disk size is too small, it could be smaller than your system, be aware; fi
elif $(echo $tmpvalue | grep -q --regexp='.patch' --regexp='.diff') ;then
patch=$tmpvalue
else
echo unknown parameter $tmpvalue
exit 1
fi
done
if [ -z "$stages" ]; then stages='ck bts bdi'; fi
echo "
Some build variables:"
echo "# hostpackages : $hostpackages
# hostpackages (32bit) : $hostpackages_32bit"
if $(echo $stages | grep -q bts); then
echo "# targetpackages : $targetpackages
# debootstrap_string : $debootstrap_string
# sources_list : $sources_list
# targetpackages_2 : $targetpackages_2
# targetpackages_3 : $targetpackages_3
# sourcelist : $sourcelist
# firmware_dir : $firmware_dir
# extra directives : $nir"
fi
echo "# target_hostname : $target_hostname
# basedir : $basedir
# mirror : $mirror
# architecture : $architecture
# stages: : $stages"
if $(echo $stages | grep -q ck); then
echo "# depends : $depends
# suggests : $suggests
# replaces : $replaces
# provides : $provides"
if [ -z "$patch" ]; then
echo "# kernel patch : no patch? are you sure?"
else
echo "# kernel patch : $patch"
fi
fi
if $(echo $stages | grep -q bdi); then echo "# disk size : $disksize M
# fstype : $fstype"; fi
echo "
you may press Ctrl+C to abort
"
sleep 30
echo ' So lets run...'
## check and install required host packages
LANG=C apt list --installed | sed 's/\/.*//g'>/tmp/aptlist
need_install=""
for i in $hostpackages; do
if ! $(grep $i /tmp/aptlist -xq); then
need_install+="$i "
fi
done
rm -f /tmp/aptlist
if [ "$need_install" != "" ]; then
apt-get install -y $need_install
if [ "$(uname -m)" == 'x86_64' ]; then
dpkg --add-architecture i386
apt-get update
apt-get install -y $(echo $hostpackages_32bit)
else
apt-get install -y libncurses5
fi
apt autoremove -y
fi
if [ ! -d "$basedir" ]; then mkdir $basedir; fi
## run stages
if $(echo $stages | grep -q ck); then
echo '
# Compilation stage
'
if [ ! -e "config" ];then
echo Downloading kernel config from github.com/quarkscript/..
wget https://raw.githubusercontent.com/quarkscript/xe303c12_play_linux/master/config
fi
if [ ! -e "config" ];then
echo Downloading kernel config from gitlab.com/quarkscript/..
wget https://gitlab.com/quarkscript/linarm/-/raw/master/xe303c12/kali-linux/config
fi
if [ ! -e "config" ];then
echo "config - kernel config file not found, probably something wrong with internet connection or repos, try pace it manually"
exit 1
fi
if [ -d ${basedir}/kernel ]; then
rm -fr ${basedir}/kernel
echo remove old kernel build folder
fi
if [ -f ${basedir}/*.deb ]; then
rm -f ${basedir}/*.deb
echo remove previous builded kernel package
fi
if [ -d ${basedir}/kernel_pkg ]; then
rm -fr ${basedir}/kernel_pkg
echo remove old kernel_pkg folder
fi
if [ -f ${basedir}/kernel_image ]; then
rm -f ${basedir}/kernel_image
echo remove previous builded kernel_image
fi
if [ -f ${basedir}/zImage ]; then
rm -fr ${basedir}/zImage
echo remove previous builded zImage
fi
if [ -d ${basedir}/linux* ]; then
rm -fr ${basedir}/linux*
echo remove previous linux source foldes
fi
export CROSS_COMPILE=arm-linux-gnueabihf-
export ARCH=arm
echo extract kernel source
tar -xf ${basedir}/../linux*tar.xz -C ${basedir}/
mv -f ${basedir}/linux* ${basedir}/kernel
cd ${basedir}/kernel
cp ${basedir}/../config .config
# apply patch
if [ ! -z "$patch" ]&&[ -f "${basedir}/../$patch" ]; then
cp "${basedir}/../$patch" $patch
git apply $patch
fi
# make ARCH=$ARCH menuconfig
echo '
forcing some optimization flags
'
for tmpcycle in $(find -name Makefile); do
# sed -i "s/armv7-a/armv7-a+mp+neon-vfpv4 --param l1-cache-size=64 --param l2-cache-size=1024 -faggressive-loop-optimizations -fguess-branch-probability -floop-nest-optimize -fomit-frame-pointer -fsel-sched-pipelining -fsel-sched-pipelining-outer-loops -fpredictive-commoning -fprefetch-loop-arrays -ftree-loop-optimize /g" $tmpcycle
# sed -i "s/vfpv /vfpv4 /g" $tmpcycle
# sed -i "s/vfpv,/vfpv4,/g" $tmpcycle
# sed -i "s/-O2/-O2 --param l1-cache-size=64 --param l2-cache-size=1024 -faggressive-loop-optimizations -fguess-branch-probability -floop-nest-optimize -fomit-frame-pointer -fsel-sched-pipelining -fsel-sched-pipelining-outer-loops -fpredictive-commoning -fprefetch-loop-arrays -ftree-loop-optimize /g" $tmpcycle
# sed -i "s/armv7-a/armv7-a+mp+neon-vfpv4 --param l1-cache-size=64 --param l2-cache-size=1024 -ftracer /g" $tmpcycle
# sed -i "s/vfpv /vfpv4 /g" $tmpcycle
# sed -i "s/vfpv,/vfpv4,/g" $tmpcycle
# sed -i "s/-O2/-O2 --param l1-cache-size=64 --param l2-cache-size=1024 -ftracer /g" $tmpcycle
sed -i "s/armv7-a/armv7-a+mp+neon-vfpv4 --param l1-cache-size=64 --param l2-cache-size=1024 -O2 -ftracer /g" $tmpcycle
sed -i "s/vfpv /vfpv4 /g" $tmpcycle
sed -i "s/vfpv,/vfpv4,/g" $tmpcycle
sed -i "s/-O2/-O2 --param l1-cache-size=64 --param l2-cache-size=1024 -ftracer -funroll-loops -fprefetch-loop-arrays -fpredictive-commoning -fsel-sched-reschedule-pipelined /g" $tmpcycle
# sed -i "s/armv7-a/armv7-a+mp+neon-vfpv4 --param l1-cache-size=64 --param l2-cache-size=1024 -O2 -ftracer /g" $tmpcycle
# sed -i "s/vfpv /vfpv4 /g" $tmpcycle
# sed -i "s/vfpv,/vfpv4,/g" $tmpcycle
# sed -i "s/-O2/-O2 --param l1-cache-size=64 --param l2-cache-size=1024 -ftracer /g" $tmpcycle
done
## build
make -j$(($(grep -c processor /proc/cpuinfo)+1)) zImage modules dtbs
## create deb-pkg
mkdir ${basedir}/kernel_pkg
mkdir ${basedir}/kernel_pkg/boot
mkdir ${basedir}/kernel_pkg/boot/dtbs
mkdir ${basedir}/kernel_pkg/boot/reflash
mkdir ${basedir}/kernel_pkg/usr
mkdir ${basedir}/kernel_pkg/DEBIAN
make modules_install INSTALL_MOD_PATH=${basedir}/kernel_pkg
# make headers_install INSTALL_HDR_PATH=${basedir}/kernel_pkg/usr
cp -f arch/arm/boot/dts/exynos5250-snow.dtb ${basedir}/kernel_pkg/boot/dtbs/exynos5250-snow.dtb
cp -f arch/arm/boot/dts/exynos5250-snow-rev5.dtb ${basedir}/kernel_pkg/boot/dtbs/exynos5250-snow-rev5.dtb
cp -f arch/arm/boot/zImage ${basedir}/kernel_pkg/boot/zImage
cp -f arch/arm/boot/zImage ${basedir}/zImage
kernver=$(ls ${basedir}/kernel_pkg/lib/modules/ | sed 's/-XE.*//g')
cd ${basedir}/kernel_pkg/lib/modules/$kernver
rm -f build
rm -f source
ln -s /usr/src/kernel build
ln -s /usr/src/kernel source
cd ${basedir}/kernel_pkg/boot
curl -o reflash/kernel.keyblock https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/master/core/linux-armv7/kernel.keyblock
curl -o reflash/kernel_data_key.vbprivk https://raw.githubusercontent.com/archlinuxarm/PKGBUILDs/master/core/linux-armv7/kernel_data_key.vbprivk
cat << __EOF__ > reflash/kernel-exynos.its
/dts-v1/;
/ {
description = "Chrome OS kernel image with one or more FDT blobs";
images {
kernel@1{
description = "kernel";
data = /incbin/("../zImage");
type = "kernel_noload";
arch = "arm";
os = "linux";
compression = "none";
load = <0>;
entry = <0>;
};
fdt@1{
description = "exynos5250-snow.dtb";
data = /incbin/("../dtbs/exynos5250-snow.dtb");
type = "flat_dt";
arch = "arm";
compression = "none";
hash@1{
algo = "sha1";
};
};
fdt@2{
description = "exynos5250-snow-rev5.dtb";
data = /incbin/("../dtbs/exynos5250-snow-rev5.dtb");
type = "flat_dt";
arch = "arm";
compression = "none";
hash@1{
algo = "sha1";
};
};
};
configurations {
default = "conf@1";
conf@1{
kernel = "kernel@1";
fdt = "fdt@1";
};
conf@2{
kernel = "kernel@1";
fdt = "fdt@2";
};
};
};
__EOF__
echo 'console=tty0 root=PARTUUID=%U/PARTNROFF=1 zswap.compressor=zstd zswap.max_pool_percent=40 noinitrd rootwait quiet loglevel=0 ' > reflash/cmdline
dd if=/dev/zero of=reflash/bootloader.bin bs=512 count=1
echo '#!/bin/bash
echo ""
echo re-signing kernel image
echo ""
sleep 5
mkimage -D "-I dts -O dtb -p 2048" -f reflash/kernel-exynos.its /tmp/exynos-kernel
vbutil_kernel --arch arm --pack kernel_image --keyblock reflash/kernel.keyblock --signprivate reflash/kernel_data_key.vbprivk --version 1 --config reflash/cmdline --bootloader reflash/bootloader.bin --vmlinuz /tmp/exynos-kernel
rm -f reflash/kernel-exynos.its reflash/cmdline reflash/bootloader.bin
' > reflash/kernel_install
chmod +x reflash/kernel_install
reflash/kernel_install
echo '#!/bin/bash
if [ "$(whoami)" == "root" ]; then
# resign kernel
echo "
You may re-sign kernel and customize kernel boot string.
Regular user do not need it, so it is safe to press n.
Do you want to do this? (y/N)"
read -r tmpvar1
if $(echo $tmpvar1 | grep -q [Yy]); then
bootcmd='"'console=tty0 root=PARTUUID=%U/PARTNROFF=1 rootwait rw noinitrd zswap.compressor=zstd zswap.max_pool_percent=40 audit=0'"'
echo "
default bootcmd is
$bootcmd
Be very careful, without root=PARTUUID=%U/PARTNROFF=1
or something like that your could get a bootfail.
Now you may specify a new one or just press Enter
"
tmpvar2=""
read -r tmpvar2
if [ ! -z "$tmpvar2" ]; then
bootcmd="$tmpvar2"
else
echo " Will be used default boot string
"
fi
# make kernel.its
echo '"'"'
/dts-v1/;
/ {
description = "Chrome OS kernel image with one or more FDT blobs";
#address-cells = <1>;
images {
kernel@1 {
description = "kernel";
data = /incbin/("/boot/zImage");
type = "kernel_noload";
arch = "arm";
os = "linux";
compression = "none";
load = <0>;
entry = <0>;
};
fdt@1 {
description = "exynos5250-snow.dtb";
data = /incbin/("/boot/dtbs/exynos5250-snow.dtb");
type = "flat_dt";
arch = "arm";
compression = "none";
hash@1 {
algo = "sha1";
};
};
fdt@2 {
description = "exynos5250-snow-rev5.dtb";
data = /incbin/("/boot/dtbs/exynos5250-snow-rev5.dtb");
type = "flat_dt";
arch = "arm";
compression = "none";
hash@1 {
algo = "sha1";
};
};
};
configurations {
default = "conf@1";
conf@1 {
kernel = "kernel@1";
fdt = "fdt@1";
};
conf@2 {
kernel = "kernel@1";
fdt = "fdt@2";
};
};
};
'"'"'> /tmp/kernel.its
#
mkimage -D "-I dts -O dtb -p 2048" -f /tmp/kernel.its /tmp/vmlinux.uimg
# make empty bootloader
dd if=/dev/zero of=/tmp/bootloader.bin bs=512 count=1
echo $bootcmd > /tmp/cmdline
if [ -f /boot/kernel_image ]; then
echo backing up existed image
mv -f /boot/kernel_image /boot/backup_kernel_image
echo you may restore it from backup_kernel_image
fi
# final step
vbutil_kernel \
--pack /boot/kernel_image \
--version 1 \
--vmlinuz /tmp/vmlinux.uimg \
--arch arm \
--keyblock /boot/reflash/kernel.keyblock \
--signprivate /boot/reflash/kernel_data_key.vbprivk \
--config /tmp/cmdline \
--bootloader /tmp/bootloader.bin
# clear used files
rm -f /tmp/vmlinux.uimg /tmp/cmdline /tmp/bootloader.bin
fi
# flash kernel
krnprts=""
krnprtc=0
for i in $(ls /dev | grep -x --regexp="mmcblk[0-9]" --regexp="sd[a-z]" --regexp="vd[a-z]"); do
if $(cgpt show /dev/$i | grep Label | grep -q [Kk]ernel); then
if $(echo $i | grep -q mmcblk); then
krnprts+="$i""p$(cgpt show /dev/$i | grep Label | grep [Kk]ernel -m 1 | sed '"'"'s/ / /g'"'"' | sed '"'"'s/ / /g'"'"' | sed '"'"'s/ La.*//g'"'"' | sed '"'"'s/.* //g'"'"') "
else
krnprts+="$i$(cgpt show /dev/$i | grep Label | grep [Kk]ernel -m 1 | sed '"'"'s/ / /g'"'"' | sed '"'"'s/ / /g'"'"' | sed '"'"'s/ La.*//g'"'"' | sed '"'"'s/.* //g'"'"') "
fi
krnprtc=$(($krnprtc+1))
fi
done
echo ""
if [ "$krnprtc" -eq 0 ]; then
echo "Chrome OS kernel partition did not detected."
echo " You may need to flash kernel_image manually."
elif [ "$krnprtc" -eq 1 ]; then
if $(echo $krnprts | grep -q mmcblk0); then
pr_part_type="# usually internal MMC"
elif $(echo $krnprts | grep -q mmcblk1); then
pr_part_type="# usually SD-card"
elif $(echo $krnprts | grep -q sd); then
pr_part_type="# usually USB-disk"
else
pr_part_type="# unknown disk type"
fi
echo "Finded ChromeOs kernel partition - $krnprts $pr_part_type"
echo " Do you want to flash a new kernel to it? (y/N)"
read -r shouldwe
if [[ $shouldwe =~ ^([yY][eE][sS]|[yY])$ ]]; then
echo make kernel partition backup to /boot/krn_pt_bk.gz
dd if=/dev/$krnprts | gzip --best > /boot/krn_pt_bk.gz
echo flash kernel
dd if=/boot/kernel_image of=/dev/$krnprts
sync
else
echo "You may flash kernel manually like:"
echo "dd if=/boot/kernel_image of=/dev/$krnprts"
fi
else
echo "Finded more than one Chrome OS kernel partition."
echo "Current root is /dev/$(mount | grep " / " | sed "s/.*dev\///g" | sed "s/ .*//g")"
echo "You need to specify next action"
echo " 0 for do not flash"
numpart=0
for i in $krnprts; do
numpart=$(($numpart+1))
if $(echo $i | grep -q mmcblk0); then
pr_part_type="# usually internal MMC"
elif $(echo $i | grep -q mmcblk1); then
pr_part_type="# usually SD-card"
elif $(echo $i | grep -q sd); then
pr_part_type="# usually USB-disk"
else
pr_part_type="# unknown disk type"
fi
echo " $numpart for flash $i partition $pr_part_type"
done
#echo ""
echo "Wrong partition may lead to bootfail. Be aware!"
read -r shouldwe
if [ $shouldwe -gt 0 ]&&[ $shouldwe -le $numpart ]; then
numpart=0
for i in $krnprts; do
numpart=$(($numpart+1))
if [ $numpart -eq $shouldwe ]; then
echo make kernel partition backup to /boot/krn_pt_bk.gz
dd if=/dev/$i | gzip --best > /boot/krn_pt_bk.gz
echo flash kernel
dd if=/boot/kernel_image of=/dev/$i
sync
fi
done
else
echo " Ok, you may flash kernel manually"
fi
fi
else
echo superuser rights required
fi
' > reflash/kernel_install
cp -f kernel_image ${basedir}/kernel_image
echo 'Package: linux-kernel-xe303c12
Version: '"$kernver"'
Architecture: '"$architecture"'
Maintainer: Kernel build script maintainer https://git[la,hu]b.com/quarkscript
Description: Custom '"$architecture"' linux kernel, builded for XE303C12 Chromebook
Depends: '"$depends"'
Replaces: '"$replaces"'
Provides: '"$provides"'
Suggests: '"$suggests"'
Section: kernel
Priority: optional
'> ${basedir}/kernel_pkg/DEBIAN/control
echo '#!/bin/bash
/boot/reflash/kernel_install
echo "
To repeat this operations run:
sudo /boot/reflash/kernel_install
"
'> ${basedir}/kernel_pkg/DEBIAN/postinst
chmod 0755 ${basedir}/kernel_pkg/DEBIAN/postinst
cd ${basedir}/
dpkg-deb --build ${basedir}/kernel_pkg $(echo linux-kernel-xe303c12-$kernver).deb
#cd ${basedir}/kernel/
#make mrproper
#cp ${basedir}/../config_w .config
#rm -f ${basedir}/../config_w
#make modules_prepare
fi
if $(echo $stages | grep -q bts); then
echo '
# Build target system stage
'
cd ${basedir}
if [ -d $target_hostname-$architecture ];then
echo remove previous build
umount ${basedir}/$target_hostname-$architecture/proc/sys/fs/binfmt_misc
umount ${basedir}/$target_hostname-$architecture/proc
umount ${basedir}/$target_hostname-$architecture/dev/pts
umount ${basedir}/$target_hostname-$architecture/dev
rm -fr $target_hostname-$architecture
if [ -f debootstrap.log ]; then rm -f debootstrap.log; fi
fi
$debootstrap_string |& tee debootstrap.log
if $(cat debootstrap.log | grep -q "Couldn't download package" -m 1); then
echo ''
echo 'Restart debootstrap'
echo ''
$debootstrap_string |& tee debootstrap.log
fi
if $(cat debootstrap.log | grep -q "Couldn't download package" -m 1); then
echo ''
echo 'Restart debootstrap'
echo ''
$debootstrap_string |& tee debootstrap.log
fi
if $(cat debootstrap.log | grep -q "Couldn't download package" -m 1); then
echo "seems some problems with network or repos; try to run $0 later"
exit 1
fi
cp /usr/bin/qemu-arm-static $target_hostname-$architecture/usr/bin/
LANG=C chroot $target_hostname-$architecture /debootstrap/debootstrap --second-stage
# Create sources.list
cat << EOF > $target_hostname-$architecture/etc/apt/sources.list
$sources_list
EOF
echo "$target_hostname" > $target_hostname-$architecture/etc/hostname
cat << EOF > $target_hostname-$architecture/etc/hosts
127.0.0.1 $target_hostname localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
EOF
cat << EOF > $target_hostname-$architecture/etc/network/interfaces
auto lo
iface lo inet loopback
EOF
cat << EOF > $target_hostname-$architecture/etc/resolv.conf
nameserver 1.1.1.1
EOF
export MALLOC_CHECK_=0 # workaround for LP: #520465
export LC_ALL=C
export DEBIAN_FRONTEND=noninteractive
mount -t proc proc $target_hostname-$architecture/proc
mount -o bind /dev/ $target_hostname-$architecture/dev/
mount -o bind /dev/pts $target_hostname-$architecture/dev/pts
cat << EOF > $target_hostname-$architecture/debconf.set
console-common console-data/keymap/policy select Select keymap from full list
console-common console-data/keymap/full select en-latin1-nodeadkeys
EOF
tmpvar1='$(grep -xq $i /tmp/aptlist)'
paclist='$paclist'
i='$i'
check_mkl='$(cat aptgetmainpkg.log | grep -q --regexp="Cannot initiate the connection" --regexp="Unable to connect" -m 1)'
cat << EOF > $target_hostname-$architecture/third-stage
#!/bin/bash
dpkg-divert --add --local --divert /usr/sbin/invoke-rc.d.chroot --rename /usr/sbin/invoke-rc.d
cp /bin/true /usr/sbin/invoke-rc.d
echo -e "#!/bin/sh\nexit 101" > /usr/sbin/policy-rc.d
chmod +x /usr/sbin/policy-rc.d
apt-get update
apt-get --yes --force-yes install locales-all
debconf-set-selections /debconf.set
rm -f /debconf.set
apt-get update
apt-get -y -d install $targetpackages_2 |& tee aptgetmainpkg.log
if $check_mkl; then
apt-get -y -d install $targetpackages_2 |& tee aptgetmainpkg.log
sleep 5
fi
if $check_mkl; then
apt-get -y -d install $targetpackages_2 |& tee aptgetmainpkg.log
fi
apt-get -y install $targetpackages_2
apt-get -y -d install $targetpackages_3
if $check_mkl; then
apt-get -y -d install $targetpackages_3 |& tee aptgetmainpkg.log
sleep 5
fi
if $check_mkl; then
apt-get -y -d install $targetpackages_3 |& tee aptgetmainpkg.log
fi
apt-get -y install $targetpackages_3
echo "root:toor" | chpasswd
sed -i -e 's/KERNEL\!=\"eth\*|/KERNEL\!=\"/' /lib/udev/rules.d/75-persistent-net-generator.rules
rm -f /etc/udev/rules.d/70-persistent-net.rules
export DEBIAN_FRONTEND=noninteractive
## check and remove from install list unavailable packages
paclist=""
LANG=C apt list | sed 's/\/.*//g' >/tmp/aptlist
for i in $targetpackages; do
if $tmpvar1; then
paclist+="$i "
else
echo $i " is unavailable, it will be ignored during install"
fi
done
rm -f /tmp/aptlist
apt-get --yes --force-yes -d install $paclist $nir |& tee aptgetmainpkg.log
sleep 5
if $check_mkl; then
apt-get --yes --force-yes -d install $paclist $nir |& tee aptgetmainpkg.log
fi
sleep 5
if $check_mkl; then
apt-get --yes --force-yes -d install $paclist $nir |& tee aptgetmainpkg.log
fi
sleep 5
if $check_mkl; then
apt-get --yes --force-yes -d install $paclist $nir |& tee aptgetmainpkg.log
fi
sleep 5
if $check_mkl; then
apt-get --yes --force-yes -d install $paclist $nir |& tee aptgetmainpkg.log
fi
if $check_mkl; then
echo ''
echo 'Something wrong with network or repos. Some packages will be missed.'
echo ''
fi
apt-get --yes --force-yes install $paclist $nir
apt-get --yes --force-yes dist-upgrade $nir
apt-get --yes --force-yes autoremove
apt-get clean
rm -f /usr/sbin/policy-rc.d
rm -f /usr/sbin/invoke-rc.d
dpkg-divert --remove --rename /usr/sbin/invoke-rc.d
rm -f /third-stage
# download firmwares
if [ ! -d $firmware_dir ]; then
mkdir -p $firmware_dir
fi
# samsung
if [ ! -f $firmware_dir/s5p-mfc.fw ]; then
curl -o $firmware_dir/s5p-mfc.fw https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/s5p-mfc.fw
fi
if [ ! -f $firmware_dir/s5p-mfc-v6-v2.fw ]; then
curl -o $firmware_dir/s5p-mfc-v6-v2.fw https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/s5p-mfc-v6-v2.fw
fi
if [ ! -f $firmware_dir/s5p-mfc-v6.fw ]; then
curl -o $firmware_dir/s5p-mfc-v6.fw https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/s5p-mfc-v6.fw
fi
if [ ! -f $firmware_dir/s5p-mfc-v7.fw ]; then
curl -o $firmware_dir/s5p-mfc-v7.fw https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/s5p-mfc-v7.fw
fi
if [ ! -f $firmware_dir/s5p-mfc-v8.fw ]; then
curl -o $firmware_dir/s5p-mfc-v8.fw https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/s5p-mfc-v8.fw
fi
if [ ! -d $firmware_dir/mrvl ]; then
mkdir -p $firmware_dir/mrvl
fi
# marvel
if [ ! -f $firmware_dir/mrvl/sd8787_uapsta.bin ]; then
curl -o $firmware_dir/mrvl/sd8787_uapsta.bin https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/mrvl/sd8787_uapsta.bin
fi
if [ ! -f $firmware_dir/mrvl/sd8797_uapsta.bin ]; then
curl -o $firmware_dir/mrvl/sd8797_uapsta.bin https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/mrvl/sd8797_uapsta.bin
fi
if [ ! -f $firmware_dir/mrvl/sd8897_uapsta.bin ]; then
curl -o $firmware_dir/mrvl/sd8897_uapsta.bin https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/plain/mrvl/sd8897_uapsta.bin
fi
sleep 5
EOF
chmod +x $target_hostname-$architecture/third-stage
LANG=C chroot $target_hostname-$architecture /third-stage
umount ${basedir}/$target_hostname-$architecture/proc/sys/fs/binfmt_misc
umount ${basedir}/$target_hostname-$architecture/proc
umount ${basedir}/$target_hostname-$architecture/dev/pts
umount ${basedir}/$target_hostname-$architecture/dev
fi
if $(echo $stages | grep -q bdi); then
echo '
# Build disk image stage
'
rootsize=$(du -s -BM ${basedir}/$target_hostname-$architecture/ 2>&1 | tail -n1 | sed 's/M.*//g')
if [ "$rootsize" -gt "$(($disksize*9/10))" ]&&[ "$fstype" == "ext4" ];then
echo Disk image size is too small. Try to repeat bdi stage with bigger disk size
exit 1
elif [ $rootsize -gt $(($disksize*2*9/10)) ]&&[ $fstype != ext4 ];then
echo Disk image size is too small even filesystem compression may not help. Try to repeat bdi stage with bigger disk size
exit 1
fi
cd ${basedir}/
if [ -d "${basedir}/root" ]; then
umount ${basedir}/root
rm -fr ${basedir}/root
fi
umount /dev/mapper/loop*
if [ -f "${basedir}/$target_hostname-$architecture-xe303c12.img" ]; then
rm -f ${basedir}/$target_hostname-$architecture-xe303c12.img
fi
echo "Creating image file for Exynos-based Samsung XE303C12 Chromebook"
dd if=/dev/zero of=${basedir}/$target_hostname-$architecture-xe303c12.img bs=1M count=$disksize
parted $target_hostname-$architecture-xe303c12.img --script -- mklabel gpt
cgpt create -z $target_hostname-$architecture-xe303c12.img
cgpt create $target_hostname-$architecture-xe303c12.img
cgpt add -i 1 -t kernel -b 8192 -s 32768 -l kernel -S 1 -T 5 -P 10 $target_hostname-$architecture-xe303c12.img
cgpt add -i 2 -t data -b 40960 -s `expr $(cgpt show $target_hostname-$architecture-xe303c12.img | grep 'Sec GPT table' | awk '{ print \$1 }') - 40960` -l Root $target_hostname-$architecture-xe303c12.img
loopdevice=`losetup -f --show ${basedir}/$target_hostname-$architecture-xe303c12.img`
device=`kpartx -va $loopdevice| sed -E 's/.*(loop[0-9])p.*/\1/g' | head -1`
sleep 5
device="/dev/mapper/${device}"
bootp=${device}p1
rootp=${device}p2
mkdir -p ${basedir}/root
if [ "$fstype" == "btrfs" ]; then
mkfs.btrfs -f --label rootfs $rootp
mount $rootp ${basedir}/root -o,compress,noatime,ssd
elif [ "$fstype" == "f2fs" ]; then
mkfs.f2fs -f -O 'extra_attr flexible_inline_xattr compression encrypt ' -l rootfs $rootp
mount $rootp ${basedir}/root -o,compress_algorithm=lzo,compress_extension=*
else
mkfs.ext4 -O ^flex_bg -O ^metadata_csum -L rootfs $rootp
mount $rootp ${basedir}/root
fi
rootuuid=$(LANG=C blkid | grep "$rootp" | grep 'LABEL="rootfs"' | sed 's/.* UUID="//g' | sed 's/".*//g')
echo "Rsyncing rootfs into image file"
rsync -HPavz -q ${basedir}/$target_hostname-$architecture/ ${basedir}/root/
if [ $? -ne 0 ]; then
echo '
Looks like not enough space at disk image.
Disk image build process terminated.
'
umount $rootp
exit 1
fi
echo '
Install kernel and clear disk image from debootstrap
'
export MALLOC_CHECK_=0 # workaround for LP: #520465
export LC_ALL=C
export DEBIAN_FRONTEND=noninteractive
mount -t proc proc ${basedir}/root/proc
mount -o bind /dev/ ${basedir}/root/dev
mount -o bind /dev/pts ${basedir}/root/dev/pts
krn_pkg_name=$(ls ${basedir}/ | grep .deb)
if [ ! -z "$krn_pkg_name" ]; then
cp ${basedir}/$krn_pkg_name ${basedir}/root/$krn_pkg_name
cat << EOF >${basedir}/root/install-kernel
apt-get install /$krn_pkg_name --force-yes --yes
EOF
chmod +x ${basedir}/root/install-kernel
LANG=C chroot ${basedir}/root /install-kernel
else
echo '
No kernel package was found. Linux disk image will be unfunctional.
'
fi
cat << EOF > ${basedir}/root/cleanup
#!/bin/bash
rm -rf /root/.bash_history
apt-get update $nir
apt-get clean
rm -f /0
rm -f /hs_err*
rm -f cleanup
rm -f /usr/bin/qemu*
rm -f install-kernel
EOF
chmod +x ${basedir}/root/cleanup
LANG=C chroot ${basedir}/root /cleanup
umount ${basedir}/root/proc/sys/fs/binfmt_misc
umount ${basedir}/root/proc
umount ${basedir}/root/dev/pts
umount ${basedir}/root/dev
cat << EOF > ${basedir}/root/etc/apt/sources.list
$sourcelist
EOF
if [ "$fstype" == "btrfs" ]; then
cat << EOF> ${basedir}/root/etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda2 during installation
UUID=$rootuuid / btrfs rw,noatime,compress=zstd:5,autodefrag,ssd 0 0
# swap was on /dev/sdaX during installation
#UUID= none swap sw 0 0
#/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
EOF
elif [ "$fstype" == "f2fs" ]; then
cat << EOF> ${basedir}/root/etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda2 during installation
UUID=$rootuuid / f2fs rw,noatime,compress_algorithm=zstd,compress_extension=* 0 1
# swap was on /dev/sdaX during installation
#UUID= none swap sw 0 0
#/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
EOF
else
cat << EOF> ${basedir}/root/etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda2 during installation
UUID=$rootuuid / ext4 rw,noatime 0 1
# swap was on /dev/sdaX during installation
#UUID= none swap sw 0 0
#/dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0
EOF
fi
cd ${basedir}
# Bit of a hack to hide eMMC partitions from XFCE
#cat << EOF > ${basedir}/root/etc/udev/rules.d/99-hide-emmc-partitions.rules
#KERNEL=="mmcblk0*", ENV{UDISKS_IGNORE}="1"
#EOF
# Disable uap0 and p2p0 interfaces in NetworkManager
#printf '\n[keyfile]\nunmanaged-devices=interface-name:p2p0\n' >> ${basedir}/root/etc/NetworkManager/NetworkManager.conf
# Touchpad configuration
mkdir -p ${basedir}/root/etc/X11/xorg.conf.d
cat << EOF > ${basedir}/root/etc/X11/xorg.conf.d/10-synaptics-chromebook.conf
Section "InputClass"
Identifier "touchpad"
MatchIsTouchpad "on"
Driver "synaptics"
Option "TapButton1" "1"
Option "TapButton2" "3"
Option "TapButton3" "2"
Option "FingerLow" "15"
Option "FingerHigh" "20"
Option "FingerPress" "256"
EndSection
EOF
# Mali GPU rules aka mali-rules package in ChromeOS
cat << EOF > ${basedir}/root/etc/udev/rules.d/50-mali.rules
KERNEL=="mali0", MODE="0660", GROUP="video"
EOF
# Video rules aka media-rules package in ChromeOS
cat << EOF > ${basedir}/root/etc/udev/rules.d/50-media.rules
ATTR{name}=="s5p-mfc-dec", SYMLINK+="video-dec"
ATTR{name}=="s5p-mfc-enc", SYMLINK+="video-enc"
ATTR{name}=="s5p-jpeg-dec", SYMLINK+="jpeg-dec"
ATTR{name}=="exynos-gsc.0*", SYMLINK+="image-proc0"
ATTR{name}=="exynos-gsc.1*", SYMLINK+="image-proc1"
ATTR{name}=="exynos-gsc.2*", SYMLINK+="image-proc2"
ATTR{name}=="exynos-gsc.3*", SYMLINK+="image-proc3"
EOF
if [ -f "${basedir}/root/etc/ssh/sshd_config" ]; then
sed -i -e 's/^#PermitRootLogin.*/PermitRootLogin yes/' ${basedir}/root/etc/ssh/sshd_config
fi
# Unmount partitions
umount $rootp