Skip to contentSkip to conversation

efi_loader: console improvements

PATCH Superseded Jan Kiszka 2 participants 8 messages Jan 18, 2023

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
author
#6 lore raw

PATCH v4 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 e40c129d1b2..84b5f60b321 100644
@@ -497,6 +497,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

Jan Kiszka

author
#0 lore raw

v4 cover efi_loader: console improvements

Changes to earlier versions:

- dropped merged "Let networking support depend on NETDEVICES"
- made scrolling on clear-screen a Kconfig option

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 | 16 +++++++++++++++-
 2 files changed, 24 insertions(+), 1 deletion(-)
Signature · 1 line
2.35.3
author
#1 lore raw

PATCH v4 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 | 10 +++++++++-
 2 files changed, 18 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 +9 -1
index 4d08dd3763a..e40c129d1b2 100644
@@ -461,10 +461,18 @@ 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;
+
+		/* Avoid overwriting previous outputs on streaming consoles */
+		for (row = 1; row < efi_cout_modes[efi_con_mode.mode].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
#2 lore raw

Re: [PATCH v4 1/2] efi_loader: Avoid overwriting previous outputs on console screen clearing

Am 18. Januar 2023 21:44:58 MEZ schrieb Jan Kiszka <[email protected]>:

Quoted 43 lines

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 | 10 +++++++++-

2 files changed, 18 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 +0 -0
index 4d08dd3763a..e40c129d1b2 100644
@@ -461,10 +461,18 @@ static efi_status_t EFIAPI efi_cout_set_attribute(
 }
 

lib/efi_loader/efi_console.c static efi_status_t EFIAPI efi_cout_set_attribute( · line 471

Quoted 10 lines
lib/efi_loader/efi_console.c +5 -1
 /**
- * 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;
+
+		/* Avoid overwriting previous outputs on streaming consoles */

Thanks for making the behavior configurable.

We cannot assume that the cursor is on the last line.

Assume that the cursor is on the first line. Then the screen will still be deleted.

Especially in GRUB the cursor often is in the upper half of the screen

The cursor should be moved to the right lower corner before scrolling.

Best regards

Heinrich

Quoted 7 lines
lib/efi_loader/efi_console.c +4 -0
+		for (row = 1; row < efi_cout_modes[efi_con_mode.mode].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.
Reviewed-by on v4 2/2
#7 lore raw

Re: [PATCH v4 2/2] efi_loader: Set default console colors on efi_cout_clear_screen if needed

In reply to Jan Kiszka

Am 18. Januar 2023 21:44:59 MEZ schrieb Jan Kiszka <[email protected]>:

Quoted 6 lines

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.

Quoted 21 lines

---
lib/efi_loader/efi_console.c | 6 ++++++

1 file changed, 6 insertions(+)
lib/efi_loader/efi_console.c +6 -0
index e40c129d1b2..84b5f60b321 100644
@@ -497,6 +497,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);
author
#3 lore raw

Re: [PATCH v4 1/2] efi_loader: Avoid overwriting previous outputs on console screen clearing

In reply to Heinrich Schuchardt
Quoted 59 lines · Heinrich Schuchardt

Am 18. Januar 2023 21:44:58 MEZ schrieb Jan Kiszka <[email protected]>:

Quoted 43 lines

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 | 10 +++++++++-

2 files changed, 18 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 +0 -0
index 4d08dd3763a..e40c129d1b2 100644
@@ -461,10 +461,18 @@ static efi_status_t EFIAPI efi_cout_set_attribute(
 }
 

lib/efi_loader/efi_console.c static efi_status_t EFIAPI efi_cout_set_attribute( · line 471

Quoted 10 lines
lib/efi_loader/efi_console.c +5 -1
 /**
- * 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;
+
+		/* Avoid overwriting previous outputs on streaming consoles */

Thanks for making the behavior configurable.

Quoted 7 lines

We cannot assume that the cursor is on the last line.

Assume that the cursor is on the first line. Then the screen will still be deleted.

Especially in GRUB the cursor often is in the upper half of the screen

The cursor should be moved to the right lower corner before scrolling.

Can do, though logging interactive menus was not in scope (and can't be solved this way anyway).

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux
#4 lore raw

Re: [PATCH v4 1/2] efi_loader: Avoid overwriting previous outputs on console screen clearing

Am 18. Januar 2023 21:58:42 MEZ schrieb Jan Kiszka <[email protected]>:

Quoted 64 lines · Heinrich Schuchardt
Quoted 63 lines

Am 18. Januar 2023 21:44:58 MEZ schrieb Jan Kiszka <[email protected]>:

Quoted 43 lines

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 | 10 +++++++++-

2 files changed, 18 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 +0 -0
index 4d08dd3763a..e40c129d1b2 100644
@@ -461,10 +461,18 @@ static efi_status_t EFIAPI efi_cout_set_attribute(
 }
 

lib/efi_loader/efi_console.c static efi_status_t EFIAPI efi_cout_set_attribute( · line 471

Quoted 10 lines
lib/efi_loader/efi_console.c +5 -1
 /**
- * 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;
+
+		/* Avoid overwriting previous outputs on streaming consoles */

Thanks for making the behavior configurable.

We cannot assume that the cursor is on the last line.

Assume that the cursor is on the first line. Then the screen will still be deleted.

Quoted 9 lines
Quoted 3 lines

Especially in GRUB the cursor often is in the upper half of the screen

The cursor should be moved to the right lower corner before scrolling.

Can do, though logging interactive menus was not in scope (and can't be solved this way anyway).

Jan

E.g. you can edit a menu entry in GRUB and press F10 and want to know what the entry looked like.

author
#5 lore raw

Re: [PATCH v4 1/2] efi_loader: Avoid overwriting previous outputs on console screen clearing

Quoted 71 lines · Heinrich Schuchardt

Am 18. Januar 2023 21:58:42 MEZ schrieb Jan Kiszka <[email protected]>:

Quoted 68 lines · Heinrich Schuchardt
Quoted 66 lines

Am 18. Januar 2023 21:44:58 MEZ schrieb Jan Kiszka <[email protected]>:

Quoted 43 lines

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 | 10 +++++++++-

2 files changed, 18 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 +0 -0
index 4d08dd3763a..e40c129d1b2 100644
@@ -461,10 +461,18 @@ static efi_status_t EFIAPI efi_cout_set_attribute(
 }
 

lib/efi_loader/efi_console.c static efi_status_t EFIAPI efi_cout_set_attribute( · line 471

Quoted 10 lines
lib/efi_loader/efi_console.c +5 -1
 /**
- * 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;
+
+		/* Avoid overwriting previous outputs on streaming consoles */

Thanks for making the behavior configurable.

We cannot assume that the cursor is on the last line.

Assume that the cursor is on the first line. Then the screen will still be deleted.

Especially in GRUB the cursor often is in the upper half of the screen

The cursor should be moved to the right lower corner before scrolling.

Quoted 9 lines
Quoted 5 lines

Can do, though logging interactive menus was not in scope (and can't be solved this way anyway).

Jan

E.g. you can edit a menu entry in GRUB and press F10 and want to know what the entry looked like.

Yes, that special case could be caught (not very relevant in embedded practice, though), but any change you did before that is likely not readably logged. That's why I don't consider interactive menus in scope here.

Nevertheless, patch update is under test now.

Jan

Signature · 2 lines
Siemens AG, Technology
Competence Center Embedded Linux