Set GRUB_GFXPAYLOAD_LINUX=keep unless it's known to be unsupported on the current hardware.

This commit is contained in:
Colin Watson 2013-11-13 00:21:54 +00:00 committed by Colin Watson
parent a2dac38edc
commit f5a925fbd7
9 changed files with 461 additions and 4 deletions

View File

@ -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])

2
debian/changelog vendored
View File

@ -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 <cjwatson@debian.org> Mon, 07 Oct 2013 09:48:53 +0100

2
debian/control vendored
View File

@ -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

256
debian/patches/gfxpayload_dynamic.patch vendored Normal file
View File

@ -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 <evan@ebroder.net>
Author: Colin Watson <cjwatson@ubuntu.com>
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 <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/dl.h>
+#include <grub/misc.h>
+#include <grub/command.h>
+#include <grub/pci.h>
+#include <grub/normal.h>
+#include <grub/file.h>
+#include <grub/env.h>
+#include <grub/i18n.h>
+#include <regex.h>
+
+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 (&regex, anchored_line, REG_EXTENDED | REG_NOSUB);
+ grub_free (anchored_line);
+ if (ret)
+ {
+ grub_free (line);
+ continue;
+ }
+
+ ret = regexec (&regex, id, 0, NULL, 0);
+ regfree (&regex);
+ 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=""

View File

@ -58,3 +58,4 @@ mkconfig_hurd_sort.patch
probe_dmraid.patch
install_efi_ubuntu_flavours.patch
quick_boot.patch
gfxpayload_dynamic.patch

9
debian/rules vendored
View File

@ -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 :=

View File

@ -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;

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <grub/dl.h>
#include <grub/misc.h>
#include <grub/command.h>
#include <grub/pci.h>
#include <grub/normal.h>
#include <grub/file.h>
#include <grub/env.h>
#include <grub/i18n.h>
#include <regex.h>
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 (&regex, anchored_line, REG_EXTENDED | REG_NOSUB);
grub_free (anchored_line);
if (ret)
{
grub_free (line);
continue;
}
ret = regexec (&regex, id, 0, NULL, 0);
regfree (&regex);
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);
}

View File

@ -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=""