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 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 gpt.img 63 rm $src_path"/"gpt.img 64 ret=1 65 fi 66 67 return $ret 68} 69 70function is_img_and_gen_file_from_src_2_dst() 71{ 72 ls $src_path"/"$1 | grep "img" > /dev/null 73 if [ $? -eq 0 ] ;then 74 $align_to_flash_block_size $src_path"/"$1 $dst_path"/"$1 $block_size 75 if [ $is_slc_nand -eq 1 ] ;then 76 $rk_bch $dst_path"/"$1 $dst_path"/"$1".bch" $page_size $oob_size 0 77 mv $dst_path"/"$1".bch" $dst_path"/"$1 78 echo "$src_path"/"$1: rk_bch: success!" 79 fi 80 fi 81} 82 83if [ -f "$src_path" ]; then 84 echo "input error, $src_path is a file!" 85 exit 86fi 87 88if [ ! -x "$src_path" ]; then 89 echo "input error, $src_path not exit!" 90 exit 91fi 92 93if [[ $is_slc_nand != 0 && $is_slc_nand != 1 ]]; then 94 echo "param is_slc_nand: $is_slc_nand not support!" 95 echo "support:" 96 echo " 1(for SLC Nand, 8 pins io)" 97 echo " 0(others)" 98 exit 99fi 100 101if [ $is_slc_nand -eq 1 ] ;then 102 if [[ $oob_size != 64 && $oob_size != 128 && $oob_size != 224 && $oob_size != 256 ]]; then 103 echo "param oob_size: $oob_size not support!" 104 echo "support:" 105 echo " 64(B)" 106 echo " 128(B)" 107 echo " 224(B)" 108 echo " 256(B)" 109 exit 110fi 111fi 112 113if [[ $page_size != 2048 && $page_size != 4096 ]]; then 114 echo "param page_size: $page_size not support!" 115 echo "support:" 116 echo " 2048(B)" 117 echo " 4096(B)" 118 exit 119fi 120 121if [[ $block_size != 128 && $block_size != 256 ]]; then 122 echo "param block_size: $block_size not support!" 123 echo "support:" 124 echo " 128(KB)" 125 echo " 256(KB)" 126 exit 127fi 128 129if [[ $soc != "rk3308" && $soc != "rv1126" ]]; then 130 echo "param soc: $soc not support!" 131 echo "support:" 132 echo " rk3308" 133 echo " rv1126" 134 exit 135fi 136 137if [ -x "$dst_path" ]; then 138 rm -rf $dst_path 139fi 140 141dst_path=$dst_path"/"$page_size"B_"$block_size"KB" 142if [[ $is_slc_nand == 1 ]]; then 143 dst_path=$dst_path"_SLC" 144else 145 dst_path=$dst_path"_SPI" 146fi 147mkdir -p $dst_path 148 149for file in `ls -a $src_path` 150do 151 if [ -f $src_path"/"$file ] ;then 152 is_miniloader_or_update_or_parameter $src_path"/"$file 153 if [ $? -eq 0 ] ;then 154 is_img_and_gen_file_from_src_2_dst $file 155 fi 156 fi 157done 158