Merge ~ubuntu-core-dev/grub/+git/ubuntu:sil2100/ubuntu-auto-nvram into ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu

Proposed by Łukasz Zemczak
Status: Merged
Approved by: Mathieu Trudel-Lapierre
Approved revision: d5f3fb20b22da07856778d9bc1b81022aa302113
Merge reported by: Mathieu Trudel-Lapierre
Merged at revision: d5f3fb20b22da07856778d9bc1b81022aa302113
Proposed branch: ~ubuntu-core-dev/grub/+git/ubuntu:sil2100/ubuntu-auto-nvram
Merge into: ~ubuntu-core-dev/grub/+git/ubuntu:ubuntu
Diff against target: 477 lines (+281/-16)
9 files modified
debian/.git-dpm (+2/-2)
debian/changelog (+8/-0)
debian/patches/add-an-auto-nvram-option-to-grub-install.patch (+226/-0)
debian/patches/series (+1/-0)
grub-core/osdep/basic/no_platform.c (+3/-2)
grub-core/osdep/unix/platform.c (+20/-2)
grub-core/osdep/windows/platform.c (+3/-2)
include/grub/util/install.h (+3/-2)
util/grub-install.c (+15/-6)
Reviewer Review Type Date Requested Status
Mathieu Trudel-Lapierre Approve
Review via email: mp+343642@code.launchpad.net

Commit message

Add the auto-nvram functionality of only attempting the NVRAM variable update if the system has access to those. Useful for dual BIOS-EFI devices.

Description of the change

Add the auto-nvram functionality of only attempting the NVRAM variable update if the system has access to those. Useful for dual BIOS-EFI devices.

git-dpm ubuntu branch (patched).

To post a comment you must log in.
d5f3fb2... by Łukasz Zemczak

