Create SquashFS Image

Change-Id: I6897db7d67a7d9b6f2beb250356a810e7932dada
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/generate-squashfs b/generate-squashfs
index 1207684..e9eb9e6 100755
--- a/generate-squashfs
+++ b/generate-squashfs
@@ -7,6 +7,8 @@
 usage: generate-squashfs [OPTION]
 
 Options:
+   -f, --file <file>      Specify destination file. Defaults to
+                          `pwd`/pnor.xz.squashfs if unspecified.
    -h, --help             Display this help text and exit.
 '
 
@@ -32,9 +34,15 @@
 "OCC"
 )
 
+outfile=`pwd`"/pnor.xz.squashfs"
+
 while [[ $# -gt 0 ]]; do
   key="$1"
   case $key in
+    -f|--file)
+      outfile="$2"
+      shift 2
+      ;;
     -h|--help)
       echo "$help"
       exit
@@ -46,8 +54,19 @@
   esac
 done
 
+scratch_dir=`mktemp -d` || exit 1
+
 for partition in "${partitions[@]}"; do
   echo "Reading ${partition}..."
-  pflash_cmd="pflash --partition=${partition} --read=/tmp/${partition}"
+  pflash_cmd="pflash --partition=${partition} --read=${scratch_dir}/${partition}"
   ${pflash_cmd} || exit 1
 done
+
+echo "Creating SquashFS image..."
+
+cd "${scratch_dir}"
+squashfs_cmd="mksquashfs ${partitions[*]} ${outfile}"
+${squashfs_cmd} || exit 1
+
+echo "SquashFS Image at ${outfile}"
+rm -r "${scratch_dir}"