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

Simon Glass
2021-07-20T13:30:01Z

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
letter 'm' is chosen because:

- 'm' as in deciMal
- cannot use a-f since they indicate a hex value (e.g. 0d would be
ambiguous)
- 'l' is harder to read since 1 and l look similar (0l123)
- 't' (as in ten) seems a bit obscure
- 'n' (Number) is easier to read than 'm', but a bit vague as to
meaning

At present, base prefixes are only accepted when no specific base is
provided to the simple_strtoul() function, i.e. base is 0. This is not
very flexible, so this series updates the code to always allow a base
prefix. So when decimal is requested, it is possible to provide 0x123 to
get a hex value.

A final patch is included for discussion only. This is intended to change
the default to hex consistently through U-Boot, although it does not quite
accomplish that. If this goal is desirable, then we should also consider:

- dropping the base argument, since callers can now hextoul() and
dectoul() when a specific base is requested
- converting these calls (with base == 0) to hextoul() since that is
what would mean

Simon Glass (15):
hash: Ensure verification hex pairs are terminated
global: Convert simple_strtoul() with hex to hextoul()
global: Convert simple_strtoul() with decimal to dectoul()
lib: Comment the base parameter with simple_strtoul/l()
lib: Drop unnecessary check for hex digit
lib: Add tests for simple_strtoull()
lib: Add octal tests for simple_strtoul/l()
lib: Move common digit-parsing code into a function
doc: Convert command-line info to rST
doc: Add a note about number representation
lib: Allow using 0x when a decimal value is requested
lib: Support a decimal prefix 0m
RFC: lib: Support a binary prefix 0y
RFC: lib: Use 0o prefix for octal
RFC: Change simple_strtoul() et al to default to hex

