2 File autogenerated by gengetopt version 2.22.4
3 generated with the following command:
4 gengetopt --file-name=imagetag_cmdline --file-name=imagetag_cmdline
6 The developers of gengetopt consider the fixed text that goes in all
7 gengetopt output files to be in the public domain:
8 we make no copyright claims on it.
11 /* If we use autoconf. */
21 #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
26 #include "imagetag_cmdline.h"
28 const char *gengetopt_args_info_purpose
= "Generate image with CFE imagetag for Broadcom 63xx routers.";
30 const char *gengetopt_args_info_usage
= "Usage: imagetag [OPTIONS]...";
32 const char *gengetopt_args_info_description
= "Copyright (C) 2008 Axel Gembe\nCopyright (C) 2009-2010 Daniel Dickinson\nLicensed unter the terms of the Gnu General Public License.\n\nGiven a root filesystem, a linux kernel, and an optional CFE, generates an \nimage with an imagetag for a Broadcom 63xx-based router. Additional parameters \nto be specified depend on the specfic brand and model of router.";
34 const char *gengetopt_args_info_help
[] = {
35 " -h, --help Print help and exit",
36 " -V, --version Print version and exit",
37 " -i, --kernel=filename File with LZMA compressed kernel to include in \n the image.",
38 " -f, --rootfs=filename File with RootFS to include in the image.",
39 " -o, --output=filename Name of output file.",
40 " --cfe=filename File with CFE to include in the image.",
41 " -b, --boardid=STRING Board ID to set in the image (must match what \n router expects, e.g. \"96345GW2\").",
42 " -c, --chipid=STRING Chip ID to set in the image (must match the \n actual hardware, e.g. \"6345\").",
43 " -s, --flash-start=address Flash start address. (default=`0xBFC00000')",
44 " -n, --image-offset=offset Offset from start address for the first byte \n after the CFE (in memory). \n (default=`0x10000')",
45 " -v, --tag-version=STRING Version number for imagetag format. \n (default=`6')",
46 " -a, --signature=STRING Magic string (signature), for boards that need \n it. (default=`Broadcom Corporatio')",
47 " -m, --signature2=STRING Second magic string (signature2). \n (default=`ver. 2.0')",
48 " -k, --block-size=STRING Flash erase block size. (default=`0x10000')",
49 " -l, --load-addr=address Kernel load address.",
50 " -e, --entry=address Address where the kernel entry point will be \n for booting.",
51 " -y, --layoutver=STRING Flash layout version (version 2.2x of the \n Broadcom code requires this).",
52 " -1, --info1=STRING String for first vendor information section.",
53 " --altinfo=STRING String for vendor information section \n (alternate/pirelli).",
54 " -2, --info2=STRING String for second vendor information section.",
55 " --root-first Put the rootfs before the kernel (only for \n stock images, e.g. captured from the router's \n flash memory). (default=off)",
56 " -r, --rsa-signature=STRING String for RSA Signature section.",
57 " --second-image-flag=flag-value\n Dual Image Flag (2=not-specified). (possible \n values=\"0\", \"1\", \"2\" default=`2')",
58 " --inactive=flag-value Inactive Flag (2=not-specified). (possible \n values=\"0\", \"1\", \"2\" default=`2')",
59 " --reserved1=STRING String for first reserved section.",
60 " --reserved2=STRING String for second reserved section.",
61 " --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)",
68 } cmdline_parser_arg_type
;
71 void clear_given (struct gengetopt_args_info
*args_info
);
73 void clear_args (struct gengetopt_args_info
*args_info
);
76 cmdline_parser_internal (int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
77 struct cmdline_parser_params
*params
, const char *additional_error
);
80 cmdline_parser_required2 (struct gengetopt_args_info
*args_info
, const char *prog_name
, const char *additional_error
);
82 const char *cmdline_parser_second_image_flag_values
[] = {"0", "1", "2", 0}; /*< Possible values for second-image-flag. */
83 const char *cmdline_parser_inactive_values
[] = {"0", "1", "2", 0}; /*< Possible values for inactive. */
86 gengetopt_strdup (const char *s
);
89 void clear_given (struct gengetopt_args_info
*args_info
)
91 args_info
->help_given
= 0 ;
92 args_info
->version_given
= 0 ;
93 args_info
->kernel_given
= 0 ;
94 args_info
->rootfs_given
= 0 ;
95 args_info
->output_given
= 0 ;
96 args_info
->cfe_given
= 0 ;
97 args_info
->boardid_given
= 0 ;
98 args_info
->chipid_given
= 0 ;
99 args_info
->flash_start_given
= 0 ;
100 args_info
->image_offset_given
= 0 ;
101 args_info
->tag_version_given
= 0 ;
102 args_info
->signature_given
= 0 ;
103 args_info
->signature2_given
= 0 ;
104 args_info
->block_size_given
= 0 ;
105 args_info
->load_addr_given
= 0 ;
106 args_info
->entry_given
= 0 ;
107 args_info
->layoutver_given
= 0 ;
108 args_info
->info1_given
= 0 ;
109 args_info
->altinfo_given
= 0 ;
110 args_info
->info2_given
= 0 ;
111 args_info
->root_first_given
= 0 ;
112 args_info
->rsa_signature_given
= 0 ;
113 args_info
->second_image_flag_given
= 0 ;
114 args_info
->inactive_given
= 0 ;
115 args_info
->reserved1_given
= 0 ;
116 args_info
->reserved2_given
= 0 ;
117 args_info
->kernel_file_has_header_given
= 0 ;
121 void clear_args (struct gengetopt_args_info
*args_info
)
123 FIX_UNUSED (args_info
);
124 args_info
->kernel_arg
= NULL
;
125 args_info
->kernel_orig
= NULL
;
126 args_info
->rootfs_arg
= NULL
;
127 args_info
->rootfs_orig
= NULL
;
128 args_info
->output_arg
= NULL
;
129 args_info
->output_orig
= NULL
;
130 args_info
->cfe_arg
= NULL
;
131 args_info
->cfe_orig
= NULL
;
132 args_info
->boardid_arg
= NULL
;
133 args_info
->boardid_orig
= NULL
;
134 args_info
->chipid_arg
= NULL
;
135 args_info
->chipid_orig
= NULL
;
136 args_info
->flash_start_arg
= gengetopt_strdup ("0xBFC00000");
137 args_info
->flash_start_orig
= NULL
;
138 args_info
->image_offset_arg
= gengetopt_strdup ("0x10000");
139 args_info
->image_offset_orig
= NULL
;
140 args_info
->tag_version_arg
= gengetopt_strdup ("6");
141 args_info
->tag_version_orig
= NULL
;
142 args_info
->signature_arg
= gengetopt_strdup ("Broadcom Corporatio");
143 args_info
->signature_orig
= NULL
;
144 args_info
->signature2_arg
= gengetopt_strdup ("ver. 2.0");
145 args_info
->signature2_orig
= NULL
;
146 args_info
->block_size_arg
= gengetopt_strdup ("0x10000");
147 args_info
->block_size_orig
= NULL
;
148 args_info
->load_addr_arg
= NULL
;
149 args_info
->load_addr_orig
= NULL
;
150 args_info
->entry_arg
= NULL
;
151 args_info
->entry_orig
= NULL
;
152 args_info
->layoutver_arg
= NULL
;
153 args_info
->layoutver_orig
= NULL
;
154 args_info
->info1_arg
= NULL
;
155 args_info
->info1_orig
= NULL
;
156 args_info
->altinfo_arg
= NULL
;
157 args_info
->altinfo_orig
= NULL
;
158 args_info
->info2_arg
= NULL
;
159 args_info
->info2_orig
= NULL
;
160 args_info
->root_first_flag
= 0;
161 args_info
->rsa_signature_arg
= NULL
;
162 args_info
->rsa_signature_orig
= NULL
;
163 args_info
->second_image_flag_arg
= gengetopt_strdup ("2");
164 args_info
->second_image_flag_orig
= NULL
;
165 args_info
->inactive_arg
= gengetopt_strdup ("2");
166 args_info
->inactive_orig
= NULL
;
167 args_info
->reserved1_arg
= NULL
;
168 args_info
->reserved1_orig
= NULL
;
169 args_info
->reserved2_arg
= NULL
;
170 args_info
->reserved2_orig
= NULL
;
171 args_info
->kernel_file_has_header_flag
= 0;
176 void init_args_info(struct gengetopt_args_info
*args_info
)
180 args_info
->help_help
= gengetopt_args_info_help
[0] ;
181 args_info
->version_help
= gengetopt_args_info_help
[1] ;
182 args_info
->kernel_help
= gengetopt_args_info_help
[2] ;
183 args_info
->rootfs_help
= gengetopt_args_info_help
[3] ;
184 args_info
->output_help
= gengetopt_args_info_help
[4] ;
185 args_info
->cfe_help
= gengetopt_args_info_help
[5] ;
186 args_info
->boardid_help
= gengetopt_args_info_help
[6] ;
187 args_info
->chipid_help
= gengetopt_args_info_help
[7] ;
188 args_info
->flash_start_help
= gengetopt_args_info_help
[8] ;
189 args_info
->image_offset_help
= gengetopt_args_info_help
[9] ;
190 args_info
->tag_version_help
= gengetopt_args_info_help
[10] ;
191 args_info
->signature_help
= gengetopt_args_info_help
[11] ;
192 args_info
->signature2_help
= gengetopt_args_info_help
[12] ;
193 args_info
->block_size_help
= gengetopt_args_info_help
[13] ;
194 args_info
->load_addr_help
= gengetopt_args_info_help
[14] ;
195 args_info
->entry_help
= gengetopt_args_info_help
[15] ;
196 args_info
->layoutver_help
= gengetopt_args_info_help
[16] ;
197 args_info
->info1_help
= gengetopt_args_info_help
[17] ;
198 args_info
->altinfo_help
= gengetopt_args_info_help
[18] ;
199 args_info
->info2_help
= gengetopt_args_info_help
[19] ;
200 args_info
->root_first_help
= gengetopt_args_info_help
[20] ;
201 args_info
->rsa_signature_help
= gengetopt_args_info_help
[21] ;
202 args_info
->second_image_flag_help
= gengetopt_args_info_help
[22] ;
203 args_info
->inactive_help
= gengetopt_args_info_help
[23] ;
204 args_info
->reserved1_help
= gengetopt_args_info_help
[24] ;
205 args_info
->reserved2_help
= gengetopt_args_info_help
[25] ;
206 args_info
->kernel_file_has_header_help
= gengetopt_args_info_help
[26] ;
211 cmdline_parser_print_version (void)
214 (strlen(CMDLINE_PARSER_PACKAGE_NAME
) ? CMDLINE_PARSER_PACKAGE_NAME
: CMDLINE_PARSER_PACKAGE
),
215 CMDLINE_PARSER_VERSION
);
218 static void print_help_common(void) {
219 cmdline_parser_print_version ();
221 if (strlen(gengetopt_args_info_purpose
) > 0)
222 printf("\n%s\n", gengetopt_args_info_purpose
);
224 if (strlen(gengetopt_args_info_usage
) > 0)
225 printf("\n%s\n", gengetopt_args_info_usage
);
229 if (strlen(gengetopt_args_info_description
) > 0)
230 printf("%s\n\n", gengetopt_args_info_description
);
234 cmdline_parser_print_help (void)
238 while (gengetopt_args_info_help
[i
])
239 printf("%s\n", gengetopt_args_info_help
[i
++]);
243 cmdline_parser_init (struct gengetopt_args_info
*args_info
)
245 clear_given (args_info
);
246 clear_args (args_info
);
247 init_args_info (args_info
);
251 cmdline_parser_params_init(struct cmdline_parser_params
*params
)
255 params
->override
= 0;
256 params
->initialize
= 1;
257 params
->check_required
= 1;
258 params
->check_ambiguity
= 0;
259 params
->print_errors
= 1;
263 struct cmdline_parser_params
*
264 cmdline_parser_params_create(void)
266 struct cmdline_parser_params
*params
=
267 (struct cmdline_parser_params
*)malloc(sizeof(struct cmdline_parser_params
));
268 cmdline_parser_params_init(params
);
273 free_string_field (char **s
)
284 cmdline_parser_release (struct gengetopt_args_info
*args_info
)
287 free_string_field (&(args_info
->kernel_arg
));
288 free_string_field (&(args_info
->kernel_orig
));
289 free_string_field (&(args_info
->rootfs_arg
));
290 free_string_field (&(args_info
->rootfs_orig
));
291 free_string_field (&(args_info
->output_arg
));
292 free_string_field (&(args_info
->output_orig
));
293 free_string_field (&(args_info
->cfe_arg
));
294 free_string_field (&(args_info
->cfe_orig
));
295 free_string_field (&(args_info
->boardid_arg
));
296 free_string_field (&(args_info
->boardid_orig
));
297 free_string_field (&(args_info
->chipid_arg
));
298 free_string_field (&(args_info
->chipid_orig
));
299 free_string_field (&(args_info
->flash_start_arg
));
300 free_string_field (&(args_info
->flash_start_orig
));
301 free_string_field (&(args_info
->image_offset_arg
));
302 free_string_field (&(args_info
->image_offset_orig
));
303 free_string_field (&(args_info
->tag_version_arg
));
304 free_string_field (&(args_info
->tag_version_orig
));
305 free_string_field (&(args_info
->signature_arg
));
306 free_string_field (&(args_info
->signature_orig
));
307 free_string_field (&(args_info
->signature2_arg
));
308 free_string_field (&(args_info
->signature2_orig
));
309 free_string_field (&(args_info
->block_size_arg
));
310 free_string_field (&(args_info
->block_size_orig
));
311 free_string_field (&(args_info
->load_addr_arg
));
312 free_string_field (&(args_info
->load_addr_orig
));
313 free_string_field (&(args_info
->entry_arg
));
314 free_string_field (&(args_info
->entry_orig
));
315 free_string_field (&(args_info
->layoutver_arg
));
316 free_string_field (&(args_info
->layoutver_orig
));
317 free_string_field (&(args_info
->info1_arg
));
318 free_string_field (&(args_info
->info1_orig
));
319 free_string_field (&(args_info
->altinfo_arg
));
320 free_string_field (&(args_info
->altinfo_orig
));
321 free_string_field (&(args_info
->info2_arg
));
322 free_string_field (&(args_info
->info2_orig
));
323 free_string_field (&(args_info
->rsa_signature_arg
));
324 free_string_field (&(args_info
->rsa_signature_orig
));
325 free_string_field (&(args_info
->second_image_flag_arg
));
326 free_string_field (&(args_info
->second_image_flag_orig
));
327 free_string_field (&(args_info
->inactive_arg
));
328 free_string_field (&(args_info
->inactive_orig
));
329 free_string_field (&(args_info
->reserved1_arg
));
330 free_string_field (&(args_info
->reserved1_orig
));
331 free_string_field (&(args_info
->reserved2_arg
));
332 free_string_field (&(args_info
->reserved2_orig
));
336 clear_given (args_info
);
340 * @param val the value to check
341 * @param values the possible values
342 * @return the index of the matched value:
343 * -1 if no value matched,
344 * -2 if more than one value has matched
347 check_possible_values(const char *val
, const char *values
[])
352 if (!val
) /* otherwise strlen() crashes below */
353 return -1; /* -1 means no argument for the option */
357 for (i
= 0, len
= strlen(val
); values
[i
]; ++i
)
359 if (strncmp(val
, values
[i
], len
) == 0)
363 if (strlen(values
[i
]) == len
)
364 return i
; /* exact macth no need to check more */
368 if (found
== 1) /* one match: OK */
371 return (found
? -2 : -1); /* return many values or none matched */
376 write_into_file(FILE *outfile
, const char *opt
, const char *arg
, const char *values
[])
381 found
= check_possible_values(arg
, values
);
384 fprintf(outfile
, "%s=\"%s\" # %s\n", opt
, arg
, values
[found
]);
386 fprintf(outfile
, "%s=\"%s\"\n", opt
, arg
);
388 fprintf(outfile
, "%s\n", opt
);
394 cmdline_parser_dump(FILE *outfile
, struct gengetopt_args_info
*args_info
)
400 fprintf (stderr
, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE
);
404 if (args_info
->help_given
)
405 write_into_file(outfile
, "help", 0, 0 );
406 if (args_info
->version_given
)
407 write_into_file(outfile
, "version", 0, 0 );
408 if (args_info
->kernel_given
)
409 write_into_file(outfile
, "kernel", args_info
->kernel_orig
, 0);
410 if (args_info
->rootfs_given
)
411 write_into_file(outfile
, "rootfs", args_info
->rootfs_orig
, 0);
412 if (args_info
->output_given
)
413 write_into_file(outfile
, "output", args_info
->output_orig
, 0);
414 if (args_info
->cfe_given
)
415 write_into_file(outfile
, "cfe", args_info
->cfe_orig
, 0);
416 if (args_info
->boardid_given
)
417 write_into_file(outfile
, "boardid", args_info
->boardid_orig
, 0);
418 if (args_info
->chipid_given
)
419 write_into_file(outfile
, "chipid", args_info
->chipid_orig
, 0);
420 if (args_info
->flash_start_given
)
421 write_into_file(outfile
, "flash-start", args_info
->flash_start_orig
, 0);
422 if (args_info
->image_offset_given
)
423 write_into_file(outfile
, "image-offset", args_info
->image_offset_orig
, 0);
424 if (args_info
->tag_version_given
)
425 write_into_file(outfile
, "tag-version", args_info
->tag_version_orig
, 0);
426 if (args_info
->signature_given
)
427 write_into_file(outfile
, "signature", args_info
->signature_orig
, 0);
428 if (args_info
->signature2_given
)
429 write_into_file(outfile
, "signature2", args_info
->signature2_orig
, 0);
430 if (args_info
->block_size_given
)
431 write_into_file(outfile
, "block-size", args_info
->block_size_orig
, 0);
432 if (args_info
->load_addr_given
)
433 write_into_file(outfile
, "load-addr", args_info
->load_addr_orig
, 0);
434 if (args_info
->entry_given
)
435 write_into_file(outfile
, "entry", args_info
->entry_orig
, 0);
436 if (args_info
->layoutver_given
)
437 write_into_file(outfile
, "layoutver", args_info
->layoutver_orig
, 0);
438 if (args_info
->info1_given
)
439 write_into_file(outfile
, "info1", args_info
->info1_orig
, 0);
440 if (args_info
->altinfo_given
)
441 write_into_file(outfile
, "altinfo", args_info
->altinfo_orig
, 0);
442 if (args_info
->info2_given
)
443 write_into_file(outfile
, "info2", args_info
->info2_orig
, 0);
444 if (args_info
->root_first_given
)
445 write_into_file(outfile
, "root-first", 0, 0 );
446 if (args_info
->rsa_signature_given
)
447 write_into_file(outfile
, "rsa-signature", args_info
->rsa_signature_orig
, 0);
448 if (args_info
->second_image_flag_given
)
449 write_into_file(outfile
, "second-image-flag", args_info
->second_image_flag_orig
, cmdline_parser_second_image_flag_values
);
450 if (args_info
->inactive_given
)
451 write_into_file(outfile
, "inactive", args_info
->inactive_orig
, cmdline_parser_inactive_values
);
452 if (args_info
->reserved1_given
)
453 write_into_file(outfile
, "reserved1", args_info
->reserved1_orig
, 0);
454 if (args_info
->reserved2_given
)
455 write_into_file(outfile
, "reserved2", args_info
->reserved2_orig
, 0);
456 if (args_info
->kernel_file_has_header_given
)
457 write_into_file(outfile
, "kernel-file-has-header", 0, 0 );
465 cmdline_parser_file_save(const char *filename
, struct gengetopt_args_info
*args_info
)
470 outfile
= fopen(filename
, "w");
474 fprintf (stderr
, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE
, filename
);
478 i
= cmdline_parser_dump(outfile
, args_info
);
485 cmdline_parser_free (struct gengetopt_args_info
*args_info
)
487 cmdline_parser_release (args_info
);
490 /** @brief replacement of strdup, which is not standard */
492 gengetopt_strdup (const char *s
)
498 result
= (char*)malloc(strlen(s
) + 1);
499 if (result
== (char*)0)
506 cmdline_parser (int argc
, char **argv
, struct gengetopt_args_info
*args_info
)
508 return cmdline_parser2 (argc
, argv
, args_info
, 0, 1, 1);
512 cmdline_parser_ext (int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
513 struct cmdline_parser_params
*params
)
516 result
= cmdline_parser_internal (argc
, argv
, args_info
, params
, 0);
518 if (result
== EXIT_FAILURE
)
520 cmdline_parser_free (args_info
);
528 cmdline_parser2 (int argc
, char **argv
, struct gengetopt_args_info
*args_info
, int override
, int initialize
, int check_required
)
531 struct cmdline_parser_params params
;
533 params
.override
= override
;
534 params
.initialize
= initialize
;
535 params
.check_required
= check_required
;
536 params
.check_ambiguity
= 0;
537 params
.print_errors
= 1;
539 result
= cmdline_parser_internal (argc
, argv
, args_info
, ¶ms
, 0);
541 if (result
== EXIT_FAILURE
)
543 cmdline_parser_free (args_info
);
551 cmdline_parser_required (struct gengetopt_args_info
*args_info
, const char *prog_name
)
553 int result
= EXIT_SUCCESS
;
555 if (cmdline_parser_required2(args_info
, prog_name
, 0) > 0)
556 result
= EXIT_FAILURE
;
558 if (result
== EXIT_FAILURE
)
560 cmdline_parser_free (args_info
);
568 cmdline_parser_required2 (struct gengetopt_args_info
*args_info
, const char *prog_name
, const char *additional_error
)
571 FIX_UNUSED (additional_error
);
573 /* checks for required options */
574 if (! args_info
->kernel_given
)
576 fprintf (stderr
, "%s: '--kernel' ('-i') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
580 if (! args_info
->rootfs_given
)
582 fprintf (stderr
, "%s: '--rootfs' ('-f') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
586 if (! args_info
->output_given
)
588 fprintf (stderr
, "%s: '--output' ('-o') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
592 if (! args_info
->boardid_given
)
594 fprintf (stderr
, "%s: '--boardid' ('-b') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
598 if (! args_info
->chipid_given
)
600 fprintf (stderr
, "%s: '--chipid' ('-c') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
604 if (! args_info
->load_addr_given
)
606 fprintf (stderr
, "%s: '--load-addr' ('-l') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
610 if (! args_info
->entry_given
)
612 fprintf (stderr
, "%s: '--entry' ('-e') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
617 /* checks for dependences among options */
623 static char *package_name
= 0;
626 * @brief updates an option
627 * @param field the generic pointer to the field to update
628 * @param orig_field the pointer to the orig field
629 * @param field_given the pointer to the number of occurrence of this option
630 * @param prev_given the pointer to the number of occurrence already seen
631 * @param value the argument for this option (if null no arg was specified)
632 * @param possible_values the possible values for this option (if specified)
633 * @param default_value the default value (in case the option only accepts fixed values)
634 * @param arg_type the type of this option
635 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
636 * @param override @see cmdline_parser_params.override
637 * @param no_free whether to free a possible previous value
638 * @param multiple_option whether this is a multiple option
639 * @param long_opt the corresponding long option
640 * @param short_opt the corresponding short option (or '-' if none)
641 * @param additional_error possible further error specification
644 int update_arg(void *field
, char **orig_field
,
645 unsigned int *field_given
, unsigned int *prev_given
,
646 char *value
, const char *possible_values
[],
647 const char *default_value
,
648 cmdline_parser_arg_type arg_type
,
649 int check_ambiguity
, int override
,
650 int no_free
, int multiple_option
,
651 const char *long_opt
, char short_opt
,
652 const char *additional_error
)
655 const char *val
= value
;
663 if (!multiple_option
&& prev_given
&& (*prev_given
|| (check_ambiguity
&& *field_given
)))
665 if (short_opt
!= '-')
666 fprintf (stderr
, "%s: `--%s' (`-%c') option given more than once%s\n",
667 package_name
, long_opt
, short_opt
,
668 (additional_error
? additional_error
: ""));
670 fprintf (stderr
, "%s: `--%s' option given more than once%s\n",
671 package_name
, long_opt
,
672 (additional_error
? additional_error
: ""));
673 return 1; /* failure */
676 if (possible_values
&& (found
= check_possible_values((value
? value
: default_value
), possible_values
)) < 0)
678 if (short_opt
!= '-')
679 fprintf (stderr
, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n",
680 package_name
, (found
== -2) ? "ambiguous" : "invalid", value
, long_opt
, short_opt
,
681 (additional_error
? additional_error
: ""));
683 fprintf (stderr
, "%s: %s argument, \"%s\", for option `--%s'%s\n",
684 package_name
, (found
== -2) ? "ambiguous" : "invalid", value
, long_opt
,
685 (additional_error
? additional_error
: ""));
686 return 1; /* failure */
689 if (field_given
&& *field_given
&& ! override
)
696 val
= possible_values
[found
];
700 *((int *)field
) = !*((int *)field
);
704 string_field
= (char **)field
;
705 if (!no_free
&& *string_field
)
706 free (*string_field
); /* free previous string */
707 *string_field
= gengetopt_strdup (val
);
715 /* store the original value */
721 if (value
&& orig_field
) {
726 free (*orig_field
); /* free previous string */
727 *orig_field
= gengetopt_strdup (value
);
737 cmdline_parser_internal (
738 int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
739 struct cmdline_parser_params
*params
, const char *additional_error
)
741 int c
; /* Character of the parsed option. */
744 struct gengetopt_args_info local_args_info
;
751 package_name
= argv
[0];
753 override
= params
->override
;
754 initialize
= params
->initialize
;
755 check_required
= params
->check_required
;
756 check_ambiguity
= params
->check_ambiguity
;
759 cmdline_parser_init (args_info
);
761 cmdline_parser_init (&local_args_info
);
765 opterr
= params
->print_errors
;
770 int option_index
= 0;
772 static struct option long_options
[] = {
773 { "help", 0, NULL
, 'h' },
774 { "version", 0, NULL
, 'V' },
775 { "kernel", 1, NULL
, 'i' },
776 { "rootfs", 1, NULL
, 'f' },
777 { "output", 1, NULL
, 'o' },
778 { "cfe", 1, NULL
, 0 },
779 { "boardid", 1, NULL
, 'b' },
780 { "chipid", 1, NULL
, 'c' },
781 { "flash-start", 1, NULL
, 's' },
782 { "image-offset", 1, NULL
, 'n' },
783 { "tag-version", 1, NULL
, 'v' },
784 { "signature", 1, NULL
, 'a' },
785 { "signature2", 1, NULL
, 'm' },
786 { "block-size", 1, NULL
, 'k' },
787 { "load-addr", 1, NULL
, 'l' },
788 { "entry", 1, NULL
, 'e' },
789 { "layoutver", 1, NULL
, 'y' },
790 { "info1", 1, NULL
, '1' },
791 { "altinfo", 1, NULL
, 0 },
792 { "info2", 1, NULL
, '2' },
793 { "root-first", 0, NULL
, 0 },
794 { "rsa-signature", 1, NULL
, 'r' },
795 { "second-image-flag", 1, NULL
, 0 },
796 { "inactive", 1, NULL
, 0 },
797 { "reserved1", 1, NULL
, 0 },
798 { "reserved2", 1, NULL
, 0 },
799 { "kernel-file-has-header", 0, NULL
, 0 },
803 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
);
805 if (c
== -1) break; /* Exit from `while (1)' loop. */
809 case 'h': /* Print help and exit. */
810 cmdline_parser_print_help ();
811 cmdline_parser_free (&local_args_info
);
814 case 'V': /* Print version and exit. */
815 cmdline_parser_print_version ();
816 cmdline_parser_free (&local_args_info
);
819 case 'i': /* File with LZMA compressed kernel to include in the image.. */
822 if (update_arg( (void *)&(args_info
->kernel_arg
),
823 &(args_info
->kernel_orig
), &(args_info
->kernel_given
),
824 &(local_args_info
.kernel_given
), optarg
, 0, 0, ARG_STRING
,
825 check_ambiguity
, override
, 0, 0,
831 case 'f': /* File with RootFS to include in the image.. */
834 if (update_arg( (void *)&(args_info
->rootfs_arg
),
835 &(args_info
->rootfs_orig
), &(args_info
->rootfs_given
),
836 &(local_args_info
.rootfs_given
), optarg
, 0, 0, ARG_STRING
,
837 check_ambiguity
, override
, 0, 0,
843 case 'o': /* Name of output file.. */
846 if (update_arg( (void *)&(args_info
->output_arg
),
847 &(args_info
->output_orig
), &(args_info
->output_given
),
848 &(local_args_info
.output_given
), optarg
, 0, 0, ARG_STRING
,
849 check_ambiguity
, override
, 0, 0,
855 case 'b': /* Board ID to set in the image (must match what router expects, e.g. \"96345GW2\").. */
858 if (update_arg( (void *)&(args_info
->boardid_arg
),
859 &(args_info
->boardid_orig
), &(args_info
->boardid_given
),
860 &(local_args_info
.boardid_given
), optarg
, 0, 0, ARG_STRING
,
861 check_ambiguity
, override
, 0, 0,
867 case 'c': /* Chip ID to set in the image (must match the actual hardware, e.g. \"6345\").. */
870 if (update_arg( (void *)&(args_info
->chipid_arg
),
871 &(args_info
->chipid_orig
), &(args_info
->chipid_given
),
872 &(local_args_info
.chipid_given
), optarg
, 0, 0, ARG_STRING
,
873 check_ambiguity
, override
, 0, 0,
879 case 's': /* Flash start address.. */
882 if (update_arg( (void *)&(args_info
->flash_start_arg
),
883 &(args_info
->flash_start_orig
), &(args_info
->flash_start_given
),
884 &(local_args_info
.flash_start_given
), optarg
, 0, "0xBFC00000", ARG_STRING
,
885 check_ambiguity
, override
, 0, 0,
891 case 'n': /* Offset from start address for the first byte after the CFE (in memory).. */
894 if (update_arg( (void *)&(args_info
->image_offset_arg
),
895 &(args_info
->image_offset_orig
), &(args_info
->image_offset_given
),
896 &(local_args_info
.image_offset_given
), optarg
, 0, "0x10000", ARG_STRING
,
897 check_ambiguity
, override
, 0, 0,
903 case 'v': /* Version number for imagetag format.. */
906 if (update_arg( (void *)&(args_info
->tag_version_arg
),
907 &(args_info
->tag_version_orig
), &(args_info
->tag_version_given
),
908 &(local_args_info
.tag_version_given
), optarg
, 0, "6", ARG_STRING
,
909 check_ambiguity
, override
, 0, 0,
915 case 'a': /* Magic string (signature), for boards that need it.. */
918 if (update_arg( (void *)&(args_info
->signature_arg
),
919 &(args_info
->signature_orig
), &(args_info
->signature_given
),
920 &(local_args_info
.signature_given
), optarg
, 0, "Broadcom Corporatio", ARG_STRING
,
921 check_ambiguity
, override
, 0, 0,
927 case 'm': /* Second magic string (signature2).. */
930 if (update_arg( (void *)&(args_info
->signature2_arg
),
931 &(args_info
->signature2_orig
), &(args_info
->signature2_given
),
932 &(local_args_info
.signature2_given
), optarg
, 0, "ver. 2.0", ARG_STRING
,
933 check_ambiguity
, override
, 0, 0,
939 case 'k': /* Flash erase block size.. */
942 if (update_arg( (void *)&(args_info
->block_size_arg
),
943 &(args_info
->block_size_orig
), &(args_info
->block_size_given
),
944 &(local_args_info
.block_size_given
), optarg
, 0, "0x10000", ARG_STRING
,
945 check_ambiguity
, override
, 0, 0,
951 case 'l': /* Kernel load address.. */
954 if (update_arg( (void *)&(args_info
->load_addr_arg
),
955 &(args_info
->load_addr_orig
), &(args_info
->load_addr_given
),
956 &(local_args_info
.load_addr_given
), optarg
, 0, 0, ARG_STRING
,
957 check_ambiguity
, override
, 0, 0,
963 case 'e': /* Address where the kernel entry point will be for booting.. */
966 if (update_arg( (void *)&(args_info
->entry_arg
),
967 &(args_info
->entry_orig
), &(args_info
->entry_given
),
968 &(local_args_info
.entry_given
), optarg
, 0, 0, ARG_STRING
,
969 check_ambiguity
, override
, 0, 0,
975 case 'y': /* Flash layout version (version 2.2x of the Broadcom code requires this).. */
978 if (update_arg( (void *)&(args_info
->layoutver_arg
),
979 &(args_info
->layoutver_orig
), &(args_info
->layoutver_given
),
980 &(local_args_info
.layoutver_given
), optarg
, 0, 0, ARG_STRING
,
981 check_ambiguity
, override
, 0, 0,
987 case '1': /* String for first vendor information section.. */
990 if (update_arg( (void *)&(args_info
->info1_arg
),
991 &(args_info
->info1_orig
), &(args_info
->info1_given
),
992 &(local_args_info
.info1_given
), optarg
, 0, 0, ARG_STRING
,
993 check_ambiguity
, override
, 0, 0,
999 case '2': /* String for second vendor information section.. */
1002 if (update_arg( (void *)&(args_info
->info2_arg
),
1003 &(args_info
->info2_orig
), &(args_info
->info2_given
),
1004 &(local_args_info
.info2_given
), optarg
, 0, 0, ARG_STRING
,
1005 check_ambiguity
, override
, 0, 0,
1011 case 'r': /* String for RSA Signature section.. */
1014 if (update_arg( (void *)&(args_info
->rsa_signature_arg
),
1015 &(args_info
->rsa_signature_orig
), &(args_info
->rsa_signature_given
),
1016 &(local_args_info
.rsa_signature_given
), optarg
, 0, 0, ARG_STRING
,
1017 check_ambiguity
, override
, 0, 0,
1018 "rsa-signature", 'r',
1024 case 0: /* Long option with no short option */
1025 /* File with CFE to include in the image.. */
1026 if (strcmp (long_options
[option_index
].name
, "cfe") == 0)
1030 if (update_arg( (void *)&(args_info
->cfe_arg
),
1031 &(args_info
->cfe_orig
), &(args_info
->cfe_given
),
1032 &(local_args_info
.cfe_given
), optarg
, 0, 0, ARG_STRING
,
1033 check_ambiguity
, override
, 0, 0,
1039 /* String for vendor information section (alternate/pirelli).. */
1040 else if (strcmp (long_options
[option_index
].name
, "altinfo") == 0)
1044 if (update_arg( (void *)&(args_info
->altinfo_arg
),
1045 &(args_info
->altinfo_orig
), &(args_info
->altinfo_given
),
1046 &(local_args_info
.altinfo_given
), optarg
, 0, 0, ARG_STRING
,
1047 check_ambiguity
, override
, 0, 0,
1053 /* Put the rootfs before the kernel (only for stock images, e.g. captured from the router's flash memory).. */
1054 else if (strcmp (long_options
[option_index
].name
, "root-first") == 0)
1058 if (update_arg((void *)&(args_info
->root_first_flag
), 0, &(args_info
->root_first_given
),
1059 &(local_args_info
.root_first_given
), optarg
, 0, 0, ARG_FLAG
,
1060 check_ambiguity
, override
, 1, 0, "root-first", '-',
1065 /* Dual Image Flag (2=not-specified).. */
1066 else if (strcmp (long_options
[option_index
].name
, "second-image-flag") == 0)
1070 if (update_arg( (void *)&(args_info
->second_image_flag_arg
),
1071 &(args_info
->second_image_flag_orig
), &(args_info
->second_image_flag_given
),
1072 &(local_args_info
.second_image_flag_given
), optarg
, cmdline_parser_second_image_flag_values
, "2", ARG_STRING
,
1073 check_ambiguity
, override
, 0, 0,
1074 "second-image-flag", '-',
1079 /* Inactive Flag (2=not-specified).. */
1080 else if (strcmp (long_options
[option_index
].name
, "inactive") == 0)
1084 if (update_arg( (void *)&(args_info
->inactive_arg
),
1085 &(args_info
->inactive_orig
), &(args_info
->inactive_given
),
1086 &(local_args_info
.inactive_given
), optarg
, cmdline_parser_inactive_values
, "2", ARG_STRING
,
1087 check_ambiguity
, override
, 0, 0,
1093 /* String for first reserved section.. */
1094 else if (strcmp (long_options
[option_index
].name
, "reserved1") == 0)
1098 if (update_arg( (void *)&(args_info
->reserved1_arg
),
1099 &(args_info
->reserved1_orig
), &(args_info
->reserved1_given
),
1100 &(local_args_info
.reserved1_given
), optarg
, 0, 0, ARG_STRING
,
1101 check_ambiguity
, override
, 0, 0,
1107 /* String for second reserved section.. */
1108 else if (strcmp (long_options
[option_index
].name
, "reserved2") == 0)
1112 if (update_arg( (void *)&(args_info
->reserved2_arg
),
1113 &(args_info
->reserved2_orig
), &(args_info
->reserved2_given
),
1114 &(local_args_info
.reserved2_given
), optarg
, 0, 0, ARG_STRING
,
1115 check_ambiguity
, override
, 0, 0,
1121 /* Indicates that the kernel file includes the kernel header with correct load address and entry point, so no changes are needed. */
1122 else if (strcmp (long_options
[option_index
].name
, "kernel-file-has-header") == 0)
1126 if (update_arg((void *)&(args_info
->kernel_file_has_header_flag
), 0, &(args_info
->kernel_file_has_header_given
),
1127 &(local_args_info
.kernel_file_has_header_given
), optarg
, 0, 0, ARG_FLAG
,
1128 check_ambiguity
, override
, 1, 0, "kernel-file-has-header", '-',
1135 case '?': /* Invalid option. */
1136 /* `getopt_long' already printed an error message. */
1139 default: /* bug: option not considered. */
1140 fprintf (stderr
, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE
, c
, (additional_error
? additional_error
: ""));
1149 error
+= cmdline_parser_required2 (args_info
, argv
[0], additional_error
);
1152 cmdline_parser_release (&local_args_info
);
1155 return (EXIT_FAILURE
);
1161 cmdline_parser_release (&local_args_info
);
1162 return (EXIT_FAILURE
);