aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--com32/elflink/ldlinux/cli.c74
-rw-r--r--com32/elflink/ldlinux/ldlinux.c84
-rw-r--r--com32/elflink/ldlinux/readconfig.c2
-rw-r--r--com32/elflink/modules/cli.h1
-rw-r--r--com32/elflink/modules/menu.h2
5 files changed, 74 insertions, 89 deletions
diff --git a/com32/elflink/ldlinux/cli.c b/com32/elflink/ldlinux/cli.c
index 2f3ef29c..3026cac2 100644
--- a/com32/elflink/ldlinux/cli.c
+++ b/com32/elflink/ldlinux/cli.c
@@ -445,76 +445,14 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
}
printf("\033[?7h");
- return ret;
-}
-
-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));
- int argc = 1, len_mn;
- char *crt_arg, *module_name;
-
- /* return if user only press enter */
- if (cmd[0] == '\0') {
- printf("\n");
- return;
- }
- printf("\n");
-
- if (history) {
- struct cli_command *comm;
- comm = malloc(sizeof(struct cli_command));
- comm->command = malloc(sizeof(char) * (strlen(cmd) + 1));
- strcpy(comm->command, cmd);
- list_add(&(comm->list), &cli_history_head);
- }
-
- // dprintf("raw cmd = %s", cmd);
- strcpy(temp_cmd, cmd);
- module_name = strtok((char *)cmd, COMMAND_DELIM);
- len_mn = strlen(module_name);
-
- if (!strcmp(module_name + len_mn - 4, ".c32")) {
- if (module_find(module_name) != NULL) {
- /* make module re-enterable */
- // dprintf("Module %s is already running");
- }
- do {
- argv[0] = module_name;
- crt_arg = strtok(NULL, COMMAND_DELIM);
- if (crt_arg != NULL && strlen(crt_arg) > 0) {
- argv[argc] = crt_arg;
- argc++;
- } else
- break;
- } while (argc < MAX_COMMAND_ARGS);
- argv[argc] = NULL;
- module_load_dependencies(module_name, MODULES_DEP);
- spawn_load(module_name, (const char **)argv);
- } else if (!strcmp(module_name + len_mn - 2, ".0")) {
- execute(cmd, KT_PXE);
- } else if (!strcmp(module_name + len_mn - 3, ".bs")) {
- } else if (!strcmp(module_name + len_mn - 4, ".img")) {
- execute(cmd, KT_FDIMAGE);
- } else if (!strcmp(module_name + len_mn - 4, ".bin")) {
- } else if (!strcmp(module_name + len_mn - 4, ".bss")) {
- execute(cmd, KT_BSS);
- } else if (!strcmp(module_name + len_mn - 4, ".com")
- || !strcmp(module_name + len_mn - 4, ".cbt")) {
- execute(cmd, KT_COMBOOT);
- } else if (!strcmp(module_name + len_mn - 4, ".cfg")
- || !strcmp(module_name + len_mn - 5, ".conf")
- || !strcmp(module_name + len_mn - 7, ".config")) {
- execute(module_name, KT_CONFIG);
- }
- /* use KT_KERNEL as default */
- else
- execute(temp_cmd, KT_KERNEL);
+ /* Add the command to the history */
+ comm_counter = malloc(sizeof(struct cli_command));
+ comm_counter->command = malloc(sizeof(char) * (strlen(ret) + 1));
+ strcpy(comm_counter->command, ret);
+ list_add(&(comm_counter->list), &cli_history_head);
- free(argv);
- free(temp_cmd);
+ return ret;
}
static int cli_init(void)
diff --git a/com32/elflink/ldlinux/ldlinux.c b/com32/elflink/ldlinux/ldlinux.c
index ea889cc5..36eaded4 100644
--- a/com32/elflink/ldlinux/ldlinux.c
+++ b/com32/elflink/ldlinux/ldlinux.c
@@ -11,35 +11,60 @@
#include <sys/module.h>
-static void enter_cmdline(void)
+/*
+ * 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;
+ char *kernel_name;
+ int len;
- /* Enter endless command line prompt, should support "exit" */
- while (1) {
- cmdline = edit_cmdline("syslinux$", 1, NULL, cat_help_file);
- if (!cmdline)
- continue;
- /* 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);
- //}
+ /* Virtual kernel? */
+ me = find_label(kernel);
+ if (me) {
+ /* XXX we don't handle LOCALBOOT yet */
+ execute(me->cmdline, KT_KERNEL);
+ /* We shouldn't return */
+ goto bad_kernel;
}
-}
-static void load_kernel(void)
-{
- enum kernel_type type;
- const char *cmdline;
+ if (!allowimplicit)
+ goto bad_implicit;
+
+ kernel_name = strtok((char *)kernel, COMMAND_DELIM);
+ len = strlen(kernel_name);
- if (defaultlevel == LEVEL_UI)
+ if (!strcmp(kernel_name + len - 4, ".c32")) {
type = KT_COM32;
+ } else if (!strcmp(kernel_name + len - 2, ".0")) {
+ type = KT_PXE;
+ } else if (!strcmp(kernel_name + len - 3, ".bs")) {
+ type = KT_BOOT;
+ } else if (!strcmp(kernel_name + len - 4, ".img")) {
+ type = KT_FDIMAGE;
+ } else if (!strcmp(kernel_name + len - 4, ".bin")) {
+ type = KT_BOOT;
+ } else if (!strcmp(kernel_name + len - 4, ".bss")) {
+ type = KT_BSS;
+ } else if (!strcmp(kernel_name + len - 4, ".com")
+ || !strcmp(kernel_name + len - 4, ".cbt")) {
+ type = KT_COMBOOT;
+ }
+ /* use KT_KERNEL as default */
else
type = KT_KERNEL;
- execute(default_cmd, type);
+ execute(kernel, type);
+bad_implicit:
+bad_kernel:
/*
* If we fail to boot the kernel execute the "onerror" command
* line.
@@ -50,6 +75,27 @@ static void load_kernel(void)
}
}
+static void enter_cmdline(void)
+{
+ const char *cmdline;
+
+ /* Enter endless command line prompt, should support "exit" */
+ while (1) {
+ cmdline = edit_cmdline("syslinux$", 1, NULL, cat_help_file);
+ if (!cmdline)
+ continue;
+
+ /* return if user only press enter */
+ if (cmdline[0] == '\0') {
+ printf("\n");
+ continue;
+ }
+ printf("\n");
+
+ load_kernel(cmdline);
+ }
+}
+
static int ldlinux_main(int argc, char **argv)
{
openconsole(&dev_rawcon_r, &dev_ansiserial_w);
@@ -67,7 +113,7 @@ static int ldlinux_main(int argc, char **argv)
*/
if (defaultlevel || noescape) {
if (defaultlevel) {
- load_kernel(); /* Shouldn't return */
+ load_kernel(default_cmd); /* Shouldn't return */
} else {
printf("No DEFAULT or UI configuration directive found!\n");
diff --git a/com32/elflink/ldlinux/readconfig.c b/com32/elflink/ldlinux/readconfig.c
index 66e84dfb..d78c0151 100644
--- a/com32/elflink/ldlinux/readconfig.c
+++ b/com32/elflink/ldlinux/readconfig.c
@@ -432,7 +432,7 @@ void print_labels(const char *prefix, size_t len)
}
}
-static struct menu_entry *find_label(const char *str)
+struct menu_entry *find_label(const char *str)
{
const char *p;
struct menu_entry *me;
diff --git a/com32/elflink/modules/cli.h b/com32/elflink/modules/cli.h
index 4ae9caf3..513c1719 100644
--- a/com32/elflink/modules/cli.h
+++ b/com32/elflink/modules/cli.h
@@ -15,7 +15,6 @@ 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 8041fc97..e79fb3e0 100644
--- a/com32/elflink/modules/menu.h
+++ b/com32/elflink/modules/menu.h
@@ -204,6 +204,8 @@ extern const int message_base_color;
extern const char *current_background;
void set_background(const char *new_background);
+extern struct menu_entry *find_label(const char *str);
+
/* execute.c */
void execute(const char *cmdline, enum kernel_type type);