iperf: move to trunk and add myself as maintainer
[openwrt.git] / tools / firmware-utils / src / imagetag_cmdline.c
index 85f214bc6cc5867cf11b4d71ef686067ae5d6992..efb82ac96b1bae6b1cc51548b27064fb6a16e3f6 100644 (file)
@@ -56,15 +56,16 @@ const char *gengetopt_args_info_help[] = {
   "  -r, --rsa-signature=STRING    String for RSA Signature section.",
   "      --second-image-flag=flag-value\n                                Dual Image Flag (2=not-specified).  (possible \n                                  values=\"0\", \"1\", \"2\" default=`2')",
   "      --inactive=flag-value     Inactive Flag (2=not-specified).  (possible \n                                  values=\"0\", \"1\", \"2\" default=`2')",
-  "      --reserved1=STRING        String for first reserved section.",
   "      --reserved2=STRING        String for second reserved section.",
   "      --kernel-file-has-header  Indicates that the kernel file includes the \n                                  kernel header with correct load address and \n                                  entry point, so no changes are needed  \n                                  (default=off)",
+  "  -p, --pad=size (in MiB)       Pad the image to this size if smaller (in MiB)",
     0
 };
 
 typedef enum {ARG_NO
   , ARG_FLAG
   , ARG_STRING
+  , ARG_INT
 } cmdline_parser_arg_type;
 
 static
@@ -112,9 +113,9 @@ void clear_given (struct gengetopt_args_info *args_info)
   args_info->rsa_signature_given = 0 ;
   args_info->second_image_flag_given = 0 ;
   args_info->inactive_given = 0 ;
-  args_info->reserved1_given = 0 ;
   args_info->reserved2_given = 0 ;
   args_info->kernel_file_has_header_given = 0 ;
+  args_info->pad_given = 0 ;
 }
 
 static
@@ -164,11 +165,10 @@ void clear_args (struct gengetopt_args_info *args_info)
   args_info->second_image_flag_orig = NULL;
   args_info->inactive_arg = gengetopt_strdup ("2");
   args_info->inactive_orig = NULL;
-  args_info->reserved1_arg = NULL;
-  args_info->reserved1_orig = NULL;
   args_info->reserved2_arg = NULL;
   args_info->reserved2_orig = NULL;
   args_info->kernel_file_has_header_flag = 0;
+  args_info->pad_orig = NULL;
   
 }
 
@@ -201,9 +201,9 @@ void init_args_info(struct gengetopt_args_info *args_info)
   args_info->rsa_signature_help = gengetopt_args_info_help[21] ;
   args_info->second_image_flag_help = gengetopt_args_info_help[22] ;
   args_info->inactive_help = gengetopt_args_info_help[23] ;
-  args_info->reserved1_help = gengetopt_args_info_help[24] ;
-  args_info->reserved2_help = gengetopt_args_info_help[25] ;
-  args_info->kernel_file_has_header_help = gengetopt_args_info_help[26] ;
+  args_info->reserved2_help = gengetopt_args_info_help[24] ;
+  args_info->kernel_file_has_header_help = gengetopt_args_info_help[25] ;
+  args_info->pad_help = gengetopt_args_info_help[26] ;
   
 }
 
@@ -326,10 +326,9 @@ cmdline_parser_release (struct gengetopt_args_info *args_info)
   free_string_field (&(args_info->second_image_flag_orig));
   free_string_field (&(args_info->inactive_arg));
   free_string_field (&(args_info->inactive_orig));
-  free_string_field (&(args_info->reserved1_arg));
-  free_string_field (&(args_info->reserved1_orig));
   free_string_field (&(args_info->reserved2_arg));
   free_string_field (&(args_info->reserved2_orig));
+  free_string_field (&(args_info->pad_orig));
   
   
 
@@ -449,12 +448,12 @@ cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
     write_into_file(outfile, "second-image-flag", args_info->second_image_flag_orig, cmdline_parser_second_image_flag_values);
   if (args_info->inactive_given)
     write_into_file(outfile, "inactive", args_info->inactive_orig, cmdline_parser_inactive_values);
-  if (args_info->reserved1_given)
-    write_into_file(outfile, "reserved1", args_info->reserved1_orig, 0);
   if (args_info->reserved2_given)
     write_into_file(outfile, "reserved2", args_info->reserved2_orig, 0);
   if (args_info->kernel_file_has_header_given)
     write_into_file(outfile, "kernel-file-has-header", 0, 0 );
+  if (args_info->pad_given)
+    write_into_file(outfile, "pad", args_info->pad_orig, 0);
   
 
   i = EXIT_SUCCESS;
@@ -699,6 +698,9 @@ int update_arg(void *field, char **orig_field,
   case ARG_FLAG:
     *((int *)field) = !*((int *)field);
     break;
+  case ARG_INT:
+    if (val) *((int *)field) = strtol (val, &stop_char, 0);
+    break;
   case ARG_STRING:
     if (val) {
       string_field = (char **)field;
@@ -711,6 +713,17 @@ int update_arg(void *field, char **orig_field,
     break;
   };
 
+  /* check numeric conversion */
+  switch(arg_type) {
+  case ARG_INT:
+    if (val && !(stop_char && *stop_char == '\0')) {
+      fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
+      return 1; /* failure */
+    }
+    break;
+  default:
+    ;
+  };
 
   /* store the original value */
   switch(arg_type) {
@@ -794,13 +807,13 @@ cmdline_parser_internal (
         { "rsa-signature",     1, NULL, 'r' },
         { "second-image-flag", 1, NULL, 0 },
         { "inactive",  1, NULL, 0 },
-        { "reserved1", 1, NULL, 0 },
         { "reserved2", 1, NULL, 0 },
         { "kernel-file-has-header",    0, NULL, 0 },
+        { "pad",       1, NULL, 'p' },
         { 0,  0, 0, 0 }
       };
 
-      c = getopt_long (argc, argv, "hVi:f:o:b:c:s:n:v:a:m:k:l:e:y:1:2:r:", long_options, &option_index);
+      c = getopt_long (argc, argv, "hVi:f:o:b:c:s:n:v:a:m:k:l:e:y:1:2:r:p:", long_options, &option_index);
 
       if (c == -1) break;      /* Exit from `while (1)' loop.  */
 
@@ -1020,6 +1033,18 @@ cmdline_parser_internal (
             goto failure;
         
           break;
+        case 'p':      /* Pad the image to this size if smaller (in MiB).  */
+        
+        
+          if (update_arg( (void *)&(args_info->pad_arg), 
+               &(args_info->pad_orig), &(args_info->pad_given),
+              &(local_args_info.pad_given), optarg, 0, 0, ARG_INT,
+              check_ambiguity, override, 0, 0,
+              "pad", 'p',
+              additional_error))
+            goto failure;
+        
+          break;
 
         case 0:        /* Long option with no short option */
           /* File with CFE to include in the image..  */
@@ -1089,20 +1114,6 @@ cmdline_parser_internal (
                 additional_error))
               goto failure;
           
-          }
-          /* String for first reserved section..  */
-          else if (strcmp (long_options[option_index].name, "reserved1") == 0)
-          {
-          
-          
-            if (update_arg( (void *)&(args_info->reserved1_arg), 
-                 &(args_info->reserved1_orig), &(args_info->reserved1_given),
-                &(local_args_info.reserved1_given), optarg, 0, 0, ARG_STRING,
-                check_ambiguity, override, 0, 0,
-                "reserved1", '-',
-                additional_error))
-              goto failure;
-          
           }
           /* String for second reserved section..  */
           else if (strcmp (long_options[option_index].name, "reserved2") == 0)