From e674896123983e152ef3cc9d1304b775e5086a5e Mon Sep 17 00:00:00 2001 From: Han Xu Date: Fri, 12 Jul 2019 15:52:58 -0500 Subject: [PATCH] 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 , # 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 --- cmd/mtdparts.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/cmd/mtdparts.c b/cmd/mtdparts.c index f7ed1a0779..9cf8f3c17e 100644 --- a/cmd/mtdparts.c +++ b/cmd/mtdparts.c @@ -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 = p; -- 2.17.1