]> git.proxmox.com Git - grub2.git/blob - debian/patches/gfxpayload-dynamic.patch
New upstream release candidate (2.04~rc1)
[grub2.git] / debian / patches / gfxpayload-dynamic.patch
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
5
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.
9
10 Author: Colin Watson <cjwatson@ubuntu.com>
11 Forwarded: no
12 Last-Update: 2019-05-25
13
14 Patch-Name: gfxpayload-dynamic.patch
15 ---
16 configure.ac | 11 ++
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
23
24 diff --git a/configure.ac b/configure.ac
25 index ebfcb618a..c061e3d19 100644
26 --- a/configure.ac
27 +++ b/configure.ac
28 @@ -1879,6 +1879,17 @@ else
29 fi
30 AC_SUBST([QUICK_BOOT])
31
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
38 +else
39 + GFXPAYLOAD_DYNAMIC=0
40 +fi
41 +AC_SUBST([GFXPAYLOAD_DYNAMIC])
42 +
43 LIBS=""
44
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;
52 };
53
54 +module = {
55 + name = hwmatch;
56 + i386_pc = commands/i386/pc/hwmatch.c;
57 + enable = i386_pc;
58 + cflags = '$(CFLAGS_POSIX) $(CFLAGS_GNULIB)';
59 + cppflags = '$(CPPFLAGS_POSIX) $(CPPFLAGS_GNULIB)';
60 +};
61 +
62 module = {
63 name = keystatus;
64 common = commands/keystatus.c;
65 diff --git a/grub-core/commands/i386/pc/hwmatch.c b/grub-core/commands/i386/pc/hwmatch.c
66 new file mode 100644
67 index 000000000..6de07cecc
68 --- /dev/null
69 +++ b/grub-core/commands/i386/pc/hwmatch.c
70 @@ -0,0 +1,146 @@
71 +/* hwmatch.c - Match hardware against a whitelist/blacklist. */
72 +/*
73 + * GRUB -- GRand Unified Bootloader
74 + * Copyright (C) 2011 Free Software Foundation, Inc.
75 + *
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.
80 + *
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.
85 + *
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/>.
88 + */
89 +
90 +#include <grub/dl.h>
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>
98 +#include <regex.h>
99 +
100 +GRUB_MOD_LICENSE ("GPLv3+");
101 +
102 +/* Context for grub_cmd_hwmatch. */
103 +struct hwmatch_ctx
104 +{
105 + grub_file_t matches_file;
106 + int class_match;
107 + int match;
108 +};
109 +
110 +/* Helper for grub_cmd_hwmatch. */
111 +static int
112 +hwmatch_iter (grub_pci_device_t dev, grub_pci_id_t pciid, void *data)
113 +{
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;
119 + char *id, *line;
120 +
121 + addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
122 + class = grub_pci_read (addr);
123 + baseclass = class >> 24;
124 +
125 + if (ctx->class_match != baseclass)
126 + return 0;
127 +
128 + vendor = pciid & 0xffff;
129 + device = pciid >> 16;
130 +
131 + addr = grub_pci_make_address (dev, GRUB_PCI_REG_SUBVENDOR);
132 + subpciid = grub_pci_read (addr);
133 +
134 + subclass = (class >> 16) & 0xff;
135 + subvendor = subpciid & 0xffff;
136 + subdevice = subpciid >> 16;
137 +
138 + id = grub_xasprintf ("v%04xd%04xsv%04xsd%04xbc%02xsc%02x",
139 + vendor, device, subvendor, subdevice,
140 + baseclass, subclass);
141 +
142 + grub_file_seek (ctx->matches_file, 0);
143 + while ((line = grub_file_getline (ctx->matches_file)) != NULL)
144 + {
145 + char *anchored_line;
146 + regex_t regex;
147 + int ret;
148 +
149 + if (! *line || *line == '#')
150 + {
151 + grub_free (line);
152 + continue;
153 + }
154 +
155 + anchored_line = grub_xasprintf ("^%s$", line);
156 + ret = regcomp (&regex, anchored_line, REG_EXTENDED | REG_NOSUB);
157 + grub_free (anchored_line);
158 + if (ret)
159 + {
160 + grub_free (line);
161 + continue;
162 + }
163 +
164 + ret = regexec (&regex, id, 0, NULL, 0);
165 + regfree (&regex);
166 + grub_free (line);
167 + if (! ret)
168 + {
169 + ctx->match = 1;
170 + return 1;
171 + }
172 + }
173 +
174 + return 0;
175 +}
176 +
177 +static grub_err_t
178 +grub_cmd_hwmatch (grub_command_t cmd __attribute__ ((unused)),
179 + int argc, char **args)
180 +{
181 + struct hwmatch_ctx ctx = { .match = 0 };
182 + char *match_str;
183 +
184 + if (argc < 2)
185 + return grub_error (GRUB_ERR_BAD_ARGUMENT, "list file and class required");
186 +
187 + ctx.matches_file = grub_file_open (args[0], GRUB_FILE_TYPE_HWMATCH);
188 + if (! ctx.matches_file)
189 + return grub_errno;
190 +
191 + ctx.class_match = grub_strtol (args[1], 0, 10);
192 +
193 + grub_pci_iterate (hwmatch_iter, &ctx);
194 +
195 + match_str = grub_xasprintf ("%d", ctx.match);
196 + grub_env_set ("match", match_str);
197 + grub_free (match_str);
198 +
199 + grub_file_close (ctx.matches_file);
200 +
201 + return GRUB_ERR_NONE;
202 +}
203 +
204 +static grub_command_t cmd;
205 +\f
206 +GRUB_MOD_INIT(hwmatch)
207 +{
208 + cmd = grub_register_command ("hwmatch", grub_cmd_hwmatch,
209 + N_("MATCHES-FILE CLASS"),
210 + N_("Match PCI devices."));
211 +}
212 +
213 +GRUB_MOD_FINI(hwmatch)
214 +{
215 + grub_unregister_command (cmd);
216 +}
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,
226
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@"
238
239 . "$pkgdatadir/grub-mkconfig_lib"
240
241 @@ -145,9 +146,10 @@ linux_entry ()
242 if [ "x$GRUB_GFXPAYLOAD_LINUX" != xtext ]; then
243 echo " load_video" | sed "s/^/$submenu_indentation/"
244 fi
245 - if [ "$ubuntu_recovery" = 0 ] || [ x$type != xrecovery ]; then
246 - echo " set gfxpayload=$GRUB_GFXPAYLOAD_LINUX" | sed "s/^/$submenu_indentation/"
247 - fi
248 + fi
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/"
252 fi
253
254 echo " insmod gzio" | sed "s/^/$submenu_indentation/"
255 @@ -226,6 +228,35 @@ prepare_root_cache=
256 boot_device_id=
257 title_correction_code=
258
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"
263 +else
264 + cat << EOF
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
270 + else
271 + set linux_gfx_mode=text
272 + fi
273 + else
274 + set linux_gfx_mode=text
275 + fi
276 + else
277 + set linux_gfx_mode=keep
278 + fi
279 +else
280 + set linux_gfx_mode=text
281 +fi
282 +EOF
283 +fi
284 +cat << EOF
285 +export linux_gfx_mode
286 +EOF
287 +
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=""