xref: /OK3568_Linux_fs/rkbin/tools/burner_image_kits/tools/align_to_flash_block_size.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1#!/bin/bash
2# align_to_flash_block_size.sh
3# param1: path-to-file
4# param2: flash block size
5
6input=$1
7out=$2
8block_size=$3
9
10function gen_file() {
11	filename=$1
12	output_file=$2
13
14	# get file align size
15	filesize=`stat -c "%s" $filename`
16	filesize=`echo "scale=0; (($filesize + 1023) / 1024 + $block_size - 1) / $block_size * $block_size" | bc`
17
18	# gen file
19	`dd if=/dev/zero of=$output_file bs=1K count=$filesize > /dev/null 2>&1`
20	`dd if=$filename of=$output_file bs=1K count=$filesize conv=notrunc > /dev/null 2>&1`
21	echo $filename": aligned_to_flash_block_size "$block_size"KB: success!"
22}
23
24if [[ $block_size != 128 && $block_size != 256 ]]; then
25  echo "$block_size not support!"
26  echo "support:"
27  echo "  128(KB)"
28  echo "  256(KB)"
29  exit
30fi
31
32if [ ! -f "$input" ]; then
33  echo "$input not exist!"
34  exit
35fi
36
37if [ -f "$out" ]; then
38  rm $out
39  exit
40fi
41
42gen_file $input $out
43