diff --git a/Documentation/NuttShell.html b/Documentation/NuttShell.html index a31b286abd..763560dfb5 100644 --- a/Documentation/NuttShell.html +++ b/Documentation/NuttShell.html @@ -4946,7 +4946,7 @@ Builtin Apps:

Built-In Application Utility Functions. - The utility functions exported by the builtin application logic are prototyped in nuttx/include/nuttx/binfmt/builtin.h and apps/include/builtin.h. + The utility functions exported by the builtin application logic are prototyped in nuttx/include/nuttx/lib/builtin.h and apps/include/builtin.h. These utility functions include:

diff --git a/binfmt/Kconfig b/binfmt/Kconfig index f6478209c1..5e9a2865e6 100644 --- a/binfmt/Kconfig +++ b/binfmt/Kconfig @@ -57,26 +57,6 @@ if ELF source binfmt/libelf/Kconfig endif -config BUILTIN - bool "Support Builtin Applications" - default n - depends on (!BUILD_PROTECTED && !BUILD_KERNEL) || EXPERIMENTAL - ---help--- - Enable support for builtin applications. This features assigns a string - name to an application and in addition if FS_BINFS is defined, retaining - those names in a file system from which they can be executed. This feature - is also the underlying requirement to support built-in applications in the - NuttShell (NSH). - - ISSUES: This feature is highly coupled with logic in the apps/ - sub-directory and, as a consequence, cannot be used in environments - that do not include the standard NuttX apps/ nor in build - configurations using BUILD_PROTECTED or BUILD_KERNEL. - -if BUILTIN -source binfmt/libbuiltin/Kconfig -endif - config BINFMT_PCODE bool "Support P-Code Applications" default n diff --git a/binfmt/Makefile b/binfmt/Makefile index e0d6d49776..e9aca9b578 100644 --- a/binfmt/Makefile +++ b/binfmt/Makefile @@ -1,7 +1,7 @@ ############################################################################ # binfmt/Makefile # -# Copyright (C) 2007-2009, 2012-2016, 2018 Gregory Nutt. All rights +# Copyright (C) 2007-2009, 2012-2016, 2018-2019 Gregory Nutt. All rights # reserved. # Author: Gregory Nutt # @@ -57,6 +57,12 @@ ifeq ($(CONFIG_LIBC_EXECFUNCS),y) BINFMT_CSRCS += binfmt_execsymtab.c endif +# Builtin application interfaces + +ifeq ($(CONFIG_BUILTIN),y) +CSRCS += builtin.c +endif + # Add configured binary modules VPATH = @@ -65,7 +71,6 @@ DEPPATH = --dep-path . include libnxflat$(DELIM)Make.defs include libelf$(DELIM)Make.defs -include libbuiltin$(DELIM)Make.defs include libpcode$(DELIM)Make.defs BINFMT_AOBJS = $(BINFMT_ASRCS:.S=$(OBJEXT)) diff --git a/binfmt/binfmt.h b/binfmt/binfmt.h index b4e7ee08ef..be8c1567f1 100644 --- a/binfmt/binfmt.h +++ b/binfmt/binfmt.h @@ -132,6 +132,39 @@ void binfmt_freeargv(FAR struct binary_s *bin); # define binfmt_freeargv(bin) #endif +/**************************************************************************** + * Name: builtin_initialize + * + * Description: + * In order to use the builtin binary format, this function must be called + * during system initialize to register the builtin binary format. + * + * Returned Value: + * This is a NuttX internal function so it follows the convention that + * 0 (OK) is returned on success and a negated errno is returned on + * failure. + * + ****************************************************************************/ + +#if defined(CONFIG_FS_BINFS) && defined(HAVE_BUILTIN_CONTEXT) +int builtin_initialize(void); +#endif + +/**************************************************************************** + * Name: builtin_uninitialize + * + * Description: + * Unregister the builtin binary loader + * + * Returned Value: + * None + * + ****************************************************************************/ + +#if defined(CONFIG_FS_BINFS) && defined(HAVE_BUILTIN_CONTEXT) +void builtin_uninitialize(void); +#endif + #undef EXTERN #if defined(__cplusplus) } diff --git a/binfmt/binfmt_initialize.c b/binfmt/binfmt_initialize.c index 6d50a72954..8f9a8dac5f 100644 --- a/binfmt/binfmt_initialize.c +++ b/binfmt/binfmt_initialize.c @@ -40,10 +40,10 @@ #include #include -#include #include #include #include +#include #ifndef CONFIG_BINFMT_DISABLE @@ -63,7 +63,7 @@ void binfmt_initialize(void) { int ret; -#ifdef CONFIG_FS_BINFS +#if defined(CONFIG_FS_BINFS) && defined(HAVE_BUILTIN_CONTEXT) ret = builtin_initialize(); if (ret < 0) { diff --git a/binfmt/builtin.c b/binfmt/builtin.c index 3b6fa016b0..52eaf534bc 100644 --- a/binfmt/builtin.c +++ b/binfmt/builtin.c @@ -51,13 +51,9 @@ #include #include #include -#include +#include -#ifdef CONFIG_BUILTIN - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ +#ifdef HAVE_BUILTIN_CONTEXT /**************************************************************************** * Private Function Prototypes @@ -197,5 +193,5 @@ void builtin_uninitialize(void) (void)unregister_binfmt(&g_builtin_binfmt); } -#endif /* CONFIG_BUILTIN */ +#endif /* HAVE_BUILTIN_CONTEXT */ diff --git a/binfmt/libbuiltin/Kconfig b/boards/sim/sim/drivers/Kconfig similarity index 100% rename from binfmt/libbuiltin/Kconfig rename to boards/sim/sim/drivers/Kconfig diff --git a/fs/binfs/fs_binfs.c b/fs/binfs/fs_binfs.c index 7e36575935..f31f9b4ec0 100644 --- a/fs/binfs/fs_binfs.c +++ b/fs/binfs/fs_binfs.c @@ -56,7 +56,7 @@ #include #include #include -#include +#include #if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_FS_BINFS) diff --git a/fs/cromfs/fs_cromfs.c b/fs/cromfs/fs_cromfs.c index c2b9c9ae63..d562dcda8c 100644 --- a/fs/cromfs/fs_cromfs.c +++ b/fs/cromfs/fs_cromfs.c @@ -56,7 +56,6 @@ #include #include #include -#include #include "cromfs.h" diff --git a/fs/unionfs/fs_unionfs.c b/fs/unionfs/fs_unionfs.c index d8e5d97092..ad567eba00 100644 --- a/fs/unionfs/fs_unionfs.c +++ b/fs/unionfs/fs_unionfs.c @@ -60,7 +60,6 @@ #include #include #include -#include #include "inode/inode.h" diff --git a/include/nuttx/binfmt/builtin.h b/include/nuttx/lib/builtin.h similarity index 84% rename from include/nuttx/binfmt/builtin.h rename to include/nuttx/lib/builtin.h index 0c17238262..25cad420e5 100644 --- a/include/nuttx/binfmt/builtin.h +++ b/include/nuttx/lib/builtin.h @@ -1,5 +1,5 @@ /**************************************************************************** - * include/nuttx/binfmt/builtin.h + * include/nuttx/lib/builtin.h * * Originally by: * @@ -8,7 +8,7 @@ * * With subsequent updates, modifications, and general maintenance by: * - * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2019 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -40,8 +40,8 @@ * ****************************************************************************/ -#ifndef __INCLUDE_NUTTX_BINFMT_BUILTIN_H -#define __INCLUDE_NUTTX_BINFMT_BUILTIN_H +#ifndef __INCLUDE_NUTTX_LIB_BUILTIN_H +#define __INCLUDE_NUTTX_LIB_BUILTIN_H /**************************************************************************** * Included Files @@ -50,6 +50,21 @@ #include #include +#ifdef CONFIG_BUILTIN + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* This logic is not usable in the KERNEL build and, furthermore, it has no + * meaning in __KERNEL__ blob of a protected build. + */ + +#if (defined(CONFIG_BUILD_FLAT) || \ + (defined(CONFIG_BUILD_PROTECTED )&& !__KERNEL__)) +# define HAVE_BUILTIN_CONTEXT +#endif + /**************************************************************************** * Public Types ****************************************************************************/ @@ -74,39 +89,15 @@ extern "C" #define EXTERN extern #endif +/* These must be provided the application layer */ + +EXTERN const struct builtin_s g_builtins[]; +EXTERN const int g_builtin_count; + /**************************************************************************** * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: builtin_initialize - * - * Description: - * In order to use the builtin binary format, this function must be called - * during system initialize to register the builtin binary format. - * - * Returned Value: - * This is a NuttX internal function so it follows the convention that - * 0 (OK) is returned on success and a negated errno is returned on - * failure. - * - ****************************************************************************/ - -int builtin_initialize(void); - -/**************************************************************************** - * Name: builtin_uninitialize - * - * Description: - * Unregister the builtin binary loader - * - * Returned Value: - * None - * - ****************************************************************************/ - -void builtin_uninitialize(void); - /**************************************************************************** * Name: builtin_isavail * @@ -168,4 +159,5 @@ FAR const struct builtin_s *builtin_for_index(int index); } #endif -#endif /* __INCLUDE_NUTTX_BINFMT_BUILTIN_H */ +#endif /* CONFIG_BUILTIN */ +#endif /* __INCLUDE_NUTTX_LIB_BUILTIN_H */ diff --git a/libs/libc/Kconfig b/libs/libc/Kconfig index 402a23e459..003a4e1099 100644 --- a/libs/libc/Kconfig +++ b/libs/libc/Kconfig @@ -27,3 +27,4 @@ source libs/libc/misc/Kconfig source libs/libc/wqueue/Kconfig source libs/libc/hex2bin/Kconfig source libs/libc/userfs/Kconfig +source libs/libc/builtins/Kconfig diff --git a/libs/libc/Makefile b/libs/libc/Makefile index db1bcaf585..0f1560541d 100644 --- a/libs/libc/Makefile +++ b/libs/libc/Makefile @@ -1,7 +1,7 @@ ############################################################################ # libs/libc/Makefile # -# Copyright (C) 2007-2014, 2016-2017 Gregory Nutt. All rights reserved. +# Copyright (C) 2007-2014, 2016-2017, 2019 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -55,6 +55,7 @@ VPATH := . include aio/Make.defs include audio/Make.defs +include builtin/Make.defs include dirent/Make.defs include dlfcn/Make.defs include endian/Make.defs diff --git a/libs/libc/README.txt b/libs/libc/README.txt index e09a876deb..ad0655ec7d 100644 --- a/libs/libc/README.txt +++ b/libs/libc/README.txt @@ -29,6 +29,7 @@ in the include/ directory provides the prototype for library functions. So we have: audio - This part of the audio system: nuttx/audio/audio.h + builtin - Support for builtin applications. Used by nuttx/binfmt and NSH. dlfcn - dlfcn.h endian - endian.h hex2bin - hex2bin.h diff --git a/libs/libc/builtin/Kconfig b/libs/libc/builtin/Kconfig new file mode 100644 index 0000000000..b2939a6106 --- /dev/null +++ b/libs/libc/builtin/Kconfig @@ -0,0 +1,15 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +config BUILTIN + bool "Support Builtin Applications" + default n + depends on !BUILD_KERNEL || EXPERIMENTAL + ---help--- + Enable support for builtin applications. This features assigns a string + name to an application and in addition if FS_BINFS is defined, retaining + those names in a file system from which they can be executed. This feature + is also the underlying requirement to support built-in applications in the + NuttShell (NSH). diff --git a/binfmt/libbuiltin/Make.defs b/libs/libc/builtin/Make.defs similarity index 86% rename from binfmt/libbuiltin/Make.defs rename to libs/libc/builtin/Make.defs index 5eec1acde4..6e2528d73d 100644 --- a/binfmt/libbuiltin/Make.defs +++ b/libs/libc/builtin/Make.defs @@ -35,18 +35,13 @@ ifeq ($(CONFIG_BUILTIN),y) -# Builtin application interfaces +# Builtin library files -BINFMT_CSRCS += builtin.c +CSRCS += lib_builtin_getname.c lib_builtin_isavail.c lib_builtin_forindex.c -# Builtin library interfaces +# Hook the builtin subdirectory into the build -BINFMT_CSRCS += libbuiltin_getname.c libbuiltin_isavail.c - -# Hook the libbuiltin subdirectory into the build - -VPATH += libbuiltin -SUBDIRS += libbuiltin -DEPPATH += --dep-path libbuiltin +DEPPATH += --dep-path builtin +VPATH += builtin endif diff --git a/libs/libc/builtin/lib_builtin_forindex.c b/libs/libc/builtin/lib_builtin_forindex.c new file mode 100644 index 0000000000..80409ca903 --- /dev/null +++ b/libs/libc/builtin/lib_builtin_forindex.c @@ -0,0 +1,62 @@ +/**************************************************************************** + * libs/libc/builtin/lib_builtin_forindex.c + * + * Copyright (C) 2011 Uros Platise. All rights reserved. + * Copyright (C) 2011, 2016, 2019 Gregory Nutt. All rights reserved. + * Authors: Uros Platise + * Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#ifdef HAVE_BUILTIN_CONTEXT + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +FAR const struct builtin_s *builtin_for_index(int index) +{ + if (index < g_builtin_count) + { + return &g_builtins[index]; + } + + return NULL; +} + +#endif /* HAVE_BUILTIN_CONTEXT */ diff --git a/binfmt/libbuiltin/libbuiltin_getname.c b/libs/libc/builtin/lib_builtin_getname.c similarity index 93% rename from binfmt/libbuiltin/libbuiltin_getname.c rename to libs/libc/builtin/lib_builtin_getname.c index 8ca6c24452..5b10ca1e98 100644 --- a/binfmt/libbuiltin/libbuiltin_getname.c +++ b/libs/libc/builtin/lib_builtin_getname.c @@ -1,5 +1,5 @@ /**************************************************************************** - * binfmt/libbuiltin/libbuiltin_getname.c + * libs/libc/builtin/libbuiltin_getname.c * * Originally by: * @@ -8,7 +8,7 @@ * * With subsequent updates, modifications, and general maintenance by: * - * Copyright (C) 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2012-2013, 2019 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -46,7 +46,9 @@ #include -#include +#include + +#ifdef HAVE_BUILTIN_CONTEXT /**************************************************************************** * Public Functions @@ -74,3 +76,5 @@ FAR const char *builtin_getname(int index) return NULL; } + +#endif /* HAVE_BUILTIN_CONTEXT */ diff --git a/binfmt/libbuiltin/libbuiltin_isavail.c b/libs/libc/builtin/lib_builtin_isavail.c similarity index 95% rename from binfmt/libbuiltin/libbuiltin_isavail.c rename to libs/libc/builtin/lib_builtin_isavail.c index 8deefa63e9..29c4ae065a 100644 --- a/binfmt/libbuiltin/libbuiltin_isavail.c +++ b/libs/libc/builtin/lib_builtin_isavail.c @@ -1,5 +1,5 @@ /**************************************************************************** - * binfmt/libbuiltin/libbuiltin_isavail.c + * libs/libc/builtin/lib_builtin_isavail.c * * Originally by: * @@ -50,7 +50,9 @@ #include #include -#include +#include + +#ifdef HAVE_BUILTIN_CONTEXT /**************************************************************************** * Public Functions @@ -81,3 +83,5 @@ int builtin_isavail(FAR const char *appname) set_errno(ENOENT); return ERROR; } + +#endif /* HAVE_BUILTIN_CONTEXT */