chiark / gitweb /
boot: efi - support embedded splash image
[elogind.git] / src / boot / efi / boot.c
index 7605c6532d58bb23a19acf9f9856872357505c76..8bdc7f8c63f35aaec9b239783de08cea76c11f04 100644 (file)
@@ -65,8 +65,6 @@ typedef struct {
         UINTN timeout_sec_config;
         INTN timeout_sec_efivar;
         CHAR16 *entry_default_pattern;
-        CHAR16 *splash;
-        EFI_GRAPHICS_OUTPUT_BLT_PIXEL *background;
         CHAR16 *entry_oneshot;
         CHAR16 *options_edit;
         CHAR16 *entries_auto;
@@ -366,46 +364,12 @@ static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_imag
         UINTN size;
         EFI_STATUS err;
         UINTN color = 0;
-        const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *pixel = config->background;
+        const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *pixel = NULL;
 
         uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);
         uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
 
-        /* show splash and wait for key */
-        for (;;) {
-                static const EFI_GRAPHICS_OUTPUT_BLT_PIXEL colors[] = {
-                        { .Red = 0xff, .Green = 0xff, .Blue = 0xff },
-                        { .Red = 0xc0, .Green = 0xc0, .Blue = 0xc0 },
-                        { .Red = 0xff, .Green =    0, .Blue =    0 },
-                        { .Red =    0, .Green = 0xff, .Blue =    0 },
-                        { .Red =    0, .Green =    0, .Blue = 0xff },
-                        { .Red =    0, .Green =    0, .Blue =    0 },
-                };
-
-                err = EFI_NOT_FOUND;
-                if (config->splash)
-                        err = graphics_splash(root_dir, config->splash, pixel);
-                if (EFI_ERROR(err))
-                        err = graphics_splash(root_dir, L"\\EFI\\systemd\\splash.bmp", pixel);
-                if (EFI_ERROR(err))
-                        break;
-
-                /* 'b' rotates through background colors */
-                console_key_read(&key, TRUE);
-                if (key == KEYPRESS(0, 0, 'b')) {
-                        pixel = &colors[color++];
-                        if (color == ELEMENTSOF(colors))
-                                color = 0;
-
-                        continue;
-                }
-
-                graphics_mode(FALSE);
-                uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
-                break;
-        }
-
-        Print(L"systemd-boot version:        " VERSION "\n");
+        Print(L"systemd-boot version:   " VERSION "\n");
         Print(L"architecture:           " EFI_MACHINE_TYPE_NAME "\n");
         Print(L"loaded image:           %s\n", loaded_image_path);
         Print(L"UEFI specification:     %d.%02d\n", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
@@ -437,13 +401,6 @@ static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_imag
         Print(L"timeout (config):       %d\n", config->timeout_sec_config);
         if (config->entry_default_pattern)
                 Print(L"default pattern:        '%s'\n", config->entry_default_pattern);
-        if (config->splash)
-                Print(L"splash                  '%s'\n", config->splash);
-        if (config->background)
-                Print(L"background              '#%02x%02x%02x'\n",
-                      config->background->Red,
-                      config->background->Green,
-                      config->background->Blue);
         Print(L"\n");
 
         Print(L"config entry count:     %d\n", config->entry_count);
@@ -481,11 +438,38 @@ static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_imag
                 entry = config->entries[i];
 
                 if (entry->splash) {
-                        err = graphics_splash(root_dir, entry->splash, config->background);
-                        if (!EFI_ERROR(err)) {
-                                console_key_read(&key, TRUE);
-                                graphics_mode(FALSE);
+                        UINT8 *content = NULL;
+                        INTN len;
+
+                        len = file_read(root_dir, entry->splash, 0, 0, &content);
+                        if (len > 0) {
+                                for (;;) {
+                                        static const EFI_GRAPHICS_OUTPUT_BLT_PIXEL colors[] = {
+                                                { .Red = 0xff, .Green = 0xff, .Blue = 0xff },
+                                                { .Red = 0xc0, .Green = 0xc0, .Blue = 0xc0 },
+                                                { .Red = 0xff, .Green =    0, .Blue =    0 },
+                                                { .Red =    0, .Green = 0xff, .Blue =    0 },
+                                                { .Red =    0, .Green =    0, .Blue = 0xff },
+                                                { .Red =    0, .Green =    0, .Blue =    0 },
+                                        };
+
+                                        err = graphics_splash(content, len, pixel);
+                                        if (EFI_ERROR(err))
+                                                break;
+
+                                        /* 'b' rotates through background colors */
+                                        console_key_read(&key, TRUE);
+                                        if (key != KEYPRESS(0, 0, 'b'))
+                                                break;
+                                        pixel = &colors[color++];
+                                        if (color == ELEMENTSOF(colors))
+                                                color = 0;
+                                }
                         }
+
+                        FreePool(content);
+                        graphics_mode(FALSE);
+                        uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
                 }
 
                 Print(L"config entry:           %d/%d\n", i+1, config->entry_count);
@@ -1064,41 +1048,6 @@ static VOID config_defaults_load_from_file(Config *config, CHAR8 *content) {
                         StrLwr(config->entry_default_pattern);
                         continue;
                 }
-
-                if (strcmpa((CHAR8 *)"splash", key) == 0) {
-                        FreePool(config->splash);
-                        config->splash = stra_to_path(value);
-                        continue;
-                }
-
-                if (strcmpa((CHAR8 *)"background", key) == 0) {
-                        CHAR16 c[3];
-
-                        /* accept #RRGGBB hex notation */
-                        if (value[0] != '#')
-                                continue;
-                        if (value[7] != '\0')
-                                continue;
-
-                        FreePool(config->background);
-                        config->background = AllocateZeroPool(sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
-                        if (!config->background)
-                                continue;
-
-                        c[0] = value[1];
-                        c[1] = value[2];
-                        c[2] = '\0';
-                        config->background->Red = xtoi(c);
-
-                        c[0] = value[3];
-                        c[1] = value[4];
-                        config->background->Green = xtoi(c);
-
-                        c[0] = value[5];
-                        c[1] = value[6];
-                        config->background->Blue = xtoi(c);
-                        continue;
-                }
         }
 }
 
@@ -1596,9 +1545,6 @@ static BOOLEAN config_entry_add_loader_auto(Config *config, EFI_HANDLE *device,
         /* do not boot right away into auto-detected entries */
         entry->no_autoselect = TRUE;
 
-        /* do not show a splash; they do not need one, or they draw their own */
-        entry->splash = StrDuplicate(L"");
-
         /* export identifiers of automatically added entries */
         if (config->entries_auto) {
                 CHAR16 *s;
@@ -1811,8 +1757,6 @@ static VOID config_free(Config *config) {
         FreePool(config->options_edit);
         FreePool(config->entry_oneshot);
         FreePool(config->entries_auto);
-        FreePool(config->splash);
-        FreePool(config->background);
 }
 
 EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
@@ -1893,15 +1837,6 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
         ZeroMem(&config, sizeof(Config));
         config_load(&config, loaded_image->DeviceHandle, root_dir, loaded_image_path);
 
-        if (!config.background) {
-                config.background = AllocateZeroPool(sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
-                if (StriCmp(L"Apple", ST->FirmwareVendor) == 0) {
-                        config.background->Red = 0xc0;
-                        config.background->Green = 0xc0;
-                        config.background->Blue = 0xc0;
-                }
-        }
-
         /* if we find some well-known loaders, add them to the end of the list */
         config_entry_add_linux(&config, loaded_image, root_dir);
         config_entry_add_loader_auto(&config, loaded_image->DeviceHandle, root_dir, loaded_image_path,
@@ -1972,25 +1907,15 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
                                 entry->call();
                                 continue;
                         }
-                } else {
-                        err = EFI_NOT_FOUND;
-
-                        /* splash from entry file */
-                        if (entry->splash) {
-                                /* some entries disable the splash because they draw their own */
-                                if (entry->splash[0] == '\0')
-                                        err = EFI_SUCCESS;
-                                else
-                                        err = graphics_splash(root_dir, entry->splash, config.background);
-                        }
+                } else if (entry->splash) {
+                        UINT8 *content = NULL;
+                        INTN len;
 
-                        /* splash from config file */
-                        if (EFI_ERROR(err) && config.splash)
-                                err = graphics_splash(root_dir, config.splash, config.background);
+                        len = file_read(root_dir, entry->splash, 0, 0, &content);
+                        if (len > 0)
+                                graphics_splash(content, len, NULL);
 
-                        /* default splash */
-                        if (EFI_ERROR(err))
-                                graphics_splash(root_dir, L"\\EFI\\systemd\\splash.bmp", config.background);
+                        FreePool(content);
                 }
 
                 /* export the selected boot entry to the system */
@@ -1998,14 +1923,9 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
 
                 uefi_call_wrapper(BS->SetWatchdogTimer, 4, 5 * 60, 0x10000, 0, NULL);
                 err = image_start(image, &config, entry);
-
-                if (err == EFI_ACCESS_DENIED || err == EFI_SECURITY_VIOLATION) {
-                        /* Platform is secure boot and requested image isn't
-                         * trusted. Need to go back to prior boot system and
-                         * install more keys or hashes. Signal failure by
-                         * returning the error */
-                        Print(L"\nImage %s gives a security error\n", entry->title);
-                        Print(L"Please enrol the hash or signature of %s\n", entry->loader);
+                if (EFI_ERROR(err)) {
+                        graphics_mode(FALSE);
+                        Print(L"\nFailed to execute %s (%s): %r\n", entry->title, entry->loader, err);
                         uefi_call_wrapper(BS->Stall, 1, 3 * 1000 * 1000);
                         goto out;
                 }