]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Add screen resolution to print status 22251/head
authorJan Janssen <medhefgo@web.de>
Wed, 26 Jan 2022 12:50:22 +0000 (13:50 +0100)
committerJan Janssen <medhefgo@web.de>
Wed, 26 Jan 2022 17:07:00 +0000 (18:07 +0100)
src/boot/efi/boot.c
src/boot/efi/console.c
src/boot/efi/console.h

index 57ca183cf338138102e0ed3fc90c11bcef090437..eed5bcc9610add3cbcb77e121a95537d10e26ddd 100644 (file)
@@ -438,6 +438,7 @@ static void ps_bool(const CHAR16 *fmt, BOOLEAN value) {
 static void print_status(Config *config, CHAR16 *loaded_image_path) {
         UINT64 key;
         UINTN x_max, y_max;
+        UINT32 screen_width = 0, screen_height = 0;
         SecureBootMode secure;
         _cleanup_freepool_ CHAR16 *device_part_uuid = NULL;
 
@@ -446,6 +447,7 @@ static void print_status(Config *config, CHAR16 *loaded_image_path) {
 
         clear_screen(COLOR_NORMAL);
         console_query_mode(&x_max, &y_max);
+        query_screen_resolution(&screen_width, &screen_height);
 
         secure = secure_boot_mode();
         (void) efivar_get(LOADER_GUID, L"LoaderDevicePartUUID", &device_part_uuid);
@@ -463,7 +465,7 @@ static void print_status(Config *config, CHAR16 *loaded_image_path) {
             Print(L"           secure boot: %s (%s)\n", yes_no(IN_SET(secure, SECURE_BOOT_USER, SECURE_BOOT_DEPLOYED)), secure_boot_mode_to_string(secure));
           ps_bool(L"                  shim: %s\n",      shim_loaded());
           ps_bool(L"                   TPM: %s\n",      tpm_present());
-            Print(L"          console mode: %d/%d (%lu x %lu)\n", ST->ConOut->Mode->Mode, ST->ConOut->Mode->MaxMode - 1LL, x_max, y_max);
+            Print(L"          console mode: %d/%d (%lux%lu @%ux%u)\n", ST->ConOut->Mode->Mode, ST->ConOut->Mode->MaxMode - 1LL, x_max, y_max, screen_width, screen_height);
 
         Print(L"\n--- Press any key to continue. ---\n\n");
         console_key_read(&key, UINT64_MAX);
index b8142c38b3f65e0adc20adad99358599f98c1743..3a0cf535e15c995e878b626057628febb545ca2d 100644 (file)
@@ -183,19 +183,32 @@ static EFI_STATUS change_mode(INT64 mode) {
         return err;
 }
 
-static INT64 get_auto_mode(void) {
-        EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
+EFI_STATUS query_screen_resolution(UINT32 *ret_w, UINT32 *ret_h) {
         EFI_STATUS err;
+        EFI_GRAPHICS_OUTPUT_PROTOCOL *go;
+
+        err = LibLocateProtocol(&GraphicsOutputProtocol, (void **) &go);
+        if (EFI_ERROR(err))
+                return err;
+
+        if (!go->Mode || !go->Mode->Info)
+                return EFI_DEVICE_ERROR;
+
+        *ret_w = go->Mode->Info->HorizontalResolution;
+        *ret_h = go->Mode->Info->VerticalResolution;
+        return EFI_SUCCESS;
+}
+
+static INT64 get_auto_mode(void) {
+        UINT32 screen_width, screen_height;
 
-        err = LibLocateProtocol(&GraphicsOutputProtocol, (void **)&GraphicsOutput);
-        if (!EFI_ERROR(err) && GraphicsOutput->Mode && GraphicsOutput->Mode->Info) {
-                EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info = GraphicsOutput->Mode->Info;
+        if (!EFI_ERROR(query_screen_resolution(&screen_width, &screen_height))) {
                 BOOLEAN keep = FALSE;
 
                 /* Start verifying if we are in a resolution larger than Full HD
                  * (1920x1080). If we're not, assume we're in a good mode and do not
                  * try to change it. */
-                if (Info->HorizontalResolution <= HORIZONTAL_MAX_OK && Info->VerticalResolution <= VERTICAL_MAX_OK)
+                if (screen_width <= HORIZONTAL_MAX_OK && screen_height <= VERTICAL_MAX_OK)
                         keep = TRUE;
                 /* For larger resolutions, calculate the ratio of the total screen
                  * area to the text viewport area. If it's less than 10 times bigger,
@@ -203,7 +216,7 @@ static INT64 get_auto_mode(void) {
                 else {
                         UINT64 text_area;
                         UINTN x_max, y_max;
-                        UINT64 screen_area = (UINT64)Info->HorizontalResolution * (UINT64)Info->VerticalResolution;
+                        UINT64 screen_area = (UINT64)screen_width * (UINT64)screen_height;
 
                         console_query_mode(&x_max, &y_max);
                         text_area = SYSTEM_FONT_WIDTH * SYSTEM_FONT_HEIGHT * (UINT64)x_max * (UINT64)y_max;
index 90086028c04142255822e13901048f66a08b8f00..c27c19b39fb53c983fb889b94bc440694f0f3cf2 100644 (file)
@@ -29,3 +29,4 @@ enum {
 EFI_STATUS console_key_read(UINT64 *key, UINT64 timeout_usec);
 EFI_STATUS console_set_mode(INT64 mode);
 EFI_STATUS console_query_mode(UINTN *x_max, UINTN *y_max);
+EFI_STATUS query_screen_resolution(UINT32 *ret_width, UINT32 *ret_height);