From d414c89a61f1e74b1d49161c3d136ef55c3289de Mon Sep 17 00:00:00 2001 From: Dominic Chen Date: Tue, 3 Jun 2014 14:22:15 -0700 Subject: util: move console command argument parsing to util.c move parse_offset_size() from flash.c to util.c for SPI flash driver usage BRANCH=none BUG=none TEST=make buildall Change-Id: Ib4824d2a7e2f5b8c3e4b918d6507c072ded8837d Signed-off-by: Dominic Chen Reviewed-on: https://chromium-review.googlesource.com/202530 Reviewed-by: Randall Spangler --- common/flash.c | 32 -------------------------------- common/util.c | 35 +++++++++++++++++++++++++++++++++++ include/util.h | 9 +++++++++ 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/common/flash.c b/common/flash.c index 10dda3768b..09b773b809 100644 --- a/common/flash.c +++ b/common/flash.c @@ -301,38 +301,6 @@ int flash_set_protect(uint32_t mask, uint32_t flags) /*****************************************************************************/ /* Console commands */ -/** - * Parse offset and size from command line argv[shift] and argv[shift+1] - * - * Default values: If argc<=shift, leaves offset unchanged, returning error if - * *offset<0. If argc shift) { - i = (uint32_t)strtoi(argv[shift], &e, 0); - if (*e) - return EC_ERROR_PARAM1; - *offset = i; - } else if (*offset < 0) - return EC_ERROR_PARAM_COUNT; - - if (argc > shift + 1) { - i = (uint32_t)strtoi(argv[shift + 1], &e, 0); - if (*e) - return EC_ERROR_PARAM2; - *size = i; - } else if (*size < 0) - return EC_ERROR_PARAM_COUNT; - - return EC_SUCCESS; -} - static int command_flash_info(int argc, char **argv) { int i; diff --git a/common/util.c b/common/util.c index f8a0519f17..f1c3e9a41e 100644 --- a/common/util.c +++ b/common/util.c @@ -424,3 +424,38 @@ int cond_went(cond_t *c, int val) return ret; } + +/****************************************************************************/ +/* console command parsing */ + +/** + * Parse offset and size from command line argv[shift] and argv[shift+1] + * + * Default values: If argc<=shift, leaves offset unchanged, returning error if + * *offset<0. If argc shift) { + i = (uint32_t)strtoi(argv[shift], &e, 0); + if (*e) + return EC_ERROR_PARAM1; + *offset = i; + } else if (*offset < 0) + return EC_ERROR_PARAM_COUNT; + + if (argc > shift + 1) { + i = (uint32_t)strtoi(argv[shift + 1], &e, 0); + if (*e) + return EC_ERROR_PARAM2; + *size = i; + } else if (*size < 0) + return EC_ERROR_PARAM_COUNT; + + return EC_SUCCESS; +} diff --git a/include/util.h b/include/util.h index 8ba25c1780..89e07deb1e 100644 --- a/include/util.h +++ b/include/util.h @@ -158,4 +158,13 @@ int cond_went(cond_t *c, int boolean); static inline int cond_went_false(cond_t *c) { return cond_went(c, 0); } static inline int cond_went_true(cond_t *c) { return cond_went(c, 1); } +/****************************************************************************/ +/* Console command parsing */ + +/* Parse command-line arguments given integer shift value to obtain + * offset and size. + */ +int parse_offset_size(int argc, char **argv, int shift, + int *offset, int *size); + #endif /* __CROS_EC_UTIL_H */ -- cgit v1.2.1