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 " --reserved2=STRING String for second reserved section.",
60 " --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)",
67 } cmdline_parser_arg_type
;
70 void clear_given (struct gengetopt_args_info
*args_info
);
72 void clear_args (struct gengetopt_args_info
*args_info
);
75 cmdline_parser_internal (int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
76 struct cmdline_parser_params
*params
, const char *additional_error
);
79 cmdline_parser_required2 (struct gengetopt_args_info
*args_info
, const char *prog_name
, const char *additional_error
);
81 const char *cmdline_parser_second_image_flag_values
[] = {"0", "1", "2", 0}; /*< Possible values for second-image-flag. */
82 const char *cmdline_parser_inactive_values
[] = {"0", "1", "2", 0}; /*< Possible values for inactive. */
85 gengetopt_strdup (const char *s
);
88 void clear_given (struct gengetopt_args_info
*args_info
)
90 args_info
->help_given
= 0 ;
91 args_info
->version_given
= 0 ;
92 args_info
->kernel_given
= 0 ;
93 args_info
->rootfs_given
= 0 ;
94 args_info
->output_given
= 0 ;
95 args_info
->cfe_given
= 0 ;
96 args_info
->boardid_given
= 0 ;
97 args_info
->chipid_given
= 0 ;
98 args_info
->flash_start_given
= 0 ;
99 args_info
->image_offset_given
= 0 ;
100 args_info
->tag_version_given
= 0 ;
101 args_info
->signature_given
= 0 ;
102 args_info
->signature2_given
= 0 ;
103 args_info
->block_size_given
= 0 ;
104 args_info
->load_addr_given
= 0 ;
105 args_info
->entry_given
= 0 ;
106 args_info
->layoutver_given
= 0 ;
107 args_info
->info1_given
= 0 ;
108 args_info
->altinfo_given
= 0 ;
109 args_info
->info2_given
= 0 ;
110 args_info
->root_first_given
= 0 ;
111 args_info
->rsa_signature_given
= 0 ;
112 args_info
->second_image_flag_given
= 0 ;
113 args_info
->inactive_given
= 0 ;
114 args_info
->reserved2_given
= 0 ;
115 args_info
->kernel_file_has_header_given
= 0 ;
119 void clear_args (struct gengetopt_args_info
*args_info
)
121 FIX_UNUSED (args_info
);
122 args_info
->kernel_arg
= NULL
;
123 args_info
->kernel_orig
= NULL
;
124 args_info
->rootfs_arg
= NULL
;
125 args_info
->rootfs_orig
= NULL
;
126 args_info
->output_arg
= NULL
;
127 args_info
->output_orig
= NULL
;
128 args_info
->cfe_arg
= NULL
;
129 args_info
->cfe_orig
= NULL
;
130 args_info
->boardid_arg
= NULL
;
131 args_info
->boardid_orig
= NULL
;
132 args_info
->chipid_arg
= NULL
;
133 args_info
->chipid_orig
= NULL
;
134 args_info
->flash_start_arg
= gengetopt_strdup ("0xBFC00000");
135 args_info
->flash_start_orig
= NULL
;
136 args_info
->image_offset_arg
= gengetopt_strdup ("0x10000");
137 args_info
->image_offset_orig
= NULL
;
138 args_info
->tag_version_arg
= gengetopt_strdup ("6");
139 args_info
->tag_version_orig
= NULL
;
140 args_info
->signature_arg
= gengetopt_strdup ("Broadcom Corporatio");
141 args_info
->signature_orig
= NULL
;
142 args_info
->signature2_arg
= gengetopt_strdup ("ver. 2.0");
143 args_info
->signature2_orig
= NULL
;
144 args_info
->block_size_arg
= gengetopt_strdup ("0x10000");
145 args_info
->block_size_orig
= NULL
;
146 args_info
->load_addr_arg
= NULL
;
147 args_info
->load_addr_orig
= NULL
;
148 args_info
->entry_arg
= NULL
;
149 args_info
->entry_orig
= NULL
;
150 args_info
->layoutver_arg
= NULL
;
151 args_info
->layoutver_orig
= NULL
;
152 args_info
->info1_arg
= NULL
;
153 args_info
->info1_orig
= NULL
;
154 args_info
->altinfo_arg
= NULL
;
155 args_info
->altinfo_orig
= NULL
;
156 args_info
->info2_arg
= NULL
;
157 args_info
->info2_orig
= NULL
;
158 args_info
->root_first_flag
= 0;
159 args_info
->rsa_signature_arg
= NULL
;
160 args_info
->rsa_signature_orig
= NULL
;
161 args_info
->second_image_flag_arg
= gengetopt_strdup ("2");
162 args_info
->second_image_flag_orig
= NULL
;
163 args_info
->inactive_arg
= gengetopt_strdup ("2");
164 args_info
->inactive_orig
= NULL
;
165 args_info
->reserved2_arg
= NULL
;
166 args_info
->reserved2_orig
= NULL
;
167 args_info
->kernel_file_has_header_flag
= 0;
172 void init_args_info(struct gengetopt_args_info
*args_info
)
176 args_info
->help_help
= gengetopt_args_info_help
[0] ;
177 args_info
->version_help
= gengetopt_args_info_help
[1] ;
178 args_info
->kernel_help
= gengetopt_args_info_help
[2] ;
179 args_info
->rootfs_help
= gengetopt_args_info_help
[3] ;
180 args_info
->output_help
= gengetopt_args_info_help
[4] ;
181 args_info
->cfe_help
= gengetopt_args_info_help
[5] ;
182 args_info
->boardid_help
= gengetopt_args_info_help
[6] ;
183 args_info
->chipid_help
= gengetopt_args_info_help
[7] ;
184 args_info
->flash_start_help
= gengetopt_args_info_help
[8] ;
185 args_info
->image_offset_help
= gengetopt_args_info_help
[9] ;
186 args_info
->tag_version_help
= gengetopt_args_info_help
[10] ;
187 args_info
->signature_help
= gengetopt_args_info_help
[11] ;
188 args_info
->signature2_help
= gengetopt_args_info_help
[12] ;
189 args_info
->block_size_help
= gengetopt_args_info_help
[13] ;
190 args_info
->load_addr_help
= gengetopt_args_info_help
[14] ;
191 args_info
->entry_help
= gengetopt_args_info_help
[15] ;
192 args_info
->layoutver_help
= gengetopt_args_info_help
[16] ;
193 args_info
->info1_help
= gengetopt_args_info_help
[17] ;
194 args_info
->altinfo_help
= gengetopt_args_info_help
[18] ;
195 args_info
->info2_help
= gengetopt_args_info_help
[19] ;
196 args_info
->root_first_help
= gengetopt_args_info_help
[20] ;
197 args_info
->rsa_signature_help
= gengetopt_args_info_help
[21] ;
198 args_info
->second_image_flag_help
= gengetopt_args_info_help
[22] ;
199 args_info
->inactive_help
= gengetopt_args_info_help
[23] ;
200 args_info
->reserved2_help
= gengetopt_args_info_help
[24] ;
201 args_info
->kernel_file_has_header_help
= gengetopt_args_info_help
[25] ;
206 cmdline_parser_print_version (void)
209 (strlen(CMDLINE_PARSER_PACKAGE_NAME
) ? CMDLINE_PARSER_PACKAGE_NAME
: CMDLINE_PARSER_PACKAGE
),
210 CMDLINE_PARSER_VERSION
);
213 static void print_help_common(void) {
214 cmdline_parser_print_version ();
216 if (strlen(gengetopt_args_info_purpose
) > 0)
217 printf("\n%s\n", gengetopt_args_info_purpose
);
219 if (strlen(gengetopt_args_info_usage
) > 0)
220 printf("\n%s\n", gengetopt_args_info_usage
);
224 if (strlen(gengetopt_args_info_description
) > 0)
225 printf("%s\n\n", gengetopt_args_info_description
);
229 cmdline_parser_print_help (void)
233 while (gengetopt_args_info_help
[i
])
234 printf("%s\n", gengetopt_args_info_help
[i
++]);
238 cmdline_parser_init (struct gengetopt_args_info
*args_info
)
240 clear_given (args_info
);
241 clear_args (args_info
);
242 init_args_info (args_info
);
246 cmdline_parser_params_init(struct cmdline_parser_params
*params
)
250 params
->override
= 0;
251 params
->initialize
= 1;
252 params
->check_required
= 1;
253 params
->check_ambiguity
= 0;
254 params
->print_errors
= 1;
258 struct cmdline_parser_params
*
259 cmdline_parser_params_create(void)
261 struct cmdline_parser_params
*params
=
262 (struct cmdline_parser_params
*)malloc(sizeof(struct cmdline_parser_params
));
263 cmdline_parser_params_init(params
);
268 free_string_field (char **s
)
279 cmdline_parser_release (struct gengetopt_args_info
*args_info
)
282 free_string_field (&(args_info
->kernel_arg
));
283 free_string_field (&(args_info
->kernel_orig
));
284 free_string_field (&(args_info
->rootfs_arg
));
285 free_string_field (&(args_info
->rootfs_orig
));
286 free_string_field (&(args_info
->output_arg
));
287 free_string_field (&(args_info
->output_orig
));
288 free_string_field (&(args_info
->cfe_arg
));
289 free_string_field (&(args_info
->cfe_orig
));
290 free_string_field (&(args_info
->boardid_arg
));
291 free_string_field (&(args_info
->boardid_orig
));
292 free_string_field (&(args_info
->chipid_arg
));
293 free_string_field (&(args_info
->chipid_orig
));
294 free_string_field (&(args_info
->flash_start_arg
));
295 free_string_field (&(args_info
->flash_start_orig
));
296 free_string_field (&(args_info
->image_offset_arg
));
297 free_string_field (&(args_info
->image_offset_orig
));
298 free_string_field (&(args_info
->tag_version_arg
));
299 free_string_field (&(args_info
->tag_version_orig
));
300 free_string_field (&(args_info
->signature_arg
));
301 free_string_field (&(args_info
->signature_orig
));
302 free_string_field (&(args_info
->signature2_arg
));
303 free_string_field (&(args_info
->signature2_orig
));
304 free_string_field (&(args_info
->block_size_arg
));
305 free_string_field (&(args_info
->block_size_orig
));
306 free_string_field (&(args_info
->load_addr_arg
));
307 free_string_field (&(args_info
->load_addr_orig
));
308 free_string_field (&(args_info
->entry_arg
));
309 free_string_field (&(args_info
->entry_orig
));
310 free_string_field (&(args_info
->layoutver_arg
));
311 free_string_field (&(args_info
->layoutver_orig
));
312 free_string_field (&(args_info
->info1_arg
));
313 free_string_field (&(args_info
->info1_orig
));
314 free_string_field (&(args_info
->altinfo_arg
));
315 free_string_field (&(args_info
->altinfo_orig
));
316 free_string_field (&(args_info
->info2_arg
));
317 free_string_field (&(args_info
->info2_orig
));
318 free_string_field (&(args_info
->rsa_signature_arg
));
319 free_string_field (&(args_info
->rsa_signature_orig
));
320 free_string_field (&(args_info
->second_image_flag_arg
));
321 free_string_field (&(args_info
->second_image_flag_orig
));
322 free_string_field (&(args_info
->inactive_arg
));
323 free_string_field (&(args_info
->inactive_orig
));
324 free_string_field (&(args_info
->reserved2_arg
));
325 free_string_field (&(args_info
->reserved2_orig
));
329 clear_given (args_info
);
333 * @param val the value to check
334 * @param values the possible values
335 * @return the index of the matched value:
336 * -1 if no value matched,
337 * -2 if more than one value has matched
340 check_possible_values(const char *val
, const char *values
[])
345 if (!val
) /* otherwise strlen() crashes below */
346 return -1; /* -1 means no argument for the option */
350 for (i
= 0, len
= strlen(val
); values
[i
]; ++i
)
352 if (strncmp(val
, values
[i
], len
) == 0)
356 if (strlen(values
[i
]) == len
)
357 return i
; /* exact macth no need to check more */
361 if (found
== 1) /* one match: OK */
364 return (found
? -2 : -1); /* return many values or none matched */
369 write_into_file(FILE *outfile
, const char *opt
, const char *arg
, const char *values
[])
374 found
= check_possible_values(arg
, values
);
377 fprintf(outfile
, "%s=\"%s\" # %s\n", opt
, arg
, values
[found
]);
379 fprintf(outfile
, "%s=\"%s\"\n", opt
, arg
);
381 fprintf(outfile
, "%s\n", opt
);
387 cmdline_parser_dump(FILE *outfile
, struct gengetopt_args_info
*args_info
)
393 fprintf (stderr
, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE
);
397 if (args_info
->help_given
)
398 write_into_file(outfile
, "help", 0, 0 );
399 if (args_info
->version_given
)
400 write_into_file(outfile
, "version", 0, 0 );
401 if (args_info
->kernel_given
)
402 write_into_file(outfile
, "kernel", args_info
->kernel_orig
, 0);
403 if (args_info
->rootfs_given
)
404 write_into_file(outfile
, "rootfs", args_info
->rootfs_orig
, 0);
405 if (args_info
->output_given
)
406 write_into_file(outfile
, "output", args_info
->output_orig
, 0);
407 if (args_info
->cfe_given
)
408 write_into_file(outfile
, "cfe", args_info
->cfe_orig
, 0);
409 if (args_info
->boardid_given
)
410 write_into_file(outfile
, "boardid", args_info
->boardid_orig
, 0);
411 if (args_info
->chipid_given
)
412 write_into_file(outfile
, "chipid", args_info
->chipid_orig
, 0);
413 if (args_info
->flash_start_given
)
414 write_into_file(outfile
, "flash-start", args_info
->flash_start_orig
, 0);
415 if (args_info
->image_offset_given
)
416 write_into_file(outfile
, "image-offset", args_info
->image_offset_orig
, 0);
417 if (args_info
->tag_version_given
)
418 write_into_file(outfile
, "tag-version", args_info
->tag_version_orig
, 0);
419 if (args_info
->signature_given
)
420 write_into_file(outfile
, "signature", args_info
->signature_orig
, 0);
421 if (args_info
->signature2_given
)
422 write_into_file(outfile
, "signature2", args_info
->signature2_orig
, 0);
423 if (args_info
->block_size_given
)
424 write_into_file(outfile
, "block-size", args_info
->block_size_orig
, 0);
425 if (args_info
->load_addr_given
)
426 write_into_file(outfile
, "load-addr", args_info
->load_addr_orig
, 0);
427 if (args_info
->entry_given
)
428 write_into_file(outfile
, "entry", args_info
->entry_orig
, 0);
429 if (args_info
->layoutver_given
)
430 write_into_file(outfile
, "layoutver", args_info
->layoutver_orig
, 0);
431 if (args_info
->info1_given
)
432 write_into_file(outfile
, "info1", args_info
->info1_orig
, 0);
433 if (args_info
->altinfo_given
)
434 write_into_file(outfile
, "altinfo", args_info
->altinfo_orig
, 0);
435 if (args_info
->info2_given
)
436 write_into_file(outfile
, "info2", args_info
->info2_orig
, 0);
437 if (args_info
->root_first_given
)
438 write_into_file(outfile
, "root-first", 0, 0 );
439 if (args_info
->rsa_signature_given
)
440 write_into_file(outfile
, "rsa-signature", args_info
->rsa_signature_orig
, 0);
441 if (args_info
->second_image_flag_given
)
442 write_into_file(outfile
, "second-image-flag", args_info
->second_image_flag_orig
, cmdline_parser_second_image_flag_values
);
443 if (args_info
->inactive_given
)
444 write_into_file(outfile
, "inactive", args_info
->inactive_orig
, cmdline_parser_inactive_values
);
445 if (args_info
->reserved2_given
)
446 write_into_file(outfile
, "reserved2", args_info
->reserved2_orig
, 0);
447 if (args_info
->kernel_file_has_header_given
)
448 write_into_file(outfile
, "kernel-file-has-header", 0, 0 );
456 cmdline_parser_file_save(const char *filename
, struct gengetopt_args_info
*args_info
)
461 outfile
= fopen(filename
, "w");
465 fprintf (stderr
, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE
, filename
);
469 i
= cmdline_parser_dump(outfile
, args_info
);
476 cmdline_parser_free (struct gengetopt_args_info
*args_info
)
478 cmdline_parser_release (args_info
);
481 /** @brief replacement of strdup, which is not standard */
483 gengetopt_strdup (const char *s
)
489 result
= (char*)malloc(strlen(s
) + 1);
490 if (result
== (char*)0)
497 cmdline_parser (int argc
, char **argv
, struct gengetopt_args_info
*args_info
)
499 return cmdline_parser2 (argc
, argv
, args_info
, 0, 1, 1);
503 cmdline_parser_ext (int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
504 struct cmdline_parser_params
*params
)
507 result
= cmdline_parser_internal (argc
, argv
, args_info
, params
, 0);
509 if (result
== EXIT_FAILURE
)
511 cmdline_parser_free (args_info
);
519 cmdline_parser2 (int argc
, char **argv
, struct gengetopt_args_info
*args_info
, int override
, int initialize
, int check_required
)
522 struct cmdline_parser_params params
;
524 params
.override
= override
;
525 params
.initialize
= initialize
;
526 params
.check_required
= check_required
;
527 params
.check_ambiguity
= 0;
528 params
.print_errors
= 1;
530 result
= cmdline_parser_internal (argc
, argv
, args_info
, ¶ms
, 0);
532 if (result
== EXIT_FAILURE
)
534 cmdline_parser_free (args_info
);
542 cmdline_parser_required (struct gengetopt_args_info
*args_info
, const char *prog_name
)
544 int result
= EXIT_SUCCESS
;
546 if (cmdline_parser_required2(args_info
, prog_name
, 0) > 0)
547 result
= EXIT_FAILURE
;
549 if (result
== EXIT_FAILURE
)
551 cmdline_parser_free (args_info
);
559 cmdline_parser_required2 (struct gengetopt_args_info
*args_info
, const char *prog_name
, const char *additional_error
)
562 FIX_UNUSED (additional_error
);
564 /* checks for required options */
565 if (! args_info
->kernel_given
)
567 fprintf (stderr
, "%s: '--kernel' ('-i') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
571 if (! args_info
->rootfs_given
)
573 fprintf (stderr
, "%s: '--rootfs' ('-f') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
577 if (! args_info
->output_given
)
579 fprintf (stderr
, "%s: '--output' ('-o') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
583 if (! args_info
->boardid_given
)
585 fprintf (stderr
, "%s: '--boardid' ('-b') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
589 if (! args_info
->chipid_given
)
591 fprintf (stderr
, "%s: '--chipid' ('-c') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
595 if (! args_info
->load_addr_given
)
597 fprintf (stderr
, "%s: '--load-addr' ('-l') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
601 if (! args_info
->entry_given
)
603 fprintf (stderr
, "%s: '--entry' ('-e') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
608 /* checks for dependences among options */
614 static char *package_name
= 0;
617 * @brief updates an option
618 * @param field the generic pointer to the field to update
619 * @param orig_field the pointer to the orig field
620 * @param field_given the pointer to the number of occurrence of this option
621 * @param prev_given the pointer to the number of occurrence already seen
622 * @param value the argument for this option (if null no arg was specified)
623 * @param possible_values the possible values for this option (if specified)
624 * @param default_value the default value (in case the option only accepts fixed values)
625 * @param arg_type the type of this option
626 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
627 * @param override @see cmdline_parser_params.override
628 * @param no_free whether to free a possible previous value
629 * @param multiple_option whether this is a multiple option
630 * @param long_opt the corresponding long option
631 * @param short_opt the corresponding short option (or '-' if none)
632 * @param additional_error possible further error specification
635 int update_arg(void *field
, char **orig_field
,
636 unsigned int *field_given
, unsigned int *prev_given
,
637 char *value
, const char *possible_values
[],
638 const char *default_value
,
639 cmdline_parser_arg_type arg_type
,
640 int check_ambiguity
, int override
,
641 int no_free
, int multiple_option
,
642 const char *long_opt
, char short_opt
,
643 const char *additional_error
)
646 const char *val
= value
;
654 if (!multiple_option
&& prev_given
&& (*prev_given
|| (check_ambiguity
&& *field_given
)))
656 if (short_opt
!= '-')
657 fprintf (stderr
, "%s: `--%s' (`-%c') option given more than once%s\n",
658 package_name
, long_opt
, short_opt
,
659 (additional_error
? additional_error
: ""));
661 fprintf (stderr
, "%s: `--%s' option given more than once%s\n",
662 package_name
, long_opt
,
663 (additional_error
? additional_error
: ""));
664 return 1; /* failure */
667 if (possible_values
&& (found
= check_possible_values((value
? value
: default_value
), possible_values
)) < 0)
669 if (short_opt
!= '-')
670 fprintf (stderr
, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n",
671 package_name
, (found
== -2) ? "ambiguous" : "invalid", value
, long_opt
, short_opt
,
672 (additional_error
? additional_error
: ""));
674 fprintf (stderr
, "%s: %s argument, \"%s\", for option `--%s'%s\n",
675 package_name
, (found
== -2) ? "ambiguous" : "invalid", value
, long_opt
,
676 (additional_error
? additional_error
: ""));
677 return 1; /* failure */
680 if (field_given
&& *field_given
&& ! override
)
687 val
= possible_values
[found
];
691 *((int *)field
) = !*((int *)field
);
695 string_field
= (char **)field
;
696 if (!no_free
&& *string_field
)
697 free (*string_field
); /* free previous string */
698 *string_field
= gengetopt_strdup (val
);
706 /* store the original value */
712 if (value
&& orig_field
) {
717 free (*orig_field
); /* free previous string */
718 *orig_field
= gengetopt_strdup (value
);
728 cmdline_parser_internal (
729 int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
730 struct cmdline_parser_params
*params
, const char *additional_error
)
732 int c
; /* Character of the parsed option. */
735 struct gengetopt_args_info local_args_info
;
742 package_name
= argv
[0];
744 override
= params
->override
;
745 initialize
= params
->initialize
;
746 check_required
= params
->check_required
;
747 check_ambiguity
= params
->check_ambiguity
;
750 cmdline_parser_init (args_info
);
752 cmdline_parser_init (&local_args_info
);
756 opterr
= params
->print_errors
;
761 int option_index
= 0;
763 static struct option long_options
[] = {
764 { "help", 0, NULL
, 'h' },
765 { "version", 0, NULL
, 'V' },
766 { "kernel", 1, NULL
, 'i' },
767 { "rootfs", 1, NULL
, 'f' },
768 { "output", 1, NULL
, 'o' },
769 { "cfe", 1, NULL
, 0 },
770 { "boardid", 1, NULL
, 'b' },
771 { "chipid", 1, NULL
, 'c' },
772 { "flash-start", 1, NULL
, 's' },
773 { "image-offset", 1, NULL
, 'n' },
774 { "tag-version", 1, NULL
, 'v' },
775 { "signature", 1, NULL
, 'a' },
776 { "signature2", 1, NULL
, 'm' },
777 { "block-size", 1, NULL
, 'k' },
778 { "load-addr", 1, NULL
, 'l' },
779 { "entry", 1, NULL
, 'e' },
780 { "layoutver", 1, NULL
, 'y' },
781 { "info1", 1, NULL
, '1' },
782 { "altinfo", 1, NULL
, 0 },
783 { "info2", 1, NULL
, '2' },
784 { "root-first", 0, NULL
, 0 },
785 { "rsa-signature", 1, NULL
, 'r' },
786 { "second-image-flag", 1, NULL
, 0 },
787 { "inactive", 1, NULL
, 0 },
788 { "reserved2", 1, NULL
, 0 },
789 { "kernel-file-has-header", 0, NULL
, 0 },
793 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
);
795 if (c
== -1) break; /* Exit from `while (1)' loop. */
799 case 'h': /* Print help and exit. */
800 cmdline_parser_print_help ();
801 cmdline_parser_free (&local_args_info
);
804 case 'V': /* Print version and exit. */
805 cmdline_parser_print_version ();
806 cmdline_parser_free (&local_args_info
);
809 case 'i': /* File with LZMA compressed kernel to include in the image.. */
812 if (update_arg( (void *)&(args_info
->kernel_arg
),
813 &(args_info
->kernel_orig
), &(args_info
->kernel_given
),
814 &(local_args_info
.kernel_given
), optarg
, 0, 0, ARG_STRING
,
815 check_ambiguity
, override
, 0, 0,
821 case 'f': /* File with RootFS to include in the image.. */
824 if (update_arg( (void *)&(args_info
->rootfs_arg
),
825 &(args_info
->rootfs_orig
), &(args_info
->rootfs_given
),
826 &(local_args_info
.rootfs_given
), optarg
, 0, 0, ARG_STRING
,
827 check_ambiguity
, override
, 0, 0,
833 case 'o': /* Name of output file.. */
836 if (update_arg( (void *)&(args_info
->output_arg
),
837 &(args_info
->output_orig
), &(args_info
->output_given
),
838 &(local_args_info
.output_given
), optarg
, 0, 0, ARG_STRING
,
839 check_ambiguity
, override
, 0, 0,
845 case 'b': /* Board ID to set in the image (must match what router expects, e.g. \"96345GW2\").. */
848 if (update_arg( (void *)&(args_info
->boardid_arg
),
849 &(args_info
->boardid_orig
), &(args_info
->boardid_given
),
850 &(local_args_info
.boardid_given
), optarg
, 0, 0, ARG_STRING
,
851 check_ambiguity
, override
, 0, 0,
857 case 'c': /* Chip ID to set in the image (must match the actual hardware, e.g. \"6345\").. */
860 if (update_arg( (void *)&(args_info
->chipid_arg
),
861 &(args_info
->chipid_orig
), &(args_info
->chipid_given
),
862 &(local_args_info
.chipid_given
), optarg
, 0, 0, ARG_STRING
,
863 check_ambiguity
, override
, 0, 0,
869 case 's': /* Flash start address.. */
872 if (update_arg( (void *)&(args_info
->flash_start_arg
),
873 &(args_info
->flash_start_orig
), &(args_info
->flash_start_given
),
874 &(local_args_info
.flash_start_given
), optarg
, 0, "0xBFC00000", ARG_STRING
,
875 check_ambiguity
, override
, 0, 0,
881 case 'n': /* Offset from start address for the first byte after the CFE (in memory).. */
884 if (update_arg( (void *)&(args_info
->image_offset_arg
),
885 &(args_info
->image_offset_orig
), &(args_info
->image_offset_given
),
886 &(local_args_info
.image_offset_given
), optarg
, 0, "0x10000", ARG_STRING
,
887 check_ambiguity
, override
, 0, 0,
893 case 'v': /* Version number for imagetag format.. */
896 if (update_arg( (void *)&(args_info
->tag_version_arg
),
897 &(args_info
->tag_version_orig
), &(args_info
->tag_version_given
),
898 &(local_args_info
.tag_version_given
), optarg
, 0, "6", ARG_STRING
,
899 check_ambiguity
, override
, 0, 0,
905 case 'a': /* Magic string (signature), for boards that need it.. */
908 if (update_arg( (void *)&(args_info
->signature_arg
),
909 &(args_info
->signature_orig
), &(args_info
->signature_given
),
910 &(local_args_info
.signature_given
), optarg
, 0, "Broadcom Corporatio", ARG_STRING
,
911 check_ambiguity
, override
, 0, 0,
917 case 'm': /* Second magic string (signature2).. */
920 if (update_arg( (void *)&(args_info
->signature2_arg
),
921 &(args_info
->signature2_orig
), &(args_info
->signature2_given
),
922 &(local_args_info
.signature2_given
), optarg
, 0, "ver. 2.0", ARG_STRING
,
923 check_ambiguity
, override
, 0, 0,
929 case 'k': /* Flash erase block size.. */
932 if (update_arg( (void *)&(args_info
->block_size_arg
),
933 &(args_info
->block_size_orig
), &(args_info
->block_size_given
),
934 &(local_args_info
.block_size_given
), optarg
, 0, "0x10000", ARG_STRING
,
935 check_ambiguity
, override
, 0, 0,
941 case 'l': /* Kernel load address.. */
944 if (update_arg( (void *)&(args_info
->load_addr_arg
),
945 &(args_info
->load_addr_orig
), &(args_info
->load_addr_given
),
946 &(local_args_info
.load_addr_given
), optarg
, 0, 0, ARG_STRING
,
947 check_ambiguity
, override
, 0, 0,
953 case 'e': /* Address where the kernel entry point will be for booting.. */
956 if (update_arg( (void *)&(args_info
->entry_arg
),
957 &(args_info
->entry_orig
), &(args_info
->entry_given
),
958 &(local_args_info
.entry_given
), optarg
, 0, 0, ARG_STRING
,
959 check_ambiguity
, override
, 0, 0,
965 case 'y': /* Flash layout version (version 2.2x of the Broadcom code requires this).. */
968 if (update_arg( (void *)&(args_info
->layoutver_arg
),
969 &(args_info
->layoutver_orig
), &(args_info
->layoutver_given
),
970 &(local_args_info
.layoutver_given
), optarg
, 0, 0, ARG_STRING
,
971 check_ambiguity
, override
, 0, 0,
977 case '1': /* String for first vendor information section.. */
980 if (update_arg( (void *)&(args_info
->info1_arg
),
981 &(args_info
->info1_orig
), &(args_info
->info1_given
),
982 &(local_args_info
.info1_given
), optarg
, 0, 0, ARG_STRING
,
983 check_ambiguity
, override
, 0, 0,
989 case '2': /* String for second vendor information section.. */
992 if (update_arg( (void *)&(args_info
->info2_arg
),
993 &(args_info
->info2_orig
), &(args_info
->info2_given
),
994 &(local_args_info
.info2_given
), optarg
, 0, 0, ARG_STRING
,
995 check_ambiguity
, override
, 0, 0,
1001 case 'r': /* String for RSA Signature section.. */
1004 if (update_arg( (void *)&(args_info
->rsa_signature_arg
),
1005 &(args_info
->rsa_signature_orig
), &(args_info
->rsa_signature_given
),
1006 &(local_args_info
.rsa_signature_given
), optarg
, 0, 0, ARG_STRING
,
1007 check_ambiguity
, override
, 0, 0,
1008 "rsa-signature", 'r',
1014 case 0: /* Long option with no short option */
1015 /* File with CFE to include in the image.. */
1016 if (strcmp (long_options
[option_index
].name
, "cfe") == 0)
1020 if (update_arg( (void *)&(args_info
->cfe_arg
),
1021 &(args_info
->cfe_orig
), &(args_info
->cfe_given
),
1022 &(local_args_info
.cfe_given
), optarg
, 0, 0, ARG_STRING
,
1023 check_ambiguity
, override
, 0, 0,
1029 /* String for vendor information section (alternate/pirelli).. */
1030 else if (strcmp (long_options
[option_index
].name
, "altinfo") == 0)
1034 if (update_arg( (void *)&(args_info
->altinfo_arg
),
1035 &(args_info
->altinfo_orig
), &(args_info
->altinfo_given
),
1036 &(local_args_info
.altinfo_given
), optarg
, 0, 0, ARG_STRING
,
1037 check_ambiguity
, override
, 0, 0,
1043 /* Put the rootfs before the kernel (only for stock images, e.g. captured from the router's flash memory).. */
1044 else if (strcmp (long_options
[option_index
].name
, "root-first") == 0)
1048 if (update_arg((void *)&(args_info
->root_first_flag
), 0, &(args_info
->root_first_given
),
1049 &(local_args_info
.root_first_given
), optarg
, 0, 0, ARG_FLAG
,
1050 check_ambiguity
, override
, 1, 0, "root-first", '-',
1055 /* Dual Image Flag (2=not-specified).. */
1056 else if (strcmp (long_options
[option_index
].name
, "second-image-flag") == 0)
1060 if (update_arg( (void *)&(args_info
->second_image_flag_arg
),
1061 &(args_info
->second_image_flag_orig
), &(args_info
->second_image_flag_given
),
1062 &(local_args_info
.second_image_flag_given
), optarg
, cmdline_parser_second_image_flag_values
, "2", ARG_STRING
,
1063 check_ambiguity
, override
, 0, 0,
1064 "second-image-flag", '-',
1069 /* Inactive Flag (2=not-specified).. */
1070 else if (strcmp (long_options
[option_index
].name
, "inactive") == 0)
1074 if (update_arg( (void *)&(args_info
->inactive_arg
),
1075 &(args_info
->inactive_orig
), &(args_info
->inactive_given
),
1076 &(local_args_info
.inactive_given
), optarg
, cmdline_parser_inactive_values
, "2", ARG_STRING
,
1077 check_ambiguity
, override
, 0, 0,
1083 /* String for second reserved section.. */
1084 else if (strcmp (long_options
[option_index
].name
, "reserved2") == 0)
1088 if (update_arg( (void *)&(args_info
->reserved2_arg
),
1089 &(args_info
->reserved2_orig
), &(args_info
->reserved2_given
),
1090 &(local_args_info
.reserved2_given
), optarg
, 0, 0, ARG_STRING
,
1091 check_ambiguity
, override
, 0, 0,
1097 /* Indicates that the kernel file includes the kernel header with correct load address and entry point, so no changes are needed. */
1098 else if (strcmp (long_options
[option_index
].name
, "kernel-file-has-header") == 0)
1102 if (update_arg((void *)&(args_info
->kernel_file_has_header_flag
), 0, &(args_info
->kernel_file_has_header_given
),
1103 &(local_args_info
.kernel_file_has_header_given
), optarg
, 0, 0, ARG_FLAG
,
1104 check_ambiguity
, override
, 1, 0, "kernel-file-has-header", '-',
1111 case '?': /* Invalid option. */
1112 /* `getopt_long' already printed an error message. */
1115 default: /* bug: option not considered. */
1116 fprintf (stderr
, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE
, c
, (additional_error
? additional_error
: ""));
1125 error
+= cmdline_parser_required2 (args_info
, argv
[0], additional_error
);
1128 cmdline_parser_release (&local_args_info
);
1131 return (EXIT_FAILURE
);
1137 cmdline_parser_release (&local_args_info
);
1138 return (EXIT_FAILURE
);