-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgrub.patch
285 lines (281 loc) · 6.22 KB
/
grub.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -762,6 +762,11 @@
};
module = {
+ name = bqcat;
+ common = commands/bqcat.c;
+};
+
+module = {
name = cmp;
common = commands/cmp.c;
};
@@ -908,6 +913,11 @@
};
module = {
+ name = popenv;
+ common = commands/popenv.c;
+};
+
+module = {
name = ls;
common = commands/ls.c;
};
@@ -1055,6 +1065,11 @@
};
module = {
+ name = bqvideoinfo;
+ common = commands/bqvideoinfo.c;
+};
+
+module = {
name = videotest;
common = commands/videotest.c;
};
--- a/grub-core/commands/bqcat.c
+++ b/grub-core/commands/bqcat.c
@@ -0,0 +1,50 @@
+/* bqcat.c - command to store the contents of a file in a variable */
+
+#include <grub/dl.h>
+#include <grub/file.h>
+#include <grub/env.h>
+#include <grub/command.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static grub_err_t
+grub_cmd_bqcat (grub_command_t cmd __attribute__ ((unused)), int argc, char **args)
+{
+ grub_file_t file;
+ grub_ssize_t size;
+ grub_ssize_t done = 0;
+ char* buffer;
+
+ if (argc != 2)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename and variable name expected"));
+
+ file = grub_file_open (args[0]);
+ if (! file)
+ return grub_errno;
+
+ buffer = grub_malloc(file->size + 1);
+
+ while ((size = grub_file_read (file, buffer + done, file->size - done)) > 0)
+ {
+ done += size;
+ }
+
+ buffer[done] = '\0';
+ grub_env_set (args[1], buffer);
+ grub_file_close (file);
+ grub_free(buffer);
+
+ return 0;
+}
+
+static grub_command_t cmd;
+
+GRUB_MOD_INIT(bqcat)
+{
+ cmd = grub_register_command ("bqcat", grub_cmd_bqcat, N_("FILE VARIABLE"), N_("Store the contents of a file in a variable."));
+}
+
+GRUB_MOD_FINI(bqcat)
+{
+ grub_unregister_command (cmd);
+}
--- a/grub-core/commands/bqvideoinfo.c
+++ b/grub-core/commands/bqvideoinfo.c
@@ -0,0 +1,95 @@
+/* bqvideoinfo.c - command to store video modes in a variable. */
+
+#include <grub/video.h>
+#include <grub/dl.h>
+#include <grub/env.h>
+#include <grub/mm.h>
+#include <grub/command.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+struct hook_ctx
+{
+ unsigned int len;
+ char* data;
+};
+
+static int
+hook (const struct grub_video_mode_info *info, void *hook_arg)
+{
+ unsigned int len;
+ struct hook_ctx *ctx = hook_arg;
+ char buf[24];
+ if (info->mode_type & GRUB_VIDEO_MODE_TYPE_PURE_TEXT)
+ return 0;
+ grub_snprintf (buf, sizeof(buf), "%dx%dx%d ", info->width, info->height, info->bpp);
+ len = grub_strlen(buf);
+ if (ctx->data)
+ {
+ grub_strcpy(ctx->data + ctx->len, buf);
+ }
+ ctx->len += len;
+ return 0;
+}
+
+static grub_err_t
+grub_cmd_bqvideoinfo (grub_command_t cmd __attribute__ ((unused)), int argc, char **args)
+{
+ grub_video_adapter_t adapter;
+ grub_video_driver_id_t id;
+ struct hook_ctx ctx;
+
+ if (argc != 1)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("variable name expected"));
+
+#ifdef GRUB_MACHINE_PCBIOS
+ grub_dl_load ("vbe");
+#endif
+
+ id = grub_video_get_driver_id ();
+
+ FOR_VIDEO_ADAPTERS (adapter)
+ {
+ if (! adapter->iterate || (adapter->id != id && (id != GRUB_VIDEO_DRIVER_NONE || adapter->init() != GRUB_ERR_NONE)))
+ {
+ continue;
+ }
+
+ ctx.data = NULL;
+ ctx.len = 0;
+ adapter->iterate (hook, &ctx);
+ ctx.data = grub_malloc(ctx.len+1);
+ ctx.data[0] = '\0'; ctx.len = 0;
+ adapter->iterate (hook, &ctx);
+
+ if (adapter->id != id)
+ {
+ adapter->fini();
+ }
+
+ if (id != GRUB_VIDEO_DRIVER_NONE || ctx.len)
+ {
+ grub_env_set (args[0], ctx.data);
+ grub_free(ctx.data);
+ break;
+ }
+ else
+ {
+ grub_free(ctx.data);
+ }
+ }
+
+ return 0;
+}
+
+static grub_command_t cmd;
+
+GRUB_MOD_INIT(bqvideoinfo)
+{
+ cmd = grub_register_command ("bqvideoinfo", grub_cmd_bqvideoinfo, N_("VARIABLE"), N_("Store available video modes in a variable."));
+}
+
+GRUB_MOD_FINI(bqvideoinfo)
+{
+ grub_unregister_command (cmd);
+}
--- a/grub-core/commands/popenv.c
+++ b/grub-core/commands/popenv.c
@@ -0,0 +1,79 @@
+/* popenv.c - commands for passing variables from submenus. */
+
+#include <grub/dl.h>
+#include <grub/env_private.h>
+#include <grub/command.h>
+#include <grub/mm.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+extern int grub_normal_exit_level;
+
+static grub_err_t
+grub_cmd_pop_env (grub_command_t cmd __attribute__ ((unused)), int argc, char **args)
+{
+
+ while (argc)
+ {
+ struct grub_env_context *cc = grub_current_context;
+ const char *value;
+
+ value = grub_env_get (args[0]);
+ if (value)
+ {
+ grub_current_context = grub_current_context->prev;
+ while(grub_current_context && grub_env_get(args[0]))
+ {
+ grub_env_set(args[0], value);
+ grub_current_context = grub_current_context->prev;
+ }
+ grub_current_context = cc;
+ }
+ argc--;
+ args++;
+ }
+
+ return 0;
+}
+
+static grub_err_t
+grub_cmd_submenu_exit (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), char **args __attribute__ ((unused)))
+{
+ grub_normal_exit_level = -1;
+ return 0;
+}
+
+static grub_err_t
+grub_cmd_clear_menu (grub_command_t cmd __attribute__ ((unused)), int argc __attribute__ ((unused)), char **args __attribute__ ((unused)))
+{
+ grub_menu_t menu = grub_env_get_menu();
+ // grub_free(menu->entry_list); // TODO: recursively?
+ menu->entry_list = NULL;
+ menu->size=0;
+ return 0;
+}
+
+static grub_command_t cmd_pop, cmd_sub_exit, cmd_clear_menu;
+
+GRUB_MOD_INIT(popenv)
+{
+ cmd_pop =
+ grub_register_command ("pop_env", grub_cmd_pop_env,
+ N_("variable_name [...]"),
+ N_("Pass variable value to parent contexts."));
+
+ cmd_sub_exit =
+ grub_register_command ("submenu_exit", grub_cmd_submenu_exit, 0,
+ N_("Exit from current submenu."));
+
+ cmd_clear_menu =
+ grub_register_command ("clear_menu", grub_cmd_clear_menu, 0,
+ N_("Clear the current (sub)menu."));
+}
+
+GRUB_MOD_FINI(popenv)
+{
+ grub_unregister_command (cmd_pop);
+ grub_unregister_command (cmd_sub_exit);
+ grub_unregister_command (cmd_clear_menu);
+}
--- a/grub-core/normal/menu.c
+++ b/grub-core/normal/menu.c
@@ -908,5 +908,11 @@
break;
}
+ if (nested && grub_normal_exit_level == -1)
+ {
+ menu_fini();
+ grub_normal_exit_level++;
+ }
+
return err1;
}