Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
   Author: anchao <anchao@pinecone.net>

     apps/, most main() function: Correct CONFIG_BUILD_LOADABLE usage
     Loadable apps/: Correct loadable symbol table generate
     apps/system/ubloxmodem:  Fix build break
     apps/examples/ostest: start restart/waitpid/user test from main loop
     apps/nshlib:  Expand reboot and poweroff commands to include a second, optional mode argument

    Author: Gregory Nutt <gnutt@nuttx.org>

     An attempt to fix build issues.  Does not work.
     apps/examples/ostest:  Fix some inappropriate renaming of static functions introduced with recent patches.
     apps/builtin/exec_builtin.c:  Fix a error introduced by recent comments.  Found in build testing.

    Author: anchao <anchao@pinecone.net>

     apps/builtin/exec_builtin.c:  Try posix_spawn if builtin apps do not have have an entry point.
     apps/Application.mk: introduce MODULE config to simplify tristate(m)
     apps/nsh:  Change the nuttx shell module type to tristate
     apps:  Add loadable application support
     script/mksymtab:  Generate symbol table name by default
     apps/builtin:  Allow loadable applications can register with apps/builtin.
  • Loading branch information
anchao authored and gregory-nutt committed Aug 23, 2018
1 parent d7bdf06 commit 220653f
Show file tree
Hide file tree
Showing 327 changed files with 594 additions and 584 deletions.
43 changes: 30 additions & 13 deletions Application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,31 @@

include $(APPDIR)/Make.defs

# If this is an executable program (with MAINSRC), we must build it as a
# loadable module for the KERNEL build (always) or if the tristate module
# has the value "m"

ifneq ($(MAINSRC),)
ifneq ($(MODULE),)
ifeq ($(CONFIG_$(MODULE)),m)
BUILD_MODULE = y
endif
endif
endif

# Pass the definition to the C/C++ code via the CFLAGS/CXXFLAGS

ifeq ($(BUILD_MODULE),y)
CFLAGS += ${shell $(DEFINE) "$(CC)" BUILD_MODULE}
CXXFLAGS += ${shell $(DEFINE) "$(CC)" BUILD_MODULE}
endif

# File extensions

CXXEXT ?= .cxx

# Object files

AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
CXXOBJS = $(CXXSRCS:$(CXXEXT)=$(OBJEXT))
Expand All @@ -52,10 +75,12 @@ endif
SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS)

ifneq ($(CONFIG_BUILD_KERNEL),y)
ifneq ($(BUILD_MODULE),y)
OBJS += $(MAINOBJ)
endif

# Module install directory

ifeq ($(WINTOOL),y)
BIN = "${shell cygpath -w $(APPDIR)$(DELIM)libapps$(LIBEXT)}"
INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}"
Expand All @@ -68,6 +93,8 @@ ROOTDEPPATH = --dep-path .

VPATH =

# Targets follow

all: .built
.PHONY: clean preconfig depend distclean
.PRECIOUS: $(APPDIR)/libapps$(LIBEXT)
Expand All @@ -89,18 +116,11 @@ $(MAINOBJ): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)
endif

ifeq ($(LOADABLE),y)
.built: $(OBJS)
$(call ELFLD, $(APPNAME)_main, $(OBJS), $(APPNAME))
$(Q) mkdir -p $(BIN_DIR)
$(Q) install $(APPNAME) $(BIN_DIR)$(DELIM)$(APPNAME)
else
.built: $(OBJS)
$(call ARCHIVE, $(BIN), $(OBJS))
$(Q) touch $@
endif

ifeq ($(CONFIG_BUILD_KERNEL),y)
ifeq ($(BUILD_MODULE), y)
$(BIN_DIR)$(DELIM)$(PROGNAME): $(OBJS) $(MAINOBJ)
@echo "LD: $(PROGNAME)"
$(Q) $(LD) $(LDELFFLAGS) $(LDLIBPATH) -o $(INSTALL_DIR)$(DELIM)$(PROGNAME) $(ARCHCRT0OBJ) $(MAINOBJ) $(LDLIBS)
Expand All @@ -118,7 +138,7 @@ ifneq ($(APPNAME),)
ifneq ($(PRIORITY),)
ifneq ($(STACKSIZE),)
$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main)
$(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(if $(BUILD_MODULE),,$(APPNAME)_main))

