Skip to contentSkip to conversation

efi: Add efitextmode command for getting/setting the text mode resolution

PATCH In review Glenn Washburn 2 participants 6 messages Jul 22, 2022 – Aug 11, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 efi: Add efitextmode command for getting/setting the text mode resolution

This command is meant to behave similarly to the 'mode' command of the EFI Shell application. In addition to allowing mode selection by giving the number of columns and rows as arguments, the command allows specifying the mode number to select the mode. Also supported are the arguments "min" and "max", which set the mode to the minimum and maximum mode respectively as calculated by the columns * rows of that mode.

---
Updates since v2:
* Merge docs patch with this patch
* Allow specifying cols and rows to select mode
* Refactor
* Other changes suggested by Daniel

Glenn

---
 docs/grub.texi                       |  42 ++++++++
 grub-core/Makefile.core.def          |   6 ++
 grub-core/commands/efi/efitextmode.c | 156 +++++++++++++++++++++++++++
 include/grub/efi/api.h               |   6 ++
 include/grub/err.h                   |   3 +-
 5 files changed, 212 insertions(+), 1 deletion(-)
 create mode 100644 grub-core/commands/efi/efitextmode.c
docs/grub.texi +42 -0
index af119dea3..31194a0c7 100644
@@ -4238,6 +4238,7 @@ you forget a command, you can run the command @command{help}
 * distrust::                    Remove a pubkey from trusted keys
 * drivemap::                    Map a drive to another
 * echo::                        Display a line of text
+* efitextmode::                 Set/Get text output mode resolution
 * eval::                        Evaluate agruments as GRUB commands
 * export::                      Export an environment variable
 * false::                       Do nothing, unsuccessfully
@@ -4685,6 +4686,47 @@ character will print that character.
 @end deffn
 
 
+@node efitextmode
+@subsection efitextmode
+
+@deffn Command efitextmode [min | max | <mode_num> | <cols> <rows>]
+When used with no arguments displays all available text output modes. The
+set mode determines the columns and rows of the text display when in
+text mode. An asterisk, @samp{*}, will be at the end of the line of the
+currently set mode.
+
+If given a single parameter, it must be @samp{min}, @samp{max}, or a mode
+number given by the listing when run with no arguments. These arguments set
+the mode to the minimum, maximum, and particular mode respectively.
+
+Otherwise, the command must be given two numerical arguments specifying the
+columns and rows of the desired mode. Specifying a columns and rows
+combination that corresponds to no supported mode, will return error, but
+otherwise have no effect.
+
+By default GRUB will start in whatever mode the EFI firmware defaults to.
+There are firmwares known to set up the default mode such that output
+behaves strangely, for example the cursor in the grub shell never reaches
+the bottom of the screen or, when typing characters at the prompt,
+characters from previous command output are overwritten. Setting the mode
+may fix this.
+
+The EFI specification says that mode 0 is must be available and have
+columns and rows of 80 and 25 respectively. Mode 1 may be defined and if
+so must have columns and rows of 80 and 50 respectively. Any other modes
+may have columns and rows arbitrarily defined by the firmware. This means
+that a mode with columns and rows of 100 and 31 on one firmware may be a
+different mode number on a different firmware or not exist at all.
+Likewise, mode number 2 on one firmware may have a different number of
+columns and rows than mode 2 on a different firmware. So one should not
+rely on a particular mode number or a mode of a certain number of columns
+and rows existing on all firmwares, except for mode 0.
+
+Note: This command is only available on EFI platforms and is similar to
+EFI shell "mode" command.
+@end deffn
+
+
 @node eval
 @subsection eval
 
grub-core/Makefile.core.def +6 -0
index 715994872..5212dfab1 100644
@@ -813,6 +813,12 @@ module = {
   enable = efi;
 };
 
