MLK-22259-2: cmd: mtdparts: skip invalid devices rather than quit
authorHan Xu <han.xu@nxp.com>
Fri, 12 Jul 2019 20:52:58 +0000 (15:52 -0500)
committerHan Xu <han.xu@nxp.com>
Tue, 16 Jul 2019 03:25:28 +0000 (22:25 -0500)
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>
cmd/mtdparts.c

index f7ed1a0..9cf8f3c 100644 (file)
@@ -157,6 +157,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),
@@ -1575,6 +1609,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;
 
@@ -1645,8 +1685,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;