[PATCH 00/15] lib: Add support for a decimal 0m prefix for numbers

Tom Rini trini at konsulko.com
Tue Jul 20 18:05:47 CEST 2021


On Tue, Jul 20, 2021 at 09:57:55AM -0600, Simon Glass wrote:
> Hi Tom,
> 
> On Tue, 20 Jul 2021 at 08:22, Tom Rini <trini at konsulko.com> wrote:
> >
> > On Tue, Jul 20, 2021 at 07:29:24AM -0600, Simon Glass wrote:
> >
> > > U-Boot mostly uses hex for value input, largely because addresses are much
> > > easier to understand in hex.
> > >
> > > But in some cases a hex value is requested, but it is more convenient to
> > > provide a decimal value. This may be because the value comes from another
> > > source, where its base cannot be controlled.
> > >
> > > This series adds support for a 0m prefix to indicate a decimal number. The
> >
> > I _really_ don't want to invent something here.  When the setexpr thread
> > came up before I went and did a little digging.  Per
> > https://en.wikipedia.org/wiki/Radix the general way to express a number
> > is (x)y where x is the number and y is the base (and y is in base10, and
> > also a subscript).  I thought it was a bit cumbersome for general use
> > and didn't bring it up at the time.
> 
> Well I don't want to invent something either...but what to do?
> 
> So for example (10)123 would mean decimal 123? I don't know how we
> would parse brackets separately from expressions though.

(123)10 would be "123" in decimal.  Which is indeed a mouthful.  But it
would also be generic and (123)16 would be 0x123.  So the parsing
shouldn't be too hard, for most commands.  But then yes, expressions
become quite hard.

> > If we're going to add some global way to always say a number is decimal,
> > and I'm not sure I think that's a good idea even (I kind of think it
> > might be better on a case by case basis to maybe tweak some prints so
> > that for example "ls mmc 0:10" tells the user it's accessing partition
> > 16 would lead to a quick "oh that's hex, #$%@!"), I think it should
> > follow the radix notation, or if not, some other well known example.
> 
> Can you give examples for what you are thinking for radix notation?

Well, since we don't have subscript in shell, '(number)base' would how
it would be.  Which I'm not convinced is better than making it clear to
users that almost everything is hex input, including a few places that
might surprise you such as partition numbers.

> BTW, quite a bit of the series is a clean-up, so can be reviewed separately.

OK.

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


More information about the U-Boot mailing list