[PATCH 4/4] EFI: console: improve vidconsole unicode output

Artem Lapkin email2tema at gmail.com
Wed Aug 4 12:22:17 CEST 2021


If EFI_CONSOLE_UTF_SAFE is enabled and vidconsole is active, unicode
characters will be replaced with "." for all console outputs.

Vidconsole does not support unicode output, and your console will suffer
display issues if EFI_CONSOLE_UTF_SAFE is disabled.

Signed-off-by: Artem Lapkin <art at khadas.com>
---
 lib/efi_loader/Kconfig       | 9 +++++++++
 lib/efi_loader/efi_console.c | 6 +++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig
index 7d00d6cde5..886e0ce111 100644
--- a/lib/efi_loader/Kconfig
+++ b/lib/efi_loader/Kconfig
@@ -393,4 +393,13 @@ config EFI_CONSOLE_MAX_COLS
 	help
 	  Set console max rows limit or set to zero to disable limit.
 
+config EFI_CONSOLE_UTF_SAFE
+	bool "If vidconsole is active, unicode characters will be replaced with '.'"
+	default n
+	help
+	  If EFI_CONSOLE_UTF_SAFE is enabled and vidconsole is active, unicode
+	  characters will be replaced with "." for all console outputs.
+	  Vidconsole does not support unicode output, and your console will
+	  suffer display issues if EFI_CONSOLE_UTF_SAFE is disabled.
+
 endif
diff --git a/lib/efi_loader/efi_console.c b/lib/efi_loader/efi_console.c
index b5d79d788f..bd1c14995d 100644
--- a/lib/efi_loader/efi_console.c
+++ b/lib/efi_loader/efi_console.c
@@ -19,6 +19,8 @@
 #define EFI_COUT_MODE_2 2
 #define EFI_MAX_COUT_MODE 3
 
+static int vidconsole_active;
+
 struct cout_mode {
 	unsigned long columns;
 	unsigned long rows;
@@ -163,7 +165,8 @@ static efi_status_t EFIAPI efi_cout_output_string(
 	}
 	pos = buf;
 	utf16_utf8_strcpy(&pos, string);
-	fputs(stdout, buf);
+	fputs(stdout, IS_ENABLED(CONFIG_EFI_CONSOLE_UTF_SAFE) &&
+	      strlen(buf) > 1 && vidconsole_active ? "." : buf);
 	free(buf);
 
 	/*
@@ -327,6 +330,7 @@ static int __maybe_unused query_vidconsole(int *rows, int *cols)
 		return -ENODEV;
 	*rows = priv->rows;
 	*cols = priv->cols;
+	vidconsole_active = 1;
 	return 0;
 }
 
-- 
2.25.1



More information about the U-Boot mailing list