From 8572f223aed89a6e44f934cce203598b2aba8849 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 4 Aug 2018 16:24:02 -0600 Subject: [PATCH] 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. --- examples/elf/Kconfig | 16 +++++++++++++--- examples/elf/elf_main.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/examples/elf/Kconfig b/examples/elf/Kconfig index 6a6e649ab..0cbc675ac 100644 --- a/examples/elf/Kconfig +++ b/examples/elf/Kconfig @@ -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 diff --git a/examples/elf/elf_main.c b/examples/elf/elf_main.c index 354589e73..a689de3fd 100644 --- a/examples/elf/elf_main.c +++ b/examples/elf/elf_main.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -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