firmware-utils: mksenaofw: rework option validation

The options firmware_type, vendor_id and product_id are not required
for decoding an image file.

Signed-off-by: Mathias Kresin <dev@kresin.me>
This commit is contained in:
Mathias Kresin 2016-08-17 20:08:52 +02:00
parent 083ef3fefe
commit 0ac50a661b

View file

@ -386,32 +386,35 @@ int main(int argc, char *argv[])
}
/* Check required arguments */
if (mode == NONE) {
fprintf(stderr, "A mode must be defined\n");
usage(progname, EXIT_FAILURE);
}
if (input_file == NULL || output_file == NULL) {
fprintf(stderr, "Input and output files must be defined\n");
usage(progname, EXIT_FAILURE);
}
if (mode == DECODE) {
if (decode_image(input_file, output_file) < 0)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
if (header.firmware_type == 0) {
fprintf(stderr, "Firmware type must be defined\n");
usage(progname, EXIT_FAILURE);
} else if (input_file == 0 || output_file == 0) {
fprintf(stderr, "Input and output files must be defined\n");
usage(progname, EXIT_FAILURE);
} else if (header.vendor_id == 0 || header.product_id == 0) {
}
if (header.vendor_id == 0 || header.product_id == 0) {
fprintf(stderr, "Vendor ID and Product ID must be defined and non-zero\n");
usage(progname, EXIT_FAILURE);
}
switch (mode) {
case NONE:
fprintf(stderr, "A mode must be defined\n");
usage(progname, EXIT_FAILURE);
break;
case ENCODE:
if (encode_image(input_file, output_file, &header, pad ? block_size : 0)
< 0)
if (encode_image(input_file, output_file, &header, pad ? block_size : 0) < 0)
return EXIT_FAILURE;
break;
case DECODE:
if (decode_image(input_file, output_file) < 0)
return EXIT_FAILURE;
break;
}
return EXIT_SUCCESS;
}