From b0a737c5cdbd7de3790bc5cf9a0e4b21dd1aed56 Mon Sep 17 00:00:00 2001 From: Matt Fleming Date: Thu, 9 Feb 2012 10:15:38 +0000 Subject: [PATCH] ldlinux: Parse kernel type for labels We need to parse the kernel type for labels aswell as things entered on the cmdline, instead of always passing KT_KERNEL or KT_NONE to execute(). Move the logic into a new helper function. This fixes a bug where an incorrect kernel type would be passed to execute() if anything other than a linux kernel (such as a .bin) was specified in a LABEL's KERNEL argument, which resulted in the file not being executed. Signed-off-by: Matt Fleming --- com32/elflink/ldlinux/ldlinux.c | 66 ++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c index 5360417..dcde542 100644 --- a/com32/elflink/ldlinux/ldlinux.c +++ b/com32/elflink/ldlinux/ldlinux.c @@ -11,43 +11,19 @@ #include -/* - * Attempt to load a kernel after deciding what type of image it is. - * - * We only return from this function if something went wrong loading - * the the kernel. If we return the caller should call enter_cmdline() - * so that the user can help us out. - */ -static void load_kernel(const char *kernel) +static enum kernel_type parse_kernel_type(char *kernel) { - struct menu_entry *me; enum kernel_type type; - const char *cmdline, *p; + const char *p; int len; - /* Virtual kernel? */ - me = find_label(kernel); - if (me) { - enum kernel_type type = KT_KERNEL; - - /* cmdline contains type specifier */ - if (me->cmdline[0] == '.') - type = KT_NONE; - - execute(me->cmdline, type); - /* We shouldn't return */ - goto bad_kernel; - } - - if (!allowimplicit) - goto bad_implicit; - - p = kernel; /* Find the end of the command */ + p = kernel; while (*p && !my_isspace(*p)) p++; len = p - kernel; + if (!strncmp(kernel + len - 4, ".c32", 4)) { type = KT_COM32; } else if (!strncmp(kernel + len - 2, ".0", 2)) { @@ -68,6 +44,40 @@ static void load_kernel(const char *kernel) else type = KT_KERNEL; + return type; +} + +/* + * Attempt to load a kernel after deciding what type of image it is. + * + * We only return from this function if something went wrong loading + * the the kernel. If we return the caller should call enter_cmdline() + * so that the user can help us out. + */ +static void load_kernel(const char *kernel) +{ + struct menu_entry *me; + enum kernel_type type; + const char *cmdline; + + /* Virtual kernel? */ + me = find_label(kernel); + if (me) { + type = parse_kernel_type(me->cmdline); + + /* cmdline contains type specifier */ + if (me->cmdline[0] == '.') + type = KT_NONE; + + execute(me->cmdline, type); + /* We shouldn't return */ + goto bad_kernel; + } + + if (!allowimplicit) + goto bad_implicit; + + type = parse_kernel_type(kernel); execute(kernel, type); bad_implicit: -- 2.7.4