context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat
else
Expand All @@ -145,9 +165,6 @@ endif
depend: .depend

clean:
ifeq ($(LOADABLE),y)
$(call DELFILE, $(APPNAME))
endif
$(call DELFILE, .built)
$(call CLEAN)

Expand Down
42 changes: 10 additions & 32 deletions Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,23 @@ DEPCONFIG = $(TOPDIR)$(DELIM).config
ifeq ($(CONFIG_WINDOWS_NATIVE),y)
define REGISTER
$(Q) echo Register: $1
$(Q) echo { "$1", $2, $3, $4 }, > "$(BUILTIN_REGISTRY)$(DELIM)$4.bdat"
$(Q) echo int $4(int argc, char *argv[]); > "$(BUILTIN_REGISTRY)$(DELIM)$4.pdat"
$(Q) echo { "$1", $2, $3, $4 }, > "$(BUILTIN_REGISTRY)$(DELIM)$1.bdat"
$(Q) if [ ! -z $4 ]; then \
echo "int $4(int argc, char *argv[]);" > "$(BUILTIN_REGISTRY)$(DELIM)$1.pdat"; \
fi;
$(Q) touch $(BUILTIN_REGISTRY)$(DELIM).updated"
endef
else
define REGISTER
$(Q) echo "Register: $1"
$(Q) echo "{ \"$1\", $2, $3, $4 }," > "$(BUILTIN_REGISTRY)$(DELIM)$4.bdat"
$(Q) echo "int $4(int argc, char *argv[]);" > "$(BUILTIN_REGISTRY)$(DELIM)$4.pdat"
$(Q) echo "Register: $1 $4"
$(Q) echo "{ \"$1\", $2, $3, $4 }," > "$(BUILTIN_REGISTRY)$(DELIM)$1.bdat"
$(Q) if [ ! -z $4 ]; then \
echo "int $4(int argc, char *argv[]);" > "$(BUILTIN_REGISTRY)$(DELIM)$1.pdat"; \
fi;
$(Q) touch "$(BUILTIN_REGISTRY)$(DELIM).updated"
endef
endif

# COMPILE - a macro to compile a loadable app in C

ifeq ($(LOADABLE),y)
define COMPILE
@echo "CC) $1"
$(Q) $(CC) -c $(CELFFLAGS) -DLOADABLE_APP $1 -o $2
endef
endif

# COMPILEXX - a macro to compile a loadable app in C++

ifeq ($(LOADABLE),y)
define COMPILEXX
@echo "CXX: $1"
$(Q) $(CXX) -c $(CXXELFFLAGS) -DLOADABLE_APP $1 -o $2
endef
endif

# ELFLD - a macro to link loadable app
# Example: $(call ELFLD, entry point, in-file(s), out-file)

define ELFLD
@echo "LD: $3"
$(Q) $(LD) $(LDELFFLAGS) $2 -o $3
$(Q) chmod +x $3
endef

# Tools
#
# In a normal build, tools will reside in the nuttx/tools sub-directory and
Expand Down Expand Up @@ -146,3 +123,4 @@ endif
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(APPDIR)$(DELIM)include"}
CXXFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(APPDIR)$(DELIM)include"}

LDLIBS = $(APPDIR)/libapps.a
35 changes: 18 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,22 @@ LIBPATH ?= $(TOPDIR)$(DELIM)staging

# The install path

BIN_DIR = $(APPDIR)$(DELIM)bin
EXE_DIR = $(APPDIR)$(DELIM)exe
BIN_DIR = $(EXE_DIR)$(DELIM)system$(DELIM)bin

# The final build target

BIN = libapps$(LIBEXT)

# Symbol table for loadable apps.

SYMTABSRC = $(APPDIR)$(DELIM)symtab_apps.c
SYMTABOBJ = $(APPDIR)$(DELIM)symtab_apps$(OBJEXT)
SYMTABSRC = $(EXE_DIR)$(DELIM)symtab_apps.c
SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT))

# Build targets

all: $(BIN)
.PHONY: import symtab install dirlinks context context_serialize clean_context context_rest .depdirs preconfig depend clean distclean
.PHONY: import install dirlinks context context_serialize clean_context context_rest .depdirs preconfig depend clean distclean
.PRECIOUS: libapps$(LIBEXT)

define MAKE_template
Expand All @@ -102,29 +103,29 @@ $(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),depend))
$(foreach SDIR, $(CLEANDIRS), $(eval $(call SDIR_template,$(SDIR),clean)))
$(foreach SDIR, $(CLEANDIRS), $(eval $(call SDIR_template,$(SDIR),distclean)))

make_symbols:
ifeq ($(CONFIG_SYSTEM_NSH_SYMTAB),y)
mkdir -p $(BIN_DIR)
$(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BIN_DIR) $(SYMTABSRC)
$(call COMPILE, $(SYMTABSRC), $(SYMTABOBJ))
$(call ARCHIVE, $(APPDIR)$(DELIM)$(BIN), $(SYMTABOBJ))
endif
ifeq ($(CONFIG_BUILD_LOADABLE),)
$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
else
$(SYMTABSRC): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all)
$(Q) $(MAKE) install TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
$(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(EXE_DIR)$(DELIM)system $(SYMTABSRC)

$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) make_symbols
$(SYMTABOBJ): %$(OBJEXT): %.c
$(call COMPILE, -fno-lto $<, $@)

$(BIN): $(SYMTABOBJ)
$(call ARCHIVE, $(BIN), $^)
endif

.install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install)

$(BIN_DIR):
mkdir -p $(BIN_DIR)
$(Q) mkdir -p $(BIN_DIR)

install: $(BIN_DIR) .install

.import: $(BIN) install

symtab: $(BIN_DIR)
$(Q) tools/mksymtab.sh $(BIN_DIR) $(APPDIR)$(DELIM)import/symtab.c
$(call MAKE_template,import,symtab)

import:
$(Q) $(MAKE) .import TOPDIR="$(APPDIR)$(DELIM)import"

Expand Down
24 changes: 20 additions & 4 deletions builtin/exec_builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,27 @@ int exec_builtin(FAR const char *appname, FAR char * const *argv,
}
}

/* Start the built-in */
#ifdef CONFIG_LIBC_EXECFUNCS
/* A NULL entry point implies that the task is a loadable application */

if (builtin->main == NULL)
{
/* Load and execute the application. */

ret = posix_spawn(&pid, builtin->name, &file_actions,
&attr, (argv) ? &argv[1] : (FAR char * const *)NULL,
NULL);
}
else
#endif
{
/* Start the built-in */

ret = task_spawn(&pid, builtin->name, builtin->main, &file_actions,
&attr, (argv) ? &argv[1] : (FAR char * const *)NULL,
(FAR char * const *)NULL);
}

ret = task_spawn(&pid, builtin->name, builtin->main, &file_actions,
&attr, (argv) ? &argv[1] : (FAR char * const *)NULL,
(FAR char * const *)NULL);
if (ret != 0)
{
serr("ERROR: task_spawn failed: %d\n", ret);
Expand Down
6 changes: 3 additions & 3 deletions examples/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ examples/alarm
Configuration:

CONFIG_EXAMPLES_ALARM - Enable the RTC driver alarm test
CONFIG_EXAMPLES_ALARM_PROGNAME - If CONFIG_BUILD_KERNEL=y, then this is
CONFIG_EXAMPLES_ALARM_PROGNAME - If CONFIG_BUILD_LOADABLE=y, then this is
the name of the program that will be use when the NSH ELF program is
installed.
CONFIG_EXAMPLES_ALARM_PRIORITY - Alarm daemon priority
Expand Down Expand Up @@ -435,7 +435,7 @@ examples/flash_test
* CONFIG_MTD_SMART=y - SMART block driver support
* CONFIG_NSH_BUILTIN_APPS=y - This example can only be built as an NSH
command
* CONFIG_BUILD_PROTECTED=n and CONFIG_BUILD_KERNEL=n- This test uses
* CONFIG_BUILD_PROTECTED=n and CONFIG_BUILD_LOADABLE=n- This test uses
internal OS interfaces and so is not available in the NUTTX kernel
builds

Expand Down Expand Up @@ -1584,7 +1584,7 @@ examples/relays
relies on internal OS interfaces that are not normally available to a
user-space program. As a result, this example cannot be used if a
NuttX is built as a protected, supervisor kernel (CONFIG_BUILD_PROTECTED
or CONFIG_BUILD_KERNEL).
or CONFIG_BUILD_LOADABLE).

