summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorHan Xu <han.xu@nxp.com>2019-07-12 15:52:58 -0500
committerYe Li <ye.li@nxp.com>2020-04-26 23:36:19 -0700
commitbc55f88f1eec2c2bc1a21cc78b4ed7de8d1e4f10 (patch)
treea50ecc5e2eacbcc046d09d01b6b3112b57299876 /cmd
parent74c597e82e620cee377b045aa0a8d3b7cd025cb9 (diff)
MLK-22259-2: cmd: mtdparts: skip invalid devices rather than quit
mtdparts quit when invalid mtd devices found. Add thes patches to skip the invalid devices, so NAND partitions can be alway found to burn boot images. For instance, On i.MX6DL Sabreauto, nand config u-boot didn't enable the weim nor, so parsing 8000000.nor leads to error: Device nor0 not found! With the patches, we can skip this invalid device and still get nand boot partition table: Device nor0 not found! current device is invalid, skip it and check the next one device nand0 <gpmi-nand>, # parts = 5 0: nandboot 0x04000000 0x00000000 0 1: nandkernel 0x01000000 0x04000000 0 2: nanddtb 0x01000000 0x05000000 0 3: nandtee 0x01000000 0x06000000 0 4: nandrootfs 0xf9000000 0x07000000 0 active partition: nand0,0 - (nandboot) 0x04000000 @ 0x00000000 Signed-off-by: Han Xu <han.xu@nxp.com> (cherry picked from commit e674896123983e152ef3cc9d1304b775e5086a5e)
Diffstat (limited to 'cmd')
-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;