Running Applications from NSH
This Wiki page describes current and planned features for the NuttX NuttShell (NSH). Think of this page as a roadmap. Most of the features have been implemented and incorporated into NSH; others are just ideas that are being tossed around (noted as NOT implemented). The NSH document will be updated as new features are included.
There currently are be three ways to execute applications from NSH:
1. Executing Builtin Applications
= Builtin Applications
The current implementation of NSH allows for the execution of "named" or "builtin" applications. The applications are simply task entry points in the common FLASH image that have names assigned to them. Simply entering that name from the NSH command line will cause the associated application to run.
See the NSH documentation for further details.
Example
For example,
Code Block |
---|
NuttShell (NSH) NuttX-6.24 nsh> hello Hello, World!! nsh> |
Configuration Settings
This functionality depends on these configuration settings:
...
In additional to other configuration needed by NSH.
2. Executing Application from a File System
OS Interfaces
NuttX supports running applications that reside on a file system as well.
The standard interfaces used to do this include:
execv()
,execl()
, andposix_spawn()
.
Configuration Settings
Execution of applications on a file system is currently supported by Nuttx. This feature is enabled with:
CONFIG_LIBC_EXECFUNCS=y
: Enable support forexecv()
,execl()
, andposix_spawn()
, andCONFIG_NSH_FILE_APPS=y
: Enable execution of programs in a file system by NSH.
Example
When this feature is enabled, you will be able to do the following:
...
Code Block |
---|
nsh> /mnt/sdcard/hello Hello, World!! nsh> |
The PATH Variable
Notice that the absolute path to the hello
program was used. This can be simplified by setting the following in your configuration:
CONFIG_BINFMT_EXEPATH=y
: Enable use of the path variable to find executable programs.
Example
Then, the example becomes:
...
Code Block |
---|
nsh> set PATH /mnt/sdcard nsh> hello Hello, World!! nsh> |
Pre-initialized PATH Variables
One final simplification: The initial PATH variable can be configured so that the PATH to your executable programs is already defined when NSH starts. This is down with:
...
This functionality is already in place.
3. Executing Builtin Applications from a File System
Namespace Management
NuttX supports a virtual file system (VFS) that may used to manage namespaces. Linux uses its VFS to manage nearly all named objects (pipes, locks, message queues, etc.). And it is a good policy for NuttX to do this too. NuttX already does this for things like drivers and mountpoints. Why not extend this mechanism to handle named, builtin applications too?
Proposed Configuration Options
The following configuration options are planned:
...
CONFIG_FS_BINFS=y
: Enable the BINFS file system that is used to access builtin applications as files,CONFIG_LIBC_EXECFUNCS=y
: Enable support forexecv()
,execl()
, andposix_spawn()
,CONFIG_NSH_FILE_APPS=y
: Enable execution of programs in a file system by NSH,CONFIG_BINFMT_EXEPATH=y
: Enable the (optional) use of the path variable to find executable programs, andCONFIG_PATH_INITIAL="/mnt/sdcard:/bin"
: Optional initial value of the PATH variable.
Example
When this feature is enable, will will be able to do this (where myapplication is the name of some, arbitrary "built-in" application):
...
Code Block |
---|
nsh> echo $PATH /mnt/sdcard:/bin nsh> myapplication ... and your FLASH based application runs ... nsh> |
Auto-Mounting BINFS
BINFS, like any file system, could be mounted by an startup script at /etc/init.d/rcS.
...
Or perhaps a better thing to do would just be to make it easier to add a startup script?
Next Steps
In the longer term, I would like to see an option to move most of the larger NSH commands out of RAM and built them as standalone programs that can reside, for example, on an SD card (NOT implemented).