Commit 72226277a00f2a26f93c85dd57a9116ba790f480

Authored by Han Xu
Committed by Ye Li
1 parent f1baf8daee
Exists in emb_lf_v2022.04

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)
(cherry picked from commit 75e8911f64b27cc90b38b3780e9ebe88b2cadad2)
(cherry picked from commit fd9441bfa12858aeb533622b786553dc07bcef39)

Showing 1 changed file with 53 additions and 1 deletions Side-by-side Diff

... ... @@ -160,6 +160,40 @@
160 160 static struct mtdids* id_find_by_mtd_id(const char *mtd_id, unsigned int mtd_id_len);
161 161 static int device_del(struct mtd_device *dev);
162 162  
  163 +#ifdef CONFIG_MTDPARTS_SKIP_INVALID
  164 +int skip_counter = 0;
  165 +/*
  166 + * find a seperator to locate the next entry
  167 + * @param p pointer of the pointer of input char string
  168 + * @param sp seperator charactor
  169 + * @param n find the nth seperator
  170 + * @param limit the looking scope
  171 + * @return 1 on success, otherwise 0
  172 + */
  173 +static int find_seperator(const char **p, char sp, int n, int limit)
  174 +{
  175 + int i, j;
  176 +
  177 + /* n = 0 means do nothing */
  178 + if (!n)
  179 + return 1;
  180 +
  181 + i = j = 0;
  182 +
  183 + while (*p && (**p != '\0') && (i < limit)) {
  184 + if (**p == sp) {
  185 + (*p)++;
  186 + j++;
  187 + if (j == n)
  188 + return 1;
  189 + }
  190 + (*p)++;
  191 + i++;
  192 + }
  193 +
  194 + return 0;
  195 +}
  196 +#endif
163 197 /**
164 198 * Parses a string into a number. The number stored at ptr is
165 199 * potentially suffixed with K (for kilobytes, or 1024 bytes),
... ... @@ -1578,6 +1612,12 @@
1578 1612  
1579 1613 while (*p != '\0') {
1580 1614 err = 1;
  1615 +#ifdef CONFIG_MTDPARTS_SKIP_INVALID
  1616 + if (!find_seperator(&p, ';', skip_counter, MTDPARTS_MAXLEN)) {
  1617 + printf("goes wrong when skip invalid parts\n");
  1618 + return 1;
  1619 + }
  1620 +#endif
1581 1621 if ((device_parse(p, &p, &dev) != 0) || (!dev))
1582 1622 break;
1583 1623  
1584 1624  
... ... @@ -1648,8 +1688,20 @@
1648 1688 p++;
1649 1689  
1650 1690 /* check if requested device exists */
1651   - if (mtd_device_validate(type, num, &size) != 0)
  1691 + if (mtd_device_validate(type, num, &size) != 0) {
  1692 +#ifdef CONFIG_MTDPARTS_SKIP_INVALID
  1693 + if (find_seperator(&p, ',', 1, MTDIDS_MAXLEN)) {
  1694 + printf("current device is invalid, skip it and check the next one\n");
  1695 + skip_counter++;
  1696 + continue;
  1697 + } else {
  1698 + printf("the only deivce is invalid\n");
  1699 + return 1;
  1700 + }
  1701 +#else
1652 1702 return 1;
  1703 +#endif
  1704 + }
1653 1705  
1654 1706 /* locate <mtd-id> */
1655 1707 mtd_id = p;