summaryrefslogtreecommitdiff
path: root/lib/vsprintf.c
AgeCommit message (Collapse)Author
2023-02-09Correct SPL use of EFI_APPSimon Glass
This converts 1 usage of this option to the non-SPL form, since there is no SPL_EFI_APP defined in Kconfig Signed-off-by: Simon Glass <sjg@chromium.org>
2023-01-23lib: Support printing an error stringSimon Glass
It is often useful to show an error code to give the user a clue as to what went wrong. When error strings are compiled into U-Boot it is possible to show a message as well. But at present it is not very convenient, since code must check if the error strings are present, then obtain the error string and use it in a printf() string. Add a %dE option which shows an error code along with an error string, if available. This makes it easy to show one or both. Signed-off-by: Simon Glass <sjg@chromium.org>
2022-12-05net: ipv6: Enable IPv6 typeconversion specifierViacheslav Mitrofanov
Add the possibility to recognize IPv6 address in print function. To output IPv6 address use %pI6 specifier. Series-changes: 3 - Substituted #if (...) for if (...) to get better readability Signed-off-by: Viacheslav Mitrofanov <v.v.mitrofanov@yadro.com> Reviewed-by: Ramon Fried <rfried.dev@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2022-02-05lib: fix snprintf() for UTF-16 stringsHeinrich Schuchardt
snprintf() must return the required buffer length. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-02-03treewide: Use 16-bit Unicode stringsSimon Glass
At present we use wide characters for Unicode but this is not necessary. Change the code to use the 'u' literal instead. This helps to fix build warnings for sandbox on the Raspberry Pi. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2022-01-19lib: printf code %pUs for GUID text representationHeinrich Schuchardt
In different places text representations are used for GUIDs, e.g. * command efidebug * command part list for GPT partitions To allow reducing code duplication introduce a new printf code %pUs. It will call uuid_guid_get_str() to get a text representation. If none is found it will fallback to %pUl and print a hexadecimal representation. Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2021-12-31efi: Make unicode printf available to the appSimon Glass
This is needed to show unicode strings. Enable this code in the app. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2021-11-11lib: Add a function to convert a string to a hex valueSimon Glass
Add an xtoa() function, similar to itoa() but for hex instead. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Artem Lapkin <email2tema@gmail.com> Tested-by: Artem Lapkin <email2tema@gmail.com>
2021-08-02global: Convert simple_strtoul() with hex to hextoul()Simon Glass
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>
2021-07-15lib/vsprintf.c: remove unused ip6_addr_string()Rasmus Villemoes
There's currently no user of %p[iI]6, so including ip6_addr_string() in the image is a waste of bytes. It's easy enough to have the compiler elide it without removing the code completely. The closest I can find to anybody "handling" ipv6 in U-Boot currently is in efi_net.c which does if (ipv6) { ret = EFI_UNSUPPORTED; As indicated in the comment, it can easily be put back, but preferably under a config knob. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2021-07-15lib/vsprintf.c: remove stale commentRasmus Villemoes
U-Boot doesn't support %pS/%pF or any other kind of kallsyms-like lookups. Remove the comment. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2021-07-15lib/vsprintf.c: implement printf() in terms of vprintf()Rasmus Villemoes
This saves some code, both in terms of #LOC and .text size, and it is also the normal convention that foo(...) is implemented in terms of vfoo(). Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
2020-07-01compiler*.h: sync include/linux/compiler*.h with Linux 5.7-rc5Tom Rini
Copy these from Linux v5.7-rc5 tag. This brings in some handy new attributes and is otherwise important to keep in sync. We drop the reference to smp_read_barrier_depends() as it is not relevant on the architectures we support at this time, based on where it's implemented in Linux today. We drop the call to kasan_check_read() as that is not relevant to U-Boot as well. Cc: Masahiro Yamada <yamada.masahiro@socionext.com> Signed-off-by: Tom Rini <trini@konsulko.com>
2020-05-18common: Drop uuid.h from common headerSimon Glass
Move this uncommon header out of the common header. Signed-off-by: Simon Glass <sjg@chromium.org>
2019-12-09lib: Always build support for formatting MAC and IP addressJoe Hershberger
Even if not communicating over the network in U-Boot, code may be manipulating and storing IP or MAC addresses to pass to Linux, etc. Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
2019-12-02Move strtomhz() to vsprintf.hSimon Glass
At present this function sits in its own file but it does not really justify it. There are similar string functions in vsprintf.h, so move it there. Also add the missing function comment. Use the vsprintf.h include file explicitly where needed. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@konsulko.com>
2019-06-07lib/vsprintf: allow printing upper case GUIDsHeinrich Schuchardt
In the UEFI context GUIDs are expected to be rendered in upper case. The patch uses the formerly unused bit 1 of the parameter str_format of function uuid_bin_to_str() to indicate if we need upper or lower case output. Function uuid_string() in vsprint.c is adjusted to correctly set the bit depending on the print format code. %pUb: 01020304-0506-0708-090a-0b0c0d0e0f10 %pUB: 01020304-0506-0708-090A-0B0C0D0E0F10 %pUl: 04030201-0605-0807-090a-0b0c0d0e0f10 %pUL: 04030201-0605-0807-090A-0B0C0D0E0F10 Up to this point only a diagnostic message in mount_ubifs() using '%pUB' is concerned by the change. Further patches are needed to adjust the UEFI subsystem. A unit test is provided inside the ut_print command. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-05-12efi_loader: make device path to text protocol customizableHeinrich Schuchardt
The device path to text protocol is not needed for EBBR compliance. So let's make it a customizable option. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-05-03lib/vsprintf: remove #include <uuid.h> from vsprintf.cHeinrich Schuchardt
common.h already includes uuid.h Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-11vsprintf: Support phys_addr_t specifier unconditionallyThierry Reding
When phys_addr_t printf specifier support was first introduced in commit 1eebd14b7902 ("vsprintf: Add modifier for phys_addr_t"), it was enabled only if CONFIG_CMD_NET was selected. Since physical addresses are not unique to networking support it doesn't make sense to conditionally add it in those cases only. Move support for it outside of the CMD_NET guard so that the specifier is always supported. Signed-off-by: Thierry Reding <treding@nvidia.com> Reviewed-by: Simon Glass <sjg@chromium.org>
2019-02-16lib/vsprintf: print '?' for illegal Unicode sequenceHeinrich Schuchardt
Commit 0e66c10a7d80 ("lib: vsprintf: avoid overflow printing UTF16 strings") broke the Unicode unit tests: an illegal UTF16 code point should be printed as '?'. Fixes: 0e66c10a7d80 ("lib: vsprintf: avoid overflow printing UTF16 strings") Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-02-13lib: vsprintf: avoid overflow printing UTF16 stringsHeinrich Schuchardt
We have to ensure while printing UTF16 strings that we do not exceed the end of the print buffer. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23lib: vsprintf: correct printing of Unicode stringsHeinrich Schuchardt
The width and precision of the printf() function refer to the number of characters not to the number of bytes printed. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23efi_loader: rename utf16_strlen, utf16_strnlenHeinrich Schuchardt
The function names utf16_strlen() and utf16_strnlen() are misnomers. The functions do not count utf-16 characters but non-zero words. So let's rename them to u16_strlen and u16_strnlen(). In utf16_dup() avoid assignment in if clause. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23lib: build charset.o only if neededHeinrich Schuchardt
charset.o is only needed for the EFI subsystem Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-09-23vsprintf.c: use #if CONFIG_IS_ENABLED(EFI_LOADER)Heinrich Schuchardt
Using CONFIG_IS_ENABLED(EFI_LOADER) allows to simply the #if statements. Suggested-by: Alexander Graf <agraf@suse.de> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-07-25vsprintf: Handle NULL with %pUSimon Glass
At present a NULL pointer passed to printf for a %pU argument will cause U-Boot to access memory at 0. Fix this by adding a check, and print "(null)" instead. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Alexander Graf <agraf@suse.de> [agraf: s/(null)/<NULL>/] Signed-off-by: Alexander Graf <agraf@suse.de>
2018-06-13lib: Add hexdumpAlexey Brodkin
Often during debugging session it's very interesting to see what data we were dealing with. For example what we write or read to/from memory or peripherals. This change introduces functions that allow to dump binary data with one simple function invocation like: ------------------->8---------------- print_hex_dump_bytes("", DUMP_PREFIX_OFFSET, buf, len); ------------------->8---------------- which gives us the following: ------------------->8---------------- 00000000: f2 b7 c9 88 62 61 75 64 72 61 74 65 3d 31 31 35 ....baudrate=115 00000010: 32 30 30 00 62 6f 6f 74 61 72 67 73 3d 63 6f 6e 200.bootargs=con 00000020: 73 6f 6c 65 3d 74 74 79 53 33 2c 31 31 35 32 30 sole=ttyS3,11520 00000030: 30 6e 38 00 62 6f 6f 74 64 65 6c 61 79 3d 33 00 0n8.bootdelay=3. 00000040: 62 6f 6f 74 66 69 6c 65 3d 75 49 6d 61 67 65 00 bootfile=uImage. 00000050: 66 64 74 63 6f 6e 74 72 6f 6c 61 64 64 72 3d 39 fdtcontroladdr=9 00000060: 66 66 62 31 62 61 30 00 6c 6f 61 64 61 64 64 72 ffb1ba0.loadaddr 00000070: 3d 30 78 38 32 30 30 30 30 30 30 00 73 74 64 65 =0x82000000.stde 00000080: 72 72 3d 73 65 72 69 61 6c 30 40 65 30 30 32 32 rr=serial0@e0022 00000090: 30 30 30 00 73 74 64 69 6e 3d 73 65 72 69 61 6c 000.stdin=serial 000000a0: 30 40 65 30 30 32 32 30 30 30 00 73 74 64 6f 75 0@e0022000.stdou 000000b0: 74 3d 73 65 72 69 61 6c 30 40 65 30 30 32 32 30 t=serial0@e00220 000000c0: 30 30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00.............. ... ------------------->8---------------- Source of hexdump.c was copied from Linux kernel v4.7-rc2. Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com> Cc: Anatolij Gustschin <agust@denx.de> Cc: Mario Six <mario.six@gdsys.cc> Cc: Simon Glass <sjg@chromium.org> Cc: Tom Rini <trini@konsulko.com> Cc: Stefan Roese <sr@denx.de>
2018-04-28Consolidate __assert_failed into one implementationAlex Kiernan
We had two implementations of __assert_failed which were almost identical, combine them into one. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2018-04-28spl: Disable printf if not requiredAlex Kiernan
Now we have a guard for printf, disable it in the build if it's not selected. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com>
2018-01-28vsprintf.c: correct printing of a NULL device pathHeinrich Schuchardt
When printing '%pD' with a value of NULL we want to output '<NULL>'. But this requires copying to buf. Leave this to string16. A unit test is supplied which relies on EFI support in the sandbox. The development for EFI support in the sandbox is currently in branch u-boot-dm/efi-working. The branch lacks commit 6ea8b580f06b ("efi_loader: correct DeviceNodeToText for media types"). Ater rebasing the aforementioned branch on U-Boot v2018.01 and adding 256060e4257a2 and this patch the test is executed successfully. Fixes: 256060e4257a2 (vsprintf.c: add EFI device path printing) Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Signed-off-by: Alexander Graf <agraf@suse.de>
2018-01-22vsprintf.c: add EFI device path printingHeinrich Schuchardt
For debugging efi_loader we need the capability to print EFI device paths. With this patch we can write: debug("device path: %pD", dp); A possible output would be device path: /MemoryMapped(0x0,0x3ff93a82,0x3ff93a82) This enhancement is not available when building without EFI support and neither in the SPL nor in the API example. A test is provided. It can be executed in the sandbox with command ut_print. The development for EFI support in the sandbox is currently in branch u-boot-dm/efi-working. The branch currently lacks commit 6ea8b580f06b ("efi_loader: correct DeviceNodeToText for media types"). Ater rebasing the aforementioned branch on U-Boot v2018.01 the test is executed successfully. Without EFI support in the sandbox the test is simply skipped. Suggested-by: Rob Clark <robdclark@gmail.com> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Alexander Graf <agraf@suse.de>
2017-09-12vsprintf.c: add GUID printingRob Clark
This works (roughly) the same way as linux's, but we currently always print lower-case (ie. we just keep %pUB and %pUL for compat with linux), mostly just because that is what uuid_bin_to_str() supports. %pUb: 01020304-0506-0708-090a-0b0c0d0e0f10 %pUl: 04030201-0605-0807-090a-0b0c0d0e0f10 It will be used by a later efi_loader paths for efi variables and for device-path-to-text protocol, and also quite useful for debug prints of protocol GUIDs. Signed-off-by: Rob Clark <robdclark@gmail.com> Tested-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
2017-09-12vsprintf.c: add UTF-16 string (%ls) supportRob Clark
This is convenient for efi_loader which deals a lot with UTF-16. Only enabled with CC_SHORT_WCHAR, leaving room to add a UTF-32 version when CC_SHORT_WCHAR is not enabled. Signed-off-by: Rob Clark <robdclark@gmail.com> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
2016-01-19vsprintf.c: Always enable CONFIG_SYS_VSNPRINTFTom Rini
Enabling this function always removes some class of string saftey issues. The size change here in general is about 400 bytes and this seems a reasonable trade-off. Cc: Peng Fan <peng.fan@nxp.com> Cc: Peter Robinson <pbrobinson@gmail.com> Cc: Fabio Estevam <fabio.estevam@freescale.com> Cc: Adrian Alonso <aalonso@freescale.com> Cc: Stefano Babic <sbabic@denx.de> Cc: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Tom Rini <trini@konsulko.com>
2015-12-13lib: split out strtoxxxx functions out of vsprintf.cSjoerd Simons
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>
2015-12-13lib: Split panic functions out of vsprintf.cSjoerd Simons
To allow panic and panic_str to still 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>
2015-11-23lib/tiny-printf.c: Add tiny printf function for space limited environmentsStefan Roese
This patch adds a small printf() version that supports all basic formats. Its intented to be used in U-Boot SPL versions on platforms with very limited internal RAM sizes. To enable it, just define CONFIG_USE_TINY_PRINTF in your defconfig. This will result in the SPL using this tiny function and the main U-Boot still using the full-blown printf() function. This code was copied from: http://www.sparetimelabs.com/printfrevisited With mostly only coding style related changes so that its checkpatch clean. The size reduction is about 2.5KiB. Here a comparison for the db-mv784mp-gp (Marvell AXP) SPL: Without this patch: 58963 18536 1928 79427 13643 ./spl/u-boot-spl With this patch: 56542 18536 1956 77034 12cea ./spl/u-boot-spl Note: To make it possible to compile tiny-printf.c instead of vsprintf.c when CONFIG_USE_TINY_PRINTF is defined, the functions printf() and vprintf() are moved from common/console.c into vsprintf.c in this patch. Signed-off-by: Stefan Roese <sr@denx.de> Cc: Simon Glass <sjg@chromium.org> Cc: Hans de Goede <hdegoede@redhat.com> Cc: Tom Rini <trini@konsulko.com> Cc: Albert Aribaud <albert.u.boot@aribaud.net>
2015-07-21lib: Add function to extract a number from the end of a stringSimon Glass
Split out the code in fdtdec which finds a number at the end of a string. It can be useful in other situations. Signed-off-by: Simon Glass <sjg@chromium.org>
2015-06-30mtd, nand: Move common functions from cmd_nand.c to common placeHeiko Schocher
Move common functions from cmd_nand.c (for calculating offset and size from cmdline paramter) to common place, so they could used from other commands which use mtd partitions. For onenand the arg_off_size() is left in common/cmd_onenand.c. It should use now the common arg_off() function, but as I could not test onenand I let it there ... Signed-off-by: Heiko Schocher <hs@denx.de> Acked-by: Scott Wood <scottwood@freescale.com> Reviewed-by: Jagannadh Teki <jteki@openedev.com>
2015-04-23dm: Add a panic_str() function to reduce code sizeSimon Glass
The printf() in panic() adds about 1.5KB of code size to SPL when compiled with Thumb-2. Provide a smaller version that does not support printf()-style arguments and use it in two commonly compiled places. Signed-off-by: Simon Glass <sjg@chromium.org>
2014-11-23vsprintf: Add modifier for phys_addr_tThierry Reding
Provide a new modifier to vsprintf() to print phys_addr_t variables to avoid having to cast or #ifdef when printing them out. The %pa modifier is used for this purpose, so phys_addr_t variables need to be passed by reference, like so: phys_addr_t start = 0; printf("start: %pa\n", &start); Depending on the size of phys_addr_t this will print out the address with 8 or 16 hexadecimal digits following a 0x prefix. Signed-off-by: Thierry Reding <treding@nvidia.com> Tested-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Simon Glass <sjg@chromium.org>
2014-11-20include: move various macros to include/linux/kernel.hMasahiro Yamada
U-Boot has imported various utility macros from Linux scattering them to various places without consistency. In include/common.h are min, max, min3, max3, ARRAY_SIZE, ALIGN, container_of, DIV_ROUND_UP, etc. In include/linux/compat.h are min_t, max_t, round_up, round_down, etc. We also have duplicated defines of min_t in some *.c files. Moreover, we are suffering from too cluttered include/common.h. This commit moves various macros that originate in include/linux/kernel.h of Linux to their original position. Note: This commit simply moves the macros; the macros roundup, min, max, min2, max3, ARRAY_SIZE are different from those of Linux at this point. Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
2014-10-27Use uint64_t instead of u64 in put_dec()Simon Glass
Use the correct type required by do_div(). Signed-off-by: Simon Glass <sjg@chromium.org>
2014-07-18lib:vsprintf: reduce scope of pack_hex_byteJeroen Hofstee
pack_hex_byte is only used when CONFIG_CMD_NET is defined so limit it to that scope. This prevents a clang warning. Signed-off-by: Jeroen Hofstee <jeroen@myspectrum.nl>
2014-01-24lib: fix return codes when CONFIG_SYS_VSNPRINTF is enabledDarwin Rambo
When CONFIG_SYS_VSNPRINTF is enabled, it protects print operations such as sprintf, snprintf, vsnprintf, etc., from buffer overflows. But vsnprintf_internal includes the terminating NULL character in the calculation of number of characters written. This affects sprintf and snprintf return values. Fix this issue by setting pointer 'str' back to the location of the '\0'. Signed-off-by: Darwin Rambo <drambo@broadcom.com> Reviewed-by: Steve Rae <srae@broadcom.com>
2013-06-26Add function to print a number with grouped digitsSimon Glass
Move bootstage's numbering printing code into a generic place so that it can be used by tracing also. Signed-off-by: Simon Glass <sjg@chromium.org>
2013-02-19vsprintf: add ustrtoll functionPiotr Wilczek
Add 'ustrtoull' function to convert size from string (ex: 1GiB) to unsigned long long type Signed-off-by: Piotr Wilczek <p.wilczek@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-12-13vsprintf:fix: Change type returned by ustrtoulLukasz Majewski
The ustrtoul shall convert string defined size (e.g. 1GiB) to unsigned long type (as its name implies). Up till now it had returned int, which might cause problems with large numbers (GiB range), when interpreted as U2 signed numbers. Signed-off-by: Lukasz Majewski <l.majewski@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
2012-11-04lib/vsprintf.c: sparse fixesKim Phillips
vsprintf.c:31:12: warning: symbol 'hex_asc' was not declared. Should it be static? vsprintf.c:398:18: warning: Using plain integer as NULL pointer Signed-off-by: Kim Phillips <kim.phillips@freescale.com>