This commit moves shared builtin information out of binfmt/libbuiltin and into libs/libc/builtin where it can be shared. This should permit builtin application in the PROTECTED build where binfmt/libbuiltin is not available in user space.

Squashed commit of the following:

    Correct some additional compile-related issues.

    Move  include/nuttx/binfmt/builtin.h to include/nuttx/lib/builtin.h.  Move apps/builtin/lib_builtin_forindex.c to libs/libc/builtin/lib_builtin_forindex.c.

    Move binfmt/libbuiltin to libs/libc/builtin.  There are calls made directly from apps/nshlib into this logic and hence, must be part of a library that can be shared between the OS and applications.
This commit is contained in:
Gregory Nutt
2019-08-23 09:07:40 -06:00
parent b3d609959c
commit dd97fb991b
19 changed files with 172 additions and 85 deletions
-20
View File
@@ -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
+7 -2
View File
@@ -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 <gnutt@nuttx.org>
#
@@ -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))
+33
View File
@@ -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)
}
+2 -2
View File
@@ -40,10 +40,10 @@
#include <nuttx/config.h>
#include <nuttx/binfmt/binfmt.h>
#include <nuttx/binfmt/builtin.h>
#include <nuttx/binfmt/elf.h>
#include <nuttx/binfmt/pcode.h>
#include <nuttx/binfmt/nxflat.h>
#include <nuttx/lib/builtin.h>
#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)
{
+3 -7
View File
@@ -51,13 +51,9 @@
#include <nuttx/fs/fs.h>
#include <nuttx/fs/ioctl.h>
#include <nuttx/binfmt/binfmt.h>
#include <nuttx/binfmt/builtin.h>
#include <nuttx/lib/builtin.h>
#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 */
-4
View File
@@ -1,4 +0,0 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
-52
View File
@@ -1,52 +0,0 @@
############################################################################
# binfmt/libbuiltin/Make.defs
#
# Copyright (C) 2013 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# 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.
#
############################################################################
ifeq ($(CONFIG_BUILTIN),y)
# Builtin application interfaces
BINFMT_CSRCS += builtin.c
# Builtin library interfaces
BINFMT_CSRCS += libbuiltin_getname.c libbuiltin_isavail.c
# Hook the libbuiltin subdirectory into the build
VPATH += libbuiltin
SUBDIRS += libbuiltin
DEPPATH += --dep-path libbuiltin
endif
-76
View File
@@ -1,76 +0,0 @@
/****************************************************************************
* binfmt/libbuiltin/libbuiltin_getname.c
*
* Originally by:
*
* Copyright (C) 2011 Uros Platise. All rights reserved.
* Author: Uros Platise <uros.platise@isotel.eu>
*
* With subsequent updates, modifications, and general maintenance by:
*
* Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#include <nuttx/binfmt/builtin.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_getname
*
* Description:
* Return the name of the application at index in the table of builtin
* applications.
*
****************************************************************************/
FAR const char *builtin_getname(int index)
{
FAR const struct builtin_s *builtin;
builtin = builtin_for_index(index);
if (builtin != NULL)
{
return builtin->name;
}
return NULL;
}
-83
View File
@@ -1,83 +0,0 @@
/****************************************************************************
* binfmt/libbuiltin/libbuiltin_isavail.c
*
* Originally by:
*
* Copyright (C) 2011 Uros Platise. All rights reserved.
* Author: Uros Platise <uros.platise@isotel.eu>
*
* With subsequent updates, modifications, and general maintenance by:
*
* Copyright (C) 2012-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <nuttx/binfmt/builtin.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_isavail
*
* Description:
* Return the index into the table of applications for the application with
* the name 'appname'.
*
****************************************************************************/
int builtin_isavail(FAR const char *appname)
{
FAR const char *name;
int i;
for (i = 0; (name = builtin_getname(i)); i++)
{
if (!strncmp(name, appname, NAME_MAX))
{
return i;
}
}
set_errno(ENOENT);
return ERROR;
}