binfmt: Decouple builtin from binfs file system

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-02-13 20:07:18 +08:00 committed by Alan Carvalho de Assis
parent 4be416a2a8
commit 47e38eb70f
8 changed files with 14 additions and 38 deletions

View File

@ -171,8 +171,7 @@ Symbol Handling
:configuration: This command is always available when :configuration: This command is always available when
CONFIG_BUILTIN is enabled, but does nothing unless CONFIG_BUILTIN is enabled, but does nothing unless
CONFIG_BUILD_PROTECTED and CONFIG_FS_BINFS are also CONFIG_BUILD_PROTECTED is also selected.
selected.
USB USB
--- ---

View File

@ -131,7 +131,7 @@ void binfmt_freeargv(FAR char * const *argv);
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_FS_BINFS #ifdef CONFIG_BUILTIN
int builtin_initialize(void); int builtin_initialize(void);
#endif #endif
@ -146,7 +146,7 @@ int builtin_initialize(void);
* *
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_FS_BINFS #ifdef CONFIG_BUILTIN
void builtin_uninitialize(void); void builtin_uninitialize(void);
#endif #endif

View File

@ -51,7 +51,7 @@ void binfmt_initialize(void)
{ {
int ret; int ret;
#ifdef CONFIG_FS_BINFS #ifdef CONFIG_BUILTIN
ret = builtin_initialize(); ret = builtin_initialize();
if (ret < 0) if (ret < 0)
{ {

View File

@ -24,21 +24,15 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <fcntl.h>
#include <debug.h> #include <debug.h>
#include <errno.h> #include <errno.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/binfmt/binfmt.h> #include <nuttx/binfmt/binfmt.h>
#include <nuttx/lib/builtin.h> #include <nuttx/lib/builtin.h>
#ifdef CONFIG_FS_BINFS #ifdef CONFIG_BUILTIN
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
@ -79,21 +73,10 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
{ {
FAR const struct builtin_s *builtin; FAR const struct builtin_s *builtin;
FAR char *name; FAR char *name;
struct file file;
int index; int index;
int ret;
binfo("Loading file: %s\n", filename); binfo("Loading file: %s\n", filename);
/* Open the binary file for reading (only) */
ret = file_open(&file, filename, O_RDONLY);
if (ret < 0)
{
berr("ERROR: Failed to open binary %s: %d\n", filename, ret);
return ret;
}
name = strrchr(filename, '/'); name = strrchr(filename, '/');
if (name != NULL) if (name != NULL)
{ {
@ -106,7 +89,6 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
if (index < 0) if (index < 0)
{ {
berr("ERROR: %s is not a builtin application\n", filename); berr("ERROR: %s is not a builtin application\n", filename);
file_close(&file);
return index; return index;
} }
@ -118,7 +100,6 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
binp->entrypt = builtin->main; binp->entrypt = builtin->main;
binp->stacksize = builtin->stacksize; binp->stacksize = builtin->stacksize;
binp->priority = builtin->priority; binp->priority = builtin->priority;
file_close(&file);
return OK; return OK;
} }
@ -173,4 +154,4 @@ void builtin_uninitialize(void)
unregister_binfmt(&g_builtin_binfmt); unregister_binfmt(&g_builtin_binfmt);
} }
#endif /* CONFIG_FS_BINFS */ #endif /* CONFIG_BUILTIN */

View File

@ -54,7 +54,7 @@
# include <nuttx/spinlock.h> # include <nuttx/spinlock.h>
#endif #endif
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_FS_BINFS) #if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_BUILTIN)
# include <nuttx/lib/builtin.h> # include <nuttx/lib/builtin.h>
#endif #endif
@ -592,13 +592,13 @@ int boardctl(unsigned int cmd, uintptr_t arg)
* ARG: A pointer to an instance of struct boardioc_builtin_s * ARG: A pointer to an instance of struct boardioc_builtin_s
* CONFIGURATION: This BOARDIOC command is always available when * CONFIGURATION: This BOARDIOC command is always available when
* CONFIG_BUILTIN is enabled, but does nothing unless * CONFIG_BUILTIN is enabled, but does nothing unless
* CONFIG_BUILD_KERNEL and CONFIG_FS_BINFS are selected. * CONFIG_BUILD_KERNEL is selected.
* DEPENDENCIES: None * DEPENDENCIES: None
*/ */
case BOARDIOC_BUILTINS: case BOARDIOC_BUILTINS:
{ {
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_FS_BINFS) #if defined(CONFIG_BUILD_PROTECTED)
FAR const struct boardioc_builtin_s *builtin = FAR const struct boardioc_builtin_s *builtin =
(FAR const struct boardioc_builtin_s *)arg; (FAR const struct boardioc_builtin_s *)arg;

View File

@ -54,8 +54,7 @@ extern "C"
#define EXTERN extern #define EXTERN extern
#endif #endif
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_FS_BINFS) && \ #if defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)
defined(__KERNEL__)
/* In the PROTECTED build, the builtin arrays are only needed by BINFS. /* In the PROTECTED build, the builtin arrays are only needed by BINFS.
* in this case, the user-space globals are not accessible and must be * in this case, the user-space globals are not accessible and must be
* provided to the OS via the boardctl(BOARDIOC_BUILTINS) call. In this * provided to the OS via the boardctl(BOARDIOC_BUILTINS) call. In this
@ -108,8 +107,7 @@ EXTERN const int g_builtin_count;
* *
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_FS_BINFS) && \ #if defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)
defined(__KERNEL__)
void builtin_setlist(FAR const struct builtin_s *builtins, int count); void builtin_setlist(FAR const struct builtin_s *builtins, int count);
#endif #endif

View File

@ -134,8 +134,7 @@
* ARG: A pointer to an instance of struct boardioc_builtin_s * ARG: A pointer to an instance of struct boardioc_builtin_s
* CONFIGURATION: This BOARDIOC command is always available when * CONFIGURATION: This BOARDIOC command is always available when
* CONFIG_BUILTIN is enabled, but does nothing unless * CONFIG_BUILTIN is enabled, but does nothing unless
* CONFIG_BUILD_PROTECTED and CONFIG_FS_BINFS are also * CONFIG_BUILD_PROTECTED is also selected.
* selected.
* DEPENDENCIES: None * DEPENDENCIES: None
* *
* CMD: BOARDIOC_USBDEV_CONTROL * CMD: BOARDIOC_USBDEV_CONTROL

View File

@ -26,8 +26,7 @@
#include <nuttx/lib/builtin.h> #include <nuttx/lib/builtin.h>
#if defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_FS_BINFS) && \ #if defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)
defined(__KERNEL__)
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@ -71,4 +70,4 @@ void builtin_setlist(FAR const struct builtin_s *builtins, int count)
g_builtin_count = count; g_builtin_count = count;
} }
#endif /* CONFIG_BUILD_PROTECTED && CONFIG_FS_BINFS && __KERNEL__ */ #endif /* CONFIG_BUILD_PROTECTED && __KERNEL__ */