[syslinux] [PATCH 2/5] ldlinux: Stop using the internal KT_* image types

Matt Fleming matt at console-pimps.org
Mon Jul 16 13:32:24 PDT 2012


From: Matt Fleming <matt.fleming at intel.com>

The KT_* image types were never meant to be used outside of
com32/menu, so use the external image types from syslinux/boot.h

Signed-off-by: Matt Fleming <matt.fleming at intel.com>
---
 com32/elflink/ldlinux/chainboot.c  |    5 ++-
 com32/elflink/ldlinux/execute.c    |   52 ++++++++++++++++++------------------
 com32/elflink/ldlinux/ldlinux.c    |   41 +++++++++++++---------------
 com32/elflink/ldlinux/readconfig.c |   16 +++++++++++
 com32/include/menu.h               |    7 -----
 com32/include/syslinux/boot.h      |   10 +++++++
 com32/menu/menumain.c              |    6 +++-
 com32/menu/readconfig.c            |    2 +-
 core/include/core.h                |    2 +
 9 files changed, 81 insertions(+), 60 deletions(-)

diff --git a/com32/elflink/ldlinux/chainboot.c b/com32/elflink/ldlinux/chainboot.c
index c1efadf..4a4a2e1 100644
--- a/com32/elflink/ldlinux/chainboot.c
+++ b/com32/elflink/ldlinux/chainboot.c
@@ -30,11 +30,12 @@
 #include "localboot.h"
 #include "bios.h"
 
+#include <syslinux/boot.h>
 #include <syslinux/bootrm.h>
 #include <syslinux/movebits.h>
 #include <syslinux/config.h>
 
