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 $1 > /dev/null 40 ddr=FlashData 41 spl=FlashBoot 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 ret=1 52 fi 53 54 ls $1 | grep "update" > /dev/null 55 if [ $? -eq 0 ] ;then 56 ret=1 57 fi 58 59 ls $1 | grep "parameter.txt" > /dev/null 60 if [ $? -eq 0 ] ;then 61 $upgrade_tool gpt $1 $src_path"/"gpt.img > /dev/null 62 is_img_and_gen_file_from_src_2_dst $src_path"/"gpt.img gpt.img 63 rm $src_path"/"gpt.img 64 ret=1 65 fi 66 67 return $ret 68} 69 70# source file absolute direction and name 71# output name 72function is_img_and_gen_file_from_src_2_dst() 73{ 74 ls $1 | grep "img" > /dev/null 75 if [ $? -eq 0 ] ;then 76 $align_to_flash_block_size $1 $dst_path"/"$2 $block_size 77 if [ $is_slc_nand -eq 1 ] ;then 78 $rk_bch $dst_path"/"$2 $dst_path"/"$2".bch" $page_size $oob_size 0 79 mv $dst_path"/"$2".bch" $dst_path"/"$2 80 echo "$1: rk_bch: success!" 81 fi 82 fi 83} 84 85if [ -f "$src_path" ]; then 86 echo "input error, $src_path is a file!" 87 exit 88fi 89 90if [ ! -x "$src_path" ]; then 91 echo "input error, $src_path not exit!" 92 exit 93fi 94 95if [[ $is_slc_nand != 0 && $is_slc_nand != 1 ]]; then 96 echo "param is_slc_nand: $is_slc_nand not support!" 97 echo "support:" 98 echo " 1(for SLC Nand, 8 pins io)" 99 echo " 0(others)" 100 exit 101fi 102 103if [ $is_slc_nand -eq 1 ] ;then 104 if [[ $oob_size != 64 && $oob_size != 128 && $oob_size != 224 && $oob_size != 256 ]]; then 105 echo "param oob_size: $oob_size not support!" 106 echo "support:" 107 echo " 64(B)" 108 echo " 128(B)" 109 echo " 224(B)" 110 echo " 256(B)" 111 exit 112fi 113fi 114 115if [[ $page_size != 2048 && $page_size != 4096 ]]; then 116 echo "param page_size: $page_size not support!" 117 echo "support:" 118 echo " 2048(B)" 119 echo " 4096(B)" 120 exit 121fi 122 123if [[ $block_size != 128 && $block_size != 256 ]]; then 124 echo "param block_size: $block_size not support!" 125 echo "support:" 126 echo " 128(KB)" 127 echo " 256(KB)" 128 exit 129fi 130 131if [[ $soc != "rk3308" && $soc != "rv1126" ]]; then 132 echo "param soc: $soc not support!" 133 echo "support:" 134 echo " rk3308" 135 echo " rv1126" 136 exit 137fi 138 139if [ -x "$dst_path" ]; then 140 rm -rf $dst_path 141fi 142 143dst_path=$dst_path"/"$page_size"B_"$block_size"KB" 144if [[ $is_slc_nand == 1 ]]; then 145 dst_path=$dst_path"_SLC" 146else 147 dst_path=$dst_path"_SPI" 148fi 149mkdir -p $dst_path 150 151for file in `ls -a $src_path` 152do 153 if [ -f $src_path"/"$file ] ;then 154 a=$src_path"/"$file 155 if [ -h $src_path"/"$file ] 156 then 157 a=$src_path"/"$file 158 b=`ls -ld $a|awk '{print $NF}'` 159 c=`ls -ld $a|awk '{print $(NF-2)}'` 160 [[ $b =~ ^/ ]] && a=$b || a=`dirname $c`/$b 161 fi 162 is_miniloader_or_update_or_parameter $a 163 if [ $? -eq 0 ] ;then 164 is_img_and_gen_file_from_src_2_dst $a $file 165 fi 166 fi 167done 168