Commit 75e8911f64b27cc90b38b3780e9ebe88b2cadad2

Authored by Han Xu
Committed by Ye Li
1 parent e6aebc13f8

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)

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

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