merge patched-ubuntu into ubuntu

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/.git-dpm b/debian/.git-dpm
2index a6e25a6..32844ae 100644
3--- a/debian/.git-dpm
4+++ b/debian/.git-dpm
5@@ -1,6 +1,6 @@
6 # see git-dpm(1) from git-dpm package
7-4a2879d2ea9e6179ac0f45d7196b9d905fcab0f6
8-4a2879d2ea9e6179ac0f45d7196b9d905fcab0f6
9+1696f83780575139eb0ad801a311c947028278f2
10+1696f83780575139eb0ad801a311c947028278f2
11 0992ffbac6a1b4c97c350d12e5301e0067daa0d6
12 0992ffbac6a1b4c97c350d12e5301e0067daa0d6
13 grub2_2.02.orig.tar.xz
14diff --git a/debian/changelog b/debian/changelog
15index 2e7a56d..07c31df 100644
16--- a/debian/changelog
17+++ b/debian/changelog
18@@ -1,3 +1,11 @@
19+grub2 (2.02-2ubuntu9) UNRELEASED; urgency=medium
20+
21+ * debian/patches/add-an-auto-nvram-option-to-grub-install.patch: Add the
22+ --auto-nvram option to grub-install for auto-detecting NVRAM availability
23+ before attempting NVRAM updates.
24+
25+ -- Łukasz 'sil2100' Zemczak <lukasz.zemczak@ubuntu.com> Fri, 20 Apr 2018 19:41:26 +0200
26+
27 grub2 (2.02-2ubuntu8) bionic; urgency=medium
28
29 * Drop debian/patches/mkconfig_keep_native_term_active.patch, which can
30diff --git a/debian/patches/add-an-auto-nvram-option-to-grub-install.patch b/debian/patches/add-an-auto-nvram-option-to-grub-install.patch
31new file mode 100644
32index 0000000..d22dae9
33--- /dev/null
34+++ b/debian/patches/add-an-auto-nvram-option-to-grub-install.patch
35@@ -0,0 +1,226 @@
36+From 1696f83780575139eb0ad801a311c947028278f2 Mon Sep 17 00:00:00 2001
37+From: Łukasz 'sil2100' Zemczak <lukasz.zemczak@canonical.com>
38+Date: Fri, 20 Apr 2018 19:27:37 +0200
39+Subject: Add an auto-nvram option to grub-install for auto-detecting NVRAM
40+ access
41+
42+This adds the auto-nvram functionality of only attempting the NVRAM
43+variable update if the system has access to those. Useful for dual
44+BIOS-EFI devices.
45+
46+Patch-Name: add-an-auto-nvram-option-to-grub-install.patch
47+---
48+ grub-core/osdep/basic/no_platform.c | 5 +++--
49+ grub-core/osdep/unix/platform.c | 22 ++++++++++++++++++++--
50+ grub-core/osdep/windows/platform.c | 5 +++--
51+ include/grub/util/install.h | 5 +++--
52+ util/grub-install.c | 21 +++++++++++++++------
53+ 5 files changed, 44 insertions(+), 14 deletions(-)
54+
55+diff --git a/grub-core/osdep/basic/no_platform.c b/grub-core/osdep/basic/no_platform.c
56+index d76c34c14..b39e97f48 100644
57+--- a/grub-core/osdep/basic/no_platform.c
58++++ b/grub-core/osdep/basic/no_platform.c
59+@@ -25,7 +25,7 @@
60+
61+ void
62+ grub_install_register_ieee1275 (int is_prep, const char *install_device,
63+- int partno, const char *relpath)
64++ int partno, const char *relpath, int detect_nvram)
65+ {
66+ grub_util_error ("%s", _("no IEEE1275 routines are available for your platform"));
67+ }
68+@@ -33,7 +33,8 @@ grub_install_register_ieee1275 (int is_prep, const char *install_device,
69+ void
70+ grub_install_register_efi (grub_device_t efidir_grub_dev,
71+ const char *efifile_path,
72+- const char *efi_distributor)
73++ const char *efi_distributor,
74++ int detect_nvram)
75+ {
76+ grub_util_error ("%s", _("no EFI routines are available for your platform"));
77+ }
78+diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c
79+index f9c376c35..04d0d8c42 100644
80+--- a/grub-core/osdep/unix/platform.c
81++++ b/grub-core/osdep/unix/platform.c
82+@@ -134,7 +134,8 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
83+ int
84+ grub_install_register_efi (grub_device_t efidir_grub_dev,
85+ const char *efifile_path,
86+- const char *efi_distributor)
87++ const char *efi_distributor,
88++ int detect_nvram)
89+ {
90+ const char * efidir_disk;
91+ int efidir_part;
92+@@ -153,6 +154,18 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
93+ #ifdef __linux__
94+ grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL });
95+ #endif
96++
97++ /* If requested, we try to detect if NVRAM access is available and if not,
98++ resume normal operation. */
99++ if (detect_nvram)
100++ {
101++ error = grub_util_exec_redirect_null ((const char * []){ "efibootmgr", NULL });
102++ if (error == 2)
103++ return 0;
104++ else if (error)
105++ return error;
106++ }
107++
108+ /* Delete old entries from the same distributor. */
109+ error = grub_install_remove_efi_entries_by_distributor (efi_distributor);
110+ if (error)
111+@@ -178,7 +191,7 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
112+
113+ void
114+ grub_install_register_ieee1275 (int is_prep, const char *install_device,
115+- int partno, const char *relpath)
116++ int partno, const char *relpath, int detect_nvram)
117+ {
118+ char *boot_device;
119+
120+@@ -189,6 +202,11 @@ grub_install_register_ieee1275 (int is_prep, const char *install_device,
121+ grub_util_error (_("%s: not found"), "ofpathname");
122+ }
123+
124++ /* If requested, we try to detect if NVRAM access is available and if not,
125++ resume normal operation. */
126++ if (detect_nvram && grub_util_exec_redirect_null ((const char * []){ "nvram", NULL }))
127++ return;
128++
129+ /* Get the Open Firmware device tree path translation. */
130+ if (!is_prep)
131+ {
132+diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c
133+index c30025b13..1c9695970 100644
134+--- a/grub-core/osdep/windows/platform.c
135++++ b/grub-core/osdep/windows/platform.c
136+@@ -210,7 +210,8 @@ set_efi_variable_bootn (grub_uint16_t n, void *in, grub_size_t len)
137+ void
138+ grub_install_register_efi (grub_device_t efidir_grub_dev,
139+ const char *efifile_path,
140+- const char *efi_distributor)
141++ const char *efi_distributor,
142++ int detect_nvram)
143+ {
144+ grub_uint16_t *boot_order, *new_boot_order;
145+ grub_uint16_t *distributor16;
146+@@ -417,7 +418,7 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
147+
148+ void
149+ grub_install_register_ieee1275 (int is_prep, const char *install_device,
150+- int partno, const char *relpath)
151++ int partno, const char *relpath, int detect_nvram)
152+ {
153+ grub_util_error ("%s", _("no IEEE1275 routines are available for your platform"));
154+ }
155+diff --git a/include/grub/util/install.h b/include/grub/util/install.h
156+index 58648e209..115188399 100644
157+--- a/include/grub/util/install.h
158++++ b/include/grub/util/install.h
159+@@ -212,11 +212,12 @@ grub_install_get_default_powerpc_machtype (void);
160+ int
161+ grub_install_register_efi (grub_device_t efidir_grub_dev,
162+ const char *efifile_path,
163+- const char *efi_distributor);
164++ const char *efi_distributor,
165++ int detect_nvram);
166+
167+ void
168+ grub_install_register_ieee1275 (int is_prep, const char *install_device,
169+- int partno, const char *relpath);
170++ int partno, const char *relpath, int detect_nvram);
171+
172+ void
173+ grub_install_sgi_setup (const char *install_device,
174+diff --git a/util/grub-install.c b/util/grub-install.c
175+index 2214e4549..b8f91101d 100644
176+--- a/util/grub-install.c
177++++ b/util/grub-install.c
178+@@ -59,6 +59,7 @@ static int removable = 0;
179+ static int no_extra_removable = 0;
180+ static int recheck = 0;
181+ static int update_nvram = 1;
182++static int auto_nvram = 0;
183+ static char *install_device = NULL;
184+ static char *debug_image = NULL;
185+ static char *rootdir = NULL;
186+@@ -115,7 +116,8 @@ enum
187+ OPTION_PRODUCT_VERSION,
188+ OPTION_UEFI_SECURE_BOOT,
189+ OPTION_NO_UEFI_SECURE_BOOT,
190+- OPTION_NO_EXTRA_REMOVABLE
191++ OPTION_NO_EXTRA_REMOVABLE,
192++ OPTION_AUTO_NVRAM
193+ };
194+
195+ static int fs_probe = 1;
196+@@ -206,6 +208,10 @@ argp_parser (int key, char *arg, struct argp_state *state)
197+ update_nvram = 0;
198+ return 0;
199+
200++ case OPTION_AUTO_NVRAM:
201++ auto_nvram = 1;
202++ return 0;
203++
204+ case OPTION_FORCE:
205+ force = 1;
206+ return 0;
207+@@ -296,6 +302,9 @@ static struct argp_option options[] = {
208+ {"no-nvram", OPTION_NO_NVRAM, 0, 0,
209+ N_("don't update the `boot-device'/`Boot*' NVRAM variables. "
210+ "This option is only available on EFI and IEEE1275 targets."), 2},
211++ {"auto-nvram", OPTION_AUTO_NVRAM, 0, 0,
212++ N_("only update NVRAM variables if possible. "
213++ "This option is only available on EFI and IEEE1275 targets."), 2},
214+ {"skip-fs-probe",'s',0, 0,
215+ N_("do not probe for filesystems in DEVICE"), 0},
216+ {"no-bootsector", OPTION_NO_BOOTSECTOR, 0, 0,
217+@@ -1924,7 +1933,7 @@ main (int argc, char *argv[])
218+ ? ins_dev->disk->partition->number + 1 : 0;
219+ dev = grub_util_get_os_disk (install_device);
220+ grub_install_register_ieee1275 (0, dev, partno,
221+- "\\\\BootX");
222++ "\\\\BootX", auto_nvram);
223+ }
224+ grub_device_close (ins_dev);
225+ free (grub_elf);
226+@@ -1956,7 +1965,7 @@ main (int argc, char *argv[])
227+ grub_device_close (ins_dev);
228+ if (update_nvram)
229+ grub_install_register_ieee1275 (1, grub_util_get_os_disk (install_device),
230+- 0, NULL);
231++ 0, NULL, auto_nvram);
232+ break;
233+ }
234+ /* fallthrough. */
235+@@ -1971,7 +1980,7 @@ main (int argc, char *argv[])
236+ ? grub_dev->disk->partition->number + 1 : 0;
237+ dev = grub_util_get_os_disk (grub_devices[0]);
238+ grub_install_register_ieee1275 (0, dev,
239+- partno, relpath);
240++ partno, relpath, auto_nvram);
241+ }
242+ break;
243+ case GRUB_INSTALL_PLATFORM_MIPS_ARC:
244+@@ -2020,7 +2029,7 @@ main (int argc, char *argv[])
245+ int error = 0;
246+ error = grub_install_register_efi (efidir_grub_dev,
247+ "\\System\\Library\\CoreServices",
248+- efi_distributor);
249++ efi_distributor, auto_nvram);
250+ if (error)
251+ grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
252+ strerror (error));
253+@@ -2135,7 +2144,7 @@ main (int argc, char *argv[])
254+ (part ? ",": ""), (part ? : ""));
255+ grub_free (part);
256+ error = grub_install_register_efi (efidir_grub_dev,
257+- efifile_path, efi_distributor);
258++ efifile_path, efi_distributor, auto_nvram);
259+ if (error)
260+ grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
261+ strerror (error));
262diff --git a/debian/patches/series b/debian/patches/series
263index 47ad08d..298e3f0 100644
264--- a/debian/patches/series
265+++ b/debian/patches/series
266@@ -75,3 +75,4 @@ bufio_sensible_block_sizes.patch
267 shorter_version_info.patch
268 skip_text_gfxpayload_where_not_supported.patch
269 yylex-explicitly_cast_fprintf_to_void.patch
270+add-an-auto-nvram-option-to-grub-install.patch
271diff --git a/grub-core/osdep/basic/no_platform.c b/grub-core/osdep/basic/no_platform.c
272index d76c34c..b39e97f 100644
273--- a/grub-core/osdep/basic/no_platform.c
274+++ b/grub-core/osdep/basic/no_platform.c
275@@ -25,7 +25,7 @@
276
277 void
278 grub_install_register_ieee1275 (int is_prep, const char *install_device,
279- int partno, const char *relpath)
280+ int partno, const char *relpath, int detect_nvram)
281 {
282 grub_util_error ("%s", _("no IEEE1275 routines are available for your platform"));
283 }
284@@ -33,7 +33,8 @@ grub_install_register_ieee1275 (int is_prep, const char *install_device,
285 void
286 grub_install_register_efi (grub_device_t efidir_grub_dev,
287 const char *efifile_path,
288- const char *efi_distributor)
289+ const char *efi_distributor,
290+ int detect_nvram)
291 {
292 grub_util_error ("%s", _("no EFI routines are available for your platform"));
293 }
294diff --git a/grub-core/osdep/unix/platform.c b/grub-core/osdep/unix/platform.c
295index f9c376c..04d0d8c 100644
296--- a/grub-core/osdep/unix/platform.c
297+++ b/grub-core/osdep/unix/platform.c
298@@ -134,7 +134,8 @@ grub_install_remove_efi_entries_by_distributor (const char *efi_distributor)
299 int
300 grub_install_register_efi (grub_device_t efidir_grub_dev,
301 const char *efifile_path,
302- const char *efi_distributor)
303+ const char *efi_distributor,
304+ int detect_nvram)
305 {
306 const char * efidir_disk;
307 int efidir_part;
308@@ -153,6 +154,18 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
309 #ifdef __linux__
310 grub_util_exec ((const char * []){ "modprobe", "-q", "efivars", NULL });
311 #endif
312+
313+ /* If requested, we try to detect if NVRAM access is available and if not,
314+ resume normal operation. */
315+ if (detect_nvram)
316+ {
317+ error = grub_util_exec_redirect_null ((const char * []){ "efibootmgr", NULL });
318+ if (error == 2)
319+ return 0;
320+ else if (error)
321+ return error;
322+ }
323+
324 /* Delete old entries from the same distributor. */
325 error = grub_install_remove_efi_entries_by_distributor (efi_distributor);
326 if (error)
327@@ -178,7 +191,7 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
328
329 void
330 grub_install_register_ieee1275 (int is_prep, const char *install_device,
331- int partno, const char *relpath)
332+ int partno, const char *relpath, int detect_nvram)
333 {
334 char *boot_device;
335
336@@ -189,6 +202,11 @@ grub_install_register_ieee1275 (int is_prep, const char *install_device,
337 grub_util_error (_("%s: not found"), "ofpathname");
338 }
339
340+ /* If requested, we try to detect if NVRAM access is available and if not,
341+ resume normal operation. */
342+ if (detect_nvram && grub_util_exec_redirect_null ((const char * []){ "nvram", NULL }))
343+ return;
344+
345 /* Get the Open Firmware device tree path translation. */
346 if (!is_prep)
347 {
348diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c
349index c30025b..1c96959 100644
350--- a/grub-core/osdep/windows/platform.c
351+++ b/grub-core/osdep/windows/platform.c
352@@ -210,7 +210,8 @@ set_efi_variable_bootn (grub_uint16_t n, void *in, grub_size_t len)
353 void
354 grub_install_register_efi (grub_device_t efidir_grub_dev,
355 const char *efifile_path,
356- const char *efi_distributor)
357+ const char *efi_distributor,
358+ int detect_nvram)
359 {
360 grub_uint16_t *boot_order, *new_boot_order;
361 grub_uint16_t *distributor16;
362@@ -417,7 +418,7 @@ grub_install_register_efi (grub_device_t efidir_grub_dev,
363
364 void
365 grub_install_register_ieee1275 (int is_prep, const char *install_device,
366- int partno, const char *relpath)
367+ int partno, const char *relpath, int detect_nvram)
368 {
369 grub_util_error ("%s", _("no IEEE1275 routines are available for your platform"));
370 }
371diff --git a/include/grub/util/install.h b/include/grub/util/install.h
372index 58648e2..1151883 100644
373--- a/include/grub/util/install.h
374+++ b/include/grub/util/install.h
375@@ -212,11 +212,12 @@ grub_install_get_default_powerpc_machtype (void);
376 int
377 grub_install_register_efi (grub_device_t efidir_grub_dev,
378 const char *efifile_path,
379- const char *efi_distributor);
380+ const char *efi_distributor,
381+ int detect_nvram);
382
383 void
384 grub_install_register_ieee1275 (int is_prep, const char *install_device,
385- int partno, const char *relpath);
386+ int partno, const char *relpath, int detect_nvram);
387
388 void
389 grub_install_sgi_setup (const char *install_device,
390diff --git a/util/grub-install.c b/util/grub-install.c
391index 2214e45..b8f9110 100644
392--- a/util/grub-install.c
393+++ b/util/grub-install.c
394@@ -59,6 +59,7 @@ static int removable = 0;
395 static int no_extra_removable = 0;
396 static int recheck = 0;
397 static int update_nvram = 1;
398+static int auto_nvram = 0;
399 static char *install_device = NULL;
400 static char *debug_image = NULL;
401 static char *rootdir = NULL;
402@@ -115,7 +116,8 @@ enum
403 OPTION_PRODUCT_VERSION,
404 OPTION_UEFI_SECURE_BOOT,
405 OPTION_NO_UEFI_SECURE_BOOT,
406- OPTION_NO_EXTRA_REMOVABLE
407+ OPTION_NO_EXTRA_REMOVABLE,
408+ OPTION_AUTO_NVRAM
409 };
410
411 static int fs_probe = 1;
412@@ -206,6 +208,10 @@ argp_parser (int key, char *arg, struct argp_state *state)
413 update_nvram = 0;
414 return 0;
415
416+ case OPTION_AUTO_NVRAM:
417+ auto_nvram = 1;
418+ return 0;
419+
420 case OPTION_FORCE:
421 force = 1;
422 return 0;
423@@ -296,6 +302,9 @@ static struct argp_option options[] = {
424 {"no-nvram", OPTION_NO_NVRAM, 0, 0,
425 N_("don't update the `boot-device'/`Boot*' NVRAM variables. "
426 "This option is only available on EFI and IEEE1275 targets."), 2},
427+ {"auto-nvram", OPTION_AUTO_NVRAM, 0, 0,
428+ N_("only update NVRAM variables if possible. "
429+ "This option is only available on EFI and IEEE1275 targets."), 2},
430 {"skip-fs-probe",'s',0, 0,
431 N_("do not probe for filesystems in DEVICE"), 0},
432 {"no-bootsector", OPTION_NO_BOOTSECTOR, 0, 0,
433@@ -1924,7 +1933,7 @@ main (int argc, char *argv[])
434 ? ins_dev->disk->partition->number + 1 : 0;
435 dev = grub_util_get_os_disk (install_device);
436 grub_install_register_ieee1275 (0, dev, partno,
437- "\\\\BootX");
438+ "\\\\BootX", auto_nvram);
439 }
440 grub_device_close (ins_dev);
441 free (grub_elf);
442@@ -1956,7 +1965,7 @@ main (int argc, char *argv[])
443 grub_device_close (ins_dev);
444 if (update_nvram)
445 grub_install_register_ieee1275 (1, grub_util_get_os_disk (install_device),
446- 0, NULL);
447+ 0, NULL, auto_nvram);
448 break;
449 }
450 /* fallthrough. */
451@@ -1971,7 +1980,7 @@ main (int argc, char *argv[])
452 ? grub_dev->disk->partition->number + 1 : 0;
453 dev = grub_util_get_os_disk (grub_devices[0]);
454 grub_install_register_ieee1275 (0, dev,
455- partno, relpath);
456+ partno, relpath, auto_nvram);
457 }
458 break;
459 case GRUB_INSTALL_PLATFORM_MIPS_ARC:
460@@ -2020,7 +2029,7 @@ main (int argc, char *argv[])
461 int error = 0;
462 error = grub_install_register_efi (efidir_grub_dev,
463 "\\System\\Library\\CoreServices",
464- efi_distributor);
465+ efi_distributor, auto_nvram);
466 if (error)
467 grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
468 strerror (error));
469@@ -2135,7 +2144,7 @@ main (int argc, char *argv[])
470 (part ? ",": ""), (part ? : ""));
471 grub_free (part);
472 error = grub_install_register_efi (efidir_grub_dev,
473- efifile_path, efi_distributor);
474+ efifile_path, efi_distributor, auto_nvram);
475 if (error)
476 grub_util_error (_("efibootmgr failed to register the boot entry: %s"),
477 strerror (error));

Subscribers

People subscribed via source and target branches