binfmt: Add binfmt_initialize(). All binary formats are now registered centrally vs. in board-specific logic. This simplifies the usage of the binfmt subsystem.

This commit is contained in:
Xiang Xiao 2018-08-23 09:09:39 -06:00 committed by Gregory Nutt
parent 0001607f71
commit 377eb30129
23 changed files with 19 additions and 279 deletions

View file

@ -607,39 +607,6 @@ cat ../syscall/syscall.csv ../libc/libc.csv | sort >tmp.csv
</ul> </ul>
</ul> </ul>
<p><b>NXFLAT Initialization</b>
These interfaces are specific to NXFLAT.
Normally, an application needs only call <code>nxflat_initialize()</code> during its initialization
to have full NXFLAT support.
</p>
<ul>
<p><b><code>int nxflat_initialize(void)</code></b>
<ul>
<p><b>Description:</b>
NXFLAT support is built unconditionally. However, it order to
use this binary format, this function must be called during system
format in order to register the NXFLAT binary format.
This function calls <code>register_binfmt()</code> appropriately.
</p>
<p><b>Returned Value:</b>
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.
</p>
</ul>
<p><b><code>void nxflat_uninitialize(void)</code></b>
<ul>
<p><b>Description:</b>
Unregister the NXFLAT binary loader
</p>
<p><b>Returned Value:</b>
None
</p>
</ul>
</ul>
<p><b>Binary Loader Interfaces</b>. <p><b>Binary Loader Interfaces</b>.
The remaining APIs are called by user applications to maintain modules in the file system. The remaining APIs are called by user applications to maintain modules in the file system.
</p> </p>

View file

@ -45,7 +45,7 @@ CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(TOPDIR)$(DELIM)sched"}
# Basic BINFMT source files # Basic BINFMT source files
BINFMT_ASRCS = BINFMT_ASRCS =
BINFMT_CSRCS = binfmt_globals.c binfmt_register.c binfmt_unregister.c BINFMT_CSRCS = binfmt_globals.c binfmt_initialize.c binfmt_register.c binfmt_unregister.c
BINFMT_CSRCS += binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c BINFMT_CSRCS += binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c
BINFMT_CSRCS += binfmt_exec.c binfmt_copyargv.c binfmt_dumpmodule.c BINFMT_CSRCS += binfmt_exec.c binfmt_copyargv.c binfmt_dumpmodule.c

View file

