1 From 94409096751781ddb277b2442f0d516c4044f560 Mon Sep 17 00:00:00 2001
2 From: Evan Broder <evan@ebroder.net>
3 Date: Mon, 13 Jan 2014 12:13:29 +0000
4 Subject: Add configure option to enable gfxpayload=keep dynamically
6 Set GRUB_GFXPAYLOAD_LINUX=keep unless it's known to be unsupported on
7 the current hardware. See
8 https://blueprints.launchpad.net/ubuntu/+spec/packageselection-foundations-n-grub2-boot-framebuffer.
10 Author: Colin Watson <cjwatson@ubuntu.com>
12 Last-Update: 2019-05-25
14 Patch-Name: gfxpayload-dynamic.patch
17 grub-core/Makefile.core.def | 8 ++
18 grub-core/commands/i386/pc/hwmatch.c | 146 +++++++++++++++++++++++++++
19 include/grub/file.h | 1 +
20 util/grub.d/10_linux.in | 37 ++++++-
21 5 files changed, 200 insertions(+), 3 deletions(-)
22 create mode 100644 grub-core/commands/i386/pc/hwmatch.c
24 diff --git a/configure.ac b/configure.ac
25 index ebfcb618a..c061e3d19 100644
28 @@ -1879,6 +1879,17 @@ else
30 AC_SUBST([QUICK_BOOT])
32 +AC_ARG_ENABLE([gfxpayload-dynamic],
33 + [AS_HELP_STRING([--enable-gfxpayload-dynamic],
34 + [use GRUB_GFXPAYLOAD_LINUX=keep unless explicitly unsupported on current hardware (default=no)])],
35 + [], [enable_gfxpayload_dynamic=no])
36 +if test x"$enable_gfxpayload_dynamic" = xyes ; then
37 + GFXPAYLOAD_DYNAMIC=1
39 + GFXPAYLOAD_DYNAMIC=0
41 +AC_SUBST([GFXPAYLOAD_DYNAMIC])
45 AC_SUBST([FONT_SOURCE])
46 diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
47 index 67a98abbb..836bf0a59 100644
48 --- a/grub-core/Makefile.core.def
49 +++ b/grub-core/Makefile.core.def
50 @@ -971,6 +971,14 @@ module = {
51 common = lib/hexdump.c;
56 + i386_pc = commands/i386/pc/hwmatch.c;
58 + cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)';
59 + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)';
64 common = commands/keystatus.c;
65 diff --git a/grub-core/commands/i386/pc/hwmatch.c b/grub-core/commands/i386/pc/hwmatch.c
67 index 000000000..6de07cecc
69 +++ b/grub-core/commands/i386/pc/hwmatch.c
71 +/* hwmatch.c - Match hardware against a whitelist/blacklist. */
73 + * GRUB -- GRand Unified Bootloader
74 + * Copyright (C) 2011 Free Software Foundation, Inc.
76 + * GRUB is free software: you can redistribute it and/or modify
77 + * it under the terms of the GNU General Public License as published by
78 + * the Free Software Foundation, either version 3 of the License, or
79 + * (at your option) any later version.
81 + * GRUB is distributed in the hope that it will be useful,
82 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
83 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84 + * GNU General Public License for more details.
86 + * You should have received a copy of the GNU General Public License
87 + * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
91 +#include <grub/misc.h>
92 +#include <grub/command.h>
93 +#include <grub/pci.h>
94 +#include <grub/normal.h>
95 +#include <grub/file.h>
96 +#include <grub/env.h>
97 +#include <grub/i18n.h>
100 +GRUB_MOD_LICENSE ("GPLv3+");
102 +/* Context for grub_cmd_hwmatch. */
105 + grub_file_t matches_file;
110 +/* Helper for grub_cmd_hwmatch. */
112 +hwmatch_iter (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
114 + struct hwmatch_ctx *ctx = data;
115 + grub_pci_address_t addr;
116 + grub_uint32_t class, baseclass, vendor, device;
117 + grub_pci_id_t subpciid;
118 + grub_uint32_t subvendor, subdevice, subclass;
121 + addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
122 + class = grub_pci_read (addr);
123 + baseclass = class >> 24;
125 + if (ctx->class_match != baseclass)
128 + vendor = pciid & 0xffff;
129 + device = pciid >> 16;
131 + addr = grub_pci_make_address (dev, GRUB_PCI_REG_SUBVENDOR);
132 + subpciid = grub_pci_read (addr);
134 + subclass = (class >> 16) & 0xff;
135 + subvendor = subpciid & 0xffff;
136 + subdevice = subpciid >> 16;
138 + id = grub_xasprintf ("v%04xd%04xsv%04xsd%04xbc%02xsc%02x",
139 + vendor, device, subvendor, subdevice,
140 + baseclass, subclass);
142 + grub_file_seek (ctx->matches_file, 0);
143 + while ((line = grub_file_getline (ctx->matches_file)) != NULL)
145 + char *anchored_line;
149 + if (! *line || *line == '#')
155 + anchored_line = grub_xasprintf ("^%s$", line);
156 + ret = regcomp (®ex, anchored_line, REG_EXTENDED | REG_NOSUB);
157 + grub_free (anchored_line);
164 + ret = regexec (®ex, id, 0, NULL, 0);
178 +grub_cmd_hwmatch (grub_command_t cmd __attribute__ ((unused)),
179 + int argc, char **args)
181 + struct hwmatch_ctx ctx = { .match = 0 };
185 + return grub_error (GRUB_ERR_BAD_ARGUMENT, "list file and class required");
187 + ctx.matches_file = grub_file_open (args[0], GRUB_FILE_TYPE_HWMATCH);
188 + if (! ctx.matches_file)
191 + ctx.class_match = grub_strtol (args[1], 0, 10);
193 + grub_pci_iterate (hwmatch_iter, &ctx);
195 + match_str = grub_xasprintf ("%d", ctx.match);
196 + grub_env_set ("match", match_str);
197 + grub_free (match_str);
199 + grub_file_close (ctx.matches_file);
201 + return GRUB_ERR_NONE;
204 +static grub_command_t cmd;
206 +GRUB_MOD_INIT(hwmatch)
208 + cmd = grub_register_command ("hwmatch", grub_cmd_hwmatch,
209 + N_("MATCHES-FILE CLASS"),
210 + N_("Match PCI devices."));
213 +GRUB_MOD_FINI(hwmatch)
215 + grub_unregister_command (cmd);
217 diff --git a/include/grub/file.h b/include/grub/file.h
218 index 31567483c..e3c4cae2b 100644
219 --- a/include/grub/file.h
220 +++ b/include/grub/file.h
221 @@ -122,6 +122,7 @@ enum grub_file_type
222 GRUB_FILE_TYPE_FS_SEARCH,
223 GRUB_FILE_TYPE_AUDIO,
224 GRUB_FILE_TYPE_VBE_DUMP,
225 + GRUB_FILE_TYPE_HWMATCH,
227 GRUB_FILE_TYPE_LOADENV,
228 GRUB_FILE_TYPE_SAVEENV,
229 diff --git a/util/grub.d/10_linux.in b/util/grub.d/10_linux.in
230 index 51cdb5e1d..2f5217358 100644
231 --- a/util/grub.d/10_linux.in
232 +++ b/util/grub.d/10_linux.in
233 @@ -23,6 +23,7 @@ datarootdir="@datarootdir@"
234 ubuntu_recovery="@UBUNTU_RECOVERY@"
235 quiet_boot="@QUIET_BOOT@"
236 quick_boot="@QUICK_BOOT@"
237 +gfxpayload_dynamic="@GFXPAYLOAD_DYNAMIC@"
239 . "$pkgdatadir/grub-mkconfig_lib"
241 @@ -145,9 +146,10 @@ linux_entry ()
242 if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
243 echo " load_video" | sed "s/^/$submenu_indentation/"
245 - if [ "$ubuntu_recovery" = 0 ] || [ x$type != xrecovery ]; then
246 - echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
249 + if ([ "$ubuntu_recovery" = 0 ] || [ x$type != xrecovery ]) && \
250 + ([ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 1 ]); then
251 + echo " set gfxpayload=\$linux_gfx_mode" | sed "s/^/$submenu_indentation/"
254 echo " insmod gzio" | sed "s/^/$submenu_indentation/"
255 @@ -226,6 +228,35 @@ prepare_root_cache=
257 title_correction_code=
259 +# Use ELILO's generic "efifb" when it's known to be available.
260 +# FIXME: We need an interface to select vesafb in case efifb can't be used.
261 +if [ "x$GRUB_GFXPAYLOAD_LINUX" != x ] || [ "$gfxpayload_dynamic" = 0 ]; then
262 + echo "set linux_gfx_mode=$GRUB_GFXPAYLOAD_LINUX"
265 +if [ "\${recordfail}" != 1 ]; then
266 + if [ -e \${prefix}/gfxblacklist.txt ]; then
267 + if hwmatch \${prefix}/gfxblacklist.txt 3; then
268 + if [ \${match} = 0 ]; then
269 + set linux_gfx_mode=keep
271 + set linux_gfx_mode=text
274 + set linux_gfx_mode=text
277 + set linux_gfx_mode=keep
280 + set linux_gfx_mode=text
285 +export linux_gfx_mode
288 # Extra indentation to add to menu entries in a submenu. We're not in a submenu
289 # yet, so it's empty. In a submenu it will be equal to '\t' (one tab).
290 submenu_indentation=""