build.sh 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. #!/bin/bash
  2. export PATH=$PATH:/opt/mips-mti-elf/2020.06-01/bin
  3. COMPILE_VENDOR=$(basename $(dirname $(pwd)))
  4. COMPLIE_BOARD=$(basename $(pwd))
  5. DEBUG_VERSION=debug
  6. VERSION="code01align"
  7. DATE=`date +%Y%m%d`
  8. CURPATH=.
  9. ROOTPATH=../../..
  10. OUTPATH=$ROOTPATH/out
  11. PREBUILDPATH=./Prebuilds
  12. BUILD_PROJECT_PATH=$ROOTPATH/build
  13. TARGETOUTPATH=./out
  14. SILICON_DATA_FILE=$OUTPATH/ddr-Monitor_SOC.bin
  15. SILICON_DATA_DB_FILE=$OUTPATH/ddr-Monitor_SOC.bin-DB
  16. BOOT_FILE=$OUTPATH/silicon_boot.bin
  17. PM_FILE=pm.bin
  18. SUPERBLK_FILE=super.bin
  19. SILICON_DATA_FILE_COMPRESSED=ddr-Monitor_SOC_compressed.bin
  20. SILICON_DATA_FILE_DB_COMPRESSED=ddr-Monitor_SOC_compressed.bin-DB
  21. DATA_FILE_COMPRESSED=temp_data_compressed.bin
  22. search_files_cal_call_check() {
  23. local dir="$1"
  24. for file in "$dir"/*; do
  25. if [ -d "$file" ]; then
  26. search_files_cal_call_check "$file"
  27. elif [ -f "$file" ] && [[ "$file" == *hv_cal_* ]] && [ -n "$(grep -l 'Hv_Drv_' "$file")" ]; then
  28. echo "$file has called func: Hv_Drv_"
  29. exit
  30. elif [ -f "$file" ] && [[ "$file" == *hv_cal_* ]] && [ -n "$(grep -l 'Hv_Mw_' "$file")" ]; then
  31. echo "$file has called func: Hv_Mw_"
  32. exit
  33. elif [ -f "$file" ] && [[ "$file" == *hv_cal_* ]] && [ -n "$(grep -l 'HvPlat_' "$file")" ]; then
  34. echo "$file has called func: HvPlat_"
  35. exit
  36. elif [ -f "$file" ] && [[ "$file" == *hv_cal_* ]] && [ -n "$(grep -l 'Hv_App_' "$file")" ]; then
  37. echo "$file has called func: Hv_App_"
  38. exit
  39. fi
  40. done
  41. }
  42. search_files_drv_call_check() {
  43. local dir="$1"
  44. for file in "$dir"/*; do
  45. if [ -d "$file" ]; then
  46. search_files_drv_call_check "$file"
  47. elif [ -f "$file" ] && [[ "$file" == *hv_drv_* ]] && [ -n "$(grep -l 'Hv_Mw_' "$file")" ]; then
  48. echo "$file has called func: Hv_Mw_"
  49. exit
  50. elif [ -f "$file" ] && [[ "$file" == *hv_drv_* ]] && [ -n "$(grep -l 'HvPlat_' "$file")" ]; then
  51. echo "$file has called func: HvPlat_"
  52. exit
  53. elif [ -f "$file" ] && [[ "$file" == *hv_drv_* ]] && [ -n "$(grep -l 'Hv_App_' "$file")" ]; then
  54. echo "$file has called func: Hv_App_"
  55. exit
  56. fi
  57. done
  58. }
  59. search_files_mw_call_check() {
  60. local dir="$1"
  61. for file in "$dir"/*; do
  62. if [ -d "$file" ]; then
  63. search_files_mw_call_check "$file"
  64. elif [ -f "$file" ] && [[ "$file" == *hv_mw_* ]] && [ -n "$(grep -l 'HvPlat_' "$file")" ]; then
  65. echo "$file has called func: HvPlat_"
  66. exit
  67. elif [ -f "$file" ] && [[ "$file" == *hv_mw_* ]] && [ -n "$(grep -l 'Hv_App_' "$file")" ]; then
  68. echo "$file has called func: Hv_App_"
  69. exit
  70. fi
  71. done
  72. }
  73. search_files_plat_file_check() {
  74. local dir="$1"
  75. for file in "$dir"/*; do
  76. if [ -d "$file" ]; then
  77. search_files_plat_file_check "$file"
  78. elif [ -f "$file" ] && [[ "$file" == *HvPlat* ]]; then
  79. echo "$file in sdk"
  80. exit
  81. fi
  82. done
  83. }
  84. search_files_plat_call_app() {
  85. local dir="$1"
  86. for file in "$dir"/*; do
  87. if [ -d "$file" ]; then
  88. search_files_plat_call_app "$file"
  89. elif [ -f "$file" ] && [[ "$file" == *HvPlat* ]] && [ -n "$(grep -l 'Hv_App_' "$file")" ]; then
  90. echo "$file has called func: Hv_App_"
  91. exit
  92. fi
  93. done
  94. }
  95. code_check(){
  96. cd $ROOTPATH/sdk/Driver
  97. search_files_cal_call_check "."
  98. search_files_drv_call_check "."
  99. search_files_mw_call_check "."
  100. search_files_plat_file_check "."
  101. cd -
  102. search_files_cal_call_check "."
  103. search_files_drv_call_check "."
  104. search_files_mw_call_check "."
  105. search_files_plat_call_app "."
  106. }
  107. cmake_project(){
  108. cd $BUILD_PROJECT_PATH
  109. bash project_config.sh $COMPILE_VENDOR $COMPLIE_BOARD ht7315
  110. make clean
  111. make $DEBUG_VERSION -j
  112. cd -
  113. if [ ! -f $SILICON_TEXT_RO_FILE ]; then
  114. echo "APP build fail, NO APP FILE-${SILICON_TEXT_RO_FILE}!"
  115. exit
  116. fi
  117. if [ ! -f $SILICON_DATA_FILE ]; then
  118. echo "APP build fail, NO APP FILE-${SILICON_DATA_FILE}!"
  119. exit
  120. fi
  121. return 0
  122. }
  123. get_git_revision(){
  124. GITREV=`git rev-parse --short HEAD`
  125. echo "GIT revision: $GITREV"
  126. }
  127. compressed_file_size(){
  128. FILE_SIZE=`wc -c < $1`
  129. echo "$1 size: $FILE_SIZE"
  130. echo "HIVIEW!" > hiview.bin
  131. echo $FILE_SIZE > size.bin
  132. cat hiview.bin size.bin > ${1}_size
  133. dd if=${1}_size of=${1}_size_aline32 ibs=32 conv=sync
  134. }
  135. pad_file(){
  136. echo "padding file"
  137. input_size=$(wc -c < $1)
  138. cp $1 $1_temp
  139. echo $input_size
  140. padding_size=$(($2-$input_size))
  141. cat $1_temp > $3
  142. echo $padding_size
  143. dd if=/dev/zero bs=1 count=$padding_size|tr "\000" "\377" >> $3
  144. }
  145. superblkOffset=$(printf "%d" 0)
  146. TEMP_CRC=$(printf "%x" 0)
  147. add_super_blk(){
  148. echo $1 $2 $3
  149. if [ "$3" = "0" ]; then
  150. echo "no padding for $2"
  151. cp $2 $2_padded;
  152. else
  153. echo "padding for $2"
  154. pad_file $2 $3 $2_padded
  155. fi
  156. echo -n "SBLK" >> $SUPERBLK_FILE
  157. string=$1
  158. result=0
  159. substring=${string:0:4}
  160. # 将每个字符转换为ASCII码值并拼接成32位的数
  161. for ((i=0; i<${#substring}; i++)); do
  162. char_code=$(printf "%d" "'${substring:i:1}")
  163. result=$(( (result << 8) | char_code ))
  164. done
  165. hex=$(printf "%08X" $result)
  166. echo $hex
  167. echo -n -e "\x${hex:0:2}\x${hex:2:2}\x${hex:4:2}\x${hex:6:2}" >> $SUPERBLK_FILE
  168. length=`wc -c < $2`
  169. hex=$(printf "%08X" $length)
  170. echo $hex
  171. echo -n -e "\x${hex:0:2}\x${hex:2:2}\x${hex:4:2}\x${hex:6:2}" >> $SUPERBLK_FILE
  172. hex=$(printf "%08X" $superblkOffset)
  173. echo $hex
  174. echo -n -e "\x${hex:0:2}\x${hex:2:2}\x${hex:4:2}\x${hex:6:2}" >> $SUPERBLK_FILE
  175. length=`wc -c < $2_padded`
  176. superblkOffset=$(($superblkOffset+$length))
  177. echo $VERSION >> $SUPERBLK_FILE
  178. crc=$(cksum $2 | cut -f1 -d' ')
  179. hex=$(printf "%08X" $crc)
  180. TEMP_CRC=${hex}
  181. echo $hex
  182. echo -n -e "\x${hex:0:2}\x${hex:2:2}\x${hex:4:2}\x${hex:6:2}" >> $SUPERBLK_FILE
  183. }
  184. pqOffset=$(printf "%d" 4096)
  185. add_pq_bin(){
  186. echo $1 $2 $3 $4
  187. echo "HEAD:add file $1"
  188. echo -n "HEAD" >> $TARGETOUTPATH/header.bin
  189. hex=$(printf "%04X" $3)
  190. echo $hex
  191. echo -n -e "\x${hex:0:2}\x${hex:2:2}" >> $TARGETOUTPATH/header.bin
  192. hex=$(printf "%04X" $4)
  193. echo $hex
  194. echo -n -e "\x${hex:0:2}\x${hex:2:2}" >> $TARGETOUTPATH/header.bin
  195. size=$(stat -c%s $PREBUILDPATH/$1)
  196. echo $size
  197. hex=$(printf "%08X" $size)
  198. echo -n -e "\x${hex:0:2}\x${hex:2:2}\x${hex:4:2}\x${hex:6:2}" >> $TARGETOUTPATH/header.bin
  199. echo $pqOffset
  200. hex=$(printf "%08X" $pqOffset)
  201. echo $hex
  202. echo -n -e "\x${hex:0:2}\x${hex:2:2}\x${hex:4:2}\x${hex:6:2}" >> $TARGETOUTPATH/header.bin
  203. offset=$((($size + 511) / 512 * 512))
  204. echo $offset
  205. hex=$(printf "%08X" $offset)
  206. echo $hex
  207. cp $PREBUILDPATH/$1 $TARGETOUTPATH/$1
  208. pad_file $TARGETOUTPATH/$1 $offset $TARGETOUTPATH/$1_pad
  209. pqOffset=$(($pqOffset+$offset))
  210. dd if=$TARGETOUTPATH/$1_pad of=$2 conv=notrunc oflag=append
  211. }
  212. find_multy_bin(){
  213. rm -rf $TARGETOUTPATH/$1.bin
  214. for ((i=1; i<=10; i++))
  215. do
  216. if [ -e $PREBUILDPATH/$1_$i.bin ]; then
  217. add_pq_bin $1_$i.bin $2 $3 $i
  218. else
  219. break
  220. fi
  221. done
  222. }
  223. find_pq_bin(){
  224. if [ -e $PREBUILDPATH/$1.bin ]; then
  225. echo "file $1"
  226. rm -rf $TARGETOUTPATH/$1.bin
  227. add_pq_bin $1.bin $2 $3 1
  228. elif [ -e $PREBUILDPATH/$1_1.bin ]; then
  229. echo " multy file $1"
  230. find_multy_bin $1 $2 $3
  231. else
  232. echo "no file $1"
  233. return;
  234. fi
  235. nodeOffset=$(($nodeOffset+16))
  236. }
  237. if [ "$1" = "nocompile" ]; then
  238. echo "$1"
  239. cd $BUILD_PROJECT_PATH
  240. bash project_config.sh $COMPILE_VENDOR $COMPLIE_BOARD ht7315
  241. cd -
  242. exit -1
  243. fi
  244. echo "vendor: $COMPILE_VENDOR"
  245. echo "board: $COMPLIE_BOARD"
  246. echo "date: $DATE"
  247. get_git_revision
  248. rm -rf $OUTPATH/Monitor_SOC_*.bin
  249. echo "code check******************************"
  250. code_check
  251. echo "Complie Bin*****************************"
  252. cmake_project
  253. if [ ! -x "$TARGETOUTPATH" ];then
  254. echo "$TARGETOUTPATH"
  255. mkdir $TARGETOUTPATH
  256. fi
  257. echo "Merge PQData*****************************"
  258. rm -rf $TARGETOUTPATH/temp_pq.bin
  259. rm -rf $TARGETOUTPATH/header.bin
  260. find_pq_bin pq_init_reg $TARGETOUTPATH/temp_pq.bin 1
  261. find_pq_bin dither $TARGETOUTPATH/temp_pq.bin 2
  262. find_pq_bin scl $TARGETOUTPATH/temp_pq.bin 3
  263. find_pq_bin ldc $TARGETOUTPATH/temp_pq.bin 4
  264. find_pq_bin od $TARGETOUTPATH/temp_pq.bin 5
  265. find_pq_bin contrast $TARGETOUTPATH/temp_pq.bin 6
  266. find_pq_bin yccm $TARGETOUTPATH/temp_pq.bin 7
  267. find_pq_bin sharpness $TARGETOUTPATH/temp_pq.bin 8
  268. find_pq_bin contrast_para $TARGETOUTPATH/temp_pq.bin 9
  269. find_pq_bin sharpness_para $TARGETOUTPATH/temp_pq.bin 10
  270. find_pq_bin gamma_t $TARGETOUTPATH/temp_pq.bin 11
  271. find_pq_bin gamma_d $TARGETOUTPATH/temp_pq.bin 12
  272. find_pq_bin osd_gmd $TARGETOUTPATH/temp_pq.bin 13
  273. find_pq_bin osd_gmi $TARGETOUTPATH/temp_pq.bin 14
  274. find_pq_bin wcg_cm $TARGETOUTPATH/temp_pq.bin 15
  275. find_pq_bin wcg_gmd $TARGETOUTPATH/temp_pq.bin 16
  276. find_pq_bin wcg_gmi $TARGETOUTPATH/temp_pq.bin 17
  277. find_pq_bin hdr $TARGETOUTPATH/temp_pq.bin 18
  278. find_pq_bin demura $TARGETOUTPATH/temp_pq.bin 19
  279. pad_file $TARGETOUTPATH/header.bin 4096 $TARGETOUTPATH/pad_header.bin
  280. cat $TARGETOUTPATH/pad_header.bin $TARGETOUTPATH/temp_pq.bin > $TARGETOUTPATH/temp_header_pq.bin
  281. echo "Merge PQData over*************************"
  282. echo "compress bin******************************"
  283. $PREBUILDPATH/LZSS e $SILICON_DATA_DB_FILE $TARGETOUTPATH/$SILICON_DATA_FILE_DB_COMPRESSED
  284. echo "compress bin"
  285. $PREBUILDPATH/LZSS e $SILICON_DATA_FILE $TARGETOUTPATH/$SILICON_DATA_FILE_COMPRESSED
  286. echo "compress bin"
  287. $PREBUILDPATH/LZSS e $TARGETOUTPATH/temp_header_pq.bin $TARGETOUTPATH/$DATA_FILE_COMPRESSED
  288. echo "compress bin over*************************"
  289. echo "Merge ALLBin*****************************"
  290. cp $OUTPATH/*.bin $TARGETOUTPATH/
  291. cp $OUTPATH/*.bin-DB $TARGETOUTPATH/
  292. cd $TARGETOUTPATH/
  293. compressed_file_size $SILICON_DATA_FILE_COMPRESSED
  294. compressed_file_size $SILICON_DATA_FILE_DB_COMPRESSED
  295. compressed_file_size $DATA_FILE_COMPRESSED
  296. pad_file $PM_FILE 32768 temp_pm.bin_padded
  297. cp temp_pm.bin_padded $SUPERBLK_FILE
  298. cat ${SILICON_DATA_FILE_COMPRESSED}_size_aline32 $SILICON_DATA_FILE_COMPRESSED > temp_silicon_data.bin
  299. echo d >> pmsb.bin
  300. pad_file pmsb.bin 36864 pmsb.bin_padded
  301. add_super_blk PMSB pmsb.bin_padded 36864
  302. add_super_blk BOOT silicon_boot.bin 61440
  303. add_super_blk BTBK silicon_boot.bin-DB 61440
  304. add_super_blk CODE temp_silicon_data.bin 1335296
  305. CODE_CRC=${TEMP_CRC}
  306. SHORT_CRC=${CODE_CRC: -4}
  307. LOGO_BIN_NAME=$(grep -w 'HV_PROJECT_CONFIG_LOGO_BIN_NAME' ../ProjectConfig.h | head -n 1 | awk -F' ' '{gsub(/[(]/,""); gsub(/[)]/,""); print $3}' | sed 's/\r$//' | tr -d '\r' | tr -d '"')
  308. if [ "$LOGO_BIN_NAME" = "" ]; then
  309. LOGO_BIN_NAME=Logo.bin
  310. fi
  311. if [ -e ../Prebuilds/${LOGO_BIN_NAME} ]; then
  312. echo $LOGO_BIN_NAME
  313. else
  314. echo ERROR:no $LOGO_BIN_NAME
  315. exit
  316. fi
  317. cp ../Prebuilds/${LOGO_BIN_NAME} ./Logo.bin
  318. add_super_blk LOGO Logo.bin 131072
  319. cat ${DATA_FILE_COMPRESSED}_size_aline32 $DATA_FILE_COMPRESSED > temp_pq_data.bin
  320. add_super_blk PQDA temp_pq_data.bin 405504
  321. cp ../Prebuilds/ConfigData.bin ./ConfigData.bin
  322. add_super_blk CFIG ConfigData.bin 65536
  323. pad_file ${SUPERBLK_FILE} 36864 ${SUPERBLK_FILE}_ota_padded
  324. touch null.bin
  325. add_super_blk FULL null.bin 0
  326. pad_file ${SUPERBLK_FILE} 36864 ${SUPERBLK_FILE}_full_padded
  327. cat ${SUPERBLK_FILE}_ota_padded silicon_boot.bin_padded silicon_boot.bin-DB_padded temp_silicon_data.bin > ../Monitor_SOC_${COMPILE_VENDOR}_${COMPLIE_BOARD}_${DATE}_GIT${GITREV}_OTA.bin
  328. #not pad pq and monitordata
  329. cat ${SUPERBLK_FILE}_full_padded silicon_boot.bin_padded silicon_boot.bin-DB_padded temp_silicon_data.bin_padded Logo.bin_padded temp_pq_data.bin > ../Monitor_SOC_${COMPILE_VENDOR}_${COMPLIE_BOARD}_${DATE}_GIT${GITREV}_FLASH.bin
  330. pad_file silicon_boot.bin 61440 silicon_boot.bin_padded
  331. pad_file silicon_boot.bin-DB 61440 silicon_boot.bin_padded-DB
  332. echo ${CODE_CRC}
  333. cat silicon_boot.bin_padded silicon_boot.bin_padded-DB temp_silicon_data.bin > ../USB-OTA.bin
  334. echo -n ${CODE_CRC} | xxd -r -p >> ../USB-OTA.bin
  335. cd -
  336. mv USB-OTA.bin $OUTPATH/His7315Upgrade.bin
  337. mv Monitor_SOC_* $OUTPATH/
  338. mv out $OUTPATH/compressed
  339. echo "Merge Bin Finish**********************"