@ -47,10 +47,6 @@
#include <nuttx/spi/spi.h> #include <nuttx/spi/spi.h>
#include <nuttx/mmcsd.h> #include <nuttx/mmcsd.h>
#ifdef CONFIG_NXFLAT
# include <nuttx/binfmt/nxflat.h>
#endif
#include "tiva_ssi.h" #include "tiva_ssi.h"
/**************************************************************************** /****************************************************************************
@ -129,18 +125,6 @@ int board_app_initialize(uintptr_t arg)
FAR struct spi_dev_s *spi; FAR struct spi_dev_s *spi;
int ret; int ret;
#ifdef CONFIG_NXFLAT
/* Initialize the NXFLAT binary loader */
ret = nxflat_initialize();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Initialization of the NXFLAT loader failed: %d\n",
ret);
}
#endif
/* Get the SPI port */ /* Get the SPI port */
syslog(LOG_INFO, "Initializing SPI port %d\n", syslog(LOG_INFO, "Initializing SPI port %d\n",

View file

@ -51,10 +51,6 @@
#include <nuttx/sched.h> #include <nuttx/sched.h>
#ifdef CONFIG_ELF
# include <nuttx/binfmt/elf.h>
#endif
#ifdef CONFIG_RNDIS #ifdef CONFIG_RNDIS
# include <nuttx/usb/rndis.h> # include <nuttx/usb/rndis.h>
#endif #endif
@ -120,16 +116,6 @@ int lc823450_bringup(void)
lc823450_wm8776initialize(0); lc823450_wm8776initialize(0);
#endif #endif
#ifdef CONFIG_ELF
/* Initialize the ELF binary loader */
ret = elf_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Failed to initialize the ELF loader: %d\n", ret);
}
#endif
#if defined(CONFIG_RNDIS) && defined(CONFIG_NSH_MACADDR) #if defined(CONFIG_RNDIS) && defined(CONFIG_NSH_MACADDR)
uint8_t mac[6]; uint8_t mac[6];
mac[0] = 0xaa; /* TODO */ mac[0] = 0xaa; /* TODO */

View file

@ -47,10 +47,6 @@
#include <nuttx/spi/spi.h> #include <nuttx/spi/spi.h>
#include <nuttx/mmcsd.h> #include <nuttx/mmcsd.h>
#ifdef CONFIG_FS_BINFS
# include <nuttx/binfmt/builtin.h>
#endif
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -65,7 +61,7 @@
* arg - The boardctl() argument is passed to the board_app_initialize() * arg - The boardctl() argument is passed to the board_app_initialize()
* implementation without modification. The argument has no * implementation without modification. The argument has no
* meaning to NuttX; the meaning of the argument is a contract * meaning to NuttX; the meaning of the argument is a contract
* between the board-specific initalization logic and the * between the board-specific initialization logic and the
* matching application logic. The value cold be such things as a * matching application logic. The value cold be such things as a
* mode enumeration value, a set of DIP switch switch settings, a * mode enumeration value, a set of DIP switch switch settings, a
* pointer to configuration data read from a file or serial FLASH, * pointer to configuration data read from a file or serial FLASH,
@ -80,17 +76,5 @@
int board_app_initialize(uintptr_t arg) int board_app_initialize(uintptr_t arg)
{ {
#ifdef CONFIG_FS_BINFS
/* Initialize the BINFS binary loader */
int ret = builtin_initialize();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Initialization of the Built-In loader failed: %d\n",
ret);
}
#endif
return OK; return OK;
} }

View file

@ -47,10 +47,6 @@
#include <nuttx/spi/spi.h> #include <nuttx/spi/spi.h>
#include <nuttx/mmcsd.h> #include <nuttx/mmcsd.h>
#ifdef CONFIG_NXFLAT
# include <nuttx/binfmt/nxflat.h>
#endif
#include "lpc17_ssp.h" #include "lpc17_ssp.h"
/**************************************************************************** /****************************************************************************
@ -148,18 +144,6 @@ int board_app_initialize(uintptr_t arg)
#endif #endif
int ret; int ret;
#ifdef CONFIG_NXFLAT
/* Initialize the NXFLAT binary loader */
ret = nxflat_initialize();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Initialization of the NXFLAT loader failed: %d\n",
ret);
}
#endif
#ifdef NSH_HAVEMMCSD #ifdef NSH_HAVEMMCSD
/* Get the SSP port */ /* Get the SSP port */

View file

@ -69,10 +69,6 @@
# include <nuttx/audio/audio.h> # include <nuttx/audio/audio.h>
#endif #endif
#if defined(CONFIG_FS_BINFS) && (CONFIG_BUILTIN)
# include <nuttx/binfmt/builtin.h>
#endif
#ifdef CONFIG_STM32_OTGFS #ifdef CONFIG_STM32_OTGFS
# include "stm32_usbhost.h" # include "stm32_usbhost.h"
#endif #endif
@ -186,17 +182,6 @@ int board_app_initialize(uintptr_t arg)
#endif #endif
int ret = OK; int ret = OK;
#if defined(CONFIG_FS_BINFS) && defined(CONFIG_BUILTIN)
/* Register the BINFS file system */
ret = builtin_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: builtin_initialize failed: %d\n", ret);
return ret;
}
#endif
/* Configure SPI-based devices */ /* Configure SPI-based devices */
#ifdef CONFIG_STM32_SPI3 #ifdef CONFIG_STM32_SPI3