+module = {
+  name = efitextmode;
+  efi = commands/efi/efitextmode.c;
+  enable = efi;
+};
+
 module = {
   name = blocklist;
   common = commands/blocklist.c;
grub-core/commands/efi/efitextmode.c new file +156 -0

156 lines not on this page · raw message

include/grub/efi/api.h +6 -0
index d4cadd8b5..b1cd036f4 100644
@@ -536,9 +536,13 @@ typedef char grub_efi_boolean_t;
 #if GRUB_CPU_SIZEOF_VOID_P == 8
 typedef grub_int64_t grub_efi_intn_t;
 typedef grub_uint64_t grub_efi_uintn_t;
+#define PRIxGRUB_EFI_UINTN_T "lx"
+#define PRIuGRUB_EFI_UINTN_T "lu"
 #else
 typedef grub_int32_t grub_efi_intn_t;
 typedef grub_uint32_t grub_efi_uintn_t;
+#define PRIxGRUB_EFI_UINTN_T "x"
+#define PRIuGRUB_EFI_UINTN_T "u"
 #endif
 typedef grub_int8_t grub_efi_int8_t;
 typedef grub_uint8_t grub_efi_uint8_t;
@@ -546,6 +550,8 @@ typedef grub_int16_t grub_efi_int16_t;
 typedef grub_uint16_t grub_efi_uint16_t;
 typedef grub_int32_t grub_efi_int32_t;
 typedef grub_uint32_t grub_efi_uint32_t;
+#define PRIxGRUB_EFI_UINT32_T "x"
+#define PRIuGRUB_EFI_UINT32_T "u"
 typedef grub_int64_t grub_efi_int64_t;
 typedef grub_uint64_t grub_efi_uint64_t;
 typedef grub_uint8_t grub_efi_char8_t;
include/grub/err.h +2 -1
index b08d5d0de..1c07034cd 100644
@@ -72,7 +72,8 @@ typedef enum
     GRUB_ERR_NET_PACKET_TOO_BIG,
     GRUB_ERR_NET_NO_DOMAIN,
     GRUB_ERR_EOF,
-    GRUB_ERR_BAD_SIGNATURE
+    GRUB_ERR_BAD_SIGNATURE,
+    GRUB_ERR_BAD_FIRMWARE
   }
 grub_err_t;
 
Signature · 1 line
2.34.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 8 lines · Glenn Washburn

This command is meant to behave similarly to the 'mode' command of the EFI Shell application. In addition to allowing mode selection by giving the number of columns and rows as arguments, the command allows specifying the mode number to select the mode. Also supported are the arguments "min" and "max", which set the mode to the minimum and maximum mode respectively as calculated by the columns * rows of that mode.

I assume this patch evolved from earlier patch called "efi: Set text-mode console resolution to maximum supported" [1]. If that is true I will ignore it...

Thank you for adding this functionality.

Daniel

[1] https://lists.gnu.org/archive/html/grub-devel/2022-05/msg00029.html

#2 lore raw
Quoted 8 lines · On Tue, 2 Aug 2022 17:39:13 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 7 lines · Glenn Washburn

This command is meant to behave similarly to the 'mode' command of the EFI Shell application. In addition to allowing mode selection by giving the number of columns and rows as arguments, the command allows specifying the mode number to select the mode. Also supported are the arguments "min" and "max", which set the mode to the minimum and maximum mode respectively as calculated by the columns * rows of that mode.

Quoted 6 lines
Quoted 1 line

I assume this patch evolved from earlier patch called "efi: Set text-mode console resolution to maximum supported" [1]. If that is true I will ignore it...

Yes, that patch can be ignored.

Glenn

Quoted 6 lines

Thank you for adding this functionality.

Daniel

[1] https://lists.gnu.org/archive/html/grub-devel/2022-05/msg00029.html

#3 lore raw
Quoted 11 lines · Glenn Washburn
Quoted 8 lines · On Tue, 2 Aug 2022 17:39:13 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 7 lines · Glenn Washburn

This command is meant to behave similarly to the 'mode' command of the EFI Shell application. In addition to allowing mode selection by giving the number of columns and rows as arguments, the command allows specifying the mode number to select the mode. Also supported are the arguments "min" and "max", which set the mode to the minimum and maximum mode respectively as calculated by the columns * rows of that mode.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I assume this patch evolved from earlier patch called "efi: Set text-mode console resolution to maximum supported" [1]. If that is true I will ignore it...

Yes, that patch can be ignored.

Cool! Thanks!

Daniel

#4 lore raw
In reply to Daniel Kiper
Quoted 11 lines · Daniel Kiper
Quoted 8 lines · Glenn Washburn

This command is meant to behave similarly to the 'mode' command of the EFI Shell application. In addition to allowing mode selection by giving the number of columns and rows as arguments, the command allows specifying the mode number to select the mode. Also supported are the arguments "min" and "max", which set the mode to the minimum and maximum mode respectively as calculated by the columns * rows of that mode.

I had to add the following fix on top of your patch.

include/grub/efi/api.h +6 -6
index b1cd036f4..1ef404622 100644
@@ -536,13 +536,13 @@ typedef char grub_efi_boolean_t;
 #if GRUB_CPU_SIZEOF_VOID_P == 8
 typedef grub_int64_t grub_efi_intn_t;
 typedef grub_uint64_t grub_efi_uintn_t;
