diff --git a/Makefile b/Makefile index 231173a21b5..4c44492b687 100644 --- a/Makefile +++ b/Makefile @@ -59,11 +59,16 @@ ARCH_SRC = $(ARCH_DIR)/src ARCH_INC = $(ARCH_DIR)/include BOARD_DIR = configs/$(CONFIG_ARCH_BOARD) +# This can be over-ridden from the command line: + +APPS_LOC = ../apps + # Add-on directories. These may or may not be in place in the # NuttX source tree (they must be specifically installed) +APPS_DIR := ${shell if [ -r $(APPS_LOC)/Makefile ]; then echo "$(APPS_LOC)"; fi} PCODE_DIR := ${shell if [ -r pcode/Makefile ]; then echo "pcode"; fi} -ADDON_DIRS := $(PCODE_DIR) $(NX_DIR) +ADDON_DIRS := $(PCODE_DIR) $(NX_DIR) $(APPS_DIR) # FSDIRS depend on file descriptor support; NONFSDIRS do not # (except for parts of FSDIRS). We will exclude FSDIRS @@ -127,6 +132,18 @@ ifeq ($(CONFIG_HAVE_CXX),y) LINKLIBS += libxx/liblibxx$(LIBEXT) endif +# Add library for application support +# Always compile the framework which includes exec_nuttapp if users +# or nuttX applications are to be included. + +ifeq ($(CONFIG_BUILTIN_APPS_NUTTX),y) +LINKLIBS += $(APPS_DIR)/libapps$(LIBEXT) +else +ifeq ($(CONFIG_BUILTIN_APPS_USER),y) +LINKLIBS += $(APPS_DIR)/libapps$(LIBEXT) +endif +endif + # Add libraries for network support ifeq ($(CONFIG_NET),y) @@ -249,6 +266,9 @@ fs/libfs$(LIBEXT): context drivers/libdrivers$(LIBEXT): context @$(MAKE) -C drivers TOPDIR="$(TOPDIR)" libdrivers$(LIBEXT) +$(APPS_DIR)/libapps$(LIBEXT): context + @$(MAKE) -C $(APPS_DIR) TOPDIR="$(TOPDIR)" libapps$(LIBEXT) + binfmt/libbinfmt$(LIBEXT): context @$(MAKE) -C binfmt TOPDIR="$(TOPDIR)" libbinfmt$(LIBEXT) diff --git a/configs/vsn/nsh/defconfig b/configs/vsn/nsh/defconfig index 7842e52138b..8e74c4c58a9 100755 --- a/configs/vsn/nsh/defconfig +++ b/configs/vsn/nsh/defconfig @@ -336,7 +336,7 @@ CONFIG_MM_REGIONS=1 CONFIG_ARCH_LOWPUTC=y CONFIG_RR_INTERVAL=200 CONFIG_SCHED_INSTRUMENTATION=n -CONFIG_TASK_NAME_SIZE=0 +CONFIG_TASK_NAME_SIZE=16 CONFIG_START_YEAR=2009 CONFIG_START_MONTH=9 CONFIG_START_DAY=21 @@ -754,6 +754,7 @@ CONFIG_EXAMPLES_NSH_FATSECTSIZE=512 CONFIG_EXAMPLES_NSH_FATNSECTORS=40 CONFIG_EXAMPLES_NSH_FATMOUNTPT=/tmp + # # Architecture-specific NSH options # @@ -817,3 +818,36 @@ CONFIG_PTHREAD_STACK_MIN=256 CONFIG_PTHREAD_STACK_DEFAULT=2048 CONFIG_HEAP_BASE= CONFIG_HEAP_SIZE= + + +######################################################################## +# +# Applications to be included within the NuttX binary as described +# under the apps/README.txt +# +# Set this config parameter above to: CONFIG_TASK_NAME_SIZE=16 +# in order to enable argv[0]= argument. Otherwise argv[0] +# will be noname. +# +# Include builtin NuttX application (disabling this option will +# exclude all of the apps found under the nuttx/apps directory, but +# not the apps found under the ../apps directory unless _APPS_USER=n. +CONFIG_BUILTIN_APPS_NUTTX=y + +# Individual selection of built-in applications: +CONFIG_BUILTIN_APPS_HELLO=y + +# Include user (external) applications located under ../apps directory? +CONFIG_BUILTIN_APPS_USER=y + +# Invoke the following application after NuttX starts +# (enter app name, as: hello) +CONFIG_BUILTIN_APP_START= + +# CONFIG_EXAMPLES_NSH_BUILTIN_APPS - Support for running the builtin +# apps from command line. See apps/README for more information. +# +CONFIG_EXAMPLES_NSH_BUILTIN_APPS=y + +# +######################################################################## diff --git a/examples/nsh/nsh_main.c b/examples/nsh/nsh_main.c index 9981ad07339..a13c6dae020 100644 --- a/examples/nsh/nsh_main.c +++ b/examples/nsh/nsh_main.c @@ -55,6 +55,10 @@ # include #endif +#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS +# include +#endif + #include "nsh.h" /**************************************************************************** @@ -487,6 +491,35 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[]) } } +#ifdef CONFIG_EXAMPLES_NSH_BUILTIN_APPS + if (handler == cmd_unrecognized) + { + /* Try to find command within pre-built application list. */ + + if ((ret = exec_nuttapp(cmd, argv)) < 0) + { + if (errno != ENOENT) + { + return -errno; + } + } + else + { + /* Is the background mode or foreground mode desired? */ +#if 0 + if (argc > 1 && strcmp(argv[argc-1], "&") == 0) + { + } + else + { + waitpid(ret, ); + } +#endif + return ret; + } + } +#endif + ret = handler(vtbl, argc, argv); return ret; } diff --git a/include/nuttx/nuttapp.h b/include/nuttx/nuttapp.h new file mode 100644 index 00000000000..a8b6e8397c6 --- /dev/null +++ b/include/nuttx/nuttapp.h @@ -0,0 +1,123 @@ +/**************************************************************************** + * include/nuttx/nuttapp.h + * + * Copyright(C) 2011 Uros Platise. All rights reserved. + * Author: Uros Platise + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +#ifndef __NUTTX_NUTTAPP_H +#define __NUTTX_NUTTAPP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct nuttapp_s +{ + const char *name; /* Invocation name and as seen under /sbin/ */ + int priority; /* Use: SCHED_PRIORITY_DEFAULT */ + int stacksize; /* Desired stack size */ + main_t main; /* Entry point: main(int argc, char *argv[]) */ +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: execute builtin NuttX application + * + * Description: + * Executes builtin application registerred during compile time. + * New application is run in a separate task context (and thread). + * + * Input Parameter: + * filename - Name of the linked-in binary to be started. + * argv - Argument list + * + * Returned Value: + * This is an end-user function, so it follows the normal convention: + * Returns the PID of the exec'ed module. On failure, it.returns + * -1 (ERROR) and sets errno appropriately. + * + * Implementation within drivers/bchsbin + ****************************************************************************/ + +EXTERN int exec_nuttapp(FAR const char *appname, FAR const char *argv[]); + +/**************************************************************************** + * Name: execute a nutt shell command + * + * Description: + * Invokes an application that is either: + * - invokes a nsh script or directly invoke: + * - system application list, registerred via XXXX + * - resides in a file system compiled/linked in NXFLAT model + * - resides in a non-executable file-system, which is loaded + * into the memory first and then executed. + * + * Input Parameter: + * Sheel command. + * + * Returned Value: + * Zero on success or -1 on error with errno set. + * + * TODO: move this command to the stdlib.h (?) and + * merge implementation with the nuttshell sh command + ****************************************************************************/ + +EXTERN FAR int system(const char *command); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif +#endif /* __NUTTX_NUTAPP_H */ diff --git a/sched/sched_waitpid.c b/sched/sched_waitpid.c index 6e544f2eb35..a1af343e1b1 100644 --- a/sched/sched_waitpid.c +++ b/sched/sched_waitpid.c @@ -195,12 +195,6 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) /* None of the options are supported */ #ifdef CONFIG_DEBUG - if (stat_loc == NULL) - { - err = EINVAL; - goto errout_with_errno; - } - if (options != 0) { err = ENOSYS; @@ -214,7 +208,7 @@ pid_t waitpid(pid_t pid, int *stat_loc, int options) * others? */ - if (tcb->stat_loc == NULL) + if (stat_loc != NULL && tcb->stat_loc == NULL) { tcb->stat_loc = stat_loc; mystat = true;