View file

@ -47,10 +47,6 @@
#include <nuttx/board.h> #include <nuttx/board.h>
#include <nuttx/net/ftmac100.h> #include <nuttx/net/ftmac100.h>
#if defined(CONFIG_FS_BINFS) && defined(CONFIG_BUILTIN)
# include <nuttx/binfmt/builtin.h>
#endif
#include <arch/board/board.h> #include <arch/board/board.h>
/**************************************************************************** /****************************************************************************
@ -94,16 +90,6 @@
int board_app_initialize(uintptr_t arg) int board_app_initialize(uintptr_t arg)
{ {
#ifndef CONFIG_BOARD_INITIALIZE #ifndef CONFIG_BOARD_INITIALIZE
#if defined(CONFIG_FS_BINFS) && (CONFIG_BUILTIN)
/* Register the BINFS file system */
int ret = builtin_initialize();
if (ret < 0)
{
fprintf(stderr, "ERROR: builtin_initialize failed: %d\n", ret);
}
#endif
#ifdef CONFIG_NET_FTMAC100 #ifdef CONFIG_NET_FTMAC100
/* Perform board-specific initialization */ /* Perform board-specific initialization */

View file

@ -73,16 +73,6 @@
#ifdef CONFIG_BOARD_INITIALIZE #ifdef CONFIG_BOARD_INITIALIZE
void board_initialize(void) void board_initialize(void)
{ {
#if defined(CONFIG_FS_BINFS) && (CONFIG_BUILTIN)
/* Register the BINFS file system */
int ret = builtin_initialize();
if (ret < 0)
{
fprintf(stderr, "ERROR: builtin_initialize failed: %d\n", ret);
}
#endif
#ifdef CONFIG_NET_FTMAC100 #ifdef CONFIG_NET_FTMAC100
/* Perform board-specific initialization */ /* Perform board-specific initialization */

View file

@ -51,10 +51,6 @@
#include <nuttx/mmcsd.h> #include <nuttx/mmcsd.h>
#include <nuttx/usb/usbhost.h> #include <nuttx/usb/usbhost.h>
#ifdef CONFIG_NXFLAT
# include <nuttx/binfmt/nxflat.h>
#endif
#include "lpc17_ssp.h" #include "lpc17_ssp.h"
#include "lpc17_gpio.h" #include "lpc17_gpio.h"
#include "lpc17_usbhost.h" #include "lpc17_usbhost.h"
@ -351,18 +347,6 @@ int board_app_initialize(uintptr_t arg)
{ {
int ret; int ret;
#ifdef CONFIG_NXFLAT
/* Initialize the NXFLAT binary loader */
ret = nxflat_initialize();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Initialization of the NXFLAT loader failed: %d\n",
ret);
}
#endif
/* Initialize SPI-based microSD */ /* Initialize SPI-based microSD */
ret = nsh_sdinitialize(); ret = nsh_sdinitialize();

View file

@ -58,7 +58,6 @@
#define HAVE_USBMONITOR 1 #define HAVE_USBMONITOR 1
#define HAVE_SDIO 1 #define HAVE_SDIO 1
#define HAVE_RTC_DRIVER 1 #define HAVE_RTC_DRIVER 1
#define HAVE_ELF 1
#define HAVE_NETMONITOR 1 #define HAVE_NETMONITOR 1
/* Can't support USB host or device features if USB OTG FS is not enabled */ /* Can't support USB host or device features if USB OTG FS is not enabled */
@ -88,12 +87,6 @@
# undef HAVE_USBMONITOR # undef HAVE_USBMONITOR
#endif #endif
/* ELF */
#if defined(CONFIG_BINFMT_DISABLE) || !defined(CONFIG_ELF)
# undef HAVE_ELF
#endif
/* NSH Network monitor */ /* NSH Network monitor */
#if !defined(CONFIG_NET) || !defined(CONFIG_STM32_EMACMAC) #if !defined(CONFIG_NET) || !defined(CONFIG_STM32_EMACMAC)

View file

@ -48,7 +48,6 @@
#include <nuttx/board.h> #include <nuttx/board.h>
#include <nuttx/mmcsd.h> #include <nuttx/mmcsd.h>
#include <nuttx/input/buttons.h> #include <nuttx/input/buttons.h>
#include <nuttx/binfmt/elf.h>
#ifdef CONFIG_USBMONITOR #ifdef CONFIG_USBMONITOR
# include <nuttx/usb/usbmonitor.h> # include <nuttx/usb/usbmonitor.h>
@ -116,17 +115,6 @@ int stm32_bringup(void)
modlib_setsymtab(MODSYMS_SYMTAB_ARRAY, MODSYMS_NSYMBOLS_VAR); modlib_setsymtab(MODSYMS_SYMTAB_ARRAY, MODSYMS_NSYMBOLS_VAR);
#endif #endif
#ifdef HAVE_ELF
/* Initialize the ELF binary loader */
ret = elf_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Initialization of the ELF loader failed: %d\n",
ret);
}
#endif
#ifdef HAVE_MMCSD #ifdef HAVE_MMCSD
/* Mount the SDIO-based MMC/SD block driver */ /* Mount the SDIO-based MMC/SD block driver */
/* First, get an instance of the SDIO interface */ /* First, get an instance of the SDIO interface */

