]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - lib/efi_selftest/efi_selftest_console.c
Merge tag 'xilinx-for-v2018.03' of git://git.denx.de/u-boot-microblaze
[people/ms/u-boot.git] / lib / efi_selftest / efi_selftest_console.c
index 7b5b724a617892d70e6a2b410accf8c7b62f4c20..e1649f48bc4bc874add10169a4e0a6cf41eb127a 100644 (file)
 struct efi_simple_text_output_protocol *con_out;
 struct efi_simple_input_interface *con_in;
 
+/*
+ * Print a MAC address to an u16 string
+ *
+ * @pointer: mac address
+ * @buf: pointer to buffer address
+ * on return position of terminating zero word
+ */
+static void mac(void *pointer, u16 **buf)
+{
+       int i, j;
+       u16 c;
+       u8 *p = (u8 *)pointer;
+       u8 byte;
+       u16 *pos = *buf;
+
+       for (i = 0; i < ARP_HLEN; ++i) {
+               if (i)
+                       *pos++ = ':';
+               byte = p[i];
+               for (j = 4; j >= 0; j -= 4) {
+                       c = (byte >> j) & 0x0f;
+                       c += '0';
+                       if (c > '9')
+                               c += 'a' - '9' - 1;
+                       *pos++ = c;
+               }
+       }
+       *pos = 0;
+       *buf = pos;
+}
+
 /*
  * Print a pointer to an u16 string
  *
@@ -99,21 +130,25 @@ static void int2dec(s32 value, u16 **buf)
 }
 
 /*
- * 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;
 
        va_start(args, fmt);
 
+       if (color >= 0)
+               con_out->set_attribute(con_out, (unsigned long)color);
        c = fmt;
        for (; *c; ++c) {
                switch (*c) {
@@ -146,7 +181,28 @@ void efi_st_printf(const char *fmt, ...)
                                int2dec(va_arg(args, s32), &pos);
                                break;
                        case 'p':
-                               pointer(va_arg(args, void*), &pos);
+                               ++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);
+                               }
                                break;
                        case 's':
                                s = va_arg(args, const char *);
@@ -167,6 +223,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);
 }
 
 /*