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