Merge tag 'dm-pull-29oct19' of git://git.denx.de/u-boot-dm
[oweals/u-boot.git] / lib / tiny-printf.c
index 0b04813dc206be9cd6163136574b7213e5933e91..1138c7012aee50c4928f953c4d1d24852b659115 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: LGPL-2.1+
 /*
  * Tiny printf version for SPL
  *
@@ -5,8 +6,6 @@
  * http://www.sparetimelabs.com/printfrevisited/printfrevisited.php
  *
  * Copyright (C) 2004,2008  Kustaa Nyholm
- *
- * SPDX-License-Identifier:    LGPL-2.1+
  */
 
 #include <common.h>
@@ -23,11 +22,6 @@ struct printf_info {
        void (*putc)(struct printf_info *info, char ch);
 };
 
-static void putc_normal(struct printf_info *info, char ch)
-{
-       putc(ch);
-}
-
 static void out(struct printf_info *info, char c)
 {
        *info->bf++ = c;
@@ -163,7 +157,8 @@ static void ip4_addr_string(struct printf_info *info, u8 *addr)
  *       decimal).
  */
 
-static void pointer(struct printf_info *info, const char *fmt, void *ptr)
+static void __maybe_unused pointer(struct printf_info *info, const char *fmt,
+                                  void *ptr)
 {
 #ifdef DEBUG
        unsigned long num = (uintptr_t)ptr;
@@ -272,6 +267,21 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va)
                                                div_out(info, &num, div);
                                }
                                break;
+                       case 'p':
+#ifdef DEBUG
+                               pointer(info, fmt, va_arg(va, void *));
+                               /*
+                                * Skip this because it pulls in _ctype which is
+                                * 256 bytes, and we don't generally implement
+                                * pointer anyway
+                                */
+                               while (isalnum(fmt[0]))
+                                       fmt++;
+                               break;
+#else
+                               islong = true;
+                               /* no break */
+#endif
                        case 'x':
                                if (islong) {
                                        num = va_arg(va, unsigned long);
@@ -293,11 +303,6 @@ static int _vprintf(struct printf_info *info, const char *fmt, va_list va)
                        case 's':
                                p = va_arg(va, char*);
                                break;
-                       case 'p':
-                               pointer(info, fmt, va_arg(va, void *));
-                               while (isalnum(fmt[0]))
-                                       fmt++;
-                               break;
                        case '%':
                                out(info, '%');
                        default:
@@ -321,6 +326,12 @@ abort:
        return 0;
 }
 
+#if CONFIG_IS_ENABLED(PRINTF)
+static void putc_normal(struct printf_info *info, char ch)
+{
+       putc(ch);
+}
+
 int vprintf(const char *fmt, va_list va)
 {
        struct printf_info info;
@@ -343,6 +354,7 @@ int printf(const char *fmt, ...)
 
        return ret;
 }
+#endif
 
 static void putc_outstr(struct printf_info *info, char ch)
 {
@@ -365,6 +377,22 @@ int sprintf(char *buf, const char *fmt, ...)
        return ret;
 }
 
+#if CONFIG_IS_ENABLED(LOG)
+/* Note that size is ignored */
+int vsnprintf(char *buf, size_t size, const char *fmt, va_list va)
+{
+       struct printf_info info;
+       int ret;
+
+       info.outstr = buf;
+       info.putc = putc_outstr;
+       ret = _vprintf(&info, fmt, va);
+       *info.outstr = '\0';
+
+       return ret;
+}
+#endif
+
 /* Note that size is ignored */
 int snprintf(char *buf, size_t size, const char *fmt, ...)
 {
@@ -382,11 +410,8 @@ int snprintf(char *buf, size_t size, const char *fmt, ...)
        return ret;
 }
 
-void __assert_fail(const char *assertion, const char *file, unsigned line,
-                  const char *function)
+void print_grouped_ull(unsigned long long int_val, int digits)
 {
-       /* This will not return */
-       printf("%s:%u: %s: Assertion `%s' failed.", file, line, function,
-              assertion);
-       hang();
+       /* Don't try to print the upper 32-bits */
+       printf("%ld ", (ulong)int_val);
 }