From fee414857c9dd625ad8f8b2ba83a0c492116d563 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 26 Mar 2025 15:05:26 -0600 Subject: [PATCH] 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 --- boot/bootmeth_extlinux.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/boot/bootmeth_extlinux.c b/boot/bootmeth_extlinux.c index 71a9009479b..2a268cca9f7 100644 --- a/boot/bootmeth_extlinux.c +++ b/boot/bootmeth_extlinux.c @@ -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); }