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)",
61 " -p, --pad=size (in MiB) Pad the image to this size if smaller (in MiB)",
69 } cmdline_parser_arg_type
;
72 void clear_given (struct gengetopt_args_info
*args_info
);
74 void clear_args (struct gengetopt_args_info
*args_info
);
77 cmdline_parser_internal (int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
78 struct cmdline_parser_params
*params
, const char *additional_error
);
81 cmdline_parser_required2 (struct gengetopt_args_info
*args_info
, const char *prog_name
, const char *additional_error
);
83 const char *cmdline_parser_second_image_flag_values
[] = {"0", "1", "2", 0}; /*< Possible values for second-image-flag. */
84 const char *cmdline_parser_inactive_values
[] = {"0", "1", "2", 0}; /*< Possible values for inactive. */
87 gengetopt_strdup (const char *s
);
90 void clear_given (struct gengetopt_args_info
*args_info
)
92 args_info
->help_given
= 0 ;
93 args_info
->version_given
= 0 ;
94 args_info
->kernel_given
= 0 ;
95 args_info
->rootfs_given
= 0 ;
96 args_info
->output_given
= 0 ;
97 args_info
->cfe_given
= 0 ;
98 args_info
->boardid_given
= 0 ;
99 args_info
->chipid_given
= 0 ;
100 args_info
->flash_start_given
= 0 ;
101 args_info
->image_offset_given
= 0 ;
102 args_info
->tag_version_given
= 0 ;
103 args_info
->signature_given
= 0 ;
104 args_info
->signature2_given
= 0 ;
105 args_info
->block_size_given
= 0 ;
106 args_info
->load_addr_given
= 0 ;
107 args_info
->entry_given
= 0 ;
108 args_info
->layoutver_given
= 0 ;
109 args_info
->info1_given
= 0 ;
110 args_info
->altinfo_given
= 0 ;
111 args_info
->info2_given
= 0 ;
112 args_info
->root_first_given
= 0 ;
113 args_info
->rsa_signature_given
= 0 ;
114 args_info
->second_image_flag_given
= 0 ;
115 args_info
->inactive_given
= 0 ;
116 args_info
->reserved2_given
= 0 ;
117 args_info
->kernel_file_has_header_given
= 0 ;
118 args_info
->pad_given
= 0 ;
122 void clear_args (struct gengetopt_args_info
*args_info
)
124 FIX_UNUSED (args_info
);
125 args_info
->kernel_arg
= NULL
;
126 args_info
->kernel_orig
= NULL
;
127 args_info
->rootfs_arg
= NULL
;
128 args_info
->rootfs_orig
= NULL
;
129 args_info
->output_arg
= NULL
;
130 args_info
->output_orig
= NULL
;
131 args_info
->cfe_arg
= NULL
;
132 args_info
->cfe_orig
= NULL
;
133 args_info
->boardid_arg
= NULL
;
134 args_info
->boardid_orig
= NULL
;
135 args_info
->chipid_arg
= NULL
;
136 args_info
->chipid_orig
= NULL
;
137 args_info
->flash_start_arg
= gengetopt_strdup ("0xBFC00000");
138 args_info
->flash_start_orig
= NULL
;
139 args_info
->image_offset_arg
= gengetopt_strdup ("0x10000");
140 args_info
->image_offset_orig
= NULL
;
141 args_info
->tag_version_arg
= gengetopt_strdup ("6");
142 args_info
->tag_version_orig
= NULL
;
143 args_info
->signature_arg
= gengetopt_strdup ("Broadcom Corporatio");
144 args_info
->signature_orig
= NULL
;
145 args_info
->signature2_arg
= gengetopt_strdup ("ver. 2.0");
146 args_info
->signature2_orig
= NULL
;
147 args_info
->block_size_arg
= gengetopt_strdup ("0x10000");
148 args_info
->block_size_orig
= NULL
;
149 args_info
->load_addr_arg
= NULL
;
150 args_info
->load_addr_orig
= NULL
;
151 args_info
->entry_arg
= NULL
;
152 args_info
->entry_orig
= NULL
;
153 args_info
->layoutver_arg
= NULL
;
154 args_info
->layoutver_orig
= NULL
;
155 args_info
->info1_arg
= NULL
;
156 args_info
->info1_orig
= NULL
;
157 args_info
->altinfo_arg
= NULL
;
158 args_info
->altinfo_orig
= NULL
;
159 args_info
->info2_arg
= NULL
;
160 args_info
->info2_orig
= NULL
;
161 args_info
->root_first_flag
= 0;
162 args_info
->rsa_signature_arg
= NULL
;
163 args_info
->rsa_signature_orig
= NULL
;
164 args_info
->second_image_flag_arg
= gengetopt_strdup ("2");
165 args_info
->second_image_flag_orig
= NULL
;
166 args_info
->inactive_arg
= gengetopt_strdup ("2");
167 args_info
->inactive_orig
= NULL
;
168 args_info
->reserved2_arg
= NULL
;
169 args_info
->reserved2_orig
= NULL
;
170 args_info
->kernel_file_has_header_flag
= 0;
171 args_info
->pad_orig
= NULL
;
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
->reserved2_help
= gengetopt_args_info_help
[24] ;
205 args_info
->kernel_file_has_header_help
= gengetopt_args_info_help
[25] ;
206 args_info
->pad_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
->reserved2_arg
));
330 free_string_field (&(args_info
->reserved2_orig
));
331 free_string_field (&(args_info
->pad_orig
));
335 clear_given (args_info
);
339 * @param val the value to check
340 * @param values the possible values
341 * @return the index of the matched value:
342 * -1 if no value matched,
343 * -2 if more than one value has matched
346 check_possible_values(const char *val
, const char *values
[])
351 if (!val
) /* otherwise strlen() crashes below */
352 return -1; /* -1 means no argument for the option */
356 for (i
= 0, len
= strlen(val
); values
[i
]; ++i
)
358 if (strncmp(val
, values
[i
], len
) == 0)
362 if (strlen(values
[i
]) == len
)
363 return i
; /* exact macth no need to check more */
367 if (found
== 1) /* one match: OK */
370 return (found
? -2 : -1); /* return many values or none matched */
375 write_into_file(FILE *outfile
, const char *opt
, const char *arg
, const char *values
[])
380 found
= check_possible_values(arg
, values
);
383 fprintf(outfile
, "%s=\"%s\" # %s\n", opt
, arg
, values
[found
]);
385 fprintf(outfile
, "%s=\"%s\"\n", opt
, arg
);
387 fprintf(outfile
, "%s\n", opt
);
393 cmdline_parser_dump(FILE *outfile
, struct gengetopt_args_info
*args_info
)
399 fprintf (stderr
, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE
);
403 if (args_info
->help_given
)
404 write_into_file(outfile
, "help", 0, 0 );
405 if (args_info
->version_given
)
406 write_into_file(outfile
, "version", 0, 0 );
407 if (args_info
->kernel_given
)
408 write_into_file(outfile
, "kernel", args_info
->kernel_orig
, 0);
409 if (args_info
->rootfs_given
)
410 write_into_file(outfile
, "rootfs", args_info
->rootfs_orig
, 0);
411 if (args_info
->output_given
)
412 write_into_file(outfile
, "output", args_info
->output_orig
, 0);
413 if (args_info
->cfe_given
)
414 write_into_file(outfile
, "cfe", args_info
->cfe_orig
, 0);
415 if (args_info
->boardid_given
)
416 write_into_file(outfile
, "boardid", args_info
->boardid_orig
, 0);
417 if (args_info
->chipid_given
)
418 write_into_file(outfile
, "chipid", args_info
->chipid_orig
, 0);
419 if (args_info
->flash_start_given
)
420 write_into_file(outfile
, "flash-start", args_info
->flash_start_orig
, 0);
421 if (args_info
->image_offset_given
)
422 write_into_file(outfile
, "image-offset", args_info
->image_offset_orig
, 0);
423 if (args_info
->tag_version_given
)
424 write_into_file(outfile
, "tag-version", args_info
->tag_version_orig
, 0);
425 if (args_info
->signature_given
)
426 write_into_file(outfile
, "signature", args_info
->signature_orig
, 0);
427 if (args_info
->signature2_given
)
428 write_into_file(outfile
, "signature2", args_info
->signature2_orig
, 0);
429 if (args_info
->block_size_given
)
430 write_into_file(outfile
, "block-size", args_info
->block_size_orig
, 0);
431 if (args_info
->load_addr_given
)
432 write_into_file(outfile
, "load-addr", args_info
->load_addr_orig
, 0);
433 if (args_info
->entry_given
)
434 write_into_file(outfile
, "entry", args_info
->entry_orig
, 0);
435 if (args_info
->layoutver_given
)
436 write_into_file(outfile
, "layoutver", args_info
->layoutver_orig
, 0);
437 if (args_info
->info1_given
)
438 write_into_file(outfile
, "info1", args_info
->info1_orig
, 0);
439 if (args_info
->altinfo_given
)
440 write_into_file(outfile
, "altinfo", args_info
->altinfo_orig
, 0);
441 if (args_info
->info2_given
)
442 write_into_file(outfile
, "info2", args_info
->info2_orig
, 0);
443 if (args_info
->root_first_given
)
444 write_into_file(outfile
, "root-first", 0, 0 );
445 if (args_info
->rsa_signature_given
)
446 write_into_file(outfile
, "rsa-signature", args_info
->rsa_signature_orig
, 0);
447 if (args_info
->second_image_flag_given
)
448 write_into_file(outfile
, "second-image-flag", args_info
->second_image_flag_orig
, cmdline_parser_second_image_flag_values
);
449 if (args_info
->inactive_given
)
450 write_into_file(outfile
, "inactive", args_info
->inactive_orig
, cmdline_parser_inactive_values
);
451 if (args_info
->reserved2_given
)
452 write_into_file(outfile
, "reserved2", args_info
->reserved2_orig
, 0);
453 if (args_info
->kernel_file_has_header_given
)
454 write_into_file(outfile
, "kernel-file-has-header", 0, 0 );
455 if (args_info
->pad_given
)
456 write_into_file(outfile
, "pad", args_info
->pad_orig
, 0);
464 cmdline_parser_file_save(const char *filename
, struct gengetopt_args_info
*args_info
)
469 outfile
= fopen(filename
, "w");
473 fprintf (stderr
, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE
, filename
);
477 i
= cmdline_parser_dump(outfile
, args_info
);
484 cmdline_parser_free (struct gengetopt_args_info
*args_info
)
486 cmdline_parser_release (args_info
);
489 /** @brief replacement of strdup, which is not standard */
491 gengetopt_strdup (const char *s
)
497 result
= (char*)malloc(strlen(s
) + 1);
498 if (result
== (char*)0)
505 cmdline_parser (int argc
, char **argv
, struct gengetopt_args_info
*args_info
)
507 return cmdline_parser2 (argc
, argv
, args_info
, 0, 1, 1);
511 cmdline_parser_ext (int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
512 struct cmdline_parser_params
*params
)
515 result
= cmdline_parser_internal (argc
, argv
, args_info
, params
, 0);
517 if (result
== EXIT_FAILURE
)
519 cmdline_parser_free (args_info
);
527 cmdline_parser2 (int argc
, char **argv
, struct gengetopt_args_info
*args_info
, int override
, int initialize
, int check_required
)
530 struct cmdline_parser_params params
;
532 params
.override
= override
;
533 params
.initialize
= initialize
;
534 params
.check_required
= check_required
;
535 params
.check_ambiguity
= 0;
536 params
.print_errors
= 1;
538 result
= cmdline_parser_internal (argc
, argv
, args_info
, ¶ms
, 0);
540 if (result
== EXIT_FAILURE
)
542 cmdline_parser_free (args_info
);
550 cmdline_parser_required (struct gengetopt_args_info
*args_info
, const char *prog_name
)
552 int result
= EXIT_SUCCESS
;
554 if (cmdline_parser_required2(args_info
, prog_name
, 0) > 0)
555 result
= EXIT_FAILURE
;
557 if (result
== EXIT_FAILURE
)
559 cmdline_parser_free (args_info
);
567 cmdline_parser_required2 (struct gengetopt_args_info
*args_info
, const char *prog_name
, const char *additional_error
)
570 FIX_UNUSED (additional_error
);
572 /* checks for required options */
573 if (! args_info
->kernel_given
)
575 fprintf (stderr
, "%s: '--kernel' ('-i') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
579 if (! args_info
->rootfs_given
)
581 fprintf (stderr
, "%s: '--rootfs' ('-f') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
585 if (! args_info
->output_given
)
587 fprintf (stderr
, "%s: '--output' ('-o') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
591 if (! args_info
->boardid_given
)
593 fprintf (stderr
, "%s: '--boardid' ('-b') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
597 if (! args_info
->chipid_given
)
599 fprintf (stderr
, "%s: '--chipid' ('-c') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
603 if (! args_info
->load_addr_given
)
605 fprintf (stderr
, "%s: '--load-addr' ('-l') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
609 if (! args_info
->entry_given
)
611 fprintf (stderr
, "%s: '--entry' ('-e') option required%s\n", prog_name
, (additional_error
? additional_error
: ""));
616 /* checks for dependences among options */
622 static char *package_name
= 0;
625 * @brief updates an option
626 * @param field the generic pointer to the field to update
627 * @param orig_field the pointer to the orig field
628 * @param field_given the pointer to the number of occurrence of this option
629 * @param prev_given the pointer to the number of occurrence already seen
630 * @param value the argument for this option (if null no arg was specified)
631 * @param possible_values the possible values for this option (if specified)
632 * @param default_value the default value (in case the option only accepts fixed values)
633 * @param arg_type the type of this option
634 * @param check_ambiguity @see cmdline_parser_params.check_ambiguity
635 * @param override @see cmdline_parser_params.override
636 * @param no_free whether to free a possible previous value
637 * @param multiple_option whether this is a multiple option
638 * @param long_opt the corresponding long option
639 * @param short_opt the corresponding short option (or '-' if none)
640 * @param additional_error possible further error specification
643 int update_arg(void *field
, char **orig_field
,
644 unsigned int *field_given
, unsigned int *prev_given
,
645 char *value
, const char *possible_values
[],
646 const char *default_value
,
647 cmdline_parser_arg_type arg_type
,
648 int check_ambiguity
, int override
,
649 int no_free
, int multiple_option
,
650 const char *long_opt
, char short_opt
,
651 const char *additional_error
)
654 const char *val
= value
;
662 if (!multiple_option
&& prev_given
&& (*prev_given
|| (check_ambiguity
&& *field_given
)))
664 if (short_opt
!= '-')
665 fprintf (stderr
, "%s: `--%s' (`-%c') option given more than once%s\n",
666 package_name
, long_opt
, short_opt
,
667 (additional_error
? additional_error
: ""));
669 fprintf (stderr
, "%s: `--%s' option given more than once%s\n",
670 package_name
, long_opt
,
671 (additional_error
? additional_error
: ""));
672 return 1; /* failure */
675 if (possible_values
&& (found
= check_possible_values((value
? value
: default_value
), possible_values
)) < 0)
677 if (short_opt
!= '-')
678 fprintf (stderr
, "%s: %s argument, \"%s\", for option `--%s' (`-%c')%s\n",
679 package_name
, (found
== -2) ? "ambiguous" : "invalid", value
, long_opt
, short_opt
,
680 (additional_error
? additional_error
: ""));
682 fprintf (stderr
, "%s: %s argument, \"%s\", for option `--%s'%s\n",
683 package_name
, (found
== -2) ? "ambiguous" : "invalid", value
, long_opt
,
684 (additional_error
? additional_error
: ""));
685 return 1; /* failure */
688 if (field_given
&& *field_given
&& ! override
)
695 val
= possible_values
[found
];
699 *((int *)field
) = !*((int *)field
);
702 if (val
) *((int *)field
) = strtol (val
, &stop_char
, 0);
706 string_field
= (char **)field
;
707 if (!no_free
&& *string_field
)
708 free (*string_field
); /* free previous string */
709 *string_field
= gengetopt_strdup (val
);
716 /* check numeric conversion */
719 if (val
&& !(stop_char
&& *stop_char
== '\0')) {
720 fprintf(stderr
, "%s: invalid numeric value: %s\n", package_name
, val
);
721 return 1; /* failure */
728 /* store the original value */
734 if (value
&& orig_field
) {
739 free (*orig_field
); /* free previous string */
740 *orig_field
= gengetopt_strdup (value
);
750 cmdline_parser_internal (
751 int argc
, char **argv
, struct gengetopt_args_info
*args_info
,
752 struct cmdline_parser_params
*params
, const char *additional_error
)
754 int c
; /* Character of the parsed option. */
757 struct gengetopt_args_info local_args_info
;
764 package_name
= argv
[0];
766 override
= params
->override
;
767 initialize
= params
->initialize
;
768 check_required
= params
->check_required
;
769 check_ambiguity
= params
->check_ambiguity
;
772 cmdline_parser_init (args_info
);
774 cmdline_parser_init (&local_args_info
);
778 opterr
= params
->print_errors
;
783 int option_index
= 0;
785 static struct option long_options
[] = {
786 { "help", 0, NULL
, 'h' },
787 { "version", 0, NULL
, 'V' },
788 { "kernel", 1, NULL
, 'i' },
789 { "rootfs", 1, NULL
, 'f' },
790 { "output", 1, NULL
, 'o' },
791 { "cfe", 1, NULL
, 0 },
792 { "boardid", 1, NULL
, 'b' },
793 { "chipid", 1, NULL
, 'c' },
794 { "flash-start", 1, NULL
, 's' },
795 { "image-offset", 1, NULL
, 'n' },
796 { "tag-version", 1, NULL
, 'v' },
797 { "signature", 1, NULL
, 'a' },
798 { "signature2", 1, NULL
, 'm' },
799 { "block-size", 1, NULL
, 'k' },
800 { "load-addr", 1, NULL
, 'l' },
801 { "entry", 1, NULL
, 'e' },
802 { "layoutver", 1, NULL
, 'y' },
803 { "info1", 1, NULL
, '1' },
804 { "altinfo", 1, NULL
, 0 },
805 { "info2", 1, NULL
, '2' },
806 { "root-first", 0, NULL
, 0 },
807 { "rsa-signature", 1, NULL
, 'r' },
808 { "second-image-flag", 1, NULL
, 0 },
809 { "inactive", 1, NULL
, 0 },
810 { "reserved2", 1, NULL
, 0 },
811 { "kernel-file-has-header", 0, NULL
, 0 },
812 { "pad", 1, NULL
, 'p' },
816 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
);
818 if (c
== -1) break; /* Exit from `while (1)' loop. */
822 case 'h': /* Print help and exit. */
823 cmdline_parser_print_help ();
824 cmdline_parser_free (&local_args_info
);
827 case 'V': /* Print version and exit. */
828 cmdline_parser_print_version ();
829 cmdline_parser_free (&local_args_info
);
832 case 'i': /* File with LZMA compressed kernel to include in the image.. */
835 if (update_arg( (void *)&(args_info
->kernel_arg
),
836 &(args_info
->kernel_orig
), &(args_info
->kernel_given
),
837 &(local_args_info
.kernel_given
), optarg
, 0, 0, ARG_STRING
,
838 check_ambiguity
, override
, 0, 0,
844 case 'f': /* File with RootFS to include in the image.. */
847 if (update_arg( (void *)&(args_info
->rootfs_arg
),
848 &(args_info
->rootfs_orig
), &(args_info
->rootfs_given
),
849 &(local_args_info
.rootfs_given
), optarg
, 0, 0, ARG_STRING
,
850 check_ambiguity
, override
, 0, 0,
856 case 'o': /* Name of output file.. */
859 if (update_arg( (void *)&(args_info
->output_arg
),
860 &(args_info
->output_orig
), &(args_info
->output_given
),
861 &(local_args_info
.output_given
), optarg
, 0, 0, ARG_STRING
,
862 check_ambiguity
, override
, 0, 0,
868 case 'b': /* Board ID to set in the image (must match what router expects, e.g. \"96345GW2\").. */
871 if (update_arg( (void *)&(args_info
->boardid_arg
),
872 &(args_info
->boardid_orig
), &(args_info
->boardid_given
),
873 &(local_args_info
.boardid_given
), optarg
, 0, 0, ARG_STRING
,
874 check_ambiguity
, override
, 0, 0,
880 case 'c': /* Chip ID to set in the image (must match the actual hardware, e.g. \"6345\").. */
883 if (update_arg( (void *)&(args_info
->chipid_arg
),
884 &(args_info
->chipid_orig
), &(args_info
->chipid_given
),
885 &(local_args_info
.chipid_given
), optarg
, 0, 0, ARG_STRING
,
886 check_ambiguity
, override
, 0, 0,
892 case 's': /* Flash start address.. */
895 if (update_arg( (void *)&(args_info
->flash_start_arg
),
896 &(args_info
->flash_start_orig
), &(args_info
->flash_start_given
),
897 &(local_args_info
.flash_start_given
), optarg
, 0, "0xBFC00000", ARG_STRING
,
898 check_ambiguity
, override
, 0, 0,
904 case 'n': /* Offset from start address for the first byte after the CFE (in memory).. */
907 if (update_arg( (void *)&(args_info
->image_offset_arg
),
908 &(args_info
->image_offset_orig
), &(args_info
->image_offset_given
),
909 &(local_args_info
.image_offset_given
), optarg
, 0, "0x10000", ARG_STRING
,
910 check_ambiguity
, override
, 0, 0,
916 case 'v': /* Version number for imagetag format.. */
919 if (update_arg( (void *)&(args_info
->tag_version_arg
),
920 &(args_info
->tag_version_orig
), &(args_info
->tag_version_given
),
921 &(local_args_info
.tag_version_given
), optarg
, 0, "6", ARG_STRING
,
922 check_ambiguity
, override
, 0, 0,
928 case 'a': /* Magic string (signature), for boards that need it.. */
931 if (update_arg( (void *)&(args_info
->signature_arg
),
932 &(args_info
->signature_orig
), &(args_info
->signature_given
),
933 &(local_args_info
.signature_given
), optarg
, 0, "Broadcom Corporatio", ARG_STRING
,
934 check_ambiguity
, override
, 0, 0,
940 case 'm': /* Second magic string (signature2).. */
943 if (update_arg( (void *)&(args_info
->signature2_arg
),
944 &(args_info
->signature2_orig
), &(args_info
->signature2_given
),
945 &(local_args_info
.signature2_given
), optarg
, 0, "ver. 2.0", ARG_STRING
,
946 check_ambiguity
, override
, 0, 0,
952 case 'k': /* Flash erase block size.. */
955 if (update_arg( (void *)&(args_info
->block_size_arg
),
956 &(args_info
->block_size_orig
), &(args_info
->block_size_given
),
957 &(local_args_info
.block_size_given
), optarg
, 0, "0x10000", ARG_STRING
,
958 check_ambiguity
, override
, 0, 0,
964 case 'l': /* Kernel load address.. */
967 if (update_arg( (void *)&(args_info
->load_addr_arg
),
968 &(args_info
->load_addr_orig
), &(args_info
->load_addr_given
),
969 &(local_args_info
.load_addr_given
), optarg
, 0, 0, ARG_STRING
,
970 check_ambiguity
, override
, 0, 0,
976 case 'e': /* Address where the kernel entry point will be for booting.. */
979 if (update_arg( (void *)&(args_info
->entry_arg
),
980 &(args_info
->entry_orig
), &(args_info
->entry_given
),
981 &(local_args_info
.entry_given
), optarg
, 0, 0, ARG_STRING
,
982 check_ambiguity
, override
, 0, 0,
988 case 'y': /* Flash layout version (version 2.2x of the Broadcom code requires this).. */
991 if (update_arg( (void *)&(args_info
->layoutver_arg
),
992 &(args_info
->layoutver_orig
), &(args_info
->layoutver_given
),
993 &(local_args_info
.layoutver_given
), optarg
, 0, 0, ARG_STRING
,
994 check_ambiguity
, override
, 0, 0,
1000 case '1': /* String for first vendor information section.. */
1003 if (update_arg( (void *)&(args_info
->info1_arg
),
1004 &(args_info
->info1_orig
), &(args_info
->info1_given
),
1005 &(local_args_info
.info1_given
), optarg
, 0, 0, ARG_STRING
,
1006 check_ambiguity
, override
, 0, 0,
1012 case '2': /* String for second vendor information section.. */
1015 if (update_arg( (void *)&(args_info
->info2_arg
),
1016 &(args_info
->info2_orig
), &(args_info
->info2_given
),
1017 &(local_args_info
.info2_given
), optarg
, 0, 0, ARG_STRING
,
1018 check_ambiguity
, override
, 0, 0,
1024 case 'r': /* String for RSA Signature section.. */
1027 if (update_arg( (void *)&(args_info
->rsa_signature_arg
),
1028 &(args_info
->rsa_signature_orig
), &(args_info
->rsa_signature_given
),
1029 &(local_args_info
.rsa_signature_given
), optarg
, 0, 0, ARG_STRING
,
1030 check_ambiguity
, override
, 0, 0,
1031 "rsa-signature", 'r',
1036 case 'p': /* Pad the image to this size if smaller (in MiB). */
1039 if (update_arg( (void *)&(args_info
->pad_arg
),
1040 &(args_info
->pad_orig
), &(args_info
->pad_given
),
1041 &(local_args_info
.pad_given
), optarg
, 0, 0, ARG_INT
,
1042 check_ambiguity
, override
, 0, 0,
1049 case 0: /* Long option with no short option */
1050 /* File with CFE to include in the image.. */
1051 if (strcmp (long_options
[option_index
].name
, "cfe") == 0)
1055 if (update_arg( (void *)&(args_info
->cfe_arg
),
1056 &(args_info
->cfe_orig
), &(args_info
->cfe_given
),
1057 &(local_args_info
.cfe_given
), optarg
, 0, 0, ARG_STRING
,
1058 check_ambiguity
, override
, 0, 0,
1064 /* String for vendor information section (alternate/pirelli).. */
1065 else if (strcmp (long_options
[option_index
].name
, "altinfo") == 0)
1069 if (update_arg( (void *)&(args_info
->altinfo_arg
),
1070 &(args_info
->altinfo_orig
), &(args_info
->altinfo_given
),
1071 &(local_args_info
.altinfo_given
), optarg
, 0, 0, ARG_STRING
,
1072 check_ambiguity
, override
, 0, 0,
1078 /* Put the rootfs before the kernel (only for stock images, e.g. captured from the router's flash memory).. */
1079 else if (strcmp (long_options
[option_index
].name
, "root-first") == 0)
1083 if (update_arg((void *)&(args_info
->root_first_flag
), 0, &(args_info
->root_first_given
),
1084 &(local_args_info
.root_first_given
), optarg
, 0, 0, ARG_FLAG
,
1085 check_ambiguity
, override
, 1, 0, "root-first", '-',
1090 /* Dual Image Flag (2=not-specified).. */
1091 else if (strcmp (long_options
[option_index
].name
, "second-image-flag") == 0)
1095 if (update_arg( (void *)&(args_info
->second_image_flag_arg
),
1096 &(args_info
->second_image_flag_orig
), &(args_info
->second_image_flag_given
),
1097 &(local_args_info
.second_image_flag_given
), optarg
, cmdline_parser_second_image_flag_values
, "2", ARG_STRING
,
1098 check_ambiguity
, override
, 0, 0,
1099 "second-image-flag", '-',
1104 /* Inactive Flag (2=not-specified).. */
1105 else if (strcmp (long_options
[option_index
].name
, "inactive") == 0)
1109 if (update_arg( (void *)&(args_info
->inactive_arg
),
1110 &(args_info
->inactive_orig
), &(args_info
->inactive_given
),
1111 &(local_args_info
.inactive_given
), optarg
, cmdline_parser_inactive_values
, "2", ARG_STRING
,
1112 check_ambiguity
, override
, 0, 0,
1118 /* String for second reserved section.. */
1119 else if (strcmp (long_options
[option_index
].name
, "reserved2") == 0)
1123 if (update_arg( (void *)&(args_info
->reserved2_arg
),
1124 &(args_info
->reserved2_orig
), &(args_info
->reserved2_given
),
1125 &(local_args_info
.reserved2_given
), optarg
, 0, 0, ARG_STRING
,
1126 check_ambiguity
, override
, 0, 0,
1132 /* Indicates that the kernel file includes the kernel header with correct load address and entry point, so no changes are needed. */
1133 else if (strcmp (long_options
[option_index
].name
, "kernel-file-has-header") == 0)
1137 if (update_arg((void *)&(args_info
->kernel_file_has_header_flag
), 0, &(args_info
->kernel_file_has_header_given
),
1138 &(local_args_info
.kernel_file_has_header_given
), optarg
, 0, 0, ARG_FLAG
,
1139 check_ambiguity
, override
, 1, 0, "kernel-file-has-header", '-',
1146 case '?': /* Invalid option. */
1147 /* `getopt_long' already printed an error message. */
1150 default: /* bug: option not considered. */
1151 fprintf (stderr
, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE
, c
, (additional_error
? additional_error
: ""));
1160 error
+= cmdline_parser_required2 (args_info
, argv
[0], additional_error
);
1163 cmdline_parser_release (&local_args_info
);
1166 return (EXIT_FAILURE
);
1172 cmdline_parser_release (&local_args_info
);
1173 return (EXIT_FAILURE
);