cosmetics for 'P' splash loop
[platform/upstream/gummiboot.git] / src / efi / gummiboot.c
index 0e72dab..90770c8 100644 (file)
@@ -61,6 +61,7 @@ typedef struct {
         enum loader_type type;
         CHAR16 *loader;
         CHAR16 *options;
+        CHAR16 *splash;
         CHAR16 key;
         EFI_STATUS (*call)(void);
         BOOLEAN no_autoselect;
@@ -76,6 +77,8 @@ 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;
@@ -365,16 +368,51 @@ static UINTN entry_lookup_key(Config *config, UINTN start, CHAR16 key) {
         return -1;
 }
 
-static VOID print_status(Config *config, CHAR16 *loaded_image_path) {
+static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_image_path) {
         UINT64 key;
         UINTN i;
         CHAR16 *s;
         CHAR8 *b;
         UINTN size;
+        EFI_STATUS err;
+        UINTN color = 0;
+        const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *pixel = config->background;
 
         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 = 255, .Green = 255, .Blue = 255 },
+                        { .Red = 255, .Green =   0, .Blue =   0 },
+                        { .Red =   0, .Green = 255, .Blue =   0 },
+                        { .Red =   0, .Green =   0, .Blue = 255 },
+                        { .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\\gummiboot\\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);
+                break;
+        }
+
         Print(L"gummiboot version:      " VERSION "\n");
         Print(L"loaded image:           %s\n", loaded_image_path);
         Print(L"UEFI version:           %d.%02d\n", ST->Hdr.Revision >> 16, ST->Hdr.Revision & 0xffff);
@@ -402,6 +440,13 @@ static VOID print_status(Config *config, CHAR16 *loaded_image_path) {
         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);
@@ -437,6 +482,15 @@ static VOID print_status(Config *config, CHAR16 *loaded_image_path) {
                         break;
 
                 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);
+                        }
+                }
+
                 Print(L"config entry:           %d/%d\n", i+1, config->entry_count);
                 if (entry->file)
                         Print(L"file                    '%s'\n", entry->file);
@@ -462,6 +516,8 @@ static VOID print_status(Config *config, CHAR16 *loaded_image_path) {
                         Print(L"loader                  '%s'\n", entry->loader);
                 if (entry->options)
                         Print(L"options                 '%s'\n", entry->options);
+                if (entry->splash)
+                        Print(L"splash                  '%s'\n", entry->splash);
                 Print(L"auto-select             %s\n", entry->no_autoselect ? L"no" : L"yes");
                 if (entry->call)
                         Print(L"internal call           yes\n");
@@ -473,7 +529,7 @@ static VOID print_status(Config *config, CHAR16 *loaded_image_path) {
         uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
 }
 
-static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, CHAR16 *loaded_image_path) {
+static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, EFI_FILE *root_dir, CHAR16 *loaded_image_path) {
         EFI_STATUS err;
         UINTN visible_max;
         UINTN idx_highlight;
@@ -794,7 +850,7 @@ static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, CHAR16 *load
                         break;
 
                 case KEYPRESS(0, 0, 'P'):
-                        print_status(config, loaded_image_path);
+                        print_status(config, root_dir, loaded_image_path);
                         refresh = TRUE;
                         break;
 
@@ -995,11 +1051,45 @@ static VOID config_defaults_load_from_file(Config *config, CHAR8 *content) {
                         FreePool(s);
                         continue;
                 }
+
                 if (strcmpa((CHAR8 *)"default", key) == 0) {
                         config->entry_default_pattern = stra_to_str(value);
                         StrLwr(config->entry_default_pattern);
                         continue;
                 }
+
+                if (strcmpa((CHAR8 *)"splash", key) == 0) {
+                        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;
+
+                        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;
+                }
         }
 }
 
@@ -1087,6 +1177,12 @@ static VOID config_entry_add_from_file(Config *config, EFI_HANDLE *device, CHAR1
                         FreePool(new);
                         continue;
                 }
+
+                if (strcmpa((CHAR8 *)"splash", key) == 0) {
+                        FreePool(entry->splash);
+                        entry->splash = stra_to_path(value);
+                        continue;
+                }
         }
 
         if (entry->type == LOADER_UNDEFINED) {
@@ -1464,9 +1560,15 @@ static BOOLEAN config_entry_add_loader(Config *config, EFI_HANDLE *device, EFI_F
         entry->loader = StrDuplicate(loader);
         entry->file = StrDuplicate(file);
         StrLwr(entry->file);
-        entry->no_autoselect = TRUE;
         entry->key = key;
         config_add_entry(config, entry);
+
+        /* do not boot right away into aut-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"");
+
         return TRUE;
 }
 
@@ -1597,6 +1699,8 @@ 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) {
@@ -1737,7 +1841,7 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
                 if (menu) {
                         efivar_set_time_usec(L"LoaderTimeMenuUSec", 0);
                         uefi_call_wrapper(BS->SetWatchdogTimer, 4, 0, 0x10000, 0, NULL);
-                        if (!menu_run(&config, &entry, loaded_image_path))
+                        if (!menu_run(&config, &entry, root_dir, loaded_image_path))
                                 break;
 
                         /* run special entry like "reboot" */
@@ -1745,6 +1849,25 @@ 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);
+                        }
+
+                        /* splash from config file */
+                        if (EFI_ERROR(err) && config.splash)
+                                err = graphics_splash(root_dir, config.splash, config.background);
+
+                        /* default splash */
+                        if (EFI_ERROR(err))
+                                graphics_splash(root_dir, L"\\EFI\\gummiboot\\splash.bmp", config.background);
                 }
 
                 /* export the selected boot entry to the system */