View file

@ -51,7 +51,6 @@
#endif #endif
#include <nuttx/drivers/ramdisk.h> #include <nuttx/drivers/ramdisk.h>
#include <nuttx/binfmt/elf.h>
#include <nuttx/i2c/i2c_master.h> #include <nuttx/i2c/i2c_master.h>
#include "sam_twi.h" #include "sam_twi.h"
@ -338,17 +337,6 @@ int sam_bringup(void)
} }
#endif #endif
#ifdef HAVE_ELF
/* Initialize the ELF binary loader */
_err("Initializing the ELF binary loader\n");
ret = elf_initialize();
if (ret < 0)
{
_err("ERROR: Initialization of the ELF loader failed: %d\n", ret);
}
#endif
#ifdef CONFIG_FS_PROCFS #ifdef CONFIG_FS_PROCFS
/* Mount the procfs file system */ /* Mount the procfs file system */

View file

@ -69,7 +69,6 @@
#define HAVE_WM8904 1 #define HAVE_WM8904 1
#define HAVE_AUDIO_NULL 1 #define HAVE_AUDIO_NULL 1
#define HAVE_PMIC 1 #define HAVE_PMIC 1
#define HAVE_ELF 1
#define HAVE_ROMFS 1 #define HAVE_ROMFS 1
#define HAVE_I2CTOOL 1 #define HAVE_I2CTOOL 1
@ -463,12 +462,6 @@
# undef HAVE_PMIC /* REVISIT: Disable anyway because it does not yet work */ # undef HAVE_PMIC /* REVISIT: Disable anyway because it does not yet work */
#endif #endif
/* ELF */
#if defined(CONFIG_BINFMT_DISABLE) || !defined(CONFIG_ELF)
# undef HAVE_ELF
#endif
/* ROMFS */ /* ROMFS */
#ifndef CONFIG_FS_ROMFS #ifndef CONFIG_FS_ROMFS

View file

