--- /dev/null
+#!/bin/sh -e
+# SeokYeon Hwang (syeon.hwang@samsung.com)
+
+SCRIPT=$(readlink -f $0)
+BASEDIR=$(dirname $SCRIPT)
+
+IMAGE_SIZE=5G
+ROOTFS_SIZE=2G
+SYSDATA_SIZE=1G
+USER_SIZE=2G
+
+check_util() {
+ TEMP=`which $1`
+ if [ -z $TEMP ]; then
+ if [ $2 = 1 ]; then
+ echo "'$1' is required."
+ exit 1
+ fi
+ return 1
+ fi
+ return 0
+}
+
+if [ ! -z $1 ]; then
+ SRC_IMG_FILE=$1
+fi
+EMUL_IMG_RAW_FILE=emul_img.raw
+EMUL_IMG_QCOW2_FILE=emul_img.qcow2
+EMUL_IMG_COMPRESSED_QCOW2_FILE=emul_img.compressed.qcow2
+
+# check prerequsite utils
+check_util resize2fs 1
+check_util dd 1
+check_util /bin/echo 1
+check_util $BASEDIR/../emulator/bin/qemu-img 0 || check_util $HOME/tizen-sdk/tools/emulator/bin/qemu-img 0 || check_util qemu-img 1
+QEMU_IMG=$TEMP
+
+# resize raw images
+if [ ! -z $SRC_IMG_FILE ]; then
+ resize2fs $SRC_IMG_FILE $IMAGE_SIZE
+ cp $SRC_IMG_FILE $EMUL_IMG_RAW_FILE
+elif [ -r emulator-rootfs.img ] && [ -r emulator-sysdata.img ] && [ -r emulator-user.img ]; then
+ PARTITIONIZED=1
+ resize2fs emulator-rootfs.img $ROOTFS_SIZE
+ resize2fs emulator-sysdata.img $SYSDATA_SIZE
+ resize2fs emulator-user.img $USER_SIZE
+elif [ -r emulator-rootfs.img ]; then
+ resize2fs emulator-rootfs.img $IMAGE_SIZE
+ cp emulator-rootfs.img $EMUL_IMG_RAW_FILE
+elif [ -r platform.img ]; then
+ resize2fs platform.img $IMAGE_SIZE
+ cp platform.img $EMUL_IMG_RAW_FILE
+else
+ echo "No rootfs image."
+ exit 1
+fi
+
+if [ ! -z $PARTITIONIZED ]; then
+ # generate space for partition table
+ dd if=/dev/zero of=temp_img.raw bs=1 count=0 seek=1M
+
+ # concatenate raw images into a single image
+ cat emulator-rootfs.img emulator-sysdata.img emulator-user.img >> temp_img.raw
+
+ # convert raw image to sparse type
+ cp --sparse=always temp_img.raw $EMUL_IMG_RAW_FILE
+ rm -f temp_img.raw
+
+ # partitioning image
+ /bin/echo -ne "n\np\n1\n\n+$ROOTFS_SIZE\nn\np\n2\n\n+$SYSDATA_SIZE\nn\np\n3\n\n\nw\n" | fdisk $EMUL_IMG_RAW_FILE
+fi
+
+# generate qcow2 image
+$QEMU_IMG convert -O qcow2 $EMUL_IMG_RAW_FILE $EMUL_IMG_QCOW2_FILE
+# generate compressed qcow2 image
+$QEMU_IMG convert -c -O qcow2 $EMUL_IMG_RAW_FILE $EMUL_IMG_COMPRESSED_QCOW2_FILE