8a74d28
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
8a74d28
From: Hans de Goede <hdegoede@redhat.com>
8a74d28
Date: Fri, 28 Jan 2022 12:43:48 +0100
8a74d28
Subject: [PATCH] EFI: console: Do not set colorstate until the first text
8a74d28
 output
8a74d28
8a74d28
GRUB_MOD_INIT(normal) does an unconditional:
8a74d28
8a74d28
grub_env_set ("color_normal", "light-gray/black");
8a74d28
8a74d28
which triggers a grub_term_setcolorstate() call. The original version
8a74d28
of the "efi/console: Do not set text-mode until we actually need it" patch:
8a74d28
https://lists.gnu.org/archive/html/grub-devel/2018-03/msg00125.html
8a74d28
8a74d28
Protected against this by caching the requested state in
8a74d28
grub_console_setcolorstate () and then only applying it when the first
8a74d28
text output actually happens. During refactoring to move the
8a74d28
grub_console_setcolorstate () up higher in the grub-core/term/efi/console.c
8a74d28
file the code to cache the color-state + bail early was accidentally
8a74d28
dropped.
8a74d28
8a74d28
Restore the cache the color-state + bail early behavior from the original.
8a74d28
8a74d28
Cc: Javier Martinez Canillas <javierm@redhat.com>
8a74d28
Fixes: 2d7c3abd871f ("efi/console: Do not set text-mode until we actually need it")
8a74d28
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
8a74d28
---
8a74d28
 grub-core/term/efi/console.c | 10 ++++++++++
8a74d28
 1 file changed, 10 insertions(+)
8a74d28
8a74d28
diff --git a/grub-core/term/efi/console.c b/grub-core/term/efi/console.c
e622855
index 2f1ae85ba7..c44b2ac318 100644
8a74d28
--- a/grub-core/term/efi/console.c
8a74d28
+++ b/grub-core/term/efi/console.c
8a74d28
@@ -82,6 +82,16 @@ grub_console_setcolorstate (struct grub_term_output *term
8a74d28
 {
8a74d28
   grub_efi_simple_text_output_interface_t *o;
8a74d28
 
8a74d28
+  if (grub_efi_is_finished || text_mode != GRUB_TEXT_MODE_AVAILABLE)
8a74d28
+    {
8a74d28
+      /*
8a74d28
+       * Cache colorstate changes before the first text-output, this avoids
8a74d28
+       * "color_normal" environment writes causing a switch to textmode.
8a74d28
+       */
8a74d28
+      text_colorstate = state;
8a74d28
+      return;
8a74d28
+    }
8a74d28
+
8a74d28
   if (grub_efi_is_finished)
8a74d28
     return;
8a74d28