[PATCH] lib: strto: Stop detection when invalid char is used

Heiko Schocher hs at denx.de
Wed Apr 22 11:25:56 CEST 2020


Hello Michal,

Am 08.04.2020 um 10:09 schrieb Michal Simek:
> This issue has been found when mtd partition are specified. Autodetection
> code should stop when the first invalid char is found.
> 
> Here is the example of commands:
> setenv mtdids nand0=memory-controller at e000e000
> setenv mtdparts "mtdparts=nand0:4m(boot),4m(env),64m(kernel),96m(rootfs)"
> mtd list
> 
> Before:
> Zynq> mtd list
> List of MTD devices:
> * nand0
>    - type: NAND flash
>    - block size: 0x20000 bytes
>    - min I/O: 0x800 bytes
>    - OOB size: 64 bytes
>    - OOB available: 16 bytes
>    - ECC strength: 1 bits
>    - ECC step size: 2048 bytes
>    - bitflip threshold: 1 bits
>    - 0x000000000000-0x000010000000 : "nand0"
> 	  - 0x000000000000-0x000000400000 : "boot"
> 	  - 0x000000400000-0x000000800000 : "env"
> 	  - 0x000000800000-0x000006c00000 : "kernel"
> 	  - 0x000006c00000-0x000010000000 : "rootfs"
> 
> Where it is visible that kernel partition has 100m instead of 64m
> 
> After:
> Zynq> mtd list
> * nand0
>    - type: NAND flash
>    - block size: 0x20000 bytes
>    - min I/O: 0x800 bytes
>    - OOB size: 64 bytes
>    - OOB available: 16 bytes
>    - ECC strength: 1 bits
>    - ECC step size: 2048 bytes
>    - bitflip threshold: 1 bits
>    - 0x000000000000-0x000010000000 : "nand0"
> 	  - 0x000000000000-0x000000400000 : "boot"
> 	  - 0x000000400000-0x000000800000 : "env"
> 	  - 0x000000800000-0x000004800000 : "kernel"
> 	  - 0x000004800000-0x00000a800000 : "rootfs"
> 
> Signed-off-by: Michal Simek <michal.simek at xilinx.com>
> ---
> 
>   lib/strto.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/lib/strto.c b/lib/strto.c
> index 1ac2b09c725c..606701566f32 100644
> --- a/lib/strto.c
> +++ b/lib/strto.c
> @@ -34,6 +34,9 @@ static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base)
>   					*base = 16;
>   					break;
>   				}
> +
> +				if (!(var >= '0' && var <= '9'))
> +					break;
>   			} while (var);
>   		}
>   	}
> 

Fixes for me same problem, detected on imx6ull based board, thanks!

Tested-by: Heiko Schocher <hs at denx.de>

for the records:
mtdparts before this patch:

=> mtdparts

device nand0 <gpmi-nand>, # parts = 1
  #: name                size            offset          mask_flags
  0: ubi                 0x10000000      0x00000000      0

device nor0 <spi1.0>, # parts = 6
  #: name                size            offset          mask_flags
  0: spl                 0x00019000      0x00000000      0
  1: u-boot              0x001da000      0x00019000      0
  2: env                 0x00019000      0x001f3000      0
  3: env-red             0x00019000      0x0020c000      0
  4: key                 0x00019000      0x00225000      0
  5: rescue              0x00dc2000      0x0023e000      0

active partition: nand0,0 - (ubi) 0x10000000 @ 0x00000000

defaults:
mtdids  : nand0=gpmi-nand,nor0=spi1.0
mtdparts: 
mtdparts=gpmi-nand:-(ubi);spi1.0:64k(spl),768k(u-boot),64k(env),64k(env-red),64k(key),-(rescue)
=>

after

=> mtdparts

device nand0 <gpmi-nand>, # parts = 1
  #: name                size            offset          mask_flags
  0: ubi                 0x10000000      0x00000000      0

device nor0 <spi1.0>, # parts = 6
  #: name                size            offset          mask_flags
  0: spl                 0x00010000      0x00000000      0
  1: u-boot              0x000c0000      0x00010000      0
  2: env                 0x00010000      0x000d0000      0
  3: env-red             0x00010000      0x000e0000      0
  4: key                 0x00010000      0x000f0000      0
  5: rescue              0x00f00000      0x00100000      0

active partition: nand0,0 - (ubi) 0x10000000 @ 0x00000000

defaults:
mtdids  : nand0=gpmi-nand,nor0=spi1.0
mtdparts: 
mtdparts=gpmi-nand:-(ubi);spi1.0:64k(spl),768k(u-boot),64k(env),64k(env-red),64k(key),-(rescue)
=>

bye,
Heiko
-- 
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de


More information about the U-Boot mailing list