* from hush: simple_itoa() was lifted from boa-0.93.15
*/
-#include <common.h>
#include <charset.h>
#include <efi_loader.h>
#include <div64.h>
#define LEFT 16 /* left justified */
#define SMALL 32 /* Must be 32 == 0x20 */
#define SPECIAL 64 /* 0x */
+#define ERRSTR 128 /* %dE showing error string if enabled */
/*
* Macro to add a new character to our output string, but only if it will
return buf;
}
-static char *string(char *buf, char *end, char *s, int field_width,
+static char *string(char *buf, char *end, const char *s, int field_width,
int precision, int flags)
{
int len, i;
}
/* U-Boot uses UTF-16 strings in the EFI context only. */
-#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
-static char *string16(char *buf, char *end, u16 *s, int field_width,
- int precision, int flags)
+static __maybe_unused char *string16(char *buf, char *end, u16 *s,
+ int field_width, int precision, int flags)
{
- const u16 *str = s ? s : L"<NULL>";
+ const u16 *str = s ? s : u"<NULL>";
ssize_t i, len = utf16_strnlen(str, precision);
if (!(flags & LEFT))
for (; len < field_width; --field_width)
ADDCH(buf, ' ');
- for (i = 0; i < len && buf + utf16_utf8_strnlen(str, 1) <= end; ++i) {
+ if (buf < end)
+ *buf = 0;
+ for (i = 0; i < len; ++i) {
+ int slen = utf16_utf8_strnlen(str, 1);
s32 s = utf16_get(&str);
if (s < 0)
s = '?';
- utf8_put(s, &buf);
+ if (buf + slen < end) {
+ utf8_put(s, &buf);
+ if (buf < end)
+ *buf = 0;
+ } else {
+ buf += slen;
+ }
}
for (; len < field_width; --field_width)
ADDCH(buf, ' ');
+
return buf;
}
return buf;
}
#endif
-#endif
static char *mac_address_string(char *buf, char *end, u8 *addr, int field_width,
int precision, int flags)
* %pUB: 01020304-0506-0708-090A-0B0C0D0E0F10
* %pUl: 04030201-0605-0807-090a-0b0c0d0e0f10
* %pUL: 04030201-0605-0807-090A-0B0C0D0E0F10
+ * %pUs: GUID text representation if known or fallback to %pUl
*/
static char *uuid_string(char *buf, char *end, u8 *addr, int field_width,
int precision, int flags, const char *fmt)
{
char uuid[UUID_STR_LEN + 1];
int str_format;
+ const char *str;
switch (*(++fmt)) {
case 'L':
case 'B':
str_format = UUID_STR_FORMAT_STD | UUID_STR_UPPER_CASE;
break;
+ case 's':
+ str = uuid_guid_get_str(addr);
+ if (str)
+ return string(buf, end, str,
+ field_width, precision, flags);
+ str_format = UUID_STR_FORMAT_GUID;
+ break;
default:
str_format = UUID_STR_FORMAT_STD;
break;
* decimal for v4 and colon separated network-order 16 bit hex for v6)
* - 'i' [46] for 'raw' IPv4/IPv6 addresses, IPv6 omits the colons, IPv4 is
* currently the same
- *
- * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
- * function pointers are really function descriptors, which contain a
- * pointer to the real address.
*/
static char *pointer(const char *fmt, char *buf, char *end, void *ptr,
int field_width, int precision, int flags)
flags |= SPECIAL;
/* Fallthrough */
case 'I':
- if (fmt[1] == '6')
+ if (IS_ENABLED(CONFIG_IPV6) && fmt[1] == '6')
return ip6_addr_string(buf, end, ptr, field_width,
precision, flags);
if (fmt[1] == '4')
case 's':
/* U-Boot uses UTF-16 strings in the EFI context only. */
-#if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
+#if (CONFIG_IS_ENABLED(EFI_LOADER) || IS_ENABLED(CONFIG_EFI_APP)) && \
+ !defined(API_BUILD)
if (qualifier == 'l') {
str = string16(str, end, va_arg(args, u16 *),
field_width, precision, flags);
case 'x':
flags |= SMALL;
+ /* fallthrough */
case 'X':
base = 16;
break;
case 'd':
+ if (fmt[1] == 'E') {
+ flags |= ERRSTR;
+ fmt++;
+ }
+ /* fallthrough */
case 'i':
flags |= SIGN;
+ /* fallthrough */
case 'u':
break;
}
str = number(str, end, num, base, field_width, precision,
flags);
+ if (IS_ENABLED(CONFIG_ERRNO_STR) && (flags & ERRSTR)) {
+ const char *p;
+
+ ADDCH(str, ':');
+ ADDCH(str, ' ');
+ for (p = errno_str(num); *p; p++)
+ ADDCH(str, *p);
+ }
}
if (size > 0) {
{
va_list args;
uint i;
- char printbuffer[CONFIG_SYS_PBSIZE];
va_start(args, fmt);
-
- /*
- * For this to work, printbuffer must be larger than
- * anything we ever want to print.
- */
- i = vscnprintf(printbuffer, sizeof(printbuffer), fmt, args);
+ i = vprintf(fmt, args);
va_end(args);
- /* Handle error */
- if (i <= 0)
- return i;
- /* Print the string */
- puts(printbuffer);
return i;
}
}
#endif
+static char local_toa[22];
+
char *simple_itoa(ulong i)
{
/* 21 digits plus null terminator, good for 64-bit or smaller ints */
- static char local[22];
- char *p = &local[21];
+ char *p = &local_toa[21];
*p-- = '\0';
do {
return p + 1;
}
+char *simple_xtoa(ulong num)
+{
+ /* 16 digits plus nul terminator, good for 64-bit or smaller ints */
+ char *p = &local_toa[17];
+
+ *--p = '\0';
+ do {
+ p -= 2;
+ hex_byte_pack(p, num & 0xff);
+ num >>= 8;
+ } while (num > 0);
+
+ return p;
+}
+
/* We don't seem to have %'d in U-Boot */
void print_grouped_ull(unsigned long long int_val, int digits)
{
{
char *endptr;
- *num = simple_strtoul(p, &endptr, 16);
+ *num = hextoul(p, &endptr);
return *p != '\0' && *endptr == '\0';
}