summaryrefslogtreecommitdiffstats
path: root/cli_classic.c
diff options
context:
space:
mode:
authorFelix Singer <felixsinger@posteo.net>2022-05-22 02:04:18 +0200
committerAnastasia Klimchuk <aklm@chromium.org>2022-08-14 22:28:26 +0000
commitf44a70ff8cdf349dd27070b33a956bbed3446285 (patch)
tree1684c60b1ec83d76043d255062286a9de945cb54 /cli_classic.c
parent9944a8a8a767149be7541aad3dca1742415933fa (diff)
downloadflashrom-f44a70ff8cdf349dd27070b33a956bbed3446285.tar.gz
flashrom-f44a70ff8cdf349dd27070b33a956bbed3446285.tar.bz2
flashrom-f44a70ff8cdf349dd27070b33a956bbed3446285.zip
cli_classic.c: Make use of bool type in the main function
Use the bool type instead of integer in the main function where possible, since this represents the purpose of some variables much better. Also, then we don't have to use the "!!" operator to turn any number into one or zero, which is used as an equivalent to true and false. Also, since we have booleans and integers now, slightly change the ordering of the variable declarations, so that the integers come before the booleans. Tested some parameters using the following commands: flashrom -L flashrom -p dummy flashrom -p dummy:emulate=SST25VF040.REMS,image=foo2 -c "SST25LF040A" --progress -v foo1 flashrom -p dummy:emulate=SST25VF040.REMS,image=foo2 -c "SST25LF040A" --progress -w foo1 flashrom -p dummy:emulate=SST25VF040.REMS,image=foo2 -c "SST25LF040A" --progress -r foo1 flashrom -p dummy:emulate=SST25VF040.REMS,image=foo2 -c "SST25LF040A" --progress -E Signed-off-by: Felix Singer <felixsinger@posteo.net> Change-Id: I06572da040e12ac88f8e5fc39f60a9e212b86bd7 Reviewed-on: https://review.coreboot.org/c/flashrom/+/64564 Reviewed-by: Evan Benn <evanbenn@google.com> Reviewed-by: Thomas Heijligen <src@posteo.de> Reviewed-by: Anastasia Klimchuk <aklm@chromium.org> Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Alexander Goncharov <chat@joursoir.net>
Diffstat (limited to 'cli_classic.c')
-rw-r--r--cli_classic.c71
1 files changed, 37 insertions, 34 deletions
diff --git a/cli_classic.c b/cli_classic.c
index 212534c94..991804d11 100644
--- a/cli_classic.c
+++ b/cli_classic.c
@@ -463,17 +463,20 @@ int main(int argc, char *argv[])
struct flashctx *fill_flash;
const char *name;
int namelen, opt, i, j;
- int startchip = -1, chipcount = 0, option_index = 0, force = 0, ifd = 0, fmap = 0;
+ int startchip = -1, chipcount = 0, option_index = 0;
+ int operation_specified = 0;
+ uint32_t wp_start = 0, wp_len = 0;
+ bool force = false, ifd = false, fmap = false;
#if CONFIG_PRINT_WIKI == 1
- int list_supported_wiki = 0;
+ bool list_supported_wiki = false;
#endif
- int flash_name = 0, flash_size = 0;
- int enable_wp = 0, disable_wp = 0, print_wp_status = 0;
- int set_wp_range = 0, set_wp_region = 0, print_wp_ranges = 0;
- uint32_t wp_start = 0, wp_len = 0;
- int read_it = 0, extract_it = 0, write_it = 0, erase_it = 0, verify_it = 0;
- int dont_verify_it = 0, dont_verify_all = 0, list_supported = 0, operation_specified = 0;
- int show_progress = 0;
+ bool flash_name = false, flash_size = false;
+ bool enable_wp = false, disable_wp = false, print_wp_status = false;
+ bool set_wp_range = false, set_wp_region = false, print_wp_ranges = false;
+ bool read_it = false, extract_it = false, write_it = false, erase_it = false, verify_it = false;
+ bool dont_verify_it = false, dont_verify_all = false;
+ bool list_supported = false;
+ bool show_progress = false;
struct flashrom_layout *layout = NULL;
static const struct programmer_entry *prog = NULL;
enum {
@@ -568,12 +571,12 @@ int main(int argc, char *argv[])
case 'r':
cli_classic_validate_singleop(&operation_specified);
filename = strdup(optarg);
- read_it = 1;
+ read_it = true;
break;
case 'w':
cli_classic_validate_singleop(&operation_specified);
filename = strdup(optarg);
- write_it = 1;
+ write_it = true;
break;
case 'v':
//FIXME: gracefully handle superfluous -v
@@ -582,20 +585,20 @@ int main(int argc, char *argv[])
cli_classic_abort_usage("--verify and --noverify are mutually exclusive. Aborting.\n");
}
filename = strdup(optarg);
- verify_it = 1;
+ verify_it = true;
break;
case 'n':
if (verify_it) {
cli_classic_abort_usage("--verify and --noverify are mutually exclusive. Aborting.\n");
}
- dont_verify_it = 1;
+ dont_verify_it = true;
break;
case 'N':
- dont_verify_all = 1;
+ dont_verify_all = true;
break;
case 'x':
cli_classic_validate_singleop(&operation_specified);
- extract_it = 1;
+ extract_it = true;
break;
case 'c':
chip_to_probe = strdup(optarg);
@@ -607,10 +610,10 @@ int main(int argc, char *argv[])
break;
case 'E':
cli_classic_validate_singleop(&operation_specified);
- erase_it = 1;
+ erase_it = true;
break;
case 'f':
- force = 1;
+ force = true;
break;
case 'l':
if (layoutfile)
@@ -626,7 +629,7 @@ int main(int argc, char *argv[])
cli_classic_abort_usage("Error: --layout and --ifd both specified. Aborting.\n");
if (fmap)
cli_classic_abort_usage("Error: --fmap-file and --ifd both specified. Aborting.\n");
- ifd = 1;
+ ifd = true;
break;
case OPTION_FMAP_FILE:
if (fmap)
@@ -637,7 +640,7 @@ int main(int argc, char *argv[])
if (layoutfile)
cli_classic_abort_usage("Error: --fmap-file and --layout both specified. Aborting.\n");
fmapfile = strdup(optarg);
- fmap = 1;
+ fmap = true;
break;
case OPTION_FMAP:
if (fmap)
@@ -647,7 +650,7 @@ int main(int argc, char *argv[])
cli_classic_abort_usage("Error: --fmap and --ifd both specified. Aborting.\n");
if (layoutfile)
cli_classic_abort_usage("Error: --layout and --fmap both specified. Aborting.\n");
- fmap = 1;
+ fmap = true;
break;
case 'i':
if (register_include_arg(&include_args, optarg))
@@ -661,42 +664,42 @@ int main(int argc, char *argv[])
break;
case OPTION_FLASH_NAME:
cli_classic_validate_singleop(&operation_specified);
- flash_name = 1;
+ flash_name = true;
break;
case OPTION_FLASH_SIZE:
cli_classic_validate_singleop(&operation_specified);
- flash_size = 1;
+ flash_size = true;
break;
case OPTION_WP_STATUS:
- print_wp_status = 1;
+ print_wp_status = true;
break;
case OPTION_WP_LIST:
- print_wp_ranges = 1;
+ print_wp_ranges = true;
break;
case OPTION_WP_SET_RANGE:
if (parse_wp_range(&wp_start, &wp_len) < 0)
cli_classic_abort_usage("Incorrect wp-range arguments provided.\n");
- set_wp_range = 1;
+ set_wp_range = true;
break;
case OPTION_WP_SET_REGION:
- set_wp_region = 1;
+ set_wp_region = true;
wp_region = strdup(optarg);
break;
case OPTION_WP_ENABLE:
- enable_wp = 1;
+ enable_wp = true;
break;
case OPTION_WP_DISABLE:
- disable_wp = 1;
+ disable_wp = true;
break;
case 'L':
cli_classic_validate_singleop(&operation_specified);
- list_supported = 1;
+ list_supported = true;
break;
case 'z':
#if CONFIG_PRINT_WIKI == 1
cli_classic_validate_singleop(&operation_specified);
- list_supported_wiki = 1;
+ list_supported_wiki = true;
#else
cli_classic_abort_usage("Error: Wiki output was not "
"compiled in. Aborting.\n");
@@ -768,7 +771,7 @@ int main(int argc, char *argv[])
}
break;
case OPTION_PROGRESS:
- show_progress = 1;
+ show_progress = true;
break;
default:
cli_classic_abort_usage(NULL);
@@ -924,7 +927,7 @@ int main(int argc, char *argv[])
goto out_shutdown;
}
msg_cinfo("Please note that forced reads most likely contain garbage.\n");
- flashrom_flag_set(&flashes[0], FLASHROM_FLAG_FORCE, !!force);
+ flashrom_flag_set(&flashes[0], FLASHROM_FLAG_FORCE, force);
ret = do_read(&flashes[0], filename);
free(flashes[0].chip);
goto out_shutdown;
@@ -1065,9 +1068,9 @@ int main(int argc, char *argv[])
goto out_release;
}
- flashrom_flag_set(fill_flash, FLASHROM_FLAG_FORCE, !!force);
+ flashrom_flag_set(fill_flash, FLASHROM_FLAG_FORCE, force);
#if CONFIG_INTERNAL == 1
- flashrom_flag_set(fill_flash, FLASHROM_FLAG_FORCE_BOARDMISMATCH, !!force_boardmismatch);
+ flashrom_flag_set(fill_flash, FLASHROM_FLAG_FORCE_BOARDMISMATCH, force_boardmismatch);
#endif
flashrom_flag_set(fill_flash, FLASHROM_FLAG_VERIFY_AFTER_WRITE, !dont_verify_it);
flashrom_flag_set(fill_flash, FLASHROM_FLAG_VERIFY_WHOLE_CHIP, !dont_verify_all);