blob: 234ab0e874c3cb69236c60c067742fe18725a198 [file] [log] [blame]
wanwei.jiang91776952021-11-19 13:10:32 +08001#!/bin/bash
2
3function pre_defconfig_cmds() {
wanwei.jiang5c8d2b62021-11-26 20:36:33 +08004 if [[ ${AMLOGIC_USERDEBUG} -eq "1" ]]; then
5 echo "CONFIG_AMLOGIC_USERDEBUG=y" >> ${ROOT_DIR}/${FRAGMENT_CONFIG}
6 else
7 echo "CONFIG_AMLOGIC_USERDEBUG=n" >> ${ROOT_DIR}/${FRAGMENT_CONFIG}
8 fi
9
10 if [[ ${AMLOGIC_NONGKI} -eq "1" ]]; then
wanwei.jiang91776952021-11-19 13:10:32 +080011 echo "CONFIG_AMLOGIC_NONGKI=y" >> ${ROOT_DIR}/${FRAGMENT_CONFIG}
12 SKIP_EXT_MODULES=1
13 export SKIP_EXT_MODULES
14 EXT_MODULES=
15 export EXT_MODULES
wanwei.jiang5c8d2b62021-11-26 20:36:33 +080016 else
17 echo "CONFIG_AMLOGIC_NONGKI=n" >> ${ROOT_DIR}/${FRAGMENT_CONFIG}
wanwei.jiang91776952021-11-19 13:10:32 +080018 fi
19 KCONFIG_CONFIG=${ROOT_DIR}/${KERNEL_DIR}/arch/arm64/configs/${DEFCONFIG} ${ROOT_DIR}/${KERNEL_DIR}/scripts/kconfig/merge_config.sh -m -r ${ROOT_DIR}/${KERNEL_DIR}/arch/arm64/configs/gki_defconfig ${ROOT_DIR}/${FRAGMENT_CONFIG}
20}
21export -f pre_defconfig_cmds
22
23function post_defconfig_cmds() {
wanwei.jiang612a8882021-11-23 17:12:23 +080024 # check_defconfig
wanwei.jiang91776952021-11-19 13:10:32 +080025 rm ${ROOT_DIR}/${KERNEL_DIR}/arch/arm64/configs/${DEFCONFIG}
26 pushd ${ROOT_DIR}/common_drivers
wanwei.jiang5c8d2b62021-11-26 20:36:33 +080027 sed -i '5,${/CONFIG_AMLOGIC_USERDEBUG/d}' ${ROOT_DIR}/${FRAGMENT_CONFIG}
28 sed -i '5,${/CONFIG_AMLOGIC_NONGKI/d}' ${ROOT_DIR}/${FRAGMENT_CONFIG}
wanwei.jiang91776952021-11-19 13:10:32 +080029 popd
30}
31export -f post_defconfig_cmds
32
33function read_ext_module_config() {
34 ALL_LINE=""
35 while read LINE
36 do
37 if [[ $LINE != \#* && $LINE != "" ]]; then
38 ALL_LINE="$ALL_LINE"" ""$LINE"
39 fi
40 done < $1
41 export GKI_EXT_MODULE_CONFIG=$ALL_LINE
42 echo "GKI_EXT_MODULE_CONFIG=${GKI_EXT_MODULE_CONFIG}"
43}
44
45function read_ext_module_predefine() {
46 PRE_DEFINE=""
47
48 for y_config in `cat $1 | grep "^CONFIG_.*=y" | sed 's/=y//'`;
49 do
50 PRE_DEFINE="$PRE_DEFINE"" -D"${y_config}
51 done
52
53 for m_config in `cat $1 | grep "^CONFIG_.*=m" | sed 's/=m//'`;
54 do
55 PRE_DEFINE="$PRE_DEFINE"" -D"${m_config}_MODULE
56 done
57
58 export GKI_EXT_MODULE_PREDEFINE=$PRE_DEFINE
59 echo "GKI_EXT_MODULE_PREDEFINE=${GKI_EXT_MODULE_PREDEFINE}"
60}
61
62function prepare_module_build() {
63 if [[ -z ${AMLOGIC_NONGKI} ]]; then
64 read_ext_module_config $FRAGMENT_CONFIG && read_ext_module_predefine $FRAGMENT_CONFIG
65 fi
66}
67
68export -f prepare_module_build
wanwei.jiang612a8882021-11-23 17:12:23 +080069
70function mod_probe() {
71 local ko=$1
72 local loop
73 for loop in `grep "$ko:" modules.dep | sed 's/.*://'`;
74 do
75 mod_probe $loop
76 echo insmod $loop >> __install.sh
77 done
78}
79
80function modules_install() {
wanwei.jiang236e9a32021-12-07 16:34:14 +080081 pushd ${DIST_DIR}
wanwei.jiang612a8882021-11-23 17:12:23 +080082 rm modules -rf
83 mkdir modules
84 cp *.ko modules
85
86 local stagin_module=$(echo ${MODULES_STAGING_DIR}/lib/modules/*)
87 echo stagin_module=${stagin_module}
88 cp ${stagin_module}/modules.dep modules
89
90 cd modules
91 sed -i 's#[^ ]*/##g' modules.dep
92
wanwei.jiang5c8d2b62021-11-26 20:36:33 +080093 touch __install.sh
wanwei.jiang612a8882021-11-23 17:12:23 +080094 for loop in `cat modules.dep | sed 's/:.*//'`; do
95 mod_probe $loop
96 echo insmod $loop >> __install.sh
97 done
98
99 cat __install.sh | awk ' {
100 if (!cnt[$2]) {
101 print $0;
102 cnt[$2]++;
103 }
104 }' > __install.sh.tmp
105
106 cp __install.sh.tmp __install.sh
107
108 sed -i '1s/^/#!\/bin\/sh\n\nset -ex\n/' __install.sh
109 echo "echo Install modules success!" >> __install.sh
110 chmod 777 __install.sh
111
112 echo "#!/bin/sh" > install.sh
113 # echo "./__install.sh || reboot" >> install.sh
114 echo "./__install.sh" >> install.sh
115 chmod 777 install.sh
116
117 echo "/modules/: all `wc -l modules.dep | awk '{print $1}'` modules."
118
119 cd ../
wanwei.jiang236e9a32021-12-07 16:34:14 +0800120 popd
wanwei.jiang612a8882021-11-23 17:12:23 +0800121}
wanwei.jiang236e9a32021-12-07 16:34:14 +0800122export -f modules_install
wanwei.jiang612a8882021-11-23 17:12:23 +0800123
124function rebuild_rootfs() {
125 pushd ${DIST_DIR}
126
wanwei.jiang612a8882021-11-23 17:12:23 +0800127 rm rootfs -rf
128 mkdir rootfs
129 cp ${ROOT_DIR}/common_drivers/rootfs_base.cpio.gz.uboot rootfs
130 cd rootfs
131 dd if=rootfs_base.cpio.gz.uboot of=rootfs_base.cpio.gz bs=64 skip=1
132 gunzip rootfs_base.cpio.gz
133 mkdir rootfs
134 cd rootfs
135 cpio -i -F ../rootfs_base.cpio
136 cp -rf ../../modules .
137 find . | cpio -o -H newc | gzip > ../rootfs_new.cpio.gz
138 cd ../
139 mkimage -A arm64 -O linux -T ramdisk -C none -d rootfs_new.cpio.gz rootfs_new.cpio.gz.uboot
140 mv rootfs_new.cpio.gz.uboot ../
141 cd ../
142
143 popd
144}
145export -f rebuild_rootfs
wanwei.jiang403c9942021-11-30 18:29:02 +0800146
147function check_undefined_symbol() {
wanwei.jiang236e9a32021-12-07 16:34:14 +0800148 pushd ${DIST_DIR}/modules
wanwei.jiang403c9942021-11-30 18:29:02 +0800149 echo
150 echo "========================================================"
151 echo "Functions or variables not defined in this module refer to which module."
wanwei.jiang236e9a32021-12-07 16:34:14 +0800152 nm ../vmlinux | grep -E " T | D | B | R | W "> vmlinux_T.txt
wanwei.jiang403c9942021-11-30 18:29:02 +0800153 cat __install.sh | grep "insmod" | cut -d ' ' -f 2 > module_list.txt
154 while read LINE
155 do
156 echo ${LINE}
157 for U in `nm ${LINE} | grep " U " | sed -e 's/^\s*//' -e 's/\s*$//' | cut -d ' ' -f 2`
158 do
159 #echo ${U}
160 U_v=`grep -w ${U} vmlinux_T.txt`
161 in_vmlinux=0
162 if [ -n "${U_v}" ];
163 then
wanwei.jiangd7b29ef2021-12-01 19:59:41 +0800164 #printf "\t%-50s <== vmlinux\n" ${U}
wanwei.jiang403c9942021-11-30 18:29:02 +0800165 in_vmlinux=1
166 continue
167 fi
168 in_module=0
169 MODULE=
170 while read LINE1
171 do
wanwei.jiangd7b29ef2021-12-01 19:59:41 +0800172 U_m=`nm ${LINE1} | grep -E " T | D | B | R " | grep -v "\.cfi_jt" | grep "${U}"`
wanwei.jiang403c9942021-11-30 18:29:02 +0800173 if [ -n "${U_m}" ];
174 then
175 in_module=1
176 MODULE=${LINE1}
177 fi
178 done < module_list.txt
179 if [ ${in_module} -eq "1" ];
180 then
181 printf "\t%-50s <== %s\n" ${U} ${MODULE}
182 continue
183 else
184 printf "\t%-50s <== none\n" ${U}
185 fi
186 done
187 echo
188 echo
189 done < module_list.txt
190 rm vmlinux_T.txt
191 rm module_list.txt
192 popd
193}
194export -f check_undefined_symbol