Add a binary 'loader' so that builtin applications can be executed from the BINFS file system

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5525 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2013-01-16 19:08:23 +00:00
parent ce0a475c9f
commit fefb836376
4 changed files with 60 additions and 26 deletions

View File

@ -478,6 +478,10 @@
* apps/include/builtin.h: Some of the content of * apps/include/builtin.h: Some of the content of
apps/include/apps.h moved to include/nuttx/binfmt/builtin.h. apps/include/apps.h moved to include/nuttx/binfmt/builtin.h.
apps/include/apps.h renamed builtin.h apps/include/apps.h renamed builtin.h
* pps/builtin/exec_builtins.c: Move utility builtin * apps/builtin/exec_builtins.c: Move utility builtin
utility functions from apps/builtin/exec_builtins.c to utility functions from apps/builtin/exec_builtins.c to
binfmt/libbuiltin/libbuiltin_utils.c binfmt/libbuiltin/libbuiltin_utils.c
* apps/nshlib/nsh_mountcmds.c: The block driver/source
argument is now optional. Many files systems do not need
a source and it is really stupid to have to enter a bogus
source parameter.

View File

@ -15,7 +15,7 @@ if NSH_LIBRARY
config NSH_BUILTIN_APPS config NSH_BUILTIN_APPS
bool "Enable built-in applications" bool "Enable built-in applications"
default y default y
select BUILTIN depends on BUILTIN
---help--- ---help---
Support external registered, "built-in" applications that can be Support external registered, "built-in" applications that can be
executed from the NSH command line (see apps/README.txt for executed from the NSH command line (see apps/README.txt for

View File

@ -133,7 +133,7 @@ static int mount_handler(FAR const char *mountpoint,
#ifdef CONFIG_FS_BINFS #ifdef CONFIG_FS_BINFS
case BINFS_MAGIC: case BINFS_MAGIC:
fstype = "bindir"; fstype = "binfs";
break; break;
#endif #endif
@ -198,9 +198,11 @@ int cmd_df(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT) defined(CONFIG_FS_READABLE) && !defined(CONFIG_NSH_DISABLE_MOUNT)
int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv) int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{ {
FAR char *source; FAR const char *source;
FAR char *target; FAR char *fullsource;
FAR char *filesystem = NULL; FAR const char *target;
FAR char *fulltarget;
FAR const char *filesystem = NULL;
bool badarg = false; bool badarg = false;
int option; int option;
int ret; int ret;
@ -248,21 +250,34 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
return ERROR; return ERROR;
} }
/* There are two required arguments after the options: the source and target /* There may be one or two required arguments after the options: the source
* paths. * and target paths. Some file systems do not require the source parameter
* so if there is only one parameter left, it must be the target.
*/ */
if (optind + 2 < argc) if (optind >= argc)
{
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
return ERROR;
}
else if (optind + 2 > argc)
{ {
nsh_output(vtbl, g_fmtargrequired, argv[0]); nsh_output(vtbl, g_fmtargrequired, argv[0]);
return ERROR; return ERROR;
} }
source = NULL;
target = argv[optind];
optind++;
if (optind < argc)
{
source = target;
target = argv[optind];
optind++;
if (optind < argc)
{
nsh_output(vtbl, g_fmttoomanyargs, argv[0]);
return ERROR;
}
}
/* While the above parsing for the -t argument looks nice, the -t argument /* While the above parsing for the -t argument looks nice, the -t argument
* not really optional. * not really optional.
*/ */
@ -277,29 +292,44 @@ int cmd_mount(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
* working directory. * working directory.
*/ */
source = nsh_getfullpath(vtbl, argv[optind]); fullsource = NULL;
if (!source) fulltarget = NULL;
if (source)
{ {
return ERROR; fullsource = nsh_getfullpath(vtbl, source);
if (!fullsource)
{
return ERROR;
}
} }
target = nsh_getfullpath(vtbl, argv[optind+1]); fulltarget = nsh_getfullpath(vtbl, target);
if (!target) if (!fulltarget)
{ {
nsh_freefullpath(source); ret = ERROR;
return ERROR; goto errout;
} }
/* Perform the mount */ /* Perform the mount */
ret = mount(source, target, filesystem, 0, NULL); ret = mount(fullsource, fulltarget, filesystem, 0, NULL);
if (ret < 0) if (ret < 0)
{ {
nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO); nsh_output(vtbl, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO);
} }
nsh_freefullpath(source); errout:
nsh_freefullpath(target); if (fullsource)
{
nsh_freefullpath(fullsource);
}
if (fulltarget)
{
nsh_freefullpath(fulltarget);
}
return ret; return ret;
} }
#endif #endif

View File

@ -301,7 +301,7 @@ static const struct cmdmap_s g_cmdmap[] =
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE) #if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE)
# ifndef CONFIG_NSH_DISABLE_MOUNT # ifndef CONFIG_NSH_DISABLE_MOUNT
{ "mount", cmd_mount, 1, 5, "[-t <fstype> <block-device> <mount-point>]" }, { "mount", cmd_mount, 1, 5, "[-t <fstype> [<block-device>] <mount-point>]" },
# endif # endif
#endif #endif