Skip to contentSkip to conversation

EFI: console: Do not set colorstate until the first text output

PATCH In review Hans de Goede 5 participants 10 messages Jan 28, 2022 – Mar 22, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 EFI: console: Do not set colorstate until the first text output

GRUB_MOD_INIT(normal) does an unconditional:

grub_env_set ("color_normal", "light-gray/black");

which triggers a grub_term_setcolorstate() call. The original version of the "efi/console: Do not set text-mode until we actually need it" patch:
https://lists.gnu.org/archive/html/grub-devel/2018-03/msg00125.html

Protected against this by caching the requested state in grub_console_setcolorstate () and then only applying it when the first text output actually happens. During refactoring to move the grub_console_setcolorstate () up higher in the grub-core/term/efi/console.c file the code to cache the color-state + bail early was accidentally dropped.

Restore the cache the color-state + bail early behavior from the original.

Cc Javier Martinez Canillas <[email protected]>
Fixes 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")
---
 grub-core/term/efi/console.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
grub-core/term/efi/console.c +10 -0
index 2f1ae85ba..c44b2ac31 100644
@@ -82,6 +82,16 @@ grub_console_setcolorstate (struct grub_term_output *term
 {
   grub_efi_simple_text_output_interface_t *o;
 
+  if (grub_efi_is_finished || text_mode != GRUB_TEXT_MODE_AVAILABLE)
+    {
+      /*
+       * Cache colorstate changes before the first text-output, this avoids
+       * "color_normal" environment writes causing a switch to textmode.
+       */
+      text_colorstate = state;
+      return;
+    }
+
   if (grub_efi_is_finished)
     return;
 
Signature · 1 line
2.33.1
#1 lore raw

PATCH 2/2 EFI: console: Do not set cursor until the first text output

To allow flickerfree boot the EFI console code does not call grub_efi_set_text_mode (1) until some text is actually output.

Depending on if the output text is because of an error loading e.g. the .cfg file; or because of showing the menu the cursor needs to be on or off when the first text is shown.

So far the cursor was hardcoded to being on, but this is causing drawing artifacts + slow drawing of the menu as reported here:
https://bugzilla.redhat.com/show_bug.cgi?id=1946969

Handle the cursorstate in the same way as the colorstate to fix this, when no text has been output yet, just cache the cursorstate and then use the last set value when the first text is output.

Fixes 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")
---
 grub-core/term/efi/console.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
grub-core/term/efi/console.c +16 -3
index c44b2ac31..a3622e4fe 100644
@@ -31,7 +31,15 @@ typedef enum {
 }
 grub_text_mode;
 
+typedef enum {
+    GRUB_CURSOR_MODE_UNDEFINED = -1,
+    GRUB_CURSOR_MODE_OFF = 0,
+    GRUB_CURSUR_MODE_ON
+}
+grub_cursor_mode;
+
 static grub_text_mode text_mode = GRUB_TEXT_MODE_UNDEFINED;
+static grub_cursor_mode cursor_mode = GRUB_CURSOR_MODE_UNDEFINED;
 static grub_term_color_state text_colorstate = GRUB_TERM_COLOR_UNDEFINED;
 
 static grub_uint32_t
@@ -119,8 +127,12 @@ grub_console_setcursor (struct grub_term_output *term __attribute__ ((unused)),
 {
   grub_efi_simple_text_output_interface_t *o;
 
-  if (grub_efi_is_finished)
-    return;
+  if (grub_efi_is_finished || text_mode != GRUB_TEXT_MODE_AVAILABLE)
+    {
+      /* Cache cursor changes before the first text-output */
+      cursor_mode = on;
+      return;
+    }
 
   o = grub_efi_system_table->con_out;
   efi_call_2 (o->enable_cursor, o, on);
@@ -143,7 +155,8 @@ grub_prepare_for_text_output (struct grub_term_output *term)
       return GRUB_ERR_BAD_DEVICE;
     }
 
-  grub_console_setcursor (term, 1);
+  if (cursor_mode != GRUB_CURSOR_MODE_UNDEFINED)
+    grub_console_setcursor (term, cursor_mode);
   if (text_colorstate != GRUB_TERM_COLOR_UNDEFINED)
     grub_console_setcolorstate (term, text_colorstate);
   text_mode = GRUB_TEXT_MODE_AVAILABLE;
Signature · 1 line
2.33.1
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] EFI: console: Do not set cursor until the first text output

Quoted 11 lines · Hans de Goede

To allow flickerfree boot the EFI console code does not call grub_efi_set_text_mode (1) until some text is actually output.

Depending on if the output text is because of an error loading e.g. the .cfg file; or because of showing the menu the cursor needs to be on or off when the first text is shown.

So far the cursor was hardcoded to being on, but this is causing drawing artifacts + slow drawing of the menu as reported here:
https://bugzilla.redhat.com/show_bug.cgi?id=1946969

Quoted 7 lines

Handle the cursorstate in the same way as the colorstate to fix this, when no text has been output yet, just cache the cursorstate and then use the last set value when the first text is output.

Fixes 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")

---

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
Reviewed-by
#3 lore raw

Re: [PATCH 2/2] EFI: console: Do not set cursor until the first text output

Quoted 16 lines · Javier Martinez Canillas
Quoted 15 lines · Hans de Goede

To allow flickerfree boot the EFI console code does not call grub_efi_set_text_mode (1) until some text is actually output.

Depending on if the output text is because of an error loading e.g. the .cfg file; or because of showing the menu the cursor needs to be on or off when the first text is shown.

So far the cursor was hardcoded to being on, but this is causing drawing artifacts + slow drawing of the menu as reported here:
https://bugzilla.redhat.com/show_bug.cgi?id=1946969

Handle the cursorstate in the same way as the colorstate to fix this, when no text has been output yet, just cache the cursorstate and then use the last set value when the first text is output.

Quoted 5 lines
Quoted 3 lines
Fixes 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")

---

Be well,
--Robbie

Reviewed-by on v1 1/2
#4 lore raw
In reply to Hans de Goede

Hello Hans,

Thanks for the patch.

Quoted 35 lines · Hans de Goede

GRUB_MOD_INIT(normal) does an unconditional:

grub_env_set ("color_normal", "light-gray/black");

which triggers a grub_term_setcolorstate() call. The original version of the "efi/console: Do not set text-mode until we actually need it" patch:
https://lists.gnu.org/archive/html/grub-devel/2018-03/msg00125.html

Protected against this by caching the requested state in grub_console_setcolorstate () and then only applying it when the first text output actually happens. During refactoring to move the grub_console_setcolorstate () up higher in the grub-core/term/efi/console.c file the code to cache the color-state + bail early was accidentally dropped.

Restore the cache the color-state + bail early behavior from the original.

Cc Javier Martinez Canillas <[email protected]>
Fixes 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")
---
 grub-core/term/efi/console.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
grub-core/term/efi/console.c +3 -0
index 2f1ae85ba..c44b2ac31 100644
@@ -82,6 +82,16 @@ grub_console_setcolorstate (struct grub_term_output *term
 {
   grub_efi_simple_text_output_interface_t *o;
 
+  if (grub_efi_is_finished || text_mode != GRUB_TEXT_MODE_AVAILABLE)
+    {
+      /*

grub-core/term/efi/console.c grub_console_setcolorstate (struct grub_term_output *term · line 97

Quoted 10 lines
grub-core/term/efi/console.c +7 -0
+       * Cache colorstate changes before the first text-output, this avoids
+       * "color_normal" environment writes causing a switch to textmode.
+       */
+      text_colorstate = state;
+      return;
+    }
+
   if (grub_efi_is_finished)
     return;
 

Indeed, sorry for messing this when addressing the concerns raised by Daniel in your original patch. The fix looks good to me.

Best regards,

Signature · 3 lines
Javier Martinez Canillas
Linux Engineering
Red Hat
Reviewed-by
#5 lore raw
Quoted 54 lines · Javier Martinez Canillas

Hello Hans,

Thanks for the patch.

Quoted 35 lines · Hans de Goede

GRUB_MOD_INIT(normal) does an unconditional:

grub_env_set ("color_normal", "light-gray/black");

which triggers a grub_term_setcolorstate() call. The original version of the "efi/console: Do not set text-mode until we actually need it" patch:
https://lists.gnu.org/archive/html/grub-devel/2018-03/msg00125.html

Protected against this by caching the requested state in grub_console_setcolorstate () and then only applying it when the first text output actually happens. During refactoring to move the grub_console_setcolorstate () up higher in the grub-core/term/efi/console.c file the code to cache the color-state + bail early was accidentally dropped.

Restore the cache the color-state + bail early behavior from the original.

Cc Javier Martinez Canillas <[email protected]>
Fixes 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")
---
 grub-core/term/efi/console.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
grub-core/term/efi/console.c +3 -0
index 2f1ae85ba..c44b2ac31 100644
@@ -82,6 +82,16 @@ grub_console_setcolorstate (struct grub_term_output *term
 {
   grub_efi_simple_text_output_interface_t *o;
 
+  if (grub_efi_is_finished || text_mode != GRUB_TEXT_MODE_AVAILABLE)
+    {
+      /*

grub-core/term/efi/console.c grub_console_setcolorstate (struct grub_term_output *term · line 97

Quoted 10 lines
grub-core/term/efi/console.c +7 -0
+       * Cache colorstate changes before the first text-output, this avoids
+       * "color_normal" environment writes causing a switch to textmode.
+       */
+      text_colorstate = state;
+      return;
+    }
+
   if (grub_efi_is_finished)
     return;
 

Indeed, sorry for messing this when addressing the concerns raised by Daniel in your original patch. The fix looks good to me.

Quoted 1 line

Be well,
--Robbie

author Reviewed-by Javier Martinez Canillas Reviewed-by Robbie Harwood on v1 1/2
#6 lore raw
In reply to Hans de Goede

Hi Daniel,

Quoted 15 lines · Hans de Goede

GRUB_MOD_INIT(normal) does an unconditional:

grub_env_set ("color_normal", "light-gray/black");

which triggers a grub_term_setcolorstate() call. The original version of the "efi/console: Do not set text-mode until we actually need it" patch:
https://lists.gnu.org/archive/html/grub-devel/2018-03/msg00125.html

Protected against this by caching the requested state in grub_console_setcolorstate () and then only applying it when the first text output actually happens. During refactoring to move the grub_console_setcolorstate () up higher in the grub-core/term/efi/console.c file the code to cache the color-state + bail early was accidentally dropped.

Quoted 5 lines

Restore the cache the color-state + bail early behavior from the original.

Cc Javier Martinez Canillas <[email protected]>
Fixes 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")

What is the status of this series? It has been well over a month and both patches have received 2 Reviewed-by-s and no other comments:

Regards,

Hans

Quoted 25 lines
---
 grub-core/term/efi/console.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
grub-core/term/efi/console.c +10 -0
index 2f1ae85ba..c44b2ac31 100644
@@ -82,6 +82,16 @@ grub_console_setcolorstate (struct grub_term_output *term
 {
   grub_efi_simple_text_output_interface_t *o;
 
+  if (grub_efi_is_finished || text_mode != GRUB_TEXT_MODE_AVAILABLE)
+    {
+      /*
+       * Cache colorstate changes before the first text-output, this avoids
+       * "color_normal" environment writes causing a switch to textmode.
+       */
+      text_colorstate = state;
+      return;
+    }
+
   if (grub_efi_is_finished)
     return;
 
#7 lore raw
Quoted 24 lines · Hans de Goede

Hi Daniel,

Quoted 15 lines · Hans de Goede

GRUB_MOD_INIT(normal) does an unconditional:

grub_env_set ("color_normal", "light-gray/black");

which triggers a grub_term_setcolorstate() call. The original version of the "efi/console: Do not set text-mode until we actually need it" patch:
https://lists.gnu.org/archive/html/grub-devel/2018-03/msg00125.html

Protected against this by caching the requested state in grub_console_setcolorstate () and then only applying it when the first text output actually happens. During refactoring to move the grub_console_setcolorstate () up higher in the grub-core/term/efi/console.c file the code to cache the color-state + bail early was accidentally dropped.

Quoted 5 lines

Restore the cache the color-state + bail early behavior from the original.

Cc Javier Martinez Canillas <[email protected]>
Fixes 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")
Quoted 5 lines

What is the status of this series? It has been well over a month and both patches have received 2 Reviewed-by-s and no other comments:

I will take a look at them in a week or two. Sorry for delay...

Daniel

Reviewed-by
#8 lore raw
In reply to Hans de Goede
Quoted 24 lines · Hans de Goede

Hi Daniel,

Quoted 15 lines · Hans de Goede

GRUB_MOD_INIT(normal) does an unconditional:

grub_env_set ("color_normal", "light-gray/black");

which triggers a grub_term_setcolorstate() call. The original version of the "efi/console: Do not set text-mode until we actually need it" patch:
https://lists.gnu.org/archive/html/grub-devel/2018-03/msg00125.html

Protected against this by caching the requested state in grub_console_setcolorstate () and then only applying it when the first text output actually happens. During refactoring to move the grub_console_setcolorstate () up higher in the grub-core/term/efi/console.c file the code to cache the color-state + bail early was accidentally dropped.

Quoted 5 lines

Restore the cache the color-state + bail early behavior from the original.

Cc Javier Martinez Canillas <[email protected]>
Fixes 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")
Quoted 5 lines

What is the status of this series? It has been well over a month and both patches have received 2 Reviewed-by-s and no other comments:

Daniel

#9 lore raw
In reply to Hans de Goede
Quoted 24 lines · Hans de Goede

Hi Daniel,

Quoted 15 lines · Hans de Goede

GRUB_MOD_INIT(normal) does an unconditional:

grub_env_set ("color_normal", "light-gray/black");

which triggers a grub_term_setcolorstate() call. The original version of the "efi/console: Do not set text-mode until we actually need it" patch:
https://lists.gnu.org/archive/html/grub-devel/2018-03/msg00125.html

Protected against this by caching the requested state in grub_console_setcolorstate () and then only applying it when the first text output actually happens. During refactoring to move the grub_console_setcolorstate () up higher in the grub-core/term/efi/console.c file the code to cache the color-state + bail early was accidentally dropped.

Quoted 5 lines

Restore the cache the color-state + bail early behavior from the original.

Cc Javier Martinez Canillas <[email protected]>
Fixes 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")
Quoted 5 lines

What is the status of this series? It has been well over a month and both patches have received 2 Reviewed-by-s and no other comments:

Argh... By mistake I forgot to add Javier's and Robbie's RB. Sorry about that...

Daniel