Skip to contentSkip to conversation

efi_loader: console improvements

PATCH New Jan Kiszka 1 participant 3 messages Jan 18, 2023

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

v5 cover efi_loader: console improvements

Changes to v4:

- move cursor to bottom-right before scrolling

Jan

Jan Kiszka (2):
efi_loader: Avoid overwriting previous outputs on console screen
clearing
efi_loader: Set default console colors on efi_cout_clear_screen if
needed

 lib/efi_loader/Kconfig       |  9 +++++++++
 lib/efi_loader/efi_console.c | 20 +++++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)
Signature · 1 line
2.35.3
author
#1 lore raw

PATCH v5 1/2 efi_loader: Avoid overwriting previous outputs on console screen clearing

From: Jan Kiszka <[email protected]>

Before clearing the screen, ensure that no previous output of firmware or UEFI programs will be overwritten on serial devices or other streaming consoles. This helps generating complete boot logs.

Tested regarding multi-output against qemu-x86_defconfig. Still, there were remaining concerns about side effects, so this is provided as an opt-in feature.

---
 lib/efi_loader/Kconfig       |  9 +++++++++
 lib/efi_loader/efi_console.c | 14 +++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)
lib/efi_loader/Kconfig +9 -0
index b498c72206f..b2c3250b4ad 100644
@@ -124,6 +124,15 @@ config EFI_SET_TIME
 	  Provide the SetTime() runtime service at boottime. This service
 	  can be used by an EFI application to adjust the real time clock.
 
+config EFI_SCROLL_ON_CLEAR_SCREEN
+	bool "Avoid overwriting previous output on clear screen"
+	help
+	  Instead of moving the cursor home when the console screen should be
+	  cleared, emit blank new lines so that previous output is scrolled
+	  out of sight rather than overwritten. This allows on serial consoles
+	  to capture complete boot logs (except for interactive menus etc.)
+	  and can ease debugging related issues.
+
 config EFI_HAVE_CAPSULE_SUPPORT
 	bool
 
lib/efi_loader/efi_console.c +13 -1
index 4d08dd3763a..faa605e88d1 100644
@@ -461,10 +461,22 @@ static efi_status_t EFIAPI efi_cout_set_attribute(
 }
 
 /**
- * efi_cout_clear_screen() - clear screen
+ * efi_clear_screen() - clear screen
  */
 static void efi_clear_screen(void)
 {
+	if (CONFIG_IS_ENABLED(EFI_SCROLL_ON_CLEAR_SCREEN)) {
+		unsigned int row, screen_rows, screen_columns;
+
+		/* Avoid overwriting previous outputs on streaming consoles */
+		screen_rows = efi_cout_modes[efi_con_mode.mode].rows;
+		screen_columns = efi_cout_modes[efi_con_mode.mode].columns;
+		printf(ESC "[%d;1H",
+		       (int)screen_rows + 1, (int)screen_columns + 1);
+		for (row = 1; row < screen_rows; row++)
+			printf("\n");
+	}
+
 	/*
 	 * The Linux console wants both a clear and a home command. The video
 	 * uclass does not support <ESC>[H without coordinates, yet.
Signature · 1 line
2.35.3
author
#2 lore raw

PATCH v5 2/2 efi_loader: Set default console colors on efi_cout_clear_screen if needed

In reply to Jan Kiszka

From: Jan Kiszka <[email protected]>

Ensures a consistent background color of the whole screen for succeeding outputs as both demanded by the spec and implemented in EDK2 as well.

---
 lib/efi_loader/efi_console.c | 6 ++++++
 1 file changed, 6 insertions(+)
lib/efi_loader/efi_console.c +6 -0
index faa605e88d1..db31b2a751a 100644
@@ -501,6 +501,12 @@ static efi_status_t EFIAPI efi_cout_clear_screen(
 {
 	EFI_ENTRY("%p", this);
 
+	/* Set default colors if not done yet */
+	if (efi_con_mode.attribute == 0) {
+		efi_con_mode.attribute = 0x07;
+		printf(ESC "[0;37;40m");
+	}
+
 	efi_clear_screen();
 
 	return EFI_EXIT(EFI_SUCCESS);
Signature · 1 line
2.35.3