xref: /rkbin/tools/burner_image_kits/make.sh (revision 4e66ef7fd0f5107f0f1c3dd32a087231ee7a7a43)
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"/"idblock1.img
43		is_img_and_gen_file_from_src_2_dst idblock1.img
44		gen_idblock $ddr $spl $src_path"/"idblock2.img
45		is_img_and_gen_file_from_src_2_dst idblock2.img
46		gen_idblock $ddr $spl $src_path"/"idblock3.img
47		is_img_and_gen_file_from_src_2_dst idblock3.img
48		gen_idblock $ddr $spl $src_path"/"idblock4.img
49		is_img_and_gen_file_from_src_2_dst idblock4.img
50		rm $src_path"/"idblock*.img
51		rm $ddr
52		rm $spl
53		ret=1
54	fi
55
56	ls $1 | grep "update" > /dev/null
57	if [ $? -eq 0 ] ;then
58		ret=1
59	fi
60
61	ls $1 | grep "parameter.txt" > /dev/null
62	if [ $? -eq 0 ] ;then
63		$upgrade_tool gpt $1 $src_path"/"gpt.img > /dev/null
64		is_img_and_gen_file_from_src_2_dst gpt.img
65		rm $src_path"/"gpt.img
66		ret=1
67	fi
68
69	return $ret
70}
71
72function is_img_and_gen_file_from_src_2_dst()
73{
74	ls $src_path"/"$1 | grep "img" > /dev/null
75	if [ $? -eq 0 ] ;then
76		$align_to_flash_block_size $src_path"/"$1 $dst_path"/"$1 $block_size
77		if [ $is_slc_nand -eq 1 ] ;then
78			$rk_bch $dst_path"/"$1 $dst_path"/"$1".bch" $page_size $oob_size 0
79			mv $dst_path"/"$1".bch" $dst_path"/"$1
80			echo "$src_path"/"$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 != 256 ]]; then
105	echo "param oob_size: $oob_size not support!"
106	echo "support:"
107	echo "  64(B)"
108	echo "  128(B)"
109	echo "  256(B)"
110	exit
111fi
112fi
113
114if [[ $page_size != 2048 && $page_size != 4096 ]]; then
115	echo "param page_size: $page_size not support!"
116	echo "support:"
117	echo "  2048(B)"
118	echo "  4096(B)"
119	exit
120fi
121
122if [[ $block_size != 128 && $block_size != 256 ]]; then
123	echo "param block_size: $block_size not support!"
124	echo "support:"
125	echo "  128(KB)"
126	echo "  256(KB)"
127	exit
128fi
129
130if [[ $soc != "rk3308" && $soc != "rv1126" ]]; then
131	echo "param soc: $soc not support!"
132	echo "support:"
133	echo "  rk3308"
134	echo "  rv1126"
135	exit
136fi
137
138if [ -x "$dst_path" ]; then
139	rm -rf $dst_path
140fi
141
142dst_path=$dst_path"/"$page_size"B_"$block_size"KB"
143if [[ $is_slc_nand == 1 ]]; then
144	dst_path=$dst_path"_SLC"
145else
146	dst_path=$dst_path"_SPI"
147fi
148mkdir -p $dst_path
149
150for file in `ls -a $src_path`
151do
152	if [ -f $src_path"/"$file ] ;then
153		is_miniloader_or_update_or_parameter $src_path"/"$file
154		if [ $? -eq 0 ] ;then
155			is_img_and_gen_file_from_src_2_dst $file
156		fi
157	fi
158done
159