6 #include <types/types.h>
7 #include <talloc/talloc.h>
8 #include <array-size/array-size.h>
13 static int builtin_set(struct grub2_script *script,
14 void *data __attribute__((unused)),
15 int argc, char *argv[])
17 char *name, *value, *p;
23 p = strchr(argv[1], '=');
27 name = talloc_strndup(script, argv[1], p - argv[1]);
28 value = talloc_strdup(script, p+1);
30 for (i = 2; i < argc; i++)
31 value = talloc_asprintf_append(value, " %s", argv[i]);
33 script_env_set(script, name, value);
38 static int builtin_linux(struct grub2_script *script,
39 void *data __attribute__((unused)),
40 int argc, char *argv[])
42 struct discover_boot_option *opt = script->opt;
47 pb_log("grub2 syntax error: 'linux' statement outside "
53 pb_log("grub2 syntax error: no filename provided to "
58 root = script_env_get(script, "root");
60 opt->boot_image = create_grub2_resource(opt, script->ctx->device,
62 opt->option->boot_args = NULL;
65 opt->option->boot_args = talloc_strdup(opt, argv[2]);
67 for (i = 3; i < argc; i++)
68 opt->option->boot_args = talloc_asprintf_append(
69 opt->option->boot_args,
74 static int builtin_initrd(struct grub2_script *script,
75 void *data __attribute__((unused)),
76 int argc, char *argv[])
78 struct discover_boot_option *opt = script->opt;
82 pb_log("grub2 syntax error: 'initrd' statement outside "
88 pb_log("grub2 syntax error: no filename provided to "
89 "initrd statement\n");
93 root = script_env_get(script, "root");
94 opt->initrd = create_grub2_resource(opt, script->ctx->device,
100 static int builtin_search(struct grub2_script *script,
101 void *data __attribute__((unused)),
102 int argc, char *argv[])
104 const char *env_var, *spec;
109 for (i = 1; i < argc - 1; i++) {
110 if (!strncmp(argv[i], "--set=", strlen("--set="))) {
111 env_var = argv[i] + strlen("--set=");
119 spec = argv[argc - 1];
121 script_env_set(script, env_var, spec);
140 .fn = builtin_initrd,
144 .fn = builtin_search,
148 void register_builtins(struct grub2_script *script)
152 for (i = 0; i < ARRAY_SIZE(builtins); i++)
153 script_register_function(script, builtins[i].name,
154 builtins[i].fn, NULL);