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