bootstd: Improve parsing on extlinux.conf files

These files can have tabs, but they are currently parsed as separate
lines. Fix this.

Also, some files provide a separate 'menu label' which has more
information than the 'label', so use that if available.

Finally, we don't yet have the ability to parse all entries in the
file until the user actually boots the extlinux.conf file. At present,
this means that the last entry is shown. It seems better to use the
first entry, so update it.

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2025-03-26 15:05:26 -06:00
parent ca46bc3115
commit fee414857c

View File

@@ -83,13 +83,29 @@ static int extlinux_fill_info(struct bootflow *bflow)
log_debug("parsing bflow file size %x\n", bflow->size);
membuf_init(&mb, bflow->buf, bflow->size);
membuf_putraw(&mb, bflow->size, true, &data);
while (len = membuf_readline(&mb, line, sizeof(line) - 1, ' ', true), len) {
while (len = membuf_readline(&mb, line, sizeof(line) - 1, 0, true), len) {
char *tok, *p = line;
const char *name = NULL;
if (*p == '#')
continue;
while (*p == ' ' || *p == '\t')
p++;
tok = strsep(&p, " ");
if (p) {
if (!strcmp("label", tok)) {
bflow->os_name = strdup(p);
name = p;
if (bflow->os_name)
break; /* just find the first */
} else if (!strcmp("menu", tok)) {
tok = strsep(&p, " ");
if (!strcmp("label", tok)) {
name = p;
}
}
if (name) {
free(bflow->os_name);
bflow->os_name = strdup(name);
if (!bflow->os_name)
return log_msg_ret("os", -ENOMEM);
}