fdtdec: support multiple phandles in memory carveout
[oweals/u-boot.git] / lib / efi_selftest / efi_selftest_console.c
index 840e2290c60c05684c6afb898e4c66db42c374da..42f51b652036ee31037226bc62f53f9e87515dfc 100644 (file)
@@ -1,16 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * EFI efi_selftest
  *
  * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
- *
- * SPDX-License-Identifier:     GPL-2.0+
  */
 
 #include <efi_selftest.h>
 #include <vsprintf.h>
 
 struct efi_simple_text_output_protocol *con_out;
-struct efi_simple_input_interface *con_in;
+struct efi_simple_text_input_protocol *con_in;
 
 /*
  * Print a MAC address to an u16 string
@@ -71,11 +70,12 @@ static void pointer(void *pointer, u16 **buf)
 /*
  * Print an unsigned 32bit value as decimal number to an u16 string
  *
- * @value: value to be printed
- * @buf: pointer to buffer address
- * on return position of terminating zero word
+ * @value:     value to be printed
+ * @prec:      minimum number of digits to display
+ * @buf:       pointer to buffer address
+ *             on return position of terminating zero word
  */
-static void uint2dec(u32 value, u16 **buf)
+static void uint2dec(u32 value, int prec, u16 **buf)
 {
        u16 *pos = *buf;
        int i;
@@ -94,7 +94,7 @@ static void uint2dec(u32 value, u16 **buf)
        for (i = 0; i < 10; ++i) {
                /* Write current digit */
                c = f >> 60;
-               if (c || pos != *buf)
+               if (c || pos != *buf || 10 - i <= prec)
                        *pos++ = c + '0';
                /* Eliminate current digit */
                f &= 0xfffffffffffffff;
@@ -110,11 +110,12 @@ static void uint2dec(u32 value, u16 **buf)
 /*
  * Print a signed 32bit value as decimal number to an u16 string
  *
- * @value: value to be printed
- * @buf: pointer to buffer address
+ * @value:     value to be printed
+ * @prec:      minimum number of digits to display
+ * @buf:       pointer to buffer address
  * on return position of terminating zero word
  */
-static void int2dec(s32 value, u16 **buf)
+static void int2dec(s32 value, int prec, u16 **buf)
 {
        u32 u;
        u16 *pos = *buf;
@@ -125,26 +126,31 @@ static void int2dec(s32 value, u16 **buf)
        } else {
                u = value;
        }
-       uint2dec(u, &pos);
+       uint2dec(u, prec, &pos);
        *buf = pos;
 }
 
 /*
- * Print a formatted string to the EFI console
+ * Print a colored formatted string to the EFI console
  *
- * @fmt: format string
- * @...: optional arguments
+ * @color      color, see constants in efi_api.h, use -1 for no color
+ * @fmt                format string
+ * @...                optional arguments
  */
-void efi_st_printf(const char *fmt, ...)
+void efi_st_printc(int color, const char *fmt, ...)
 {
        va_list args;
        u16 buf[160];
        const char *c;
        u16 *pos = buf;
        const char *s;
+       u16 *u;
+       int prec;
 
        va_start(args, fmt);
 
+       if (color >= 0)
+               con_out->set_attribute(con_out, (unsigned long)color);
        c = fmt;
        for (; *c; ++c) {
                switch (*c) {
@@ -169,19 +175,40 @@ void efi_st_printf(const char *fmt, ...)
                        break;
                case '%':
                        ++c;
+                       /* Parse precision */
+                       if (*c == '.') {
+                               ++c;
+                               prec = *c - '0';
+                               ++c;
+                       } else {
+                               prec = 0;
+                       }
                        switch (*c) {
                        case '\0':
                                --c;
                                break;
                        case 'd':
-                               int2dec(va_arg(args, s32), &pos);
+                               int2dec(va_arg(args, s32), prec, &pos);
                                break;
                        case 'p':
                                ++c;
                                switch (*c) {
+                               /* MAC address */
                                case 'm':
                                        mac(va_arg(args, void*), &pos);
                                        break;
+
+                               /* u16 string */
+                               case 's':
+                                       u = va_arg(args, u16*);
+                                       if (pos > buf) {
+                                               *pos = 0;
+                                               con_out->output_string(con_out,
+                                                                      buf);
+                                       }
+                                       con_out->output_string(con_out, u);
+                                       pos = buf;
+                                       break;
                                default:
                                        --c;
                                        pointer(va_arg(args, void*), &pos);
@@ -193,7 +220,7 @@ void efi_st_printf(const char *fmt, ...)
                                        *pos++ = *s;
                                break;
                        case 'u':
-                               uint2dec(va_arg(args, u32), &pos);
+                               uint2dec(va_arg(args, u32), prec, &pos);
                                break;
                        default:
                                break;
@@ -206,6 +233,8 @@ void efi_st_printf(const char *fmt, ...)
        va_end(args);
        *pos = 0;
        con_out->output_string(con_out, buf);
+       if (color >= 0)
+               con_out->set_attribute(con_out, EFI_LIGHTGRAY);
 }
 
 /*