diff --git a/configure.ac b/configure.ac index fbe1e57e8..51dbe3867 100644 --- a/configure.ac +++ b/configure.ac @@ -1098,6 +1098,17 @@ else fi AC_SUBST([QUICK_BOOT]) +AC_ARG_ENABLE([gfxpayload-dynamic], + [AS_HELP_STRING([--enable-gfxpayload-dynamic], + [use GRUB_GFXPAYLOAD_LINUX=keep unless explicitly unsupported on current hardware (default=no)])], + [], [enable_gfxpayload_dynamic=no]) +if test x"$enable_gfxpayload_dynamic" = xyes ; then + GFXPAYLOAD_DYNAMIC=1 +else + GFXPAYLOAD_DYNAMIC=0 +fi +AC_SUBST([GFXPAYLOAD_DYNAMIC]) + LIBS="" AC_SUBST([FONT_SOURCE]) diff --git a/debian/changelog b/debian/changelog index 43add23db..b580d761e 100644 --- a/debian/changelog +++ b/debian/changelog @@ -18,6 +18,8 @@ grub2 (2.00-20) UNRELEASED; urgency=low - If building for Ubuntu: + Bypass menu unless other OSes are installed or Shift is pressed. + Show the boot menu if the previous boot failed. + + Set GRUB_GFXPAYLOAD_LINUX=keep unless it's known to be unsupported + on the current hardware. -- Colin Watson Mon, 07 Oct 2013 09:48:53 +0100 diff --git a/debian/control b/debian/control index 294c36236..4f032fe56 100644 --- a/debian/control +++ b/debian/control @@ -152,7 +152,7 @@ Description: GRand Unified Bootloader, version 2 (PC/BIOS debug files) Package: grub-pc Priority: optional Architecture: any-i386 any-amd64 -Depends: ${shlibs:Depends}, ${misc:Depends}, grub2-common (= ${binary:Version}), grub-pc-bin (= ${binary:Version}), ucf, freebsd-utils (>= 8.0-4) [kfreebsd-any] +Depends: ${shlibs:Depends}, ${misc:Depends}, grub2-common (= ${binary:Version}), grub-pc-bin (= ${binary:Version}), ucf, freebsd-utils (>= 8.0-4) [kfreebsd-any], ${gfxpayload-depends} Replaces: grub, grub-legacy, grub2 (<< ${source:Version}), grub-common (<= 1.97~beta2-1), grub-efi-amd64, grub-efi-ia32, grub-coreboot, grub-ieee1275 Conflicts: grub (<< 0.97-54), grub-legacy, grub-efi-amd64, grub-efi-ia32, grub-coreboot, grub-ieee1275 Multi-Arch: foreign diff --git a/debian/patches/gfxpayload_dynamic.patch b/debian/patches/gfxpayload_dynamic.patch new file mode 100644 index 000000000..fe889a440 --- /dev/null +++ b/debian/patches/gfxpayload_dynamic.patch @@ -0,0 +1,256 @@ +Description: Add configure option to enable gfxpayload=keep dynamically + Set GRUB_GFXPAYLOAD_LINUX=keep unless it's known to be unsupported on the + current hardware. See + https://blueprints.launchpad.net/ubuntu/+spec/packageselection-foundations-n-grub2-boot-framebuffer. +Author: Evan Broder +Author: Colin Watson +Forwarded: no +Last-Update: 2013-11-13 + +Index: b/configure.ac +=================================================================== +--- a/configure.ac ++++ b/configure.ac +@@ -1098,6 +1098,17 @@ + fi + AC_SUBST([QUICK_BOOT]) + ++AC_ARG_ENABLE([gfxpayload-dynamic], ++ [AS_HELP_STRING([--enable-gfxpayload-dynamic], ++ [use GRUB_GFXPAYLOAD_LINUX=keep unless explicitly unsupported on current hardware (default=no)])], ++ [], [enable_gfxpayload_dynamic=no]) ++if test x"$enable_gfxpayload_dynamic" = xyes ; then ++ GFXPAYLOAD_DYNAMIC=1 ++else ++ GFXPAYLOAD_DYNAMIC=0 ++fi ++AC_SUBST([GFXPAYLOAD_DYNAMIC]) ++ + LIBS="" + + AC_SUBST([FONT_SOURCE]) +Index: b/grub-core/Makefile.core.def +=================================================================== +--- a/grub-core/Makefile.core.def ++++ b/grub-core/Makefile.core.def +@@ -704,6 +704,15 @@ + }; + + module = { ++ name = hwmatch; ++ i386_pc = commands/i386/pc/hwmatch.c; ++ enable = i386_pc; ++ ldadd = libgnulib.a; ++ cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; ++ cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)'; ++}; ++ ++module = { + name = keystatus; + common = commands/keystatus.c; + }; +Index: b/grub-core/commands/i386/pc/hwmatch.c +=================================================================== +--- /dev/null ++++ b/grub-core/commands/i386/pc/hwmatch.c +@@ -0,0 +1,141 @@ ++/* hwmatch.c - Match hardware against a whitelist/blacklist. */ ++/* ++ * GRUB -- GRand Unified Bootloader ++ * Copyright (C) 2011 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 . ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++GRUB_MOD_LICENSE ("GPLv3+"); ++ ++static grub_err_t ++grub_cmd_hwmatch (grub_command_t cmd __attribute__ ((unused)), ++ int argc, char **args) ++{ ++ grub_file_t matches_file; ++ int class_match; ++ int match = 0; ++ char *match_str; ++ ++ auto int NESTED_FUNC_ATTR hwmatch_iter (grub_pci_device_t dev, ++ grub_pci_id_t pciid); ++ ++ int NESTED_FUNC_ATTR hwmatch_iter (grub_pci_device_t dev, ++ grub_pci_id_t pciid) ++ { ++ grub_pci_address_t addr; ++ grub_uint32_t class, baseclass, vendor, device; ++ grub_pci_id_t subpciid; ++ grub_uint32_t subvendor, subdevice, subclass; ++ char *id, *line; ++ ++ addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); ++ class = grub_pci_read (addr); ++ baseclass = class >> 24; ++ ++ if (class_match != baseclass) ++ return 0; ++ ++ vendor = pciid & 0xffff; ++ device = pciid >> 16; ++ ++ addr = grub_pci_make_address (dev, GRUB_PCI_REG_SUBVENDOR); ++ subpciid = grub_pci_read (addr); ++ ++ subclass = (class >> 16) & 0xff; ++ subvendor = subpciid & 0xffff; ++ subdevice = subpciid >> 16; ++ ++ id = grub_xasprintf ("v%04xd%04xsv%04xsd%04xbc%02xsc%02x", ++ vendor, device, subvendor, subdevice, ++ baseclass, subclass); ++ ++ grub_file_seek (matches_file, 0); ++ while ((line = grub_file_getline (matches_file)) != NULL) ++ { ++ char *anchored_line; ++ regex_t regex; ++ int ret; ++ ++ if (! *line || *line == '#') ++ { ++ grub_free (line); ++ continue; ++ } ++ ++ anchored_line = grub_xasprintf ("^%s$", line); ++ ret = regcomp (®ex, anchored_line, REG_EXTENDED | REG_NOSUB); ++ grub_free (anchored_line); ++ if (ret) ++ { ++ grub_free (line); ++ continue; ++ } ++ ++ ret = regexec (®ex, id, 0, NULL, 0); ++ regfree (®ex); ++ grub_free (line); ++ if (! ret) ++ { ++ match = 1; ++ return 1; ++ } ++ } ++ ++ return 0; ++ } ++ ++ if (argc < 2) ++ return grub_error (GRUB_ERR_BAD_ARGUMENT, "list file and class required"); ++ ++ matches_file = grub_file_open (args[0]); ++ if (! matches_file) ++ return grub_errno; ++ ++ class_match = grub_strtol (args[1], 0, 10); ++ ++ grub_pci_iterate (hwmatch_iter); ++ ++ match_str = grub_xasprintf ("%d", match); ++ grub_env_set ("match", match_str); ++ grub_free (match_str); ++ ++ grub_file_close (matches_file); ++ ++ return GRUB_ERR_NONE; ++} ++ ++static grub_command_t cmd; ++ ++GRUB_MOD_INIT(hwmatch) ++{ ++ cmd = grub_register_command ("hwmatch", grub_cmd_hwmatch, ++ N_("MATCHES-FILE CLASS"), ++ N_("Match PCI devices.")); ++} ++ ++GRUB_MOD_FINI(hwmatch) ++{ ++ grub_unregister_command (cmd); ++} +Index: b/util/grub.d/10_linux.in +=================================================================== +--- a/util/grub.d/10_linux.in ++++ b/util/grub.d/10_linux.in +@@ -22,6 +22,7 @@ + datarootdir="@datarootdir@" + quiet_boot="@QUIET_BOOT@" + quick_boot="@QUICK_BOOT@" ++gfxpayload_dynamic="@GFXPAYLOAD_DYNAMIC@" + + . "@datadir@/@PACKAGE@/grub-mkconfig_lib" + +@@ -129,7 +130,9 @@ + if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then + echo " load_video" | sed "s/^/$submenu_indentation/" + fi +- echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/" ++ fi ++ if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 1 ]; then ++ echo " set gfxpayload=\$linux_gfx_mode" | sed "s/^/$submenu_indentation/" + fi + + echo " insmod gzio" | sed "s/^/$submenu_indentation/" +@@ -202,6 +205,35 @@ + boot_device_id= + title_correction_code= + ++# 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 ] || [ "$gfxpayload_dynamic" = 0 ]; then ++ echo "set linux_gfx_mode=$GRUB_GFXPAYLOAD_LINUX" ++else ++ cat << EOF ++if [ "\${recordfail}" != 1 ]; then ++ if [ -e \${prefix}/gfxblacklist.txt ]; then ++ if hwmatch \${prefix}/gfxblacklist.txt 3; then ++ if [ \${match} = 0 ]; then ++ set linux_gfx_mode=keep ++ else ++ set linux_gfx_mode=text ++ fi ++ else ++ set linux_gfx_mode=text ++ fi ++ else ++ set linux_gfx_mode=keep ++ fi ++else ++ set linux_gfx_mode=text ++fi ++EOF ++fi ++cat << EOF ++export linux_gfx_mode ++EOF ++ + # Extra indentation to add to menu entries in a submenu. We're not in a submenu + # yet, so it's empty. In a submenu it will be equal to '\t' (one tab). + submenu_indentation="" diff --git a/debian/patches/series b/debian/patches/series index d0d05a1f0..196c83314 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -58,3 +58,4 @@ mkconfig_hurd_sort.patch probe_dmraid.patch install_efi_ubuntu_flavours.patch quick_boot.patch +gfxpayload_dynamic.patch diff --git a/debian/rules b/debian/rules index 1a7d2e721..8f6355371 100755 --- a/debian/rules +++ b/debian/rules @@ -54,8 +54,13 @@ endif ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes)) DEFAULT_CMDLINE := quiet splash -confflags += --enable-quiet-boot --enable-quick-boot -substvars := -Vlsb-base-depends="lsb-base (>= 3.0-6)" +confflags += \ + --enable-quiet-boot \ + --enable-quick-boot \ + --enable-gfxpayload-dynamic +substvars := \ + -Vlsb-base-depends="lsb-base (>= 3.0-6)" \ + -Vgfxpayload-depends="grub-gfxpayload-lists [any-i386 any-amd64]" else DEFAULT_CMDLINE := quiet substvars := diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 22ab7e012..74930a341 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -703,6 +703,15 @@ module = { common = lib/hexdump.c; }; +module = { + name = hwmatch; + i386_pc = commands/i386/pc/hwmatch.c; + enable = i386_pc; + ldadd = libgnulib.a; + cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)'; + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)'; +}; + module = { name = keystatus; common = commands/keystatus.c; diff --git a/grub-core/commands/i386/pc/hwmatch.c b/grub-core/commands/i386/pc/hwmatch.c new file mode 100644 index 000000000..5627eb41d --- /dev/null +++ b/grub-core/commands/i386/pc/hwmatch.c @@ -0,0 +1,141 @@ +/* hwmatch.c - Match hardware against a whitelist/blacklist. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2011 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 . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +GRUB_MOD_LICENSE ("GPLv3+"); + +static grub_err_t +grub_cmd_hwmatch (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) +{ + grub_file_t matches_file; + int class_match; + int match = 0; + char *match_str; + + auto int NESTED_FUNC_ATTR hwmatch_iter (grub_pci_device_t dev, + grub_pci_id_t pciid); + + int NESTED_FUNC_ATTR hwmatch_iter (grub_pci_device_t dev, + grub_pci_id_t pciid) + { + grub_pci_address_t addr; + grub_uint32_t class, baseclass, vendor, device; + grub_pci_id_t subpciid; + grub_uint32_t subvendor, subdevice, subclass; + char *id, *line; + + addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS); + class = grub_pci_read (addr); + baseclass = class >> 24; + + if (class_match != baseclass) + return 0; + + vendor = pciid & 0xffff; + device = pciid >> 16; + + addr = grub_pci_make_address (dev, GRUB_PCI_REG_SUBVENDOR); + subpciid = grub_pci_read (addr); + + subclass = (class >> 16) & 0xff; + subvendor = subpciid & 0xffff; + subdevice = subpciid >> 16; + + id = grub_xasprintf ("v%04xd%04xsv%04xsd%04xbc%02xsc%02x", + vendor, device, subvendor, subdevice, + baseclass, subclass); + + grub_file_seek (matches_file, 0); + while ((line = grub_file_getline (matches_file)) != NULL) + { + char *anchored_line; + regex_t regex; + int ret; + + if (! *line || *line == '#') + { + grub_free (line); + continue; + } + + anchored_line = grub_xasprintf ("^%s$", line); + ret = regcomp (®ex, anchored_line, REG_EXTENDED | REG_NOSUB); + grub_free (anchored_line); + if (ret) + { + grub_free (line); + continue; + } + + ret = regexec (®ex, id, 0, NULL, 0); + regfree (®ex); + grub_free (line); + if (! ret) + { + match = 1; + return 1; + } + } + + return 0; + } + + if (argc < 2) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "list file and class required"); + + matches_file = grub_file_open (args[0]); + if (! matches_file) + return grub_errno; + + class_match = grub_strtol (args[1], 0, 10); + + grub_pci_iterate (hwmatch_iter); + + match_str = grub_xasprintf ("%d", match); + grub_env_set ("match", match_str); + grub_free (match_str); + + grub_file_close (matches_file); + + return GRUB_ERR_NONE; +} + +static grub_command_t cmd; + +GRUB_MOD_INIT(hwmatch) +{ + cmd = grub_register_command ("hwmatch", grub_cmd_hwmatch, + N_("MATCHES-FILE CLASS"), + N_("Match PCI devices.")); +} + +GRUB_MOD_FINI(hwmatch) +{ + grub_unregister_command (cmd); +} diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in index 20d1979d8..c04bda5de 100644 --- a/util/grub.d/10_linux.in +++ b/util/grub.d/10_linux.in @@ -22,6 +22,7 @@ exec_prefix="@exec_prefix@" datarootdir="@datarootdir@" quiet_boot="@QUIET_BOOT@" quick_boot="@QUICK_BOOT@" +gfxpayload_dynamic="@GFXPAYLOAD_DYNAMIC@" . "@datadir@/@PACKAGE@/grub-mkconfig_lib" @@ -129,7 +130,9 @@ linux_entry () if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then echo " load_video" | sed "s/^/$submenu_indentation/" fi - echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/" + fi + if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 1 ]; then + echo " set gfxpayload=\$linux_gfx_mode" | sed "s/^/$submenu_indentation/" fi echo " insmod gzio" | sed "s/^/$submenu_indentation/" @@ -202,6 +205,35 @@ prepare_root_cache= boot_device_id= title_correction_code= +# 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 ] || [ "$gfxpayload_dynamic" = 0 ]; then + echo "set linux_gfx_mode=$GRUB_GFXPAYLOAD_LINUX" +else + cat << EOF +if [ "\${recordfail}" != 1 ]; then + if [ -e \${prefix}/gfxblacklist.txt ]; then + if hwmatch \${prefix}/gfxblacklist.txt 3; then + if [ \${match} = 0 ]; then + set linux_gfx_mode=keep + else + set linux_gfx_mode=text + fi + else + set linux_gfx_mode=text + fi + else + set linux_gfx_mode=keep + fi +else + set linux_gfx_mode=text +fi +EOF +fi +cat << EOF +export linux_gfx_mode +EOF + # Extra indentation to add to menu entries in a submenu. We're not in a submenu # yet, so it's empty. In a submenu it will be equal to '\t' (one tab). submenu_indentation=""