aboutsummaryrefslogtreecommitdiffstats
path: root/tools/firmware-utils/src
diff options
context:
space:
mode:
authorMathias Kresin <dev@kresin.me>2016-08-17 20:08:52 +0200
committerMathias Kresin <dev@kresin.me>2016-08-17 20:08:52 +0200
commit0ac50a661b4c717f095d11caf51f6e3e610a608d (patch)
tree9eb0ece2eed95e61d83f0b9335be7ed05381ca7f /tools/firmware-utils/src
parent083ef3fefecd024b2b9cdc496e1f7811c225041e (diff)
downloadupstream-0ac50a661b4c717f095d11caf51f6e3e610a608d.tar.gz
upstream-0ac50a661b4c717f095d11caf51f6e3e610a608d.tar.bz2
upstream-0ac50a661b4c717f095d11caf51f6e3e610a608d.zip
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>
Diffstat (limited to 'tools/firmware-utils/src')
-rw-r--r--tools/firmware-utils/src/mksenaofw.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/tools/firmware-utils/src/mksenaofw.c b/tools/firmware-utils/src/mksenaofw.c
index 7ea58f56d7..0f10ebdfbe 100644
--- a/tools/firmware-utils/src/mksenaofw.c
+++ b/tools/firmware-utils/src/mksenaofw.c
@@ -385,33 +385,36 @@ int main(int argc, char *argv[])
}
}
- /* Check required arguments*/
- if (header.firmware_type == 0) {
- fprintf(stderr, "Firmware type must be defined\n");
+ /* Check required arguments */
+ if (mode == NONE) {
+ fprintf(stderr, "A mode must be defined\n");
usage(progname, EXIT_FAILURE);
- } else if (input_file == 0 || output_file == 0) {
+ }
+
+ if (input_file == NULL || output_file == NULL) {
fprintf(stderr, "Input and output files must be defined\n");
usage(progname, EXIT_FAILURE);
- } else if (header.vendor_id == 0 || header.product_id == 0) {
- fprintf(stderr, "Vendor ID and Product ID must be defined and non-zero\n");
+ }
+
+ 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);
}
- switch (mode) {
- case NONE:
- fprintf(stderr, "A mode must be defined\n");
+ 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);
- break;
- case ENCODE:
- 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;
}
+ if (encode_image(input_file, output_file, &header, pad ? block_size : 0) < 0)
+ return EXIT_FAILURE;
+
return EXIT_SUCCESS;
}