From 2549b4d9a83d310e32329255a5a02604eb9e028b Mon Sep 17 00:00:00 2001 From: Chris Johns Date: Tue, 28 Apr 2009 06:34:38 +0000 Subject: 2009-04-28 Chris Johns * bootcard.c, include/bootcard.h: Remove argc/argv/envp and replace with a single BSP boot command line a BSP can optionally support. --- c/src/lib/libbsp/shared/ChangeLog | 6 ++ c/src/lib/libbsp/shared/bootcard.c | 45 +++++---------- c/src/lib/libbsp/shared/bspinit.c | 93 ++++++++++++++++++++++++++++++ c/src/lib/libbsp/shared/include/bootcard.h | 2 +- 4 files changed, 113 insertions(+), 33 deletions(-) create mode 100644 c/src/lib/libbsp/shared/bspinit.c diff --git a/c/src/lib/libbsp/shared/ChangeLog b/c/src/lib/libbsp/shared/ChangeLog index 98e261cad2..cfcd0ce801 100644 --- a/c/src/lib/libbsp/shared/ChangeLog +++ b/c/src/lib/libbsp/shared/ChangeLog @@ -1,3 +1,9 @@ +2009-04-28 Chris Johns + + * bootcard.c, include/bootcard.h: Remove argc/argv/envp and + replace with a single BSP boot command line a BSP can optionally + support. + 2009-03-10 Eric Norum * bootcard.c: Swap order of RTEMS Workspace and Malloc Heap. This diff --git a/c/src/lib/libbsp/shared/bootcard.c b/c/src/lib/libbsp/shared/bootcard.c index 10a3b0d7a8..abb5216a63 100644 --- a/c/src/lib/libbsp/shared/bootcard.c +++ b/c/src/lib/libbsp/shared/bootcard.c @@ -48,9 +48,10 @@ #include /* - * Since there is a forward reference + * At most a single pointer to the cmdline for those target + * short on memory and not supporting a command line. */ -char *rtems_progname; +const char *bsp_boot_cmdline; /* * Are we using a single heap for the RTEMS Workspace and C Program Heap? @@ -114,21 +115,15 @@ static rtems_status_code bootcard_bsp_libc_helper( * as much as possible. */ int boot_card( - int argc, - char **argv, - char **envp + const char *cmdline ) { - static char *argv_pointer = NULL; - static char *envp_pointer = NULL; - char **argv_p = &argv_pointer; - char **envp_p = &envp_pointer; - rtems_interrupt_level bsp_isr_level; - rtems_status_code sc = RTEMS_SUCCESSFUL; - void *work_area_start = NULL; - intptr_t work_area_size = 0; - void *heap_start = NULL; - intptr_t heap_size = 0; + rtems_interrupt_level bsp_isr_level; + rtems_status_code sc = RTEMS_SUCCESSFUL; + void *work_area_start = NULL; + intptr_t work_area_size = 0; + void *heap_start = NULL; + intptr_t heap_size = 0; /* * Special case for PowerPC: The interrupt disable mask is stored in SPRG0. @@ -143,22 +138,7 @@ int boot_card( */ rtems_interrupt_disable( bsp_isr_level ); - /* - * Set things up so we have real pointers for argv and envp. - * If the BSP has passed us something useful, then pass it on. - * Somehow we need to eventually make this available to - * a real main() in user land. :) - */ - if ( argv ) argv_p = argv; - if ( envp ) envp_p = envp; - - /* - * Set the program name in case some application cares. - */ - if ((argc > 0) && argv && argv[0]) - rtems_progname = argv[0]; - else - rtems_progname = "RTEMS"; + bsp_boot_cmdline = cmdline; /* * Invoke Board Support Package initialization routine written in C. @@ -169,7 +149,8 @@ int boot_card( * Find out where the block of memory the BSP will use for * the RTEMS Workspace and the C Program Heap is. */ - bsp_get_work_area(&work_area_start, &work_area_size, &heap_start, &heap_size); + bsp_get_work_area(&work_area_start, (ssize_t*) &work_area_size, + &heap_start, (ssize_t*) &heap_size); if ( work_area_size <= Configuration.work_space_size ) { printk( "bootcard: Work space too big for work area!\n"); 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 +#include + +#include +#include + +/* + * 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)); diff --git a/c/src/lib/libbsp/shared/include/bootcard.h b/c/src/lib/libbsp/shared/include/bootcard.h index 12bb45a3ff..18c9069f2e 100644 --- a/c/src/lib/libbsp/shared/include/bootcard.h +++ b/c/src/lib/libbsp/shared/include/bootcard.h @@ -60,7 +60,7 @@ void bsp_get_work_area( ssize_t *heap_size ); -int boot_card( int argc, char **argv, char **envp); +int boot_card( const char *cmdline ); void bsp_libc_init( void *heap_start, size_t heap_size, size_t sbrk_amount); -- cgit v1.2.3