blob: 434e9fed248957245dd2fb81a675b305c2ac4812 [file] [log] [blame]
wanwei.jiang91776952021-11-19 13:10:32 +08001#!/bin/bash
2
3function pre_defconfig_cmds() {
wanwei.jiang91776952021-11-19 13:10:32 +08004 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}
5}
6export -f pre_defconfig_cmds
7
8function post_defconfig_cmds() {
wanwei.jiang1482c872022-05-13 20:33:51 +08009 if [[ ${CHECK_DEFCONFIG} -eq "1" ]]; then
10 check_defconfig
11 fi
wanwei.jiang91776952021-11-19 13:10:32 +080012 rm ${ROOT_DIR}/${KERNEL_DIR}/arch/arm64/configs/${DEFCONFIG}
wanwei.jiang91776952021-11-19 13:10:32 +080013}
14export -f post_defconfig_cmds
15
16function read_ext_module_config() {
17 ALL_LINE=""
18 while read LINE
19 do
20 if [[ $LINE != \#* && $LINE != "" ]]; then
21 ALL_LINE="$ALL_LINE"" ""$LINE"
22 fi
23 done < $1
wanwei.jiang5c861ae2022-04-21 00:51:50 +080024
25 echo "${ALL_LINE}"
wanwei.jiang91776952021-11-19 13:10:32 +080026}
27
28function read_ext_module_predefine() {
29 PRE_DEFINE=""
30
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +080031 for y_config in `cat $1 | grep "^CONFIG_.*=y" | sed 's/=y//'`; do
wanwei.jiang91776952021-11-19 13:10:32 +080032 PRE_DEFINE="$PRE_DEFINE"" -D"${y_config}
33 done
34
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +080035 for m_config in `cat $1 | grep "^CONFIG_.*=m" | sed 's/=m//'`; do
wanwei.jiang91776952021-11-19 13:10:32 +080036 PRE_DEFINE="$PRE_DEFINE"" -D"${m_config}_MODULE
37 done
38
wanwei.jiang5c861ae2022-04-21 00:51:50 +080039 echo "${PRE_DEFINE}"
wanwei.jiang91776952021-11-19 13:10:32 +080040}
41
wanwei.jiang8d4a5132022-04-28 16:43:54 +080042top_ext_drivers=top_ext_drivers
wanwei.jiang91776952021-11-19 13:10:32 +080043function prepare_module_build() {
wanwei.jiang5c861ae2022-04-21 00:51:50 +080044 local temp_file=`mktemp /tmp/kernel.XXXXXXXXXXXX`
wanwei.jiangb9ad1ef2021-12-27 15:23:30 +080045 if [[ -z ${IN_KERNEL_MODULES} ]]; then
wanwei.jiang5c861ae2022-04-21 00:51:50 +080046 sed 's:#.*$::g' ${ROOT_DIR}/${FRAGMENT_CONFIG} | sed '/^$/d' | sed 's/^[ ]*//' | sed 's/[ ]*$//' > ${temp_file}
47 GKI_EXT_KERNEL_MODULE_CONFIG=$(read_ext_module_config ${temp_file})
48 GKI_EXT_KERNEL_MODULE_PREDEFINE=$(read_ext_module_predefine ${temp_file})
49 export GKI_EXT_KERNEL_MODULE_CONFIG GKI_EXT_KERNEL_MODULE_PREDEFINE
wanwei.jiang91776952021-11-19 13:10:32 +080050 fi
wanwei.jiang5c861ae2022-04-21 00:51:50 +080051
52 for ext_module_config in ${EXT_MODULES_CONFIG}; do
53 sed 's:#.*$::g' ${ROOT_DIR}/${ext_module_config} | sed '/^$/d' | sed 's/^[ ]*//' | sed 's/[ ]*$//' > ${temp_file}
54 GKI_EXT_MODULE_CONFIG=$(read_ext_module_config ${temp_file})
55 GKI_EXT_MODULE_PREDEFINE=$(read_ext_module_predefine ${temp_file})
56 done
57 export GKI_EXT_MODULE_CONFIG GKI_EXT_MODULE_PREDEFINE
58 echo GKI_EXT_MODULE_CONFIG=${GKI_EXT_MODULE_CONFIG}
59 echo GKI_EXT_MODULE_PREDEFINE=${GKI_EXT_MODULE_PREDEFINE}
60
61 local flag=0
wanwei.jiangcb5c4c82022-04-25 16:47:24 +080062 ext_modules=
63 for ext_module in ${EXT_MODULES}; do
64 ext_modules="${ext_modules} ${ext_module}"
65 done
wanwei.jiang8d4a5132022-04-28 16:43:54 +080066 if [[ -d ${top_ext_drivers} ]]; then
67 rm -rf ${top_ext_drivers}
68 fi
69 mkdir -p ${top_ext_drivers}
wanwei.jiang5c861ae2022-04-21 00:51:50 +080070 for ext_module_path in ${EXT_MODULES_PATH}; do
71 sed 's:#.*$::g' ${ROOT_DIR}/${ext_module_path} | sed '/^$/d' | sed 's/^[ ]*//' | sed 's/[ ]*$//' > ${temp_file}
wanwei.jiang5c861ae2022-04-21 00:51:50 +080072 extra_symbols="KBUILD_EXTRA_SYMBOLS +="
73 while read LINE
74 do
wanwei.jiang8d4a5132022-04-28 16:43:54 +080075 module_abs_path=`readlink -e ${LINE}`
76 module_rel_path=$(rel_path ${module_abs_path} ${ROOT_DIR})
77 if [[ `echo ${module_rel_path} | grep "\.\."` ]]; then
78 cp -rf ${module_abs_path} ${top_ext_drivers}
79 module_rel_path=${top_ext_drivers}/${module_abs_path##*/}
80 fi
81 ext_modules="${ext_modules} ${module_rel_path}"
82
83 ext_mod_rel=$(rel_path ${module_rel_path} ${KERNEL_DIR})
wanwei.jiang5c861ae2022-04-21 00:51:50 +080084 if [[ ${flag} -eq "1" ]]; then
wanwei.jiang8d4a5132022-04-28 16:43:54 +080085 sed -i "/# auto add KBUILD_EXTRA_SYMBOLS start/,/# auto add KBUILD_EXTRA_SYMBOLS end/d" ${module_rel_path}/Makefile
86 sed -i "2 i # auto add KBUILD_EXTRA_SYMBOLS end" ${module_rel_path}/Makefile
87 sed -i "2 i ${extra_symbols}" ${module_rel_path}/Makefile
88 sed -i "2 i # auto add KBUILD_EXTRA_SYMBOLS start" ${module_rel_path}/Makefile
89 echo "${module_rel_path}/Makefile add: ${extra_symbols}"
wanwei.jiang5c861ae2022-04-21 00:51:50 +080090 fi
91 flag=1
92 extra_symbols="${extra_symbols} ${ext_mod_rel}/Module.symvers"
93 done < ${temp_file}
wanwei.jiang5c861ae2022-04-21 00:51:50 +080094 done
wanwei.jiangcb5c4c82022-04-25 16:47:24 +080095 EXT_MODULES=${ext_modules}
wanwei.jiang5c861ae2022-04-21 00:51:50 +080096 export EXT_MODULES
97 echo EXT_MODULES=${EXT_MODULES}
98
99 rm ${temp_file}
wanwei.jiang91776952021-11-19 13:10:32 +0800100}
101
102export -f prepare_module_build
wanwei.jiang612a8882021-11-23 17:12:23 +0800103
wanwei.jiang5c861ae2022-04-21 00:51:50 +0800104function extra_cmds() {
105 local temp_file=`mktemp /tmp/kernel.XXXXXXXXXXXX`
106 local flag=0
107
108 for ext_module_path in ${EXT_MODULES_PATH}; do
109 sed 's:#.*$::g' ${ROOT_DIR}/${ext_module_path} | sed '/^$/d' | sed 's/^[ ]*//' | sed 's/[ ]*$//' > ${temp_file}
110 while read LINE
111 do
wanwei.jiang8d4a5132022-04-28 16:43:54 +0800112 module_abs_path=`readlink -e ${LINE}`
wanwei.jiang5c861ae2022-04-21 00:51:50 +0800113 if [[ ${flag} -eq "1" ]]; then
wanwei.jiang8d4a5132022-04-28 16:43:54 +0800114 sed -i "/# auto add KBUILD_EXTRA_SYMBOLS start/,/# auto add KBUILD_EXTRA_SYMBOLS end/d" ${module_abs_path}/Makefile
wanwei.jiang5c861ae2022-04-21 00:51:50 +0800115 fi
116 flag=1
117 done < ${temp_file}
118 done
119
120 rm ${temp_file}
wanwei.jiang8d4a5132022-04-28 16:43:54 +0800121 if [[ -d ${top_ext_drivers} ]]; then
122 rm -rf ${top_ext_drivers}
123 fi
wanwei.jiang3eab75f2022-05-25 00:39:52 +0800124
125 for FILE in ${FILES}; do
126 if [[ "${FILE}" =~ \.dtbo ]] && \
127 [ -n "${DTS_EXT_DIR}" ] && [ -f "${OUT_DIR}/${DTS_EXT_DIR}/${FILE}" ] ; then
128 MKDTIMG_DTBOS="${MKDTIMG_DTBOS} ${DIST_DIR}/${FILE}"
129 fi
130 done
131 export MKDTIMG_DTBOS
132
133 modules_install
134
135 local src_dir=$(echo ${MODULES_STAGING_DIR}/lib/modules/*)
136 pushd ${src_dir}
137 : > modules.order
138 while read LINE
139 do
140 find -name ${LINE} >> modules.order
141 done < ${DIST_DIR}/modules/modules.order
142 sed -i 's/..//' modules.order
143 for EXT_MOD in ${EXT_MODULES}; do
144 ext_modules_order_file=$(ls extra/${EXT_MOD}/modules.order.*)
145 : > ${ext_modules_order_file}
146 done
147 popd
wanwei.jiang1d154992022-05-30 14:56:26 +0800148
149 if [[ -z ${ANDROID_PROJECT} ]]; then
150 FILES="$FILES `ls ${OUT_DIR}/${DTS_EXT_DIR}`"
151 fi
wanwei.jiang5c861ae2022-04-21 00:51:50 +0800152}
153
154export -f extra_cmds
155
wanwei.jiang612a8882021-11-23 17:12:23 +0800156function mod_probe() {
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800157 local ko=$1
158 local loop
159 for loop in `grep "$ko:" modules.dep | sed 's/.*://'`; do
160 mod_probe $loop
161 echo insmod $loop >> __install.sh
162 done
wanwei.jiang612a8882021-11-23 17:12:23 +0800163}
164
wanwei.jiangb12abc82021-12-25 22:17:10 +0800165function adjust_sequence_modules_loading() {
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800166 if [[ -n $1 ]]; then
167 chips=$1
wanwei.jiangb12abc82021-12-25 22:17:10 +0800168 fi
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800169
170 source ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/scripts/amlogic/modules_sequence_list
171 cp modules.dep modules.dep.temp
172
173 soc_module=()
174 for chip in ${chips[@]}; do
175 chip_module=`ls amlogic-*-soc-${chip}.ko`
176 soc_module=(${soc_module[@]} ${chip_module[@]})
177 done
178 echo soc_module=${soc_module[*]}
179
180 delete_soc_module=()
181 if [[ ${#soc_module[@]} == 0 ]]; then
182 echo "Use all soc module"
183 else
184 for module in `ls amlogic-*-soc-*`; do
185 if [[ ! "${soc_module[@]}" =~ "${module}" ]] ; then
186 echo Delete soc module: ${module}
187 sed -n "/${module}:/p" modules.dep.temp
188 sed -i "/${module}:/d" modules.dep.temp
189 delete_soc_module=(${delete_soc_module[@]} ${module})
190 fi
191 done
192 echo delete_soc_module=${delete_soc_module[*]}
193 fi
194
195 delete_module=()
wanwei.jiang50759e12022-03-24 12:36:17 +0800196 for module in ${MODULES_LOAD_BLACK_LIST[@]}; do
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800197 modules=`ls ${module}*`
198 delete_module=(${delete_module[@]} ${modules[@]})
199 done
200 if [[ ${#delete_module[@]} == 0 ]]; then
wanwei.jiang50759e12022-03-24 12:36:17 +0800201 echo "No delete module, MODULES_LOAD_BLACK_LIST=${MODULES_LOAD_BLACK_LIST[*]}"
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800202 else
203 echo delete_module=${delete_module[*]}
204 for module in ${delete_module[@]}; do
205 echo Delete module: ${module}
206 sed -n "/${module}:/p" modules.dep.temp
207 sed -i "/${module}:/d" modules.dep.temp
208 done
209 fi
210
211 cat modules.dep.temp | cut -d ':' -f 2 > modules.dep.temp1
212 delete_modules=(${delete_soc_module[@]} ${delete_module[@]})
213 for module in ${delete_modules[@]}; do
214 match=`sed -n "/${module}/=" modules.dep.temp1`
215 for match in ${match[@]}; do
216 match_count=(${match_count[@]} $match)
217 done
218 if [[ ${#match_count[@]} != 0 ]]; then
219 echo "Error ${#match_count[@]} modules depend on ${module}, please modify:"
wanwei.jiang50759e12022-03-24 12:36:17 +0800220 echo ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/scripts/amlogic/modules_sequence_list:MODULES_LOAD_BLACK_LIST
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800221 exit
222 fi
223 rm -f ${module}
224 done
225 rm -f modules.dep.temp1
wanwei.jiangb12abc82021-12-25 22:17:10 +0800226 touch modules.dep.temp1
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800227
228 for module in ${RAMDISK_MODULES_LOAD_LIST[@]}; do
229 echo RAMDISK_MODULES_LOAD_LIST: $module
wanwei.jiangb12abc82021-12-25 22:17:10 +0800230 sed -n "/${module}:/p" modules.dep.temp
231 sed -n "/${module}:/p" modules.dep.temp >> modules.dep.temp1
232 sed -i "/${module}:/d" modules.dep.temp
233 sed -n "/${module}.*\.ko:/p" modules.dep.temp
234 sed -n "/${module}.*\.ko:/p" modules.dep.temp >> modules.dep.temp1
235 sed -i "/${module}.*\.ko:/d" modules.dep.temp
236 done
237
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800238 for module in ${VENDOR_MODULES_LOAD_FIRST_LIST[@]}; do
239 echo VENDOR_MODULES_LOAD_FIRST_LIST: $module
240 sed -n "/${module}:/p" modules.dep.temp
241 sed -n "/${module}:/p" modules.dep.temp >> modules.dep.temp1
242 sed -i "/${module}:/d" modules.dep.temp
243 sed -n "/${module}.*\.ko:/p" modules.dep.temp
244 sed -n "/${module}.*\.ko:/p" modules.dep.temp >> modules.dep.temp1
245 sed -i "/${module}.*\.ko:/d" modules.dep.temp
wanwei.jiangb12abc82021-12-25 22:17:10 +0800246 done
247
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800248 if [ -f modules.dep.temp2 ]; then
249 rm modules.dep.temp2
250 fi
251 touch modules.dep.temp2
252 for module in ${VENDOR_MODULES_LOAD_LAST_LIST[@]}; do
253 echo VENDOR_MODULES_LOAD_FIRST_LIST: $module
254 sed -n "/${module}:/p" modules.dep.temp
255 sed -n "/${module}:/p" modules.dep.temp >> modules.dep.temp2
256 sed -i "/${module}:/d" modules.dep.temp
257 sed -n "/${module}.*\.ko:/p" modules.dep.temp
258 sed -n "/${module}.*\.ko:/p" modules.dep.temp >> modules.dep.temp2
259 sed -i "/${module}.*\.ko:/d" modules.dep.temp
260 done
261
262 cat modules.dep.temp >> modules.dep.temp1
263 cat modules.dep.temp2 >> modules.dep.temp1
264
wanwei.jiangb12abc82021-12-25 22:17:10 +0800265 cp modules.dep.temp1 modules.dep
266 rm modules.dep.temp
267 rm modules.dep.temp1
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800268 rm modules.dep.temp2
269}
270
qinglin.lie5b951e2022-06-07 16:13:44 +0800271create_ramdisk_vendor() {
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800272 install_temp=$1
273 source ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/scripts/amlogic/modules_sequence_list
274 last_ramdisk_module=${RAMDISK_MODULES_LOAD_LIST[${#RAMDISK_MODULES_LOAD_LIST[@]}-1]}
275 last_ramdisk_module_line=`sed -n "/${last_ramdisk_module}/=" ${install_temp}`
276 for line in ${last_ramdisk_module_line}; do
277 ramdisk_last_line=${line}
278 done
279 head -n ${ramdisk_last_line} ${install_temp} > ramdisk_install.sh
wanwei.jiang50759e12022-03-24 12:36:17 +0800280 mkdir ramdisk
281 cat ramdisk_install.sh | cut -d ' ' -f 2 | xargs mv -t ramdisk/
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800282
qinglin.lie5b951e2022-06-07 16:13:44 +0800283 sed -i '1s/^/#!\/bin\/sh\n\nset -x\n/' ramdisk_install.sh
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800284 echo "echo Install ramdisk modules success!" >> ramdisk_install.sh
285 chmod 755 ramdisk_install.sh
wanwei.jiang50759e12022-03-24 12:36:17 +0800286 mv ramdisk_install.sh ramdisk/
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800287
288 file_last_line=`sed -n "$=" ${install_temp}`
289 let line=${file_last_line}-${ramdisk_last_line}
290 tail -n ${line} ${install_temp} > vendor_install.sh
wanwei.jiang50759e12022-03-24 12:36:17 +0800291 mkdir vendor
292 cat vendor_install.sh | cut -d ' ' -f 2 | xargs mv -t vendor/
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800293
qinglin.lie5b951e2022-06-07 16:13:44 +0800294 sed -i '1s/^/#!\/bin\/sh\n\nset -x\n/' vendor_install.sh
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800295 echo "echo Install vendor modules success!" >> vendor_install.sh
296 chmod 755 vendor_install.sh
wanwei.jiang50759e12022-03-24 12:36:17 +0800297 mv vendor_install.sh vendor/
wanwei.jiangb12abc82021-12-25 22:17:10 +0800298}
299
wanwei.jiang612a8882021-11-23 17:12:23 +0800300function modules_install() {
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800301 arg1=$1
302
wanwei.jiang236e9a32021-12-07 16:34:14 +0800303 pushd ${DIST_DIR}
wanwei.jiang612a8882021-11-23 17:12:23 +0800304 rm modules -rf
305 mkdir modules
wanwei.jiang8abddcc2022-03-16 21:18:48 +0800306 local modules_list=$(find ${MODULES_STAGING_DIR}/lib/modules -type f -name "*.ko")
wanwei.jiang67a191d2022-04-18 20:39:13 +0800307 #cp ${modules_list} modules
308 for module in ${modules_list}; do
309 cp ${module} modules/
310 done
wanwei.jiang612a8882021-11-23 17:12:23 +0800311
312 local stagin_module=$(echo ${MODULES_STAGING_DIR}/lib/modules/*)
313 echo stagin_module=${stagin_module}
314 cp ${stagin_module}/modules.dep modules
315
316 cd modules
317 sed -i 's#[^ ]*/##g' modules.dep
318
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800319 adjust_sequence_modules_loading "${arg1[*]}"
wanwei.jiangb12abc82021-12-25 22:17:10 +0800320
wanwei.jiang5c8d2b62021-11-26 20:36:33 +0800321 touch __install.sh
wanwei.jiang3eab75f2022-05-25 00:39:52 +0800322 touch modules.order
wanwei.jiang612a8882021-11-23 17:12:23 +0800323 for loop in `cat modules.dep | sed 's/:.*//'`; do
324 mod_probe $loop
wanwei.jiang3eab75f2022-05-25 00:39:52 +0800325 echo $loop >> modules.order
wanwei.jiang612a8882021-11-23 17:12:23 +0800326 echo insmod $loop >> __install.sh
327 done
328
329 cat __install.sh | awk ' {
330 if (!cnt[$2]) {
331 print $0;
332 cnt[$2]++;
333 }
334 }' > __install.sh.tmp
335
qinglin.lie5b951e2022-06-07 16:13:44 +0800336 create_ramdisk_vendor __install.sh.tmp
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800337
wanwei.jiang612a8882021-11-23 17:12:23 +0800338 cp __install.sh.tmp __install.sh
339
wanwei.jiang50759e12022-03-24 12:36:17 +0800340 #sed -i '1s/^/#!\/bin\/sh\n\nset -ex\n/' __install.sh
341 #echo "echo Install modules success!" >> __install.sh
342 #chmod 755 __install.sh
wanwei.jiang612a8882021-11-23 17:12:23 +0800343
344 echo "#!/bin/sh" > install.sh
345 # echo "./__install.sh || reboot" >> install.sh
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800346 # echo "./__install.sh" >> install.sh
wanwei.jiang50759e12022-03-24 12:36:17 +0800347 echo "cd ramdisk" >> install.sh
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800348 echo "./ramdisk_install.sh" >> install.sh
wanwei.jiang50759e12022-03-24 12:36:17 +0800349 echo "cd ../vendor" >> install.sh
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800350 echo "./vendor_install.sh" >> install.sh
wanwei.jiang50759e12022-03-24 12:36:17 +0800351 echo "cd ../" >> install.sh
wanwei.jiang0a8d6ee2022-03-23 09:36:19 +0800352 chmod 755 install.sh
wanwei.jiang612a8882021-11-23 17:12:23 +0800353
354 echo "/modules/: all `wc -l modules.dep | awk '{print $1}'` modules."
wanwei.jiang50759e12022-03-24 12:36:17 +0800355 rm __install.sh __install.sh.tmp modules.dep
wanwei.jiang612a8882021-11-23 17:12:23 +0800356
357 cd ../
wanwei.jiang236e9a32021-12-07 16:34:14 +0800358 popd
wanwei.jiang612a8882021-11-23 17:12:23 +0800359}
wanwei.jiang236e9a32021-12-07 16:34:14 +0800360export -f modules_install
wanwei.jiang612a8882021-11-23 17:12:23 +0800361
362function rebuild_rootfs() {
363 pushd ${DIST_DIR}
364
Lei Zhang475c17b2022-03-03 11:08:50 +0800365 local ARCH=arm64
366 if [[ -n $1 ]]; then
367 ARCH=$1
368 fi
369
wanwei.jiang612a8882021-11-23 17:12:23 +0800370 rm rootfs -rf
371 mkdir rootfs
wanwei.jiang7ef5fd42022-02-18 16:36:19 +0800372 cp ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/rootfs_base.cpio.gz.uboot rootfs
wanwei.jiang612a8882021-11-23 17:12:23 +0800373 cd rootfs
374 dd if=rootfs_base.cpio.gz.uboot of=rootfs_base.cpio.gz bs=64 skip=1
375 gunzip rootfs_base.cpio.gz
376 mkdir rootfs
377 cd rootfs
378 cpio -i -F ../rootfs_base.cpio
wanwei.jiang7ef5fd42022-02-18 16:36:19 +0800379 if [ -d ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/customer ]; then
380 cp ${ROOT_DIR}/${KERNEL_DIR}/${COMMON_DRIVERS_DIR}/customer . -rf
qinglin.li3c25dbb2022-01-14 11:23:10 +0800381 fi
wanwei.jiang612a8882021-11-23 17:12:23 +0800382 cp -rf ../../modules .
wanwei.jiang8abddcc2022-03-16 21:18:48 +0800383
wanwei.jiang2c818dc2022-03-24 17:48:00 +0800384 #modules_modules=`ls modules/*.ko`
385 ramdisk_modules=`ls modules/ramdisk/*.ko`
386 vendor_modules=`ls modules/vendor/*.ko`
387 strip_modules=(${modules_modules[@]} ${ramdisk_modules[@]} ${vendor_modules[@]})
wanwei.jiang8abddcc2022-03-16 21:18:48 +0800388 if [[ -n ${LLVM} ]]; then
wanwei.jiang2c818dc2022-03-24 17:48:00 +0800389 for module in ${strip_modules[@]}; do
wanwei.jiang8abddcc2022-03-16 21:18:48 +0800390 ${ROOT_DIR}/${CLANG_PREBUILT_BIN}/llvm-objcopy --strip-debug ${module}
391 done
392 elif [[ -n ${CROSS_COMPILE} ]]; then
wanwei.jiang2c818dc2022-03-24 17:48:00 +0800393 for module in ${strip_modules[@]}; do
wanwei.jiang8abddcc2022-03-16 21:18:48 +0800394 ${CROSS_COMPILE}objcopy --strip-debug ${module}
395 done
396 else
wanwei.jiang2c818dc2022-03-24 17:48:00 +0800397 echo "can't find compile tool"
wanwei.jiang8abddcc2022-03-16 21:18:48 +0800398 fi
399
wanwei.jiang612a8882021-11-23 17:12:23 +0800400 find . | cpio -o -H newc | gzip > ../rootfs_new.cpio.gz
401 cd ../
Lei Zhang475c17b2022-03-03 11:08:50 +0800402 mkimage -A ${ARCH} -O linux -T ramdisk -C none -d rootfs_new.cpio.gz rootfs_new.cpio.gz.uboot
wanwei.jiang612a8882021-11-23 17:12:23 +0800403 mv rootfs_new.cpio.gz.uboot ../
404 cd ../
405
406 popd
407}
408export -f rebuild_rootfs
wanwei.jiang403c9942021-11-30 18:29:02 +0800409
410function check_undefined_symbol() {
wanwei.jiang236e9a32021-12-07 16:34:14 +0800411 pushd ${DIST_DIR}/modules
wanwei.jiang403c9942021-11-30 18:29:02 +0800412 echo
413 echo "========================================================"
414 echo "Functions or variables not defined in this module refer to which module."
wanwei.jiang2c818dc2022-03-24 17:48:00 +0800415 if [[ -n ${LLVM} ]]; then
416 compile_tool=${ROOT_DIR}/${CLANG_PREBUILT_BIN}/llvm-
417 elif [[ -n ${CROSS_COMPILE} ]]; then
418 compile_tool=${CROSS_COMPILE}
419 else
420 echo "can't find compile tool"
421 fi
422 ${compile_tool}nm ../vmlinux | grep -E " T | D | B | R | W "> vmlinux_T.txt
423 # cat __install.sh | grep "insmod" | cut -d ' ' -f 2 > module_list.txt
424 cat ramdisk/ramdisk_install.sh | grep "insmod" | cut -d ' ' -f 2 > module_list.txt
425 cat vendor/vendor_install.sh | grep "insmod" | cut -d ' ' -f 2 >> module_list.txt
426 cp ramdisk/*.ko .
427 cp vendor/*.ko .
wanwei.jiang403c9942021-11-30 18:29:02 +0800428 while read LINE
429 do
430 echo ${LINE}
wanwei.jiang2c818dc2022-03-24 17:48:00 +0800431 for U in `${compile_tool}nm ${LINE} | grep " U " | sed -e 's/^\s*//' -e 's/\s*$//' | cut -d ' ' -f 2`
wanwei.jiang403c9942021-11-30 18:29:02 +0800432 do
433 #echo ${U}
434 U_v=`grep -w ${U} vmlinux_T.txt`
435 in_vmlinux=0
436 if [ -n "${U_v}" ];
437 then
wanwei.jiangd7b29ef2021-12-01 19:59:41 +0800438 #printf "\t%-50s <== vmlinux\n" ${U}
wanwei.jiang403c9942021-11-30 18:29:02 +0800439 in_vmlinux=1
440 continue
441 fi
442 in_module=0
443 MODULE=
444 while read LINE1
445 do
wanwei.jiang2c818dc2022-03-24 17:48:00 +0800446 U_m=`${compile_tool}nm ${LINE1} | grep -E " T | D | B | R " | grep -v "\.cfi_jt" | grep "${U}"`
wanwei.jiang403c9942021-11-30 18:29:02 +0800447 if [ -n "${U_m}" ];
448 then
449 in_module=1
450 MODULE=${LINE1}
451 fi
452 done < module_list.txt
453 if [ ${in_module} -eq "1" ];
454 then
455 printf "\t%-50s <== %s\n" ${U} ${MODULE}
456 continue
457 else
458 printf "\t%-50s <== none\n" ${U}
459 fi
460 done
461 echo
462 echo
463 done < module_list.txt
464 rm vmlinux_T.txt
465 rm module_list.txt
wanwei.jiang2c818dc2022-03-24 17:48:00 +0800466 rm *.ko
wanwei.jiang403c9942021-11-30 18:29:02 +0800467 popd
468}
469export -f check_undefined_symbol