2012-10-25 22:06:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* examples/elf/elf_main.c
|
|
|
|
*
|
2020-04-11 20:13:56 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-10-25 22:06:46 +02:00
|
|
|
*
|
2020-04-11 20:13:56 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-10-25 22:06:46 +02:00
|
|
|
*
|
2020-04-11 20:13:56 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-10-25 22:06:46 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
|
|
|
|
#include <sys/mount.h>
|
2018-08-05 00:24:02 +02:00
|
|
|
#include <sys/stat.h>
|
2012-10-29 20:32:05 +01:00
|
|
|
|
2012-10-25 22:06:46 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2017-10-02 22:32:17 +02:00
|
|
|
#include <nuttx/symtab.h>
|
2016-07-20 22:02:41 +02:00
|
|
|
#include <nuttx/drivers/ramdisk.h>
|
2012-10-25 22:06:46 +02:00
|
|
|
#include <nuttx/binfmt/binfmt.h>
|
|
|
|
|
2017-05-14 00:53:33 +02:00
|
|
|
#include "platform/cxxinitialize.h"
|
|
|
|
|
2018-03-24 18:36:20 +01:00
|
|
|
#if defined(CONFIG_EXAMPLES_ELF_ROMFS)
|
|
|
|
# include "tests/romfs.h"
|
|
|
|
#elif defined(CONFIG_EXAMPLES_ELF_CROMFS)
|
|
|
|
# include "tests/cromfs.h"
|
2018-08-04 21:10:40 +02:00
|
|
|
#elif !defined(CONFIG_EXAMPLES_ELF_EXTERN)
|
2018-03-24 18:36:20 +01:00
|
|
|
# error "No file system selected"
|
|
|
|
#endif
|
|
|
|
|
2012-10-25 22:06:46 +02:00
|
|
|
#include "tests/dirlist.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-02 22:06:11 +02:00
|
|
|
* Pre-processor Definitions
|
2012-10-25 22:06:46 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Check configuration. This is not all of the configuration settings that
|
|
|
|
* are required -- only the more obvious.
|
|
|
|
*/
|
|
|
|
|
2012-12-19 22:16:03 +01:00
|
|
|
#ifdef CONFIG_BINFMT_DISABLE
|
|
|
|
# error "The binary loader is disabled (CONFIG_BINFMT_DISABLE)!"
|
|
|
|
#endif
|
|
|
|
|
2012-10-25 22:06:46 +02:00
|
|
|
#ifndef CONFIG_ELF
|
|
|
|
# error "You must select CONFIG_ELF in your configuration file"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_DISABLE_MOUNTPOINT
|
|
|
|
# error "You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT in your configuration file"
|
|
|
|
#endif
|
|
|
|
|
2018-03-24 18:36:20 +01:00
|
|
|
#if defined(CONFIG_EXAMPLES_ELF_ROMFS)
|
2012-10-25 22:06:46 +02:00
|
|
|
/* Describe the ROMFS file system */
|
|
|
|
|
2018-03-24 18:36:20 +01:00
|
|
|
# define SECTORSIZE 512
|
|
|
|
# define NSECTORS(b) (((b) + SECTORSIZE - 1) / SECTORSIZE)
|
|
|
|
# define MOUNTPT "/mnt/romfs"
|
2012-10-25 22:06:46 +02:00
|
|
|
|
2018-03-24 18:36:20 +01:00
|
|
|
# ifndef CONFIG_EXAMPLES_ELF_DEVMINOR
|
|
|
|
# define CONFIG_EXAMPLES_ELF_DEVMINOR 0
|
|
|
|
# endif
|
|
|
|
|
|
|
|
# ifndef CONFIG_EXAMPLES_ELF_DEVPATH
|
|
|
|
# define CONFIG_EXAMPLES_ELF_DEVPATH "/dev/ram0"
|
|
|
|
# endif
|
|
|
|
|
2018-08-04 21:10:40 +02:00
|
|
|
#elif defined(CONFIG_EXAMPLES_ELF_CROMFS)
|
2018-03-24 18:36:20 +01:00
|
|
|
/* Describe the CROMFS file system */
|
2012-10-26 00:10:56 +02:00
|
|
|
|
2018-03-24 18:36:20 +01:00
|
|
|
# define MOUNTPT "/mnt/cromfs"
|
2018-08-04 21:10:40 +02:00
|
|
|
|
apps/examples/elf: Correct mount point configuration error.
If an external file system is used but is not mounted by the the ELF example, then a compilation error will occur. This configuration problem has existed for a long time but was unmasked by a recent PR. In the failure mode, CONFIG_EXAMPLES_ELF_FSTYPE would not be defined because it depends on CONFIG_EXAMPLES_ELF_FSMOUNT which is not defined. The resulting mountpoint, MOUNTPT, would therefore be left in an invalid state. Previous changes to conditional logic now allowed setenv() to run and to attempt to set the PATH variable to MOUNTPT, causing a compile time failure like this:
CC: elf_main.c
elf_main.c: In function 'elf_main':
elf_main.c:113:32: error: expected ')' before 'CONFIG_EXAMPLES_ELF_FSTYPE'
# define MOUNTPT "/mnt/" CONFIG_EXAMPLES_ELF_FSTYPE
^~~~~~~~~~~~~~~~~~~~~~~~~~
elf_main.c:364:18: note: in expansion of macro 'MOUNTPT'
setenv("PATH", MOUNTPT, 1);
^~~~~~~
elf_main.c:364:3: error: too few arguments to function 'setenv'
setenv("PATH", MOUNTPT, 1);
^~~~~~
In file included from elf_main.c:47:
D:\Spuda\Documents\projects\nuttx\master\nuttx-fork\include/stdlib.h:158:11: note: declared here
int setenv(FAR const char *name, FAR const char *value, int overwrite);
^~~~~~
This problem was found during manual build testing using configuration lx_cpu:nsh.
2020-02-15 17:14:03 +01:00
|
|
|
#elif defined(CONFIG_EXAMPLES_ELF_EXTERN) && defined(CONFIG_EXAMPLES_ELF_FSMOUNT)
|
2018-08-04 21:10:40 +02:00
|
|
|
/* Describe the external file system */
|
|
|
|
|
|
|
|
# define MOUNTPT "/mnt/" CONFIG_EXAMPLES_ELF_FSTYPE
|
|
|
|
|
2018-03-24 18:36:20 +01:00
|
|
|
#else
|
apps/examples/elf: Correct mount point configuration error.
If an external file system is used but is not mounted by the the ELF example, then a compilation error will occur. This configuration problem has existed for a long time but was unmasked by a recent PR. In the failure mode, CONFIG_EXAMPLES_ELF_FSTYPE would not be defined because it depends on CONFIG_EXAMPLES_ELF_FSMOUNT which is not defined. The resulting mountpoint, MOUNTPT, would therefore be left in an invalid state. Previous changes to conditional logic now allowed setenv() to run and to attempt to set the PATH variable to MOUNTPT, causing a compile time failure like this:
CC: elf_main.c
elf_main.c: In function 'elf_main':
elf_main.c:113:32: error: expected ')' before 'CONFIG_EXAMPLES_ELF_FSTYPE'
# define MOUNTPT "/mnt/" CONFIG_EXAMPLES_ELF_FSTYPE
^~~~~~~~~~~~~~~~~~~~~~~~~~
elf_main.c:364:18: note: in expansion of macro 'MOUNTPT'
setenv("PATH", MOUNTPT, 1);
^~~~~~~
elf_main.c:364:3: error: too few arguments to function 'setenv'
setenv("PATH", MOUNTPT, 1);
^~~~~~
In file included from elf_main.c:47:
D:\Spuda\Documents\projects\nuttx\master\nuttx-fork\include/stdlib.h:158:11: note: declared here
int setenv(FAR const char *name, FAR const char *value, int overwrite);
^~~~~~
This problem was found during manual build testing using configuration lx_cpu:nsh.
2020-02-15 17:14:03 +01:00
|
|
|
# undef MOUNTPT
|
2012-10-26 00:10:56 +02:00
|
|
|
#endif
|
|
|
|
|
2020-04-11 20:56:24 +02:00
|
|
|
/* If CONFIG_DEBUG_FEATURES is enabled, use info/err instead of printf so
|
|
|
|
* that the output will be synchronous with the debug output.
|
2012-10-25 22:06:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_CPP_HAVE_VARARGS
|
2017-10-02 22:32:17 +02:00
|
|
|
# ifdef CONFIG_DEBUG_INFO
|
2018-03-24 18:36:20 +01:00
|
|
|
# define message(format, ...) syslog(LOG_INFO, format, ##__VA_ARGS__)
|
2012-10-25 22:06:46 +02:00
|
|
|
# else
|
2018-03-24 18:36:20 +01:00
|
|
|
# define message(format, ...) printf(format, ##__VA_ARGS__)
|
2017-10-02 22:32:17 +02:00
|
|
|
# endif
|
|
|
|
# ifdef CONFIG_DEBUG_ERROR
|
2018-03-24 18:36:20 +01:00
|
|
|
# define errmsg(format, ...) syslog(LOG_ERR, format, ##__VA_ARGS__)
|
2017-10-02 22:32:17 +02:00
|
|
|
# else
|
2018-03-24 18:36:20 +01:00
|
|
|
# define errmsg(format, ...) fprintf(stderr, format, ##__VA_ARGS__)
|
2012-10-25 22:06:46 +02:00
|
|
|
# endif
|
|
|
|
#else
|
2017-10-02 22:32:17 +02:00
|
|
|
# ifdef CONFIG_DEBUG_INFO
|
2018-03-24 18:36:20 +01:00
|
|
|
# define message _info
|
2012-10-25 22:06:46 +02:00
|
|
|
# else
|
2018-03-24 18:36:20 +01:00
|
|
|
# define message printf
|
2017-10-02 22:32:17 +02:00
|
|
|
# endif
|
|
|
|
# ifdef CONFIG_DEBUG_ERROR
|
2018-03-24 18:36:20 +01:00
|
|
|
# define errmsg _err
|
2017-10-02 22:32:17 +02:00
|
|
|
# else
|
2018-03-24 18:36:20 +01:00
|
|
|
# define errmsg printf
|
2012-10-25 22:06:46 +02:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-10-29 20:32:05 +01:00
|
|
|
static unsigned int g_mminitial; /* Initial memory usage */
|
|
|
|
static unsigned int g_mmstep; /* Memory Usage at beginning of test step */
|
|
|
|
|
2012-10-25 22:06:46 +02:00
|
|
|
static const char delimiter[] =
|
2020-04-11 20:56:24 +02:00
|
|
|
"**************************************"
|
|
|
|
"**************************************";
|
2012-10-25 22:06:46 +02:00
|
|
|
|
2018-11-08 14:31:52 +01:00
|
|
|
#ifndef CONFIG_LIB_ENVPATH
|
2012-12-19 22:16:03 +01:00
|
|
|
static char fullpath[128];
|
|
|
|
#endif
|
2012-10-25 22:06:46 +02:00
|
|
|
|
2012-10-27 02:04:47 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Symbols from Auto-Generated Code
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-07-15 00:36:25 +02:00
|
|
|
extern const struct symtab_s g_elf_exports[];
|
|
|
|
extern const int g_elf_nexports;
|
2012-10-27 02:04:47 +02:00
|
|
|
|
2012-10-25 22:06:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-10-29 20:32:05 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: mm_update
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void mm_update(FAR unsigned int *previous, FAR const char *msg)
|
|
|
|
{
|
|
|
|
struct mallinfo mmcurrent;
|
|
|
|
|
|
|
|
/* Get the current memory usage */
|
|
|
|
|
|
|
|
mmcurrent = mallinfo();
|
|
|
|
|
|
|
|
/* Show the change from the previous time */
|
|
|
|
|
|
|
|
printf("\nMemory Usage %s:\n", msg);
|
|
|
|
printf(" Before: %8u After: %8u Change: %8d\n",
|
2020-04-11 20:56:24 +02:00
|
|
|
*previous, mmcurrent.uordblks,
|
|
|
|
(int)mmcurrent.uordblks - (int)*previous);
|
2012-10-29 20:32:05 +01:00
|
|
|
|
|
|
|
/* Set up for the next test */
|
|
|
|
|
|
|
|
*previous = mmcurrent.uordblks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: mm_initmonitor
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void mm_initmonitor(void)
|
|
|
|
{
|
|
|
|
struct mallinfo mmcurrent;
|
|
|
|
|
|
|
|
mmcurrent = mallinfo();
|
|
|
|
|
|
|
|
g_mminitial = mmcurrent.uordblks;
|
|
|
|
g_mmstep = mmcurrent.uordblks;
|
|
|
|
|
|
|
|
printf("Initial memory usage: %d\n", mmcurrent.uordblks);
|
|
|
|
}
|
|
|
|
|
2012-10-25 22:06:46 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: testheader
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void testheader(FAR const char *progname)
|
|
|
|
{
|
|
|
|
message("\n%s\n* Executing %s\n%s\n\n", delimiter, progname, delimiter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: elf_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-06 17:23:23 +02:00
|
|
|
int main(int argc, FAR char *argv[])
|
2012-10-25 22:06:46 +02:00
|
|
|
{
|
2018-08-05 00:24:02 +02:00
|
|
|
#ifdef CONFIG_EXAMPLES_ELF_FSREMOVEABLE
|
|
|
|
struct stat buf;
|
|
|
|
#endif
|
2017-10-02 22:32:17 +02:00
|
|
|
FAR char *args[1];
|
2012-10-25 22:06:46 +02:00
|
|
|
int ret;
|
|
|
|
int i;
|
|
|
|
|
2017-10-02 22:32:17 +02:00
|
|
|
#if defined(CONFIG_EXAMPLES_ELF_CXXINITIALIZE)
|
2015-05-29 19:47:40 +02:00
|
|
|
/* Call all C++ static constructors */
|
|
|
|
|
|
|
|
up_cxxinitialize();
|
|
|
|
#endif
|
|
|
|
|
2012-10-29 20:32:05 +01:00
|
|
|
/* Initialize the memory monitor */
|
|
|
|
|
|
|
|
mm_initmonitor();
|
|
|
|
|
2018-03-24 18:36:20 +01:00
|
|
|
#if defined(CONFIG_EXAMPLES_ELF_ROMFS)
|
2018-08-04 21:10:40 +02:00
|
|
|
#if defined(CONFIG_BUILD_FLAT)
|
|
|
|
/* This example violates the portable POSIX interface by calling the OS
|
|
|
|
* internal function romdisk_register() (aka ramdisk_register()). We can
|
|
|
|
* squeak by in with this violation in the FLAT build mode, but not in
|
|
|
|
* other build modes. In other build modes, the following logic must be
|
|
|
|
* performed in the OS board initialization logic (where it really belongs
|
|
|
|
* anyway).
|
|
|
|
*/
|
|
|
|
|
2012-10-25 22:06:46 +02:00
|
|
|
/* Create a ROM disk for the ROMFS filesystem */
|
|
|
|
|
2017-10-02 22:32:17 +02:00
|
|
|
message("Registering romdisk at /dev/ram%d\n",
|
|
|
|
CONFIG_EXAMPLES_ELF_DEVMINOR);
|
|
|
|
ret = romdisk_register(CONFIG_EXAMPLES_ELF_DEVMINOR,
|
|
|
|
(FAR uint8_t *)romfs_img,
|
2012-10-26 00:10:56 +02:00
|
|
|
NSECTORS(romfs_img_len), SECTORSIZE);
|
2012-10-25 22:06:46 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: romdisk_register failed: %d\n", ret);
|
2012-10-25 22:06:46 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2012-10-29 20:32:05 +01:00
|
|
|
mm_update(&g_mmstep, "after romdisk_register");
|
2018-08-04 21:10:40 +02:00
|
|
|
#endif
|
2012-10-29 20:32:05 +01:00
|
|
|
|
2018-03-24 18:36:20 +01:00
|
|
|
/* Mount the ROMFS file system */
|
2012-10-25 22:06:46 +02:00
|
|
|
|
|
|
|
message("Mounting ROMFS filesystem at target=%s with source=%s\n",
|
2012-10-26 00:10:56 +02:00
|
|
|
MOUNTPT, CONFIG_EXAMPLES_ELF_DEVPATH);
|
2012-10-25 22:06:46 +02:00
|
|
|
|
2020-04-11 20:56:24 +02:00
|
|
|
ret = mount(CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, "romfs",
|
|
|
|
MS_RDONLY, NULL);
|
2012-10-25 22:06:46 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: mount(%s,%s,romfs) failed: %s\n",
|
|
|
|
CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, errno);
|
2012-10-25 22:06:46 +02:00
|
|
|
}
|
|
|
|
|
2018-03-24 18:36:20 +01:00
|
|
|
#elif defined(CONFIG_EXAMPLES_ELF_CROMFS)
|
|
|
|
/* Mount the CROMFS file system */
|
|
|
|
|
|
|
|
message("Mounting CROMFS filesystem at target=%s\n", MOUNTPT);
|
|
|
|
|
|
|
|
ret = mount(NULL, MOUNTPT, "cromfs", MS_RDONLY, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2018-08-04 21:10:40 +02:00
|
|
|
errmsg("ERROR: mount(%s, cromfs) failed: %d\n", MOUNTPT, errno);
|
|
|
|
}
|
|
|
|
#elif defined(CONFIG_EXAMPLES_ELF_EXTERN)
|
2018-08-05 00:24:02 +02:00
|
|
|
/* An external file system is being used */
|
|
|
|
|
|
|
|
#if defined(CONFIG_EXAMPLES_ELF_FSMOUNT)
|
|
|
|
#if defined(CONFIG_EXAMPLES_ELF_FSREMOVEABLE)
|
|
|
|
/* The file system is removable, wait until the block driver is available */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ret = stat(CONFIG_EXAMPLES_ELF_DEVPATH, &buf);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
int errcode = errno;
|
|
|
|
if (errcode == ENOENT)
|
|
|
|
{
|
|
|
|
printf("%s does not exist. Waiting...\n",
|
|
|
|
CONFIG_EXAMPLES_ELF_DEVPATH);
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("ERROR: stat(%s) failed: %d Aborting...\n",
|
|
|
|
CONFIG_EXAMPLES_ELF_DEVPATH, errcode);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!S_ISBLK(buf.st_mode))
|
|
|
|
{
|
|
|
|
printf("ERROR: stat(%s) exists but is not a block driver: %04x\n",
|
|
|
|
CONFIG_EXAMPLES_ELF_DEVPATH, buf.st_mode);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (ret < 0);
|
|
|
|
#endif
|
|
|
|
|
2018-08-04 21:10:40 +02:00
|
|
|
/* Mount the external file system */
|
|
|
|
|
|
|
|
message("Mounting %s filesystem at target=%s\n",
|
|
|
|
CONFIG_EXAMPLES_ELF_FSTYPE, MOUNTPT);
|
|
|
|
|
|
|
|
ret = mount(CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT,
|
|
|
|
CONFIG_EXAMPLES_ELF_FSTYPE, MS_RDONLY, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2020-04-11 20:56:24 +02:00
|
|
|
errmsg("ERROR: mount(%s, %s, %s) failed: %d\n",
|
2018-08-04 21:10:40 +02:00
|
|
|
CONFIG_EXAMPLES_ELF_DEVPATH, CONFIG_EXAMPLES_ELF_FSTYPE,
|
|
|
|
MOUNTPT, errno);
|
2018-03-24 18:36:20 +01:00
|
|
|
}
|
2018-08-05 00:24:02 +02:00
|
|
|
#endif
|
2018-03-24 18:36:20 +01:00
|
|
|
#else
|
2018-08-04 21:10:40 +02:00
|
|
|
# Warning "No file system selected"
|
2018-03-24 18:36:20 +01:00
|
|
|
#endif
|
|
|
|
|
2012-10-29 20:32:05 +01:00
|
|
|
mm_update(&g_mmstep, "after mount");
|
|
|
|
|
apps/examples/elf: Correct mount point configuration error.
If an external file system is used but is not mounted by the the ELF example, then a compilation error will occur. This configuration problem has existed for a long time but was unmasked by a recent PR. In the failure mode, CONFIG_EXAMPLES_ELF_FSTYPE would not be defined because it depends on CONFIG_EXAMPLES_ELF_FSMOUNT which is not defined. The resulting mountpoint, MOUNTPT, would therefore be left in an invalid state. Previous changes to conditional logic now allowed setenv() to run and to attempt to set the PATH variable to MOUNTPT, causing a compile time failure like this:
CC: elf_main.c
elf_main.c: In function 'elf_main':
elf_main.c:113:32: error: expected ')' before 'CONFIG_EXAMPLES_ELF_FSTYPE'
# define MOUNTPT "/mnt/" CONFIG_EXAMPLES_ELF_FSTYPE
^~~~~~~~~~~~~~~~~~~~~~~~~~
elf_main.c:364:18: note: in expansion of macro 'MOUNTPT'
setenv("PATH", MOUNTPT, 1);
^~~~~~~
elf_main.c:364:3: error: too few arguments to function 'setenv'
setenv("PATH", MOUNTPT, 1);
^~~~~~
In file included from elf_main.c:47:
D:\Spuda\Documents\projects\nuttx\master\nuttx-fork\include/stdlib.h:158:11: note: declared here
int setenv(FAR const char *name, FAR const char *value, int overwrite);
^~~~~~
This problem was found during manual build testing using configuration lx_cpu:nsh.
2020-02-15 17:14:03 +01:00
|
|
|
#if defined(CONFIG_LIB_ENVPATH) && defined(MOUNTPT)
|
2020-02-14 10:23:25 +01:00
|
|
|
/* Does the system support the PATH variable?
|
|
|
|
* If YES, then set the PATH variable to the ROMFS mountpoint.
|
2012-12-19 22:16:03 +01:00
|
|
|
*/
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
setenv("PATH", MOUNTPT, 1);
|
2012-12-19 22:16:03 +01:00
|
|
|
#endif
|
|
|
|
|
2018-03-16 15:51:49 +01:00
|
|
|
/* Now exercise every program in the ROMFS file system */
|
2012-10-25 22:06:46 +02:00
|
|
|
|
|
|
|
for (i = 0; dirlist[i]; i++)
|
|
|
|
{
|
2017-10-02 22:32:17 +02:00
|
|
|
FAR const char *filename;
|
|
|
|
|
2018-03-16 15:51:49 +01:00
|
|
|
/* Output a separator so that we can clearly discriminate the output of
|
2012-12-19 22:16:03 +01:00
|
|
|
* this program from the others.
|
|
|
|
*/
|
|
|
|
|
2012-10-25 22:06:46 +02:00
|
|
|
testheader(dirlist[i]);
|
|
|
|
|
2012-12-19 22:16:03 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2018-11-08 14:31:52 +01:00
|
|
|
#ifdef CONFIG_LIB_ENVPATH
|
2017-10-02 22:32:17 +02:00
|
|
|
filename = dirlist[i];
|
2012-12-19 22:16:03 +01:00
|
|
|
#else
|
|
|
|
snprintf(fullpath, 128, "%s/%s", MOUNTPT, dirlist[i]);
|
2017-10-02 22:32:17 +02:00
|
|
|
filename = fullpath;
|
2012-12-19 22:16:03 +01:00
|
|
|
#endif
|
2012-10-29 20:32:05 +01:00
|
|
|
|
2017-10-06 23:13:00 +02:00
|
|
|
/* Execute the ELF module.
|
|
|
|
*
|
|
|
|
* NOTE: The standard posix_spawn() interface would be more correct.
|
|
|
|
* The non-standard exec() function is used because it provides a
|
|
|
|
* simple way to pass the symbol table information needed to load the
|
|
|
|
* program. posix_spawn(), on the other hand, will assume that symbol
|
|
|
|
* table information is available within the OS.
|
|
|
|
*/
|
2012-12-19 22:16:03 +01:00
|
|
|
|
2017-10-02 22:32:17 +02:00
|
|
|
args[0] = NULL;
|
2018-07-15 00:36:25 +02:00
|
|
|
ret = exec(filename, args, g_elf_exports, g_elf_nexports);
|
2012-10-29 20:32:05 +01:00
|
|
|
|
2017-10-02 22:32:17 +02:00
|
|
|
mm_update(&g_mmstep, "after exec");
|
2012-10-29 20:32:05 +01:00
|
|
|
|
2012-10-25 22:06:46 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-10-02 22:32:17 +02:00
|
|
|
errmsg("ERROR: exec(%s) failed: %d\n", dirlist[i], errno);
|
2012-10-29 20:32:05 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
message("Wait a bit for test completion\n");
|
|
|
|
sleep(4);
|
2012-10-25 22:06:46 +02:00
|
|
|
}
|
|
|
|
|
2017-10-02 22:32:17 +02:00
|
|
|
mm_update(&g_mmstep, "after program execution");
|
2012-10-25 22:06:46 +02:00
|
|
|
}
|
|
|
|
|
2012-10-29 20:32:05 +01:00
|
|
|
mm_update(&g_mmstep, "End-of-Test");
|
2012-10-25 22:06:46 +02:00
|
|
|
return 0;
|
|
|
|
}
|