summaryrefslogtreecommitdiff
path: root/lib/vsprintf.c
AgeCommit message (Collapse)AuthorFilesLines
2021-12-31efi: Make unicode printf available to the appSimon Glass1-5/+4
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-12lib: Add a function to convert a string to a hex valueSimon Glass1-2/+18
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 Glass1-1/+1
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-16lib/vsprintf.c: remove unused ip6_addr_string()Rasmus Villemoes1-1/+5
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-16lib/vsprintf.c: remove stale commentRasmus Villemoes1-3/+0
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-16lib/vsprintf.c: implement printf() in terms of vprintf()Rasmus Villemoes1-12/+1
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 Rini1-2/+0
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 Glass1-0/+1
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 Hershberger1-4/+0
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-03Move strtomhz() to vsprintf.hSimon Glass1-0/+19
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 Schuchardt1-6/+8
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 Schuchardt1-1/+3
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 Schuchardt1-1/+0
common.h already includes uuid.h Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
2019-04-12vsprintf: Support phys_addr_t specifier unconditionallyThierry Reding1-1/+1
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 Schuchardt1-0/+2
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 Schuchardt1-3/+7
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 Schuchardt1-9/+4
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 Schuchardt1-1/+1
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 Schuchardt1-4/+8
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 Schuchardt1-4/+4
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 Glass1-1/+4
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 Brodkin1-14/+4
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-29Consolidate __assert_failed into one implementationAlex Kiernan1-8/+0
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-29spl: Disable printf if not requiredAlex Kiernan1-1/+2
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 Schuchardt1-1/+2
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-23vsprintf.c: add EFI device path printingHeinrich Schuchardt1-6/+41
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-13vsprintf.c: add GUID printingRob Clark1-2/+44
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-13vsprintf.c: add UTF-16 string (%ls) supportRob Clark1-2/+28
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 Rini1-12/+0
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-14lib: split out strtoxxxx functions out of vsprintf.cSjoerd Simons1-164/+0
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-14lib: Split panic functions out of vsprintf.cSjoerd Simons1-29/+0
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 Roese1-0/+36
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-22lib: Add function to extract a number from the end of a stringSimon Glass1-0/+19
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-29mtd, nand: Move common functions from cmd_nand.c to common placeHeiko Schocher1-0/+16
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 Glass1-5/+18
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 Reding1-2/+14
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 Yamada1-3/+0
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 Glass1-1/+1
Use the correct type required by do_div(). Signed-off-by: Simon Glass <sjg@chromium.org>
2014-07-19lib:vsprintf: reduce scope of pack_hex_byteJeroen Hofstee1-11/+11
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-25lib: fix return codes when CONFIG_SYS_VSNPRINTF is enabledDarwin Rambo1-0/+1
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 Glass1-0/+16
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-20vsprintf: add ustrtoll functionPiotr Wilczek1-0/+23
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 Majewski1-1/+1
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 Phillips1-2/+2
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>
2012-11-03lib/vsprintf.c: don't special-case pointers to address nullWolfgang Denk1-0/+6
The %p format of printf() would print a pointer to address null as "(null)". This makes sense in a real OS where a NULL pointer must never be dereferenced, but this is a bootloader, and there are cases where accessing the data at address null makes perfect sense. Remove the special case in lib/vsprintf.c using "#if 0" with a comment to make clear this was an intentional change and to stop re-adding this code. Signed-off-by: Wolfgang Denk <wd@denx.de> Acked-by: Joe Hershberger <joe.hershberger@ni.com>
2012-10-15lib: vsprintf.c: replace NUM_TYPE with s64/u64 typesDaniel Schwierzeck1-6/+5
This fixes warnings when compiling with ELDK-5.2.1 for MIPS64: vsprintf.c: In function 'put_dec': vsprintf.c:258:9: warning: comparison of distinct pointer types lacks a cast [enabled by default] vsprintf.c:258:3: warning: passing argument 1 of '__div64_32' from incompatible pointer type [enabled by default] include/div64.h:22:17: note: expected 'uint64_t *' but argument is of type 'long long unsigned int *' Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
2012-10-15lib: vsprintf.c: fix checkpath.pl warningsDaniel Schwierzeck1-50/+77
Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
2011-12-18vsprintf: Move function documentation into header fileSimon Glass1-100/+0
Now that this is not in common.h, perhaps it is acceptable to move this documentation into the header file. Signed-off-by: Simon Glass <sjg@chromium.org>
2011-12-18Add safe vsnprintf and snprintf library functionsSonny Rao1-52/+213
From: Sonny Rao <sonnyrao@chromium.org> These functions are useful in U-Boot because they allow a graceful failure rather than an unpredictable stack overflow when printf() buffers are exceeded. Mostly copied from the Linux kernel. I copied vscnprintf and scnprintf so we can change printf and vprintf to use the safe implementation but still return the correct values. (Simon Glass <sjg@chromium.org> modified this commit a little) Signed-off-by: Sonny Rao <sonnyrao@chromium.org>
2011-10-26Move simple_itoa to vsprintfSimon Glass1-0/+16
This function is generally useful and shouldn't hide away in hush. It has been moved as is. Signed-off-by: Simon Glass <sjg@chromium.org>