From: Matt Fleming <matt.fleming at linux.intel.com> This is a series of patches that, * shrink the core by moving things into an ldlinux ELF module * begin wiring up some of the C versions of various functions The core now only contains essential code and loads the ldlinux module to do everything else, like providing a command line interface and loading kernels. The config file parsing and kernel load are now done entirely in C. This allows us to only parse the config file once, even when using the menu module. Previously the config file would be parsed from asm to extract the ui module or kernel to load, and then (once the menu module was running) would be parsed again in order to build the menu data structures. We now build the menu data structures on the first (and only) parse of the config file, not to mention the fact that we only need one copy of the parser now. Other functions will be converted from asm to C later. This series is also available at, git://git.zytor.com/users/mfleming/syslinux.git elflink-readconfig-for-hpa Matt Fleming (12): dprintf: Print to stdout as well as serial ports elflink: Remove *.c32 on 'make clean' core: Be less verbose at boot elflink: Don't pass NULL to spawn_load() elflink: Move code out of core and into ldlinux.c32 elflink: Look for syslinux.cfg elflink: Move config data into config.h elflink: Don't reload the current EXEC_MODULE module Convert mp() to dprintf() ldlinux: Record "default" and "ui" command lines ldlinux: Parse configuration files ldlinux: Parse and store the "onerror" command line com32/Makefile | 2 +- com32/elflink/ldlinux/Makefile | 38 ++++ {core/elflink => com32/elflink/ldlinux}/adv.c | 0 {core/elflink => com32/elflink/ldlinux}/cli.c | 51 ++++- {core/elflink => com32/elflink/ldlinux}/colors.c | 0 com32/elflink/ldlinux/config.h | 39 ++++ {core/elflink => com32/elflink/ldlinux}/getadv.c | 0 {core/elflink => com32/elflink/ldlinux}/ipappend.c | 0 com32/elflink/ldlinux/ldlinux.c | 83 +++++++ .../elflink => com32/elflink/ldlinux}/readconfig.c | 92 +++++---- {core/elflink => com32/elflink/ldlinux}/refstr.c | 0 {core/elflink => com32/elflink/ldlinux}/refstr.h | 0 com32/elflink/modules/Makefile | 4 +- com32/elflink/modules/cli.h | 6 +- com32/elflink/modules/menu.h | 17 -- com32/elflink/modules/menumain.c | 6 +- com32/elflink/modules/test.c | 7 +- com32/include/sys/module.h | 2 +- com32/lib/sys/module/elf_module.c | 3 +- com32/lib/sys/module/exec.c | 35 +++- com32/lib/vdprintf.c | 6 +- core/elflink/abort_new.c | 29 --- core/elflink/cli.h | 23 -- core/elflink/core-elf.h | 21 ++- core/elflink/execute.c | 30 +++- core/elflink/get_key.c | 175 --------------- core/elflink/getkey.h | 80 ------- core/elflink/kernel.c | 8 +- core/elflink/load_env32.c | 52 +----- core/elflink/menu.h | 229 -------------------- core/extern.inc | 2 +- core/isolinux.asm | 6 - core/mem/free.c | 3 +- core/mem/init.c | 9 +- core/ui.inc | 1 - elf_gen_dep.sh | 2 +- 36 files changed, 363 insertions(+), 698 deletions(-) create mode 100644 com32/elflink/ldlinux/Makefile rename {core/elflink => com32/elflink/ldlinux}/adv.c (100%) rename {core/elflink => com32/elflink/ldlinux}/cli.c (90%) rename {core/elflink => com32/elflink/ldlinux}/colors.c (100%) create mode 100644 com32/elflink/ldlinux/config.h rename {core/elflink => com32/elflink/ldlinux}/getadv.c (100%) rename {core/elflink => com32/elflink/ldlinux}/ipappend.c (100%) create mode 100644 com32/elflink/ldlinux/ldlinux.c rename {core/elflink => com32/elflink/ldlinux}/readconfig.c (93%) rename {core/elflink => com32/elflink/ldlinux}/refstr.c (100%) rename {core/elflink => com32/elflink/ldlinux}/refstr.h (100%) delete mode 100644 core/elflink/abort_new.c delete mode 100644 core/elflink/cli.h delete mode 100644 core/elflink/get_key.c delete mode 100644 core/elflink/getkey.h delete mode 100644 core/elflink/menu.h -- 1.7.4
Matt Fleming
2011-Mar-09 16:00 UTC
[syslinux] [PATCH 01/12] dprintf: Print to stdout as well as serial ports
From: Matt Fleming <matt.fleming at linux.intel.com> The intention here is to make dprintf the de-facto function for printing all debugging information. As such, it's useful to print to the serial ports and stdout so that developers are not required to hook up a serial port to view output. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/lib/vdprintf.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/com32/lib/vdprintf.c b/com32/lib/vdprintf.c index d74f278..76da012 100644 --- a/com32/lib/vdprintf.c +++ b/com32/lib/vdprintf.c @@ -49,13 +49,13 @@ static void debug_putc(char c) void vdprintf(const char *format, va_list ap) { - int rv; + int rv, _rv; char buffer[BUFFER_SIZE]; char *p; static bool debug_init = false; static bool debug_ok = false; - rv = vsnprintf(buffer, BUFFER_SIZE, format, ap); + _rv = rv = vsnprintf(buffer, BUFFER_SIZE, format, ap); if (rv < 0) return; @@ -113,4 +113,6 @@ void vdprintf(const char *format, va_list ap) p = buffer; while (rv--) debug_putc(*p++); + + _fwrite(buffer, _rv, stdout); } -- 1.7.4
Matt Fleming
2011-Mar-09 16:00 UTC
[syslinux] [PATCH 02/12] elflink: Remove *.c32 on 'make clean'
From: Matt Fleming <matt.fleming at linux.intel.com> The clean target should also remove any .c32 files. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/modules/Makefile | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/com32/elflink/modules/Makefile b/com32/elflink/modules/Makefile index 9c9cb97..8a97835 100644 --- a/com32/elflink/modules/Makefile +++ b/com32/elflink/modules/Makefile @@ -97,7 +97,7 @@ tidy dist: rm -f *.o *.lo *.a *.lst .*.d clean: tidy - rm -f *.lss *.lnx *.com + rm -f *.lss *.lnx *.com *.c32 spotless: clean rm -f *~ \#* -- 1.7.4
From: Matt Fleming <matt.fleming at linux.intel.com> Change some printf() calls to dprintf() so that we stop printing debugging information that is only useful for developers. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- core/elflink/load_env32.c | 3 ++- core/mem/free.c | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c index 8d0a557..e4e4d62 100644 --- a/core/elflink/load_env32.c +++ b/core/elflink/load_env32.c @@ -3,6 +3,7 @@ #include <unistd.h> #include <string.h> #include <console.h> +#include <dprintf.h> #include <com32.h> #include <syslinux/adv.h> #include <syslinux/config.h> @@ -112,7 +113,7 @@ void start_ui(char *config_file) /* note to self: do _*NOT*_ use static key word on this function */ void load_env32(com32sys_t * regs) { - printf("Starting 32 bit elf module subsystem...\n"); + dprintf("Starting 32 bit elf module subsystem...\n"); call_constr(); openconsole(&dev_rawcon_r, &dev_ansiserial_w); INIT_LIST_HEAD(&cli_history_head); diff --git a/core/mem/free.c b/core/mem/free.c index 70b45a3..2908943 100644 --- a/core/mem/free.c +++ b/core/mem/free.c @@ -100,8 +100,7 @@ void __inject_free_block(struct free_arena_header *ah) size_t a_end = (size_t) ah + ARENA_SIZE_GET(ah->a.attrs); size_t n_end; - //dprintf("inject: %#zx bytes @ %p, heap %u (%p)\n", - printf("inject: %#zx bytes @%p, heap%u (%p)\n", + dprintf("inject: %#zx bytes @ %p, heap %u (%p)\n", ARENA_SIZE_GET(ah->a.attrs), ah, ARENA_HEAP_GET(ah->a.attrs), head); -- 1.7.4
Matt Fleming
2011-Mar-09 16:00 UTC
[syslinux] [PATCH 04/12] elflink: Don't pass NULL to spawn_load()
From: Matt Fleming <matt.fleming at linux.intel.com> As spawn_load() dereferences the 'argv' parameter it really doesn't expect it to be NULL. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/lib/sys/module/exec.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-) diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c index 30a61c0..0e7aa3f 100644 --- a/com32/lib/sys/module/exec.c +++ b/com32/lib/sys/module/exec.c @@ -387,8 +387,10 @@ int module_load_dependencies(const char *name,const char *dep_file) i++; /* skip a space */ if (strlen(temp_name)) { + char *argv[2] = { NULL, NULL }; + module_load_dependencies(temp_name, MODULES_DEP); - if (spawn_load(temp_name, NULL) < 0) + if (spawn_load(temp_name, argv) < 0) continue; } } -- 1.7.4
Matt Fleming
2011-Mar-09 16:00 UTC
[syslinux] [PATCH 05/12] elflink: Move code out of core and into ldlinux.c32
From: Matt Fleming <matt.fleming at linux.intel.com> Currently, there is a lot of code in core/elflink that is not strictly required for the core to function. There are benefits to keeping the core proper as small as possible, for example so that it can fit within a single 64K block on btrfs. So move the following pieces of code out of core/elflink and into a new ldlinux ELF module which will be automatically loaded by the core: - command line interface code - C configuration parser - refstr implementation - rest of the menu system Below are some measurements of the size of ldlinux.elf before and after this change. Before: text data bss dec hex filename 161328 10439 913468 1085235 108f33 core/ldlinux.elf After: text data bss dec hex filename 142423 10415 909500 1062338 1035c2 core/ldlinux.elf Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/Makefile | 2 +- com32/elflink/ldlinux/Makefile | 38 ++++ {core/elflink => com32/elflink/ldlinux}/adv.c | 0 {core/elflink => com32/elflink/ldlinux}/cli.c | 46 ++++- {core/elflink => com32/elflink/ldlinux}/colors.c | 0 {core/elflink => com32/elflink/ldlinux}/getadv.c | 0 {core/elflink => com32/elflink/ldlinux}/ipappend.c | 0 com32/elflink/ldlinux/ldlinux.c | 34 +++ .../elflink => com32/elflink/ldlinux}/readconfig.c | 21 +-- {core/elflink => com32/elflink/ldlinux}/refstr.c | 0 {core/elflink => com32/elflink/ldlinux}/refstr.h | 0 com32/elflink/modules/Makefile | 2 + com32/elflink/modules/cli.h | 6 +- com32/elflink/modules/menu.h | 17 -- com32/elflink/modules/menumain.c | 1 + core/elflink/abort_new.c | 29 --- core/elflink/cli.h | 23 -- core/elflink/core-elf.h | 21 ++- core/elflink/execute.c | 27 +++- core/elflink/get_key.c | 175 --------------- core/elflink/getkey.h | 80 ------- core/elflink/kernel.c | 3 + core/elflink/load_env32.c | 49 +---- core/elflink/menu.h | 229 -------------------- core/extern.inc | 2 +- core/ui.inc | 1 - elf_gen_dep.sh | 2 +- 27 files changed, 168 insertions(+), 640 deletions(-) create mode 100644 com32/elflink/ldlinux/Makefile rename {core/elflink => com32/elflink/ldlinux}/adv.c (100%) rename {core/elflink => com32/elflink/ldlinux}/cli.c (91%) rename {core/elflink => com32/elflink/ldlinux}/colors.c (100%) rename {core/elflink => com32/elflink/ldlinux}/getadv.c (100%) rename {core/elflink => com32/elflink/ldlinux}/ipappend.c (100%) create mode 100644 com32/elflink/ldlinux/ldlinux.c rename {core/elflink => com32/elflink/ldlinux}/readconfig.c (99%) rename {core/elflink => com32/elflink/ldlinux}/refstr.c (100%) rename {core/elflink => com32/elflink/ldlinux}/refstr.h (100%) delete mode 100644 core/elflink/abort_new.c delete mode 100644 core/elflink/cli.h delete mode 100644 core/elflink/get_key.c delete mode 100644 core/elflink/getkey.h delete mode 100644 core/elflink/menu.h diff --git a/com32/Makefile b/com32/Makefile index de9ad28..bc13cf6 100644 --- a/com32/Makefile +++ b/com32/Makefile @@ -1,4 +1,4 @@ SUBDIRS = tools lib gpllib libutil modules mboot menu samples elflink elflink/modules rosh cmenu \ - hdt gfxboot sysdump lua/src + hdt gfxboot sysdump lua/src elflink/ldlinux all tidy dist clean spotless install: set -e; for d in $(SUBDIRS); do $(MAKE) -C $$d $@; done diff --git a/com32/elflink/ldlinux/Makefile b/com32/elflink/ldlinux/Makefile new file mode 100644 index 0000000..339e13e --- /dev/null +++ b/com32/elflink/ldlinux/Makefile @@ -0,0 +1,38 @@ +## ----------------------------------------------------------------------- +## +## Copyright 2011 Intel Corporation - All Rights Reserved +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation, Inc., 53 Temple Place Ste 330, +## Boston MA 02111-1307, USA; either version 2 of the License, or +## (at your option) any later version; incorporated herein by reference. +## +## ----------------------------------------------------------------------- + +topdir = ../../.. +include ../modules/MCONFIG + +CFLAGS += -I../modules -I$(topdir)/core/elflink + +all: ldlinux.c32 + +ldlinux.c32 : ldlinux.o cli.o readconfig.o refstr.o colors.o getadv.o \ + adv.o ipappend.o + $(LD) $(LDFLAGS) -o $@ $^ + +tidy dist: + rm -f *.o *.lo *.a *.lst .*.d + +clean: tidy + rm -f *.lss *.lnx *.com *.c32 + +spotless: clean + rm -f *~ \#* + +install: all + mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR) + install -m 644 ldlinux.c32 $(INSTALLROOT)$(AUXDIR) + + +-include .*.d diff --git a/core/elflink/adv.c b/com32/elflink/ldlinux/adv.c similarity index 100% rename from core/elflink/adv.c rename to com32/elflink/ldlinux/adv.c diff --git a/core/elflink/cli.c b/com32/elflink/ldlinux/cli.c similarity index 91% rename from core/elflink/cli.c rename to com32/elflink/ldlinux/cli.c index f029ae4..551113f 100644 --- a/core/elflink/cli.c +++ b/com32/elflink/ldlinux/cli.c @@ -12,16 +12,19 @@ #include <linux/list.h> #include <sys/exec.h> #include <sys/module.h> -#include <core.h> +#include <core-elf.h> #include "getkey.h" -#include "common.h" #include "menu.h" #include "cli.h" +static jmp_buf timeout_jump; + +static struct list_head cli_history_head; + void clear_screen(void) { - mp("enter"); + //mp("enter"); fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout); } @@ -31,7 +34,7 @@ int mygetkey(clock_t timeout) clock_t tto, to; int key; - //mp("enter"); + //mp("enter"); if (!totaltimeout) return get_key(stdin, timeout); @@ -39,9 +42,9 @@ int mygetkey(clock_t timeout) tto = min(totaltimeout, INT_MAX); to = timeout ? min(tto, timeout) : tto; - t0 = jiffies(); + t0 = 0; key = get_key(stdin, to); - t = jiffies() - t0; + t = 0 - t0; if (totaltimeout <= t) longjmp(timeout_jump, 1); @@ -348,7 +351,7 @@ const char *edit_cmdline(const char *input, int top /*, int width */ , return ret; } -void process_command(const char *cmd) +void process_command(const char *cmd, bool history) { char **argv = malloc((MAX_COMMAND_ARGS + 1) * sizeof(char *)); char *temp_cmd = (char *)malloc(sizeof(char) * (strlen(cmd) + 1)); @@ -362,7 +365,17 @@ void process_command(const char *cmd) } printf("\n"); - mp("raw cmd = %s", cmd); + if (history) { + struct cli_command *comm; + + comm = (struct cli_command *)malloc(sizeof(struct cli_command *)); + comm->command + (char *)malloc(sizeof(char) * (strlen(cmd) + 1)); + strcpy(comm->command, cmd); + list_add(&(comm->list), &cli_history_head); + } + + // mp("raw cmd = %s", cmd); strcpy(temp_cmd, cmd); module_name = strtok(cmd, COMMAND_DELIM); len_mn = strlen(module_name); @@ -370,7 +383,7 @@ void process_command(const char *cmd) if (!strcmp(module_name + len_mn - 4, ".c32")) { if (module_find(module_name) != NULL) { /* make module re-enterable */ - mp("Module %s is already running"); + // mp("Module %s is already running"); } do { argv[0] = module_name; @@ -408,3 +421,18 @@ cleanup: free(argv); free(temp_cmd); } + +static int cli_init(void) +{ + INIT_LIST_HEAD(&cli_history_head); + + return 0; +} + +static void cli_exit(void) +{ + /* Nothing to do */ +} + +MODULE_INIT(cli_init); +MODULE_EXIT(cli_exit); diff --git a/core/elflink/colors.c b/com32/elflink/ldlinux/colors.c similarity index 100% rename from core/elflink/colors.c rename to com32/elflink/ldlinux/colors.c diff --git a/core/elflink/getadv.c b/com32/elflink/ldlinux/getadv.c similarity index 100% rename from core/elflink/getadv.c rename to com32/elflink/ldlinux/getadv.c diff --git a/core/elflink/ipappend.c b/com32/elflink/ldlinux/ipappend.c similarity index 100% rename from core/elflink/ipappend.c rename to com32/elflink/ldlinux/ipappend.c diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c new file mode 100644 index 0000000..967eebb --- /dev/null +++ b/com32/elflink/ldlinux/ldlinux.c @@ -0,0 +1,34 @@ +#include <linux/list.h> +#include <sys/times.h> +#include <stdbool.h> +#include "cli.h" +#include "console.h" + +#include <sys/module.h> + +static void enter_cmdline(void) +{ + struct cli_command *aux; + char *cmdline; + + /* Enter endless command line prompt, should support "exit" */ + while (1) { + cmdline = edit_cmdline("", 1, NULL, NULL); + /* feng: give up the aux check here */ + //aux = list_entry(cli_history_head.next, typeof(*aux), list); + //if (strcmp(aux->command, cmdline)) { + process_command(cmdline, true); + //} + } +} + +static int ldlinux_main(int argc, char **argv) +{ + openconsole(&dev_rawcon_r, &dev_ansiserial_w); + + /* Should never return */ + enter_cmdline(); + + return 0; +} +MODULE_MAIN(ldlinux_main); diff --git a/core/elflink/readconfig.c b/com32/elflink/ldlinux/readconfig.c similarity index 99% rename from core/elflink/readconfig.c rename to com32/elflink/ldlinux/readconfig.c index 39b5d12..9857233 100644 --- a/core/elflink/readconfig.c +++ b/com32/elflink/ldlinux/readconfig.c @@ -22,6 +22,7 @@ #include <com32.h> #include <syslinux/adv.h> #include <syslinux/config.h> +#include <core-elf.h> #include "menu.h" @@ -70,7 +71,7 @@ long long totaltimeout = 0; /* Keep track of global default */ static int has_ui = 0; /* DEFAULT only counts if UI is found */ -char *globaldefault = NULL; +extern char *globaldefault; static bool menusave = false; /* True if there is any "menu save" */ /* Linked list of all entires, hidden or not; used by unlabel() */ @@ -90,22 +91,6 @@ static const struct messages messages[MSG_COUNT] = { if ( __p ) memcpy(__p, __x, __n); \ __p; }) -/* Must match enum kernel_type */ -const char *const kernel_types[] = { - "none", - "localboot", - "kernel", - "linux", - "boot", - "bss", - "pxe", - "fdimage", - "comboot", - "com32", - "config", - NULL -}; - /* * Search the list of all menus for a specific label */ @@ -579,7 +564,7 @@ uint32_t parse_argb(char **p) * same way as if the files had been concatenated together. */ //static const char *append = NULL; -char *append = NULL; +extern char *append; //static unsigned int ipappend = 0; unsigned int ipappend = 0; static struct labeldata ld; diff --git a/core/elflink/refstr.c b/com32/elflink/ldlinux/refstr.c similarity index 100% rename from core/elflink/refstr.c rename to com32/elflink/ldlinux/refstr.c diff --git a/core/elflink/refstr.h b/com32/elflink/ldlinux/refstr.h similarity index 100% rename from core/elflink/refstr.h rename to com32/elflink/ldlinux/refstr.h diff --git a/com32/elflink/modules/Makefile b/com32/elflink/modules/Makefile index 8a97835..6cd0767 100644 --- a/com32/elflink/modules/Makefile +++ b/com32/elflink/modules/Makefile @@ -13,6 +13,8 @@ topdir = ../../.. include MCONFIG +CFLAGS += -I$(topdir)/core/elflink + MODULES = hello.c32 sort.c32 mytest.c32 menumain.c32 printmsg.c32 background.c32 passwd.c32 sha1hash.c32 \ unbase64.c32 sha512crypt.c32 md5.c32 crypt-md5.c32 sha256crypt.c32 get_key.c32 ansiraw.c32 test.c32 \ meminfo.c32 menu.c32 drain.c32 dir.c32 pcitest.c32 vesainfo.c32 cpuid.c32 cpuidtest.c32 diff --git a/com32/elflink/modules/cli.h b/com32/elflink/modules/cli.h index c452643..4ae9caf 100644 --- a/com32/elflink/modules/cli.h +++ b/com32/elflink/modules/cli.h @@ -2,18 +2,20 @@ #define CLI_H #define MAX_CMD_HISTORY 64 +#define COMMAND_DELIM " \t\n" // Whitespace delimiters +#define MAX_COMMAND_ARGS 40 struct cli_command { struct list_head list; char *command; }; -struct list_head cli_history_head; - extern void clear_screen(void); extern int mygetkey(clock_t timeout); extern const char *edit_cmdline(const char *input, int top /*, int width */ , int (*pDraw_Menu) (int, int, int), void (*show_fkey) (int)); +extern void process_command(const char *cmd, bool history); +extern struct menu *root_menu, *start_menu, *hide_menu, *menu_list, *default_menu; #endif diff --git a/com32/elflink/modules/menu.h b/com32/elflink/modules/menu.h index 5b05fe8..c7d7079 100644 --- a/com32/elflink/modules/menu.h +++ b/com32/elflink/modules/menu.h @@ -69,23 +69,6 @@ static inline bool is_disabled(struct menu_entry *me) return me->action == MA_DISABLED; } -enum kernel_type { - /* Meta-types for internal use */ - KT_NONE, - KT_LOCALBOOT, - - /* The ones we can pass off to SYSLINUX, in order */ - KT_KERNEL, /* Undefined type */ - KT_LINUX, /* Linux kernel */ - KT_BOOT, /* Bootstrap program */ - KT_BSS, /* Boot sector with patch */ - KT_PXE, /* PXE NBP */ - KT_FDIMAGE, /* Floppy disk image */ - KT_COMBOOT, /* COMBOOT image */ - KT_COM32, /* COM32 image */ - KT_CONFIG, /* Configuration file */ -}; - extern const char *const kernel_types[]; /* Configurable integer parameters */ diff --git a/com32/elflink/modules/menumain.c b/com32/elflink/modules/menumain.c index 8628585..265f4c4 100644 --- a/com32/elflink/modules/menumain.c +++ b/com32/elflink/modules/menumain.c @@ -30,6 +30,7 @@ #include <com32.h> #include <syslinux/adv.h> #include <sys/module.h> +#include <core-elf.h> #include "menu.h" #include "cli.h" diff --git a/core/elflink/abort_new.c b/core/elflink/abort_new.c deleted file mode 100644 index 39ba226..0000000 --- a/core/elflink/abort_new.c +++ /dev/null @@ -1,29 +0,0 @@ -#include <stdbool.h> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <console.h> - -//#include <syslinux/loadfile.h> -//#include <syslinux/linux.h> -//#include <syslinux/pxe.h> - -#include "core.h" -#include "core-elf.h" -#include "menu.h" - -void abort_load_new(com32sys_t *reg) -{ - char *str; - - str = (void *)reg->esi.l; - - printf("Error!\n"); - if (str) - printf("%s\n", str); - - if (onerrorlen) - execute(start_menu->onerror, KT_NONE); - enter_cmdline(); - return; -} diff --git a/core/elflink/cli.h b/core/elflink/cli.h deleted file mode 100644 index 9cd8c16..0000000 --- a/core/elflink/cli.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef CLI_H -#define CLI_H - -#define MAX_CMD_HISTORY 64 -#define COMMAND_DELIM " \t\n" // Whitespace delimiters -#define MAX_COMMAND_ARGS 40 - -struct cli_command { - struct list_head list; - char *command; -}; - -struct list_head cli_history_head; - -extern void clear_screen(void); -extern int mygetkey(clock_t timeout); -extern const char *edit_cmdline(const char *input, int top /*, int width */ , - int (*pDraw_Menu) (int, int, int), - void (*show_fkey) (int)); -extern void process_command(const char *cmd); - -extern struct menu *root_menu, *start_menu, *hide_menu, *menu_list, *default_menu; -#endif diff --git a/core/elflink/core-elf.h b/core/elflink/core-elf.h index 1edd174..d13f506 100644 --- a/core/elflink/core-elf.h +++ b/core/elflink/core-elf.h @@ -1,16 +1,29 @@ #ifndef _CORE_ELF_H #define _coRE_ELF_H +enum kernel_type { + /* Meta-types for internal use */ + KT_NONE, + KT_LOCALBOOT, + + /* The ones we can pass off to SYSLINUX, in order */ + KT_KERNEL, /* Undefined type */ + KT_LINUX, /* Linux kernel */ + KT_BOOT, /* Bootstrap program */ + KT_BSS, /* Boot sector with patch */ + KT_PXE, /* PXE NBP */ + KT_FDIMAGE, /* Floppy disk image */ + KT_COMBOOT, /* COMBOOT image */ + KT_COM32, /* COM32 image */ + KT_CONFIG, /* Configuration file */ +}; + extern char *append; extern char *ippappend; extern char *globaldefault; extern short onerrorlen; -extern void parse_configs(char **argv); extern int new_linux_kernel(char *okernel, char *ocmdline); -/* load_env32.c, should be moved out */ -extern void enter_cmdline(void); - extern void start_ui(char *config_file); #endif diff --git a/core/elflink/execute.c b/core/elflink/execute.c index 29e9933..6410c7d 100644 --- a/core/elflink/execute.c +++ b/core/elflink/execute.c @@ -15,7 +15,28 @@ #include <stdio.h> #include <com32.h> -#include "menu.h" +#include "core-elf.h" + +/* Must match enum kernel_type */ +const char *const kernel_types[] = { + "none", + "localboot", + "kernel", + "linux", + "boot", + "bss", + "pxe", + "fdimage", + "comboot", + "com32", + "config", + NULL +}; + +static inline int my_isspace(char c) +{ + return (unsigned char)c <= ' '; +} void execute(const char *cmdline, enum kernel_type type) { @@ -72,7 +93,9 @@ void execute(const char *cmdline, enum kernel_type type) new_linux_kernel(kernel, cmdline); } else if (type == KT_CONFIG) { /* kernel contains the config file name */ - start_ui(kernel); + spawn_load_param[0] = args; + module_load_dependencies("ui.c32", "modules.dep"); + spawn_load(kernel, spawn_load_param); } else { /* process the image need int 22 support */ if (type == KT_LOCALBOOT) { diff --git a/core/elflink/get_key.c b/core/elflink/get_key.c deleted file mode 100644 index b2f7092..0000000 --- a/core/elflink/get_key.c +++ /dev/null @@ -1,175 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2004-2008 H. Peter Anvin - All Rights Reserved - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall - * be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * ----------------------------------------------------------------------- */ - -/* - * get_key.c - * - * Get a single key, and try to pick apart function key codes. - * This doesn't decode anywhere close to all possiblities, but - * hopefully is enough to be useful. - */ - -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <unistd.h> -#include <time.h> -#include <core.h> - -#include <sys/times.h> -#include <sys/module.h> - -#include "getkey.h" - -struct keycode { - int code; - int seqlen; - const unsigned char *seq; -}; - -#define MAXLEN 8 -#define CODE(x,y) { x, (sizeof y)-1, y } - -static const struct keycode keycodes[] = { - /* First, the BIOS combined codes */ - CODE(KEY_F1, "\0\x3B"), - CODE(KEY_F2, "\0\x3C"), - CODE(KEY_F3, "\0\x3D"), - CODE(KEY_F4, "\0\x3E"), - CODE(KEY_F5, "\0\x3F"), - CODE(KEY_F6, "\0\x40"), - CODE(KEY_F7, "\0\x41"), - CODE(KEY_F8, "\0\x42"), - CODE(KEY_F9, "\0\x43"), - CODE(KEY_F10, "\0\x44"), - CODE(KEY_F11, "\0\x85"), - CODE(KEY_F12, "\0\x86"), - - CODE(KEY_UP, "\0\x48"), - CODE(KEY_DOWN, "\0\x50"), - CODE(KEY_LEFT, "\0\x4B"), - CODE(KEY_RIGHT, "\0\x4D"), - CODE(KEY_PGUP, "\0\x49"), - CODE(KEY_PGDN, "\0\x51"), - CODE(KEY_HOME, "\0\x47"), - CODE(KEY_END, "\0\x4F"), - CODE(KEY_INSERT, "\0\x52"), - CODE(KEY_DELETE, "\0\x53"), - - /* Now, VT/xterm/Linux codes */ - CODE(KEY_F1, "\033[[A"), - CODE(KEY_F1, "\033OP"), - CODE(KEY_F2, "\033[[B"), - CODE(KEY_F2, "\033OQ"), - CODE(KEY_F3, "\033[[C"), - CODE(KEY_F3, "\033OR"), - CODE(KEY_F4, "\033[[D"), - CODE(KEY_F4, "\033OS"), - CODE(KEY_F5, "\033[[E"), - CODE(KEY_F5, "\033[15~"), - CODE(KEY_F6, "\033[17~"), - CODE(KEY_F7, "\033[18~"), - CODE(KEY_F8, "\033[19~"), - CODE(KEY_F9, "\033[20~"), - CODE(KEY_F10, "\033[21~"), - CODE(KEY_F11, "\033[23~"), - CODE(KEY_F12, "\033[24~"), - - CODE(KEY_UP, "\033[A"), - CODE(KEY_DOWN, "\033[B"), - CODE(KEY_LEFT, "\033[D"), - CODE(KEY_RIGHT, "\033[C"), - CODE(KEY_PGUP, "\033[5~"), - CODE(KEY_PGUP, "\033[V"), - CODE(KEY_PGDN, "\033[6~"), - CODE(KEY_PGDN, "\033[U"), - CODE(KEY_HOME, "\033[1~"), - CODE(KEY_HOME, "\033[H"), - CODE(KEY_END, "\033[4~"), - CODE(KEY_END, "\033[F"), - CODE(KEY_END, "\033OF"), - CODE(KEY_INSERT, "\033[2~"), - CODE(KEY_INSERT, "\033[@"), - CODE(KEY_DELETE, "\033[3~"), -}; - -#define NCODES ((int)(sizeof keycodes/sizeof(struct keycode))) - -#define KEY_TIMEOUT ((CLK_TCK+9)/10) - -int get_key(FILE * f, clock_t timeout) -{ - unsigned char buffer[MAXLEN]; - int nc, i, rv; - const struct keycode *kc; - int another; - unsigned char ch; - clock_t start; - - /* We typically start in the middle of a clock tick */ - if (timeout) - timeout++; - - nc = 0; - start = jiffies(); - do { - rv = read(fileno(f), &ch, 1); - if (rv == 0 || (rv == -1 && errno == EAGAIN)) { - clock_t lateness = jiffies() - start; - if (nc && lateness > 1 + KEY_TIMEOUT) { - if (nc == 1) - return buffer[0]; /* timeout in sequence */ - else if (timeout && lateness > timeout) - return KEY_NONE; - } else if (!nc && timeout && lateness > timeout) - return KEY_NONE; /* timeout before sequence */ - - syslinux_idle(); - - another = 1; - continue; - } - - start = jiffies(); - - buffer[nc++] = ch; - - another = 0; - for (i = 0, kc = keycodes; i < NCODES; i++, kc++) { - if (nc == kc->seqlen && !memcmp(buffer, kc->seq, nc)) - return kc->code; - else if (nc < kc->seqlen && !memcmp(buffer, kc->seq, nc)) { - another = 1; - break; - } - } - } while (another); - - /* We got an unrecognized sequence; return the first character */ - /* We really should remember this and return subsequent characters later */ - return buffer[0]; -} diff --git a/core/elflink/getkey.h b/core/elflink/getkey.h deleted file mode 100644 index 52312a2..0000000 --- a/core/elflink/getkey.h +++ /dev/null @@ -1,80 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2004-2008 H. Peter Anvin - All Rights Reserved - * - * Permission is hereby granted, free of charge, to any person - * obtaining a copy of this software and associated documentation - * files (the "Software"), to deal in the Software without - * restriction, including without limitation the rights to use, - * copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom - * the Software is furnished to do so, subject to the following - * conditions: - * - * The above copyright notice and this permission notice shall - * be included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - * - * ----------------------------------------------------------------------- */ - -/* - * getkey.h - * - * Function to get a key symbol and parse it - */ - -#ifndef LIBUTIL_GETKEY_H -#define LIBUTIL_GETKEY_H - -#include <stdio.h> -#include <unistd.h> -#include <sys/times.h> - -#ifndef CLK_TCK -# define CLK_TCK sysconf(_SC_CLK_TCK) -#endif - -#define KEY_NONE (-1) - -#define KEY_CTRL(x) ((x) & 0x001f) -#define KEY_BACKSPACE 0x0008 -#define KEY_TAB 0x0009 -#define KEY_ENTER 0x000d -#define KEY_ESC 0x001b -#define KEY_DEL 0x007f - -#define KEY_F1 0x0100 -#define KEY_F2 0x0101 -#define KEY_F3 0x0102 -#define KEY_F4 0x0103 -#define KEY_F5 0x0104 -#define KEY_F6 0x0105 -#define KEY_F7 0x0106 -#define KEY_F8 0x0107 -#define KEY_F9 0x0108 -#define KEY_F10 0x0109 -#define KEY_F11 0x010A -#define KEY_F12 0x010B - -#define KEY_UP 0x0120 -#define KEY_DOWN 0x0121 -#define KEY_LEFT 0x0122 -#define KEY_RIGHT 0x0123 -#define KEY_PGUP 0x0124 -#define KEY_PGDN 0x0125 -#define KEY_HOME 0x0126 -#define KEY_END 0x0127 -#define KEY_INSERT 0x0128 -#define KEY_DELETE 0x0129 - -int get_key(FILE *, clock_t); - -#endif /* LIBUTIL_GETKEY_H */ diff --git a/core/elflink/kernel.c b/core/elflink/kernel.c index 2e63df6..d191e6e 100644 --- a/core/elflink/kernel.c +++ b/core/elflink/kernel.c @@ -9,6 +9,9 @@ #include "core.h" #include "core-elf.h" +char *globaldefault = NULL; +char *append = NULL; + /* Will be called from readconfig.c */ int new_linux_kernel(char *okernel, char *ocmdline) { diff --git a/core/elflink/load_env32.c b/core/elflink/load_env32.c index e4e4d62..501f267 100644 --- a/core/elflink/load_env32.c +++ b/core/elflink/load_env32.c @@ -16,7 +16,6 @@ #include <sys/module.h> #include "common.h" #include "menu.h" -#include "cli.h" #include "core-elf.h" typedef void (*constructor_t) (void); @@ -66,59 +65,13 @@ static void call_constr(void) (*p) (); } -void enter_cmdline(void) -{ - struct cli_command *comm, *aux; - char *cmdline; - - /* Enter endless command line prompt, should support "exit" */ - while (1) { - cmdline = edit_cmdline("", 1, NULL, NULL); - /* feng: give up the aux check here */ - //aux = list_entry(cli_history_head.next, typeof(*aux), list); - //if (strcmp(aux->command, cmdline)) { - comm = (struct cli_command *)malloc(sizeof(struct cli_command *)); - comm->command - (char *)malloc(sizeof(char) * (strlen(cmdline) + 1)); - strcpy(comm->command, cmdline); - list_add(&(comm->list), &cli_history_head); - process_command(cmdline); - //} - } -} - -/* parameter is the config file name if any */ -void start_ui(char *config_file) -{ - char *cmdline; - char *argv[2] = {config_file, NULL}; - - mp("enter, config file = %s", config_file); - - parse_configs(argv); - - /* run the default menu if found */ - if (default_menu) { - cmdline = default_menu->menu_entries[default_menu->defentry]->cmdline; - if (*cmdline == '.') { - while (*cmdline++ != ' '); - } - process_command(cmdline); - } - - /* Should never return */ - enter_cmdline(); -} - /* note to self: do _*NOT*_ use static key word on this function */ void load_env32(com32sys_t * regs) { dprintf("Starting 32 bit elf module subsystem...\n"); call_constr(); - openconsole(&dev_rawcon_r, &dev_ansiserial_w); - INIT_LIST_HEAD(&cli_history_head); init_module_subsystem(&core_module); - start_ui(NULL); + execute("ldlinux.c32", KT_COM32); } diff --git a/core/elflink/menu.h b/core/elflink/menu.h deleted file mode 100644 index 3bdf2d4..0000000 --- a/core/elflink/menu.h +++ /dev/null @@ -1,229 +0,0 @@ -/* ----------------------------------------------------------------------- * - * - * Copyright 2004-2008 H. Peter Anvin - All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston MA 02110-1301, USA; either version 2 of the License, or - * (at your option) any later version; incorporated herein by reference. - * - * ----------------------------------------------------------------------- */ - -/* - * menu.h - * - * Header file for the simple menu system - */ - -#ifndef MENU_H -#define MENU_H - -#include <time.h> -#include <sys/time.h> -#include <sys/times.h> -#include <inttypes.h> -#include <unistd.h> -#include <colortbl.h> -#include <stdbool.h> -#include <setjmp.h> -#include "refstr.h" - -#ifndef CLK_TCK -# define CLK_TCK sysconf(_SC_CLK_TCK) -#endif - -struct menu; - -/* Note: the _UNRES variants must always be immediately after their - "normal" versions. */ -enum menu_action { - MA_NONE, /* Undefined value */ - MA_CMD, /* Execute a command */ - MA_DISABLED, /* Disabled menu entry */ - MA_SUBMENU, /* This is a submenu entry */ - MA_GOTO, /* Go to another menu */ - MA_GOTO_UNRES, /* Unresolved go to */ - MA_QUIT, /* Quit to CLI */ - MA_EXIT, /* Exit to higher-level menu */ - MA_EXIT_UNRES, /* Unresolved exit */ -}; - -struct menu_entry { - struct menu *menu; /* Parent menu */ - const char *displayname; - const char *label; - const char *passwd; - char *helptext; - const char *cmdline; - struct menu *submenu; - struct menu_entry *next; /* Linked list of all labels across menus */ - int entry; /* Entry number inside menu */ - enum menu_action action; - unsigned char hotkey; - bool save; /* Save this entry if selected */ -}; - -static inline bool is_disabled(struct menu_entry *me) -{ - return me->action == MA_DISABLED; -} - -enum kernel_type { - /* Meta-types for internal use */ - KT_NONE, - KT_LOCALBOOT, - - /* The ones we can pass off to SYSLINUX, in order */ - KT_KERNEL, /* Undefined type */ - KT_LINUX, /* Linux kernel */ - KT_BOOT, /* Bootstrap program */ - KT_BSS, /* Boot sector with patch */ - KT_PXE, /* PXE NBP */ - KT_FDIMAGE, /* Floppy disk image */ - KT_COMBOOT, /* COMBOOT image */ - KT_COM32, /* COM32 image */ - KT_CONFIG, /* Configuration file */ -}; - -extern const char *const kernel_types[]; - -/* Configurable integer parameters */ -enum parameter_number { - P_WIDTH, - P_MARGIN, - P_PASSWD_MARGIN, - P_MENU_ROWS, - P_TABMSG_ROW, - P_CMDLINE_ROW, - P_END_ROW, - P_PASSWD_ROW, - P_TIMEOUT_ROW, - P_HELPMSG_ROW, - P_HELPMSGEND_ROW, - P_HSHIFT, - P_VSHIFT, - P_HIDDEN_ROW, - - NPARAMS -}; - -/* Configurable messages */ -enum message_number { - MSG_TITLE, - MSG_AUTOBOOT, - MSG_TAB, - MSG_NOTAB, - MSG_PASSPROMPT, - - MSG_COUNT -}; - -struct messages { - const char *name; /* Message configuration name */ - const char *defmsg; /* Default message text */ -}; - -struct menu_parameter { - const char *name; - int value; -}; - -extern const struct menu_parameter mparm[NPARAMS]; - -struct fkey_help { - const char *textname; - const char *background; -}; - -struct menu { - struct menu *next; /* Linked list of all menus */ - const char *label; /* Goto label for this menu */ - struct menu *parent; - struct menu_entry *parent_entry; /* Entry for self in parent */ - - struct menu_entry **menu_entries; - struct menu_entry *menu_hotkeys[256]; - - const char *messages[MSG_COUNT]; - int mparm[NPARAMS]; - - int nentries; - int nentries_space; - int defentry; - int timeout; - - bool allowedit; - bool save; /* MENU SAVE default for this menu */ - - int curentry; - int curtop; - - const char *title; - const char *ontimeout; - const char *onerror; - const char *menu_master_passwd; - const char *menu_background; - - struct color_table *color_table; - - struct fkey_help fkeyhelp[12]; -}; - -extern struct menu *root_menu, *start_menu, *hide_menu, *menu_list; - -/* 2048 is the current definition inside syslinux */ -#define MAX_CMDLINE_LEN 2048 - -/* These are global parameters regardless of which menu we're displaying */ -extern int shiftkey; -extern int hiddenmenu; -extern long long totaltimeout; -jmp_buf timeout_jump; - -void parse_configs(char **argv); -extern int draw_background(const char *filename); - -static inline int my_isspace(char c) -{ - return (unsigned char)c <= ' '; -} - -int my_isxdigit(char c); -unsigned int hexval(char c); -unsigned int hexval2(const char *p); -uint32_t parse_argb(char **p); - -int menu_main(int argc, char *argv[]); -void console_prepare(void); -void console_cleanup(void); - -extern const int message_base_color, menu_color_table_size; -int mygetkey(clock_t timeout); -int show_message_file(const char *filename, const char *background); - -/* passwd.c */ -int passwd_compare(const char *passwd, const char *entry); - -/* colors.c */ -#define MSG_COLORS_DEF_FG 0x90ffffff -#define MSG_COLORS_DEF_BG 0x80ffffff -#define MSG_COLORS_DEF_SHADOW SHADOW_NORMAL -void set_msg_colors_global(struct color_table *tbl, - unsigned int fg, unsigned int bg, - enum color_table_shadow shadow); -struct color_table *default_color_table(void); -struct color_table *copy_color_table(const struct color_table *master); -extern const int message_base_color; - -/* background.c */ -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); - -#endif /* MENU_H */ diff --git a/core/extern.inc b/core/extern.inc index b1dad18..90599f2 100644 --- a/core/extern.inc +++ b/core/extern.inc @@ -16,7 +16,7 @@ extern abort_load_new ; elflink/load_env32.c - extern load_env32, enter_cmdline + extern load_env32 ; memscan.c extern highmem_init diff --git a/core/ui.inc b/core/ui.inc index 4022413..84bafee 100644 --- a/core/ui.inc +++ b/core/ui.inc @@ -23,7 +23,6 @@ load_kernel: kernel_good_saved: kernel_corrupt: pm_call hello - pm_call enter_cmdline ; Never return %else ; comment off the original ui.inc load_config_file: diff --git a/elf_gen_dep.sh b/elf_gen_dep.sh index 404ebbe..dba990d 100755 --- a/elf_gen_dep.sh +++ b/elf_gen_dep.sh @@ -4,7 +4,7 @@ # Round 1: get all the loacl and external symbols ####################################################### -for i in com32/elflink/modules/*.c32 core/isolinux.elf core/pxelinux.elf +for i in com32/elflink/modules/*.c32 core/isolinux.elf core/pxelinux.elf com32/elflink/ldlinux/*.c32 do # module=$(echo $i | sed "s/^\(.*\).o$/\1/") -- 1.7.4
Matt Fleming
2011-Mar-09 16:00 UTC
[syslinux] [PATCH 06/12] elflink: Look for syslinux.cfg
From: Matt Fleming <matt.fleming at linux.intel.com> Add syslinux.cfg to the list of configuration file names to check for when the config parser searches for configuration files. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/ldlinux/readconfig.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c index 9857233..18c1183 100644 --- a/com32/elflink/ldlinux/readconfig.c +++ b/com32/elflink/ldlinux/readconfig.c @@ -1049,6 +1049,10 @@ static int parse_one_config(const char *filename) if (f) goto config_found; + f = fopen("syslinux.cfg", "r"); + if (f) + goto config_found; + return -1; config_found: parse_config_file(f); -- 1.7.4
Matt Fleming
2011-Mar-09 16:00 UTC
[syslinux] [PATCH 07/12] elflink: Move config data into config.h
From: Matt Fleming <matt.fleming at linux.intel.com> Move some definitions that other compilation units need to know about into config.h. In subsequent patches ldlinux.c will use the global options set by readconfig.c to decide which kernel to boot. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/ldlinux/config.h | 29 +++++++++++++++++++++++++++++ com32/elflink/ldlinux/ldlinux.c | 4 ++++ com32/elflink/ldlinux/readconfig.c | 17 +++++++++-------- 3 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 com32/elflink/ldlinux/config.h diff --git a/com32/elflink/ldlinux/config.h b/com32/elflink/ldlinux/config.h new file mode 100644 index 0000000..3125b27 --- /dev/null +++ b/com32/elflink/ldlinux/config.h @@ -0,0 +1,29 @@ +/* + * Copyright 2011 Intel Corporation - All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, + * Boston MA 02110-1301, USA; either version 2 of the License, or + * (at your option) any later version; incorporated herein by reference. + * + */ + +#ifndef __CONFIG_H__ +#define __CONFIG_H__ + +extern short uappendlen; //bytes in append= command +extern short ontimeoutlen; //bytes in ontimeout command +extern short onerrorlen; //bytes in onerror command +extern short forceprompt; //force prompt +extern short noescape; //no escape +extern short nocomplete; //no label completion on TAB key +extern short allowimplicit; //allow implicit kernels +extern short allowoptions; //user-specified options allowed +extern short includelevel; //nesting level +extern short defaultlevel; //the current level of default +extern short vkernel; //have we seen any "label" statements? +extern short displaycon; //conio.inc +extern short nohalt; //idle.inc + +#endif /* __CONFIG_H__ */ diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c index 967eebb..b348490 100644 --- a/com32/elflink/ldlinux/ldlinux.c +++ b/com32/elflink/ldlinux/ldlinux.c @@ -1,8 +1,12 @@ #include <linux/list.h> #include <sys/times.h> #include <stdbool.h> +#include <core-elf.h> #include "cli.h" #include "console.h" +#include "com32.h" +#include "menu.h" +#include "config.h" #include <sys/module.h> diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c index 18c1183..1fb9156 100644 --- a/com32/elflink/ldlinux/readconfig.c +++ b/com32/elflink/ldlinux/readconfig.c @@ -25,6 +25,7 @@ #include <core-elf.h> #include "menu.h" +#include "config.h" const struct menu_parameter mparm[NPARAMS] = { [P_WIDTH] = {"width", 0}, @@ -43,17 +44,17 @@ const struct menu_parameter mparm[NPARAMS] = { [P_HIDDEN_ROW] = {"hiddenrow", -2}, }; -short uappendlen; //bytes in append= command -short ontimeoutlen; //bytes in ontimeout command -short onerrorlen; //bytes in onerror command -short forceprompt; //force prompt -short noescape; //no escape -short nocomplete; //no label completion on TAB key +short uappendlen = 0; //bytes in append= command +short ontimeoutlen = 0; //bytes in ontimeout command +short onerrorlen = 0; //bytes in onerror command +short forceprompt = 0; //force prompt +short noescape = 0; //no escape +short nocomplete = 0; //no label completion on TAB key short allowimplicit = 1; //allow implicit kernels short allowoptions = 1; //user-specified options allowed short includelevel = 1; //nesting level -short defaultlevel; //the current level of default -short vkernel; //have we seen any "label" statements? +short defaultlevel = 0; //the current level of default +short vkernel = 0; //have we seen any "label" statements? short displaycon = 1; //conio.inc short nohalt = 1; //idle.inc -- 1.7.4
Matt Fleming
2011-Mar-09 16:00 UTC
[syslinux] [PATCH 08/12] elflink: Don't reload the current EXEC_MODULE module
From: Matt Fleming <matt.fleming at linux.intel.com> As the ldlinux.c32 ELF module is an executable (EXEC_MODULE) and not a library (LIB_MODULE), we need to make sure we don't reload it when another executable wants to resolve a symbol exported by ldlinux. Whenever an EXEC_MODULE module is loaded its MODULE_MAIN function is executed. In the case of ldlinux, the MODULE_MAIN function drops the user at a command line. So, what currently happens is that if we load an executable module, say menu.c32, which needs symbols exported by ldlinux and ldlinux is already loaded and running, we'll reload ldlinux when resolving undefined symbols from menu.c32 and end up dropping the user at a command prompt and _not_ resolve the symbols and return control to menu.c32's MODULE_MAIN function. ldlinux.c32 effectively steals control of the proces. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/lib/sys/module/exec.c | 18 +++++++++++++++--- 1 files changed, 15 insertions(+), 3 deletions(-) diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c index 0e7aa3f..03d11cb 100644 --- a/com32/lib/sys/module/exec.c +++ b/com32/lib/sys/module/exec.c @@ -237,11 +237,23 @@ int spawn_load(const char *name,const char **argv) if (module == NULL) return -1; - /* ugly hack to reload the same module */ if (!strcmp(cur_module->name, module->name)) { mp("We is running this module %s already!", module->name); - module_unload(cur_module); - cur_module = NULL; + + /* + * If we're already running the module and it's of + * type EXEC_MODULE, then just return. We don't reload + * the module because that might cause us to re-run + * the init functions, which will cause us to run the + * MODULE_MAIN function, which will take control of + * this process. + * + * This can happen if some other EXEC_MODULE is + * resolving a symbol that is exported by the current + * EXEC_MODULE. + */ + if (get_module_type(module) == EXEC_MODULE) + return 0; } res = module_load(module); -- 1.7.4
From: Matt Fleming <matt.fleming at linux.intel.com> There's only one function required for printing debugging information and that is dprintf() - there is no need to invent another. dprintf() is also superior to mp() because it can be enabled/disabled on a per-file basis via the DEBUG symbol. Switch all users of mp() to dprintf() and leave them disabled (don't define the DEBUG) so we have a less verbose boot by default. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/ldlinux/cli.c | 13 +++++++------ com32/elflink/ldlinux/readconfig.c | 19 ++++++++++--------- com32/elflink/modules/menumain.c | 5 +++-- com32/elflink/modules/test.c | 7 ++++--- com32/include/sys/module.h | 2 +- com32/lib/sys/module/elf_module.c | 3 ++- com32/lib/sys/module/exec.c | 13 +++++++------ core/elflink/execute.c | 3 ++- core/elflink/kernel.c | 5 +++-- core/mem/init.c | 9 +++++---- 10 files changed, 44 insertions(+), 35 deletions(-) diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c index 551113f..77d32cd 100644 --- a/com32/elflink/ldlinux/cli.c +++ b/com32/elflink/ldlinux/cli.c @@ -13,6 +13,7 @@ #include <sys/exec.h> #include <sys/module.h> #include <core-elf.h> +#include <dprintf.h> #include "getkey.h" #include "menu.h" @@ -24,7 +25,7 @@ static struct list_head cli_history_head; void clear_screen(void) { - //mp("enter"); + //dprintf("enter"); fputs("\033e\033%@\033)0\033(B\1#0\033[?25l\033[2J", stdout); } @@ -34,7 +35,7 @@ int mygetkey(clock_t timeout) clock_t tto, to; int key; - //mp("enter"); + //dprintf("enter"); if (!totaltimeout) return get_key(stdin, timeout); @@ -52,13 +53,13 @@ int mygetkey(clock_t timeout) totaltimeout -= t; if (key != KEY_NONE) { - //mp("get key 0x%x", key); + //dprintf("get key 0x%x", key); return key; } if (timeout) { if (timeout <= t) { - //mp("timeout"); + //dprintf("timeout"); return KEY_NONE; } @@ -375,7 +376,7 @@ void process_command(const char *cmd, bool history) list_add(&(comm->list), &cli_history_head); } - // mp("raw cmd = %s", cmd); + // dprintf("raw cmd = %s", cmd); strcpy(temp_cmd, cmd); module_name = strtok(cmd, COMMAND_DELIM); len_mn = strlen(module_name); @@ -383,7 +384,7 @@ void process_command(const char *cmd, bool history) if (!strcmp(module_name + len_mn - 4, ".c32")) { if (module_find(module_name) != NULL) { /* make module re-enterable */ - // mp("Module %s is already running"); + // dprintf("Module %s is already running"); } do { argv[0] = module_name; diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c index 1fb9156..f365b6f 100644 --- a/com32/elflink/ldlinux/readconfig.c +++ b/com32/elflink/ldlinux/readconfig.c @@ -23,6 +23,7 @@ #include <syslinux/adv.h> #include <syslinux/config.h> #include <core-elf.h> +#include <dprintf.h> #include "menu.h" #include "config.h" @@ -171,7 +172,7 @@ static struct menu *new_menu(struct menu *parent, struct menu *m = calloc(1, sizeof(struct menu)); int i; - //mp("enter: menu_label = %s", label); + //dprintf("enter: menu_label = %s", label); m->label = label; m->title = refstr_get(empty_string); @@ -260,7 +261,7 @@ static struct menu_entry *new_entry(struct menu *m) { struct menu_entry *me; - //mp("enter, call from menu %s", m->label); + //dprintf("enter, call from menu %s", m->label); if (m->nentries >= m->nentries_space) { if (!m->nentries_space) @@ -377,7 +378,7 @@ static void record(struct menu *m, struct labeldata *ld, const char *append) else rsprintf(&me->cmdline, ".%s %s%s%s%s", kernel_types[ld->type], ld->kernel, s, a, ipoptions); - mp("type = %s, cmd = %s", kernel_types[ld->type], me->cmdline); + dprintf("type = %s, cmd = %s", kernel_types[ld->type], me->cmdline); break; case MA_GOTO_UNRES: @@ -931,7 +932,7 @@ do_include: refstr_put(append); append = a; } - //mp("we got a append: %s", a); + //dprintf("we got a append: %s", a); } else if (looking_at(p, "initrd")) { const char *a = refstrdup(skipspace(p + 6)); if (ld.label) { @@ -961,7 +962,7 @@ do_include: refstr_put(ld.kernel); ld.kernel = refstrdup(skipspace(ep)); ld.type = type; - //mp("got a kernel: %s, type = %d", ld.kernel, ld.type); + //dprintf("got a kernel: %s, type = %d", ld.kernel, ld.type); } } else if (looking_at(p, "timeout")) { m->timeout = (atoi(skipspace(p + 7)) * CLK_TCK + 9) / 10; @@ -1083,7 +1084,7 @@ static void resolve_gotos(void) static void dump_menu(struct menu *menu) { - mp("will dump menu for %s:", menu->label); + dprintf("will dump menu for %s:", menu->label); printf("entries num: %d\n", menu->nentries); printf("defentry: %d, nam = %s\n", menu->defentry, menu->menu_entries[menu->defentry]->label); @@ -1099,7 +1100,7 @@ void parse_configs(char **argv) struct menu *m; struct menu_entry *me; char *cmdline; - mp("enter"); + dprintf("enter"); empty_string = refstrdup(""); @@ -1122,7 +1123,7 @@ void parse_configs(char **argv) parse_one_config("~"); } else { while ((filename = *argv++)) { - mp("Parsing config: %s", filename); + dprintf("Parsing config: %s", filename); parse_one_config(filename); } } @@ -1136,7 +1137,7 @@ void parse_configs(char **argv) /* Handle global default */ //if (has_ui && globaldefault) { if (globaldefault) { - mp("gloabldefault = %s", globaldefault); + dprintf("gloabldefault = %s", globaldefault); me = find_label(globaldefault); if (me && me->menu != hide_menu) { me->menu->defentry = me->entry; diff --git a/com32/elflink/modules/menumain.c b/com32/elflink/modules/menumain.c index 265f4c4..4d00dc3 100644 --- a/com32/elflink/modules/menumain.c +++ b/com32/elflink/modules/menumain.c @@ -31,6 +31,7 @@ #include <syslinux/adv.h> #include <sys/module.h> #include <core-elf.h> +#include <dprintf.h> #include "menu.h" #include "cli.h" @@ -899,7 +900,7 @@ static const char *run_menu(void) static void dump_menu(struct menu *menu) { - mp("will dump menu for %s:", menu->label); + dprintf("will dump menu for %s:", menu->label); printf("entries num: %d\n", menu->nentries); printf("defentry: %d, nam = %s\n", menu->defentry, menu->menu_entries[menu->defentry]->label); @@ -956,7 +957,7 @@ int menu_main(int argc, char *argv[]) printf("\033[?25h\033[%d;1H\033[0m", END_ROW); if (cmdline) { - mp("cmdline = %s", cmdline); + dprintf("cmdline = %s", cmdline); execute(cmdline, KT_NONE); if (cm->onerror) execute(cm->onerror, KT_NONE); diff --git a/com32/elflink/modules/test.c b/com32/elflink/modules/test.c index 82df642..dd9e520 100644 --- a/com32/elflink/modules/test.c +++ b/com32/elflink/modules/test.c @@ -46,6 +46,7 @@ #include <syslinux/loadfile.h> #include <syslinux/linux.h> #include <sys/module.h> +#include <dprintf.h> //const char *progname = "test.c32"; @@ -94,11 +95,11 @@ static int test_main(int argc, char *argv[]) if (initramfs_load_archive(initramfs, "initrd.gz")) - mp("initrd load failure\n"); + dprintf("initrd load failure\n"); else - mp("initrd load success\n"); + dprintf("initrd load success\n"); - mp("1111"); + dprintf("1111"); /* This should not return... */ syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline); diff --git a/com32/include/sys/module.h b/com32/include/sys/module.h index 0c7c71f..dbeab4a 100644 --- a/com32/include/sys/module.h +++ b/com32/include/sys/module.h @@ -135,7 +135,7 @@ struct elf_module { static inline void dump_elf_module(struct elf_module *module) { /* - mp("module name = %s", module->name); + dprintf("module name = %s", module->name); printf("base_addr = 0x%p, module_size = %d\n", module->base_addr, module->module_size); printf("hash tlb = 0x%p, ghash tbl = 0x%p\n", module->hash_table, module->ghash_table); printf("str tbl = 0x%p, size = %d\n", module->str_table, module->strtable_size); diff --git a/com32/lib/sys/module/elf_module.c b/com32/lib/sys/module/elf_module.c index d04230e..4bc5d94 100644 --- a/com32/lib/sys/module/elf_module.c +++ b/com32/lib/sys/module/elf_module.c @@ -10,6 +10,7 @@ #include <string.h> #include <stdio.h> #include <elf.h> +#include <dprintf.h> #include <linux/list.h> #include <sys/module.h> @@ -480,7 +481,7 @@ int module_load(struct elf_module *module) { // Perform the relocations resolve_symbols(module); - //mp("module->symtable_size = %d\n", module->symtable_size); + //dprintf("module->symtable_size = %d\n", module->symtable_size); //print_elf_symbols(module); diff --git a/com32/lib/sys/module/exec.c b/com32/lib/sys/module/exec.c index 03d11cb..54182cc 100644 --- a/com32/lib/sys/module/exec.c +++ b/com32/lib/sys/module/exec.c @@ -14,8 +14,9 @@ #include <setjmp.h> #include <setjmp.h> #include <alloca.h> +#include <dprintf.h> -#define DBG_PRINT(fmt, args...) fprintf(stderr, "[EXEC] " fmt, ##args) +#define DBG_PRINT(fmt, args...) dprintf("[EXEC] " fmt, ##args) static struct elf_module *mod_root = NULL; struct elf_module *__syslinux_current = NULL; @@ -232,13 +233,13 @@ int spawn_load(const char *name,const char **argv) int type; - mp("enter: name = %s", name); + dprintf("enter: name = %s", name); if (module == NULL) return -1; if (!strcmp(cur_module->name, module->name)) { - mp("We is running this module %s already!", module->name); + dprintf("We is running this module %s already!", module->name); /* * If we're already running the module and it's of @@ -266,7 +267,7 @@ int spawn_load(const char *name,const char **argv) prev_module = cur_module; cur_module = module; - mp("type = %d, prev = %s, cur = %s", + dprintf("type = %d, prev = %s, cur = %s", type, prev_module->name, cur_module->name); if(type==LIB_MODULE) @@ -383,7 +384,7 @@ int module_load_dependencies(const char *name,const char *dep_file) while (line[i] != '\n') aux[j++] = line[i++]; aux[j] = '\0'; - //mp("found dependency: temp_name = %s, aux = %s, name = %s", temp_name, aux, name); + //dprintf("found dependency: temp_name = %s, aux = %s, name = %s", temp_name, aux, name); break; } } @@ -394,7 +395,7 @@ int module_load_dependencies(const char *name,const char *dep_file) i = 0; while (aux[i]) { sscanf(aux + i, "%s", temp_name); - //mp("load module: %s", temp_name); + //dprintf("load module: %s", temp_name); i += strlen(temp_name); i++; /* skip a space */ diff --git a/core/elflink/execute.c b/core/elflink/execute.c index 6410c7d..79dbc55 100644 --- a/core/elflink/execute.c +++ b/core/elflink/execute.c @@ -13,6 +13,7 @@ #include <stdlib.h> #include <string.h> #include <stdio.h> +#include <dprintf.h> #include <com32.h> #include "core-elf.h" @@ -71,7 +72,7 @@ void execute(const char *cmdline, enum kernel_type type) strcpy(q, p); - mp("kernel is %s, args = %s type = %d \n", kernel, args, type); + dprintf("kernel is %s, args = %s type = %d \n", kernel, args, type); if (kernel[0] == '.' && type == KT_NONE) { /* It might be a type specifier */ diff --git a/core/elflink/kernel.c b/core/elflink/kernel.c index d191e6e..6cb3363 100644 --- a/core/elflink/kernel.c +++ b/core/elflink/kernel.c @@ -3,6 +3,7 @@ #include <stdio.h> #include <string.h> #include <console.h> +#include <dprintf.h> #include <syslinux/loadfile.h> #include <syslinux/linux.h> #include <syslinux/pxe.h> @@ -25,7 +26,7 @@ int new_linux_kernel(char *okernel, char *ocmdline) char cmdline_buf[256], *cmdline; int i; - mp("okernel = %s, ocmdline = %s", okernel, ocmdline); + dprintf("okernel = %s, ocmdline = %s", okernel, ocmdline); cmdline = cmdline_buf; @@ -116,7 +117,7 @@ int new_linux_kernel(char *okernel, char *ocmdline) initramfs_load_archive(initramfs, initrd_name); } - //mp("loading initrd done"); + //dprintf("loading initrd done"); /* This should not return... */ syslinux_boot_linux(kernel_data, kernel_len, initramfs, cmdline); diff --git a/core/mem/init.c b/core/mem/init.c index bfc6430..4ee2541 100644 --- a/core/mem/init.c +++ b/core/mem/init.c @@ -1,6 +1,7 @@ #include <stdlib.h> #include <errno.h> #include <string.h> +#include <dprintf.h> #include "malloc.h" #include <stdio.h> @@ -18,7 +19,7 @@ int scan_highmem_area(void *data, addr_t start, addr_t len, bool is_ram) struct free_arena_header *fp; addr_t end; - mp("start = %x, len = %x, is_ram = %d", start, len, is_ram); + dprintf("start = %x, len = %x, is_ram = %d", start, len, is_ram); if (start < 0x100000 || start > E820_MEM_MAX || !is_ram) @@ -36,7 +37,7 @@ int scan_highmem_area(void *data, addr_t start, addr_t len, bool is_ram) fp = (struct free_arena_header *)start; fp->a.attrs = ARENA_TYPE_USED | (HEAP_MAIN << ARENA_HEAP_POS); ARENA_SIZE_SET(fp->a.attrs, len); - mp("will inject a block start:0x%x size 0x%x", start, len); + dprintf("will inject a block start:0x%x size 0x%x", start, len); __inject_free_block(fp); } @@ -70,7 +71,7 @@ void mem_init(void) int i; uint16_t *bios_free_mem = (uint16_t *)0x413; - //mp("enter"); + //dprintf("enter"); /* Initialize the head nodes */ fp = &__core_malloc_head[0]; @@ -81,7 +82,7 @@ void mem_init(void) fp++; } - //mp("__lowmem_heap = 0x%p bios_free = 0x%p", + //dprintf("__lowmem_heap = 0x%p bios_free = 0x%p", // __lowmem_heap, *bios_free_mem); /* Initialize the lowmem heap */ -- 1.7.4
Matt Fleming
2011-Mar-09 16:00 UTC
[syslinux] [PATCH 10/12] ldlinux: Record "default" and "ui" command lines
From: Matt Fleming <matt.fleming at linux.intel.com> The command line following the "default" and "ui" options may be a kernel or com32 module to load and execute, so we need to record it for later processing. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/ldlinux/config.h | 9 +++++++++ com32/elflink/ldlinux/readconfig.c | 22 +++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/com32/elflink/ldlinux/config.h b/com32/elflink/ldlinux/config.h index 3125b27..17c7b28 100644 --- a/com32/elflink/ldlinux/config.h +++ b/com32/elflink/ldlinux/config.h @@ -12,6 +12,13 @@ #ifndef __CONFIG_H__ #define __CONFIG_H__ +/* + * These values correspond to the "default" and "ui" commands + * respectively. "ui" takes precendence over "default". + */ +#define LEVEL_DEFAULT 1 +#define LEVEL_UI 2 + extern short uappendlen; //bytes in append= command extern short ontimeoutlen; //bytes in ontimeout command extern short onerrorlen; //bytes in onerror command @@ -26,4 +33,6 @@ extern short vkernel; //have we seen any "label" statements? extern short displaycon; //conio.inc extern short nohalt; //idle.inc +extern char *default_cmd; //"default" command line + #endif /* __CONFIG_H__ */ diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c index f365b6f..ed498ff 100644 --- a/com32/elflink/ldlinux/readconfig.c +++ b/com32/elflink/ldlinux/readconfig.c @@ -59,6 +59,7 @@ short vkernel = 0; //have we seen any "label" statements? short displaycon = 1; //conio.inc short nohalt = 1; //idle.inc +char *default_cmd = NULL; //"default" command line /* Empty refstring */ const char *empty_string; @@ -978,11 +979,26 @@ do_include: else ipappend = atoi(skipspace(p + 8)); } else if (looking_at(p, "default")) { - /* default could be a kernel image or another label */ - refstr_put(globaldefault); - globaldefault = refstrdup(skipspace(p + 7)); + /* default could be a kernel image or another label */ + refstr_put(globaldefault); + globaldefault = refstrdup(skipspace(p + 7)); + + /* + * On the chance that "default" is actually a kernel image + * and not a label, store a copy of it, but only if we + * haven't seen a "ui" command. "ui" commands take + * precendence over "default" commands. + */ + if (defaultlevel < LEVEL_UI) { + defaultlevel = LEVEL_DEFAULT; + refstr_put(default_cmd); + default_cmd = refstrdup(globaldefault); + } } else if (looking_at(p, "ui")) { has_ui = 1; + defaultlevel = LEVEL_UI; + refstr_put(default_cmd); + default_cmd = refstrdup(skipspace(p + 2)); } /* -- 1.7.4
Matt Fleming
2011-Mar-09 16:00 UTC
[syslinux] [PATCH 11/12] ldlinux: Parse configuration files
From: Matt Fleming <matt.fleming at linux.intel.com> Use the configuration file parser provided by ldlinux to search for and parse any configuration files. If a kernel or ui module is found in the configuration file, it is executed once parsing completes. Parsing and loading kernels is now entirely done in C! The parser also builds the data structures for later use by the menu system. Previously, after the asm config parser had parsed the config file and found a kernel image to boot (or dropped the user at a command prompt), the menu.c32 module had to open the config file and re-parse it. Now, we only need to parse the file once. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/ldlinux/ldlinux.c | 35 +++++++++++++++++++++++++++++++++++ core/isolinux.asm | 6 ------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c index b348490..b94010e 100644 --- a/com32/elflink/ldlinux/ldlinux.c +++ b/com32/elflink/ldlinux/ldlinux.c @@ -26,10 +26,45 @@ static void enter_cmdline(void) } } +static void load_kernel(void) +{ + enum kernel_type type; + + if (defaultlevel == LEVEL_UI) + type = KT_COM32; + else + type = KT_KERNEL; + + execute(default_cmd, type); +} + static int ldlinux_main(int argc, char **argv) { openconsole(&dev_rawcon_r, &dev_ansiserial_w); + parse_configs(NULL); + + /* TODO: ADV */ + /* TODO: Check KbdFlags? */ + + if (forceprompt) + goto cmdline; + + /* + * Auto boot + */ + if (defaultlevel || !noescape) { + if (defaultlevel) { + load_kernel(); /* Shouldn't return */ + } else { + printf("No DEFAULT or UI configuration directive found!\n"); + + if (noescape) + kaboom(); + } + } + +cmdline: /* Should never return */ enter_cmdline(); diff --git a/core/isolinux.asm b/core/isolinux.asm index ba1d156..8995ce8 100644 --- a/core/isolinux.asm +++ b/core/isolinux.asm @@ -1185,12 +1185,6 @@ ROOT_FS_OPS: section .text16 ; -; Locate the configuration file -; - ;pm_call pm_load_config - ;jz no_config_file - -; ; Now we have the config file open. Parse the config file and ; run the user interface. ; -- 1.7.4
Matt Fleming
2011-Mar-09 16:00 UTC
[syslinux] [PATCH 12/12] ldlinux: Parse and store the "onerror" command line
From: Matt Fleming <matt.fleming at linux.intel.com> If we fail to load a kernel and the parser found an "onerror" directive, execute the onerror command line. Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> --- com32/elflink/ldlinux/config.h | 1 + com32/elflink/ldlinux/ldlinux.c | 10 ++++++++++ com32/elflink/ldlinux/readconfig.c | 9 +++++++++ 3 files changed, 20 insertions(+), 0 deletions(-) diff --git a/com32/elflink/ldlinux/config.h b/com32/elflink/ldlinux/config.h index 17c7b28..7765266 100644 --- a/com32/elflink/ldlinux/config.h +++ b/com32/elflink/ldlinux/config.h @@ -34,5 +34,6 @@ extern short displaycon; //conio.inc extern short nohalt; //idle.inc extern char *default_cmd; //"default" command line +extern char *onerror; //"onerror" command line #endif /* __CONFIG_H__ */ diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c index b94010e..b5a4409 100644 --- a/com32/elflink/ldlinux/ldlinux.c +++ b/com32/elflink/ldlinux/ldlinux.c @@ -29,6 +29,7 @@ static void enter_cmdline(void) static void load_kernel(void) { enum kernel_type type; + const char *cmdline; if (defaultlevel == LEVEL_UI) type = KT_COM32; @@ -36,6 +37,15 @@ static void load_kernel(void) type = KT_KERNEL; execute(default_cmd, type); + + /* + * If we fail to boot the kernel execute the "onerror" command + * line. + */ + if (onerrorlen) { + rsprintf(&cmdline, "%s %s", onerror, default_cmd); + execute(cmdline, KT_COM32); + } } static int ldlinux_main(int argc, char **argv) diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c index ed498ff..898ee19 100644 --- a/com32/elflink/ldlinux/readconfig.c +++ b/com32/elflink/ldlinux/readconfig.c @@ -60,6 +60,7 @@ short displaycon = 1; //conio.inc short nohalt = 1; //idle.inc char *default_cmd = NULL; //"default" command line +char *onerror = NULL; //"onerror" command line /* Empty refstring */ const char *empty_string; @@ -703,6 +704,8 @@ static void parse_config_file(FILE * f) refstr_put(m->onerror); m->onerror = refstrdup(skipspace(p + 7)); onerrorlen = strlen(m->onerror); + refstr_put(onerror); + onerror = refstrdup(m->onerror); } else if (looking_at(p, "master")) { p = skipspace(p + 6); if (looking_at(p, "passwd")) { @@ -1030,6 +1033,12 @@ do_include: nocomplete = atoi(skipspace(p + 10)); } else if (looking_at(p, "nohalt")) { nohalt = atoi(skipspace(p + 8)); + } else if (looking_at(p, "onerror")) { + refstr_put(m->onerror); + m->onerror = refstrdup(skipspace(p + 7)); + onerrorlen = strlen(m->onerror); + refstr_put(onerror); + onerror = refstrdup(m->onerror); } /* serial setting, bps, flow control */ -- 1.7.4
On 03/09/2011 08:00 AM, Matt Fleming wrote:> From: Matt Fleming <matt.fleming at linux.intel.com> > > This is a series of patches that, > > * shrink the core by moving things into an ldlinux ELF module > * begin wiring up some of the C versions of various functions > > The core now only contains essential code and loads the ldlinux module > to do everything else, like providing a command line interface and > loading kernels. > > The config file parsing and kernel load are now done entirely in > C. This allows us to only parse the config file once, even when using > the menu module. Previously the config file would be parsed from asm > to extract the ui module or kernel to load, and then (once the menu > module was running) would be parsed again in order to build the menu > data structures. We now build the menu data structures on the first > (and only) parse of the config file, not to mention the fact that we > only need one copy of the parser now. > > Other functions will be converted from asm to C later. > > This series is also available at, > > git://git.zytor.com/users/mfleming/syslinux.git elflink-readconfig-for-hpa >Hi Matt, Looked over it and merged. Thanks! -hpa
H. Peter Anvin
2011-Mar-14 22:34 UTC
[syslinux] [PATCH 06/12] elflink: Look for syslinux.cfg
On 03/09/2011 08:00 AM, Matt Fleming wrote:> From: Matt Fleming <matt.fleming at linux.intel.com> > > Add syslinux.cfg to the list of configuration file names to check for > when the config parser searches for configuration files. > > Signed-off-by: Matt Fleming <matt.fleming at linux.intel.com> > --- > com32/elflink/ldlinux/readconfig.c | 4 ++++ > 1 files changed, 4 insertions(+), 0 deletions(-) > > diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c > index 9857233..18c1183 100644 > --- a/com32/elflink/ldlinux/readconfig.c > +++ b/com32/elflink/ldlinux/readconfig.c > @@ -1049,6 +1049,10 @@ static int parse_one_config(const char *filename) > if (f) > goto config_found; > > + f = fopen("syslinux.cfg", "r"); > + if (f) > + goto config_found; > + > return -1; > config_found: > parse_config_file(f);This should, at least eventually, use the routine in the filesystem core for searching for the config file. This is probably *not* in the elflink branch since the elflink branch is relatively stale against trunk; but it should be merged in, of course. -hpa