]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: Introduce log_wait
authorJan Janssen <medhefgo@web.de>
Sun, 5 Jun 2022 11:19:21 +0000 (13:19 +0200)
committerJan Janssen <medhefgo@web.de>
Wed, 18 Jan 2023 15:50:04 +0000 (16:50 +0100)
Instead of stalling for every log message as it appears we now wait for
several messages at strategic locations.

src/boot/efi/boot.c
src/boot/efi/console.c
src/boot/efi/graphics.c
src/boot/efi/linux.c
src/boot/efi/linux_x86.c
src/boot/efi/log.c
src/boot/efi/log.h
src/boot/efi/stub.c
src/boot/efi/util.c

index 7d0bc2ef1124b75f90a27cca9b097a9686074346..98c49e96cec51c501bf503f9d0f797f9b294fa43 100644 (file)
@@ -2626,7 +2626,7 @@ static EFI_STATUS discover_root_dir(EFI_LOADED_IMAGE_PROTOCOL *loaded_image, EFI
                 return open_volume(loaded_image->DeviceHandle, ret_dir);
 }
 
-EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
+static EFI_STATUS real_main(EFI_HANDLE image) {
         EFI_LOADED_IMAGE_PROTOCOL *loaded_image;
         _cleanup_(file_closep) EFI_FILE *root_dir = NULL;
         _cleanup_(config_free) Config config = {};
@@ -2635,11 +2635,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         uint64_t init_usec;
         bool menu = false;
 
-        InitializeLib(image, sys_table);
         init_usec = time_usec();
-        debug_hook(L"systemd-boot");
-        /* Uncomment the next line if you need to wait for debugger. */
-        // debug_break();
 
         err = BS->OpenProtocol(image,
                         &LoadedImageProtocol,
@@ -2728,3 +2724,15 @@ out:
         BS->CloseProtocol(image, &LoadedImageProtocol, image, NULL);
         return err;
 }
+
+EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
+        InitializeLib(image, sys_table);
+
+        debug_hook(L"systemd-boot");
+        /* Uncomment the next line if you need to wait for debugger. */
+        // debug_break();
+
+        EFI_STATUS err = real_main(image);
+        log_wait();
+        return err;
+}
index 6d77d13ca4af9944e0ff0d1d19a8586dbd60d4c2..2e5c857b04d4e3a2859730d0d44ac76e9d2412e4 100644 (file)
@@ -172,6 +172,7 @@ static EFI_STATUS change_mode(int64_t mode) {
         mode = CLAMP(mode, CONSOLE_MODE_RANGE_MIN, CONSOLE_MODE_RANGE_MAX);
         old_mode = MAX(CONSOLE_MODE_RANGE_MIN, ST->ConOut->Mode->Mode);
 
+        log_wait();
         err = ST->ConOut->SetMode(ST->ConOut, mode);
         if (err == EFI_SUCCESS)
                 return EFI_SUCCESS;
index dc646bce1f2293da6e75b62222434b741e6dac9f..350d1bc4347ed21c023a9930037650b11e8b0f4f 100644 (file)
@@ -25,16 +25,17 @@ EFI_STATUS graphics_mode(bool on) {
                 return err == EFI_NOT_FOUND ? EFI_SUCCESS : err;
 
         /* check current mode */
-        err =ConsoleControl->GetMode(ConsoleControl, &current, &uga_exists, &stdin_locked);
+        err = ConsoleControl->GetMode(ConsoleControl, &current, &uga_exists, &stdin_locked);
         if (err != EFI_SUCCESS)
                 return err;
 
         /* do not touch the mode */
-        new  = on ? EfiConsoleControlScreenGraphics : EfiConsoleControlScreenText;
+        new = on ? EfiConsoleControlScreenGraphics : EfiConsoleControlScreenText;
         if (new == current)
                 return EFI_SUCCESS;
 
-        err =ConsoleControl->SetMode(ConsoleControl, new);
+        log_wait();
+        err = ConsoleControl->SetMode(ConsoleControl, new);
 
         /* some firmware enables the cursor when switching modes */
         ST->ConOut->EnableCursor(ST->ConOut, false);
index 2ae68ec2959cbcbe8fe88e7a1e3f1f47bc677ddd..727e5071015f1f78e8c35491898eff48deb4524d 100644 (file)
@@ -142,6 +142,7 @@ EFI_STATUS linux_exec(
         if (err != EFI_SUCCESS)
                 return log_error_status(err, "Error registering initrd: %m");
 
+        log_wait();
         err = BS->StartImage(kernel_image, NULL, NULL);
 
         /* Try calling the kernel compat entry point if one exists. */
index cbd92201b65f0706cbae1c1a8c876b16fbc19d51..eaae988d975579fad441843abf376aad264a9425 100644 (file)
@@ -209,6 +209,7 @@ EFI_STATUS linux_exec_efi_handover(
         boot_params->hdr.ramdisk_size = initrd_length;
         boot_params->ext_ramdisk_size = ((uint64_t) initrd_length) >> 32;
 
+        log_wait();
         linux_efi_handover(parent, (uintptr_t) linux_buffer, boot_params);
         return EFI_LOAD_ERROR;
 }
index 38e7c5a8a89fdd52714cbc0a0eeccd39c9db8b7d..b1a613e4e5981ae5739ffd4738fa8dee94ee497a 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "log.h"
 
+static unsigned log_count = 0;
+
 void efi_assert(const char *expr, const char *file, unsigned line, const char *function) {
         log_error("systemd-boot assertion '%s' failed at %s:%u@%s. Halting.", expr, file, line, function);
         for (;;)
@@ -28,7 +30,14 @@ EFI_STATUS log_internal(EFI_STATUS status, const char *format, ...) {
         ST->ConOut->OutputString(ST->ConOut, (char16_t *) u"\r\n");
         ST->ConOut->SetAttribute(ST->ConOut, attr);
 
-        /* Give the user a chance to see the message. */
-        BS->Stall(3 * 1000 * 1000);
+        log_count++;
         return status;
 }
+
+void log_wait(void) {
+        if (log_count == 0)
+                return;
+
+        BS->Stall(MIN(4u, log_count) * 2500 * 1000);
+        log_count = 0;
+}
index c6e8d626ce3a8de5f9404209a32e17cb84a27985..f24034fd7897c4ab4fa26bf87a0a9c389870e920 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "efi-string.h"
 
+void log_wait(void);
 _gnu_printf_(2, 3) EFI_STATUS log_internal(EFI_STATUS status, const char *format, ...);
 #define log_error_status(status, ...) log_internal(status, __VA_ARGS__)
 #define log_error(...) log_internal(EFI_INVALID_PARAMETER, __VA_ARGS__)
index 4f627e9a667b430786fcf5c8dd5bdae11b5abb26..bb647f1d78d925a9798de207dd9e53ce400308f4 100644 (file)
@@ -180,7 +180,7 @@ static bool use_load_options(
         return true;
 }
 
-EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
+static EFI_STATUS real_main(EFI_HANDLE image) {
         _cleanup_free_ void *credential_initrd = NULL, *global_credential_initrd = NULL, *sysext_initrd = NULL, *pcrsig_initrd = NULL, *pcrpkey_initrd = NULL;
         size_t credential_initrd_size = 0, global_credential_initrd_size = 0, sysext_initrd_size = 0, pcrsig_initrd_size = 0, pcrpkey_initrd_size = 0;
         size_t linux_size, initrd_size, dt_size;
@@ -194,11 +194,6 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         uint64_t loader_features = 0;
         EFI_STATUS err;
 
-        InitializeLib(image, sys_table);
-        debug_hook(L"systemd-stub");
-        /* Uncomment the next line if you need to wait for debugger. */
-        // debug_break();
-
         err = BS->OpenProtocol(
                         image,
                         &LoadedImageProtocol,
@@ -421,3 +416,15 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         graphics_mode(false);
         return err;
 }
+
+EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
+        InitializeLib(image, sys_table);
+
+        debug_hook(L"systemd-stub");
+        /* Uncomment the next line if you need to wait for debugger. */
+        // debug_break();
+
+        EFI_STATUS err = real_main(image);
+        log_wait();
+        return err;
+}
index e9267be575df23d842849151886a512ccf2f5147..86bc9cb543b8941dac0d3e466e48f5bd473cc672 100644 (file)
@@ -347,6 +347,7 @@ void print_at(UINTN x, UINTN y, UINTN attr, const char16_t *str) {
 }
 
 void clear_screen(UINTN attr) {
+        log_wait();
         ST->ConOut->SetAttribute(ST->ConOut, attr);
         ST->ConOut->ClearScreen(ST->ConOut);
 }