README | 41 ------
arch/arm/cpu/armv8/fsl-layerscape/fdt.c | 12 +-
arch/arm/cpu/armv8/fsl-layerscape/soc.c | 2 +-
arch/arm/lib/semihosting.c | 2 +-
arch/arm/mach-imx/cmd_dek.c | 6 +-
arch/arm/mach-imx/cmd_mfgprot.c | 4 +-
arch/arm/mach-imx/cmd_nandbcb.c | 10 +-
arch/arm/mach-imx/hab.c | 6 +-
arch/arm/mach-imx/imx8/ahab.c | 2 +-
arch/arm/mach-imx/imx8/snvs_security_sc.c | 56 ++++----
arch/arm/mach-imx/imx_bootaux.c | 2 +-
arch/arm/mach-imx/mx6/mp.c | 2 +-
arch/arm/mach-keystone/cmd_clock.c | 10 +-
arch/arm/mach-keystone/cmd_mon.c | 8 +-
arch/arm/mach-kirkwood/cpu.c | 2 +-
arch/arm/mach-nexell/clock.c | 2 +-
arch/arm/mach-snapdragon/misc.c | 2 +-
arch/arm/mach-socfpga/misc.c | 2 +-
arch/arm/mach-socfpga/vab.c | 4 +-
arch/arm/mach-stm32mp/cmd_stm32key.c | 4 +-
.../cmd_stm32prog/cmd_stm32prog.c | 6 +-
.../mach-stm32mp/cmd_stm32prog/stm32prog.c | 2 +-
arch/arm/mach-uniphier/board_late_init.c | 2 +-
arch/arm/mach-zynqmp/mp.c | 2 +-
arch/mips/mach-octeon/bootoctlinux.c | 5 +-
arch/nds32/lib/bootm.c | 2 +-
arch/nios2/lib/bootm.c | 2 +-
arch/powerpc/cpu/mpc83xx/ecc.c | 18 +--
arch/powerpc/cpu/mpc85xx/mp.c | 2 +-
arch/sh/lib/zimageboot.c | 5 +-
arch/x86/lib/zimage.c | 14 +-
board/Arcturus/ucp1020/ucp1020.c | 2 +-
board/BuS/eb_cpu5282/eb_cpu5282.c | 10 +-
board/Marvell/octeontx2/board.c | 2 +-
board/amlogic/beelink-s922x/beelink-s922x.c | 2 +-
board/amlogic/odroid-n2/odroid-n2.c | 2 +-
board/amlogic/vim3/vim3.c | 2 +-
board/atmel/common/board.c | 2 +-
board/bluewater/gurnard/gurnard.c | 2 +-
board/cavium/thunderx/atf.c | 32 ++---
board/compulab/common/eeprom.c | 2 +-
board/compulab/common/omap3_display.c | 2 +-
board/davinci/da8xxevm/da850evm.c | 2 +-
board/esd/meesc/meesc.c | 2 +-
board/freescale/common/cmd_esbc_validate.c | 2 +-
board/freescale/common/fsl_validate.c | 2 +-
board/freescale/common/pixis.c | 8 +-
board/freescale/common/sys_eeprom.c | 6 +-
board/freescale/lx2160a/eth_lx2160aqds.c | 2 +-
board/freescale/lx2160a/eth_lx2162aqds.c | 2 +-
board/freescale/p1_p2_rdb_pc/p1_p2_rdb_pc.c | 2 +-
board/freescale/p2041rdb/cpld.c | 4 +-
board/gateworks/gw_ventana/common.c | 2 +-
board/gateworks/gw_ventana/gsc.c | 4 +-
board/gateworks/gw_ventana/gw_ventana.c | 4 +-
board/gateworks/venice/gsc.c | 2 +-
board/gdsys/common/cmd_ioloop.c | 16 +--
board/gdsys/common/osd.c | 18 +--
board/gdsys/common/osd_cmd.c | 16 +--
board/keymile/common/common.c | 4 +-
board/kontron/sl28/cmds.c | 2 +-
board/menlo/m53menlo/m53menlo.c | 2 +-
board/renesas/stout/cpld.c | 4 +-
board/renesas/ulcb/cpld.c | 4 +-
board/samsung/common/exynos5-dt.c | 2 +-
board/samsung/odroid/odroid.c | 2 +-
board/siemens/common/factoryset.c | 14 +-
board/siemens/taurus/taurus.c | 5 +-
.../unmatched/hifive-platform-i2c-eeprom.c | 8 +-
board/synopsys/hsdk/env-lib.c | 4 +-
board/ti/am64x/evm.c | 2 +-
board/ti/j721e/evm.c | 2 +-
board/toradex/common/tdx-cfg-block.c | 14 +-
board/varisys/common/sys_eeprom.c | 6 +-
.../work_92105/work_92105_display.c | 3 +-
board/xilinx/common/fru.c | 4 +-
board/xilinx/versal/cmds.c | 2 +-
board/xilinx/zynq/cmds.c | 14 +-
board/xilinx/zynqmp/cmds.c | 46 +++----
cmd/abootimg.c | 2 +-
cmd/adtimg.c | 2 +-
cmd/aes.c | 10 +-
cmd/armflash.c | 2 +-
cmd/avb.c | 26 ++--
cmd/axi.c | 18 +--
cmd/bedbug.c | 6 +-
cmd/bind.c | 4 +-
cmd/binop.c | 8 +-
cmd/blk_common.c | 16 +--
cmd/blob.c | 8 +-
cmd/bmp.c | 10 +-
cmd/boot.c | 2 +-
cmd/bootefi.c | 4 +-
cmd/booti.c | 2 +-
cmd/bootm.c | 4 +-
cmd/bootstage.c | 4 +-
cmd/bootz.c | 2 +-
cmd/broadcom/nitro_image_load.c | 4 +-
cmd/cbfs.c | 6 +-
cmd/clk.c | 2 +-
cmd/clone.c | 2 +-
cmd/cramfs.c | 4 +-
cmd/cros_ec.c | 8 +-
cmd/demo.c | 4 +-
cmd/disk.c | 2 +-
cmd/efidebug.c | 14 +-
cmd/elf.c | 4 +-
cmd/exit.c | 2 +-
cmd/fastboot.c | 4 +-
cmd/fdt.c | 41 +++---
cmd/flash.c | 16 +--
cmd/fpga.c | 10 +-
cmd/fpgad.c | 6 +-
cmd/gpio.c | 4 +-
cmd/gpt.c | 2 +-
cmd/host.c | 6 +-
cmd/i2c.c | 68 +++++-----
cmd/ini.c | 8 +-
cmd/io.c | 8 +-
cmd/iotrace.c | 8 +-
cmd/itest.c | 6 +-
cmd/jffs2.c | 2 +-
cmd/led.c | 2 +-
cmd/legacy_led.c | 2 +-
cmd/load.c | 16 +--
cmd/log.c | 4 +-
cmd/lzmadec.c | 6 +-
cmd/mbr.c | 2 +-
cmd/md5sum.c | 14 +-
cmd/mdio.c | 2 +-
cmd/mem.c | 56 ++++----
cmd/mfsl.c | 14 +-
cmd/mii.c | 8 +-
cmd/misc.c | 6 +-
cmd/mmc.c | 80 +++++------
cmd/mp.c | 2 +-
cmd/mtd.c | 10 +-
cmd/mvebu/bubt.c | 2 +-
cmd/mvebu/comphy_rx_training.c | 4 +-
cmd/nand.c | 20 +--
cmd/net.c | 6 +-
cmd/nvedit.c | 12 +-
cmd/nvedit_efi.c | 4 +-
cmd/onenand.c | 8 +-
cmd/optee_rpmb.c | 2 +-
cmd/osd.c | 20 +--
cmd/pcap.c | 4 +-
cmd/pci.c | 12 +-
cmd/pstore.c | 16 +--
cmd/pwm.c | 10 +-
cmd/pxe_utils.c | 4 +-
cmd/qfw.c | 10 +-
cmd/read.c | 10 +-
cmd/reiser.c | 10 +-
cmd/remoteproc.c | 10 +-
cmd/rng.c | 2 +-
cmd/rtc.c | 14 +-
cmd/sata.c | 2 +-
cmd/setexpr.c | 4 +-
cmd/sf.c | 10 +-
cmd/sleep.c | 2 +-
cmd/smccc.c | 16 +--
cmd/sound.c | 4 +-
cmd/source.c | 2 +-
cmd/spi.c | 10 +-
cmd/strings.c | 4 +-
cmd/ti/ddr3.c | 10 +-
cmd/ti/pd.c | 4 +-
cmd/tlv_eeprom.c | 2 +-
cmd/tpm-common.c | 4 +-
cmd/trace.c | 4 +-
cmd/tsi148.c | 10 +-
cmd/ubi.c | 10 +-
cmd/ubifs.c | 4 +-
cmd/ufs.c | 2 +-
cmd/universe.c | 12 +-
cmd/unlz4.c | 6 +-
cmd/unzip.c | 12 +-
cmd/usb.c | 6 +-
cmd/w1.c | 8 +-
cmd/x86/mtrr.c | 6 +-
cmd/ximg.c | 6 +-
cmd/yaffs2.c | 10 +-
cmd/zfs.c | 6 +-
cmd/zip.c | 8 +-
common/bedbug.c | 4 +-
common/bootm_os.c | 5 +-
common/fdt_support.c | 2 +-
common/hash.c | 14 +-
common/image-fdt.c | 6 +-
common/image-fit.c | 2 +-
common/image.c | 12 +-
common/kallsyms.c | 2 +-
common/lcd.c | 2 +-
common/lcd_console.c | 4 +-
common/splash.c | 4 +-
common/splash_source.c | 2 +-
common/update.c | 2 +-
disk/part.c | 6 +-
disk/part_amiga.c | 4 +-
doc/usage/cmdline.rst | 103 +++++++++++++++
doc/usage/index.rst | 1 +
drivers/dfu/dfu_mmc.c | 2 +-
drivers/dfu/dfu_mtd.c | 6 +-
drivers/dfu/dfu_nand.c | 8 +-
drivers/dfu/dfu_ram.c | 4 +-
drivers/dfu/dfu_sf.c | 8 +-
drivers/dfu/dfu_virt.c | 2 +-
drivers/fastboot/fb_command.c | 2 +-
drivers/gpio/gpio-uclass.c | 2 +-
drivers/gpio/mxs_gpio.c | 4 +-
drivers/gpio/pca953x.c | 4 +-
drivers/gpio/tca642x.c | 4 +-
drivers/misc/ds4510.c | 10 +-
drivers/net/e1000.c | 2 +-
drivers/net/e1000_spi.c | 4 +-
drivers/net/fm/fdt.c | 2 +-
drivers/net/fsl-mc/mc.c | 5 +-
drivers/net/netconsole.c | 6 +-
drivers/net/pfe_eth/pfe_cmd.c | 14 +-
drivers/net/pfe_eth/pfe_firmware.c | 2 +-
drivers/net/phy/b53.c | 14 +-
drivers/net/phy/mv88e6352.c | 14 +-
drivers/net/qe/dm_qe_uec.c | 4 +-
drivers/pinctrl/nexell/pinctrl-nexell.c | 2 +-
drivers/pinctrl/pinctrl-uclass.c | 2 +-
drivers/power/power_core.c | 6 +-
drivers/qe/qe.c | 4 +-
drivers/ram/octeon/octeon_ddr.c | 2 +-
drivers/rtc/m41t60.c | 2 +-
drivers/serial/serial-uclass.c | 2 +-
drivers/serial/serial.c | 2 +-
drivers/usb/cdns3/gadget.c | 2 +-
drivers/usb/gadget/epautoconf.c | 2 +-
drivers/usb/gadget/ether.c | 3 +-
drivers/video/ati_radeon_fb.c | 2 +-
drivers/video/cfb_console.c | 2 +-
drivers/video/mx3fb.c | 2 +-
drivers/video/vidconsole-uclass.c | 4 +-
examples/standalone/atmel_df_pow2.c | 5 +-
fs/fs.c | 14 +-
include/vsprintf.h | 63 ++++++++-
lib/dhry/cmd_dhry.c | 2 +-
lib/fdtdec.c | 2 +-
lib/net_utils.c | 4 +-
lib/strto.c | 80 ++++++++---
lib/uuid.c | 14 +-
lib/vsprintf.c | 2 +-
net/bootp.c | 2 +-
net/eth-uclass.c | 4 +-
net/eth_legacy.c | 2 +-
net/net.c | 2 +-
net/tftp.c | 13 +-
test/str_ut.c | 125 +++++++++++++++++-
254 files changed, 1217 insertions(+), 950 deletions(-)
create mode 100644 doc/usage/cmdline.rst

--
2.32.0.402.g57bb445576-goog