diff options
author | Chris Johns <chrisj@rtems.org> | 2009-04-28 06:34:38 +0000 |
---|---|---|
committer | Chris Johns <chrisj@rtems.org> | 2009-04-28 06:34:38 +0000 |
commit | 2549b4d9a83d310e32329255a5a02604eb9e028b (patch) | |
tree | 0dd35b9944f836cb3869c87b77bafafb3b090eac /c/src/lib/libbsp/shared/bspinit.c | |
parent | 2009-04-28 Chris Johns <chrisj@rtems.org> (diff) | |
download | rtems-2549b4d9a83d310e32329255a5a02604eb9e028b.tar.bz2 |
2009-04-28 Chris Johns <chrisj@rtems.org>
* bootcard.c, include/bootcard.h: Remove argc/argv/envp and
replace with a single BSP boot command line a BSP can optionally
support.
Diffstat (limited to '')
-rw-r--r-- | c/src/lib/libbsp/shared/bspinit.c | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/shared/bspinit.c b/c/src/lib/libbsp/shared/bspinit.c new file mode 100644 index 0000000000..1c9f6a4b6b --- /dev/null +++ b/c/src/lib/libbsp/shared/bspinit.c @@ -0,0 +1,93 @@ +/* + * COPYRIGHT (c) 1989-2009. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#include <stdlib.h> +#include <string.h> + +#include <bsp.h> +#include <bsp/bootcard.h> + +/* + * This routine calls main from a confdefs.h default Init task + * set up. The bootcard will provide the task argument as + * command line string (ASCIIZ). + */ + +int main (int argc, char* argv[]); + +void Init (rtems_task_argument arg) +{ + const char* boot_cmdline = *((const char**) arg); + char* cmdline = 0; + char* command; + int argc = 0; + char** argv = NULL; + int result = -124; + + if (boot_cmdline) + { + cmdline = malloc (strlen (boot_cmdline) + 1); + + if (cmdline) + { + strcpy (cmdline, boot_cmdline); + + command = cmdline; + + /* + * Break the line up into arguments with "" being ignored. + */ + while (true) + { + command = strtok (command, " \t\r\n"); + if (command == NULL) + break; + argc++; + command = '\0'; + } + + argv = calloc (argc, sizeof (char*)); + + if (argv) + { + int a; + + command = cmdline; + argv[0] = command; + + for (a = 1; a < argc; a++) + { + command += strlen (command) + 1; + argv[a] = command; + } + } + else + argc = 0; + } + } + +#ifdef RTEMS_NETWORKING + rtems_bsdnet_initialize_network (); +#endif + + result = main (argc, argv); + + free (argv); + free (cmdline); + + exit (result); +} + +/* + * By making this a weak alias and a user can provide there own. + */ + +void Init (rtems_task_argument arg) __attribute__ ((weak)); |