hc
2024-11-15 a46a1ad097419aeea7350987dd95230f50d90392
commit | author | age
a07526 1 #!/bin/bash
H 2
3 DIR="$( cd "$( dirname "$0"  )" && pwd  )"
4 src_path=$1
5 dst_path=$2
6 soc=$3
7 block_size=$4
8 page_size=$5
9 oob_size=$6
10 is_slc_nand=$7
11
12 temp_path=./IMAGES_T
13 ddr=
14 spl=
15
16 transfer_4K_2_2K=$DIR/tools/transfer_4K_2_2K.sh
17 rk_bch=$DIR/tools/rk_bch
18 mkimage=$DIR/../mkimage
19 upgrade_tool=$DIR/../upgrade_tool
20 align_to_flash_block_size=$DIR/tools/align_to_flash_block_size.sh
21 boot_merger=$DIR/../boot_merger
22
23 function 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
35 function 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
69 function 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
82 if [ -f "$src_path" ]; then
83    echo "input error, $src_path is a file!"
84    exit
85 fi
86
87 if [ ! -x "$src_path" ]; then
88    echo "input error, $src_path not exit!"
89    exit
90 fi
91
92 if [[ $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
98 fi
99
100 if [ $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
109 fi
110 fi
111
112 if [[ $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
118 fi
119
120 if [[ $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
126 fi
127
128 if [[ $soc != "rk3308" && $soc != "rv1126" ]]; then
129    echo "param soc: $soc not support!"
130    echo "support:"
131    echo "  rk3308"
132    echo "  rv1126"
133    exit
134 fi
135
136 if [ -x "$dst_path" ]; then
137    rm -rf $dst_path
138 fi
139
140 if [ -x "$temp_path" ]; then
141    rm -rf $temp_path
142 fi
143 mkdir $temp_path
144
145 dst_path=$dst_path"/"$page_size"B_"$block_size"KB"
146 if [[ $is_slc_nand == 1 ]]; then
147    dst_path=$dst_path"_SLC"
148 else
149    dst_path=$dst_path"_SPI"
150 fi
151 mkdir -p $dst_path
152
153 for file in `ls -a $src_path`
154 do
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
182 done
183
184 echo "rm -rf $temp_path"
185 rm -rf $temp_path