After discussion with Vladimir on IRC, I've brought his efigfx branch (sftp://bzr.sv.gnu.org/srv/bzr/grub/branches/efigfx/) up to date with trunk and added some more features to it. It now seems pretty good and I think it's ready to be merged. Could others review it and let us know what you think?
Here's a ChangeLog fragment for the parts I was responsible for. Vladimir said that he would write a ChangeLog for the parts he wrote (i.e. most of the branch ...). Following that is a diff of the branch against trunk. 2010-06-17 Colin Watson <cjwat...@ubuntu.com> * util/grub-mkconfig.in: Capitalise and export GRUB_PREFIX. Stop setting GRUB_VIDEO_BACKEND. Make it available as a user override instead. Replace the gfxterm backend check with a check that ${GRUB_PREFIX}/video.lst is non-empty. * util/grub.d/00_header.in: Use GRUB_PREFIX rather than computing it again. (load_video): New generated function. Call it before loading gfxterm rather than loading ${GRUB_VIDEO_BACKEND}. * util/grub.d/10_linux.in (linux_entry): Call load_video. * util/grub.d/30_os-prober.in (osx_entry): Likewise. * docs/grub.texi (Simple configuration): Document GRUB_VIDEO_BACKEND. === modified file 'conf/i386-pc.rmk' --- conf/i386-pc.rmk 2010-06-11 20:31:16 +0000 +++ conf/i386-pc.rmk 2010-06-12 10:30:21 +0000 @@ -147,7 +147,7 @@ linux_mod_CFLAGS = $(COMMON_CFLAGS) linux_mod_LDFLAGS = $(COMMON_LDFLAGS) pkglib_MODULES += xnu.mod -xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/i386/pc/xnu.c \ +xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c \ loader/macho32.c loader/macho64.c loader/macho.c loader/xnu.c xnu_mod_CFLAGS = $(COMMON_CFLAGS) xnu_mod_LDFLAGS = $(COMMON_LDFLAGS) === modified file 'conf/x86-efi.rmk' --- conf/x86-efi.rmk 2010-06-11 20:31:16 +0000 +++ conf/x86-efi.rmk 2010-06-12 10:37:26 +0000 @@ -102,7 +102,7 @@ efi_gop_mod_CFLAGS = $(COMMON_CFLAGS) efi_gop_mod_LDFLAGS = $(COMMON_LDFLAGS) pkglib_MODULES += xnu.mod -xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c loader/i386/efi/xnu.c \ +xnu_mod_SOURCES = loader/xnu_resume.c loader/i386/xnu.c \ loader/macho32.c loader/macho64.c loader/macho.c loader/xnu.c xnu_mod_CFLAGS = $(COMMON_CFLAGS) xnu_mod_LDFLAGS = $(COMMON_LDFLAGS) === modified file 'docs/grub.texi' --- docs/grub.texi 2010-06-13 12:17:23 +0000 +++ docs/grub.texi 2010-06-17 15:12:28 +0000 @@ -934,6 +934,16 @@ Disable the generation of recovery mode @item GRUB_DISABLE_NETBSD_RECOVERY Disable the generation of recovery mode menu entries for NetBSD. +...@item GRUB_VIDEO_BACKEND +If graphical video support is required, either because the @samp{gfxterm} +graphical terminal is in use or because @samp{GRUB_GFXPAYLOAD_LINUX} is set, +then @command{grub-mkconfig} will normally load all available GRUB video +drivers and use the one most appropriate for your hardware. If you need to +override this for some reason, then you can set this option. + +After @command{grub-install} has been run, the available video drivers are +listed in @file{/boot/grub/video.lst}. + @item GRUB_GFXMODE Set the resolution used on the @samp{gfxterm} graphical terminal. Note that you can only use modes which your graphics card supports via VESA BIOS === modified file 'include/grub/i386/xnu.h' --- include/grub/i386/xnu.h 2009-12-18 02:57:32 +0000 +++ include/grub/i386/xnu.h 2010-06-11 21:06:30 +0000 @@ -114,8 +114,6 @@ extern grub_uint32_t grub_xnu_stack; extern grub_uint32_t grub_xnu_arg1; extern char grub_xnu_cmdline[1024]; grub_err_t grub_xnu_boot (void); -grub_err_t grub_xnu_set_video (struct grub_xnu_boot_params *bootparams_relloc); -grub_err_t -grub_cpu_xnu_fill_devicetree (void); +grub_err_t grub_cpu_xnu_fill_devicetree (void); extern grub_uint32_t grub_xnu_heap_will_be_at; #endif === modified file 'include/grub/video.h' --- include/grub/video.h 2010-06-12 13:33:09 +0000 +++ include/grub/video.h 2010-06-12 17:49:14 +0000 @@ -183,9 +183,19 @@ typedef enum grub_video_driver_id GRUB_VIDEO_DRIVER_EFI_UGA, GRUB_VIDEO_DRIVER_EFI_GOP, GRUB_VIDEO_DRIVER_SM712, - GRUB_VIDEO_DRIVER_VGA + GRUB_VIDEO_DRIVER_VGA, + GRUB_VIDEO_DRIVER_SDL } grub_video_driver_id_t; +typedef enum grub_video_adapter_prio + { + GRUB_VIDEO_ADAPTER_PRIO_FALLBACK = 60, + GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE_DIRTY = 70, + GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE = 80, + GRUB_VIDEO_ADAPTER_PRIO_NATIVE = 100 + } grub_video_adapter_prio_t; + + struct grub_video_adapter { /* The next video adapter. */ @@ -195,6 +205,8 @@ struct grub_video_adapter const char *name; grub_video_driver_id_t id; + grub_video_adapter_prio_t prio; + /* Initialize the video adapter. */ grub_err_t (*init) (void); @@ -269,8 +281,11 @@ extern grub_video_adapter_t EXPORT_VAR(g static inline void grub_video_register (grub_video_adapter_t adapter) { - grub_list_push (GRUB_AS_LIST_P (&grub_video_adapter_list), - GRUB_AS_LIST (adapter)); + grub_video_adapter_t *p; + for (p = &grub_video_adapter_list; *p && (*p)->prio > adapter->prio; + p = &((*p)->next)); + adapter->next = *p; + *p = adapter; } #endif === modified file 'loader/i386/efi/linux.c' --- loader/i386/efi/linux.c 2010-02-10 19:27:12 +0000 +++ loader/i386/efi/linux.c 2010-06-17 15:18:08 +0000 @@ -29,10 +29,11 @@ #include <grub/cpu/linux.h> #include <grub/efi/api.h> #include <grub/efi/efi.h> -#include <grub/efi/uga_draw.h> -#include <grub/pci.h> #include <grub/command.h> #include <grub/memory.h> +#include <grub/env.h> +#include <grub/video.h> +#include <grub/time.h> #include <grub/i18n.h> #define GRUB_LINUX_CL_OFFSET 0x1000 @@ -286,6 +287,67 @@ grub_e820_add_region (struct grub_e820_m } } +static grub_err_t +grub_linux_setup_video (struct linux_kernel_params *params) +{ + struct grub_video_mode_info mode_info; + void *framebuffer; + grub_err_t err; + + err = grub_video_get_info_and_fini (&mode_info, &framebuffer); + + if (err) + return err; + + params->lfb_width = mode_info.width; + params->lfb_height = mode_info.height; + params->lfb_depth = mode_info.bpp; + params->lfb_line_len = mode_info.pitch; + + params->lfb_base = (grub_size_t) framebuffer; + params->lfb_size = ALIGN_UP (params->lfb_line_len * params->lfb_height, + 65536); + + params->red_mask_size = mode_info.red_mask_size; + params->red_field_pos = mode_info.red_field_pos; + params->green_mask_size = mode_info.green_mask_size; + params->green_field_pos = mode_info.green_field_pos; + params->blue_mask_size = mode_info.blue_mask_size; + params->blue_field_pos = mode_info.blue_field_pos; + params->reserved_mask_size = mode_info.reserved_mask_size; + params->reserved_field_pos = mode_info.reserved_field_pos; + + params->have_vga = GRUB_VIDEO_LINUX_TYPE_SIMPLE; + +#ifdef GRUB_MACHINE_PCBIOS + /* VESA packed modes may come with zeroed mask sizes, which need + to be set here according to DAC Palette width. If we don't, + this results in Linux displaying a black screen. */ + if (mode_info.bpp <= 8) + { + struct grub_vbe_info_block controller_info; + int status; + int width = 8; + + status = grub_vbe_bios_get_controller_info (&controller_info); + + if (status == GRUB_VBE_STATUS_OK && + (controller_info.capabilities & GRUB_VBE_CAPABILITY_DACWIDTH)) + status = grub_vbe_bios_set_dac_palette_width (&width); + + if (status != GRUB_VBE_STATUS_OK) + /* 6 is default after mode reset. */ + width = 6; + + params->red_mask_size = params->green_mask_size + = params->blue_mask_size = width; + params->reserved_mask_size = 0; + } +#endif + + return 0; +} + #ifdef __x86_64__ extern grub_uint8_t grub_linux_trampoline_start[]; extern grub_uint8_t grub_linux_trampoline_end[]; @@ -300,6 +362,9 @@ grub_linux_boot (void) grub_efi_uintn_t desc_size; grub_efi_uint32_t desc_version; int e820_num; + const char *modevar; + char *tmp; + grub_err_t err; params = real_mode_mem; @@ -353,6 +418,35 @@ grub_linux_boot (void) grub_mmap_iterate (hook); params->mmap_size = e820_num; + grub_printf ("Trampoline at %p. code32=%x, real_mode_mem=%p\n", + ((char *) prot_mode_mem + (prot_mode_pages << 12)), + (unsigned) params->code32_start, real_mode_mem); + + modevar = grub_env_get ("gfxpayload"); + + /* Now all graphical modes are acceptable. + May change in future if we have modes without framebuffer. */ + if (modevar && *modevar != 0) + { + tmp = grub_xasprintf ("%s;auto", modevar); + if (! tmp) + return grub_errno; + err = grub_video_set_mode (tmp, GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); + grub_free (tmp); + } + else + err = grub_video_set_mode ("auto", GRUB_VIDEO_MODE_TYPE_PURE_TEXT, 0); + + if (!err) + err = grub_linux_setup_video (params); + + if (err) + { + grub_print_error (); + grub_printf ("Booting however\n"); + grub_errno = GRUB_ERR_NONE; + } + mmap_size = find_mmap_size (); if (grub_efi_get_memory_map (&mmap_size, mmap_buf, &map_key, &desc_size, &desc_version) <= 0) @@ -425,174 +519,6 @@ grub_linux_unload (void) return GRUB_ERR_NONE; } -static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID; - - -#define RGB_MASK 0xffffff -#define RGB_MAGIC 0x121314 -#define LINE_MIN 800 -#define LINE_MAX 4096 -#define FBTEST_STEP (0x10000 >> 2) -#define FBTEST_COUNT 8 - -static int -find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) -{ - grub_uint32_t *base = (grub_uint32_t *) (grub_target_addr_t) *fb_base; - int i; - - for (i = 0; i < FBTEST_COUNT; i++, base += FBTEST_STEP) - { - if ((*base & RGB_MASK) == RGB_MAGIC) - { - int j; - - for (j = LINE_MIN; j <= LINE_MAX; j++) - { - if ((base[j] & RGB_MASK) == RGB_MAGIC) - { - *fb_base = (grub_uint32_t) (grub_target_addr_t) base; - *line_len = j << 2; - - return 1; - } - } - - break; - } - } - - return 0; -} - -static int -find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len) -{ - int found = 0; - - auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, - grub_pci_id_t pciid); - - int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, - grub_pci_id_t pciid) - { - grub_pci_address_t addr; - - addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); - if (grub_pci_read (addr) >> 24 == 0x3) - { - int i; - - grub_printf ("Display controller: %d:%d.%d\nDevice id: %x\n", - grub_pci_get_bus (dev), grub_pci_get_device (dev), - grub_pci_get_function (dev), pciid); - addr += 8; - for (i = 0; i < 6; i++, addr += 4) - { - grub_uint32_t old_bar1, old_bar2, type; - grub_uint64_t base64; - - old_bar1 = grub_pci_read (addr); - if ((! old_bar1) || (old_bar1 & GRUB_PCI_ADDR_SPACE_IO)) - continue; - - type = old_bar1 & GRUB_PCI_ADDR_MEM_TYPE_MASK; - if (type == GRUB_PCI_ADDR_MEM_TYPE_64) - { - if (i == 5) - break; - - old_bar2 = grub_pci_read (addr + 4); - } - else - old_bar2 = 0; - - base64 = old_bar2; - base64 <<= 32; - base64 |= (old_bar1 & GRUB_PCI_ADDR_MEM_MASK); - - grub_printf ("%s(%d): 0x%llx\n", - ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ? - "VMEM" : "MMIO"), i, - (unsigned long long) base64); - - if ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) && (! found)) - { - *fb_base = base64; - if (find_line_len (fb_base, line_len)) - found++; - } - - if (type == GRUB_PCI_ADDR_MEM_TYPE_64) - { - i++; - addr += 4; - } - } - } - - return found; - } - - grub_pci_iterate (find_card); - return found; -} - -static int -grub_linux_setup_video (struct linux_kernel_params *params) -{ - grub_efi_uga_draw_protocol_t *c; - grub_uint32_t width, height, depth, rate, pixel, fb_base, line_len; - int ret; - - c = grub_efi_locate_protocol (&uga_draw_guid, 0); - if (! c) - return 1; - - if (efi_call_5 (c->get_mode, c, &width, &height, &depth, &rate)) - return 1; - - grub_printf ("Video mode: %ux%u...@%u\n", width, height, depth, rate); - - grub_efi_set_text_mode (0); - pixel = RGB_MAGIC; - efi_call_10 (c->blt, c, (struct grub_efi_uga_pixel *) &pixel, - GRUB_EFI_UGA_VIDEO_FILL, 0, 0, 0, 0, 1, height, 0); - ret = find_framebuf (&fb_base, &line_len); - grub_efi_set_text_mode (1); - - if (! ret) - { - grub_printf ("Can\'t find frame buffer address\n"); - return 1; - } - - grub_printf ("Frame buffer base: 0x%x\n", fb_base); - grub_printf ("Video line length: %d\n", line_len); - - params->lfb_width = width; - params->lfb_height = height; - params->lfb_depth = depth; - params->lfb_line_len = line_len; - - params->lfb_base = fb_base; - params->lfb_size = ALIGN_UP (line_len * params->lfb_height, 65536); - - params->red_mask_size = 8; - params->red_field_pos = 16; - params->green_mask_size = 8; - params->green_field_pos = 8; - params->blue_mask_size = 8; - params->blue_field_pos = 0; - params->reserved_mask_size = 8; - params->reserved_field_pos = 24; - - params->have_vga = GRUB_VIDEO_LINUX_TYPE_VESA; - params->vid_mode = 0x338; /* 1024x768x32 */ - - return 0; -} - static grub_err_t grub_cmd_linux (grub_command_t cmd __attribute__ ((unused)), int argc, char *argv[]) @@ -809,8 +735,6 @@ grub_cmd_linux (grub_command_t cmd __att grub_printf (" [Linux-bzImage, setup=0x%x, size=0x%x]\n", (unsigned) real_size, (unsigned) prot_size); - grub_linux_setup_video (params); - /* Detect explicitly specified memory size, if any. */ linux_mem_size = 0; for (i = 1; i < argc; i++) @@ -876,7 +800,7 @@ grub_cmd_linux (grub_command_t cmd __att if (grub_errno == GRUB_ERR_NONE) { - grub_loader_set (grub_linux_boot, grub_linux_unload, 1); + grub_loader_set (grub_linux_boot, grub_linux_unload, 0); loaded = 1; } === removed file 'loader/i386/efi/xnu.c' --- loader/i386/efi/xnu.c 2010-01-20 19:40:30 +0000 +++ loader/i386/efi/xnu.c 1970-01-01 00:00:00 +0000 @@ -1,178 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <grub/env.h> -#include <grub/xnu.h> -#include <grub/cpu/xnu.h> -#include <grub/efi/api.h> -#include <grub/efi/efi.h> -#include <grub/efi/uga_draw.h> -#include <grub/pci.h> -#include <grub/misc.h> - -/* Setup video for xnu. Big parts are copied from linux.c. */ - -static grub_efi_guid_t uga_draw_guid = GRUB_EFI_UGA_DRAW_GUID; - -#define RGB_MASK 0xffffff -#define RGB_MAGIC 0x121314 -#define LINE_MIN 800 -#define LINE_MAX 4096 -#define FBTEST_STEP (0x10000 >> 2) -#define FBTEST_COUNT 8 - -static int -find_line_len (grub_uint32_t *fb_base, grub_uint32_t *line_len) -{ - grub_uint32_t *base = (grub_uint32_t *) (grub_target_addr_t) *fb_base; - int i; - - for (i = 0; i < FBTEST_COUNT; i++, base += FBTEST_STEP) - { - if ((*base & RGB_MASK) == RGB_MAGIC) - { - int j; - - for (j = LINE_MIN; j <= LINE_MAX; j++) - { - if ((base[j] & RGB_MASK) == RGB_MAGIC) - { - *fb_base = (grub_uint32_t) (grub_target_addr_t) base; - *line_len = j << 2; - - return 1; - } - } - - break; - } - } - - return 0; -} - -static int -find_framebuf (grub_uint32_t *fb_base, grub_uint32_t *line_len) -{ - int found = 0; - - auto int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, - grub_pci_id_t pciid); - - int NESTED_FUNC_ATTR find_card (grub_pci_device_t dev, - grub_pci_id_t pciid) - { - grub_pci_address_t addr; - - addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); - if (grub_pci_read (addr) >> 24 == 0x3) - { - int i; - - grub_printf ("Display controller: %d:%d.%d\nDevice id: %x\n", - grub_pci_get_bus (dev), grub_pci_get_device (dev), - grub_pci_get_function (dev), pciid); - addr += 8; - for (i = 0; i < 6; i++, addr += 4) - { - grub_uint32_t old_bar1, old_bar2, type; - grub_uint64_t base64; - - old_bar1 = grub_pci_read (addr); - if ((! old_bar1) || (old_bar1 & GRUB_PCI_ADDR_SPACE_IO)) - continue; - - type = old_bar1 & GRUB_PCI_ADDR_MEM_TYPE_MASK; - if (type == GRUB_PCI_ADDR_MEM_TYPE_64) - { - if (i == 5) - break; - - old_bar2 = grub_pci_read (addr + 4); - } - else - old_bar2 = 0; - - base64 = old_bar2; - base64 <<= 32; - base64 |= (old_bar1 & GRUB_PCI_ADDR_MEM_MASK); - - grub_printf ("%s(%d): 0x%llx\n", - ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) ? - "VMEM" : "MMIO"), i, - (unsigned long long) base64); - - if ((old_bar1 & GRUB_PCI_ADDR_MEM_PREFETCH) && (! found)) - { - *fb_base = base64; - if (find_line_len (fb_base, line_len)) - found++; - } - - if (type == GRUB_PCI_ADDR_MEM_TYPE_64) - { - i++; - addr += 4; - } - } - } - - return found; - } - - grub_pci_iterate (find_card); - return found; -} - -grub_err_t -grub_xnu_set_video (struct grub_xnu_boot_params *params) -{ - grub_efi_uga_draw_protocol_t *c; - grub_uint32_t width, height, depth, rate, pixel, fb_base, line_len; - int ret; - - c = grub_efi_locate_protocol (&uga_draw_guid, 0); - if (! c) - return grub_error (GRUB_ERR_IO, "couldn't find UGADraw"); - - if (efi_call_5 (c->get_mode, c, &width, &height, &depth, &rate)) - return grub_error (GRUB_ERR_IO, "couldn't retrieve video mode"); - - grub_printf ("Video mode: %ux%u...@%u\n", width, height, depth, rate); - - grub_efi_set_text_mode (0); - pixel = RGB_MAGIC; - efi_call_10 (c->blt, c, (struct grub_efi_uga_pixel *) &pixel, - GRUB_EFI_UGA_VIDEO_FILL, 0, 0, 0, 0, 1, height, 0); - ret = find_framebuf (&fb_base, &line_len); - grub_efi_set_text_mode (1); - - if (! ret) - return grub_error (GRUB_ERR_IO, "can\'t find frame buffer address"); - - grub_printf ("Frame buffer base: 0x%x\n", fb_base); - grub_printf ("Video line length: %d\n", line_len); - - params->lfb_width = width; - params->lfb_height = height; - params->lfb_depth = depth; - params->lfb_line_len = line_len; - params->lfb_mode = GRUB_XNU_VIDEO_TEXT_IN_VIDEO; - params->lfb_base = fb_base; - return GRUB_ERR_NONE; -} === removed file 'loader/i386/pc/xnu.c' --- loader/i386/pc/xnu.c 2010-02-06 15:32:45 +0000 +++ loader/i386/pc/xnu.c 1970-01-01 00:00:00 +0000 @@ -1,123 +0,0 @@ -/* - * GRUB -- GRand Unified Bootloader - * Copyright (C) 2009 Free Software Foundation, Inc. - * - * GRUB is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GRUB 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GRUB. If not, see <http://www.gnu.org/licenses/>. - */ - -#include <grub/env.h> -#include <grub/misc.h> -#include <grub/xnu.h> -#include <grub/mm.h> -#include <grub/cpu/xnu.h> -#include <grub/video_fb.h> -#include <grub/bitmap_scale.h> - -#define min(a,b) (((a) < (b)) ? (a) : (b)) -#define max(a,b) (((a) > (b)) ? (a) : (b)) - -#define DEFAULT_VIDEO_MODE "auto" - -/* Setup video for xnu. */ -grub_err_t -grub_xnu_set_video (struct grub_xnu_boot_params *params) -{ - struct grub_video_mode_info mode_info; - int ret; - char *tmp; - const char *modevar; - void *framebuffer; - grub_err_t err; - struct grub_video_bitmap *bitmap = NULL; - - modevar = grub_env_get ("gfxpayload"); - /* Consider only graphical 32-bit deep modes. */ - if (! modevar || *modevar == 0) - err = grub_video_set_mode (DEFAULT_VIDEO_MODE, - GRUB_VIDEO_MODE_TYPE_PURE_TEXT - | GRUB_VIDEO_MODE_TYPE_DEPTH_MASK, - 32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS); - else - { - tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar); - if (! tmp) - return grub_errno; - err = grub_video_set_mode (tmp, - GRUB_VIDEO_MODE_TYPE_PURE_TEXT - | GRUB_VIDEO_MODE_TYPE_DEPTH_MASK, - 32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS); - grub_free (tmp); - } - - if (err) - return err; - - ret = grub_video_get_info (&mode_info); - if (ret) - return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters"); - - if (grub_xnu_bitmap) - { - if (grub_xnu_bitmap_mode == GRUB_XNU_BITMAP_STRETCH) - err = grub_video_bitmap_create_scaled (&bitmap, - mode_info.width, - mode_info.height, - grub_xnu_bitmap, - GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); - else - bitmap = grub_xnu_bitmap; - } - - if (bitmap) - { - int x, y; - - x = mode_info.width - bitmap->mode_info.width; - x /= 2; - y = mode_info.height - bitmap->mode_info.height; - y /= 2; - err = grub_video_blit_bitmap (bitmap, - GRUB_VIDEO_BLIT_REPLACE, - x > 0 ? x : 0, - y > 0 ? y : 0, - x < 0 ? -x : 0, - y < 0 ? -y : 0, - min (bitmap->mode_info.width, - mode_info.width), - min (bitmap->mode_info.height, - mode_info.height)); - } - if (err) - { - grub_print_error (); - grub_errno = GRUB_ERR_NONE; - bitmap = 0; - } - - ret = grub_video_get_info_and_fini (&mode_info, &framebuffer); - if (ret) - return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters"); - - params->lfb_width = mode_info.width; - params->lfb_height = mode_info.height; - params->lfb_depth = mode_info.bpp; - params->lfb_line_len = mode_info.pitch; - - params->lfb_base = PTR_TO_UINT32 (framebuffer); - params->lfb_mode = bitmap ? GRUB_XNU_VIDEO_SPLASH - : GRUB_XNU_VIDEO_TEXT_IN_VIDEO; - - return GRUB_ERR_NONE; -} - === modified file 'loader/i386/xnu.c' --- loader/i386/xnu.c 2010-01-20 06:36:17 +0000 +++ loader/i386/xnu.c 2010-06-12 10:44:55 +0000 @@ -33,6 +33,12 @@ #include <grub/command.h> #include <grub/gzio.h> #include <grub/i18n.h> +#include <grub/bitmap_scale.h> + +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#define max(a,b) (((a) > (b)) ? (a) : (b)) + +#define DEFAULT_VIDEO_MODE "auto" char grub_xnu_cmdline[1024]; grub_uint32_t grub_xnu_heap_will_be_at; @@ -838,6 +844,98 @@ grub_xnu_boot_resume (void) state); } +/* Setup video for xnu. */ +static grub_err_t +grub_xnu_set_video (struct grub_xnu_boot_params *params) +{ + struct grub_video_mode_info mode_info; + int ret; + char *tmp; + const char *modevar; + void *framebuffer; + grub_err_t err; + struct grub_video_bitmap *bitmap = NULL; + + modevar = grub_env_get ("gfxpayload"); + /* Consider only graphical 32-bit deep modes. */ + if (! modevar || *modevar == 0) + err = grub_video_set_mode (DEFAULT_VIDEO_MODE, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT + | GRUB_VIDEO_MODE_TYPE_DEPTH_MASK, + 32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS); + else + { + tmp = grub_xasprintf ("%s;" DEFAULT_VIDEO_MODE, modevar); + if (! tmp) + return grub_errno; + err = grub_video_set_mode (tmp, + GRUB_VIDEO_MODE_TYPE_PURE_TEXT + | GRUB_VIDEO_MODE_TYPE_DEPTH_MASK, + 32 << GRUB_VIDEO_MODE_TYPE_DEPTH_POS); + grub_free (tmp); + } + + if (err) + return err; + + ret = grub_video_get_info (&mode_info); + if (ret) + return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters"); + + if (grub_xnu_bitmap) + { + if (grub_xnu_bitmap_mode == GRUB_XNU_BITMAP_STRETCH) + err = grub_video_bitmap_create_scaled (&bitmap, + mode_info.width, + mode_info.height, + grub_xnu_bitmap, + GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); + else + bitmap = grub_xnu_bitmap; + } + + if (bitmap) + { + int x, y; + + x = mode_info.width - bitmap->mode_info.width; + x /= 2; + y = mode_info.height - bitmap->mode_info.height; + y /= 2; + err = grub_video_blit_bitmap (bitmap, + GRUB_VIDEO_BLIT_REPLACE, + x > 0 ? x : 0, + y > 0 ? y : 0, + x < 0 ? -x : 0, + y < 0 ? -y : 0, + min (bitmap->mode_info.width, + mode_info.width), + min (bitmap->mode_info.height, + mode_info.height)); + } + if (err) + { + grub_print_error (); + grub_errno = GRUB_ERR_NONE; + bitmap = 0; + } + + ret = grub_video_get_info_and_fini (&mode_info, &framebuffer); + if (ret) + return grub_error (GRUB_ERR_IO, "couldn't retrieve video parameters"); + + params->lfb_width = mode_info.width; + params->lfb_height = mode_info.height; + params->lfb_depth = mode_info.bpp; + params->lfb_line_len = mode_info.pitch; + + params->lfb_base = PTR_TO_UINT32 (framebuffer); + params->lfb_mode = bitmap ? GRUB_XNU_VIDEO_SPLASH + : GRUB_XNU_VIDEO_TEXT_IN_VIDEO; + + return GRUB_ERR_NONE; +} + /* Boot xnu. */ grub_err_t grub_xnu_boot (void) === modified file 'util/grub-mkconfig.in' --- util/grub-mkconfig.in 2010-06-16 11:51:26 +0000 +++ util/grub-mkconfig.in 2010-06-17 15:12:28 +0000 @@ -96,11 +96,11 @@ case "$host_os" in netbsd* | openbsd*) # Because /boot is used for the boot block in NetBSD and OpenBSD, use /grub # instead of /boot/grub. - grub_prefix=`echo /grub | sed ${transform}` + GRUB_PREFIX=`echo /grub | sed ${transform}` ;; *) # Use /boot/grub by default. - grub_prefix=`echo /boot/grub | sed ${transform}` + GRUB_PREFIX=`echo /boot/grub | sed ${transform}` ;; esac @@ -141,9 +141,9 @@ else exit 1 fi -mkdir -p ${grub_prefix} +mkdir -p ${GRUB_PREFIX} -if test -e ${grub_prefix}/device.map ; then : ; else +if test -e ${GRUB_PREFIX}/device.map ; then : ; else ${grub_mkdevicemap} fi @@ -178,17 +178,14 @@ fi for x in ${GRUB_TERMINAL_OUTPUT}; do if [ "x${x}" = "xgfxterm" ]; then # If this platform supports gfxterm, try to use it. - if ! test -e ${grub_prefix}/gfxterm.mod ; then + if ! test -e ${GRUB_PREFIX}/gfxterm.mod ; then if [ "x$termoutdefault" != "x1" ]; then echo "gfxterm isn't available on your platform" >&2 ; exit 1 fi GRUB_TERMINAL_OUTPUT= break; fi - # FIXME: this should do something smarter than just loading first - # video backend. - GRUB_VIDEO_BACKEND=$(head -n 1 ${grub_prefix}/video.lst || true) - if [ -z "${GRUB_VIDEO_BACKEND}" ] ; then + if [ ! -s "${GRUB_PREFIX}/video.lst" ] ; then if [ "x$termoutdefault" != "x1" ]; then echo "No suitable backend could be found for gfxterm." >&2 ; exit 1 fi @@ -246,7 +243,7 @@ export GRUB_DEVICE \ GRUB_FS \ GRUB_FONT_PATH \ GRUB_PRELOAD_MODULES \ - GRUB_VIDEO_BACKEND + GRUB_PREFIX # These are optional, user-defined variables. export GRUB_DEFAULT \ @@ -268,6 +265,7 @@ export GRUB_DEFAULT \ GRUB_DISABLE_LINUX_UUID \ GRUB_DISABLE_LINUX_RECOVERY \ GRUB_DISABLE_NETBSD_RECOVERY \ + GRUB_VIDEO_BACKEND \ GRUB_GFXMODE \ GRUB_BACKGROUND \ GRUB_THEME \ === modified file 'util/grub.d/00_header.in' --- util/grub.d/00_header.in 2010-06-07 13:22:40 +0000 +++ util/grub.d/00_header.in 2010-06-17 14:52:56 +0000 @@ -21,8 +21,7 @@ transform="@program_transform_name@" pref...@prefix@ exec_pref...@exec_prefix@ libd...@libdir@ -grub_prefix=`echo /boot/grub | sed ${transform}` -locale_dir=`echo /boot/grub/locale | sed ${transform}` +locale_dir=`echo ${GRUB_PREFIX}/locale | sed ${transform}` grub_lang=`echo $LANG | cut -d _ -f 1` . ${libdir}/grub/grub-mkconfig_lib @@ -75,6 +74,24 @@ function savedefault { save_env saved_entry fi } + +function load_video { +EOF +if [ -n "${GRUB_VIDEO_BACKEND}" ]; then + cat <<EOF + insmod ${GRUB_VIDEO_BACKEND} +EOF +else + # Insert all available backends; GRUB will use the most appropriate. + for backend in $(cat "${GRUB_PREFIX}/video.lst"); do + cat <<EOF + insmod ${backend} +EOF + done +fi +cat <<EOF +} + EOF serial=0; @@ -89,7 +106,7 @@ for x in ${GRUB_TERMINAL_INPUT} ${GRUB_T done if [ "x$serial" = x1 ]; then - if ! test -e ${grub_prefix}/serial.mod ; then + if ! test -e ${GRUB_PREFIX}/serial.mod ; then echo "Serial terminal not available on this platform." >&2 ; exit 1 fi @@ -107,8 +124,8 @@ if [ "x$gfxterm" = x1 ]; then cat << EOF if loadfont `make_system_path_relative_to_its_root "${GRUB_FONT_PATH}"` ; then set gfxmode=${GRUB_GFXMODE} + load_video insmod gfxterm - insmod ${GRUB_VIDEO_BACKEND} EOF if [ "x$GRUB_THEME" != x ] && [ -f "$GRUB_THEME" ] \ && is_path_readable_by_grub "$GRUB_THEME"; then === modified file 'util/grub.d/10_linux.in' --- util/grub.d/10_linux.in 2010-06-09 18:43:25 +0000 +++ util/grub.d/10_linux.in 2010-06-17 14:44:43 +0000 @@ -66,6 +66,9 @@ linux_entry () # Use ELILO's generic "efifb" when it's known to be available. # FIXME: We need an interface to select vesafb in case efifb can't be used. if [ "x$GRUB_GFXPAYLOAD_LINUX" = x ]; then + cat << EOF + load_video +EOF if grep -qx "CONFIG_FB_EFI=y" /boot/config-${version} 2> /dev/null \ && grep -qx "CONFIG_VT_HW_CONSOLE_BINDING=y" /boot/config-${version} 2> /dev/null; then cat << EOF === modified file 'util/grub.d/30_os-prober.in' --- util/grub.d/30_os-prober.in 2010-02-03 00:24:07 +0000 +++ util/grub.d/30_os-prober.in 2010-06-17 14:18:39 +0000 @@ -44,7 +44,7 @@ EOF save_default_entry | sed -e "s/^/\t/" prepare_grub_to_access_device ${DEVICE} | sed -e "s/^/\t/" cat << EOF - insmod ${GRUB_VIDEO_BACKEND} + load_video set do_resume=0 if [ /var/vm/sleepimage -nt10 / ]; then if xnu_resume /var/vm/sleepimage; then === modified file 'video/efi_gop.c' --- video/efi_gop.c 2010-03-07 12:01:43 +0000 +++ video/efi_gop.c 2010-06-12 17:49:14 +0000 @@ -355,6 +355,8 @@ static struct grub_video_adapter grub_vi .name = "EFI GOP driver", .id = GRUB_VIDEO_DRIVER_EFI_GOP, + .prio = GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE, + .init = grub_video_gop_init, .fini = grub_video_gop_fini, .setup = grub_video_gop_setup, === modified file 'video/efi_uga.c' --- video/efi_uga.c 2010-03-07 12:01:43 +0000 +++ video/efi_uga.c 2010-06-12 17:49:14 +0000 @@ -302,6 +302,8 @@ static struct grub_video_adapter grub_vi .name = "EFI UGA driver", .id = GRUB_VIDEO_DRIVER_EFI_UGA, + .prio = GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE_DIRTY, + .init = grub_video_uga_init, .fini = grub_video_uga_fini, .setup = grub_video_uga_setup, === modified file 'video/emu/sdl.c' --- video/emu/sdl.c 2010-04-27 05:20:28 +0000 +++ video/emu/sdl.c 2010-06-12 17:49:14 +0000 @@ -200,6 +200,9 @@ grub_video_sdl_set_active_render_target static struct grub_video_adapter grub_video_sdl_adapter = { .name = "SDL Video Driver", + .id = GRUB_VIDEO_DRIVER_SDL, + + .prio = GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE, .init = grub_video_sdl_init, .fini = grub_video_sdl_fini, === modified file 'video/i386/pc/vbe.c' --- video/i386/pc/vbe.c 2010-03-07 12:01:43 +0000 +++ video/i386/pc/vbe.c 2010-06-12 17:49:14 +0000 @@ -783,6 +783,8 @@ static struct grub_video_adapter grub_vi .name = "VESA BIOS Extension Video Driver", .id = GRUB_VIDEO_DRIVER_VBE, + .prio = GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE, + .init = grub_video_vbe_init, .fini = grub_video_vbe_fini, .setup = grub_video_vbe_setup, === modified file 'video/i386/pc/vga.c' --- video/i386/pc/vga.c 2010-05-09 09:00:21 +0000 +++ video/i386/pc/vga.c 2010-06-12 17:49:14 +0000 @@ -375,6 +375,8 @@ static struct grub_video_adapter grub_vi .name = "VGA Video Driver", .id = GRUB_VIDEO_DRIVER_VGA, + .prio = GRUB_VIDEO_ADAPTER_PRIO_FALLBACK, + .init = grub_video_vga_init, .fini = grub_video_vga_fini, .setup = grub_video_vga_setup, === modified file 'video/ieee1275.c' --- video/ieee1275.c 2010-03-14 15:32:50 +0000 +++ video/ieee1275.c 2010-06-12 17:49:14 +0000 @@ -254,6 +254,8 @@ static struct grub_video_adapter grub_vi { .name = "IEEE1275 video driver", + .prio = GRUB_VIDEO_ADAPTER_PRIO_FIRMWARE, + .init = grub_video_ieee1275_init, .fini = grub_video_ieee1275_fini, .setup = grub_video_ieee1275_setup, === modified file 'video/sm712.c' --- video/sm712.c 2010-04-03 12:12:43 +0000 +++ video/sm712.c 2010-06-12 17:49:14 +0000 @@ -193,6 +193,8 @@ static struct grub_video_adapter grub_vi .name = "SM712 Video Driver", .id = GRUB_VIDEO_DRIVER_SM712, + .prio = GRUB_VIDEO_ADAPTER_PRIO_NATIVE, + .init = grub_video_sm712_video_init, .fini = grub_video_sm712_video_fini, .setup = grub_video_sm712_setup, -- Colin Watson [cjwat...@ubuntu.com] _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org http://lists.gnu.org/mailman/listinfo/grub-devel