xref: /rkbin/tools/burner_image_kits/make.sh (revision 75f45d5e792ed483083afd8c0a85db2d4e787f84)
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 != 256 ]]; then
103	echo "param oob_size: $oob_size not support!"
104	echo "support:"
105	echo "  64(B)"
106	echo "  128(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
140dst_path=$dst_path"/"$page_size"B_"$block_size"KB"
141if [[ $is_slc_nand == 1 ]]; then
142	dst_path=$dst_path"_SLC"
143else
144	dst_path=$dst_path"_SPI"
145fi
146mkdir -p $dst_path
147
148for file in `ls -a $src_path`
149do
150	if [ -f $src_path"/"$file ] ;then
151		is_miniloader_or_update_or_parameter $src_path"/"$file
152		if [ $? -eq 0 ] ;then
153			is_img_and_gen_file_from_src_2_dst $file
154		fi
155	fi
156done
157