-#define PRIxGRUB_EFI_UINTN_T "lx"
-#define PRIuGRUB_EFI_UINTN_T "lu"
+#define PRIxGRUB_EFI_UINTN_T	PRIxGRUB_UINT64_T
+#define PRIuGRUB_EFI_UINTN_T	PRIuGRUB_UINT64_T
 #else
 typedef grub_int32_t grub_efi_intn_t;
 typedef grub_uint32_t grub_efi_uintn_t;
-#define PRIxGRUB_EFI_UINTN_T "x"
-#define PRIuGRUB_EFI_UINTN_T "u"
+#define PRIxGRUB_EFI_UINTN_T	PRIxGRUB_UINT32_T
+#define PRIuGRUB_EFI_UINTN_T	PRIuGRUB_UINT32_T
 #endif
 typedef grub_int8_t grub_efi_int8_t;
 typedef grub_uint8_t grub_efi_uint8_t;
@@ -550,8 +550,8 @@ typedef grub_int16_t grub_efi_int16_t;
 typedef grub_uint16_t grub_efi_uint16_t;
 typedef grub_int32_t grub_efi_int32_t;
 typedef grub_uint32_t grub_efi_uint32_t;
-#define PRIxGRUB_EFI_UINT32_T "x"
-#define PRIuGRUB_EFI_UINT32_T "u"
+#define PRIxGRUB_EFI_UINT32_T	PRIxGRUB_UINT32_T
+#define PRIuGRUB_EFI_UINT32_T	PRIuGRUB_UINT32_T
 typedef grub_int64_t grub_efi_int64_t;
 typedef grub_uint64_t grub_efi_uint64_t;
 typedef grub_uint8_t grub_efi_char8_t;

Otherwise one of Windows builds has been broken.

Daniel

#5 lore raw
Quoted 49 lines · On Wed, 10 Aug 2022 15:55:52 +0200 Daniel Kiper <[email protected]> wrote:
Quoted 11 lines · Daniel Kiper
Quoted 8 lines · Glenn Washburn

This command is meant to behave similarly to the 'mode' command of the EFI Shell application. In addition to allowing mode selection by giving the number of columns and rows as arguments, the command allows specifying the mode number to select the mode. Also supported are the arguments "min" and "max", which set the mode to the minimum and maximum mode respectively as calculated by the columns * rows of that mode.

I had to add the following fix on top of your patch.

include/grub/efi/api.h +6 -6
index b1cd036f4..1ef404622 100644
@@ -536,13 +536,13 @@ typedef char grub_efi_boolean_t;
 #if GRUB_CPU_SIZEOF_VOID_P == 8
 typedef grub_int64_t grub_efi_intn_t;
 typedef grub_uint64_t grub_efi_uintn_t;
-#define PRIxGRUB_EFI_UINTN_T "lx"
-#define PRIuGRUB_EFI_UINTN_T "lu"
+#define PRIxGRUB_EFI_UINTN_T	PRIxGRUB_UINT64_T
+#define PRIuGRUB_EFI_UINTN_T	PRIuGRUB_UINT64_T
 #else
 typedef grub_int32_t grub_efi_intn_t;
 typedef grub_uint32_t grub_efi_uintn_t;
-#define PRIxGRUB_EFI_UINTN_T "x"
-#define PRIuGRUB_EFI_UINTN_T "u"
+#define PRIxGRUB_EFI_UINTN_T	PRIxGRUB_UINT32_T
+#define PRIuGRUB_EFI_UINTN_T	PRIuGRUB_UINT32_T
 #endif
 typedef grub_int8_t grub_efi_int8_t;
 typedef grub_uint8_t grub_efi_uint8_t;
@@ -550,8 +550,8 @@ typedef grub_int16_t grub_efi_int16_t;
 typedef grub_uint16_t grub_efi_uint16_t;
 typedef grub_int32_t grub_efi_int32_t;
 typedef grub_uint32_t grub_efi_uint32_t;
-#define PRIxGRUB_EFI_UINT32_T "x"
-#define PRIuGRUB_EFI_UINT32_T "u"
+#define PRIxGRUB_EFI_UINT32_T	PRIxGRUB_UINT32_T
+#define PRIuGRUB_EFI_UINT32_T	PRIuGRUB_UINT32_T
 typedef grub_int64_t grub_efi_int64_t;
 typedef grub_uint64_t grub_efi_uint64_t;
 typedef grub_uint8_t grub_efi_char8_t;
Quoted 1 line

Otherwise one of Windows builds has been broken.

Ok, thanks. I didn't check windows builds.

Glenn