#!/bin/bash

# source files
src=$1
# generate image
dst=$2

# the size of generate image, get info from parameter.txt
# eg. 0x00040000@0x00016000(rootfs)
# calculate size fo rootfs partition: 0x00040000 * 512 / 1024 /1024 = 128M
dst_size=$3

cwd=$(dirname $(readlink -f $0))

rm -f $dst

$cwd/e2fsprogs-1.43.9/mkfs.ext4 -d $src -r 1 -N 0 -m 5 -L "" -O ^64bit,^huge_file $dst "$dst_size" 
if [ $? != 0 ]; then 
	echo "*** Maybe you need to increase the filesystem size "
	exit 1
fi
$cwd/e2fsprogs-1.43.9/resize2fs -M $dst
$cwd/e2fsprogs-1.43.9/e2fsck -fy  $dst
$cwd/e2fsprogs-1.43.9/tune2fs -m 5  $dst
$cwd/e2fsprogs-1.43.9/resize2fs -M $dst
