summaryrefslogtreecommitdiffstats
path: root/discover
diff options
context:
space:
mode:
authorJavier Martinez Canillas <javierm@redhat.com>2018-04-17 19:09:00 +0200
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-04-18 11:10:48 +1000
commitc41ffccdaf16b0820904c5dd2e5d7612bfbefc65 (patch)
treef87703a1a1544c43b5030b98792297be5e986baf /discover
parentf78714f16515783d79e636040cedccb3eb6611a3 (diff)
downloadtalos-petitboot-c41ffccdaf16b0820904c5dd2e5d7612bfbefc65.zip
talos-petitboot-c41ffccdaf16b0820904c5dd2e5d7612bfbefc65.tar.gz
discover/grub: Allow to set a default index for BLS entries
When the BLS support was added, the conclusion was that default indexes didn't apply for BLS snippets. But for GRUB 2 the indexes refers to the boot menu entries in memory, regardless of how these were generated. Since in GRUB 2 is valid to set a default index even for menu entries generated from BLS fragments, allow this to also be done in Petitboot. Signed-off-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover')
-rw-r--r--discover/grub2/blscfg.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/discover/grub2/blscfg.c b/discover/grub2/blscfg.c
index 5dadd2c..a1076b9 100644
--- a/discover/grub2/blscfg.c
+++ b/discover/grub2/blscfg.c
@@ -20,6 +20,7 @@
struct bls_state {
struct discover_boot_option *opt;
struct grub2_script *script;
+ unsigned int idx;
const char *filename;
const char *title;
const char *version;
@@ -81,19 +82,25 @@ static void bls_process_pair(struct conf_context *conf, const char *name,
}
}
-static bool option_is_default(struct grub2_script *script,
+static bool option_is_default(struct bls_state *state,
struct boot_option *option)
{
+ unsigned int idx;
const char *var;
+ char *end;
- var = script_env_get(script, "default");
+ var = script_env_get(state->script, "default");
if (!var)
return false;
if (!strcmp(var, option->id))
return true;
- return !strcmp(var, option->name);
+ if (!strcmp(var, option->name))
+ return true;
+
+ idx = strtoul(var, &end, 10);
+ return end != var && *end == '\0' && idx == state->idx;
}
static void bls_finish(struct conf_context *conf)
@@ -141,7 +148,7 @@ static void bls_finish(struct conf_context *conf)
opt->dtb = create_grub2_resource(opt, conf->dc->device,
root, state->dtb);
- option->is_default = option_is_default(state->script, option);
+ option->is_default = option_is_default(state, option);
list_add_tail(&state->script->options, &opt->list);
state->script->n_options++;
@@ -176,6 +183,7 @@ int builtin_blscfg(struct grub2_script *script,
int argc __attribute__((unused)),
char *argv[] __attribute__((unused)))
{
+ unsigned int current_idx = script->n_options;
struct discover_context *dc = script->ctx;
struct dirent **bls_entries;
struct conf_context *conf;
@@ -217,6 +225,7 @@ int builtin_blscfg(struct grub2_script *script,
state->script = script;
state->filename = filename;
+ state->idx = current_idx++;
conf->parser_info = state;
rc = parser_request_file(dc, dc->device, filename, &buf, &len);
OpenPOWER on IntegriCloud