History log of /u-boot/lib/strto.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 467382ca 14-Dec-2023 Tom Rini <trini@konsulko.com>

lib: Remove <common.h> inclusion from these files

After some header file cleanups to add missing include files, remove
common.h from all files in the lib directory. This primarily means just
dropping the line but in a few cases we need to add in other header
files now.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Tom Rini <trini@konsulko.com>

# 3e96ed44 17-Jan-2023 Simon Glass <sjg@chromium.org>

lib: Add a function to split a string into substrings

Some environment variables provide a space-separated list of strings. It
is easier to process these when they are broken out into an array of
strings.

Add a utility function to handle this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8565efd5 24-Apr-2022 Simon Glass <sjg@chromium.org>

lib: Add a way to find the postiion of a trailing number

At present it is not possible to find out which part of the string is the
number part and which is before it. Add a new variant which provides this
feature, so we can separate the two in the caller.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d667a0d8 24-Apr-2022 Simon Glass <sjg@chromium.org>

lib: Fix a few bugs in trailing_strtoln()

At present this has a minor bug in that it reads the byte before the
start of the string, if it is empty. Also it doesn't handle a
non-numeric prefix which is only one character long.

Fix these bugs with a reworked implementation. Add a test for the second
case. The first one is hard to test.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# e6951139 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Allow using 0x when a decimal value is requested

U-Boot mostly uses hex for value input, largely because addresses are much
easier to understand in hex.

But in some cases a decimal value is requested, such as where the value is
small or hex does not make sense in the context. In these cases it is
sometimes useful to be able to provide a hex value in any case, if only to
resolve any ambiguity.

Add this functionality, for increased flexibility.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a94546e 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Move common digit-parsing code into a function

The code to convert a character into a digit is repeated twice in this
file. Factor it out into a separate function. This also makes the code a
little easier to read.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 96b23440 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Drop unnecessary check for hex digit

If we see 0x then we can assume this is the start of a hex value. It
does not seem necessary to check for a hex digit after that since it will
happen when parsing the value anyway.

Drop this check to simplify the code and reduce size. Add a few more test
cases for when a 0x prefix is used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b016428 22-Jul-2021 Roland Gaudig <roland.gaudig@weidmueller.com>

lib: strto: add simple_strtoll function

Add simple_strtoll function for converting a string containing digits
into a long long int value.

Signed-off-by: Roland Gaudig <roland.gaudig@weidmueller.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 4b485893 08-Apr-2020 Michal Simek <michal.simek@amd.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>

# 0486497e 07-Feb-2020 Michal Simek <michal.simek@amd.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>

# b87b0d8d 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: fix metric suffix parsing in strtoul[l]

While 1kB or 1kiB will be parsed correctly, 1k will return the right
amount, but the metric suffix will not be escaped once the char
pointer updated. Fix this situation by simplifying the move of the
endp pointer.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# a353e6aa 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: parse all lowercase metric prefixes in ustrtoul[l]

Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the
SI symbols for Mega and Giga are 'M' and 'G', certain entries of
eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'.

I do not see how parsing lowercase prefixes could break anything, so
parse them like their uppercase counterpart.

Also, even though kiB is not equal to kB in general, lets not change
U-Boot behavior and always use kiB and kB (same applies for MiB vs. MB
and GiB vs. GB) as a representation for 1024 instead of 1000.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# 2e794614 11-Sep-2017 Rob Clark <robdclark@gmail.com>

lib: strto: fix incorrect handling of specified base

The strto functions should honor the specified base (if non-zero) rather
than permitting a hex or octal string when the user wanted (for example)
base 10.

This has been fixed somewhere along the way in the upstream linux kernel
src tree, at some point after these was copied in to u-boot. And also
in a way that duplicates less code. So port _parse_integer_fixup_radix()
to u-boot.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b91c6a12 05-Oct-2016 Simon Glass <sjg@chromium.org>

Fix return value in trailing_strtoln()

This function should return -1 if there is no trailing integer in the
string. Instead it returns 0. Fix it by checking for this condition at the
start.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# e4c5383e 04-Dec-2015 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

lib: split out strtoxxxx functions out of vsprintf.c

To allow the various string to number conversion functions to be used
when using tiny-printf,split them out into their own file which gets
build regardless of what printf implementation is used.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>

# 3e96ed44 17-Jan-2023 Simon Glass <sjg@chromium.org>

lib: Add a function to split a string into substrings

Some environment variables provide a space-separated list of strings. It
is easier to process these when they are broken out into an array of
strings.

Add a utility function to handle this.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 8565efd5 24-Apr-2022 Simon Glass <sjg@chromium.org>

lib: Add a way to find the postiion of a trailing number

At present it is not possible to find out which part of the string is the
number part and which is before it. Add a new variant which provides this
feature, so we can separate the two in the caller.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d667a0d8 24-Apr-2022 Simon Glass <sjg@chromium.org>

lib: Fix a few bugs in trailing_strtoln()

At present this has a minor bug in that it reads the byte before the
start of the string, if it is empty. Also it doesn't handle a
non-numeric prefix which is only one character long.

Fix these bugs with a reworked implementation. Add a test for the second
case. The first one is hard to test.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# e6951139 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Allow using 0x when a decimal value is requested

U-Boot mostly uses hex for value input, largely because addresses are much
easier to understand in hex.

But in some cases a decimal value is requested, such as where the value is
small or hex does not make sense in the context. In these cases it is
sometimes useful to be able to provide a hex value in any case, if only to
resolve any ambiguity.

Add this functionality, for increased flexibility.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a94546e 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Move common digit-parsing code into a function

The code to convert a character into a digit is repeated twice in this
file. Factor it out into a separate function. This also makes the code a
little easier to read.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 96b23440 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Drop unnecessary check for hex digit

If we see 0x then we can assume this is the start of a hex value. It
does not seem necessary to check for a hex digit after that since it will
happen when parsing the value anyway.

Drop this check to simplify the code and reduce size. Add a few more test
cases for when a 0x prefix is used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b016428 22-Jul-2021 Roland Gaudig <roland.gaudig@weidmueller.com>

lib: strto: add simple_strtoll function

Add simple_strtoll function for converting a string containing digits
into a long long int value.

Signed-off-by: Roland Gaudig <roland.gaudig@weidmueller.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 4b485893 08-Apr-2020 Michal Simek <michal.simek@amd.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>

# 0486497e 07-Feb-2020 Michal Simek <michal.simek@amd.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>

# b87b0d8d 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: fix metric suffix parsing in strtoul[l]

While 1kB or 1kiB will be parsed correctly, 1k will return the right
amount, but the metric suffix will not be escaped once the char
pointer updated. Fix this situation by simplifying the move of the
endp pointer.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# a353e6aa 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: parse all lowercase metric prefixes in ustrtoul[l]

Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the
SI symbols for Mega and Giga are 'M' and 'G', certain entries of
eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'.

I do not see how parsing lowercase prefixes could break anything, so
parse them like their uppercase counterpart.

Also, even though kiB is not equal to kB in general, lets not change
U-Boot behavior and always use kiB and kB (same applies for MiB vs. MB
and GiB vs. GB) as a representation for 1024 instead of 1000.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# 2e794614 11-Sep-2017 Rob Clark <robdclark@gmail.com>

lib: strto: fix incorrect handling of specified base

The strto functions should honor the specified base (if non-zero) rather
than permitting a hex or octal string when the user wanted (for example)
base 10.

This has been fixed somewhere along the way in the upstream linux kernel
src tree, at some point after these was copied in to u-boot. And also
in a way that duplicates less code. So port _parse_integer_fixup_radix()
to u-boot.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b91c6a12 05-Oct-2016 Simon Glass <sjg@chromium.org>

Fix return value in trailing_strtoln()

This function should return -1 if there is no trailing integer in the
string. Instead it returns 0. Fix it by checking for this condition at the
start.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# e4c5383e 04-Dec-2015 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

lib: split out strtoxxxx functions out of vsprintf.c

To allow the various string to number conversion functions to be used
when using tiny-printf,split them out into their own file which gets
build regardless of what printf implementation is used.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>

# 8565efd5 24-Apr-2022 Simon Glass <sjg@chromium.org>

lib: Add a way to find the postiion of a trailing number

At present it is not possible to find out which part of the string is the
number part and which is before it. Add a new variant which provides this
feature, so we can separate the two in the caller.

Signed-off-by: Simon Glass <sjg@chromium.org>

# d667a0d8 24-Apr-2022 Simon Glass <sjg@chromium.org>

lib: Fix a few bugs in trailing_strtoln()

At present this has a minor bug in that it reads the byte before the
start of the string, if it is empty. Also it doesn't handle a
non-numeric prefix which is only one character long.

Fix these bugs with a reworked implementation. Add a test for the second
case. The first one is hard to test.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# e6951139 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Allow using 0x when a decimal value is requested

U-Boot mostly uses hex for value input, largely because addresses are much
easier to understand in hex.

But in some cases a decimal value is requested, such as where the value is
small or hex does not make sense in the context. In these cases it is
sometimes useful to be able to provide a hex value in any case, if only to
resolve any ambiguity.

Add this functionality, for increased flexibility.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a94546e 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Move common digit-parsing code into a function

The code to convert a character into a digit is repeated twice in this
file. Factor it out into a separate function. This also makes the code a
little easier to read.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 96b23440 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Drop unnecessary check for hex digit

If we see 0x then we can assume this is the start of a hex value. It
does not seem necessary to check for a hex digit after that since it will
happen when parsing the value anyway.

Drop this check to simplify the code and reduce size. Add a few more test
cases for when a 0x prefix is used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b016428 22-Jul-2021 Roland Gaudig <roland.gaudig@weidmueller.com>

lib: strto: add simple_strtoll function

Add simple_strtoll function for converting a string containing digits
into a long long int value.

Signed-off-by: Roland Gaudig <roland.gaudig@weidmueller.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 4b485893 08-Apr-2020 Michal Simek <michal.simek@amd.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>

# 0486497e 07-Feb-2020 Michal Simek <michal.simek@amd.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>

# b87b0d8d 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: fix metric suffix parsing in strtoul[l]

While 1kB or 1kiB will be parsed correctly, 1k will return the right
amount, but the metric suffix will not be escaped once the char
pointer updated. Fix this situation by simplifying the move of the
endp pointer.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# a353e6aa 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: parse all lowercase metric prefixes in ustrtoul[l]

Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the
SI symbols for Mega and Giga are 'M' and 'G', certain entries of
eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'.

I do not see how parsing lowercase prefixes could break anything, so
parse them like their uppercase counterpart.

Also, even though kiB is not equal to kB in general, lets not change
U-Boot behavior and always use kiB and kB (same applies for MiB vs. MB
and GiB vs. GB) as a representation for 1024 instead of 1000.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# 2e794614 11-Sep-2017 Rob Clark <robdclark@gmail.com>

lib: strto: fix incorrect handling of specified base

The strto functions should honor the specified base (if non-zero) rather
than permitting a hex or octal string when the user wanted (for example)
base 10.

This has been fixed somewhere along the way in the upstream linux kernel
src tree, at some point after these was copied in to u-boot. And also
in a way that duplicates less code. So port _parse_integer_fixup_radix()
to u-boot.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b91c6a12 05-Oct-2016 Simon Glass <sjg@chromium.org>

Fix return value in trailing_strtoln()

This function should return -1 if there is no trailing integer in the
string. Instead it returns 0. Fix it by checking for this condition at the
start.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# e4c5383e 04-Dec-2015 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

lib: split out strtoxxxx functions out of vsprintf.c

To allow the various string to number conversion functions to be used
when using tiny-printf,split them out into their own file which gets
build regardless of what printf implementation is used.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>

# 185f812c 19-Jan-2022 Heinrich Schuchardt <xypron.glpk@gmx.de>

doc: replace @return by Return:

Sphinx expects Return: and not @return to indicate a return value.

find . -name '*.c' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

find . -name '*.h' -exec \
sed -i 's/^\(\s\)\*\(\s*\)@return\(\s\)/\1*\2Return:\3/' {} \;

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>

# e6951139 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Allow using 0x when a decimal value is requested

U-Boot mostly uses hex for value input, largely because addresses are much
easier to understand in hex.

But in some cases a decimal value is requested, such as where the value is
small or hex does not make sense in the context. In these cases it is
sometimes useful to be able to provide a hex value in any case, if only to
resolve any ambiguity.

Add this functionality, for increased flexibility.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a94546e 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Move common digit-parsing code into a function

The code to convert a character into a digit is repeated twice in this
file. Factor it out into a separate function. This also makes the code a
little easier to read.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 96b23440 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Drop unnecessary check for hex digit

If we see 0x then we can assume this is the start of a hex value. It
does not seem necessary to check for a hex digit after that since it will
happen when parsing the value anyway.

Drop this check to simplify the code and reduce size. Add a few more test
cases for when a 0x prefix is used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b016428 22-Jul-2021 Roland Gaudig <roland.gaudig@weidmueller.com>

lib: strto: add simple_strtoll function

Add simple_strtoll function for converting a string containing digits
into a long long int value.

Signed-off-by: Roland Gaudig <roland.gaudig@weidmueller.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>

# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>

# b87b0d8d 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: fix metric suffix parsing in strtoul[l]

While 1kB or 1kiB will be parsed correctly, 1k will return the right
amount, but the metric suffix will not be escaped once the char
pointer updated. Fix this situation by simplifying the move of the
endp pointer.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# a353e6aa 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: parse all lowercase metric prefixes in ustrtoul[l]

Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the
SI symbols for Mega and Giga are 'M' and 'G', certain entries of
eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'.

I do not see how parsing lowercase prefixes could break anything, so
parse them like their uppercase counterpart.

Also, even though kiB is not equal to kB in general, lets not change
U-Boot behavior and always use kiB and kB (same applies for MiB vs. MB
and GiB vs. GB) as a representation for 1024 instead of 1000.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# 2e794614 11-Sep-2017 Rob Clark <robdclark@gmail.com>

lib: strto: fix incorrect handling of specified base

The strto functions should honor the specified base (if non-zero) rather
than permitting a hex or octal string when the user wanted (for example)
base 10.

This has been fixed somewhere along the way in the upstream linux kernel
src tree, at some point after these was copied in to u-boot. And also
in a way that duplicates less code. So port _parse_integer_fixup_radix()
to u-boot.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b91c6a12 05-Oct-2016 Simon Glass <sjg@chromium.org>

Fix return value in trailing_strtoln()

This function should return -1 if there is no trailing integer in the
string. Instead it returns 0. Fix it by checking for this condition at the
start.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# e4c5383e 04-Dec-2015 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

lib: split out strtoxxxx functions out of vsprintf.c

To allow the various string to number conversion functions to be used
when using tiny-printf,split them out into their own file which gets
build regardless of what printf implementation is used.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>

# e6951139 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Allow using 0x when a decimal value is requested

U-Boot mostly uses hex for value input, largely because addresses are much
easier to understand in hex.

But in some cases a decimal value is requested, such as where the value is
small or hex does not make sense in the context. In these cases it is
sometimes useful to be able to provide a hex value in any case, if only to
resolve any ambiguity.

Add this functionality, for increased flexibility.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 5a94546e 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Move common digit-parsing code into a function

The code to convert a character into a digit is repeated twice in this
file. Factor it out into a separate function. This also makes the code a
little easier to read.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 96b23440 24-Jul-2021 Simon Glass <sjg@chromium.org>

lib: Drop unnecessary check for hex digit

If we see 0x then we can assume this is the start of a hex value. It
does not seem necessary to check for a hex digit after that since it will
happen when parsing the value anyway.

Drop this check to simplify the code and reduce size. Add a few more test
cases for when a 0x prefix is used.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b1284eb 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with decimal to dectoul()

It is a pain to have to specify the value 10 in each call. Add a new
dectoul() function and update the code to use it.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 7e5f460e 24-Jul-2021 Simon Glass <sjg@chromium.org>

global: Convert simple_strtoul() with hex to hextoul()

It is a pain to have to specify the value 16 in each call. Add a new
hextoul() function and update the code to use it.

Add a proper comment to simple_strtoul() while we are here.

Signed-off-by: Simon Glass <sjg@chromium.org>

# 0b016428 22-Jul-2021 Roland Gaudig <roland.gaudig@weidmueller.com>

lib: strto: add simple_strtoll function

Add simple_strtoll function for converting a string containing digits
into a long long int value.

Signed-off-by: Roland Gaudig <roland.gaudig@weidmueller.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>

# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>

# b87b0d8d 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: fix metric suffix parsing in strtoul[l]

While 1kB or 1kiB will be parsed correctly, 1k will return the right
amount, but the metric suffix will not be escaped once the char
pointer updated. Fix this situation by simplifying the move of the
endp pointer.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# a353e6aa 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: parse all lowercase metric prefixes in ustrtoul[l]

Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the
SI symbols for Mega and Giga are 'M' and 'G', certain entries of
eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'.

I do not see how parsing lowercase prefixes could break anything, so
parse them like their uppercase counterpart.

Also, even though kiB is not equal to kB in general, lets not change
U-Boot behavior and always use kiB and kB (same applies for MiB vs. MB
and GiB vs. GB) as a representation for 1024 instead of 1000.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# 2e794614 11-Sep-2017 Rob Clark <robdclark@gmail.com>

lib: strto: fix incorrect handling of specified base

The strto functions should honor the specified base (if non-zero) rather
than permitting a hex or octal string when the user wanted (for example)
base 10.

This has been fixed somewhere along the way in the upstream linux kernel
src tree, at some point after these was copied in to u-boot. And also
in a way that duplicates less code. So port _parse_integer_fixup_radix()
to u-boot.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b91c6a12 05-Oct-2016 Simon Glass <sjg@chromium.org>

Fix return value in trailing_strtoln()

This function should return -1 if there is no trailing integer in the
string. Instead it returns 0. Fix it by checking for this condition at the
start.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# e4c5383e 04-Dec-2015 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

lib: split out strtoxxxx functions out of vsprintf.c

To allow the various string to number conversion functions to be used
when using tiny-printf,split them out into their own file which gets
build regardless of what printf implementation is used.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>

# 0b016428 22-Jul-2021 Roland Gaudig <roland.gaudig@weidmueller.com>

lib: strto: add simple_strtoll function

Add simple_strtoll function for converting a string containing digits
into a long long int value.

Signed-off-by: Roland Gaudig <roland.gaudig@weidmueller.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>

# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>

# b87b0d8d 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: fix metric suffix parsing in strtoul[l]

While 1kB or 1kiB will be parsed correctly, 1k will return the right
amount, but the metric suffix will not be escaped once the char
pointer updated. Fix this situation by simplifying the move of the
endp pointer.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# a353e6aa 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: parse all lowercase metric prefixes in ustrtoul[l]

Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the
SI symbols for Mega and Giga are 'M' and 'G', certain entries of
eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'.

I do not see how parsing lowercase prefixes could break anything, so
parse them like their uppercase counterpart.

Also, even though kiB is not equal to kB in general, lets not change
U-Boot behavior and always use kiB and kB (same applies for MiB vs. MB
and GiB vs. GB) as a representation for 1024 instead of 1000.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>

# 2e794614 11-Sep-2017 Rob Clark <robdclark@gmail.com>

lib: strto: fix incorrect handling of specified base

The strto functions should honor the specified base (if non-zero) rather
than permitting a hex or octal string when the user wanted (for example)
base 10.

This has been fixed somewhere along the way in the upstream linux kernel
src tree, at some point after these was copied in to u-boot. And also
in a way that duplicates less code. So port _parse_integer_fixup_radix()
to u-boot.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>

# b91c6a12 05-Oct-2016 Simon Glass <sjg@chromium.org>

Fix return value in trailing_strtoln()

This function should return -1 if there is no trailing integer in the
string. Instead it returns 0. Fix it by checking for this condition at the
start.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

# e4c5383e 04-Dec-2015 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

lib: split out strtoxxxx functions out of vsprintf.c

To allow the various string to number conversion functions to be used
when using tiny-printf,split them out into their own file which gets
build regardless of what printf implementation is used.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>

# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 1fae7412 06-Jun-2020 Sean Anderson <seanga2@gmail.com>

Revert "lib: Improve _parse_integer_fixup_radix base 16 detection"

This reverts commit 0486497e2b5f4d36fa968a1a60fea358cbf70b65.

The strtoul has well-defined semantics. It is defined by the C standard and
POSIX. To quote the relevant section of the man pages,

> If base is zero or 16, the string may then include a "0x" prefix, and the
> number will be read in base 16; otherwise, a zero base is taken as 10
> (decimal) unless the next character is '0', in which case it is taken as
> 8 (octal).

