Pass in the size of the UBI image

Allow user to pass in the size of the PNOR UBI image.
Default is 128.

Change-Id: Ifbd7ff0e9185e4d445f39be144f07eb907f0051e
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/generate-ubi b/generate-ubi
index 2633500..511edcb 100755
--- a/generate-ubi
+++ b/generate-ubi
@@ -13,8 +13,12 @@
                           `pwd`/<PNOR Tarball FILE, removing .squashfs.tar>.ubi.mtd
                           (For example, "generate-ubi my.pnor.squashfs.tar"
                           would generate `pwd`/my.pnor.ubi.mtd output.)
+   -s, --size <MiB>       Specify the size of the PNOR UBI image in MiBs.
+                          Defaults to 128.
    -h, --help             Display this help text and exit.
 '
+# 128MiB is the default image size
+image_size="128"
 
 while [[ $# -gt 0 ]]; do
   key="$1"
@@ -23,6 +27,10 @@
       outfile="$2"
       shift 2
       ;;
+    -s|--size)
+      image_size="$2"
+      shift 2
+      ;;
     -h|--help)
       echo "$help"
       exit
@@ -81,9 +89,9 @@
 FLASH_PAGE_SIZE="1"
 # kibibyte(KiB)
 FLASH_PEB_SIZE="64"
-# Future enhancement would be to allow this to be passed in
-# 128MiB (128 * 1024)
-FLASH_SIZE="131072"
+
+# Convert image size from MiB to KiB
+image_size=$((${image_size} * 1024))
 
 # Create UBI volume
 add_volume()
@@ -133,7 +141,7 @@
 
 # Build the UBI image
 ubinize -p ${FLASH_PEB_SIZE}KiB -m ${FLASH_PAGE_SIZE} -o ${tmpfile} $config_file
-mk_nor_image ${outfile} ${FLASH_SIZE}
+mk_nor_image ${outfile} ${image_size}
 dd bs=1k conv=notrunc seek=0 if=${tmpfile} of=${outfile}
 
 echo "PNOR UBI image at ${outfile}"