2011-03-20 19:18:19 +01:00
|
|
|
/****************************************************************************
|
2021-05-14 06:37:30 +02:00
|
|
|
* apps/examples/nxflat/nxflat_main.c
|
2011-03-20 19:18:19 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +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
|
2011-03-20 19:18:19 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-03-20 19:18:19 +01:00
|
|
|
*
|
2021-06-15 09:09:58 +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.
|
2011-03-20 19:18:19 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <nuttx/compiler.h>
|
|
|
|
|
|
|
|
#include <sys/mount.h>
|
2021-05-14 06:37:30 +02:00
|
|
|
#include <sys/boardctl.h>
|
2011-03-20 19:18:19 +01: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-24 22:19:44 +02:00
|
|
|
#include <nuttx/binfmt/binfmt.h>
|
2011-03-20 19:18:19 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-10-02 22:06:11 +02:00
|
|
|
* Pre-processor Definitions
|
2011-03-20 19:18:19 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Check configuration. This is not all of the configuration settings that
|
|
|
|
* are required -- only the more obvious.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_NXFLAT
|
|
|
|
# error "You must select CONFIG_NXFLAT in your configuration file"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef CONFIG_FS_ROMFS
|
|
|
|
# error "You must select CONFIG_FS_ROMFS in your configuration file"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_DISABLE_MOUNTPOINT
|
|
|
|
# error "You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT in your configuration file"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_BINFMT_DISABLE
|
|
|
|
# error "You must not disable loadable modules via CONFIG_BINFMT_DISABLE in your configuration file"
|
|
|
|
#endif
|
|
|
|
|
2021-05-20 01:42:28 +02:00
|
|
|
#ifndef CONFIG_BOARDCTL_ROMDISK
|
|
|
|
# error "CONFIG_BOARDCTL_ROMDISK should be enabled in the configuration file"
|
|
|
|
#endif
|
2011-03-20 19:18:19 +01:00
|
|
|
/* Describe the ROMFS file system */
|
|
|
|
|
|
|
|
#define SECTORSIZE 512
|
|
|
|
#define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
|
|
|
|
#define ROMFSDEV "/dev/ram0"
|
|
|
|
#define MOUNTPT "/mnt/romfs"
|
|
|
|
|
2017-10-02 22:32:17 +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.
|
2011-03-20 19:18:19 +01:00
|
|
|
*/
|
|
|
|
|
2020-05-04 12:52:59 +02:00
|
|
|
#ifdef CONFIG_DEBUG_INFO
|
|
|
|
# define message _info
|
2011-03-20 19:18:19 +01:00
|
|
|
#else
|
2020-05-04 12:52:59 +02:00
|
|
|
# define message printf
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_DEBUG_ERROR
|
|
|
|
# define errmsg _err
|
|
|
|
#else
|
|
|
|
# define errmsg printf
|
2011-03-20 19:18:19 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static const char delimiter[] =
|
2020-05-05 21:03:56 +02:00
|
|
|
"**************************************"
|
|
|
|
"**************************************";
|
2011-03-20 19:18:19 +01:00
|
|
|
|
2021-08-01 09:28:27 +02:00
|
|
|
#ifndef CONFIG_LIBC_ENVPATH
|
2012-12-19 22:16:03 +01:00
|
|
|
static char fullpath[128];
|
|
|
|
#endif
|
2011-03-20 19:18:19 +01:00
|
|
|
|
2020-05-14 05:32:35 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Symbols from Auto-Generated Code
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
extern const unsigned char romfs_img[];
|
|
|
|
extern const unsigned int romfs_img_len;
|
|
|
|
|
|
|
|
extern const char *dirlist[];
|
|
|
|
|
|
|
|
extern const struct symtab_s g_nxflat_exports[];
|
|
|
|
extern const int g_nxflat_nexports;
|
|
|
|
|
2011-03-20 19:18:19 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-08-30 22:13:50 +02:00
|
|
|
* Name: nxflat_main
|
2011-03-20 19:18:19 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-09-06 17:23:23 +02:00
|
|
|
int main(int argc, FAR char *argv[])
|
2011-03-20 19:18:19 +01:00
|
|
|
{
|
2021-06-15 20:55:57 +02:00
|
|
|
FAR char *args[2];
|
2011-03-20 19:18:19 +01:00
|
|
|
int ret;
|
|
|
|
int i;
|
2021-05-14 06:37:30 +02:00
|
|
|
struct boardioc_romdisk_s desc;
|
2011-03-20 19:18:19 +01:00
|
|
|
|
|
|
|
/* Create a ROM disk for the ROMFS filesystem */
|
|
|
|
|
|
|
|
message("Registering romdisk\n");
|
2021-05-14 06:37:30 +02:00
|
|
|
|
|
|
|
desc.minor = 0; /* Minor device number of the ROM disk. */
|
|
|
|
desc.nsectors = NSECTORS(romfs_img_len); /* The number of sectors in the ROM disk */
|
|
|
|
desc.sectsize = SECTORSIZE; /* The size of one sector in bytes */
|
|
|
|
desc.image = (FAR uint8_t *)romfs_img; /* File system image */
|
|
|
|
|
|
|
|
ret = boardctl(BOARDIOC_ROMDISK, (uintptr_t)&desc);
|
2011-03-20 19:18:19 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 22:49:55 +02:00
|
|
|
errmsg("ERROR: romdisk_register failed: %d\n", ret);
|
2011-03-20 19:18:19 +01:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Mount the file system */
|
|
|
|
|
|
|
|
message("Mounting ROMFS filesystem at target=%s with source=%s\n",
|
|
|
|
MOUNTPT, ROMFSDEV);
|
|
|
|
|
|
|
|
ret = mount(ROMFSDEV, MOUNTPT, "romfs", MS_RDONLY, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2021-05-14 06:37:30 +02:00
|
|
|
errmsg("ERROR: mount(%s,%s,romfs) failed: %d\n",
|
2016-06-11 22:49:55 +02:00
|
|
|
ROMFSDEV, MOUNTPT, errno);
|
2011-03-20 19:18:19 +01:00
|
|
|
}
|
|
|
|
|
2021-08-01 09:28:27 +02:00
|
|
|
#if defined(CONFIG_LIBC_ENVPATH) && !defined(CONFIG_PATH_INITIAL)
|
2012-12-19 22:16:03 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
setenv("PATH", MOUNTPT, 1);
|
2012-12-19 22:16:03 +01:00
|
|
|
#endif
|
|
|
|
|
2020-02-22 19:52:12 +01:00
|
|
|
/* Now exercise every progrm in the ROMFS file system */
|
2011-03-20 19:18:19 +01:00
|
|
|
|
|
|
|
for (i = 0; dirlist[i]; i++)
|
|
|
|
{
|
2017-10-02 22:32:17 +02:00
|
|
|
FAR const char *filename;
|
|
|
|
|
2020-02-22 19:52:12 +01:00
|
|
|
/* Output a separated so that we can clearly discrinmate the output of
|
2012-12-19 22:16:03 +01:00
|
|
|
* this program from the others.
|
|
|
|
*/
|
|
|
|
|
2011-03-20 19:18:19 +01: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.
|
|
|
|
*/
|
|
|
|
|
2021-08-01 09:28:27 +02:00
|
|
|
#ifdef CONFIG_LIBC_ENVPATH
|
2017-10-02 22:32:17 +02:00
|
|
|
filename = dirlist[i];
|
2012-12-19 22:16:03 +01:00
|
|
|
#else
|
2023-03-20 09:46:48 +01:00
|
|
|
snprintf(fullpath, sizeof(fullpath), "%s/%s", MOUNTPT, dirlist[i]);
|
2017-10-02 22:32:17 +02:00
|
|
|
filename = fullpath;
|
2012-12-19 22:16:03 +01:00
|
|
|
#endif
|
2011-03-20 19:18:19 +01:00
|
|
|
|
2017-10-06 23:13:00 +02:00
|
|
|
/* Execute the NXFLAT 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
|
|
|
|
2021-06-15 20:55:57 +02:00
|
|
|
args[0] = (FAR char *)dirlist[i];
|
|
|
|
args[1] = NULL;
|
2022-04-21 05:55:35 +02:00
|
|
|
ret = exec(filename, args, NULL, g_nxflat_exports, g_nxflat_nexports);
|
2011-03-20 19:18:19 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-10-02 22:32:17 +02:00
|
|
|
errmsg("ERROR: exec(%s) failed: %d\n", dirlist[i], errno);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
message("Wait a bit for test completion\n");
|
|
|
|
sleep(4);
|
2011-03-20 19:18:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
message("End-of-Test.. Exit-ing\n");
|
|
|
|
return 0;
|
|
|
|
}
|