mkimage: Move argument processing into its own function

At present main() is very long. Split out the argument processing to make
it easier to follow.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/mkimage.c b/tools/mkimage.c
index facebcd..a465fa3 100644
--- a/tools/mkimage.c
+++ b/tools/mkimage.c
@@ -67,18 +67,9 @@
 	fprintf(stderr, "\n");
 }
 
-int main(int argc, char **argv)
+static void process_args(int argc, char **argv)
 {
-	int ifd = -1;
-	struct stat sbuf;
 	char *ptr;
-	int retval = 0;
-	struct image_type_params *tparams = NULL;
-	int pad_len = 0;
-	int dfd;
-
-	params.cmdname = *argv;
-	params.addr = params.ep = 0;
 
 	while (--argc > 0 && **++argv == '-') {
 		while (*++*argv) {
@@ -90,7 +81,7 @@
 				if ((--argc <= 0) ||
 					(params.arch =
 					genimg_get_arch_id (*++argv)) < 0)
-					usage ();
+					usage();
 				goto NXTARG;
 			case 'c':
 				if (--argc <= 0)
@@ -101,11 +92,11 @@
 				if ((--argc <= 0) ||
 					(params.comp =
 					genimg_get_comp_id (*++argv)) < 0)
-					usage ();
+					usage();
 				goto NXTARG;
 			case 'D':
 				if (--argc <= 0)
-					usage ();
+					usage();
 				params.dtc = *++argv;
 				goto NXTARG;
 
@@ -113,7 +104,7 @@
 				if ((--argc <= 0) ||
 					(params.os =
 					genimg_get_os_id (*++argv)) < 0)
-					usage ();
+					usage();
 				goto NXTARG;
 			case 'T':
 				params.type = -1;
@@ -128,7 +119,7 @@
 				goto NXTARG;
 			case 'a':
 				if (--argc <= 0)
-					usage ();
+					usage();
 				params.addr = strtoull(*++argv, &ptr, 16);
 				if (*ptr) {
 					fprintf (stderr,
@@ -139,13 +130,13 @@
 				goto NXTARG;
 			case 'd':
 				if (--argc <= 0)
-					usage ();
+					usage();
 				params.datafile = *++argv;
 				params.dflag = 1;
 				goto NXTARG;
 			case 'e':
 				if (--argc <= 0)
-					usage ();
+					usage();
 				params.ep = strtoull(*++argv, &ptr, 16);
 				if (*ptr) {
 					fprintf (stderr,
@@ -157,7 +148,7 @@
 				goto NXTARG;
 			case 'f':
 				if (--argc <= 0)
-					usage ();
+					usage();
 				params.datafile = *++argv;
 				/* no break */
 			case 'F':
@@ -180,7 +171,7 @@
 				goto NXTARG;
 			case 'n':
 				if (--argc <= 0)
-					usage ();
+					usage();
 				params.imagename = *++argv;
 				goto NXTARG;
 			case 'r':
@@ -208,14 +199,33 @@
 				params.xflag++;
 				break;
 			default:
-				usage ();
+				usage();
 			}
 		}
 NXTARG:		;
 	}
 
 	if (argc != 1)
-		usage ();
+		usage();
+	params.imagefile = *argv;
+}
+
+
+int main(int argc, char **argv)
+{
+	int ifd = -1;
+	struct stat sbuf;
+	char *ptr;
+	int retval = 0;
+	struct image_type_params *tparams = NULL;
+	int pad_len = 0;
+	int dfd;
+
+	params.cmdname = *argv;
+	params.addr = 0;
+	params.ep = 0;
+
+	process_args(argc, argv);
 
 	/* set tparams as per input type_id */
 	tparams = imagetool_get_type(params.type);
@@ -231,7 +241,7 @@
 	 */
 	if (tparams->check_params)
 		if (tparams->check_params (&params))
-			usage ();
+			usage();
 
 	if (!params.eflag) {
 		params.ep = params.addr;
@@ -240,8 +250,6 @@
 			params.ep += tparams->header_size;
 	}
 
-	params.imagefile = *argv;
-
 	if (params.fflag){
 		if (tparams->fflag_handle)
 			/*