summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/mtdparts.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c
index b40c2afadd..786841875e 100644
--- a/cmd/mtdparts.c
+++ b/cmd/mtdparts.c
@@ -158,6 +158,40 @@ static struct part_info* mtd_part_info(struct mtd_device *dev, unsigned int part
static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len);
static int device_del(struct mtd_device *dev);
+#ifdef CONFIG_MTDPARTS_SKIP_INVALID
+int skip_counter = 0;
+/*
+ * find a seperator to locate the next entry
+ * @param p pointer of the pointer of input char string
+ * @param sp seperator charactor
+ * @param n find the nth seperator
+ * @param limit the looking scope
+ * @return 1 on success, otherwise 0
+ */
+static int find_seperator(const char **p, char sp, int n, int limit)
+{
+ int i, j;
+
+ /* n = 0 means do nothing */
+ if (!n)
+ return 1;
+
+ i = j = 0;
+
+ while (*p && (**p != '\0') && (i < limit)) {
+ if (**p == sp) {
+ (*p)++;
+ j++;
+ if (j == n)
+ return 1;
+ }
+ (*p)++;
+ i++;
+ }
+
+ return 0;
+}
+#endif
/**
* Parses a string into a number. The number stored at ptr is
* potentially suffixed with K (for kilobytes, or 1024 bytes),
@@ -1576,6 +1610,12 @@ static int parse_mtdparts(const char *const mtdparts)
while (*p != '\0') {
err = 1;
+#ifdef CONFIG_MTDPARTS_SKIP_INVALID
+ if (!find_seperator(&p, ';', skip_counter, MTDPARTS_MAXLEN)) {
+ printf("goes wrong when skip invalid parts\n");
+ return 1;
+ }
+#endif
if ((device_parse(p, &p, &dev) != 0) || (!dev))
break;
@@ -1646,8 +1686,20 @@ static int parse_mtdids(const char *const ids)
p++;
/* check if requested device exists */
- if (mtd_device_validate(type, num, &size) != 0)
+ if (mtd_device_validate(type, num, &size) != 0) {
+#ifdef CONFIG_MTDPARTS_SKIP_INVALID
+ if (find_seperator(&p, ',', 1, MTDIDS_MAXLEN)) {
+ printf("current device is invalid, skip it and check the next one\n");
+ skip_counter++;
+ continue;
+ } else {
+ printf("the only deivce is invalid\n");
+ return 1;
+ }
+#else
return 1;
+#endif
+ }
/* locate <mtd-id> */
mtd_id = p;