public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH] lib: strto: Stop detection when invalid char is used
@ 2020-04-08  8:09 Michal Simek
  2020-04-22  9:25 ` Heiko Schocher
  2020-04-26 11:26 ` Tom Rini
  0 siblings, 2 replies; 3+ messages in thread
From: Michal Simek @ 2020-04-08  8:09 UTC (permalink / raw)
  To: u-boot

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@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);
 		}
 	}
-- 
2.26.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] lib: strto: Stop detection when invalid char is used
  2020-04-08  8:09 [PATCH] lib: strto: Stop detection when invalid char is used Michal Simek
@ 2020-04-22  9:25 ` Heiko Schocher
  2020-04-26 11:26 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Heiko Schocher @ 2020-04-22  9:25 UTC (permalink / raw)
  To: u-boot

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@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@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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] lib: strto: Stop detection when invalid char is used
  2020-04-08  8:09 [PATCH] lib: strto: Stop detection when invalid char is used Michal Simek
  2020-04-22  9:25 ` Heiko Schocher
@ 2020-04-26 11:26 ` Tom Rini
  1 sibling, 0 replies; 3+ messages in thread
From: Tom Rini @ 2020-04-26 11:26 UTC (permalink / raw)
  To: u-boot

On Wed, Apr 08, 2020 at 10:09:16AM +0200, Michal Simek wrote:

> 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@xilinx.com>
> Tested-by: Heiko Schocher <hs@denx.de>

Applied to u-boot/master, thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200426/68b84333/attachment.sig>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-26 11:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-04-08  8:09 [PATCH] lib: strto: Stop detection when invalid char is used Michal Simek
2020-04-22  9:25 ` Heiko Schocher
2020-04-26 11:26 ` Tom Rini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox