From: Sean Anderson <seanga2@gmail.com>
To: Simon Glass <sjg@chromium.org>,
U-Boot Mailing List <u-boot@lists.denx.de>
Cc: "Eugeniu Rosca" <erosca@de.adit-jv.com>,
"Roland Gaudig" <roland.gaudig@weidmueller.com>,
"Heinrich Schuchardt" <xypron.glpk@gmx.de>,
"Stefan Herbrechtsmeier" <stefan.herbrechtsmeier@weidmueller.com>,
"Marek Behún" <marek.behun@nic.cz>,
"Tom Rini" <trini@konsulko.com>, "Marek Vasut" <marex@denx.de>
Subject: Re: [PATCH 13/15] RFC: lib: Support a binary prefix 0y
Date: Wed, 21 Jul 2021 04:05:30 -0400 [thread overview]
Message-ID: <9e1797ea-c1bf-5749-03a6-cf0e9430f3c3@gmail.com> (raw)
In-Reply-To: <20210720132940.1171011-14-sjg@chromium.org>
On 7/20/21 9:29 AM, Simon Glass wrote:
> In some cases it is useful to be able to supply a binary value to a
> command. Use the '0y' prefix for this (binarY).
To bikeshed: 0b please
https://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html
--Sean
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> doc/usage/cmdline.rst | 6 ++++++
> lib/strto.c | 3 +++
> test/str_ut.c | 8 ++++++++
> 3 files changed, 17 insertions(+)
>
> diff --git a/doc/usage/cmdline.rst b/doc/usage/cmdline.rst
> index 7f2cfad2a0f..05ce65958c4 100644
> --- a/doc/usage/cmdline.rst
> +++ b/doc/usage/cmdline.rst
> @@ -96,3 +96,9 @@ convenient::
>
> => i2c speed 0x30000
> Setting bus speed to 196608 Hz
> +
> +U-Boot also supports a `0y` for binary base 2 ("binarY")::
> +
> + => mw 100 0y11010011
> + => md 100 1
> + 00000100: 000000d3 ....
> diff --git a/lib/strto.c b/lib/strto.c
> index 120214d83f8..a7531e877f5 100644
> --- a/lib/strto.c
> +++ b/lib/strto.c
> @@ -26,6 +26,9 @@ static const char *_parse_integer_fixup_radix(const char *s, uint *basep)
> } else if (ch == 'm') {
> *basep = 10;
> s += 2;
> + } else if (ch == 'y') {
> + *basep = 2;
> + s += 2;
> } else if (!*basep) {
> /* Only select octal if we don't have a base */
> *basep = 8;
> diff --git a/test/str_ut.c b/test/str_ut.c
> index 716f7c45c38..731ef0c49ae 100644
> --- a/test/str_ut.c
> +++ b/test/str_ut.c
> @@ -117,6 +117,10 @@ static int str_simple_strtoul(struct unit_test_state *uts)
> ut_assertok(run_strtoul(uts, "0x123fg", 0, 0x123f, 6, false));
> ut_assertok(run_strtoul(uts, "0m123a", 16, 123, 5, false));
>
> + /* check binary */
> + ut_assertok(run_strtoul(uts, "1011b", 2, 0xb, 4, false));
> + ut_assertok(run_strtoul(uts, "0y111more", 0, 7, 5, false));
> +
> return 0;
> }
> STR_TEST(str_simple_strtoul, 0);
> @@ -186,6 +190,10 @@ static int str_simple_strtoull(struct unit_test_state *uts)
> ut_assertok(run_strtoull(uts, "0x123fg", 0, 0x123f, 6, false));
> ut_assertok(run_strtoull(uts, "0m123a", 16, 123, 5, false));
>
> + /* check binary */
> + ut_assertok(run_strtoull(uts, "1011b", 2, 0xb, 4, false));
> + ut_assertok(run_strtoull(uts, "0y111more", 0, 7, 5, false));
> +
> return 0;
> }
> STR_TEST(str_simple_strtoull, 0);
>
next prev parent reply other threads:[~2021-07-21 8:05 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-20 13:29 [PATCH 00/15] lib: Add support for a decimal 0m prefix for numbers Simon Glass
2021-07-20 13:29 ` [PATCH 01/15] hash: Ensure verification hex pairs are terminated Simon Glass
2021-07-20 13:29 ` [PATCH 02/15] global: Convert simple_strtoul() with hex to hextoul() Simon Glass
2021-07-20 13:29 ` [PATCH 03/15] global: Convert simple_strtoul() with decimal to dectoul() Simon Glass
2021-07-20 13:29 ` [PATCH 04/15] lib: Comment the base parameter with simple_strtoul/l() Simon Glass
2021-07-20 13:29 ` [PATCH 05/15] lib: Drop unnecessary check for hex digit Simon Glass
2021-07-20 13:29 ` [PATCH 06/15] lib: Add tests for simple_strtoull() Simon Glass
2021-07-20 13:29 ` [PATCH 07/15] lib: Add octal tests for simple_strtoul/l() Simon Glass
2021-07-20 13:29 ` [PATCH 08/15] lib: Move common digit-parsing code into a function Simon Glass
2021-07-20 13:29 ` [PATCH 09/15] doc: Convert command-line info to rST Simon Glass
2021-07-20 13:29 ` [PATCH 10/15] doc: Add a note about number representation Simon Glass
2021-07-20 13:29 ` [PATCH 11/15] lib: Allow using 0x when a decimal value is requested Simon Glass
2021-07-20 13:29 ` [PATCH 12/15] lib: Support a decimal prefix 0m Simon Glass
2021-07-20 13:29 ` [PATCH 13/15] RFC: lib: Support a binary prefix 0y Simon Glass
2021-07-21 8:05 ` Sean Anderson [this message]
2021-07-21 8:30 ` Wolfgang Denk
2021-07-21 8:27 ` Wolfgang Denk
2021-07-21 14:23 ` Simon Glass
2021-07-22 9:48 ` Wolfgang Denk
2021-07-22 13:28 ` Simon Glass
2021-07-22 14:44 ` Tom Rini
2021-07-23 3:07 ` Simon Glass
2021-07-23 6:55 ` Wolfgang Denk
2021-07-23 21:41 ` Simon Glass
2021-07-24 13:00 ` Wolfgang Denk
2021-07-20 13:29 ` [PATCH 14/15] RFC: lib: Use 0o prefix for octal Simon Glass
2021-07-20 13:29 ` [PATCH 15/15] RFC: Change simple_strtoul() et al to default to hex Simon Glass
2021-07-20 14:22 ` [PATCH 00/15] lib: Add support for a decimal 0m prefix for numbers Tom Rini
2021-07-20 15:57 ` Simon Glass
2021-07-20 16:05 ` Tom Rini
2021-07-20 16:30 ` Eugeniu Rosca
2021-07-20 18:33 ` Simon Glass
2021-07-20 19:28 ` Tom Rini
2021-07-21 13:57 ` Simon Glass
2021-07-21 7:52 ` Wolfgang Denk
2021-07-21 14:46 ` Simon Glass
2021-07-23 21:41 ` Simon Glass
2021-07-20 15:00 ` Jonathan A. Kollasch
2021-07-20 15:04 ` Tom Rini
2021-07-21 7:42 ` Wolfgang Denk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9e1797ea-c1bf-5749-03a6-cf0e9430f3c3@gmail.com \
--to=seanga2@gmail.com \
--cc=erosca@de.adit-jv.com \
--cc=marek.behun@nic.cz \
--cc=marex@denx.de \
--cc=roland.gaudig@weidmueller.com \
--cc=sjg@chromium.org \
--cc=stefan.herbrechtsmeier@weidmueller.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=xypron.glpk@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox