[systemd-commits] 2 commits - Makefile.am src/boot test/test-efi-create-disk.sh

Kay Sievers kay at kemper.freedesktop.org
Thu Feb 26 10:56:00 PST 2015


 Makefile.am                  |    2 
 src/boot/efi/boot.c          |   65 --------
 src/boot/efi/graphics.c      |  300 ----------------------------------------
 src/boot/efi/graphics.h      |    1 
 src/boot/efi/splash.c        |  322 +++++++++++++++++++++++++++++++++++++++++++
 src/boot/efi/splash.h        |   22 ++
 src/boot/efi/stub.c          |    1 
 test/test-efi-create-disk.sh |    3 
 8 files changed, 352 insertions(+), 364 deletions(-)

New commits:
commit 7361099e4245ee31f6d70dc659d78fc533952893
Author: Kay Sievers <kay at vrfy.org>
Date:   Thu Feb 26 19:51:08 2015 +0100

    boot: efi - remove custom splash support

diff --git a/Makefile.am b/Makefile.am
index 74c9a50..e77a242 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2566,14 +2566,12 @@ systemd_boot_headers = \
 	src/boot/efi/util.h \
 	src/boot/efi/console.h \
 	src/boot/efi/graphics.h \
-	src/boot/efi/splash.h \
 	src/boot/efi/pefile.h
 
 systemd_boot_sources = \
 	src/boot/efi/util.c \
 	src/boot/efi/console.c \
 	src/boot/efi/graphics.c \
-	src/boot/efi/splash.c \
 	src/boot/efi/pefile.c \
 	src/boot/efi/boot.c
 
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
index 0990fb8..b6ecfa4 100644
--- a/src/boot/efi/boot.c
+++ b/src/boot/efi/boot.c
@@ -21,7 +21,6 @@
 #include "util.h"
 #include "console.h"
 #include "graphics.h"
-#include "splash.h"
 #include "pefile.h"
 #include "linux.h"
 
@@ -50,7 +49,6 @@ typedef struct {
         enum loader_type type;
         CHAR16 *loader;
         CHAR16 *options;
-        CHAR16 *splash;
         CHAR16 key;
         EFI_STATUS (*call)(VOID);
         BOOLEAN no_autoselect;
@@ -355,7 +353,7 @@ static UINTN entry_lookup_key(Config *config, UINTN start, CHAR16 key) {
         return -1;
 }
 
-static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_image_path) {
+static VOID print_status(Config *config, CHAR16 *loaded_image_path) {
         UINT64 key;
         UINTN i;
         CHAR16 *s;
@@ -363,9 +361,6 @@ static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_imag
         UINTN x;
         UINTN y;
         UINTN size;
-        EFI_STATUS err;
-        UINTN color = 0;
-        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);
@@ -437,42 +432,6 @@ static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_imag
                         break;
 
                 entry = config->entries[i];
-
-                if (entry->splash) {
-                        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);
                 if (entry->file)
                         Print(L"file                    '%s'\n", entry->file);
@@ -498,8 +457,6 @@ static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_imag
                         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");
@@ -511,7 +468,7 @@ static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_imag
         uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
 }
 
-static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, EFI_FILE *root_dir, CHAR16 *loaded_image_path) {
+static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, CHAR16 *loaded_image_path) {
         EFI_STATUS err;
         UINTN visible_max;
         UINTN idx_highlight;
@@ -835,7 +792,7 @@ static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, EFI_FILE *ro
                         break;
 
                 case KEYPRESS(0, 0, 'P'):
-                        print_status(config, root_dir, loaded_image_path);
+                        print_status(config, loaded_image_path);
                         refresh = TRUE;
                         break;
 
@@ -1145,12 +1102,6 @@ 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) {
@@ -1900,7 +1851,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, root_dir, loaded_image_path))
+                        if (!menu_run(&config, &entry, loaded_image_path))
                                 break;
 
                         /* run special entry like "reboot" */
@@ -1908,15 +1859,6 @@ EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *sys_table) {
                                 entry->call();
                                 continue;
                         }
-                } else if (entry->splash) {
-                        UINT8 *content = NULL;
-                        INTN len;
-
-                        len = file_read(root_dir, entry->splash, 0, 0, &content);
-                        if (len > 0)
-                                graphics_splash(content, len, NULL);
-
-                        FreePool(content);
                 }
 
                 /* export the selected boot entry to the system */
diff --git a/test/test-efi-create-disk.sh b/test/test-efi-create-disk.sh
index 62d8439..56dd09a 100755
--- a/test/test-efi-create-disk.sh
+++ b/test/test-efi-create-disk.sh
@@ -13,7 +13,6 @@ mount ${LOOP}p1 mnt
 
 mkdir -p mnt/EFI/{Boot,systemd}
 cp systemd-bootx64.efi mnt/EFI/Boot/bootx64.efi
-cp test/splash.bmp mnt/
 
 [ -e /boot/shellx64.efi ] && cp /boot/shellx64.efi mnt/
 
@@ -30,7 +29,7 @@ objcopy \
 # install entries
 mkdir -p mnt/loader/entries
 echo -e "timeout 3\n" > mnt/loader/loader.conf
-echo -e "title Test\nefi /test\nsplash /splash.bmp\n" > mnt/loader/entries/test.conf
+echo -e "title Test\nefi /test\n" > mnt/loader/entries/test.conf
 echo -e "title Test2\nlinux /test2\noptions option=yes word number=1000 more\n" > mnt/loader/entries/test2.conf
 echo -e "title Test3\nlinux /test3\n" > mnt/loader/entries/test3.conf
 echo -e "title Test4\nlinux /test4\n" > mnt/loader/entries/test4.conf

commit 2f8d336478536af789d654599f9523d02e0ca693
Author: Kay Sievers <kay at vrfy.org>
Date:   Thu Feb 26 19:45:08 2015 +0100

    boot: efi - split graphics and splash handling

diff --git a/Makefile.am b/Makefile.am
index 25cc50c..74c9a50 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2566,12 +2566,14 @@ systemd_boot_headers = \
 	src/boot/efi/util.h \
 	src/boot/efi/console.h \
 	src/boot/efi/graphics.h \
+	src/boot/efi/splash.h \
 	src/boot/efi/pefile.h
 
 systemd_boot_sources = \
 	src/boot/efi/util.c \
 	src/boot/efi/console.c \
 	src/boot/efi/graphics.c \
+	src/boot/efi/splash.c \
 	src/boot/efi/pefile.c \
 	src/boot/efi/boot.c
 
@@ -2602,12 +2604,14 @@ stub_headers = \
 	src/boot/efi/util.h \
 	src/boot/efi/pefile.h \
 	src/boot/efi/graphics.h \
+	src/boot/efi/splash.h \
 	src/boot/efi/linux.h
 
 stub_sources = \
 	src/boot/efi/util.c \
 	src/boot/efi/pefile.c \
 	src/boot/efi/graphics.c \
+	src/boot/efi/splash.c \
 	src/boot/efi/linux.c \
 	src/boot/efi/stub.c
 
diff --git a/src/boot/efi/boot.c b/src/boot/efi/boot.c
index 8bdc7f8..0990fb8 100644
--- a/src/boot/efi/boot.c
+++ b/src/boot/efi/boot.c
@@ -21,6 +21,7 @@
 #include "util.h"
 #include "console.h"
 #include "graphics.h"
+#include "splash.h"
 #include "pefile.h"
 #include "linux.h"
 
diff --git a/src/boot/efi/graphics.c b/src/boot/efi/graphics.c
index 124022a..2e9c11f 100644
--- a/src/boot/efi/graphics.c
+++ b/src/boot/efi/graphics.c
@@ -89,303 +89,3 @@ EFI_STATUS graphics_mode(BOOLEAN on) {
 
         return err;
 }
-
-struct bmp_file {
-        CHAR8 signature[2];
-        UINT32 size;
-        UINT16 reserved[2];
-        UINT32 offset;
-} __attribute__((packed));
-
-/* we require at least BITMAPINFOHEADER, later versions are
-   accepted, but their features ignored */
-struct bmp_dib {
-        UINT32 size;
-        UINT32 x;
-        UINT32 y;
-        UINT16 planes;
-        UINT16 depth;
-        UINT32 compression;
-        UINT32 image_size;
-        INT32 x_pixel_meter;
-        INT32 y_pixel_meter;
-        UINT32 colors_used;
-        UINT32 colors_important;
-} __attribute__((packed));
-
-struct bmp_map {
-        UINT8 blue;
-        UINT8 green;
-        UINT8 red;
-        UINT8 reserved;
-} __attribute__((packed));
-
-EFI_STATUS bmp_parse_header(UINT8 *bmp, UINTN size, struct bmp_dib **ret_dib,
-                            struct bmp_map **ret_map, UINT8 **pixmap) {
-        struct bmp_file *file;
-        struct bmp_dib *dib;
-        struct bmp_map *map;
-        UINTN row_size;
-
-        if (size < sizeof(struct bmp_file) + sizeof(struct bmp_dib))
-                return EFI_INVALID_PARAMETER;
-
-        /* check file header */
-        file = (struct bmp_file *)bmp;
-        if (file->signature[0] != 'B' || file->signature[1] != 'M')
-                return EFI_INVALID_PARAMETER;
-        if (file->size != size)
-                return EFI_INVALID_PARAMETER;
-        if (file->size < file->offset)
-                return EFI_INVALID_PARAMETER;
-
-        /*  check device-independent bitmap */
-        dib = (struct bmp_dib *)(bmp + sizeof(struct bmp_file));
-        if (dib->size < sizeof(struct bmp_dib))
-                return EFI_UNSUPPORTED;
-
-        switch (dib->depth) {
-        case 1:
-        case 4:
-        case 8:
-        case 24:
-                if (dib->compression != 0)
-                        return EFI_UNSUPPORTED;
-
-                break;
-
-        case 16:
-        case 32:
-                if (dib->compression != 0 && dib->compression != 3)
-                        return EFI_UNSUPPORTED;
-
-                break;
-
-        default:
-                return EFI_UNSUPPORTED;
-        }
-
-        row_size = (((dib->depth * dib->x) + 31) / 32) * 4;
-        if (file->size - file->offset <  dib->y * row_size)
-                return EFI_INVALID_PARAMETER;
-        if (row_size * dib->y > 64 * 1024 * 1024)
-                return EFI_INVALID_PARAMETER;
-
-        /* check color table */
-        map = (struct bmp_map *)(bmp + sizeof(struct bmp_file) + dib->size);
-        if (file->offset < sizeof(struct bmp_file) + dib->size)
-                return EFI_INVALID_PARAMETER;
-
-        if (file->offset > sizeof(struct bmp_file) + dib->size) {
-                UINT32 map_count;
-                UINTN map_size;
-
-                if (dib->colors_used)
-                        map_count = dib->colors_used;
-                else {
-                        switch (dib->depth) {
-                        case 1:
-                        case 4:
-                        case 8:
-                                map_count = 1 << dib->depth;
-                                break;
-
-                        default:
-                                map_count = 0;
-                                break;
-                        }
-                }
-
-                map_size = file->offset - (sizeof(struct bmp_file) + dib->size);
-                if (map_size != sizeof(struct bmp_map) * map_count)
-                        return EFI_INVALID_PARAMETER;
-        }
-
-        *ret_map = map;
-        *ret_dib = dib;
-        *pixmap = bmp + file->offset;
-
-        return EFI_SUCCESS;
-}
-
-static VOID pixel_blend(UINT32 *dst, const UINT32 source) {
-        UINT32 alpha, src, src_rb, src_g, dst_rb, dst_g, rb, g;
-
-        alpha = (source & 0xff);
-
-        /* convert src from RGBA to XRGB */
-        src = source >> 8;
-
-        /* decompose into RB and G components */
-        src_rb = (src & 0xff00ff);
-        src_g  = (src & 0x00ff00);
-
-        dst_rb = (*dst & 0xff00ff);
-        dst_g  = (*dst & 0x00ff00);
-
-        /* blend */
-        rb = ((((src_rb - dst_rb) * alpha + 0x800080) >> 8) + dst_rb) & 0xff00ff;
-        g  = ((((src_g  -  dst_g) * alpha + 0x008000) >> 8) +  dst_g) & 0x00ff00;
-
-        *dst = (rb | g);
-}
-
-EFI_STATUS bmp_to_blt(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *buf,
-                      struct bmp_dib *dib, struct bmp_map *map,
-                      UINT8 *pixmap) {
-        UINT8 *in;
-        UINTN y;
-
-        /* transform and copy pixels */
-        in = pixmap;
-        for (y = 0; y < dib->y; y++) {
-                EFI_GRAPHICS_OUTPUT_BLT_PIXEL *out;
-                UINTN row_size;
-                UINTN x;
-
-                out = &buf[(dib->y - y - 1) * dib->x];
-                for (x = 0; x < dib->x; x++, in++, out++) {
-                        switch (dib->depth) {
-                        case 1: {
-                                UINTN i;
-
-                                for (i = 0; i < 8 && x < dib->x; i++) {
-                                        out->Red = map[((*in) >> (7 - i)) & 1].red;
-                                        out->Green = map[((*in) >> (7 - i)) & 1].green;
-                                        out->Blue = map[((*in) >> (7 - i)) & 1].blue;
-                                        out++;
-                                        x++;
-                                }
-                                out--;
-                                x--;
-                                break;
-                        }
-
-                        case 4: {
-                                UINTN i;
-
-                                i = (*in) >> 4;
-                                out->Red = map[i].red;
-                                out->Green = map[i].green;
-                                out->Blue = map[i].blue;
-                                if (x < (dib->x - 1)) {
-                                        out++;
-                                        x++;
-                                        i = (*in) & 0x0f;
-                                        out->Red = map[i].red;
-                                        out->Green = map[i].green;
-                                        out->Blue = map[i].blue;
-                                }
-                                break;
-                        }
-
-                        case 8:
-                                out->Red = map[*in].red;
-                                out->Green = map[*in].green;
-                                out->Blue = map[*in].blue;
-                                break;
-
-                        case 16: {
-                                UINT16 i = *(UINT16 *) in;
-
-                                out->Red = (i & 0x7c00) >> 7;
-                                out->Green = (i & 0x3e0) >> 2;
-                                out->Blue = (i & 0x1f) << 3;
-                                in += 1;
-                                break;
-                        }
-
-                        case 24:
-                                out->Red = in[2];
-                                out->Green = in[1];
-                                out->Blue = in[0];
-                                in += 2;
-                                break;
-
-                        case 32: {
-                                UINT32 i = *(UINT32 *) in;
-
-                                pixel_blend((UINT32 *)out, i);
-
-                                in += 3;
-                                break;
-                        }
-                        }
-                }
-
-                /* add row padding; new lines always start at 32 bit boundary */
-                row_size = in - pixmap;
-                in += ((row_size + 3) & ~3) - row_size;
-        }
-
-        return EFI_SUCCESS;
-}
-
-EFI_STATUS graphics_splash(UINT8 *content, UINTN len, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *background) {
-        EFI_GRAPHICS_OUTPUT_BLT_PIXEL pixel = {};
-        EFI_GUID GraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
-        EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput = NULL;
-        struct bmp_dib *dib;
-        struct bmp_map *map;
-        UINT8 *pixmap;
-        UINT64 blt_size;
-        VOID *blt = NULL;
-        UINTN x_pos = 0;
-        UINTN y_pos = 0;
-        EFI_STATUS err;
-
-        if (!background) {
-                if (StriCmp(L"Apple", ST->FirmwareVendor) == 0) {
-                        pixel.Red = 0xc0;
-                        pixel.Green = 0xc0;
-                        pixel.Blue = 0xc0;
-                }
-                background = &pixel;
-        }
-
-        err = LibLocateProtocol(&GraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
-        if (EFI_ERROR(err))
-                return err;
-
-        err = bmp_parse_header(content, len, &dib, &map, &pixmap);
-        if (EFI_ERROR(err))
-                goto err;
-
-        if(dib->x < GraphicsOutput->Mode->Info->HorizontalResolution)
-                x_pos = (GraphicsOutput->Mode->Info->HorizontalResolution - dib->x) / 2;
-        if(dib->y < GraphicsOutput->Mode->Info->VerticalResolution)
-                y_pos = (GraphicsOutput->Mode->Info->VerticalResolution - dib->y) / 2;
-
-        uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
-                          (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)background,
-                          EfiBltVideoFill, 0, 0, 0, 0,
-                          GraphicsOutput->Mode->Info->HorizontalResolution,
-                          GraphicsOutput->Mode->Info->VerticalResolution, 0);
-
-        /* EFI buffer */
-        blt_size = dib->x * dib->y * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
-        blt = AllocatePool(blt_size);
-        if (!blt)
-                return EFI_OUT_OF_RESOURCES;
-
-        err = uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
-                                blt, EfiBltVideoToBltBuffer, x_pos, y_pos, 0, 0,
-                                dib->x, dib->y, 0);
-        if (EFI_ERROR(err))
-                goto err;
-
-        err = bmp_to_blt(blt, dib, map, pixmap);
-        if (EFI_ERROR(err))
-                goto err;
-
-        err = graphics_mode(TRUE);
-        if (EFI_ERROR(err))
-                goto err;
-
-        err = uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
-                                blt, EfiBltBufferToVideo, 0, 0, x_pos, y_pos,
-                                dib->x, dib->y, 0);
-err:
-        FreePool(blt);
-        return err;
-}
diff --git a/src/boot/efi/graphics.h b/src/boot/efi/graphics.h
index 6ada263..3ee4972 100644
--- a/src/boot/efi/graphics.h
+++ b/src/boot/efi/graphics.h
@@ -21,5 +21,4 @@
 #define __SDBOOT_GRAPHICS_H
 
 EFI_STATUS graphics_mode(BOOLEAN on);
-EFI_STATUS graphics_splash(UINT8 *content, UINTN len, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *background);
 #endif
diff --git a/src/boot/efi/splash.c b/src/boot/efi/splash.c
new file mode 100644
index 0000000..3f2aa27
--- /dev/null
+++ b/src/boot/efi/splash.c
@@ -0,0 +1,322 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Copyright (C) 2012-2013 Kay Sievers <kay at vrfy.org>
+ * Copyright (C) 2012 Harald Hoyer <harald at redhat.com>
+ */
+
+#include <efi.h>
+#include <efilib.h>
+
+#include "util.h"
+#include "splash.h"
+
+struct bmp_file {
+        CHAR8 signature[2];
+        UINT32 size;
+        UINT16 reserved[2];
+        UINT32 offset;
+} __attribute__((packed));
+
+/* we require at least BITMAPINFOHEADER, later versions are
+   accepted, but their features ignored */
+struct bmp_dib {
+        UINT32 size;
+        UINT32 x;
+        UINT32 y;
+        UINT16 planes;
+        UINT16 depth;
+        UINT32 compression;
+        UINT32 image_size;
+        INT32 x_pixel_meter;
+        INT32 y_pixel_meter;
+        UINT32 colors_used;
+        UINT32 colors_important;
+} __attribute__((packed));
+
+struct bmp_map {
+        UINT8 blue;
+        UINT8 green;
+        UINT8 red;
+        UINT8 reserved;
+} __attribute__((packed));
+
+EFI_STATUS bmp_parse_header(UINT8 *bmp, UINTN size, struct bmp_dib **ret_dib,
+                            struct bmp_map **ret_map, UINT8 **pixmap) {
+        struct bmp_file *file;
+        struct bmp_dib *dib;
+        struct bmp_map *map;
+        UINTN row_size;
+
+        if (size < sizeof(struct bmp_file) + sizeof(struct bmp_dib))
+                return EFI_INVALID_PARAMETER;
+
+        /* check file header */
+        file = (struct bmp_file *)bmp;
+        if (file->signature[0] != 'B' || file->signature[1] != 'M')
+                return EFI_INVALID_PARAMETER;
+        if (file->size != size)
+                return EFI_INVALID_PARAMETER;
+        if (file->size < file->offset)
+                return EFI_INVALID_PARAMETER;
+
+        /*  check device-independent bitmap */
+        dib = (struct bmp_dib *)(bmp + sizeof(struct bmp_file));
+        if (dib->size < sizeof(struct bmp_dib))
+                return EFI_UNSUPPORTED;
+
+        switch (dib->depth) {
+        case 1:
+        case 4:
+        case 8:
+        case 24:
+                if (dib->compression != 0)
+                        return EFI_UNSUPPORTED;
+
+                break;
+
+        case 16:
+        case 32:
+                if (dib->compression != 0 && dib->compression != 3)
+                        return EFI_UNSUPPORTED;
+
+                break;
+
+        default:
+                return EFI_UNSUPPORTED;
+        }
+
+        row_size = (((dib->depth * dib->x) + 31) / 32) * 4;
+        if (file->size - file->offset <  dib->y * row_size)
+                return EFI_INVALID_PARAMETER;
+        if (row_size * dib->y > 64 * 1024 * 1024)
+                return EFI_INVALID_PARAMETER;
+
+        /* check color table */
+        map = (struct bmp_map *)(bmp + sizeof(struct bmp_file) + dib->size);
+        if (file->offset < sizeof(struct bmp_file) + dib->size)
+                return EFI_INVALID_PARAMETER;
+
+        if (file->offset > sizeof(struct bmp_file) + dib->size) {
+                UINT32 map_count;
+                UINTN map_size;
+
+                if (dib->colors_used)
+                        map_count = dib->colors_used;
+                else {
+                        switch (dib->depth) {
+                        case 1:
+                        case 4:
+                        case 8:
+                                map_count = 1 << dib->depth;
+                                break;
+
+                        default:
+                                map_count = 0;
+                                break;
+                        }
+                }
+
+                map_size = file->offset - (sizeof(struct bmp_file) + dib->size);
+                if (map_size != sizeof(struct bmp_map) * map_count)
+                        return EFI_INVALID_PARAMETER;
+        }
+
+        *ret_map = map;
+        *ret_dib = dib;
+        *pixmap = bmp + file->offset;
+
+        return EFI_SUCCESS;
+}
+
+static VOID pixel_blend(UINT32 *dst, const UINT32 source) {
+        UINT32 alpha, src, src_rb, src_g, dst_rb, dst_g, rb, g;
+
+        alpha = (source & 0xff);
+
+        /* convert src from RGBA to XRGB */
+        src = source >> 8;
+
+        /* decompose into RB and G components */
+        src_rb = (src & 0xff00ff);
+        src_g  = (src & 0x00ff00);
+
+        dst_rb = (*dst & 0xff00ff);
+        dst_g  = (*dst & 0x00ff00);
+
+        /* blend */
+        rb = ((((src_rb - dst_rb) * alpha + 0x800080) >> 8) + dst_rb) & 0xff00ff;
+        g  = ((((src_g  -  dst_g) * alpha + 0x008000) >> 8) +  dst_g) & 0x00ff00;
+
+        *dst = (rb | g);
+}
+
+EFI_STATUS bmp_to_blt(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *buf,
+                      struct bmp_dib *dib, struct bmp_map *map,
+                      UINT8 *pixmap) {
+        UINT8 *in;
+        UINTN y;
+
+        /* transform and copy pixels */
+        in = pixmap;
+        for (y = 0; y < dib->y; y++) {
+                EFI_GRAPHICS_OUTPUT_BLT_PIXEL *out;
+                UINTN row_size;
+                UINTN x;
+
+                out = &buf[(dib->y - y - 1) * dib->x];
+                for (x = 0; x < dib->x; x++, in++, out++) {
+                        switch (dib->depth) {
+                        case 1: {
+                                UINTN i;
+
+                                for (i = 0; i < 8 && x < dib->x; i++) {
+                                        out->Red = map[((*in) >> (7 - i)) & 1].red;
+                                        out->Green = map[((*in) >> (7 - i)) & 1].green;
+                                        out->Blue = map[((*in) >> (7 - i)) & 1].blue;
+                                        out++;
+                                        x++;
+                                }
+                                out--;
+                                x--;
+                                break;
+                        }
+
+                        case 4: {
+                                UINTN i;
+
+                                i = (*in) >> 4;
+                                out->Red = map[i].red;
+                                out->Green = map[i].green;
+                                out->Blue = map[i].blue;
+                                if (x < (dib->x - 1)) {
+                                        out++;
+                                        x++;
+                                        i = (*in) & 0x0f;
+                                        out->Red = map[i].red;
+                                        out->Green = map[i].green;
+                                        out->Blue = map[i].blue;
+                                }
+                                break;
+                        }
+
+                        case 8:
+                                out->Red = map[*in].red;
+                                out->Green = map[*in].green;
+                                out->Blue = map[*in].blue;
+                                break;
+
+                        case 16: {
+                                UINT16 i = *(UINT16 *) in;
+
+                                out->Red = (i & 0x7c00) >> 7;
+                                out->Green = (i & 0x3e0) >> 2;
+                                out->Blue = (i & 0x1f) << 3;
+                                in += 1;
+                                break;
+                        }
+
+                        case 24:
+                                out->Red = in[2];
+                                out->Green = in[1];
+                                out->Blue = in[0];
+                                in += 2;
+                                break;
+
+                        case 32: {
+                                UINT32 i = *(UINT32 *) in;
+
+                                pixel_blend((UINT32 *)out, i);
+
+                                in += 3;
+                                break;
+                        }
+                        }
+                }
+
+                /* add row padding; new lines always start at 32 bit boundary */
+                row_size = in - pixmap;
+                in += ((row_size + 3) & ~3) - row_size;
+        }
+
+        return EFI_SUCCESS;
+}
+
+EFI_STATUS graphics_splash(UINT8 *content, UINTN len, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *background) {
+        EFI_GRAPHICS_OUTPUT_BLT_PIXEL pixel = {};
+        EFI_GUID GraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
+        EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput = NULL;
+        struct bmp_dib *dib;
+        struct bmp_map *map;
+        UINT8 *pixmap;
+        UINT64 blt_size;
+        VOID *blt = NULL;
+        UINTN x_pos = 0;
+        UINTN y_pos = 0;
+        EFI_STATUS err;
+
+        if (!background) {
+                if (StriCmp(L"Apple", ST->FirmwareVendor) == 0) {
+                        pixel.Red = 0xc0;
+                        pixel.Green = 0xc0;
+                        pixel.Blue = 0xc0;
+                }
+                background = &pixel;
+        }
+
+        err = LibLocateProtocol(&GraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
+        if (EFI_ERROR(err))
+                return err;
+
+        err = bmp_parse_header(content, len, &dib, &map, &pixmap);
+        if (EFI_ERROR(err))
+                goto err;
+
+        if(dib->x < GraphicsOutput->Mode->Info->HorizontalResolution)
+                x_pos = (GraphicsOutput->Mode->Info->HorizontalResolution - dib->x) / 2;
+        if(dib->y < GraphicsOutput->Mode->Info->VerticalResolution)
+                y_pos = (GraphicsOutput->Mode->Info->VerticalResolution - dib->y) / 2;
+
+        uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
+                          (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)background,
+                          EfiBltVideoFill, 0, 0, 0, 0,
+                          GraphicsOutput->Mode->Info->HorizontalResolution,
+                          GraphicsOutput->Mode->Info->VerticalResolution, 0);
+
+        /* EFI buffer */
+        blt_size = dib->x * dib->y * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
+        blt = AllocatePool(blt_size);
+        if (!blt)
+                return EFI_OUT_OF_RESOURCES;
+
+        err = uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
+                                blt, EfiBltVideoToBltBuffer, x_pos, y_pos, 0, 0,
+                                dib->x, dib->y, 0);
+        if (EFI_ERROR(err))
+                goto err;
+
+        err = bmp_to_blt(blt, dib, map, pixmap);
+        if (EFI_ERROR(err))
+                goto err;
+
+        err = graphics_mode(TRUE);
+        if (EFI_ERROR(err))
+                goto err;
+
+        err = uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
+                                blt, EfiBltBufferToVideo, 0, 0, x_pos, y_pos,
+                                dib->x, dib->y, 0);
+err:
+        FreePool(blt);
+        return err;
+}
diff --git a/src/boot/efi/splash.h b/src/boot/efi/splash.h
new file mode 100644
index 0000000..0183e79
--- /dev/null
+++ b/src/boot/efi/splash.h
@@ -0,0 +1,22 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/*
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * Copyright (C) 2012-2013 Kay Sievers <kay at vrfy.org>
+ * Copyright (C) 2012 Harald Hoyer <harald at redhat.com>
+ */
+
+#ifndef __SDBOOT_SPLASH_H
+#define __SDBOOT_SPLASH_H
+
+EFI_STATUS graphics_splash(UINT8 *content, UINTN len, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *background);
+#endif
diff --git a/src/boot/efi/stub.c b/src/boot/efi/stub.c
index bd39196..0b1bc49 100644
--- a/src/boot/efi/stub.c
+++ b/src/boot/efi/stub.c
@@ -19,6 +19,7 @@
 #include "util.h"
 #include "pefile.h"
 #include "graphics.h"
+#include "splash.h"
 #include "linux.h"
 
 /* magic string to find in the binary image */



More information about the systemd-commits mailing list