Skip to contentSkip to conversation

Fix screen coud be filled with leftover artifacts

PATCH In review Michael Chang via Grub-devel 2 participants 4 messages Oct 3, 2024 – Oct 4, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix screen coud be filled with leftover artifacts

A regression in grub 2.12 causes the grub screen to become cluttered with artifacts from the previous screen, whether it's the UEFI post ui, UEFI shell, or any graphical UI running before grub. this issue occurs in situations like booting grub from the UEFI shell and going straight to the rescue or command shell, causing visual discomfort.

The regression was introduced by commit 2d7c3abd8 (efi/console: Do not set text-mode until it is actually needed). To address the screen flickering issue, this commit suppresses the text-mode setting until the first output is requested. Before text-mode is set, any attempt to clear the screen has no effect. This inactive period renders the clear screen ineffective in early boot stages, potentially leaving leftover artifacts that will clutter the grub console display, as there is no guarantee there will always be a clear screen after the first output.

The issue is fixed by ensuring grub_console_cls() to work through lazy mode-setting, while also avoiding screen clearing for the hidden menu, which the flicker-free patch aims to improve.

Fixes 2d7c3abd8 (efi/console: Do not set text-mode until we actually need it)
---
 grub-core/normal/menu.c      | 7 ++++---
 grub-core/term/efi/console.c | 2 +-
 2 files changed, 5 insertions(+), 4 deletions(-)
grub-core/normal/menu.c +4 -3
index 6a90e091f..f24544b27 100644
@@ -881,13 +881,14 @@ show_menu (grub_menu_t menu, int nested, int autobooted)
       if (! e)
 	continue; /* Menu is empty.  */
 
-      grub_cls ();
-
       if (auto_boot)
 	grub_menu_execute_with_fallback (menu, e, autobooted,
 					 &execution_callback, &notify_boot);
       else
-	grub_menu_execute_entry (e, 0);
+	{
+	  grub_cls ();
+	  grub_menu_execute_entry (e, 0);
+	}
       if (autobooted)
 	break;
     }
grub-core/term/efi/console.c +1 -1
index bb587f39d..258b52737 100644
@@ -432,7 +432,7 @@ grub_console_cls (struct grub_term_output *term __attribute__ ((unused)))
   grub_efi_simple_text_output_interface_t *o;
   grub_efi_int32_t orig_attr;
 
-  if (grub_efi_is_finished || text_mode != GRUB_TEXT_MODE_AVAILABLE)
+  if (grub_prepare_for_text_output (term) != GRUB_ERR_NONE)
     return;
 
   o = grub_efi_system_table->con_out;
Signature · 7 lines
2.46.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by on v1 1/1
#1 lore raw
Quoted 15 lines · Michael Chang via Grub-devel

A regression in grub 2.12 causes the grub screen to become cluttered with artifacts from the previous screen, whether it's the UEFI post ui, UEFI shell, or any graphical UI running before grub. this issue occurs in situations like booting grub from the UEFI shell and going straight to the rescue or command shell, causing visual discomfort.

The regression was introduced by commit 2d7c3abd8 (efi/console: Do not set text-mode until it is actually needed). To address the screen flickering issue, this commit suppresses the text-mode setting until the first output is requested. Before text-mode is set, any attempt to clear the screen has no effect. This inactive period renders the clear screen ineffective in early boot stages, potentially leaving leftover artifacts that will clutter the grub console display, as there is no guarantee there will always be a clear screen after the first output.

Quoted 6 lines

The issue is fixed by ensuring grub_console_cls() to work through lazy mode-setting, while also avoiding screen clearing for the hidden menu, which the flicker-free patch aims to improve.

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

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
In reply to Michael Chang via Grub-devel

---- On Thu, 03 Oct 2024 11:23:08 +0400 Michael Chang via Grub-devel wrote ---

Quoted 1 line

A regression in grub 2.12 causes the grub screen to become cluttered

I just tested. Your patch doesn't fix anything for me!

(Note: I'm not GRUB developer, I'm just a user.)

Hi. I'm annoyed by screen cluttering, too. So I applied this patch to see whether this will help. Unfortunately, it did not.

Here is my test setup: I boot GRUB x86_64-efi in Qemu. My grub.cfg is so:
****
echo "This is /EFI/debian/grub.cfg from main file system (iso9660)" echo "Testing shows that this file is loaded during UEFI-CD" sleep 10
****

As you can see, my grub.cfg does "sleep 10" before GRUB command line. Also, note that there is no any "menuentry". So, menu is not shown.

Okay, so what happens?

Both with your patch and without your patch the following happens: I see message "This is /EFI/debian/grub.cfg from..." on screen with artifacts, then, after 10 seconds I switch to GRUB command line without artifacts.

