1#!/bin/bash 2 3DIR="$( cd "$( dirname "$0" )" && pwd )" 4src_path=$1 5dst_path=$2 6soc=$3 7block_size=$4 8page_size=$5 9oob_size=$6 10is_slc_nand=$7 11 12ddr= 13spl= 14 15transfer_4K_2_2K=$DIR/tools/transfer_4K_2_2K.sh 16rk_bch=$DIR/tools/rk_bch 17mkimage=$DIR/../mkimage 18upgrade_tool=$DIR/../upgrade_tool 19align_to_flash_block_size=$DIR/tools/align_to_flash_block_size.sh 20boot_merger=$DIR/../boot_merger 21 22function gen_idblock() 23{ 24 $mkimage -n $soc -T rksd -d $1:$2 idblock1.img.temp > /dev/null 25 echo $3": gen_idblock: success!" 26 if [[ $is_slc_nand == 1 && $page_size == 4096 ]]; then 27 $transfer_4K_2_2K idblock1.img.temp $3 28 rm idblock1.img.temp 29 else 30 mv idblock1.img.temp $3 31 fi 32} 33 34function is_miniloader_or_update_or_parameter() 35{ 36 ret=0 37 ls $1 | grep "MiniLoaderAll.bin" > /dev/null 38 if [ $? -eq 0 ] ;then 39 $boot_merger unpack --loader $1 --output ./ > /dev/null 40 ddr=FlashData.bin 41 spl=FlashBoot.bin 42 gen_idblock $ddr $spl $src_path"/"idblock.img 43 is_img_and_gen_file_from_src_2_dst $src_path"/"idblock.img idblock.img 44 cat $dst_path"/"idblock.img >> $dst_path"/"idblocks.img 45 cat $dst_path"/"idblock.img >> $dst_path"/"idblocks.img 46 cat $dst_path"/"idblock.img >> $dst_path"/"idblocks.img 47 mv $dst_path"/"idblock.img $dst_path"/"idblock.img.bak 48 rm $src_path"/"idblock*.img 49 rm $ddr 50 rm $spl 51 52 ret=1 53 fi 54 55 ls $1 | grep "update" > /dev/null 56 if [ $? -eq 0 ] ;then 57 ret=1 58 fi 59 60 ls $1 | grep "parameter.txt" > /dev/null 61 if [ $? -eq 0 ] ;then 62 $upgrade_tool gpt $1 $src_path"/"gpt.img > /dev/null 63 is_img_and_gen_file_from_src_2_dst $src_path"/"gpt.img gpt.img 64 rm $src_path"/"gpt.img 65 ret=1 66 fi 67 68 return $ret 69} 70 71# source file absolute direction and name 72# output name 73function is_img_and_gen_file_from_src_2_dst() 74{ 75 ls $1 | grep "img" > /dev/null 76 if [ $? -eq 0 ] ;then 77 $align_to_flash_block_size $1 $dst_path"/"$2 $block_size 78 if [ $is_slc_nand -eq 1 ] ;then 79 $rk_bch $dst_path"/"$2 $dst_path"/"$2".bch" $page_size $oob_size 0 80 mv $dst_path"/"$2".bch" $dst_path"/"$2 81 echo "$1: rk_bch: success!" 82 fi 83 fi 84} 85 86if [ -f "$src_path" ]; then 87 echo "input error, $src_path is a file!" 88 exit 89fi 90 91if [ ! -x "$src_path" ]; then 92 echo "input error, $src_path not exit!" 93 exit 94fi 95 96if [[ $is_slc_nand != 0 && $is_slc_nand != 1 ]]; then 97 echo "param is_slc_nand: $is_slc_nand not support!" 98 echo "support:" 99 echo " 1(for SLC Nand, 8 pins io)" 100 echo " 0(others)" 101 exit 102fi 103 104if [ $is_slc_nand -eq 1 ] ;then 105 if [[ $oob_size != 64 && $oob_size != 128 && $oob_size != 224 && $oob_size != 256 ]]; then 106 echo "param oob_size: $oob_size not support!" 107 echo "support:" 108 echo " 64(B)" 109 echo " 128(B)" 110 echo " 224(B)" 111 echo " 256(B)" 112 exit 113fi 114fi 115 116if [[ $page_size != 2048 && $page_size != 4096 ]]; then 117 echo "param page_size: $page_size not support!" 118 echo "support:" 119 echo " 2048(B)" 120 echo " 4096(B)" 121 exit 122fi 123 124if [[ $block_size != 128 && $block_size != 256 ]]; then 125 echo "param block_size: $block_size not support!" 126 echo "support:" 127 echo " 128(KB)" 128 echo " 256(KB)" 129 exit 130fi 131 132if [[ $soc != "rk3308" && $soc != "rv1126" ]]; then 133 echo "param soc: $soc not support!" 134 echo "support:" 135 echo " rk3308" 136 echo " rv1126" 137 exit 138fi 139 140if [ -x "$dst_path" ]; then 141 rm -rf $dst_path 142fi 143 144dst_path=$dst_path"/"$page_size"B_"$block_size"KB" 145if [[ $is_slc_nand == 1 ]]; then 146 dst_path=$dst_path"_SLC" 147else 148 dst_path=$dst_path"_SPI" 149fi 150mkdir -p $dst_path 151 152for file in `ls -a $src_path` 153do 154 if [ -f $src_path"/"$file ] ;then 155 a=$src_path"/"$file 156 if [ -h $src_path"/"$file ] 157 then 158 a=$src_path"/"$file 159 b=`ls -ld $a|awk '{print $NF}'` 160 c=`ls -ld $a|awk '{print $(NF-2)}'` 161 [[ $b =~ ^/ ]] && a=$b || a=`dirname $c`/$b 162 fi 163 is_miniloader_or_update_or_parameter $a 164 if [ $? -eq 0 ] ;then 165 is_img_and_gen_file_from_src_2_dst $a $file 166 fi 167 fi 168done 169