@ -54,7 +54,6 @@
#include <nuttx/drivers/drivers.h> #include <nuttx/drivers/drivers.h>
#include <nuttx/drivers/ramdisk.h> #include <nuttx/drivers/ramdisk.h>
#include <nuttx/fs/nxffs.h> #include <nuttx/fs/nxffs.h>
#include <nuttx/binfmt/elf.h>
#include <nuttx/i2c/i2c_master.h> #include <nuttx/i2c/i2c_master.h>
#include "sam_twihs.h" #include "sam_twihs.h"
@ -349,16 +348,6 @@ int sam_bringup(void)
} }
#endif #endif
#ifdef HAVE_ELF
/* Initialize the ELF binary loader */
ret = elf_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: Initialization of the ELF loader failed: %d\n", ret);
}
#endif
#if defined(CONFIG_SAMV7_DAC0) || defined(CONFIG_SAMV7_DAC1) #if defined(CONFIG_SAMV7_DAC0) || defined(CONFIG_SAMV7_DAC1)
ret = sam_dacdev_initialize(); ret = sam_dacdev_initialize();
if (ret < 0) if (ret < 0)

View file

@ -54,7 +54,6 @@
#include <nuttx/drivers/drivers.h> #include <nuttx/drivers/drivers.h>
#include <nuttx/drivers/ramdisk.h> #include <nuttx/drivers/ramdisk.h>
#include <nuttx/fs/nxffs.h> #include <nuttx/fs/nxffs.h>
#include <nuttx/binfmt/elf.h>
#include <nuttx/i2c/i2c_master.h> #include <nuttx/i2c/i2c_master.h>
#include <nuttx/video/fb.h> #include <nuttx/video/fb.h>
@ -550,18 +549,6 @@ int sam_bringup(void)
} }
#endif #endif
#ifdef HAVE_ELF
/* Initialize the ELF binary loader */
ret = elf_initialize();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Initialization of the ELF loader failed: %d\n",
ret);
}
#endif
#ifdef CONFIG_VIDEO_FB #ifdef CONFIG_VIDEO_FB
/* Initialize and register the LCD framebuffer driver */ /* Initialize and register the LCD framebuffer driver */

View file

@ -46,10 +46,6 @@
#include <nuttx/board.h> #include <nuttx/board.h>
#ifdef CONFIG_NXFLAT
# include <nuttx/binfmt/nxflat.h>
#endif
#include "stm32.h" #include "stm32.h"
#include "shenzhou.h" #include "shenzhou.h"
@ -171,18 +167,6 @@ int board_app_initialize(uintptr_t arg)
{ {
int ret; int ret;
#ifdef CONFIG_NXFLAT
/* Initialize the NXFLAT binary loader */
ret = nxflat_initialize();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Initialization of the NXFLAT loader failed: %d\n",
ret);
}
#endif
#ifdef HAVE_W25 #ifdef HAVE_W25
/* Initialize and register the W25 FLASH file system. */ /* Initialize and register the W25 FLASH file system. */

View file

@ -56,10 +56,6 @@
#include <nuttx/wireless/bluetooth/bt_null.h> #include <nuttx/wireless/bluetooth/bt_null.h>
#include <nuttx/wireless/ieee802154/ieee802154_loopback.h> #include <nuttx/wireless/ieee802154/ieee802154_loopback.h>
#if defined(CONFIG_FS_BINFS) && defined(CONFIG_BUILTIN)
# include <nuttx/binfmt/builtin.h>
#endif
#include "up_internal.h" #include "up_internal.h"
#include "sim.h" #include "sim.h"
@ -111,16 +107,6 @@ int sim_bringup(void)
#endif #endif
int ret; int ret;
#if defined(CONFIG_FS_BINFS) && defined(CONFIG_BUILTIN)
/* Register the BINFS file system */
ret = builtin_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "ERROR: builtin_initialize failed: %d\n", ret);
}
#endif
#ifdef CONFIG_FS_PROCFS #ifdef CONFIG_FS_PROCFS
/* Mount the procfs file system */ /* Mount the procfs file system */

View file

