summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominic Chen <ddchen@chromium.org>2014-06-03 14:22:15 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-06-11 00:17:06 +0000
commitd414c89a61f1e74b1d49161c3d136ef55c3289de (patch)
treead06a9b2951272b676f236019ce4ccaece784286
parentf317b4de30681026bc2284c6c2643b53afb8262b (diff)
downloadchrome-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>
-rw-r--r--common/flash.c32
-rw-r--r--common/util.c35
-rw-r--r--include/util.h9
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+1, leaves size unchanged, returning error if
- * *size<0.
- */
-static 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;
-}
-
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+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;
+}
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 */