-
Notifications
You must be signed in to change notification settings - Fork 9
/
amlogic_utils.sh
1977 lines (1791 loc) · 66 KB
/
amlogic_utils.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
function real_path() {
export PATH=${ROOT_DIR}/build/kernel/build-tools/path/linux-x86:$PATH
if [[ "${FULL_KERNEL_VERSION}" == "common13-5.15" ]]; then
rel_path $@
else
realpath $1 --relative-to $2
fi
}
function pre_defconfig_cmds() {
export OUT_AMLOGIC_DIR=$(readlink -m ${COMMON_OUT_DIR}/amlogic)
if [ "${ARCH}" = "arm" ]; then
export PATH=${PATH}:/usr/bin/
fi
if [[ -z ${ANDROID_PROJECT} ]]; then
local temp_file=`mktemp /tmp/config.XXXXXXXXXXXX`
echo "CONFIG_AMLOGIC_SERIAL_MESON=y" > ${temp_file}
echo "CONFIG_DEVTMPFS=y" >> ${temp_file}
if [[ ${ARCH} == arm ]]; then
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${GKI_BASE_CONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG} ${temp_file}
else
if [[ ${GKI_CONFIG} == gki_20 ]]; then
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${GKI_BASE_CONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG} ${temp_file}
else
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${GKI_BASE_CONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG_GKI10} ${ROOT_DIR}/${FRAGMENT_CONFIG_DEBUG} ${temp_file}
fi
fi
rm ${temp_file}
else
if [[ ${ARCH} == arm ]]; then
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${GKI_BASE_CONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG}
else
if [[ ${GKI_CONFIG} == gki_20 ]]; then
if [[ -n ${CHECK_GKI_20} ]]; then
local temp_file=`mktemp /tmp/config.XXXXXXXXXXXX`
echo "CONFIG_STMMAC_ETH=n" > ${temp_file}
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${GKI_BASE_CONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG} ${temp_file}
rm ${temp_file}
else
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${GKI_BASE_CONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG}
fi
else
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${GKI_BASE_CONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG_GKI10} ${ROOT_DIR}/${FRAGMENT_CONFIG_DEBUG}
fi
fi
fi
if [[ ${UPGRADE_PROJECT} == r || ${UPGRADE_PROJECT} == R ]]; then
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG_UPGRADE_R}
fi
if [[ ${UPGRADE_PROJECT} == p || ${UPGRADE_PROJECT} == P ]]; then
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG_UPGRADE_P}
fi
if [[ ${UPGRADE_PROJECT} == s || ${UPGRADE_PROJECT} == S ]]; then
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG_UPGRADE_S}
fi
if [[ ${UPGRADE_PROJECT} == u || ${UPGRADE_PROJECT} == U ]]; then
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${FRAGMENT_CONFIG_UPGRADE_U}
fi
if [[ ${IN_BUILD_GKI_10} == 1 ]]; then
local temp_file=`mktemp /tmp/config.XXXXXXXXXXXX`
echo "CONFIG_MODULE_SIG_ALL=y" >> ${temp_file}
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${temp_file}
rm ${temp_file}
fi
if [[ -n ${DEV_CONFIGS} ]]; then
local config_list=$(echo ${DEV_CONFIGS}|sed 's/+/ /g')
for config_name in ${config_list[@]}
do
if [[ -f ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/arch/${ARCH}/configs/${config_name} ]]; then
config_file=${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/arch/${ARCH}/configs/${config_name}
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${config_file}
elif [[ -f ${config_name} ]]; then
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${config_name}
else
echo "ERROR: config file ${config_name} is not in the right path!!"
exit
fi
done
fi
if [[ ${UPGRADE_PROJECT} == r || ${UPGRADE_PROJECT} == R ]] && [[ "${CONFIG_BOOTIMAGE}" == "user" ]]; then
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${AMLOGIC_R_USER_DIFFCONFIG}
fi
if [[ -n ${KASAN} ]]; then
local temp_file=`mktemp /tmp/config.XXXXXXXXXXXX`
cat ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/arch/${ARCH}/configs/amlogic_kasan.defconfig > ${temp_file}
KCONFIG_CONFIG=${ROOT_DIR}/${KCONFIG_DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r \
${ROOT_DIR}/${KCONFIG_DEFCONFIG} \
${temp_file}
rm ${temp_file}
fi
}
export -f pre_defconfig_cmds
function post_defconfig_cmds() {
rm ${ROOT_DIR}/${KCONFIG_DEFCONFIG}
}
export -f post_defconfig_cmds
function read_ext_module_config() {
ALL_LINE=""
while read LINE
do
if [[ $LINE != \#* && $LINE != "" ]]; then
ALL_LINE="$ALL_LINE"" ""$LINE"
fi
done < $1
echo "${ALL_LINE}"
}
function copy_pre_commit(){
if [[ -d ${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/.git/hooks/ ]]; then
if [[ ! -f ${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/.git/hooks/pre-commit ]]; then
cp ${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/scripts/amlogic/pre-commit ${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/.git/hooks/pre-commit
cp ${KERNEL_DIR}/scripts/amlogic/pre-commit ${KERNEL_DIR}/.git/hooks/pre-commit
chmod +x ${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/.git/hooks/pre-commit
chmod +x ${KERNEL_DIR}/.git/hooks/pre-commit
fi
fi
}
function read_ext_module_predefine() {
PRE_DEFINE=""
for y_config in `cat $1 | grep "^CONFIG_.*=y" | sed 's/=y//'`; do
PRE_DEFINE="$PRE_DEFINE"" -D"${y_config}
done
for m_config in `cat $1 | grep "^CONFIG_.*=m" | sed 's/=m//'`; do
PRE_DEFINE="$PRE_DEFINE"" -D"${m_config}_MODULE
done
echo "${PRE_DEFINE}"
}
top_ext_drivers=top_ext_drivers
function prepare_module_build() {
local temp_file=`mktemp /tmp/kernel.XXXXXXXXXXXX`
if [[ ! `grep "CONFIG_AMLOGIC_IN_KERNEL_MODULES=y" ${ROOT_DIR}/${FRAGMENT_CONFIG}` ]]; then
sed 's:#.*$::g' ${ROOT_DIR}/${FRAGMENT_CONFIG} | sed '/^$/d' | sed 's/^[ ]*//' | sed 's/[ ]*$//' > ${temp_file}
GKI_EXT_KERNEL_MODULE_CONFIG=$(read_ext_module_config ${temp_file})
GKI_EXT_KERNEL_MODULE_PREDEFINE=$(read_ext_module_predefine ${temp_file})
export GKI_EXT_KERNEL_MODULE_CONFIG GKI_EXT_KERNEL_MODULE_PREDEFINE
fi
for ext_module_config in ${EXT_MODULES_CONFIG}; do
sed 's:#.*$::g' ${ROOT_DIR}/${ext_module_config} | sed '/^$/d' | sed 's/^[ ]*//' | sed 's/[ ]*$//' > ${temp_file}
GKI_EXT_MODULE_CONFIG=$(read_ext_module_config ${temp_file})
GKI_EXT_MODULE_PREDEFINE=$(read_ext_module_predefine ${temp_file})
done
export GKI_EXT_MODULE_CONFIG GKI_EXT_MODULE_PREDEFINE
echo GKI_EXT_MODULE_CONFIG=${GKI_EXT_MODULE_CONFIG}
echo GKI_EXT_MODULE_PREDEFINE=${GKI_EXT_MODULE_PREDEFINE}
if [[ ${TOP_EXT_MODULE_COPY_BUILD} -eq "1" ]]; then
if [[ -d ${top_ext_drivers} ]]; then
rm -rf ${top_ext_drivers}
fi
mkdir -p ${top_ext_drivers}
fi
if [[ ${AUTO_ADD_EXT_SYMBOLS} -eq "1" ]]; then
extra_symbols="KBUILD_EXTRA_SYMBOLS +="
fi
ext_modules=
for ext_module in ${EXT_MODULES}; do
module_abs_path=`readlink -e ${ext_module}`
module_rel_path=$(real_path ${module_abs_path} ${ROOT_DIR})
if [[ ${TOP_EXT_MODULE_COPY_BUILD} -eq "1" ]]; then
if [[ `echo ${module_rel_path} | grep "\.\.\/"` ]]; then
cp -rf ${module_abs_path} ${top_ext_drivers}
module_rel_path=${top_ext_drivers}/${module_abs_path##*/}
fi
fi
ext_modules="${ext_modules} ${module_rel_path}"
done
for ext_module_path in ${EXT_MODULES_PATH}; do
sed 's:#.*$::g' ${ROOT_DIR}/${ext_module_path} | sed '/^$/d' | sed 's/^[ ]*//' | sed 's/[ ]*$//' > ${temp_file}
while read LINE
do
module_abs_path=`readlink -e ${LINE}`
module_rel_path=$(real_path ${module_abs_path} ${ROOT_DIR})
if [[ ${TOP_EXT_MODULE_COPY_BUILD} -eq "1" ]]; then
if [[ `echo ${module_rel_path} | grep "\.\.\/"` ]]; then
cp -rf ${module_abs_path} ${top_ext_drivers}
module_rel_path=${top_ext_drivers}/${module_abs_path##*/}
fi
fi
ext_modules="${ext_modules} ${module_rel_path}"
done < ${temp_file}
done
EXT_MODULES=${ext_modules}
local flag=0
if [[ ${AUTO_ADD_EXT_SYMBOLS} -eq "1" ]]; then
for ext_module in ${EXT_MODULES}; do
ext_mod_rel=$(real_path ${ext_module} ${KERNEL_DIR})
if [[ ${flag} -eq "1" ]]; then
sed -i "/# auto add KBUILD_EXTRA_SYMBOLS start/,/# auto add KBUILD_EXTRA_SYMBOLS end/d" ${ext_module}/Makefile
sed -i "2 i # auto add KBUILD_EXTRA_SYMBOLS end" ${ext_module}/Makefile
sed -i "2 i ${extra_symbols}" ${ext_module}/Makefile
sed -i "2 i # auto add KBUILD_EXTRA_SYMBOLS start" ${ext_module}/Makefile
echo "${ext_module}/Makefile add: ${extra_symbols}"
fi
extra_symbols="${extra_symbols} ${ext_mod_rel}/Module.symvers"
flag=1
done
fi
export EXT_MODULES
echo EXT_MODULES=${EXT_MODULES}
rm ${temp_file}
}
export -f prepare_module_build
function extra_cmds() {
echo "========================================================"
echo " Running extra build command(s):"
if [[ ${AUTO_ADD_EXT_SYMBOLS} -eq "1" ]]; then
for ext_module in ${EXT_MODULES}; do
sed -i "/# auto add KBUILD_EXTRA_SYMBOLS start/,/# auto add KBUILD_EXTRA_SYMBOLS end/d" ${ext_module}/Makefile
done
fi
if [[ ${TOP_EXT_MODULE_COPY_BUILD} -eq "1" ]]; then
if [[ -d ${top_ext_drivers} ]]; then
rm -rf ${top_ext_drivers}
fi
fi
for FILE in ${FILES}; do
if [[ "${FILE}" =~ \.dtbo ]] && \
[ -n "${DTS_EXT_DIR}" ] && [ -f "${OUT_DIR}/${DTS_EXT_DIR}/${FILE}" ] ; then
MKDTIMG_DTBOS="${MKDTIMG_DTBOS} ${DIST_DIR}/${FILE}"
fi
done
export MKDTIMG_DTBOS
set +x
modules_install
set -x
local src_dir=$(echo ${MODULES_STAGING_DIR}/lib/modules/*)
pushd ${src_dir}
cp modules.order modules_order.back
: > modules.order
set +x
while read LINE
do
find -name ${LINE} >> modules.order
done < ${OUT_AMLOGIC_DIR}/modules/modules.order
set -x
sed -i "s/^\.\///" modules.order
: > ${OUT_AMLOGIC_DIR}/ext_modules/ext_modules.order
ext_modules=
for ext_module in ${EXT_MODULES}; do
if [[ ${ext_module} =~ "../" ]]; then
ext_module_old=${ext_module}
ext_module=${ext_module//\.\.\//}
ext_dir=$(dirname ${ext_module})
[[ -d extra/${ext_module} ]] && rm -rf extra/${ext_dir}
mkdir -p extra/${ext_dir}
cp -rf extra/${ext_module_old} extra/${ext_dir}
ext_modules_order_file=$(ls extra/${ext_module}/modules.order.*)
ext_dir_top=${ext_module%/*}
sed -i "s/\.\.\///g" ${ext_modules_order_file}
cat ${ext_modules_order_file} >> modules.order
cat ${ext_modules_order_file} | awk -F/ '{print $NF}' >> ${OUT_AMLOGIC_DIR}/ext_modules/ext_modules.order
: > ${ext_modules_order_file}
else
ext_modules_order_file=$(ls extra/${ext_module}/modules.order.*)
cat ${ext_modules_order_file} >> modules.order
cat ${ext_modules_order_file} | awk -F/ '{print $NF}' >> ${OUT_AMLOGIC_DIR}/ext_modules/ext_modules.order
: > ${ext_modules_order_file}
fi
ext_modules="${ext_modules} ${ext_module}"
done
EXT_MODULES=${ext_modules}
echo EXT_MODULES=${EXT_MODULES}
export EXT_MODULES
head -n ${ramdisk_last_line} modules.order > vendor_boot_modules
file_last_line=`sed -n "$=" modules.order`
let line=${file_last_line}-${ramdisk_last_line}
tail -n ${line} modules.order > vendor_dlkm_modules
export MODULES_LIST=${src_dir}/vendor_boot_modules
if [[ "${ARCH}" = "arm64" && -z ${FAST_BUILD} ]]; then
export VENDOR_DLKM_MODULES_LIST=${src_dir}/vendor_dlkm_modules
fi
popd
if [[ -z ${ANDROID_PROJECT} ]] && [[ -d ${OUT_DIR}/${DTS_EXT_DIR} ]]; then
FILES="$FILES `ls ${OUT_DIR}/${DTS_EXT_DIR}`"
fi
if [[ -f ${KERNEL_BUILD_VAR_FILE} ]]; then
: > ${KERNEL_BUILD_VAR_FILE}
echo "KERNEL_DIR=${KERNEL_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "COMMON_OUT_DIR=${COMMON_OUT_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "OUT_DIR=${OUT_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "DIST_DIR=${DIST_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "OUT_AMLOGIC_DIR=${OUT_AMLOGIC_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "MODULES_STAGING_DIR=${MODULES_STAGING_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "MODULES_PRIVATE_DIR=${MODULES_PRIVATE_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "INITRAMFS_STAGING_DIR=${INITRAMFS_STAGING_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "SYSTEM_DLKM_STAGING_DIR=${SYSTEM_DLKM_STAGING_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "VENDOR_DLKM_STAGING_DIR=${VENDOR_DLKM_STAGING_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "MKBOOTIMG_STAGING_DIR=${MKBOOTIMG_STAGING_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "DIST_GKI_DIR=${DIST_GKI_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "FULL_KERNEL_VERSION=${FULL_KERNEL_VERSION}" >> ${KERNEL_BUILD_VAR_FILE}
echo "GKI_MODULES_LOAD_WHITE_LIST=\"${GKI_MODULES_LOAD_WHITE_LIST[*]}\"" >> ${KERNEL_BUILD_VAR_FILE}
echo "BAZEL=${BAZEL}" >> ${KERNEL_BUILD_VAR_FILE}
fi
for module_path in ${PREBUILT_MODULES_PATH}; do
find ${module_path} -type f -name "*.ko" -exec cp {} ${DIST_DIR} \;
done
}
export -f extra_cmds
function bazel_extra_cmds() {
modules_install
if [[ -f ${KERNEL_BUILD_VAR_FILE} ]]; then
: > ${KERNEL_BUILD_VAR_FILE}
echo "KERNEL_DIR=${KERNEL_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "COMMON_OUT_DIR=${COMMON_OUT_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "DIST_DIR=${DIST_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "OUT_AMLOGIC_DIR=${OUT_AMLOGIC_DIR}" >> ${KERNEL_BUILD_VAR_FILE}
echo "GKI_MODULES_LOAD_WHITE_LIST=\"${GKI_MODULES_LOAD_WHITE_LIST[*]}\"" >> ${KERNEL_BUILD_VAR_FILE}
echo "BAZEL=${BAZEL}" >> ${KERNEL_BUILD_VAR_FILE}
fi
if [[ ${GKI_CONFIG} != gki_20 ]]; then
[[ -f ${DIST_DIR}/system_dlkm_staging_archive_back.tar.gz ]] && rm -f ${DIST_DIR}/system_dlkm_staging_archive_back.tar.gz
mv ${DIST_DIR}/system_dlkm_staging_archive.tar.gz ${DIST_DIR}/system_dlkm_staging_archive_back.tar.gz
[[ -d ${DIST_DIR}/system_dlkm_gki10 ]] && rm -rf ${DIST_DIR}/system_dlkm_gki10
mkdir ${DIST_DIR}/system_dlkm_gki10
pushd ${DIST_DIR}/system_dlkm_gki10
tar zxf ${DIST_DIR}/system_dlkm_staging_archive_back.tar.gz
find -name "*.ko" | while read module; do
module_name=${module##*/}
if [[ ! `grep "/${module_name}" ${DIST_DIR}/system_dlkm.modules.load` ]]; then
rm -f ${module}
fi
done
tar czf ${DIST_DIR}/system_dlkm_staging_archive.tar.gz lib
popd
rm -rf ${DIST_DIR}/system_dlkm_gki10
fi
}
export -f bazel_extra_cmds
#$1 dep_file
#$2 ko
#$3 install_sh
function mod_probe() {
local dep_file=$1
local ko=$2
local install_sh=$3
local loop
for loop in `grep "^${ko}:" ${dep_file} | sed 's/.*://'`; do
[[ `grep "^${loop}" ${install_sh}` ]] && continue
mod_probe ${dep_file} ${loop} ${install_sh}
echo insmod ${loop} >> ${install_sh}
done
}
function create_install_and_order_filles() {
local modules_dep_file=$1
local install_file=$2
local modules_order_file=$3
local loop
[[ -f ${install_file} ]] && rm -f ${install_file}
touch ${install_file}
[[ -f ${install_file}.tmp ]] && rm -f ${install_file}.tmp
touch ${install_file}.tmp
[[ -f ${modules_order_file} ]] && rm -f ${modules_order_file}
touch ${modules_order_file}
[[ -f ${modules_order_file}.tmp ]] && rm -f ${modules_order_file}.tmp
touch ${modules_order_file}.tmp
for loop in `cat ${modules_dep_file} | sed 's/:.*//'`; do
echo ${loop} >> ${modules_order_file}.tmp
[[ `grep "^${loop}" ${install_file}.tmp` ]] && continue
mod_probe ${modules_dep_file} ${loop} ${install_file}.tmp
echo insmod ${loop} >> ${install_file}.tmp
done
cat ${install_file}.tmp | awk ' {
if (!cnt[$2]) {
print $0;
cnt[$2]++;
}
}' > ${install_file}
cut -d ' ' -f 2 ${install_file} > ${modules_order_file}
}
function adjust_sequence_modules_loading() {
if [[ -n $1 ]]; then
chips=$1
fi
cp modules.dep modules.dep.temp
soc_module=()
for chip in ${chips[@]}; do
chip_module=`ls amlogic-*-soc-${chip}.ko`
soc_module=(${soc_module[@]} ${chip_module[@]})
done
echo soc_module=${soc_module[*]}
delete_soc_module=()
if [[ ${#soc_module[@]} == 0 ]]; then
echo "Use all soc module"
else
for module in `ls amlogic-*-soc-*`; do
if [[ ! "${soc_module[@]}" =~ "${module}" ]] ; then
echo Delete soc module: ${module}
sed -n "/${module}:/p" modules.dep.temp
sed -i "/${module}:/d" modules.dep.temp
delete_soc_module=(${delete_soc_module[@]} ${module})
fi
done
echo delete_soc_module=${delete_soc_module[*]}
fi
if [[ -n ${CLK_SOC_MODULE} ]]; then
delete_clk_soc_modules=()
for module in `ls amlogic-clk-soc-*`; do
if [[ "${CLK_SOC_MODULE}" != "${module}" ]] ; then
echo Delete clk soc module: ${module}
sed -n "/${module}:/p" modules.dep.temp
sed -i "/${module}:/d" modules.dep.temp
delete_clk_soc_modules=(${delete_clk_soc_modules[@]} ${module})
fi
done
echo delete_clk_soc_modules=${delete_clk_soc_modules[*]}
fi
if [[ -n ${PINCTRL_SOC_MODULE} ]]; then
delete_pinctrl_soc_modules=()
for module in `ls amlogic-pinctrl-soc-*`; do
if [[ "${PINCTRL_SOC_MODULE}" != "${module}" ]] ; then
echo Delete pinctrl soc module: ${module}
sed -n "/${module}:/p" modules.dep.temp
sed -i "/${module}:/d" modules.dep.temp
delete_pinctrl_soc_modules=(${delete_pinctrl_soc_modules[@]} ${module})
fi
done
echo delete_pinctrl_soc_modules=${delete_pinctrl_soc_modules[*]}
fi
in_line_i=a
delete_type_modules=()
[[ -z ${TYPE_MODULE_SELECT_MODULE} ]] && TYPE_MODULE_SELECT_MODULE=${TYPE_MODULE_SELECT_MODULE_ANDROID}
echo "TYPE_MODULE_SELECT_MODULE=${TYPE_MODULE_SELECT_MODULE}"
mkdir temp_dir
cd temp_dir
in_temp_dir=y
for element in ${TYPE_MODULE_SELECT_MODULE}; do
if [[ ${in_temp_dir} = y ]]; then
cd ../
rm -r temp_dir
in_temp_dir=
fi
if [[ ${in_line_i} = a ]]; then
in_line_i=b
type_module=${element}
select_modules_i=0
select_modules_count=
select_modules=
elif [[ ${in_line_i} = b ]]; then
in_line_i=c
select_modules_count=${element}
else
let select_modules_i+=1
select_modules="${select_modules} ${element}"
if [[ ${select_modules_i} -eq ${select_modules_count} ]]; then
in_line_i=a
echo type_module=$type_module select_modules=$select_modules
for module in `ls ${type_module}`; do
dont_delete_module=0
for select_module in ${select_modules}; do
if [[ "${select_module}" == "${module}" ]] ; then
dont_delete_module=1
break;
fi
done
if [[ ${dont_delete_module} != 1 ]]; then
echo Delete module: ${module}
sed -n "/${module}:/p" modules.dep.temp
sed -i "/${module}:/d" modules.dep.temp
delete_type_modules=(${delete_type_modules[@]} ${module})
fi
done
echo delete_type_modules=${delete_type_modules[*]}
fi
fi
done
if [[ -n ${in_temp_dir} ]]; then
cd ../
rm -r temp_dir
fi
mkdir service_module
echo MODULES_SERVICE_LOAD_LIST=${MODULES_SERVICE_LOAD_LIST[@]}
mkdir extra_closed_source_modules
echo EXTRA_CLOSED_SOURCE_MODULE_LIST=${EXTRA_CLOSED_SOURCE_MODULE_LIST[@]}
BLACK_LIST=(${MODULES_LOAD_BLACK_LIST[@]} ${MODULES_SERVICE_LOAD_LIST[@]} ${EXTRA_CLOSED_SOURCE_MODULE_LIST[@]})
echo BLACK_LIST=${BLACK_LIST[@]}
black_modules=()
for module in ${BLACK_LIST[@]}; do
if [[ `ls ${module}* 2>/dev/null` ]]; then
modules=`ls ${module}*`
else
continue
fi
black_modules=(${black_modules[@]} ${modules[@]})
done
if [[ ${#black_modules[@]} == 0 ]]; then
echo "black_modules is null, don't delete modules, MODULES_LOAD_BLACK_LIST=${MODULES_LOAD_BLACK_LIST[*]}"
else
echo black_modules=${black_modules[*]}
for module in ${black_modules[@]}; do
echo Delete module: ${module}
sed -n "/${module}:/p" modules.dep.temp
sed -i "/${module}:/d" modules.dep.temp
done
fi
GKI_MODULES_LOAD_BLACK_LIST=()
if [[ "${FULL_KERNEL_VERSION}" != "common13-5.15" && "${ARCH}" == "arm64" ]]; then
gki_modules_temp_file=`mktemp /tmp/config.XXXXXXXXXXXX`
if [[ ${BAZEL} == "1" ]]; then
cp $DIST_DIR/system_dlkm.modules.load ${gki_modules_temp_file}
else
rm -f ${gki_modules_temp_file}
cat ${ROOT_DIR}/${KERNEL_DIR}/modules.bzl |grep ko | while read LINE
do
echo $LINE | sed 's/^[^"]*"//' | sed 's/".*$//' >> ${gki_modules_temp_file}
done
fi
for module in ${GKI_MODULES_LOAD_WHITE_LIST[@]}; do
sed -i "/\/${module}/d" ${gki_modules_temp_file}
done
for module in `cat ${gki_modules_temp_file}`; do
module=${module##*/}
GKI_MODULES_LOAD_BLACK_LIST[${#GKI_MODULES_LOAD_BLACK_LIST[*]}]=${module}
done
rm -f ${gki_modules_temp_file}
for module in ${GKI_MODULES_LOAD_BLACK_LIST[@]}; do
echo Delete module: ${module}
sed -n "/^${module}:/p" modules.dep.temp
sed -i "/^${module}:/d" modules.dep.temp
done
fi
cat modules.dep.temp | cut -d ':' -f 2 > modules.dep.temp1
delete_modules=(${delete_soc_module[@]} ${delete_clk_soc_modules[@]} ${delete_pinctrl_soc_modules[@]} ${delete_type_modules[@]} ${black_modules[@]} ${GKI_MODULES_LOAD_BLACK_LIST[@]})
for module in ${delete_modules[@]}; do
if [[ ! -f $module ]]; then
continue
fi
match=`sed -n "/${module}/=" modules.dep.temp1`
for match in ${match[@]}; do
match_count=(${match_count[@]} $match)
done
if [[ ${#match_count[@]} != 0 ]]; then
echo "Error ${#match_count[@]} modules depend on ${module}, please modify:"
echo ${MODULES_SEQUENCE_LIST}:MODULES_LOAD_BLACK_LIST
exit
fi
if [[ -n ${ANDROID_PROJECT} ]]; then
for service_module_temp in ${MODULES_SERVICE_LOAD_LIST[@]}; do
if [[ ${module} =~ ${service_module_temp} ]]; then
mv ${module} service_module
fi
done
fi
for extra_closed_source_module in ${EXTRA_CLOSED_SOURCE_MODULE_LIST[@]}; do
if [[ ${module} =~ ${extra_closed_source_module} ]]; then
mv ${module} extra_closed_source_modules
fi
done
rm -f ${module}
done
rm -f modules.dep.temp1
touch modules.dep.temp1
for module in ${RAMDISK_MODULES_LOAD_LIST[@]}; do
echo RAMDISK_MODULES_LOAD_LIST: $module
sed -n "/${module}:/p" modules.dep.temp
sed -n "/${module}:/p" modules.dep.temp >> modules.dep.temp1
sed -i "/${module}:/d" modules.dep.temp
sed -n "/${module}.*\.ko:/p" modules.dep.temp
sed -n "/${module}.*\.ko:/p" modules.dep.temp >> modules.dep.temp1
sed -i "/${module}.*\.ko:/d" modules.dep.temp
done
if [[ -n ${ANDROID_PROJECT} ]]; then
cp modules.dep.temp modules_recovery.dep.temp
cp modules.dep.temp1 modules_recovery.dep.temp1
for module in ${RECOVERY_MODULES_LOAD_LIST[@]}; do
echo RECOVERY_MODULES_LOAD_LIST: $module
sed -n "/${module}:/p" modules_recovery.dep.temp
sed -n "/${module}:/p" modules_recovery.dep.temp >> modules_recovery.dep.temp1
sed -i "/${module}:/d" modules_recovery.dep.temp
sed -n "/${module}.*\.ko:/p" modules_recovery.dep.temp
sed -n "/${module}.*\.ko:/p" modules_recovery.dep.temp >> modules_recovery.dep.temp1
sed -i "/${module}.*\.ko:/d" modules_recovery.dep.temp
done
cat modules_recovery.dep.temp >> modules_recovery.dep.temp1
cp modules_recovery.dep.temp1 modules_recovery.dep
rm modules_recovery.dep.temp
rm modules_recovery.dep.temp1
fi
for module in ${VENDOR_MODULES_LOAD_FIRST_LIST[@]}; do
echo VENDOR_MODULES_LOAD_FIRST_LIST: $module
sed -n "/${module}:/p" modules.dep.temp
sed -n "/${module}:/p" modules.dep.temp >> modules.dep.temp1
sed -i "/${module}:/d" modules.dep.temp
sed -n "/${module}.*\.ko:/p" modules.dep.temp
sed -n "/${module}.*\.ko:/p" modules.dep.temp >> modules.dep.temp1
sed -i "/${module}.*\.ko:/d" modules.dep.temp
done
: > modules.dep.temp2
for module in ${VENDOR_MODULES_LOAD_LAST_LIST[@]}; do
echo VENDOR_MODULES_LOAD_FIRST_LIST: $module
sed -n "/${module}:/p" modules.dep.temp
sed -n "/${module}:/p" modules.dep.temp >> modules.dep.temp2
sed -i "/${module}:/d" modules.dep.temp
sed -n "/${module}.*\.ko:/p" modules.dep.temp
sed -n "/${module}.*\.ko:/p" modules.dep.temp >> modules.dep.temp2
sed -i "/${module}.*\.ko:/d" modules.dep.temp
done
cat modules.dep.temp >> modules.dep.temp1
cat modules.dep.temp2 >> modules.dep.temp1
cp modules.dep.temp1 modules.dep
rm modules.dep.temp
rm modules.dep.temp1
rm modules.dep.temp2
}
function calculate_first_line() {
local modules_order_file=$1
local modules_list=($2)
local module
local module_lines=()
local lines
local first_line
for module in ${modules_list[@]}; do
module_lines[${#module_lines[@]}]=`sed -n "/${module}/=" ${modules_order_file}`
done
lines=`echo ${module_lines[*]} | tr ' ' '\n' | sort -n`
first_line=`echo ${lines} | cut -d ' ' -f 1`
echo ${first_line}
}
function calculate_last_line() {
local modules_order_file=$1
local modules_list=($2)
local module
local module_lines=()
local lines
local last_line
for module in ${modules_list[@]}; do
module_lines[${#module_lines[@]}]=`sed -n "/${module}/=" ${modules_order_file}`
done
lines=`echo ${module_lines[*]} | tr ' ' '\n' | sort -n -r`
last_line=`echo ${lines} | cut -d ' ' -f 1`
[[ -z ${last_line} ]] && last_line=0
echo ${last_line}
}
function create_ramdisk_vendor_recovery() {
modules_order=$1
if [[ -n ${ANDROID_PROJECT} ]]; then
modules_recovery_order=$2
fi
local modules_list
modules_list=`echo ${RAMDISK_MODULES_LOAD_LIST[@]}`
export ramdisk_last_line=`calculate_last_line ${modules_order} "${modules_list}"`
export ramdisk_last_line_add_1=${ramdisk_last_line}
let ramdisk_last_line_add_1+=1
echo ramdisk_last_line=${ramdisk_last_line}
if [[ -n ${ANDROID_PROJECT} ]]; then
modules_list=`echo ${RECOVERY_MODULES_LOAD_LIST[@]}`
recovery_last_line=`calculate_last_line ${modules_recovery_order} "${modules_list}"`
echo recovery_last_line=${recovery_last_line}
mkdir recovery
if [[ ${recovery_last_line} == 0 ]]; then
: > recovery/recovery_modules.order
: > recovery_install.sh
else
sed -n "${ramdisk_last_line_add_1},${recovery_last_line}p" ${modules_recovery_order} > recovery/recovery_modules.order
cat recovery/recovery_modules.order | xargs cp -t recovery/
cat recovery/recovery_modules.order | sed "s/^/insmod &/" > recovery_install.sh
fi
sed -i '1s/^/#!\/bin\/sh\n\nset -x\n/' recovery_install.sh
echo "echo Install recovery modules success!" >> recovery_install.sh
chmod 755 recovery_install.sh
mv recovery_install.sh recovery/
fi
mkdir ramdisk
head -n ${ramdisk_last_line} ${modules_order} > ramdisk/ramdisk_modules.order
echo -e "#!/bin/sh\n\nset -x" > ramdisk/ramdisk_install.sh
if [[ ${ramdisk_last_line} != 0 ]]; then
cat ramdisk/ramdisk_modules.order | xargs mv -t ramdisk/
cat ramdisk/ramdisk_modules.order | sed "s/^/insmod &/" >> ramdisk/ramdisk_install.sh
fi
echo "echo Install ramdisk modules success!" >> ramdisk/ramdisk_install.sh
chmod 755 ramdisk/ramdisk_install.sh
mkdir vendor
sed -n "${ramdisk_last_line_add_1},$$p" ${modules_order} > vendor/vendor_modules.order
echo -e "#!/bin/sh\n\nset -x" > vendor/vendor_install.sh
if [[ -s vendor/vendor_modules.order ]]; then
cat vendor/vendor_modules.order | xargs mv -t vendor/
cat vendor/vendor_modules.order | sed "s/^/insmod &/" >> vendor/vendor_install.sh
fi
echo "echo Install vendor modules success!" >> vendor/vendor_install.sh
chmod 755 vendor/vendor_install.sh
}
function modules_install() {
arg1=$1
if [[ ! -f ${MODULES_SEQUENCE_LIST} ]]; then
MODULES_SEQUENCE_LIST=${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/scripts/amlogic/modules_sequence_list
fi
source ${MODULES_SEQUENCE_LIST}
if [[ ! -f ${EXTRA_MODULES_LIST} ]]; then
EXTRA_MODULES_LIST=${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/scripts/amlogic/ext_modules_list
fi
source ${EXTRA_MODULES_LIST}
export OUT_AMLOGIC_DIR=${OUT_AMLOGIC_DIR:-$(readlink -m ${COMMON_OUT_DIR}/amlogic)}
echo $OUT_AMLOGIC_DIR
rm -rf ${OUT_AMLOGIC_DIR}
mkdir -p ${OUT_AMLOGIC_DIR}
mkdir -p ${OUT_AMLOGIC_DIR}/modules
mkdir -p ${OUT_AMLOGIC_DIR}/ext_modules
mkdir -p ${OUT_AMLOGIC_DIR}/symbols
if [[ ${BAZEL} == "1" ]]; then
BAZEL_OUT=bazel-out/
while read module
do
module_name=${module##*/}
if [[ -z ${ANDROID_PROJECT} || `echo ${module} | grep "^kernel\/"` ]]; then
if [[ -f ${DIST_DIR}/${module_name} ]]; then
cp ${DIST_DIR}/${module_name} ${OUT_AMLOGIC_DIR}/modules
else
module=`find ${BAZEL_OUT} -name ${module_name} | grep "amlogic_modules_install"`
cp ${module} ${OUT_AMLOGIC_DIR}/modules
fi
elif [[ `echo ${module} | grep "^extra\/"` ]]; then
module=${module#*/}
local match=
for ext_module in ${EXT_MODULES_ANDROID_AUTO_LOAD}; do
if [[ "${module}" =~ "${ext_module}" ]]; then
match=1
break
fi
done
if [[ ${match} == 1 ]]; then
cp ${DIST_DIR}/${module_name} ${OUT_AMLOGIC_DIR}/modules
else
cp ${DIST_DIR}/${module_name} ${OUT_AMLOGIC_DIR}/ext_modules
fi
else
echo "warning unrecognized module: ${module}"
fi
done < ${DIST_DIR}/modules.load
dep_file=`find ${BAZEL_OUT} -name *.dep | grep "amlogic"`
cp ${dep_file} ${OUT_AMLOGIC_DIR}/modules/full_modules.dep
if [[ -n ${ANDROID_PROJECT} ]]; then
grep -E "^kernel\/" ${dep_file} > ${OUT_AMLOGIC_DIR}/modules/modules.dep
for ext_module in ${EXT_MODULES_ANDROID_AUTO_LOAD}; do
cat ${dep_file} | cut -d ':' -f 1 | grep -n "${ext_module}" | cut -d ':' -f 1 | while read line; do
sed -n ${line}p ${dep_file} >> ${OUT_AMLOGIC_DIR}/modules/modules.dep
done
done
touch ${module} ${OUT_AMLOGIC_DIR}/ext_modules/ext_modules.order
for order_file in `find ${BAZEL_OUT} -name "modules.order.*" | grep "amlogic"`; do
order_file_dir=${order_file#*/extra/}
order_file_dir=${order_file_dir%/modules.order.*}
if [[ ! "${EXT_MODULES_ANDROID_AUTO_LOAD}" =~ "${order_file_dir}" ]]; then
echo "# ${order_file}" >> ${OUT_AMLOGIC_DIR}/ext_modules/ext_modules.order
cat ${order_file} >> ${OUT_AMLOGIC_DIR}/ext_modules/ext_modules.order
echo >> ${OUT_AMLOGIC_DIR}/ext_modules/ext_modules.order
fi
done
else
cp ${dep_file} ${OUT_AMLOGIC_DIR}/modules/modules.dep
fi
else
local MODULES_ROOT_DIR=$(echo ${MODULES_STAGING_DIR}/lib/modules/*)
pushd ${MODULES_ROOT_DIR}
local common_drivers=${COMMON_DRIVERS_DIR##*/}
local modules_list=$(find -type f -name "*.ko")
for module in ${modules_list}; do
if [[ -n ${ANDROID_PROJECT} ]]; then # copy internal build modules
if [[ `echo ${module} | grep -E "\.\/kernel\/|\/${common_drivers}\/"` ]]; then
cp ${module} ${OUT_AMLOGIC_DIR}/modules/
else
local match=
for ext_module in ${EXT_MODULES_ANDROID_AUTO_LOAD}; do
if [[ "${module}" =~ "${ext_module}" ]]; then
match=1
break
fi
done
if [[ ${match} == 1 ]]; then
cp ${module} ${OUT_AMLOGIC_DIR}/modules/
else
cp ${module} ${OUT_AMLOGIC_DIR}/ext_modules/
fi
fi
else
cp ${module} ${OUT_AMLOGIC_DIR}/modules/
fi
done
if [[ -n ${ANDROID_PROJECT} ]]; then # internal build modules
grep -E "^kernel\/|^${common_drivers}\/" modules.dep > ${OUT_AMLOGIC_DIR}/modules/modules.dep
dep_file=modules.dep
for ext_module in ${EXT_MODULES_ANDROID_AUTO_LOAD}; do
cat ${dep_file} | cut -d ':' -f 1 | grep -n "${ext_module}" | cut -d ':' -f 1 | while read line; do
sed -n ${line}p ${dep_file} >> ${OUT_AMLOGIC_DIR}/modules/modules.dep
done
done
else # all modules, include external modules
cp modules.dep ${OUT_AMLOGIC_DIR}/modules
fi
popd
fi
pushd ${OUT_AMLOGIC_DIR}/modules
sed -i 's#[^ ]*/##g' modules.dep
echo adjust_sequence_modules_loading
adjust_sequence_modules_loading "${arg1[*]}"
echo create_install_and_order_filles modules.order
create_install_and_order_filles modules.dep __install.sh modules.order
if [[ -n ${ANDROID_PROJECT} ]]; then
echo create_install_and_order_filles modules_recovery.order
create_install_and_order_filles modules_recovery.dep __install_recovery.sh modules_recovery.order
fi
create_ramdisk_vendor_recovery modules.order modules_recovery.order
if [[ -n ${MANUAL_INSMOD_MODULE} ]]; then
install_file=manual_install.sh
else
install_file=install.sh
fi
echo "#!/bin/sh" > ${install_file}
echo "cd ramdisk" >> ${install_file}
echo "./ramdisk_install.sh" >> ${install_file}
echo "cd ../vendor" >> ${install_file}
echo "./vendor_install.sh" >> ${install_file}
echo "cd ../" >> ${install_file}
chmod 755 ${install_file}
echo "/modules/: all `wc -l modules.dep | awk '{print $1}'` modules."
if [[ -n ${ANDROID_PROJECT} ]]; then
rm __install_recovery.sh __install_recovery.sh.tmp
fi
popd
if [[ ${BAZEL} == "1" ]]; then
cp ${DIST_DIR}/vmlinux ${OUT_AMLOGIC_DIR}/symbols
find ${BAZEL_OUT} -name *.ko | grep "unstripped" | while read module; do
cp ${module} ${OUT_AMLOGIC_DIR}/symbols
done
else
cp ${OUT_DIR}/vmlinux ${OUT_AMLOGIC_DIR}/symbols
find ${OUT_DIR} -type f -name "*.ko" -exec cp {} ${OUT_AMLOGIC_DIR}/symbols \;
for ext_module in ${EXT_MODULES}; do
find ${COMMON_OUT_DIR}/${ext_module} -type f -name "*.ko" -exec cp {} ${OUT_AMLOGIC_DIR}/symbols \;
done
fi
}
export -f modules_install
function rename_external_module_name() {
local external_coppied
sed 's/^[\t ]*\|[\t ]*$//g' ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/modules_rename.txt | sed '/^#/d;/^$/d' | sed 's/[[:space:]][[:space:]]*/ /g' | while read module_line; do
target_module_name=`echo ${module_line%%:*} | sed '/^#/d;/^$/d'`
modules_name=`echo ${module_line##:*} | sed '/^#/d;/^$/d'`
[[ -f ${OUT_AMLOGIC_DIR}/ext_modules/${target_module_name} ]] && external_coppied=1
echo target_module_name=$target_module_name modules_name=$modules_name external_coppied=$external_coppied
for module in ${modules_name}; do
echo module=$module
if [[ -f ${OUT_AMLOGIC_DIR}/ext_modules/${module} ]]; then
if [[ -z ${external_coppied} ]]; then
cp ${OUT_AMLOGIC_DIR}/ext_modules/${module} ${OUT_AMLOGIC_DIR}/ext_modules/${target_module_name}
external_coppied=1
fi
rm -f ${OUT_AMLOGIC_DIR}/ext_modules/${module}
fi
done
external_coppied=
done
}
export -f rename_external_module_name
# function rebuild_rootfs can rebuild the rootfs if rootfs_base.cpio.gz.uboot exist
function rebuild_rootfs() {
echo
echo "========================================================"
if [ -f ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/rootfs_base.cpio.gz.uboot ]; then
echo "Rebuild rootfs in order to install modules!"
else
echo "There's no file ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/rootfs_base.cpio.gz.uboot, so don't rebuild rootfs!"
return
fi
pushd ${OUT_AMLOGIC_DIR}
local ARCH=arm64
if [[ -n $1 ]]; then
ARCH=$1
fi
rm rootfs -rf
mkdir rootfs
cp ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/rootfs_base.cpio.gz.uboot rootfs
cd rootfs
dd if=rootfs_base.cpio.gz.uboot of=rootfs_base.cpio.gz bs=64 skip=1
gunzip rootfs_base.cpio.gz
mkdir rootfs
cd rootfs
fakeroot cpio -i -F ../rootfs_base.cpio
if [ -d ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/customer ]; then
cp ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/customer . -rf
fi
cp -rf ../../modules .
find . | fakeroot cpio -o -H newc | gzip > ../rootfs_new.cpio.gz
cd ../
mkimage -A ${ARCH} -O linux -T ramdisk -C none -d rootfs_new.cpio.gz rootfs_new.cpio.gz.uboot
mv rootfs_new.cpio.gz.uboot ../
cd ../
cp rootfs_new.cpio.gz.uboot ${DIST_DIR}
popd
}
export -f rebuild_rootfs
# function check_undefined_symbol can check the dependence among the modules
# parameter:
# --modules_depend
function check_undefined_symbol() {
if [[ ${MODULES_DEPEND} != "1" ]]; then
return
fi
echo "========================================================"
echo "print modules depend"
pushd ${OUT_AMLOGIC_DIR}/modules
echo