Some minor fixes for CONFIG_ADDRENV=y

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5444 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2012-12-19 21:16:03 +00:00
parent 56a6504618
commit 272fc3b523
7 changed files with 92 additions and 12 deletions

View File

@ -429,4 +429,7 @@
* Rename CONFIG_PCODE and CONFIG_FICL as CONFIG_INTERPRETERS_PCODE and * Rename CONFIG_PCODE and CONFIG_FICL as CONFIG_INTERPRETERS_PCODE and
CONFIG_INTERPRETERS_FICL for consistency with other configuration naming. CONFIG_INTERPRETERS_FICL for consistency with other configuration naming.
* apps/examples/keypadtest: A keypad test example contributed by Denis * apps/examples/keypadtest: A keypad test example contributed by Denis
Carikli Carikli.
* apps/examples/elf and nxflat: If CONFIG_BINFMT_EXEPATH is defined, these
tests will now use a relative path to the program and expect the binfmt/
logic to find the absolute path to the program using the PATH variable.

View File

@ -70,6 +70,10 @@
# error "You must provide file descriptors via CONFIG_NFILE_DESCRIPTORS in your configuration file" # error "You must provide file descriptors via CONFIG_NFILE_DESCRIPTORS in your configuration file"
#endif #endif
#ifdef CONFIG_BINFMT_DISABLE
# error "The binary loader is disabled (CONFIG_BINFMT_DISABLE)!"
#endif
#ifndef CONFIG_ELF #ifndef CONFIG_ELF
# error "You must select CONFIG_ELF in your configuration file" # error "You must select CONFIG_ELF in your configuration file"
#endif #endif
@ -136,7 +140,9 @@ static unsigned int g_mmstep; /* Memory Usage at beginning of test step */
static const char delimiter[] = static const char delimiter[] =
"****************************************************************************"; "****************************************************************************";
static char path[128]; #ifndef CONFIG_BINFMT_EXEPATH
static char fullpath[128];
#endif
/**************************************************************************** /****************************************************************************
* Symbols from Auto-Generated Code * Symbols from Auto-Generated Code
@ -264,19 +270,46 @@ int elf_main(int argc, char *argv[])
mm_update(&g_mmstep, "after mount"); mm_update(&g_mmstep, "after mount");
/* Does the system support the PATH variable? Has the PATH variable
* already been set? If YES and NO, then set the PATH variable to
* the ROMFS mountpoint.
*/
#if defined(CONFIG_BINFMT_EXEPATH) && !defined(CONFIG_PATH_INITIAL)
(void)setenv("PATH", MOUNTPT, 1);
#endif
/* Now excercise every program in the ROMFS file system */ /* Now excercise every program in the ROMFS file system */
for (i = 0; dirlist[i]; i++) for (i = 0; dirlist[i]; i++)
{ {
/* Output a seperated so that we can clearly discrinmate the output of
* this program from the others.
*/
testheader(dirlist[i]); testheader(dirlist[i]);
memset(&bin, 0, sizeof(struct binary_s)); /* Initialize the binary_s structure */
snprintf(path, 128, "%s/%s", MOUNTPT, dirlist[i]);
bin.filename = path; memset(&bin, 0, sizeof(struct binary_s));
/* If the binary loader does not support the PATH variable, then
* create the full path to the executable program. Otherwise,
* use the relative path so that the binary loader will have to
* search the PATH variable to find the executable.
*/
#ifdef CONFIG_BINFMT_EXEPATH
bin.filename = dirlist[i];
#else
snprintf(fullpath, 128, "%s/%s", MOUNTPT, dirlist[i]);
bin.filename = fullpath;
#endif
bin.exports = exports; bin.exports = exports;
bin.nexports = nexports; bin.nexports = nexports;
/* Load the ELF module */
ret = load_module(&bin); ret = load_module(&bin);
if (ret < 0) if (ret < 0)
{ {
@ -286,6 +319,8 @@ int elf_main(int argc, char *argv[])
mm_update(&g_mmstep, "after load_module"); mm_update(&g_mmstep, "after load_module");
/* Execute the ELF module */
ret = exec_module(&bin, 50); ret = exec_module(&bin, 50);
mm_update(&g_mmstep, "after exec_module"); mm_update(&g_mmstep, "after exec_module");

View File

@ -69,6 +69,10 @@
# error "You must provide file descriptors via CONFIG_NFILE_DESCRIPTORS in your configuration file" # error "You must provide file descriptors via CONFIG_NFILE_DESCRIPTORS in your configuration file"
#endif #endif
#ifdef CONFIG_BINFMT_DISABLE
# error "The binary loader is disabled (CONFIG_BINFMT_DISABLE)!"
#endif
#ifndef CONFIG_NXFLAT #ifndef CONFIG_NXFLAT
# error "You must select CONFIG_NXFLAT in your configuration file" # error "You must select CONFIG_NXFLAT in your configuration file"
#endif #endif
@ -125,7 +129,9 @@
static const char delimiter[] = static const char delimiter[] =
"****************************************************************************"; "****************************************************************************";
static char path[128]; #ifndef CONFIG_BINFMT_EXEPATH
static char fullpath[128];
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@ -188,19 +194,46 @@ int nxflat_main(int argc, char *argv[])
nxflat_uninitialize(); nxflat_uninitialize();
} }
/* Does the system support the PATH variable? Has the PATH variable
* already been set? If YES and NO, then set the PATH variable to
* the ROMFS mountpoint.
*/
#if defined(CONFIG_BINFMT_EXEPATH) && !defined(CONFIG_PATH_INITIAL)
(void)setenv("PATH", MOUNTPT, 1);
#endif
/* Now excercise every progrm in the ROMFS file system */ /* Now excercise every progrm in the ROMFS file system */
for (i = 0; dirlist[i]; i++) for (i = 0; dirlist[i]; i++)
{ {
/* Output a seperated so that we can clearly discrinmate the output of
* this program from the others.
*/
testheader(dirlist[i]); testheader(dirlist[i]);
memset(&bin, 0, sizeof(struct binary_s)); /* Initialize the binary_s structure */
snprintf(path, 128, "%s/%s", MOUNTPT, dirlist[i]);
bin.filename = path; memset(&bin, 0, sizeof(struct binary_s));
/* If the binary loader does not support the PATH variable, then
* create the full path to the executable program. Otherwise,
* use the relative path so that the binary loader will have to
* search the PATH variable to find the executable.
*/
#ifdef CONFIG_BINFMT_EXEPATH
bin.filename = dirlist[i];
#else
snprintf(fullpath, 128, "%s/%s", MOUNTPT, dirlist[i]);
bin.filename = fullpath;
#endif
bin.exports = exports; bin.exports = exports;
bin.nexports = NEXPORTS; bin.nexports = NEXPORTS;
/* Load the NXFLAT module */
ret = load_module(&bin); ret = load_module(&bin);
if (ret < 0) if (ret < 0)
{ {
@ -208,6 +241,8 @@ int nxflat_main(int argc, char *argv[])
exit(1); exit(1);
} }
/* Execute the ELF module */
ret = exec_module(&bin, 50); ret = exec_module(&bin, 50);
if (ret < 0) if (ret < 0)
{ {

View File

@ -183,7 +183,7 @@ int unload_module(FAR const struct binary_s *binp)
if (binp->alloc[i]) if (binp->alloc[i])
{ {
bvdbg("Freeing alloc[%d]: %p\n", i, binp->alloc[i]); bvdbg("Freeing alloc[%d]: %p\n", i, binp->alloc[i]);
free(binp->alloc[i]); free((FAR void *)binp->alloc[i]);
} }
} }

View File

@ -39,6 +39,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>

View File

@ -38,6 +38,7 @@
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@ -248,7 +249,7 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
DEBUGASSERT(offset + nrelocs * sizeof(struct nxflat_reloc_s) DEBUGASSERT(offset + nrelocs * sizeof(struct nxflat_reloc_s)
<= (loadinfo->isize + loadinfo->dsize)); <= (loadinfo->isize + loadinfo->dsize));
relocs = (FAR struct nxflat_reloc_s*) relocs = (FAR struct nxflat_reloc_s *)
(offset - loadinfo->isize + loadinfo->dspace->region); (offset - loadinfo->isize + loadinfo->dspace->region);
bvdbg("isize: %08lx dpsace: %p relocs: %p\n", bvdbg("isize: %08lx dpsace: %p relocs: %p\n",
(long)loadinfo->isize, loadinfo->dspace->region, relocs); (long)loadinfo->isize, loadinfo->dspace->region, relocs);
@ -276,7 +277,13 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
{ {
/* Handle the relocation by the relocation type */ /* Handle the relocation by the relocation type */
#ifdef CONFIG_CAN_PASS_STRUCTS
reloc = *relocs++; reloc = *relocs++;
#else
memcpy(&reloc, relocs, sizeof(struct nxflat_reloc_s));
relocs++;
#endif
result = OK; result = OK;
switch (NXFLAT_RELOC_TYPE(reloc.r_info)) switch (NXFLAT_RELOC_TYPE(reloc.r_info))
{ {

View File

@ -95,4 +95,3 @@ int nxflat_unload(struct nxflat_loadinfo_s *loadinfo)
nxflat_addrenv_free(loadinfo); nxflat_addrenv_free(loadinfo);
return OK; return OK;
} }