@ -49,8 +49,6 @@
# include <nuttx/usb/usbmonitor.h> # include <nuttx/usb/usbmonitor.h>
#endif #endif
#include <nuttx/binfmt/elf.h>
#include "stm32.h" #include "stm32.h"
#include "stm32_romfs.h" #include "stm32_romfs.h"
@ -291,16 +289,6 @@ int stm32_bringup(void)
} }
#endif #endif
#ifdef HAVE_ELF
/* Initialize the ELF binary loader */
ret = elf_initialize();
if (ret < 0)
{
serr("ERROR: Initialization of the ELF loader failed: %d\n", ret);
}
#endif
#ifdef CONFIG_SENSORS_MAX31855 #ifdef CONFIG_SENSORS_MAX31855
/* Register device 0 on spi channel 2 */ /* Register device 0 on spi channel 2 */

View file

@ -81,7 +81,6 @@
#define HAVE_SDIO 1 #define HAVE_SDIO 1
#define HAVE_CS43L22 1 #define HAVE_CS43L22 1
#define HAVE_RTC_DRIVER 1 #define HAVE_RTC_DRIVER 1
#define HAVE_ELF 1
#define HAVE_NETMONITOR 1 #define HAVE_NETMONITOR 1
#define HAVE_HCIUART 1 #define HAVE_HCIUART 1
@ -178,12 +177,6 @@
# undef HAVE_RTC_DRIVER # undef HAVE_RTC_DRIVER
#endif #endif
/* ELF */
#if defined(CONFIG_BINFMT_DISABLE) || !defined(CONFIG_ELF)
# undef HAVE_ELF
#endif
/* NSH Network monitor */ /* NSH Network monitor */
#if !defined(CONFIG_NET) || !defined(CONFIG_STM32_EMACMAC) #if !defined(CONFIG_NET) || !defined(CONFIG_STM32_EMACMAC)

View file

@ -52,10 +52,6 @@
#include <nuttx/spi/spi.h> #include <nuttx/spi/spi.h>
#include <nuttx/mmcsd.h> #include <nuttx/mmcsd.h>
#ifdef CONFIG_NXFLAT
# include <nuttx/binfmt/nxflat.h>
#endif
#include "lpc17_spi.h" #include "lpc17_spi.h"
#include "zkit-arm-1769.h" #include "zkit-arm-1769.h"
@ -170,18 +166,6 @@ int board_app_initialize(uintptr_t arg)
#endif #endif
int ret; int ret;
#ifdef CONFIG_NXFLAT
/* Initialize the NXFLAT binary loader */
ret = nxflat_initialize();
if (ret < 0)
{
syslog(LOG_ERR,
"ERROR: Initialization of the NXFLAT loader failed: %d\n",
ret);
}
#endif
#ifdef CONFIG_NSH_HAVEMMCSD #ifdef CONFIG_NSH_HAVEMMCSD
/* Get the SPI port */ /* Get the SPI port */

View file

@ -166,6 +166,16 @@ extern "C"
* Public Function Prototypes * Public Function Prototypes
****************************************************************************/ ****************************************************************************/
/****************************************************************************
* Name: binfmt_initialize
*
* Description:
* initialize binfmt subsystem
*
****************************************************************************/
void binfmt_initialize(void);
/**************************************************************************** /****************************************************************************
* Name: register_binfmt * Name: register_binfmt
* *

View file

@ -55,6 +55,7 @@
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include <nuttx/sched_note.h> #include <nuttx/sched_note.h>
#include <nuttx/syslog/syslog.h> #include <nuttx/syslog/syslog.h>
#include <nuttx/binfmt/binfmt.h>
#include <nuttx/init.h> #include <nuttx/init.h>
#include "sched/sched.h" #include "sched/sched.h"
@ -717,6 +718,12 @@ void os_start(void)
lib_initialize(); lib_initialize();
#ifndef CONFIG_BINFMT_DISABLE
/* Initialize the binfmt system */
binfmt_initialize();
#endif
/* IDLE Group Initialization **********************************************/ /* IDLE Group Initialization **********************************************/
/* Announce that the CPU0 IDLE task has started */ /* Announce that the CPU0 IDLE task has started */