diff options
author | Dominic Chen <ddchen@chromium.org> | 2014-06-03 14:22:15 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2014-06-11 00:17:06 +0000 |
commit | d414c89a61f1e74b1d49161c3d136ef55c3289de (patch) | |
tree | ad06a9b2951272b676f236019ce4ccaece784286 /common/util.c | |
parent | f317b4de30681026bc2284c6c2643b53afb8262b (diff) | |
download | chrome-ec-d414c89a61f1e74b1d49161c3d136ef55c3289de.tar.gz |
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 <ddchen@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/202530
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common/util.c')
-rw-r--r-- | common/util.c | 35 |
1 files changed, 35 insertions, 0 deletions
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+1, leaves size unchanged, returning error if + * *size<0. + */ +int parse_offset_size(int argc, char **argv, int shift, + int *offset, int *size) +{ + char *e; + int i; + + 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; +} |