apps/examples/elf: If the test ELF files are on media in removable meda such as SD or USB FLASH, the wait until the media has been installed and initialized before starting the test.

This commit is contained in:
Gregory Nutt 2018-08-04 16:24:02 -06:00
parent ba2d9e7c42
commit 8572f223ae
2 changed files with 53 additions and 3 deletions

View File

@ -32,6 +32,16 @@ config EXAMPLES_ELF_EXTERN
endchoice # ROM File System
config EXAMPLES_ELF_FSMOUNT
bool "Mount external file system"
default y
depends on EXAMPLES_ELF_EXTERN
config EXAMPLES_ELF_FSREMOVEABLE
bool "Removable file system"
default n
depends on EXAMPLES_ELF_FSMOUNT
config EXAMPLES_ELF_DEVMINOR
int "ROMFS Minor Device Number"
default 0
@ -45,7 +55,7 @@ config EXAMPLES_ELF_DEVMINOR
config EXAMPLES_ELF_FSTYPE
string "External file system type"
default "vfat"
depends on EXAMPLES_ELF_EXTERN
depends on EXAMPLES_ELF_FSMOUNT
---help---
The minor device number of the ROMFS block. For example, the N in
/dev/ramN. Used for registering the RAM block driver that will hold
@ -55,8 +65,8 @@ config EXAMPLES_ELF_FSTYPE
config EXAMPLES_ELF_DEVPATH
string "Block driver device path"
default "/dev/ram0" if EXAMPLES_ELF_ROMFS
default "/dev/mmcsd0" if EXAMPLES_ELF_EXTERN
depends on EXAMPLES_ELF_ROMFS || EXAMPLES_ELF_EXTERN
default "/dev/mmcsd0" if EXAMPLES_ELF_FSMOUNT
depends on EXAMPLES_ELF_ROMFS || EXAMPLES_ELF_FSMOUNT
---help---
The path to the ROMFS/External block driver device. This must match
EXAMPLES_ELF_DEVMINOR for the case of ROMFS. Used for mounting the

View File

@ -41,6 +41,7 @@
#include <nuttx/compiler.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
@ -242,6 +243,9 @@ int main(int argc, FAR char *argv[])
int elf_main(int argc, char *argv[])
#endif
{
#ifdef CONFIG_EXAMPLES_ELF_FSREMOVEABLE
struct stat buf;
#endif
FAR char *args[1];
int ret;
int i;
@ -305,6 +309,41 @@ int elf_main(int argc, char *argv[])
errmsg("ERROR: mount(%s, cromfs) failed: %d\n", MOUNTPT, errno);
}
#elif defined(CONFIG_EXAMPLES_ELF_EXTERN)
/* 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
/* Mount the external file system */
message("Mounting %s filesystem at target=%s\n",
@ -318,6 +357,7 @@ int elf_main(int argc, char *argv[])
CONFIG_EXAMPLES_ELF_DEVPATH, CONFIG_EXAMPLES_ELF_FSTYPE,
MOUNTPT, errno);
}
#endif
#else
# Warning "No file system selected"
#endif