So, yes, artifacts are not present at GRUB command line screen, but they ARE present (both with and without your patch) before we switch to GRUB command line.

Now let me describe my exact setup for testing this.

I checked out GRUB's master branch. Then I compiled it so (both with and without your branch) (in debian sid x86_64 docker):

***
./bootstrap
./configure --prefix=/opt/grub --with-platform=efi make
make install
***

Note that freshly built GRUB got to /opt/grub.

Then I built ".efi" file so (inside debian sid x86_64 docker):

***
/opt/grub/bin/grub-mkimage -O x86_64-efi -o /tmp/grub.efi -d /opt/grub/lib/grub/x86_64-efi -p /EFI/debian all_video boot cat configfile echo fat font gfxmenu gfxterm gfxterm_background help iso9660 loadenv ls memdisk minicmd normal part_msdos part_gpt regexp search sleep test true video
***

Then I built ".iso" file by this script (inside debian sid x86_64 docker):
***
#!/bin/bash
# This script creates isohybrid disk, which supports UEFI booting # The disk can be used both as CD image and as USB disk image # So, in total 2 boot modes are supported: UEFI-CD and UEFI-USB {
# This is just boilerplate I insert to all my bash scripts set -e
set -u
set -o pipefail
shopt -s inherit_errexit
shopt -s nullglob
export LC_ALL=C.UTF-8

  if [ $# != 1 ]; then
    echo "Usage: ${0##*/} OUT" >&2
    exit 1
  fi

OUT="$1"

  DIR="$(mktemp -d /tmp/grub-XXXXXX)"

mkdir -p "$DIR/esp/EFI/boot" "$DIR/esp/EFI/debian" "$DIR/main-root/EFI/debian" "$DIR/main-root/boot/grub"
wget -O "$DIR/esp/EFI/boot/bootx64.efi" 'https://sources.debian.org/src/shim-signed/latest/shimx64.efi.signed/' mv /tmp/grub.efi "$DIR/esp/EFI/boot/grubx64.efi"
cat << "EOF" > "$DIR/esp/EFI/debian/grub.cfg"
echo "This is /EFI/debian/grub.cfg from ESP"
echo "Testing shows that this file is loaded during UEFI-USB"
sleep 10
EOF
mkfs.vfat -C "$DIR/main-root/boot/grub/efi.img" 10000
mcopy -s -i "$DIR/main-root/boot/grub/efi.img" "$DIR/esp/EFI" ::/
cat << "EOF" > "$DIR/main-root/EFI/debian/grub.cfg"
echo "This is /EFI/debian/grub.cfg from main file system (iso9660)"
echo "Testing shows that this file is loaded during UEFI-CD"
sleep 10
EOF
# I don't know why this "$DIR/main-root/zero" is needed. Anyway this is just a demo
dd if=/dev/zero of="$DIR/main-root/zero" bs=1M count=1
xorriso -as mkisofs -b /zero -no-emul-boot --efi-boot /boot/grub/efi.img -efi-boot-part --efi-boot-image -o "$OUT" -r "$DIR/main-root" rm -r "$DIR"
exit 0
}
***

Then I booted resulting .iso file in Qemu running on my host (debian bookworm x86_64) by this command:
***
qemu-system-x86_64 -enable-kvm -m 4096 -bios OVMF.fd -cdrom /tmp/dx/o.iso
***

Then in Qemu I saw text "This is /EFI/debian/grub.cfg from..." AND artifacts. Then, after 10 seconds I saw GRUB command line without artifacts. All these happened both with and without your patch, i. e. your patch doesn't fix anything for me.

--
Askar Safin
https://types.pl/@safinaskar

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#3 lore raw
Quoted 4 lines · Askar Safin

---- On Thu, 03 Oct 2024 11:23:08 +0400 Michael Chang via Grub-devel wrote ---

Quoted 1 line

A regression in grub 2.12 causes the grub screen to become cluttered

I just tested. Your patch doesn't fix anything for me!

Thank you for sharing the report. Let me try to explain what happened here.

Quoted 13 lines

(Note: I'm not GRUB developer, I'm just a user.)

Hi. I'm annoyed by screen cluttering, too. So I applied this patch to see whether this will help. Unfortunately, it did not.

Here is my test setup: I boot GRUB x86_64-efi in Qemu. My grub.cfg is so:
****
echo "This is /EFI/debian/grub.cfg from main file system (iso9660)" echo "Testing shows that this file is loaded during UEFI-CD" sleep 10
****

Quoted 5 lines

As you can see, my grub.cfg does "sleep 10" before GRUB command line. Also, note that there is no any "menuentry". So, menu is not shown.

Okay, so what happens?

Both with your patch and without your patch the following happens: I see message "This is /EFI/debian/grub.cfg from..." on screen with artifacts, then, after 10 seconds I switch to GRUB command line without artifacts.