-void chainboot_file(const char *file, enum kernel_type type)
+void chainboot_file(const char *file, uint32_t type)
 {
     uint8_t keeppxe = 0;
     const union syslinux_derivative_info *sdi;
@@ -97,7 +98,7 @@ void chainboot_file(const char *file, enum kernel_type type)
      * superblock.
      */
     if (sdi->c.filesystem == SYSLINUX_FS_SYSLINUX &&
-	type == KT_BSS && this_fs->fs_ops->copy_super(buf))
+	type == IMAGE_TYPE_BSS && this_fs->fs_ops->copy_super(buf))
 	goto bail;
 
     if (sdi->c.filesystem == SYSLINUX_FS_PXELINUX) {
diff --git a/com32/elflink/ldlinux/execute.c b/com32/elflink/ldlinux/execute.c
index 5d128cb..77d268c 100644
--- a/com32/elflink/ldlinux/execute.c
+++ b/com32/elflink/ldlinux/execute.c
@@ -28,29 +28,28 @@
 #include <syslinux/bootrm.h>
 #include <syslinux/movebits.h>
 #include <syslinux/config.h>
-
-/* Must match enum kernel_type */
-const char *const kernel_types[] = {
-    "none",
-    "localboot",
-    "kernel",
-    "linux",
-    "boot",
-    "bss",
-    "pxe",
-    "fdimage",
-    "comboot",
-    "com32",
-    "config",
-    NULL
+#include <syslinux/boot.h>
+
+const struct image_types image_boot_types[] = {
+    { "localboot", IMAGE_TYPE_LOCALBOOT },
+    { "kernel", IMAGE_TYPE_KERNEL },
+    { "linux", IMAGE_TYPE_LINUX },
+    { "boot", IMAGE_TYPE_BOOT },
+    { "bss", IMAGE_TYPE_BSS },
+    { "pxe", IMAGE_TYPE_PXE },
+    { "fdimage", IMAGE_TYPE_FDIMAGE },
+    { "comboot", IMAGE_TYPE_COMBOOT },
+    { "com32", IMAGE_TYPE_COM32 },
+    { "config", IMAGE_TYPE_CONFIG },
+    { NULL, 0 },
 };
 
 extern int create_args_and_load(char *);
 
-void execute(const char *cmdline, enum kernel_type type)
+void execute(const char *cmdline, uint32_t type)
 {
-	const char *p, *const *pp;
 	const char *kernel, *args;
+	const char *p;
 	com32sys_t ireg;
 	char *q;
 
@@ -79,22 +78,22 @@ void execute(const char *cmdline, enum kernel_type type)
 
 	dprintf("kernel is %s, args = %s  type = %d \n", kernel, args, type);
 
-	if (kernel[0] == '.' && type == KT_NONE) {
+	if (kernel[0] == '.') {
 		/* It might be a type specifier */
-		enum kernel_type type = KT_NONE;
-		for (pp = kernel_types; *pp; pp++, type++) {
-			if (!strcmp(kernel + 1, *pp)) {
+		const struct image_types *t;
+		for (t = image_boot_types; t->name; t++) {
+			if (!strcmp(kernel + 1, t->name)) {
 				/* Strip the type specifier and retry */
-				execute(p, type);
+				execute(p, t->type);
 				return;
 			}
 		}
 	}
 
-	if (type == KT_COM32) {
+	if (type == IMAGE_TYPE_COM32) {
 		/* new entry for elf format c32 */
 		create_args_and_load((char *)cmdline);
-	} else if (type == KT_CONFIG) {
+	} else if (type == IMAGE_TYPE_CONFIG) {
 		char *argv[] = { "ldlinux.c32", NULL };
 
 		/* kernel contains the config file name */
@@ -105,9 +104,10 @@ void execute(const char *cmdline, enum kernel_type type)
 			mangle_name(config_cwd, args);
 
 		start_ldlinux(argv);
-	} else if (type == KT_LOCALBOOT) {
+	} else if (type == IMAGE_TYPE_LOCALBOOT) {
 		local_boot(strtoul(kernel, NULL, 0));
-	} else if (type == KT_PXE || type == KT_BSS || type == KT_BOOT) {
+	} else if (type == IMAGE_TYPE_PXE || type == IMAGE_TYPE_BSS ||
+		   type == IMAGE_TYPE_BOOT) {
 		chainboot_file(kernel, type);
 	} else {
 		/* Need add one item for kernel load, as we don't use
diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index f56f2c0..8879d2a 100644
--- a/com32/elflink/ldlinux/ldlinux.c
+++ b/com32/elflink/ldlinux/ldlinux.c
@@ -11,6 +11,7 @@
 #include "menu.h"
 #include "config.h"
 #include "syslinux/adv.h"
+#include "syslinux/boot.h"
 
 #include <sys/module.h>
 
@@ -20,15 +21,15 @@ struct file_ext {
 };
 
 static const struct file_ext file_extensions[] = {
-	{ ".com", KT_COMBOOT },
-	{ ".cbt", KT_COMBOOT },
-	{ ".c32", KT_COM32 },
-	{ ".img", KT_FDIMAGE },
-	{ ".bss", KT_BSS },
-	{ ".bin", KT_BOOT },
-	{ ".bs", KT_BOOT },
-	{ ".0", KT_PXE },
-	{ NULL, KT_NONE },
+	{ ".com", IMAGE_TYPE_COMBOOT },
+	{ ".cbt", IMAGE_TYPE_COMBOOT },
+	{ ".c32", IMAGE_TYPE_COM32 },
+	{ ".img", IMAGE_TYPE_FDIMAGE },
+	{ ".bss", IMAGE_TYPE_BSS },
+	{ ".bin", IMAGE_TYPE_BOOT },
+	{ ".bs", IMAGE_TYPE_BOOT },
+	{ ".0", IMAGE_TYPE_PXE },
+	{ NULL, 0 },
 };
 
 /*
@@ -45,7 +46,7 @@ static inline const char *find_command(const char *str)
 	return p;
 }
 
-enum kernel_type parse_kernel_type(const char *kernel)
+uint32_t parse_image_type(const char *kernel)
 {
 	const struct file_ext *ext;
 	const char *p;
@@ -62,8 +63,8 @@ enum kernel_type parse_kernel_type(const char *kernel)
 			return ext->type;
 	}
 
-	/* use KT_KERNEL as default */
-	return KT_KERNEL;
+	/* use IMAGE_TYPE_KERNEL as default */
+	return IMAGE_TYPE_KERNEL;
 }
 
 /*
@@ -139,9 +140,9 @@ static const char *apply_extension(const char *kernel, const char *ext)
 static void load_kernel(const char *command_line)
 {
 	struct menu_entry *me;
-	enum kernel_type type;
 	const char *cmdline;
 	const char *kernel;
+	uint32_t type;
 
 	kernel = strdup(command_line);
 	if (!kernel)
@@ -150,11 +151,7 @@ static void load_kernel(const char *command_line)
 	/* 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;
+		type = parse_image_type(me->cmdline);
 
 		execute(me->cmdline, type);
 		/* We shouldn't return */
@@ -170,8 +167,8 @@ static void load_kernel(const char *command_line)
 		*p = '\0';
 	}
 
-	type = parse_kernel_type(kernel);
-	if (type == KT_KERNEL) {
+	type = parse_image_type(kernel);
+	if (type == IMAGE_TYPE_KERNEL) {
 		const char *ext;
 
 		/*
@@ -189,7 +186,7 @@ static void load_kernel(const char *command_line)
 			free((void *)kernel);
 			kernel = k;
 
-			type = parse_kernel_type(kernel);
+			type = parse_image_type(kernel);
 		}
 	}
 
@@ -204,7 +201,7 @@ bad_kernel:
 	 */
 	if (onerrorlen) {
 		rsprintf(&cmdline, "%s %s", onerror, default_cmd);
-		execute(cmdline, KT_COM32);
+		execute(cmdline, IMAGE_TYPE_COM32);
 	}
 }
 
diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c
index 1a8434c..1db397a 100644
--- a/com32/elflink/ldlinux/readconfig.c
+++ b/com32/elflink/ldlinux/readconfig.c
@@ -52,6 +52,22 @@ const struct menu_parameter mparm[NPARAMS] = {
     [P_HIDDEN_ROW] = {"hiddenrow", -2},
 };
 
+/* Must match enum kernel_type */
+static const char *const kernel_types[] = {
+    "none",
+    "localboot",
+    "kernel",
+    "linux",
+    "boot",
+    "bss",
+    "pxe",
+    "fdimage",
+    "comboot",
+    "com32",
+    "config",
+    NULL
+};
+
 short uappendlen = 0;		//bytes in append= command
 short ontimeoutlen = 0;		//bytes in ontimeout command
 short onerrorlen = 0;		//bytes in onerror command
diff --git a/com32/include/menu.h b/com32/include/menu.h
index a3e9cd6..5a4c901 100644
--- a/com32/include/menu.h
+++ b/com32/include/menu.h
@@ -92,10 +92,6 @@ enum kernel_type {
     KT_CONFIG,			/* Configuration file */
 };
 
-extern const char *const kernel_types[];
-
-extern enum kernel_type parse_kernel_type(const char *kernel);
-
 /* Configurable integer parameters */
 enum parameter_number {
     P_WIDTH,
@@ -230,9 +226,6 @@ extern const int message_base_color;
 extern const char *current_background;
 void set_background(const char *new_background);
 
-/* execute.c */
-void execute(const char *cmdline, enum kernel_type type);
-
 /* drain.c */
 void drain_keyboard(void);
 
diff --git a/com32/include/syslinux/boot.h b/com32/include/syslinux/boot.h
index 870cff3..aea32d9 100644
--- a/com32/include/syslinux/boot.h
+++ b/com32/include/syslinux/boot.h
@@ -48,6 +48,13 @@ void syslinux_chain_bootstrap(uint16_t flags, const void *bootstrap,
 			      uint32_t bootstrap_len, uint32_t edx,
 			      uint32_t esi, uint16_t ds);
 
+struct image_types {
+    const char *name;
+    uint32_t type;
+};
+
+extern const struct image_types image_boot_types[];
+
 #define IMAGE_TYPE_KERNEL	0
 #define IMAGE_TYPE_LINUX	1
 #define IMAGE_TYPE_BOOT		2
@@ -57,6 +64,9 @@ void syslinux_chain_bootstrap(uint16_t flags, const void *bootstrap,
 #define IMAGE_TYPE_COMBOOT	6
 #define IMAGE_TYPE_COM32	7
 #define IMAGE_TYPE_CONFIG	8
+#define IMAGE_TYPE_LOCALBOOT	9
+
+uint32_t parse_image_type(const char *cmdline);
 void syslinux_run_kernel_image(const char *filename, const char *cmdline,
 			       uint32_t ipappend_flags, uint32_t type);
 
diff --git a/com32/menu/menumain.c b/com32/menu/menumain.c
index 53bc6c6..c9762b2 100644
--- a/com32/menu/menumain.c
+++ b/com32/menu/menumain.c
@@ -28,7 +28,9 @@
 #include <setjmp.h>
 #include <limits.h>
 #include <com32.h>
+#include <core.h>
 #include <syslinux/adv.h>
+#include <syslinux/boot.h>
 
 #include "menu.h"
 
@@ -1161,11 +1163,11 @@ int main(int argc, char *argv[])
 	printf("\033[?25h\033[%d;1H\033[0m", cursorrow);
 
 	if (cmdline) {
-	    enum kernel_type type = parse_kernel_type(cmdline);
+	    uint32_t type = parse_image_type(cmdline);
 
 	    execute(cmdline, type);
 	    if (cm->onerror) {
-		type = parse_kernel_type(cm->onerror);
+		type = parse_image_type(cm->onerror);
 		execute(cm->onerror, type);
 	    }
 	} else {
diff --git a/com32/menu/readconfig.c b/com32/menu/readconfig.c
index 8f9d237..69f524c 100644
--- a/com32/menu/readconfig.c
+++ b/com32/menu/readconfig.c
@@ -62,7 +62,7 @@ static const struct messages messages[MSG_COUNT] = {
                       __p; })
 
 /* Must match enum kernel_type */
-const char *const kernel_types[] = {
+static const char *const kernel_types[] = {
     "none",
     "localboot",
     "kernel",
diff --git a/core/include/core.h b/core/include/core.h
index e19f2f1..6604a5b 100644
--- a/core/include/core.h
+++ b/core/include/core.h
@@ -111,4 +111,6 @@ extern void cleanup_hardware(void);
 extern void sirq_cleanup(void);
 extern void adjust_screen(void);
 
+extern void execute(const char *cmdline, uint32_t type);
+
 #endif /* CORE_H */
-- 
1.7.4.4




More information about the Syslinux mailing list