examples/rfid_readuid
^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion examples/adc/adc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static void parse_args(FAR struct adc_state_s *adc, int argc, FAR char **argv)
* Name: adc_main
****************************************************************************/

#ifdef CONFIG_BUILD_KERNEL
#ifdef BUILD_MODULE
int main(int argc, FAR char *argv[])
#else
int adc_main(int argc, char *argv[])
Expand Down
2 changes: 1 addition & 1 deletion examples/adxl372_test/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if EXAMPLES_ADXL372_TEST
config EXAMPLES_ADXL372_TEST_PROGNAME
string "Program name"
default "ADXL372_test"
depends on BUILD_KERNEL
depends on BUILD_LOADABLE
---help---
This is the name of the program that will be use when the NSH ELF
program is installed.
Expand Down
2 changes: 1 addition & 1 deletion examples/adxl372_test/adxl372_test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ static int adxl372_test(int is_interactive, FAR char *path)
*
****************************************************************************/

#ifdef CONFIG_BUILD_KERNEL
#ifdef BUILD_MODULE
int main(int argc, FAR char *argv[])
#else
int adxl372_test_main(int argc, FAR char *argv[])
Expand Down
2 changes: 1 addition & 1 deletion examples/ajoystick/ajoy_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ static int ajoy_calibrate(int fd)
* ajoy_main
****************************************************************************/

#ifdef CONFIG_BUILD_KERNEL
#ifdef BUILD_MODULE
int main(int argc, FAR char *argv[])
#else
int ajoy_main(int argc, char *argv[])
Expand Down
2 changes: 1 addition & 1 deletion examples/alarm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if EXAMPLES_ALARM
config EXAMPLES_ALARM_PROGNAME
string "Program name"
default "alarm"
depends on BUILD_KERNEL
depends on BUILD_LOADABLE
---help---
This is the name of the program that will be use when the NSH ELF
program is installed.
Expand Down
2 changes: 1 addition & 1 deletion examples/alarm/alarm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static void show_usage(FAR const char *progname)
* alarm_main
****************************************************************************/

#ifdef CONFIG_BUILD_KERNEL
#ifdef BUILD_MODULE
int main(int argc, FAR char *argv[])
#else
int alarm_main(int argc, FAR char *argv[])
Expand Down
2 changes: 1 addition & 1 deletion examples/apa102/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if EXAMPLES_APA102
config EXAMPLES_APA102_PROGNAME
string "Program name"
default "apa102"
depends on BUILD_KERNEL
depends on BUILD_LOADABLE
---help---
This is the name of the program that will be use when the NSH ELF
program is installed.
Expand Down
2 changes: 1 addition & 1 deletion examples/apa102/apa102_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ static struct apa102_ledstrip_s hsvtorgb(uint16_t h, uint8_t s, uint8_t v)
* apa102_main
****************************************************************************/

#ifdef CONFIG_BUILD_KERNEL
#ifdef BUILD_MODULE
int main(int argc, FAR char *argv[])
#else
int apa102_main(int argc, char *argv[])
Expand Down
2 changes: 1 addition & 1 deletion examples/apds9960/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if EXAMPLES_APDS9960
config EXAMPLES_APDS9960_PROGNAME
string "APDS-9960 Test Program name"
default "apds9960"
depends on BUILD_KERNEL
depends on BUILD_LOADABLE
---help---
This is the name of the program that will be use when the NSH ELF
program is installed.
Expand Down
2 changes: 1 addition & 1 deletion examples/apds9960/apds9960_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
* apds9960_main
****************************************************************************/

#ifdef CONFIG_BUILD_KERNEL
#ifdef BUILD_MODULE
int main(int argc, FAR char *argv[])
#else
int apds9960_main(int argc, char *argv[])
Expand Down
Loading

0 comments on commit 220653f

Please sign in to comment.