Keeping these semantics is important for several reasons. First, it is very
surprising for standard library functions to behave differently than usual.
Every other implementation of strtoul has different semantics than the
implementation in U-Boot at the moment. Second, it can result in very
surprising results from small changes. For example, changing the string
"1f" to "20" causes the parsed value to *decrease*. Forcing use of the "0x"
prefix to specify hexidecimal numbers is a feature, not a bug. Lastly, this
is slightly less performant, since the entire number is parsed twice.

This fixes the str_simple_strtoul test failing with

test/str_ut.c:29, run_strtoul(): expect_val == val: Expected 0x44b (1099), got 0x1099ab (1087915)
test/str_ut.c:46, str_simple_strtoul(): 0 == run_strtoul(uts, str2, 0, 1099, 4): Expected 0x0 (0), got 0x1 (1)

Signed-off-by: Sean Anderson <seanga2@gmail.com>
CC: Michal Simek <michal.simek@xilinx.com>
CC: Shiril Tichkule <shirilt@xilinx.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# fdc79a6b 08-Apr-2020 Simon Glass <sjg@chromium.org>

lib: Add a function to convert a string to upper case

Add a helper function for this operation. Update the strtoul() tests to
check upper case as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>


# 4b485893 08-Apr-2020 Michal Simek <michal.simek@xilinx.com>

lib: strto: Stop detection when invalid char is used

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@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>
Fixes: 0486497e2b5f ("lib: Improve _parse_integer_fixup_radix base 16 detection")
Tested-by: Heiko Schocher <hs@denx.de>
Tested-by: Pali Rohár <pali@kernel.org>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# 0486497e 07-Feb-2020 Michal Simek <michal.simek@xilinx.com>

lib: Improve _parse_integer_fixup_radix base 16 detection

Base autodetection is failing for this case:
if test 257 -gt 3ae; then echo first; else echo second; fi

It is because base for 3ae is recognized by _parse_integer_fixup_radix() as
10. The code detects the first char which is not between 'a'/'A' or 'f'/'F'
to change base from dec to hex.

Signed-off-by: Michal Simek <michal.simek@xilinx.com>
Signed-off-by: Shiril Tichkule <shirilt@xlinx.com>


# b87b0d8d 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: fix metric suffix parsing in strtoul[l]

While 1kB or 1kiB will be parsed correctly, 1k will return the right
amount, but the metric suffix will not be escaped once the char
pointer updated. Fix this situation by simplifying the move of the
endp pointer.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>


# a353e6aa 06-Sep-2018 Miquel Raynal <miquel.raynal@bootlin.com>

lib: strto: parse all lowercase metric prefixes in ustrtoul[l]

Both ustrtoul and ustrtoull interpret 1k but not 1m or 1g. Even if the
SI symbols for Mega and Giga are 'M' and 'G', certain entries of
eg. mtdparts also use (wrongly) the metric prefix 'm' and 'g'.

I do not see how parsing lowercase prefixes could break anything, so
parse them like their uppercase counterpart.

Also, even though kiB is not equal to kB in general, lets not change
U-Boot behavior and always use kiB and kB (same applies for MiB vs. MB
and GiB vs. GB) as a representation for 1024 instead of 1000.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Reviewed-by: Stefan Roese <sr@denx.de>


# 2e794614 11-Sep-2017 Rob Clark <robdclark@gmail.com>

lib: strto: fix incorrect handling of specified base

The strto functions should honor the specified base (if non-zero) rather
than permitting a hex or octal string when the user wanted (for example)
base 10.

This has been fixed somewhere along the way in the upstream linux kernel
src tree, at some point after these was copied in to u-boot. And also
in a way that duplicates less code. So port _parse_integer_fixup_radix()
to u-boot.

Signed-off-by: Rob Clark <robdclark@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>


# b91c6a12 05-Oct-2016 Simon Glass <sjg@chromium.org>

Fix return value in trailing_strtoln()

This function should return -1 if there is no trailing integer in the
string. Instead it returns 0. Fix it by checking for this condition at the
start.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>


# e4c5383e 04-Dec-2015 Sjoerd Simons <sjoerd.simons@collabora.co.uk>

lib: split out strtoxxxx functions out of vsprintf.c

To allow the various string to number conversion functions to be used
when using tiny-printf,split them out into their own file which gets
build regardless of what printf implementation is used.

Signed-off-by: Sjoerd Simons <sjoerd.simons@collabora.co.uk>