To maintain the integrity of the flicker-free implementation, we cannot enforce a universal clear screen to clean up any leftover artifacts at the start. Therefore, if this doesn't occur automatically, you may need to manually clear the screen by explicitly using the clear command, as shown below:

****
clear
echo "This is /EFI/debian/grub.cfg from main file system (iso9660)" echo "Testing shows that this file is loaded during UEFI-CD" sleep 10
****

Please note that the clear command above will not work if you are testing without the patch, as there is an inactive period for any screen clearing attempts before text output occurs.

Quoted 2 lines

So, yes, artifacts are not present at GRUB command line screen, but they ARE present (both with and without your patch) before we switch to GRUB command line.

You won’t notice a difference because some text is output before falling into the grub command line (CLI). As part of the flicker-less patch, the text output reinstates the clear function, allowing the screen to clear properly before entering the CLI by itself.

However, the issue I encountered was that no text was output before entering the CLI. As a result, all the screen clearing done at the code level before the CLI didn’t take effect, leading to a cluttered screen. This is what the patch is intended to deal with.

I hope this clarifies the issue a bit.

Thanks,
Michael

Quoted 72 lines

Now let me describe my exact setup for testing this.

I checked out GRUB's master branch. Then I compiled it so (both with and without your branch) (in debian sid x86_64 docker):

***
./bootstrap
./configure --prefix=/opt/grub --with-platform=efi make
make install
***

Note that freshly built GRUB got to /opt/grub.

Then I built ".efi" file so (inside debian sid x86_64 docker):

***
/opt/grub/bin/grub-mkimage -O x86_64-efi -o /tmp/grub.efi -d /opt/grub/lib/grub/x86_64-efi -p /EFI/debian all_video boot cat configfile echo fat font gfxmenu gfxterm gfxterm_background help iso9660 loadenv ls memdisk minicmd normal part_msdos part_gpt regexp search sleep test true video
***

Then I built ".iso" file by this script (inside debian sid x86_64 docker):
***
#!/bin/bash
# This script creates isohybrid disk, which supports UEFI booting # The disk can be used both as CD image and as USB disk image # So, in total 2 boot modes are supported: UEFI-CD and UEFI-USB {
# This is just boilerplate I insert to all my bash scripts set -e
set -u
set -o pipefail
shopt -s inherit_errexit
shopt -s nullglob
export LC_ALL=C.UTF-8

  if [ $# != 1 ]; then
    echo "Usage: ${0##*/} OUT" >&2
    exit 1
  fi

OUT="$1"

  DIR="$(mktemp -d /tmp/grub-XXXXXX)"

mkdir -p "$DIR/esp/EFI/boot" "$DIR/esp/EFI/debian" "$DIR/main-root/EFI/debian" "$DIR/main-root/boot/grub"
wget -O "$DIR/esp/EFI/boot/bootx64.efi" 'https://sources.debian.org/src/shim-signed/latest/shimx64.efi.signed/' mv /tmp/grub.efi "$DIR/esp/EFI/boot/grubx64.efi"
cat << "EOF" > "$DIR/esp/EFI/debian/grub.cfg"
echo "This is /EFI/debian/grub.cfg from ESP"
echo "Testing shows that this file is loaded during UEFI-USB"
sleep 10
EOF
mkfs.vfat -C "$DIR/main-root/boot/grub/efi.img" 10000
mcopy -s -i "$DIR/main-root/boot/grub/efi.img" "$DIR/esp/EFI" ::/
cat << "EOF" > "$DIR/main-root/EFI/debian/grub.cfg"
echo "This is /EFI/debian/grub.cfg from main file system (iso9660)"
echo "Testing shows that this file is loaded during UEFI-CD"
sleep 10
EOF
# I don't know why this "$DIR/main-root/zero" is needed. Anyway this is just a demo
dd if=/dev/zero of="$DIR/main-root/zero" bs=1M count=1
xorriso -as mkisofs -b /zero -no-emul-boot --efi-boot /boot/grub/efi.img -efi-boot-part --efi-boot-image -o "$OUT" -r "$DIR/main-root" rm -r "$DIR"
exit 0
}
***

Then I booted resulting .iso file in Qemu running on my host (debian bookworm x86_64) by this command:
***
qemu-system-x86_64 -enable-kvm -m 4096 -bios OVMF.fd -cdrom /tmp/dx/o.iso
***

Quoted 7 lines

Then in Qemu I saw text "This is /EFI/debian/grub.cfg from..." AND artifacts. Then, after 10 seconds I saw GRUB command line without artifacts. All these happened both with and without your patch, i. e. your patch doesn't fix anything for me.

--
Askar Safin
https://types.pl/@safinaskar

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel