From c9e0baeb529fcd7bae1e4a6fd8afc0102de37140 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 16:26:15 -0600 Subject: [PATCH 01/23] Remove all hardcoded directories from Makefile --- Makefile | 91 ++++++++++++++++---------------------------------------- 1 file changed, 26 insertions(+), 65 deletions(-) diff --git a/Makefile b/Makefile index d580d2f10..f444765d6 100644 --- a/Makefile +++ b/Makefile @@ -42,62 +42,25 @@ TOPDIR ?= $(APPDIR)/import # Application Directories -# CONFIGURED_APPS is the list of all configured built-in directories/built -# action. -# SUBDIRS is the list of all directories containing Makefiles. It is used -# only for cleaning. +# BUILDIRS is the list of top-level directories containing Make.defs files +# CONFIGDIRS is the list all top-level directories containing Kconfig files +# CLEANDIRS is the list of all top-level directories containing Makefiles. +# It is used only for cleaning. + +BUILDIRS := $(dir $(filter-out import/Make.defs,$(wildcard */Make.defs))) +CONFIGDIRS := $(dir $(wildcard */Kconfig)) +CLEANDIRS := $(dir $(wildcard */Makefile)) + +# CONFIGURED_APPS is the application directories that should be built in +# the current configuration. CONFIGURED_APPS = -SUBDIRS = examples graphics interpreters modbus builtin import nshlib -SUBDIRS += netutils platform system -# The list of configured directories is derived from NuttX configuration -# file: The selected applications are enabled settings in the configuration -# file. For example, -# -# CONFIG_EXAMPLES_HELLO=y -# -# Will cause the "Hello, World!" example at apps/examples/hello to be -# built and added int libapps.a. -# out. - -# builtin/Make.defs must be included first - -include builtin/Make.defs -include examples/Make.defs -include graphics/Make.defs -include interpreters/Make.defs -include modbus/Make.defs -include netutils/Make.defs -include nshlib/Make.defs -include platform/Make.defs -include system/Make.defs --include external/Make.defs - -# INSTALLED_APPS is the list of currently available application directories. It -# is the same as CONFIGURED_APPS, but filtered to exclude any non-existent -# application directory. builtin is always in the list of applications to be -# built. - -INSTALLED_APPS = - -# Create the list of available applications (INSTALLED_APPS) - -define ADD_BUILTIN - INSTALLED_APPS += $(if $(wildcard $1$(DELIM)Makefile),$1,) +define Add_Application + include $(1)Make.defs endef -$(foreach BUILTIN, $(CONFIGURED_APPS), $(eval $(call ADD_BUILTIN,$(BUILTIN)))) - -# The external/ directory may also be added to the INSTALLED_APPS. But there -# is no external/ directory in the repository. Rather, this directory may be -# provided by the user (possibly as a symbolic link) to add libraries and -# applications to the standard build from the repository. - -EXTERNAL_DIR := $(dir $(wildcard external$(DELIM)Makefile)) - -INSTALLED_APPS += $(EXTERNAL_DIR) -SUBDIRS += $(EXTERNAL_DIR) +$(foreach BDIR, $(BUILDIRS), $(eval $(call Add_Application,$(BDIR)))) # Library path @@ -121,16 +84,16 @@ $(1)_$(2): $(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" BIN_DIR="$(BIN_DIR)" endef -$(foreach SDIR, $(INSTALLED_APPS), $(eval $(call SDIR_template,$(SDIR),all))) -$(foreach SDIR, $(INSTALLED_APPS), $(eval $(call SDIR_template,$(SDIR),install))) -$(foreach SDIR, $(INSTALLED_APPS), $(eval $(call SDIR_template,$(SDIR),context))) -$(foreach SDIR, $(INSTALLED_APPS), $(eval $(call SDIR_template,$(SDIR),depend))) -$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),clean))) -$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),distclean))) +$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),all))) +$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),install))) +$(foreach SDIR, $(CONFIGURED_APPS), $(eval $(call SDIR_template,$(SDIR),context))) +$(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))) -$(BIN): $(foreach SDIR, $(INSTALLED_APPS), $(SDIR)_all) +$(BIN): $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_all) -.install: $(foreach SDIR, $(INSTALLED_APPS), $(SDIR)_install) +.install: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_install) $(BIN_DIR): mkdir -p $(BIN_DIR) @@ -142,7 +105,7 @@ install: $(BIN_DIR) .install import: $(Q) $(MAKE) .import TOPDIR="$(APPDIR)$(DELIM)import" -context_rest: $(foreach SDIR, $(INSTALLED_APPS), $(SDIR)_context) +context_rest: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_context) context_serialize: $(Q) $(MAKE) -C builtin context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" @@ -150,19 +113,19 @@ context_serialize: context: context_serialize -.depdirs: $(foreach SDIR, $(INSTALLED_APPS), $(SDIR)_depend) +.depdirs: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_depend) .depend: context Makefile .depdirs $(Q) touch $@ depend: .depend -clean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_clean) +clean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_clean) $(call DELFILE, $(BIN)) $(call DELDIR, $(BIN_DIR)) $(call CLEAN) -distclean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_distclean) +distclean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_distclean) ifeq ($(CONFIG_WINDOWS_NATIVE),y) $(Q) ( if exist external ( \ echo ********************************************************" \ @@ -179,5 +142,3 @@ else endif $(call DELFILE, .depend) $(call DELDIR, $(BIN_DIR)) - - From 74801cf38ee854fc7ea31b0dabc03994be48a15c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 11 Aug 2015 17:49:10 -0600 Subject: [PATCH 02/23] apps/tools/mkkconfig.sh: The top-level Kconfig file is not auto-generated. The autogenerated Kconfig file will be constructed so that every second level directory that contains a Kconfig file will automatically be sourced --- .gitignore | 1 + ChangeLog.txt | 17 +++++++ Kconfig | 44 ------------------ Makefile | 21 +++++++-- NxWidgets/Kconfig | 3 ++ README.txt | 2 +- builtin/Kconfig | 5 +- examples/Kconfig | 4 ++ graphics/Kconfig | 4 +- interpreters/Kconfig | 3 ++ modbus/Kconfig | 3 ++ netutils/Kconfig | 4 +- nshlib/Kconfig | 3 ++ platform/Kconfig | 4 ++ system/Kconfig | 3 ++ tools/mkkconfig.sh | 107 +++++++++++++++++++++++++++++++++++++++++++ 16 files changed, 176 insertions(+), 52 deletions(-) delete mode 100644 Kconfig create mode 100755 tools/mkkconfig.sh diff --git a/.gitignore b/.gitignore index 7a658a38b..64741c525 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ Make.dep core .gdbinit cscope.out +/Kconfig /bin /external /.context diff --git a/ChangeLog.txt b/ChangeLog.txt index 3d104f937..b5039789a 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1373,3 +1373,20 @@ * apps/system/readline and apps/nshlib: Add support for an in-memory command line history that can be retrieved using the up and down arrows. Contributed by Nghia Ho (2015-08-09). + * apps/Makefile: No longer depends on hardcoded lists of directories. + Instead, it does a wildcard search to find all appropriate + directories. This means that to install a new application, you + simply have to copy the directory (or link it) into the apps/ + directory. If the new directory includes a Makefile and Make.defs + file, the it will automatically be included in the build (2015-08-11). + * apps/Makefile, Kconfig, */Kconfig, tools/mkkconfig.sh: Add the tool + mkkconfig.sh that dynamically builds the apps/Kconfig file at + configuration time. The hardcoded configuration file has been removed + and now the top-level Makefile executes tools/mkkconfig.sh to auto- + generate the top-level Kconfig file. A new apps/ make target call + preconfig: was added to support this operation. Now you do not have + to modify the top-level Kconfig file to add a new directory into the + configuration; the top-level subdirectory simply needs to include a + Kconfig file and it will automatically be included in the + configuration. The native Windows build is temporarily broken until + a new apps/tools/mkconfig.bat script is generated (2015-08-11). diff --git a/Kconfig b/Kconfig deleted file mode 100644 index 7b21c6387..000000000 --- a/Kconfig +++ /dev/null @@ -1,44 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menu "Built-In Applications" -source "$APPSDIR/builtin/Kconfig" -endmenu - -menu "Examples" -source "$APPSDIR/examples/Kconfig" -endmenu - -menu "Graphics Support" -source "$APPSDIR/graphics/Kconfig" -endmenu - -menu "Interpreters" -source "$APPSDIR/interpreters/Kconfig" -endmenu - -menu "Network Utilities" -source "$APPSDIR/netutils/Kconfig" -endmenu - -menu "FreeModBus" -source "$APPSDIR/modbus/Kconfig" -endmenu - -menu "NSH Library" -source "$APPSDIR/nshlib/Kconfig" -endmenu - -menu "NxWidgets/NxWM" -source "$APPSDIR/NxWidgets/Kconfig" -endmenu - -menu "Platform-specific Support" -source "$APPSDIR/platform/Kconfig" -endmenu - -menu "System Libraries and NSH Add-Ons" -source "$APPSDIR/system/Kconfig" -endmenu diff --git a/Makefile b/Makefile index f444765d6..76b23eddd 100644 --- a/Makefile +++ b/Makefile @@ -40,15 +40,21 @@ TOPDIR ?= $(APPDIR)/import -include $(TOPDIR)/Make.defs +# Tools + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + MKKCONFIG = ${shell $(APPDIR)\tools\mkkconfig.bat} +else + MKKCONFIG = ${shell $(APPDIR)/tools/mkkconfig.sh} +endif + # Application Directories # BUILDIRS is the list of top-level directories containing Make.defs files -# CONFIGDIRS is the list all top-level directories containing Kconfig files # CLEANDIRS is the list of all top-level directories containing Makefiles. # It is used only for cleaning. BUILDIRS := $(dir $(filter-out import/Make.defs,$(wildcard */Make.defs))) -CONFIGDIRS := $(dir $(wildcard */Kconfig)) CLEANDIRS := $(dir $(wildcard */Makefile)) # CONFIGURED_APPS is the application directories that should be built in @@ -77,7 +83,7 @@ BIN = libapps$(LIBEXT) # Build targets all: $(BIN) -.PHONY: import install context context_serialize context_rest .depdirs depend clean distclean +.PHONY: import install context context_serialize context_rest .depdirs preconfig depend clean distclean define SDIR_template $(1)_$(2): @@ -113,6 +119,11 @@ context_serialize: context: context_serialize +Kconfig: $(MKKCONFIG) + $(MKKCONFIG) + +preconfig: Kconfig + .depdirs: $(foreach SDIR, $(CONFIGURED_APPS), $(SDIR)_depend) .depend: context Makefile .depdirs @@ -122,6 +133,7 @@ depend: .depend clean: $(foreach SDIR, $(CLEANDIRS), $(SDIR)_clean) $(call DELFILE, $(BIN)) + $(call DELFILE, Kconfig) $(call DELDIR, $(BIN_DIR)) $(call CLEAN) @@ -141,4 +153,7 @@ else ) endif $(call DELFILE, .depend) + $(call DELFILE, $(BIN)) + $(call DELFILE, Kconfig) $(call DELDIR, $(BIN_DIR)) + $(call CLEAN) diff --git a/NxWidgets/Kconfig b/NxWidgets/Kconfig index 018e5f9b6..d0026e492 100644 --- a/NxWidgets/Kconfig +++ b/NxWidgets/Kconfig @@ -3,6 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +menu "NxWidgets/NxWM" + config NXWIDGETS bool "Enable NxWidgets" default n @@ -1281,3 +1283,4 @@ endif # NXWM_MEDIAPLAYER endmenu # NxWM Media Player Display Settings endif # NXWM +endmenu # NxWidgets/NxWM diff --git a/README.txt b/README.txt index 909499378..b65a175e6 100644 --- a/README.txt +++ b/README.txt @@ -83,7 +83,7 @@ asynchronously with NSH. If you want to force NSH to execute commands then wait for the command to execute, you can enable that feature by adding the following to the NuttX configuration file: -CONFIG_SCHED_WAITPID=y + CONFIG_SCHED_WAITPID=y The configuration option enables support for the waitpid() RTOS interface. When that interface is enabled, NSH will use it to wait, sleeping until diff --git a/builtin/Kconfig b/builtin/Kconfig index 8ea51b38a..e8384234a 100644 --- a/builtin/Kconfig +++ b/builtin/Kconfig @@ -3,7 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -if BUILTIN +menu "Built-In Applications" + depends on BUILTIN config BUILTIN_PROXY_STACKSIZE int "Builtin Proxy Stack Size" @@ -14,4 +15,4 @@ config BUILTIN_PROXY_STACKSIZE configuration item specifies the stack size used for the proxy. Default: 1024 bytes. -endif +endmenu # Built-In Applications diff --git a/examples/Kconfig b/examples/Kconfig index bd90ae004..eaae41035 100644 --- a/examples/Kconfig +++ b/examples/Kconfig @@ -3,6 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +menu "Examples" + source "$APPSDIR/examples/adc/Kconfig" source "$APPSDIR/examples/ajoystick/Kconfig" source "$APPSDIR/examples/bastest/Kconfig" @@ -83,3 +85,5 @@ source "$APPSDIR/examples/watchdog/Kconfig" source "$APPSDIR/examples/wget/Kconfig" source "$APPSDIR/examples/wgetjson/Kconfig" source "$APPSDIR/examples/xmlrpc/Kconfig" + +endmenu # Examples diff --git a/graphics/Kconfig b/graphics/Kconfig index 4e8b40809..8bfad9e8d 100644 --- a/graphics/Kconfig +++ b/graphics/Kconfig @@ -3,6 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +menu "Graphics Support" + config TIFF bool "TIFF file generation library" default n @@ -31,4 +33,4 @@ source "$APPSDIR/graphics/traveler/Kconfig" endmenu endif # GRAPHICS_TRAVELER - +endmenu # Graphics Support diff --git a/interpreters/Kconfig b/interpreters/Kconfig index 3bace79e4..bed828685 100644 --- a/interpreters/Kconfig +++ b/interpreters/Kconfig @@ -3,6 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +menu "Interpreters" + source "$APPSDIR/interpreters/bas/Kconfig" source "$APPSDIR/interpreters/ficl/Kconfig" @@ -20,3 +22,4 @@ if INTERPRETERS_PCODE endif source "$APPSDIR/interpreters/micropython/Kconfig" +endmenu # Interpreters diff --git a/modbus/Kconfig b/modbus/Kconfig index 29b073c16..33b3b517a 100644 --- a/modbus/Kconfig +++ b/modbus/Kconfig @@ -3,6 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +menu "FreeModBus" + config MODBUS bool "Modbus support via FreeModBus" default n @@ -159,3 +161,4 @@ config MB_MASTER_TOTAL_SLAVE_NUM endif # MB_ASCII_MASTER || MB_RTU_MASTER endif # MODBUS +endmenu # FreeModBus diff --git a/netutils/Kconfig b/netutils/Kconfig index 4031a8b87..8c214c0c5 100644 --- a/netutils/Kconfig +++ b/netutils/Kconfig @@ -3,7 +3,7 @@ # see the file kconfig-language.txt in the NuttX tools repository. # -comment "Networking Utilities" +menu "Network Utilities" source "$APPSDIR/netutils/codecs/Kconfig" source "$APPSDIR/netutils/dhcpc/Kconfig" @@ -22,3 +22,5 @@ source "$APPSDIR/netutils/ntpclient/Kconfig" source "$APPSDIR/netutils/discover/Kconfig" source "$APPSDIR/netutils/xmlrpc/Kconfig" source "$APPSDIR/netutils/pppd/Kconfig" + +endmenu # Network Utilities diff --git a/nshlib/Kconfig b/nshlib/Kconfig index d6a17d23b..d1de1e8c0 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -3,6 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +menu "NSH Library" + config NSH_LIBRARY bool "NSH Library" default n @@ -1381,3 +1383,4 @@ endif # NSH_TELNET_LOGIN endif # NSH_TELNET endmenu # Telnet Configuration endif # NSH_LIBRARY +endmenu # NSH Library diff --git a/platform/Kconfig b/platform/Kconfig index 218119e85..8fd145b6e 100644 --- a/platform/Kconfig +++ b/platform/Kconfig @@ -3,6 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +menu "Platform-specific Support" + config PLATFORM_CONFIGDATA bool "Platform configuration data" default n @@ -15,3 +17,5 @@ config PLATFORM_CONFIGDATA FLASH, etc. source "$APPSDIR/platform/mikroe-stm32f4/Kconfig" + +endmenu # Platform-specific Support diff --git a/system/Kconfig b/system/Kconfig index 7e4a61fe8..1d32f3a7e 100644 --- a/system/Kconfig +++ b/system/Kconfig @@ -3,6 +3,8 @@ # see the file kconfig-language.txt in the NuttX tools repository. # +menu "System Libraries and NSH Add-Ons" + source "$APPSDIR/system/free/Kconfig" source "$APPSDIR/system/cle/Kconfig" source "$APPSDIR/system/cu/Kconfig" @@ -30,3 +32,4 @@ source "$APPSDIR/system/usbmonitor/Kconfig" source "$APPSDIR/system/zmodem/Kconfig" source "$APPSDIR/system/zoneinfo/Kconfig" +endmenu # System Libraries and NSH Add-Ons diff --git a/tools/mkkconfig.sh b/tools/mkkconfig.sh new file mode 100755 index 000000000..714ca5117 --- /dev/null +++ b/tools/mkkconfig.sh @@ -0,0 +1,107 @@ +#!/bin/bash +# apps/tools/mkkconfig.sh +# +# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Author: 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. +# + +# Get the input parameter list + +USAGE="USAGE: mkkconfig.sh [-d] [-h] [-t ] [-o ]" +unset TOPDIR +KCONFIG=Kconfig + +while [ ! -z "$1" ]; do + case $1 in + -d ) + set -x + ;; + -t ) + shift + TOPDIR=$1 + ;; + -o ) + shift + KCONFIG=$1 + ;; + -h ) + echo $USAGE + exit 0 + ;; + * ) + echo "ERROR: Unrecognized argument: $1" + echo $USAGE + exit 1 + ;; + esac + shift +done + +# Check arguments + +if [ -z "$TOPDIR" ]; then + if [ -x "tools/mkkconfig.sh" ]; then + TOPDIR=$PWD + else + cd .. || { echo "cd .. failed"; exit 1; } + if [ -x "tools/mkkconfig.sh" ]; then + TOPDIR=$PWD + else + echo "ERROR: This script must be executed from a known location" + echo " OR you must provide the path in the command line" + echo $USAGE + exit 1 + fi + fi +else + if [ ! -x "${TOPDIR}/tools/mkkconfig.sh" ]; then + echo "ERROR: \"${TOPDIR}\" is not correct" + echo $USAGE + exit 1 + fi + cd ${TOPDIR} || { echo "cd ${TOPDIR} failed"; exit 1; } +fi + +if [ -f ${TOPDIR}/${KCONFIG} ]; then + rm ${TOPDIR}/${KCONFIG} || { echo "ERROR: Failed to remove ${TOPDIR}/${KCONFIG}"; exit 1; } +fi + +KCONFIG_LIST=`ls -1 */Kconfig` + +echo "#" > ${TOPDIR}/${KCONFIG} +echo "# For a description of the syntax of this configuration file," >> ${TOPDIR}/${KCONFIG} +echo "# see the file kconfig-language.txt in the NuttX tools repository." >> ${TOPDIR}/${KCONFIG} +echo "#" >> ${TOPDIR}/${KCONFIG} +echo "" >> ${TOPDIR}/${KCONFIG} + +for FILE in ${KCONFIG_LIST}; do + echo "source \"\$APPSDIR/${FILE}\"" >> ${TOPDIR}/${KCONFIG} +done + From 3a55ecabf8d9b3d6126456d851b16d5844109678 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 12 Aug 2015 07:43:08 -0600 Subject: [PATCH 03/23] Update README file --- ChangeLog.txt | 2 +- README.txt | 71 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index b5039789a..9f425750c 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1378,7 +1378,7 @@ directories. This means that to install a new application, you simply have to copy the directory (or link it) into the apps/ directory. If the new directory includes a Makefile and Make.defs - file, the it will automatically be included in the build (2015-08-11). + file, then it will automatically be included in the build (2015-08-11). * apps/Makefile, Kconfig, */Kconfig, tools/mkkconfig.sh: Add the tool mkkconfig.sh that dynamically builds the apps/Kconfig file at configuration time. The hardcoded configuration file has been removed diff --git a/README.txt b/README.txt index b65a175e6..77640bd77 100644 --- a/README.txt +++ b/README.txt @@ -150,7 +150,7 @@ Building NuttX with Board-Specific Pieces Outside the Source Tree Q: Has anyone come up with a tidy way to build NuttX with board- specific pieces outside the source tree? -A: Here are four: +A: Here are three: 1) There is a make target called 'make export'. It will build NuttX, then bundle all of the header files, libaries, startup @@ -176,38 +176,51 @@ A: Here are four: 3) If you like the random collection of stuff in the apps/ directory but just want to expand the existing components with your own, external sub-directory then there is an easy way to that too: - You just create the sympolic link at apps/external that - redirects to your application sub-directory. The apps/Makefile - will always automatically check for the existence of an - apps/external directory and if it exists, it will automatically - incorporate it into the build. + You just create a sympolic link in the apps/ directory that + redirects to your application sub-directory. - This feature of the apps/Makefile is documented only here. + In order to be incorporated into the build, the directory that + you link under the apps/ directory should contain (1) a Makefile + that supports the clean and distclean targets (see other Makefiles + for examples), and (2) a tiny Make.defs file that simply adds the + custon build directories to the variable CONFIGURED_APPS like: - You can, for example, create a script called install.sh that + CONFIGURED_APPS += my_directory1 my_directory2 + + The apps/Makefile will always automatically check for the + existence of subdirectories containing a Makefile and a Make.defs + file. The Makefile will be used only to support cleaning operations. + The Make.defs file provides the set of directories to be built; these + directories must also contain a Makefile. That Makefile must be able + to build the sources and add the objects to the apps/libapps.a archive. + (see other Makefiles for examples). It should support the all, + install, context, and depend targets. + + apps/Makefile does not depend on any hardcoded lists of directories. + Instead, it does a wildcard search to find all appropriate + directories. This means that to install a new application, you + simply have to copy the directory (or link it) into the apps/ + directory. If the new directory includes a Makefile and Make.defs + file, then it will automatically be included in the build. + + If the directory that you add also includes a Kconfig file, then it + will automatically be included in the NuttX configuration system as + well. apps/Makefile uses a tool at apps/tools/mkkconfig.sh that + dynamically builds the apps/Kconfig file at pre-configuration time. + + NOTE: The native Windows build is temporarily broken until a new + apps/tools/mkconfig.bat script is generated (2015-08-11). + + You could, for example, create a script called install.sh that installs a custom application, configuration, and board specific directory: - a) Copy 'MyBoard' directory to configs/MyBoard. - b) Add a symbolic link to MyApplication at apps/external - c) Configure NuttX (usually by: + a) Copy 'MyBoard' directory to configs/MyBoard. + b) Add a symbolic link to MyApplication at apps/external + c) Configure NuttX (usually by: - tools/configure.sh MyBoard/MyConfiguration + tools/configure.sh MyBoard/MyConfiguration - or simply by copying defconfig->nuttx/.config, - setenv.sh->nuttx/setenv.sh, and Make.defs->nuttx/Make.defs. - - Using the 'external' link makes it especially easy to add a - 'built-in' application an existing configuration. - - 4) Add any link to apps/ - - a) Add symbolic links apps/ to as many other directories as you - want, - b) Add the symbolic link to the list of candidate paths in the - top level apps/Makefile, and - b) Add the (relative) paths to the CONFIGURED_APPS list - in the Make.defs file in your new directory. - - That is basically the same as my option #3 but doesn't use the - magic 'external' link. + Use of the name ''apps/external'' is suggested because that name + is included in the .gitignore file and will save you some nuisance + when working with GIT. From d64f6c300e93577d2883a670afc3c8f8fbfa6056 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 12 Aug 2015 15:29:52 -0600 Subject: [PATCH 04/23] Add a mkkconfig.bat script needed for the Windows native build --- ChangeLog.txt | 4 ++ README.txt | 3 - tools/mkkconfig.bat | 141 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 145 insertions(+), 3 deletions(-) create mode 100755 tools/mkkconfig.bat diff --git a/ChangeLog.txt b/ChangeLog.txt index 9f425750c..eb7ce483f 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1390,3 +1390,7 @@ Kconfig file and it will automatically be included in the configuration. The native Windows build is temporarily broken until a new apps/tools/mkconfig.bat script is generated (2015-08-11). + * apps/tools/mkkconfig.bat: Add the Windows script corresponding to + apps/tools/mkkconfig.sh. Needed for a Windows native build. Untested + on initial commit (2015-08-12). + diff --git a/README.txt b/README.txt index 77640bd77..4f481cefb 100644 --- a/README.txt +++ b/README.txt @@ -208,9 +208,6 @@ A: Here are three: well. apps/Makefile uses a tool at apps/tools/mkkconfig.sh that dynamically builds the apps/Kconfig file at pre-configuration time. - NOTE: The native Windows build is temporarily broken until a new - apps/tools/mkconfig.bat script is generated (2015-08-11). - You could, for example, create a script called install.sh that installs a custom application, configuration, and board specific directory: diff --git a/tools/mkkconfig.bat b/tools/mkkconfig.bat new file mode 100755 index 000000000..c2a2a1986 --- /dev/null +++ b/tools/mkkconfig.bat @@ -0,0 +1,141 @@ +@Echo off + +REM apps/tools/mkkconfig.bat +REM +REM Copyright (C) 2015 Gregory Nutt. All rights reserved. +REM Author: Gregory Nutt +REM +REM Redistribution and use in source and binary forms, with or without +REM modification, are permitted provided that the following conditions +REM are met: +REM +REM 1. Redistributions of source code must retain the above copyright +REM notice, this list of conditions and the following disclaimer. +REM 2. Redistributions in binary form must reproduce the above copyright +REM notice, this list of conditions and the following disclaimer in +REM the documentation and/or other materials provided with the +REM distribution. +REM 3. Neither the name NuttX nor the names of its contributors may be +REM used to endorse or promote products derived from this software +REM without specific prior written permission. +REM +REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +REM "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +REM LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +REM FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +REM COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +REM INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +REM BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS +REM OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED +REM AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +REM LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +REM ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +REM POSSIBILITY OF SUCH DAMAGE. +REM + +REM Parse command line arguments + +SET topdir= +SET kconfig=Kconfig + +:ArgLoop +IF "%1"=="" GOTO :EndOfLoop +IF "%1"=="-t" GOTO :SetTopDir +IF "%1"=="-o" GOTO :SetKconfig +IF "%1"=="-h" GOTO :ShowUsage + +Echo ERROR: Unrecogized option %1 +GOTO :ShowUsage + +:SetDebug +SET debug=-d +GOTO :NextArg + +:SetTopDir +SHIFT +SET topdir=%1 +GOTO :NextArg + +:SetKconfig +SHIFT +SET kconfig=%1 + +:NextArg +SHIFT +GOTO :ArgLoop + +REM Check input Parameters + +:EndOfLoop +IF "%topdir%"=="" ( + IF EXIST tools\mkkconfig.bat ( + SET topdir=%cd% + ) ELSE ( + cd .. + IF %ERRORLEVEL% GTR 0 ( + Echo ERROR: failed cd .. + GOTO :End + ) + IF EXIST tools\mkkconfig.bat ( + SET topdir=%cd% + ) ELSE ( + Echo ERROR: Cannot find top directory + GOTO :End + ) + ) +) ELSE ( + IF NOT EXIST "%topdir%" ( + Echo ERROR: %topdir% does not EXIST + GOTO :End + ) + Cd %topdir% + IF %ERRORLEVEL% GTR 0 ( + Echo ERROR: failed cd %topdir% + GOTO :End + ) +) + +IF EXIST %kconfig% ( + Del /f /q %kconfig% +REM IF %ERRORLEVEL% GTR 0 ( +REM Echo ERROR: failed to remove %kconfig% +REM GOTO :End +REM ) +) + +Echo # > %kconfig% +Echo # For a description of the syntax of this configuration file, >> %kconfig% +Echo # see the file kconfig-language.txt in the NuttX tools repository. >> %kconfig% +Echo # >> %kconfig% + +DIR /B /A:D >_tmp_.dat + +Echo source "$APPSDIR/builtin/Kconfig" >> %kconfig% +FOR /F "tokens=*" %%s IN (_tmp_.dat) do ( + if "%%s" NEQ "builtin" Echo source "$APPSDIR/%%s/Kconfig" >> %kconfig% +) +DEL _tmp_.dat + +GOTO :End + +REM Exit showing usage + +:ShowUsage +Echo USAGE: %0 [-d] [-t ^] [-o ^] +Echo %0 [-h] +Echo Where: +Echo ^<-d^>: +Echo Enables debug output +Echo -t ^: +Echo Identifies the top applicatino directory +Echo -o ^: +Echo Identifies the specific configuratin for the selected ^. +Echo This must correspond to a sub-directory under the board directory at +Echo under nuttx/configs/^/. +Echo ^<-h^>: +Echo Prints this message and exits. + +REM Exit + +:End + From 2f3303526fe2c41cea0782bd143959e88415637e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Aug 2015 08:09:14 -0600 Subject: [PATCH 05/23] apps/examples/can: In extended ID mode, need to set some unused bits to zero or otherwise the memcmp() will fail on comparison with the returned value --- examples/can/can_main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/can/can_main.c b/examples/can/can_main.c index 9daafc56a..b309f2b7c 100644 --- a/examples/can/can_main.c +++ b/examples/can/can_main.c @@ -204,11 +204,12 @@ int can_main(int argc, char *argv[]) /* Construct the next TX message */ #ifndef CONFIG_EXAMPLES_CAN_READONLY - txmsg.cm_hdr.ch_id = msgid; - txmsg.cm_hdr.ch_rtr = false; - txmsg.cm_hdr.ch_dlc = msgdlc; + txmsg.cm_hdr.ch_id = msgid; + txmsg.cm_hdr.ch_rtr = false; + txmsg.cm_hdr.ch_dlc = msgdlc; #ifdef CONFIG_CAN_EXTID - txmsg.cm_hdr.ch_extid = true; + txmsg.cm_hdr.ch_extid = true; + txmsg.cm_hdr.ch_unused = 0; #endif for (i = 0; i < msgdlc; i++) From 54235ebb8dff78eb2415d9c4df02f96605c5d852 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 13 Aug 2015 11:52:55 -0600 Subject: [PATCH 06/23] Prep for 7.11 release --- ChangeLog.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index eb7ce483f..110299924 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1313,7 +1313,7 @@ * apps/nshlib/: The NSH mount command now recognizes the Union file system type when listing mounted file systems (2015-06-07). -7.11 2015-xx-xx Gregory Nutt +7.11 2015-08-13 Gregory Nutt * apps/netutils/thttpd: Fix compilation problems when CONFIG_THTTPD_GENERATE_INDICES is defined (2015-06-12). @@ -1359,7 +1359,7 @@ don't have the wherewithal for that change today (2015-04-14)`. * apps/nshlib and apps/examaples/thttpd: Change decoding to handle the increased size of the scheduling policy field in the TCB (2015-07-23). - * apps/examples/ostest: Improve syncrhonization in round robin tests. + * apps/examples/ostest: Improve synchronization in round robin tests. On very fast processors, there are race conditions that make the test failure. Need better interlocking to assure that the threads actually do start at the same time (2015-07-24). @@ -1394,3 +1394,4 @@ apps/tools/mkkconfig.sh. Needed for a Windows native build. Untested on initial commit (2015-08-12). +7.12 2015-xx-xx Gregory Nutt From c11c4d6bd9f577112d9b91298738dbca5393eed3 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 14 Aug 2015 10:12:35 -0600 Subject: [PATCH 07/23] Add si_errno to siginfo_t --- examples/elf/tests/signal/signal.c | 3 ++- examples/nxflat/tests/signal/signal.c | 3 ++- examples/ostest/sighand.c | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/elf/tests/signal/signal.c b/examples/elf/tests/signal/signal.c index d43f012cb..089c56510 100644 --- a/examples/elf/tests/signal/signal.c +++ b/examples/elf/tests/signal/signal.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/elf/tests/signal/signal.c * - * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2012, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -100,6 +100,7 @@ void siguser_action(int signo, siginfo_t *siginfo, void *arg) printf("siginfo:\n"); printf(" si_signo = %d\n", siginfo->si_signo); printf(" si_code = %d\n", siginfo->si_code); + printf(" si_errno = %d\n", siginfo->si_errno); printf(" si_value = %d\n", siginfo->si_value.sival_int); } } diff --git a/examples/nxflat/tests/signal/signal.c b/examples/nxflat/tests/signal/signal.c index ac03f6d33..8032b5cf1 100644 --- a/examples/nxflat/tests/signal/signal.c +++ b/examples/nxflat/tests/signal/signal.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/nxflat/tests/signal/signal.c * - * Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2009, 2012, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -100,6 +100,7 @@ void siguser_action(int signo, siginfo_t *siginfo, void *arg) printf("siginfo:\n"); printf(" si_signo = %d\n", siginfo->si_signo); printf(" si_code = %d\n", siginfo->si_code); + printf(" si_errno = %d\n", siginfo->si_errno); printf(" si_value = %d\n", siginfo->si_value.sival_int); } } diff --git a/examples/ostest/sighand.c b/examples/ostest/sighand.c index cacfb6072..c3454b5d2 100644 --- a/examples/ostest/sighand.c +++ b/examples/ostest/sighand.c @@ -78,8 +78,10 @@ static void death_of_child(int signo, siginfo_t *info, void *ucontext) if (info) { - printf("death_of_child: PID %d received signal=%d code=%d pid=%d status=%d\n", - getpid(), signo, info->si_code, info->si_pid, info->si_status); + printf("death_of_child: PID %d received signal=%d code=%d " + "errno=%d pid=%d status=%d\n", + getpid(), signo, info->si_code, info->si_errno, + info->si_pid, info->si_status); } else { From 64e1548bb7f9b2b99b4e6eab8ff1026aaf4972dc Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 17 Aug 2015 11:07:39 -0600 Subject: [PATCH 08/23] apps/examples/can: Extended the CAN test by adding more command line options --- ChangeLog.txt | 4 + examples/can/Kconfig | 7 ++ examples/can/can_main.c | 162 +++++++++++++++++++++++++++++++++------- 3 files changed, 148 insertions(+), 25 deletions(-) mode change 100644 => 100755 ChangeLog.txt diff --git a/ChangeLog.txt b/ChangeLog.txt old mode 100644 new mode 100755 index 110299924..c6448b4bb --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1395,3 +1395,7 @@ on initial commit (2015-08-12). 7.12 2015-xx-xx Gregory Nutt + + * apps/examples/can: Extend the CAN loopback test by adding more + command line options (2015-08-17). + diff --git a/examples/can/Kconfig b/examples/can/Kconfig index 70092c5e2..dfef83c53 100644 --- a/examples/can/Kconfig +++ b/examples/can/Kconfig @@ -10,5 +10,12 @@ config EXAMPLES_CAN Enable the CAN example if EXAMPLES_CAN + +config EXAMPLES_CAN_NMSGS + int "Number of Messages" + default 32 + ---help--- + The number of CAN messages to send before returning + endif diff --git a/examples/can/can_main.c b/examples/can/can_main.c index b309f2b7c..3f5232b51 100644 --- a/examples/can/can_main.c +++ b/examples/can/can_main.c @@ -70,10 +70,17 @@ # define CAN_OFLAGS O_RDWR #endif +#ifndef CONFIG_EXAMPLES_CAN_NMSGS +# define CONFIG_EXAMPLES_CAN_NMSGS 32 +#endif + +#define MAX_EXTID (1 << 29) +#define MAX_STDID (1 << 11) + #ifdef CONFIG_CAN_EXTID -# define MAX_ID (1 << 29) +# define MAX_ID MAX_EXTID #else -# define MAX_ID (1 << 11) +# define MAX_ID MAX_STDID #endif /**************************************************************************** @@ -96,6 +103,27 @@ * Private Functions ****************************************************************************/ +static void show_usage(FAR const char *progname) +{ +#ifdef CONFIG_CAN_EXTID + fprintf(stderr, "USAGE: %s [-s] [-n ] [b ]\n", + progname); +#else + fprintf(stderr, "USAGE: %s [-n ] [b ]\n", + progname); +#endif + fprintf(stderr, "USAGE: %s -h\n", + progname); + fprintf(stderr, "\nWhere:\n"); +#ifdef CONFIG_CAN_EXTID + fprintf(stderr, "-s: Use standard IDs. Default: Extended ID\n"); +#endif + fprintf(stderr, "-n : The number of messages to send. Default: 32\n"); + fprintf(stderr, "-a : The start message id. Default 1\n"); + fprintf(stderr, "-b : The start message id. Default %d\n", MAX_ID - 1); + fprintf(stderr, "-h: Show this message and exit\n"); +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -113,10 +141,13 @@ int can_main(int argc, char *argv[]) #ifndef CONFIG_EXAMPLES_CAN_READONLY struct can_msg_s txmsg; #ifdef CONFIG_CAN_EXTID + bool extended; uint32_t msgid; #else uint16_t msgid; #endif + long minid; + long maxid; int msgdlc; uint8_t msgdata; #endif @@ -127,31 +158,118 @@ int can_main(int argc, char *argv[]) size_t msgsize; ssize_t nbytes; -#if defined(CONFIG_NSH_BUILTIN_APPS) || defined(CONFIG_EXAMPLES_CAN_NMSGS) + bool badarg; + bool help; long nmsgs; -#endif - + int option; int fd; int errval = 0; int ret; int i; - /* If this example is configured as an NX add-on, then limit the number of - * samples that we collect before returning. Otherwise, we never return - */ + /* Parse command line parameters */ -#if defined(CONFIG_NSH_BUILTIN_APPS) - nmsgs = CONFIG_EXAMPLES_CAN_NMSGS; - if (argc > 1) + nmsgs = CONFIG_EXAMPLES_CAN_NMSGS; + minid = 1; + maxid = MAX_ID - 1; + badarg = false; +#ifdef CONFIG_CAN_EXTID + extended = true; +#endif + badarg = false; + help = false; + +#ifdef CONFIG_CAN_EXTID + while ((option = getopt(argc, argv, ":n:a:b:hs")) != ERROR) +#else + while ((option = getopt(argc, argv, ":n:a:b:h")) != ERROR) +#endif { - nmsgs = strtol(argv[1], NULL, 10); + switch (option) + { + case 'a': + minid = strtol(optarg, NULL, 10); + if (minid < 1 || minid > maxid) + { + fprintf(stderr, " out of range\n"); + badarg = true; + } + break; + + case 'b': + maxid = strtol(optarg, NULL, 10); + if (maxid < minid || maxid >= MAX_ID) + { + fprintf(stderr, "ERROR: out of range\n"); + badarg = true; + } + break; + + case 'h': + help = true; + break; + +#ifdef CONFIG_CAN_EXTID + case 's': + extended = false; + break; +#endif + + case 'n': + nmsgs = strtol(optarg, NULL, 10); + if (nmsgs < 1) + { + fprintf(stderr, "ERROR: out of range\n"); + badarg = true; + } + break; + + case ':': + fprintf(stderr, "ERROR: Bad option argument\n"); + badarg = true; + break; + + case '?': + default: + fprintf(stderr, "ERROR: Unrecognized option\n"); + badarg = true; + break; + } } - printf("can_main: nmsgs: %ld\n", nmsgs); -#elif defined(CONFIG_EXAMPLES_CAN_NMSGS) - printf("can_main: nmsgs: %d\n", CONFIG_EXAMPLES_CAN_NMSGS); + if (badarg) + { + show_usage(argv[0]); + return EXIT_FAILURE; + } + + if (help) + { + show_usage(argv[0]); + return EXIT_SUCCESS; + } + +#ifdef CONFIG_CAN_EXTID + if (!extended && maxid >= MAX_STDID) + { + maxid = MAX_STDID - 1; + if (minid > maxid) + { + minid = maxid; + } + } #endif + if (optind != argc) + { + fprintf(stderr, "ERROR: Garbage on command line\n"); + show_usage(argv[0]); + return EXIT_FAILURE; + } + + printf("can_main: nmsgs: %d min ID: %d max ID: %d\n", + nmsgs, minid, maxid); + /* Initialization of the CAN hardware is performed by logic external to * this test. */ @@ -183,17 +301,11 @@ int can_main(int argc, char *argv[]) #ifndef CONFIG_EXAMPLES_CAN_READONLY msgdlc = 1; - msgid = 1; + msgid = minid; msgdata = 0; #endif -#if defined(CONFIG_NSH_BUILTIN_APPS) - for (; nmsgs > 0; nmsgs--) -#elif defined(CONFIG_EXAMPLES_CAN_NMSGS) for (nmsgs = 0; nmsgs < CONFIG_EXAMPLES_CAN_NMSGS; nmsgs++) -#else - for (;;) -#endif { /* Flush any output before the loop entered or from the previous pass * through the loop. @@ -208,7 +320,7 @@ int can_main(int argc, char *argv[]) txmsg.cm_hdr.ch_rtr = false; txmsg.cm_hdr.ch_dlc = msgdlc; #ifdef CONFIG_CAN_EXTID - txmsg.cm_hdr.ch_extid = true; + txmsg.cm_hdr.ch_extid = extended; txmsg.cm_hdr.ch_unused = 0; #endif @@ -285,9 +397,9 @@ int can_main(int argc, char *argv[]) #ifndef CONFIG_EXAMPLES_CAN_READONLY msgdata += msgdlc; - if (++msgid >= MAX_ID) + if (++msgid > maxid) { - msgid = 1; + msgid = minid; } if (++msgdlc > CAN_MAXDATALEN) From 546450cc92da599050fe1f4377c93c936ec233f5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 17 Aug 2015 11:57:25 -0600 Subject: [PATCH 09/23] apps/examples/can: Fix usage of new number-of-messages command line option --- examples/can/can_main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/can/can_main.c b/examples/can/can_main.c index 3f5232b51..b60cc3810 100644 --- a/examples/can/can_main.c +++ b/examples/can/can_main.c @@ -164,6 +164,7 @@ int can_main(int argc, char *argv[]) int option; int fd; int errval = 0; + int msgno; int ret; int i; @@ -305,7 +306,7 @@ int can_main(int argc, char *argv[]) msgdata = 0; #endif - for (nmsgs = 0; nmsgs < CONFIG_EXAMPLES_CAN_NMSGS; nmsgs++) + for (msgno = 0; msgno < nmsgs; msgno++) { /* Flush any output before the loop entered or from the previous pass * through the loop. From cb25507a064435792026f29e58178fed1fc6587f Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Aug 2015 08:50:14 -0600 Subject: [PATCH 10/23] apps/examples/can: Extend test to report an errors reported by the CAN driver --- examples/can/can_main.c | 212 ++++++++++++++++++++++++++-------------- 1 file changed, 141 insertions(+), 71 deletions(-) diff --git a/examples/can/can_main.c b/examples/can/can_main.c index b60cc3810..31ad280fd 100644 --- a/examples/can/can_main.c +++ b/examples/can/can_main.c @@ -307,108 +307,178 @@ int can_main(int argc, char *argv[]) #endif for (msgno = 0; msgno < nmsgs; msgno++) - { - /* Flush any output before the loop entered or from the previous pass - * through the loop. - */ + { + /* Flush any output before the loop entered or from the previous pass + * through the loop. + */ - fflush(stdout); + fflush(stdout); - /* Construct the next TX message */ + /* Construct the next TX message */ #ifndef CONFIG_EXAMPLES_CAN_READONLY - txmsg.cm_hdr.ch_id = msgid; - txmsg.cm_hdr.ch_rtr = false; - txmsg.cm_hdr.ch_dlc = msgdlc; + txmsg.cm_hdr.ch_id = msgid; + txmsg.cm_hdr.ch_rtr = false; + txmsg.cm_hdr.ch_dlc = msgdlc; + txmsg.cm_hdr.ch_error = 0; #ifdef CONFIG_CAN_EXTID - txmsg.cm_hdr.ch_extid = extended; - txmsg.cm_hdr.ch_unused = 0; + txmsg.cm_hdr.ch_extid = extended; #endif + txmsg.cm_hdr.ch_unused = 0; - for (i = 0; i < msgdlc; i++) - { - txmsg.cm_data[i] = msgdata + i; - } + for (i = 0; i < msgdlc; i++) + { + txmsg.cm_data[i] = msgdata + i; + } - /* Send the TX message */ + /* Send the TX message */ - msgsize = CAN_MSGLEN(msgdlc); - nbytes = write(fd, &txmsg, msgsize); - if (nbytes != msgsize) - { - printf("ERROR: write(%ld) returned %ld\n", (long)msgsize, (long)nbytes); - errval = 3; - goto errout_with_dev; - } + msgsize = CAN_MSGLEN(msgdlc); + nbytes = write(fd, &txmsg, msgsize); + if (nbytes != msgsize) + { + printf("ERROR: write(%ld) returned %ld\n", + (long)msgsize, (long)nbytes); + errval = 3; + goto errout_with_dev; + } #endif #ifdef CONFIG_EXAMPLES_CAN_WRITEONLY - printf(" ID: %4u DLC: %d\n", msgid, msgdlc); + printf(" ID: %4u DLC: %d\n", msgid, msgdlc); #endif - /* Read the RX message */ + /* Read the RX message */ #ifndef CONFIG_EXAMPLES_CAN_WRITEONLY - msgsize = sizeof(struct can_msg_s); - nbytes = read(fd, &rxmsg, msgsize); - if (nbytes < CAN_MSGLEN(0) || nbytes > msgsize) - { - printf("ERROR: read(%ld) returned %ld\n", (long)msgsize, (long)nbytes); - errval = 4; - goto errout_with_dev; - } + msgsize = sizeof(struct can_msg_s); + nbytes = read(fd, &rxmsg, msgsize); + if (nbytes < CAN_MSGLEN(0) || nbytes > msgsize) + { + printf("ERROR: read(%ld) returned %ld\n", + (long)msgsize, (long)nbytes); + errval = 4; + goto errout_with_dev; + } #endif #ifndef CONFIG_EXAMPLES_CAN_READONLY - printf(" ID: %4u DLC: %u\n", rxmsg.cm_hdr.ch_id, rxmsg.cm_hdr.ch_dlc); + printf(" ID: %4u DLC: %u\n", + rxmsg.cm_hdr.ch_id, rxmsg.cm_hdr.ch_dlc); #endif - /* Verify that the received messages are the same */ + /* Check for error reports */ + +#ifndef CONFIG_EXAMPLES_CAN_WRITEONLY + if (rxmsg.cm_hdr.ch_error != 0) + { + printf("ERROR: CAN error report: [%04x]\n", rxmsg.cm_hdr.ch_id); + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_SYSTEM) != 0) + { + printf(" Driver internal error\n"); + } + + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_RXLOST) != 0) + { + printf(" RX Message Lost\n"); + } + + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_TXLOST) != 0) + { + printf(" TX Message Lost\n"); + } + + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_ACCESS) != 0) + { + printf(" RAM Access Failure\n"); + } + + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_TIMEOUT) != 0) + { + printf(" Timeout Occurred\n"); + } + + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_PASSIVE) != 0) + { + printf(" Error Passive\n"); + } + + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_CRC) != 0) + { + printf(" RX CRC Error\n"); + } + + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_BIT) != 0) + { + printf(" Bit Error\n"); + } + + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_ACK) != 0) + { + printf(" Acknowledge Error\n"); + } + + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_FORMAT) != 0) + { + printf(" Format Error\n"); + } + + if ((rxmsg.cm_hdr.ch_id & CAN_ERROR_STUFF) != 0) + { + printf(" Stuff Error\n"); + } + } + else + { + /* Verify that the received messages are the same */ #ifdef CONFIG_EXAMPLES_CAN_READWRITE - if (memcmp(&txmsg.cm_hdr, &rxmsg.cm_hdr, sizeof(struct can_hdr_s)) != 0) - { - printf("ERROR: Sent header does not match received header:\n"); - lib_dumpbuffer("Sent header", (FAR const uint8_t*)&txmsg.cm_hdr, - sizeof(struct can_hdr_s)); - lib_dumpbuffer("Received header", (FAR const uint8_t*)&rxmsg.cm_hdr, - sizeof(struct can_hdr_s)); - errval = 4; - goto errout_with_dev; - } + if (memcmp(&txmsg.cm_hdr, &rxmsg.cm_hdr, sizeof(struct can_hdr_s)) != 0) + { + printf("ERROR: Sent header does not match received header:\n"); + lib_dumpbuffer("Sent header", (FAR const uint8_t*)&txmsg.cm_hdr, + sizeof(struct can_hdr_s)); + lib_dumpbuffer("Received header", (FAR const uint8_t*)&rxmsg.cm_hdr, + sizeof(struct can_hdr_s)); + errval = 4; + goto errout_with_dev; + } - if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgdlc) != 0) - { - printf("ERROR: Data does not match. DLC=%d\n", msgdlc); - for (i = 0; i < msgdlc; i++) - { - printf(" %d: TX %02x RX %02x\n", i, txmsg.cm_data[i], rxmsg.cm_data[i]); - errval = 5; - goto errout_with_dev; - } - } - - /* Report success */ - - printf(" ID: %4u DLC: %d -- OK\n", msgid, msgdlc); + if (memcmp(txmsg.cm_data, rxmsg.cm_data, msgdlc) != 0) + { + printf("ERROR: Data does not match. DLC=%d\n", msgdlc); + for (i = 0; i < msgdlc; i++) + { + printf(" %d: TX %02x RX %02x\n", + i, txmsg.cm_data[i], rxmsg.cm_data[i]); + errval = 5; + goto errout_with_dev; + } + } + } #endif - /* Set up for the next pass */ + /* Report success */ + + printf(" ID: %4u DLC: %d -- OK\n", msgid, msgdlc); +#endif + + /* Set up for the next pass */ #ifndef CONFIG_EXAMPLES_CAN_READONLY - msgdata += msgdlc; + msgdata += msgdlc; - if (++msgid > maxid) - { - msgid = minid; - } + if (++msgid > maxid) + { + msgid = minid; + } - if (++msgdlc > CAN_MAXDATALEN) - { - msgdlc = 1; - } + if (++msgdlc > CAN_MAXDATALEN) + { + msgdlc = 1; + } #endif - } + } errout_with_dev: close(fd); From 9abb28c725f9151d81a0f0a2c17a4fb5e1e18384 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Aug 2015 11:21:47 -0600 Subject: [PATCH 11/23] apps/examples/can: Use new IOCTL commands to show the current bit timing values --- examples/can/can_main.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/examples/can/can_main.c b/examples/can/can_main.c index 31ad280fd..d9cb977db 100644 --- a/examples/can/can_main.c +++ b/examples/can/can_main.c @@ -40,6 +40,7 @@ #include #include +#include #include #include @@ -138,6 +139,7 @@ int main(int argc, FAR char *argv[]) int can_main(int argc, char *argv[]) #endif { + struct canioc_bittiming_s bt; #ifndef CONFIG_EXAMPLES_CAN_READONLY struct can_msg_s txmsg; #ifdef CONFIG_CAN_EXTID @@ -296,6 +298,24 @@ int can_main(int argc, char *argv[]) goto errout_with_dev; } + /* Show bit timing information .. if provided by the driver. Not all CAN + * drivers will support this IOCTL. + */ + + ret = ioctl(fd, CANIOC_GET_BITTIMING, (unsigned long)((uintptr_t)&bt)); + if (ret < 0) + { + printf("Bit timing not available: %d\n", errno); + } + else + { + printf("Bit timing:\n"); + printf(" Baud: %lu\n", (unsigned long)bt.bt_baud); + printf(" TSEG1: %u\n", bt.bt_tseg1); + printf(" TSEG2: %u\n", bt.bt_tseg2); + printf(" SJW: %u\n", bt.bt_sjw); + } + /* Now loop the appropriate number of times, performing one loopback test * on each pass. */ From e35f64a3cf27a61e2106771c5d363bfb7e7effa5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Aug 2015 12:41:10 -0600 Subject: [PATCH 12/23] apps/examples/can: Trivial clean/simplification for test output --- examples/can/can_main.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/examples/can/can_main.c b/examples/can/can_main.c index d9cb977db..efe6d3a42 100644 --- a/examples/can/can_main.c +++ b/examples/can/can_main.c @@ -270,29 +270,26 @@ int can_main(int argc, char *argv[]) return EXIT_FAILURE; } - printf("can_main: nmsgs: %d min ID: %d max ID: %d\n", - nmsgs, minid, maxid); + printf("nmsgs: %d min ID: %d max ID: %d\n", nmsgs, minid, maxid); /* Initialization of the CAN hardware is performed by logic external to * this test. */ - printf("can_main: Initializing external CAN device\n"); ret = can_devinit(); if (ret != OK) { - printf("can_main: can_devinit failed: %d\n", ret); + printf("ERROR: can_devinit failed: %d\n", ret); errval = 1; goto errout; } /* Open the CAN device for reading */ - printf("can_main: Hardware initialized. Opening the CAN device\n"); fd = open(CONFIG_EXAMPLES_CAN_DEVPATH, CAN_OFLAGS); if (fd < 0) { - printf("can_main: open %s failed: %d\n", + printf("ERROR: open %s failed: %d\n", CONFIG_EXAMPLES_CAN_DEVPATH, errno); errval = 2; goto errout_with_dev; From bc2cf8affdacea22f7fd9f337a7cba94a9507954 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 18 Aug 2015 13:25:30 -0600 Subject: [PATCH 13/23] apps/examples/can: Remove can_devinit(). Replace with boardctl(BOARDIOC_CAN_INITIAILIZE,0) --- examples/can/Kconfig | 2 ++ examples/can/can.h | 11 ----------- examples/can/can_main.c | 5 +++-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/examples/can/Kconfig b/examples/can/Kconfig index dfef83c53..b0afb0dad 100644 --- a/examples/can/Kconfig +++ b/examples/can/Kconfig @@ -6,6 +6,8 @@ config EXAMPLES_CAN bool "CAN example" default n + depends on CAN && LIB_BOARDCTL + select BOARDCTL_CANINIT ---help--- Enable the CAN example diff --git a/examples/can/can.h b/examples/can/can.h index 794a84b33..b3d14a3d3 100644 --- a/examples/can/can.h +++ b/examples/can/can.h @@ -97,15 +97,4 @@ * Public Function Prototypes ****************************************************************************/ -/**************************************************************************** - * Name: can_devinit() - * - * Description: - * Perform architecuture-specific initialization of the CAN hardware. This - * interface must be provided by all configurations using apps/examples/can - * - ****************************************************************************/ - -int can_devinit(void); - #endif /* __APPS_EXAMPLES_CAN_CAN_H */ diff --git a/examples/can/can_main.c b/examples/can/can_main.c index efe6d3a42..b25269d5c 100644 --- a/examples/can/can_main.c +++ b/examples/can/can_main.c @@ -41,6 +41,7 @@ #include #include +#include #include #include @@ -276,10 +277,10 @@ int can_main(int argc, char *argv[]) * this test. */ - ret = can_devinit(); + ret = boardctl(BOARDIOC_CAN_INITIALIZE, 0); if (ret != OK) { - printf("ERROR: can_devinit failed: %d\n", ret); + printf("ERROR: BOARDIOC_CAN_INITIALIZE failed: %d\n", ret); errval = 1; goto errout; } From d836478728624600e198738ecaed2dc8036c451b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 20 Aug 2015 10:40:31 -0600 Subject: [PATCH 14/23] apps/examples/usbserial: Can now be run as an NSH builtin-function. Now uses a configurable IO buffer size --- ChangeLog.txt | 2 ++ examples/usbserial/Kconfig | 7 ++++++ examples/usbserial/Makefile | 12 +++++++++ examples/usbserial/Makefile.host | 5 +++- examples/usbserial/host.c | 19 ++++++++++---- examples/usbserial/usbserial_main.c | 39 ++++++++++++++++++++--------- 6 files changed, 66 insertions(+), 18 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index c6448b4bb..9b205521c 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1398,4 +1398,6 @@ * apps/examples/can: Extend the CAN loopback test by adding more command line options (2015-08-17). + * apps/examples/usbserial: Can now be run as an NSH builtin-function. + Now uses a configurable IO buffer size (2015-08-20). diff --git a/examples/usbserial/Kconfig b/examples/usbserial/Kconfig index 1fd4e9b18..0ceea5d75 100644 --- a/examples/usbserial/Kconfig +++ b/examples/usbserial/Kconfig @@ -11,6 +11,13 @@ config EXAMPLES_USBSERIAL if EXAMPLES_USBSERIAL +config EXAMPLES_USBSERIAL_BUFSIZE + int "Target I/O Buffer Size" + default 512 + ---help--- + The size of the array that is used as an I/O buffer for USB serial + data transfers. + config EXAMPLES_USBSERIAL_TRACEINIT bool "USB Trace Initialization" default n diff --git a/examples/usbserial/Makefile b/examples/usbserial/Makefile index 78dd4b1c7..f7d0b9602 100644 --- a/examples/usbserial/Makefile +++ b/examples/usbserial/Makefile @@ -37,6 +37,11 @@ include $(APPDIR)/Make.defs # USB serial device example +# Built-in application info + +APPNAME = usbserial +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 2048 ASRCS = CSRCS = @@ -104,7 +109,14 @@ install: endif +ifeq ($(CONFIG_NSH_BUILTIN_APPS),y) +$(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat: $(DEPCONFIG) Makefile + $(call REGISTER,$(APPNAME),$(PRIORITY),$(STACKSIZE),$(APPNAME)_main) + +context: $(BUILTIN_REGISTRY)$(DELIM)$(APPNAME)_main.bdat +else context: +endif .depend: Makefile $(SRCS) @$(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep diff --git a/examples/usbserial/Makefile.host b/examples/usbserial/Makefile.host index 2dbaa7e92..c6ebf54e5 100644 --- a/examples/usbserial/Makefile.host +++ b/examples/usbserial/Makefile.host @@ -1,7 +1,7 @@ ############################################################################ # apps/examples/usbserial/Makefile.host # -# Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved. +# Copyright (C) 2008, 2011, 2015 Gregory Nutt. All rights reserved. # Author: Gregory Nutt # # Redistribution and use in source and binary forms, with or without @@ -53,6 +53,9 @@ endif ifeq ($(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG),y) DEFINES += -DCONFIG_EXAMPLES_USBSERIAL_ONLYBIG=1 endif +ifeq ($(CONFIG_CDCACM),y) +DEFINES += -DCONFIG_CDCACM=1 +endif all: $(BIN) diff --git a/examples/usbserial/host.c b/examples/usbserial/host.c index 37ff9efa8..1ccfce124 100644 --- a/examples/usbserial/host.c +++ b/examples/usbserial/host.c @@ -50,7 +50,7 @@ #include /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ #if defined(CONFIG_EXAMPLES_USBSERIAL_INONLY) && defined(CONFIG_EXAMPLES_USBSERIAL_OUTONLY) @@ -181,6 +181,7 @@ int main(int argc, char **argv, char **envp) fprintf(stderr, "Too many arguments on command line\n"); show_usage(argv[0], 1); } + g_ttydev = argv[1]; } @@ -192,13 +193,15 @@ int main(int argc, char **argv, char **envp) fd = open(g_ttydev, O_RDWR); if (fd < 0) { - printf("main: ERROR: Failed to open %s: %s\n", g_ttydev, strerror(errno)); + printf("main: ERROR: Failed to open %s: %s\n", + g_ttydev, strerror(errno)); printf("main: Assume not connected. Wait and try again.\n"); printf("main: (Control-C to terminate).\n"); sleep(5); } } while (fd < 0); + printf("main: Successfully opened the serial driver\n"); /* Configure the serial port in raw mode (at least turn off echo) */ @@ -206,7 +209,8 @@ int main(int argc, char **argv, char **envp) ret = tcgetattr(fd, &tty); if (ret < 0) { - printf("main: ERROR: Failed to get termios for %s: %s\n", g_ttydev, strerror(errno)); + printf("main: ERROR: Failed to get termios for %s: %s\n", + g_ttydev, strerror(errno)); close(fd); return 1; } @@ -220,7 +224,8 @@ int main(int argc, char **argv, char **envp) ret = tcsetattr(fd, TCSANOW, &tty); if (ret < 0) { - printf("main: ERROR: Failed to set termios for %s: %s\n", g_ttydev, strerror(errno)); + printf("main: ERROR: Failed to set termios for %s: %s\n", + g_ttydev, strerror(errno)); close(fd); return 1; } @@ -237,7 +242,8 @@ int main(int argc, char **argv, char **envp) nbytes = read(fd, g_iobuffer, BUFFER_SIZE-1); if (nbytes < 0) { - printf("main: ERROR: Failed to read from %s: %s\n", g_ttydev, strerror(errno)); + printf("main: ERROR: Failed to read from %s: %s\n", + g_ttydev, strerror(errno)); close(fd); return 2; } @@ -271,9 +277,11 @@ int main(int argc, char **argv, char **envp) nbytes = write(fd, g_longmsg, sizeof(g_longmsg)); count = 0; } + #elif !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL) printf("main: Sending %d bytes..\n", sizeof(g_longmsg)); nbytes = write(fd, g_longmsg, sizeof(g_longmsg)); + #else /* !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG) */ printf("main: Sending %d bytes..\n", sizeof(g_shortmsg)); nbytes = write(fd, g_shortmsg, sizeof(g_shortmsg)); @@ -287,6 +295,7 @@ int main(int argc, char **argv, char **envp) close(fd); return 2; } + printf("main: %ld bytes sent\n", (long)nbytes); #endif /* CONFIG_EXAMPLES_USBSERIAL_INONLY */ } diff --git a/examples/usbserial/usbserial_main.c b/examples/usbserial/usbserial_main.c index 13c4bdb5c..7a80d90e6 100644 --- a/examples/usbserial/usbserial_main.c +++ b/examples/usbserial/usbserial_main.c @@ -1,7 +1,7 @@ /**************************************************************************** * examples/usbserial/usbserial_main.c * - * Copyright (C) 2008, 2010-2012 Gregory Nutt. All rights reserved. + * Copyright (C) 2008, 2010-2012, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -56,7 +56,7 @@ #endif /**************************************************************************** - * Definitions + * Pre-processor Definitions ****************************************************************************/ #if defined(CONFIG_EXAMPLES_USBSERIAL_INONLY) && defined(CONFIG_EXAMPLES_USBSERIAL_OUTONLY) @@ -113,7 +113,9 @@ # define USBSER_DEVNAME "/dev/ttyUSB0" #endif -#define IOBUFFER_SIZE 256 +#ifndef CONFIG_EXAMPLES_USBSERIAL_BUFSIZE +# define CONFIG_EXAMPLES_USBSERIAL_BUFSIZE 256 +#endif /**************************************************************************** * Private Data @@ -153,7 +155,7 @@ static const char g_longmsg[] = #endif #ifndef CONFIG_EXAMPLES_USBSERIAL_INONLY -static char g_iobuffer[IOBUFFER_SIZE]; +static char g_iobuffer[CONFIG_EXAMPLES_USBSERIAL_BUFSIZE]; #endif /**************************************************************************** @@ -214,9 +216,11 @@ int usbserial_main(int argc, char *argv[]) #endif if (ret < 0) { - printf("usbserial_main: ERROR: Failed to create the USB serial device: %d\n", -ret); + printf("usbserial_main: ERROR: Failed to create the USB serial device: %d\n", + -ret); return 1; } + printf("usbserial_main: Successfully registered the serial driver\n"); #if CONFIG_USBDEV_TRACE && CONFIG_USBDEV_TRACE_INITIALIDSET != 0 @@ -242,7 +246,8 @@ int usbserial_main(int argc, char *argv[]) if (outfd < 0) { int errcode = errno; - printf("usbserial_main: ERROR: Failed to open " USBSER_DEVNAME " for writing: %d\n", errcode); + printf("usbserial_main: ERROR: Failed to open " USBSER_DEVNAME + " for writing: %d\n", errcode); /* ENOTCONN means that the USB device is not yet connected */ @@ -274,7 +279,8 @@ int usbserial_main(int argc, char *argv[]) infd = open(USBSER_DEVNAME, O_RDONLY|O_NONBLOCK); if (infd < 0) { - printf("usbserial_main: ERROR: Failed to open " USBSER_DEVNAME " for reading: %d\n", errno); + printf("usbserial_main: ERROR: Failed to open " USBSER_DEVNAME + " for reading: %d\n", errno); close(outfd); return 3; } @@ -285,7 +291,8 @@ int usbserial_main(int argc, char *argv[]) if (infd < 0) { int errcode = errno; - printf("usbserial_main: ERROR: Failed to open " USBSER_DEVNAME " for reading: %d\n", errno); + printf("usbserial_main: ERROR: Failed to open " USBSER_DEVNAME + " for reading: %d\n", errno); /* ENOTCONN means that the USB device is not yet connected */ @@ -333,9 +340,11 @@ int usbserial_main(int argc, char *argv[]) nbytes = write(outfd, g_longmsg, sizeof(g_longmsg)); count = 0; } + #elif !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYSMALL) printf("usbserial_main: Reciting QEI's speech of 1588\n"); nbytes = write(outfd, g_longmsg, sizeof(g_longmsg)); + #else /* !defined(CONFIG_EXAMPLES_USBSERIAL_ONLYBIG) */ printf("usbserial_main: Saying hello\n"); nbytes = write(outfd, g_shortmsg, sizeof(g_shortmsg)); @@ -352,6 +361,7 @@ int usbserial_main(int argc, char *argv[]) close(outfd); return 4; } + printf("usbserial_main: %ld bytes sent\n", (long)nbytes); #endif /* CONFIG_EXAMPLES_USBSERIAL_OUTONLY */ @@ -363,8 +373,8 @@ int usbserial_main(int argc, char *argv[]) printf("usbserial_main: Polling for OUT messages\n"); for (i = 0; i < 5; i++) { - memset(g_iobuffer, 'X', IOBUFFER_SIZE); - nbytes = read(infd, g_iobuffer, IOBUFFER_SIZE); + memset(g_iobuffer, 'X', CONFIG_EXAMPLES_USBSERIAL_BUFSIZE); + nbytes = read(infd, g_iobuffer, CONFIG_EXAMPLES_USBSERIAL_BUFSIZE); if (nbytes < 0) { int errorcode = errno; @@ -380,7 +390,7 @@ int usbserial_main(int argc, char *argv[]) } else { - printf("usbserial_main: Received l%d bytes:\n", (long)nbytes); + printf("usbserial_main: Received %ld bytes:\n", (long)nbytes); if (nbytes > 0) { for (j = 0; j < nbytes; j += 16) @@ -392,6 +402,7 @@ int usbserial_main(int argc, char *argv[]) { printf(" "); } + if (j+k < nbytes) { printf("%02x", g_iobuffer[j+k]); @@ -401,6 +412,7 @@ int usbserial_main(int argc, char *argv[]) printf(" "); } } + printf(" "); for (k = 0; k < 16; k++) { @@ -408,6 +420,7 @@ int usbserial_main(int argc, char *argv[]) { printf(" "); } + if (j+k < nbytes) { if (g_iobuffer[j+k] >= 0x20 && g_iobuffer[j+k] < 0x7f) @@ -424,12 +437,15 @@ int usbserial_main(int argc, char *argv[]) printf(" "); } } + printf("\n"); } } } + sleep(1); } + #else /* CONFIG_EXAMPLES_USBSERIAL_INONLY */ printf("usbserial_main: Waiting\n"); sleep(5); @@ -450,4 +466,3 @@ int usbserial_main(int argc, char *argv[]) #endif return 0; } - From 64fb2c63b682d0e6fc3db654d28478eb0443d0c2 Mon Sep 17 00:00:00 2001 From: Pavel Pisa Date: Thu, 20 Aug 2015 16:08:45 -0600 Subject: [PATCH 15/23] Correct numerous places where NETUTILS_DNSCLIENT was instead of NETDB_DNSCLIENT --- examples/bridge/Kconfig | 4 ++-- examples/discover/Kconfig | 2 +- examples/tcpecho/Kconfig | 2 +- examples/xmlrpc/Kconfig | 2 +- nshlib/Kconfig | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/bridge/Kconfig b/examples/bridge/Kconfig index 4ae08ecb6..c275fc331 100644 --- a/examples/bridge/Kconfig +++ b/examples/bridge/Kconfig @@ -47,7 +47,7 @@ config EXAMPLES_BRIDGE_NET1_DHCPC bool "DHCP Client" default n select NETUTILS_DHCPC - select NETUTILS_DNSCLIENT + select NETDB_DNSCLIENT config EXAMPLES_BRIDGE_NET1_NOMAC bool "Use Canned MAC Address" @@ -129,7 +129,7 @@ config EXAMPLES_BRIDGE_NET2_DHCPC bool "DHCP Client" default n select NETUTILS_DHCPC - select NETUTILS_DNSCLIENT + select NETDB_DNSCLIENT config EXAMPLES_BRIDGE_NET2_NOMAC bool "Use Canned MAC Address" diff --git a/examples/discover/Kconfig b/examples/discover/Kconfig index 4955be359..3f847d044 100644 --- a/examples/discover/Kconfig +++ b/examples/discover/Kconfig @@ -22,7 +22,7 @@ config EXAMPLES_DISCOVER_DHCPC default n depends on EXAMPLES_DISCOVER && !NSH_BUILTIN_APPS select NETUTILS_DHCPC - select NETUTILS_DNSCLIENT + select NETDB_DNSCLIENT config EXAMPLES_DISCOVER_NOMAC bool "Use Canned MAC Address" diff --git a/examples/tcpecho/Kconfig b/examples/tcpecho/Kconfig index c3760b744..b39e6abd8 100644 --- a/examples/tcpecho/Kconfig +++ b/examples/tcpecho/Kconfig @@ -31,7 +31,7 @@ config EXAMPLES_TCPECHO_DHCPC default n depends on EXAMPLES_TCPECHO && !NSH_BUILTIN_APPS select NETUTILS_DHCPC - select NETUTILS_DNSCLIENT + select NETDB_DNSCLIENT config EXAMPLES_TCPECHO_NOMAC bool "Use Canned MAC Address" diff --git a/examples/xmlrpc/Kconfig b/examples/xmlrpc/Kconfig index fd1f41dfc..6014b1a6b 100644 --- a/examples/xmlrpc/Kconfig +++ b/examples/xmlrpc/Kconfig @@ -23,7 +23,7 @@ config EXAMPLES_XMLRPC_DHCPC default n depends on EXAMPLES_XMLRPC && !NSH_BUILTIN_APPS select NETUTILS_DHCPC - select NETUTILS_DNSCLIENT + select NETDB_DNSCLIENT config EXAMPLES_XMLRPC_NOMAC bool "Use Canned MAC Address" diff --git a/nshlib/Kconfig b/nshlib/Kconfig index d1de1e8c0..27c302070 100644 --- a/nshlib/Kconfig +++ b/nshlib/Kconfig @@ -1239,7 +1239,7 @@ endmenu # IP Address Configuration config NSH_DNS bool "Use DNS" default n - depends on NSH_LIBRARY && NETUTILS_DNSCLIENT + depends on NSH_LIBRARY && NETDB_DNSCLIENT ---help--- Configure to use a DNS. From f73ee9d3528aa7313553116d32c3980a57e52a74 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 21 Aug 2015 09:29:38 -0600 Subject: [PATCH 16/23] apps/system/netdb would not build unless CONFIG_NETDB_HOSTFILE was defined because it needed gethostbyname. Noted by OrbitalFox --- ChangeLog.txt | 5 +++++ system/netdb/netdb_main.c | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ChangeLog.txt b/ChangeLog.txt index 9b205521c..cb47161df 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1400,4 +1400,9 @@ command line options (2015-08-17). * apps/examples/usbserial: Can now be run as an NSH builtin-function. Now uses a configurable IO buffer size (2015-08-20). + * Various Kconfig files in netutils: Fix some changes from from + NETUTILS_DNSCLIENT to NETDB_DNSCLIENT. From Pavel Pisa (2015-08-20). + * system/netdb: Failed to build if CONFIG_NET_HOSTFILE was not defined + because gethostbyaddr() was not available. Noted by OrbitalFox + (2015-08-21). diff --git a/system/netdb/netdb_main.c b/system/netdb/netdb_main.c index c195ad34d..4c0872179 100644 --- a/system/netdb/netdb_main.c +++ b/system/netdb/netdb_main.c @@ -65,6 +65,15 @@ # define CONFIG_SYSTEM_NETDB_PRIORITY 50 #endif +/* REVIST: Currently the availability of gethostbyaddr() depends on + * CONFIG_NETDB_HOSTFILE. That might not always be true, however. + */ + +#undef HAVE_GETHOSTBYADDR +#ifdef CONFIG_NETDB_HOSTFILE +# define HAVE_GETHOSTBYADDR 1 +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -73,8 +82,10 @@ static void show_usage(FAR const char *progname, int exitcode) noreturn_function static void show_usage(FAR const char *progname, int exitcode) { fprintf(stderr, "USAGE: %s --ipv4 \n", progname); +#ifdef HAVE_GETHOSTBYADDR fprintf(stderr, " %s --ipv6 \n", progname); fprintf(stderr, " %s --host \n", progname); +#endif fprintf(stderr, " %s --help\n", progname); exit(exitcode); } @@ -110,6 +121,7 @@ int netdb_main(int argc, char **argv) show_usage(argv[0], EXIT_FAILURE); } +#ifdef HAVE_GETHOSTBYADDR /* Handle: netdb --ipv4 */ else if (strcmp(argv[1], "--ipv4") == 0) @@ -161,6 +173,7 @@ int netdb_main(int argc, char **argv) return EXIT_FAILURE; } } +#endif /* HAVE_GETHOSTBYADDR */ /* Handle: netdb --host */ From c7d8ef0f7c80330e8b53c20169fd14eb81927526 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 23 Aug 2015 11:59:07 -0600 Subject: [PATCH 17/23] Move logic from nuttx/libc/symtab to apps/system/symtab --- ChangeLog.txt | 7 +++ include/symtab.h | 102 ++++++++++++++++++++++++++++++++++++++ system/Kconfig | 1 + system/Make.defs | 4 ++ system/Makefile | 2 +- system/symtab/.gitignore | 11 +++++ system/symtab/Kconfig | 15 ++++++ system/symtab/Makefile | 104 +++++++++++++++++++++++++++++++++++++++ system/symtab/README.txt | 61 +++++++++++++++++++++++ system/symtab/symtab.c | 79 +++++++++++++++++++++++++++++ 10 files changed, 385 insertions(+), 1 deletion(-) create mode 100644 include/symtab.h create mode 100644 system/symtab/.gitignore create mode 100644 system/symtab/Kconfig create mode 100644 system/symtab/Makefile create mode 100644 system/symtab/README.txt create mode 100644 system/symtab/symtab.c diff --git a/ChangeLog.txt b/ChangeLog.txt index cb47161df..cf8de35eb 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1405,4 +1405,11 @@ * system/netdb: Failed to build if CONFIG_NET_HOSTFILE was not defined because gethostbyaddr() was not available. Noted by OrbitalFox (2015-08-21). + * apps/system/symtab: Optional canned symtab inclusion to the build. When + option CONFIG_SYSTEM_SYMTAB is selected and symbol table file + libc/symtab/canned_symtab.inc is prepared then application can + use system provided complete symbol table. The option has + substantial effect on system image size. Mainly code/text. If + loading of applications at runtime is not planned do not select + this. From Pavel Pisa (2015-08-23). diff --git a/include/symtab.h b/include/symtab.h new file mode 100644 index 000000000..c1d59c51d --- /dev/null +++ b/include/symtab.h @@ -0,0 +1,102 @@ +/**************************************************************************** + * apps/include/symtab.h + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: 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. + * + ****************************************************************************/ + +#ifndef __APPS_INCLUDE_SYMTAB_H +#define __APPS_INCLUDE_SYMTAB_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* struct symbtab_s describes one entry in the symbol table. A symbol table + * is a fixed size array of struct symtab_s. The information is intentionally + * minimal and supports only: + * + * 1. Function pointers as sym_values. Of other kinds of values need to be + * supported, then typing information would also need to be included in + * the structure. + * + * 2. Fixed size arrays. There is no explicit provisional for dynamically + * adding or removing entries from the symbol table (realloc might be + * used for that purpose if needed). The intention is to support only + * fixed size arrays completely defined at compilation or link time. + */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: symtab_initialize + * + * Description: + * Setup a user provided symbol table. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void symtab_initialize(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __APPS_INCLUDE_SYMTAB_H */ + diff --git a/system/Kconfig b/system/Kconfig index 1d32f3a7e..a7fae6f7e 100644 --- a/system/Kconfig +++ b/system/Kconfig @@ -25,6 +25,7 @@ source "$APPSDIR/system/sudoku/Kconfig" source "$APPSDIR/system/lm75/Kconfig" source "$APPSDIR/system/vi/Kconfig" source "$APPSDIR/system/stackmonitor/Kconfig" +source "$APPSDIR/system/symtab/Kconfig" source "$APPSDIR/system/cdcacm/Kconfig" source "$APPSDIR/system/composite/Kconfig" source "$APPSDIR/system/usbmsc/Kconfig" diff --git a/system/Make.defs b/system/Make.defs index c7acecd61..b818a9709 100644 --- a/system/Make.defs +++ b/system/Make.defs @@ -114,6 +114,10 @@ ifeq ($(CONFIG_SYSTEM_STACKMONITOR),y) CONFIGURED_APPS += system/stackmonitor endif +ifeq ($(CONFIG_SYSTEM_SYMTAB),y) +CONFIGURED_APPS += system/symtab +endif + ifeq ($(CONFIG_SYSTEM_USBMSC),y) CONFIGURED_APPS += system/usbmsc endif diff --git a/system/Makefile b/system/Makefile index f23bbfdcb..a5ba4e506 100644 --- a/system/Makefile +++ b/system/Makefile @@ -39,7 +39,7 @@ SUBDIRS = cdcacm cle composite cu flash_eraseall free i2c hex2bin inifile SUBDIRS += install lm75 mdio netdb nxplayer ramtest ramtron readline sdcard -SUBDIRS += stackmonitor sudoku usbmonitor usbmsc vi zmodem zoneinfo +SUBDIRS += stackmonitor sudoku symtab usbmonitor usbmsc vi zmodem zoneinfo # Create the list of installed runtime modules (INSTALLED_DIRS) diff --git a/system/symtab/.gitignore b/system/symtab/.gitignore new file mode 100644 index 000000000..83bd7b811 --- /dev/null +++ b/system/symtab/.gitignore @@ -0,0 +1,11 @@ +/Make.dep +/.depend +/.built +/*.asm +/*.rel +/*.lst +/*.sym +/*.adb +/*.lib +/*.src +/*.obj diff --git a/system/symtab/Kconfig b/system/symtab/Kconfig new file mode 100644 index 000000000..ac83a48fa --- /dev/null +++ b/system/symtab/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 SYSTEM_SYMTAB + bool "User-provided symbol table" + default n + depends on EXECFUNCS_HAVE_SYMTAB && LIB_BOARDCTL + select BOARDCTL_SYMTAB + ---help--- + Build and include default symbol table in the NuttX application. + The symbol table is selected by call symtab_initialize(). The + table apps/system/symtab/symtab.inc has to be generated using + mksymtab manually before this option is selected. diff --git a/system/symtab/Makefile b/system/symtab/Makefile new file mode 100644 index 000000000..196c1a786 --- /dev/null +++ b/system/symtab/Makefile @@ -0,0 +1,104 @@ +############################################################################ +# apps/system/system/Makefile +# +# Copyright (C) 2015 Gregory Nutt. All rights reserved. +# Author: 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. +# +############################################################################ + +-include $(TOPDIR)/.config +-include $(TOPDIR)/Make.defs +include $(APPDIR)/Make.defs + +ifeq ($(WINTOOL),y) +INCDIROPT = -w +endif + +# Symbol table support + +ASRCS = +CSRCS = symtab.c + +AOBJS = $(ASRCS:.S=$(OBJEXT)) +COBJS = $(CSRCS:.c=$(OBJEXT)) + +SRCS = $(ASRCS) $(CSRCS) +OBJS = $(AOBJS) $(COBJS) + +ifeq ($(CONFIG_WINDOWS_NATIVE),y) + BIN = ..\..\libapps$(LIBEXT) +else +ifeq ($(WINTOOL),y) + BIN = ..\\..\\libapps$(LIBEXT) +else + BIN = ../../libapps$(LIBEXT) +endif +endif + +ROOTDEPPATH = --dep-path . + +# Common build + +VPATH = + +all: .built +.PHONY: context depend clean distclean + +$(AOBJS): %$(OBJEXT): %.S + $(call ASSEMBLE, $<, $@) + +$(COBJS) $(MAINOBJ): %$(OBJEXT): %.c + $(call COMPILE, $<, $@) + +.built: $(OBJS) + $(call ARCHIVE, $(BIN), $(OBJS)) + $(Q) touch .built + +install: + +context: + +# Create dependencies + +.depend: Makefile $(SRCS) + $(Q) $(MKDEP) $(ROOTDEPPATH) "$(CC)" -- $(CFLAGS) -- $(SRCS) >Make.dep + $(Q) touch $@ + +depend: .depend + +clean: + $(call DELFILE, .built) + $(call CLEAN) + +distclean: clean + $(call DELFILE, Make.dep) + $(call DELFILE, .depend) + +-include Make.dep diff --git a/system/symtab/README.txt b/system/symtab/README.txt new file mode 100644 index 000000000..8de5e98ac --- /dev/null +++ b/system/symtab/README.txt @@ -0,0 +1,61 @@ +symtab +====== + +Symbol Tables and Build Modes +----------------------------- +This directory provide support for a symbol table which provides all/most of +system and C library services/functions to the application and NSH. + +Symbol tables have differing usefulness in different NuttX build modes: + + 1. In the FLAT build (CONFIG_BUILD_FLAT), symbol tables are used to bind + addresses in loaded ELF or NxFLAT modules to base code that usually + resides in FLASH memory. Both OS interfaces and user/application + libraries are made available to the loaded module via symbol tables. + + 2. Symbol tables may be of value in a protected build + (CONFIG_BUILD_PROTECTED) where the newly started user task must + share resources with other user code (but should use system calls to + interact with the OS). + + 3. But in the kernel build mode (CONFIG_BUILD_KERNEL), only fully linked + executables loadable via execl(), execv(), or posix_spawan() can used. + There is no use for a symbol table with the kernel build since all + memory resources are separate; nothing is share-able with the newly + started process. + +Creating the Canned Symbol Table +-------------------------------- +The support is selected by CONFIG_SYSTEM_SYMTAB option and table has to be +prepared in advance manually. It can be prepared from NuttX top level +directory by using the following commands: + + cd + cat syscall/syscall.csv libc/libc.csv | sort > /symtab/symtab.csv + tools/mksymtab /symtab/symtab.csv /symtab/symtab.inc + +where: + is the path to the NuttX top level build directory + is the path to the top level application directory + +You may want omit syscall/syscall.csv in the above command in the protected +mode. It is optional since the system calls are provided through system +call traps. + +Your board-level start up code code then needs to select the symbol table +by calling the function symtab_initialize(): + + #include + ... + symtab_initialize(); + +Code/Text Size Implications +--------------------------- +The option can have substantial effect on system image size, mainly +code/text. That is because the instructions to generate symtab.inc +above will cause EVERY interface in the NuttX RTOS and the C library to be +included into build. Add to that the size of a huge symbol table. + +In order to reduce the code/text size, you may want to manually prune the +auto-generated symtab.inc file to remove all interfaces that you do +not wish to include into the base FLASH image. diff --git a/system/symtab/symtab.c b/system/symtab/symtab.c new file mode 100644 index 000000000..194c119fc --- /dev/null +++ b/system/symtab/symtab.c @@ -0,0 +1,79 @@ +/**************************************************************************** + * apps/system/symtab/lib_symtab.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Pavel Pisa + * + * 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 + +#ifdef CONFIG_SYSTEM_SYMTAB + +#include +#include +#include + +#include "symtab.inc" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: symtab_initialize + * + * Description: + * Setup a user provided symbol table. + * + * Input Parameters: + * None + * + * Returned Value: + * None + * + ****************************************************************************/ + +void symtab_initialize(void) +{ + /* We set the symbol table indirectly through the boardctl() */ + + struct symtab_desc_s symdesc; + + symdesc.symtab = g_symtab; + symdesc.nsymbols = NSYMBOLS; + (void)boardctl(BOARDIOC_SYMTAB, (uinptr_t)&symdesc); +} + +#endif /* CONFIG_SYSTEM_SYMTAB */ From 73fc8b501ef9f492f3313905702714c315d33f41 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 23 Aug 2015 12:19:52 -0600 Subject: [PATCH 18/23] apps/system/symtab: Fix some typos; update .gitignore --- system/symtab/.gitignore | 1 + system/symtab/symtab.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/system/symtab/.gitignore b/system/symtab/.gitignore index 83bd7b811..84ab58307 100644 --- a/system/symtab/.gitignore +++ b/system/symtab/.gitignore @@ -1,3 +1,4 @@ +/symtab.inc /Make.dep /.depend /.built diff --git a/system/symtab/symtab.c b/system/symtab/symtab.c index 194c119fc..49709c258 100644 --- a/system/symtab/symtab.c +++ b/system/symtab/symtab.c @@ -69,11 +69,11 @@ void symtab_initialize(void) { /* We set the symbol table indirectly through the boardctl() */ - struct symtab_desc_s symdesc; + struct boardioc_symtab_s symdesc; symdesc.symtab = g_symtab; symdesc.nsymbols = NSYMBOLS; - (void)boardctl(BOARDIOC_SYMTAB, (uinptr_t)&symdesc); + (void)boardctl(BOARDIOC_SYMTAB, (uintptr_t)&symdesc); } #endif /* CONFIG_SYSTEM_SYMTAB */ From ce3a2dc0d4237a1f09c9819bf749ce16232e666c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 24 Aug 2015 13:59:52 -0600 Subject: [PATCH 19/23] NSH changes to work with the network local loopback device --- nshlib/nsh.h | 3 ++- nshlib/nsh_netcmds.c | 9 +++++++++ nshlib/nsh_netinit.c | 17 ++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/nshlib/nsh.h b/nshlib/nsh.h index e87177eb4..895b1e228 100644 --- a/nshlib/nsh.h +++ b/nshlib/nsh.h @@ -155,7 +155,8 @@ * domain sockets were enable. */ -#if !defined(CONFIG_NET_ETHERNET) && !defined(CONFIG_NET_SLIP) && !defined(CONFIG_NET_TUN) +#if !defined(CONFIG_NET_ETHERNET) && !defined(CONFIG_NET_LOOPBACK) && \ + !defined(CONFIG_NET_SLIP) && !defined(CONFIG_NET_TUN) /* No link layer protocol is a good indication that there is no network * device. */ diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c index 39be39e65..ce4c6a42e 100644 --- a/nshlib/nsh_netcmds.c +++ b/nshlib/nsh_netcmds.c @@ -515,6 +515,12 @@ static int ifconfig_callback(FAR struct net_driver_s *dev, void *arg) break; # endif +# if defined(CONFIG_NET_LOOPBACK) + case NET_LL_LOOPBACK: + nsh_output(vtbl, "%s\tLink encap:Local Loopback\n", dev->d_ifname); + break; +# endif + # if defined(CONFIG_NET_SLIP) case NET_LL_SLIP: nsh_output(vtbl, "%s\tLink encap:SLIP", dev->d_ifname); @@ -543,6 +549,9 @@ static int ifconfig_callback(FAR struct net_driver_s *dev, void *arg) nsh_output(vtbl, "%s\tLink encap:Ethernet HWaddr %s at %s\n", dev->d_ifname, ether_ntoa(&dev->d_mac), status); +#elif defined(CONFIG_NET_LOOPBACK) + nsh_output(vtbl, "%s\tLink encap:Local Loopback\n", dev->d_ifname); + #elif defined(CONFIG_NET_SLIP) nsh_output(vtbl, "%s\tLink encap:SLIP at %s\n", dev->d_ifname, status); diff --git a/nshlib/nsh_netinit.c b/nshlib/nsh_netinit.c index 393997e33..38e20aeb2 100644 --- a/nshlib/nsh_netinit.c +++ b/nshlib/nsh_netinit.c @@ -103,19 +103,32 @@ #if defined(CONFIG_NET_ETHERNET) # define NET_DEVNAME "eth0" +# define NSH_HAVE_NETDEV #elif defined(CONFIG_NET_SLIP) # define NET_DEVNAME "sl0" # ifndef CONFIG_NSH_NOMAC # error "CONFIG_NSH_NOMAC must be defined for SLIP" # endif +# define NSH_HAVE_NETDEV #elif defined(CONFIG_NET_TUN) # define NET_DEVNAME "tun0" +# define NSH_HAVE_NETDEV #elif defined(CONFIG_NET_LOCAL) # define NET_DEVNAME "lo" -#else +# define NSH_HAVE_NETDEV +#elif !defined(CONFIG_NET_LOOPBACK) # error ERROR: No link layer protocol defined #endif +/* If we have no network device (only only the local loopback device), then we + * cannot support the network monitor. + */ + +#ifndef NSH_HAVE_NETDEV +# undef CONFIG_NSH_NETINIT_MONITOR +#endif + + /* We need a valid IP domain (any domain) to create a socket that we can use * to comunicate with the network device. */ @@ -208,6 +221,7 @@ static const uint16_t g_ipv6_netmask[8] = static void nsh_netinit_configure(void) { +#ifdef NSH_HAVE_NETDEV #ifdef CONFIG_NET_IPv4 struct in_addr addr; #endif @@ -328,6 +342,7 @@ static void nsh_netinit_configure(void) dhcpc_close(handle); } #endif +#endif /* NSH_HAVE_NETDEV */ nvdbg("Exit\n"); } From b7b943067adddfba167db526e4f0381ff2834da1 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Aug 2015 07:59:12 -0600 Subject: [PATCH 20/23] NSH: Fix formatting of ifconfig Local Loopback output --- nshlib/nsh_netcmds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nshlib/nsh_netcmds.c b/nshlib/nsh_netcmds.c index ce4c6a42e..555eef29e 100644 --- a/nshlib/nsh_netcmds.c +++ b/nshlib/nsh_netcmds.c @@ -517,7 +517,7 @@ static int ifconfig_callback(FAR struct net_driver_s *dev, void *arg) # if defined(CONFIG_NET_LOOPBACK) case NET_LL_LOOPBACK: - nsh_output(vtbl, "%s\tLink encap:Local Loopback\n", dev->d_ifname); + nsh_output(vtbl, "%s\tLink encap:Local Loopback", dev->d_ifname); break; # endif @@ -550,7 +550,7 @@ static int ifconfig_callback(FAR struct net_driver_s *dev, void *arg) dev->d_ifname, ether_ntoa(&dev->d_mac), status); #elif defined(CONFIG_NET_LOOPBACK) - nsh_output(vtbl, "%s\tLink encap:Local Loopback\n", dev->d_ifname); + nsh_output(vtbl, "%s\tLink encap:Local Loopback at %s\n", dev->d_ifname, status); #elif defined(CONFIG_NET_SLIP) nsh_output(vtbl, "%s\tLink encap:SLIP at %s\n", dev->d_ifname, status); From 6cedfcd632a2c1f2ee7eef0317a3e71ec83e4a53 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Aug 2015 09:06:41 -0600 Subject: [PATCH 21/23] apps/examples/nettest: Add option to suppress networking initialization --- ChangeLog.txt | 3 +++ examples/nettest/Kconfig | 27 +++++++++++++++++++---- examples/nettest/nettest.c | 45 ++++++++++++++++++++++++++++---------- 3 files changed, 59 insertions(+), 16 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index cf8de35eb..78c6a7b03 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1412,4 +1412,7 @@ substantial effect on system image size. Mainly code/text. If loading of applications at runtime is not planned do not select this. From Pavel Pisa (2015-08-23). + * apps/nettest: Add option to suppress network initialization. This + is necessary if the nettest is run from NSH which has already + initialized the network (2015-08-26). diff --git a/examples/nettest/Kconfig b/examples/nettest/Kconfig index 4ccc04052..55ba511c5 100644 --- a/examples/nettest/Kconfig +++ b/examples/nettest/Kconfig @@ -26,10 +26,6 @@ config EXAMPLES_NETTEST_PERFORMANCE Configure the example to test for network performance. Default: Test is for network functionality. -config EXAMPLES_NETTEST_NOMAC - bool "Use Canned MAC Address" - default n - choice prompt "IP Domain" default EXAMPLES_NETTEST_IPv4 if NET_IPv4 @@ -45,10 +41,28 @@ config EXAMPLES_NETTEST_IPv6 endchoice # IP Domain +config EXAMPLES_NETTEST_INIT + bool "Initialize network" + default n if NSH_BUILTIN_APPS + default y if !NSH_BUILTIN_APPS + depends on !BUILD_KERNEL + ---help--- + Include logic to initialize the network. This should not be done if + the network is already initialized when nettest runs. This is + usually the case, for example, when nettest is run as an NSH built- + in task. + +config EXAMPLES_NETTEST_NOMAC + bool "Use Canned MAC Address" + default n + depends on EXAMPLES_NETTEST_INIT + if EXAMPLES_NETTEST_IPv4 comment "IPv4 addresses" +if EXAMPLES_NETTEST_INIT + config EXAMPLES_NETTEST_IPADDR hex "Target IP address" default 0x0a000002 @@ -61,6 +75,8 @@ config EXAMPLES_NETTEST_NETMASK hex "Network Mask" default 0xffffff00 +endif # EXAMPLES_NETTEST_INIT + config EXAMPLES_NETTEST_CLIENTIP hex "Client IP Address" default 0x0a000001 if !EXAMPLES_NETTEST_SERVER @@ -80,6 +96,8 @@ if !NET_ICMPv6_AUTOCONF comment "Target IPv6 address" +if EXAMPLES_NETTEST_INIT + config EXAMPLES_NETTEST_IPv6ADDR_1 hex "[0]" default 0xfc00 @@ -325,6 +343,7 @@ config EXAMPLES_NETTEST_IPv6NETMASK_8 all eight values is fe00::0. endif # NET_ICMPv6_AUTOCONF +endif # EXAMPLES_NETTEST_INIT comment "Client IPv6 address" diff --git a/examples/nettest/nettest.c b/examples/nettest/nettest.c index b03b288c1..ee2afb615 100644 --- a/examples/nettest/nettest.c +++ b/examples/nettest/nettest.c @@ -60,7 +60,9 @@ * Private Data ****************************************************************************/ -#if defined(CONFIG_EXAMPLES_NETTEST_IPv6) && !defined(CONFIG_NET_ICMPv6_AUTOCONF) +#if defined(CONFIG_EXAMPLES_NETTEST_INIT) && \ + defined(CONFIG_EXAMPLES_NETTEST_IPv6) && \ + !defined(CONFIG_NET_ICMPv6_AUTOCONF) /* Our host IPv6 address */ static const uint16_t g_ipv6_hostaddr[8] = @@ -102,21 +104,14 @@ static const uint16_t g_ipv6_netmask[8] = HTONS(CONFIG_EXAMPLES_NETTEST_IPv6NETMASK_7), HTONS(CONFIG_EXAMPLES_NETTEST_IPv6NETMASK_8), }; -#endif /* CONFIG_EXAMPLES_NETTEST_IPv6 && !CONFIG_NET_ICMPv6_AUTOCONF */ +#endif /* CONFIG_EXAMPLES_NETTEST_INIT && CONFIG_EXAMPLES_NETTEST_IPv6 && !CONFIG_NET_ICMPv6_AUTOCONF */ /**************************************************************************** - * Public Functions + * Private Functions ****************************************************************************/ -/**************************************************************************** - * nettest_main - ****************************************************************************/ - -#ifdef CONFIG_BUILD_KERNEL -int main(int argc, FAR char *argv[]) -#else -int nettest_main(int argc, char *argv[]) -#endif +#ifdef CONFIG_EXAMPLES_NETTEST_INIT +static void netest_initialize(void) { #ifndef CONFIG_EXAMPLES_NETTEST_IPv6 struct in_addr addr; @@ -179,10 +174,36 @@ int nettest_main(int argc, char *argv[]) netlib_set_ipv4netmask("eth0", &addr); #endif /* CONFIG_EXAMPLES_NETTEST_IPv6 */ +} +#endif /*CONFIG_EXAMPLES_NETTEST_INIT */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * nettest_main + ****************************************************************************/ + +#ifdef CONFIG_BUILD_KERNEL +int main(int argc, FAR char *argv[]) +#else +int nettest_main(int argc, char *argv[]) +#endif +{ +#ifdef CONFIG_EXAMPLES_NETTEST_INIT + /* Initialize the network */ + + netest_initialize(); +#endif #ifdef CONFIG_EXAMPLES_NETTEST_SERVER + /* Then perform the server side of the test */ + recv_server(); #else + /* Then perform the client side of the test */ + send_client(); #endif From a7853cdc89a4760ffbd273ec3bd239e576ce894e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 26 Aug 2015 10:35:40 -0600 Subject: [PATCH 22/23] apps/examples/nettest: Extend the test so that it can be down using the local loopback device --- ChangeLog.txt | 2 ++ examples/nettest/Kconfig | 37 ++++++++++++++++++++++---- examples/nettest/Makefile | 44 +++++++++++++++++++------------ examples/nettest/nettest.c | 42 +++++++++++++++++++++++++---- examples/nettest/nettest_client.c | 16 +++++++++++ 5 files changed, 114 insertions(+), 27 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 78c6a7b03..af9eee2e9 100755 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -1415,4 +1415,6 @@ * apps/nettest: Add option to suppress network initialization. This is necessary if the nettest is run from NSH which has already initialized the network (2015-08-26). + * apps/nettest: Extend test so that can be performed using the local + loopback device (2015-08-26). diff --git a/examples/nettest/Kconfig b/examples/nettest/Kconfig index 55ba511c5..7f5d8d8b0 100644 --- a/examples/nettest/Kconfig +++ b/examples/nettest/Kconfig @@ -12,19 +12,40 @@ config EXAMPLES_NETTEST if EXAMPLES_NETTEST +config EXAMPLES_NETTEST_LOOPBACK + bool "Loopback test" + default n + depends on NET_LOOPBACK + ---help--- + Perform the test using the local loopback device. In this case, + both the client and the server reside on the target. + +if EXAMPLES_NETTEST_LOOPBACK + +config EXAMPLES_NETTEST_STACKSIZE + int "Server stack size" + default 2048 + +config EXAMPLES_NETTEST_PRIORITY + int "Server priority" + default 100 + +endif # EXAMPLES_NETTEST_LOOPBACK + config EXAMPLES_NETTEST_SERVER bool "Target is server" default n + depends on !EXAMPLES_NETTEST_LOOPBACK ---help--- - Select to use the host as the client side of the test. Default: The - target is the client side of the test + Select to use the host as the client side of the test. Default: The + target is the client side of the test config EXAMPLES_NETTEST_PERFORMANCE bool "Test for Performance" default n ---help--- - Configure the example to test for network performance. Default: Test - is for network functionality. + Configure the example to test for network performance. Default: Test + is for network functionality. choice prompt "IP Domain" @@ -45,7 +66,7 @@ config EXAMPLES_NETTEST_INIT bool "Initialize network" default n if NSH_BUILTIN_APPS default y if !NSH_BUILTIN_APPS - depends on !BUILD_KERNEL + depends on !BUILD_KERNEL && !EXAMPLES_NETTEST_LOOPBACK ---help--- Include logic to initialize the network. This should not be done if the network is already initialized when nettest runs. This is @@ -77,6 +98,8 @@ config EXAMPLES_NETTEST_NETMASK endif # EXAMPLES_NETTEST_INIT +if !EXAMPLES_NETTEST_LOOPBACK + config EXAMPLES_NETTEST_CLIENTIP hex "Client IP Address" default 0x0a000001 if !EXAMPLES_NETTEST_SERVER @@ -89,6 +112,7 @@ config EXAMPLES_NETTEST_CLIENTIP host PC IP address (possibly the gateway address, EXAMPLES_NETTEST_DRIPADDR?). +endif # !EXAMPLES_NETTEST_LOOPBACK endif # EXAMPLES_NETTEST_IPv4 if EXAMPLES_NETTEST_IPv6 @@ -345,6 +369,8 @@ config EXAMPLES_NETTEST_IPv6NETMASK_8 endif # NET_ICMPv6_AUTOCONF endif # EXAMPLES_NETTEST_INIT +if !EXAMPLES_NETTEST_LOOPBACK + comment "Client IPv6 address" config EXAMPLES_NETTEST_CLIENTIPv6ADDR_1 @@ -476,5 +502,6 @@ config EXAMPLES_NETTEST_CLIENTIPv6ADDR_8 values forming the full IP address must be specified individually. This is the last of the 8-values. +endif # !EXAMPLES_NETTEST_LOOPBACK endif # EXAMPLES_NETTEST_IPv6 endif # EXAMPLES_NETTEST diff --git a/examples/nettest/Makefile b/examples/nettest/Makefile index b41eeccf9..fbefe3701 100644 --- a/examples/nettest/Makefile +++ b/examples/nettest/Makefile @@ -43,7 +43,9 @@ TARG_ASRCS = TARG_AOBJS = $(TARG_ASRCS:.S=$(OBJEXT)) TARG_CSRCS = -ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) +ifeq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) +TARG_CSRCS += nettest_server.c nettest_client.c +else ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) TARG_CSRCS += nettest_server.c else TARG_CSRCS += nettest_client.c @@ -70,24 +72,26 @@ else endif endif -HOSTCFLAGS += -DNETTEST_HOST=1 -ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) -HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_CLIENTIP="$(CONFIG_EXAMPLES_NETTEST_CLIENTIP)" -endif -ifeq ($(CONFIG_EXAMPLES_NETTEST_PERFORMANCE),y) -HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_PERFORMANCE=1 -endif +ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) + HOSTCFLAGS += -DNETTEST_HOST=1 + ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) + HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_SERVER=1 -DCONFIG_EXAMPLES_NETTEST_CLIENTIP="$(CONFIG_EXAMPLES_NETTEST_CLIENTIP)" + endif + ifeq ($(CONFIG_EXAMPLES_NETTEST_PERFORMANCE),y) + HOSTCFLAGS += -DCONFIG_EXAMPLES_NETTEST_PERFORMANCE=1 + endif -HOST_SRCS = host.c -ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) -HOST_SRCS += nettest_client.c -else -HOST_SRCS += nettest_server.c -endif + HOST_SRCS = host.c + ifeq ($(CONFIG_EXAMPLES_NETTEST_SERVER),y) + HOST_SRCS += nettest_client.c + else + HOST_SRCS += nettest_server.c + endif -HOSTOBJEXT ?= .hobj -HOST_OBJS = $(HOST_SRCS:.c=$(HOSTOBJEXT)) -HOST_BIN = host + HOSTOBJEXT ?= .hobj + HOST_OBJS = $(HOST_SRCS:.c=$(HOSTOBJEXT)) + HOST_BIN = host +endif ifeq ($(WINTOOL),y) INSTALL_DIR = "${shell cygpath -w $(BIN_DIR)}" @@ -119,17 +123,21 @@ $(TARG_AOBJS): %$(OBJEXT): %.S $(TARG_COBJS) $(TARG_MAINOBJ): %$(OBJEXT): %.c $(call COMPILE, $<, $@) +ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) $(HOST_OBJS): %$(HOSTOBJEXT): %.c @echo "CC: $<" $(Q) $(HOSTCC) -c $(HOSTCFLAGS) $< -o $@ +endif config.h: $(TOPDIR)/include/nuttx/config.h @echo "CP: $<" $(Q) cp $< $@ +ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) $(HOST_BIN): config.h $(HOST_OBJS) @echo "LD: $@" $(Q) $(HOSTCC) $(HOSTLDFLAGS) $(HOST_OBJS) -o $@ +endif .built: config.h $(TARG_OBJS) $(call ARCHIVE, $(TARG_BIN), $(TARG_OBJS)) @@ -164,8 +172,10 @@ endif depend: .depend clean: +ifneq ($(CONFIG_EXAMPLES_NETTEST_LOOPBACK),y) $(call DELFILE, *$(HOSTOBJEXT)) $(call DELFILE, $(HOST_BIN)) +endif $(call DELFILE, .built) $(call DELFILE, *.dSYM) $(call DELFILE, config.h) diff --git a/examples/nettest/nettest.c b/examples/nettest/nettest.c index ee2afb615..16e7fcf69 100644 --- a/examples/nettest/nettest.c +++ b/examples/nettest/nettest.c @@ -41,7 +41,10 @@ //#include #include +#include #include +#include +#include #include #include @@ -177,6 +180,14 @@ static void netest_initialize(void) } #endif /*CONFIG_EXAMPLES_NETTEST_INIT */ +#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK +static int server_child(int argc, char *argv[]) +{ + recv_server(); + return EXIT_SUCCESS; +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -191,21 +202,42 @@ int main(int argc, FAR char *argv[]) int nettest_main(int argc, char *argv[]) #endif { +#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) + pid_t child; +#endif + #ifdef CONFIG_EXAMPLES_NETTEST_INIT /* Initialize the network */ netest_initialize(); #endif -#ifdef CONFIG_EXAMPLES_NETTEST_SERVER - /* Then perform the server side of the test */ +#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) + /* Then perform the server side of the test on a child task */ + + child = task_create("Nettest Child", CONFIG_EXAMPLES_NETTEST_PRIORITY, + CONFIG_EXAMPLES_NETTEST_STACKSIZE, server_child, + NULL); + if (child < 0) + { + fprintf(stderr, "ERROR: Failed to server daemon\n"); + return EXIT_FAILURE; + } + + usleep(500*10000); + +#elif defined(CONFIG_EXAMPLES_NETTEST_SERVER) + /* Then perform the server side of the test on this thread */ recv_server(); -#else - /* Then perform the client side of the test */ +#endif + +#if !defined(CONFIG_EXAMPLES_NETTEST_SERVER) || \ + defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) + /* Then perform the client side of the test on this thread */ send_client(); #endif - return 0; + return EXIT_SUCCESS; } diff --git a/examples/nettest/nettest_client.c b/examples/nettest/nettest_client.c index 42699b177..d377a9b3a 100644 --- a/examples/nettest/nettest_client.c +++ b/examples/nettest/nettest_client.c @@ -106,6 +106,16 @@ void send_client(void) myaddr.sin6_family = AF_INET6; myaddr.sin6_port = HTONS(PORTNO); +#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK + myaddr.sin6_addr.s6_addr16[0] = 0; + myaddr.sin6_addr.s6_addr16[1] = 0; + myaddr.sin6_addr.s6_addr16[2] = 0; + myaddr.sin6_addr.s6_addr16[3] = 0; + myaddr.sin6_addr.s6_addr16[4] = 0; + myaddr.sin6_addr.s6_addr16[5] = 0; + myaddr.sin6_addr.s6_addr16[6] = 0; + myaddr.sin6_addr.s6_addr16[7] = HTONS(1); +#else myaddr.sin6_addr.s6_addr16[0] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_1); myaddr.sin6_addr.s6_addr16[1] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_2); myaddr.sin6_addr.s6_addr16[2] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_3); @@ -114,12 +124,18 @@ void send_client(void) myaddr.sin6_addr.s6_addr16[5] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_6); myaddr.sin6_addr.s6_addr16[6] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_7); myaddr.sin6_addr.s6_addr16[7] = HTONS(CONFIG_EXAMPLES_NETTEST_CLIENTIPv6ADDR_8); +#endif addrlen = sizeof(struct sockaddr_in6); #else myaddr.sin_family = AF_INET; myaddr.sin_port = HTONS(PORTNO); + +#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK + myaddr.sin_addr.s_addr = HTONL(0x7f000001); +#else myaddr.sin_addr.s_addr = HTONL(CONFIG_EXAMPLES_NETTEST_CLIENTIP); +#endif addrlen = sizeof(struct sockaddr_in); #endif From ed2ccad73500f7f968db6c75b75931a04f6aab9e Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 27 Aug 2015 11:46:42 -0600 Subject: [PATCH 23/23] examples/nettest: Fix a couple of crazy long delays that may make you think something is broken. In main, add a wait for the server to exit --- examples/nettest/nettest.c | 13 +++++++++++-- examples/nettest/nettest_server.c | 4 +++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/examples/nettest/nettest.c b/examples/nettest/nettest.c index 16e7fcf69..6a894804e 100644 --- a/examples/nettest/nettest.c +++ b/examples/nettest/nettest.c @@ -40,6 +40,7 @@ #include "config.h" //#include +#include #include #include #include @@ -202,8 +203,11 @@ int main(int argc, FAR char *argv[]) int nettest_main(int argc, char *argv[]) #endif { -#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) +#ifdef CONFIG_EXAMPLES_NETTEST_LOOPBACK pid_t child; +#ifdef CONFIG_SCHED_WAITPID + int statloc; +#endif #endif #ifdef CONFIG_EXAMPLES_NETTEST_INIT @@ -224,7 +228,7 @@ int nettest_main(int argc, char *argv[]) return EXIT_FAILURE; } - usleep(500*10000); + usleep(500*1000); #elif defined(CONFIG_EXAMPLES_NETTEST_SERVER) /* Then perform the server side of the test on this thread */ @@ -239,5 +243,10 @@ int nettest_main(int argc, char *argv[]) send_client(); #endif +#if defined(CONFIG_EXAMPLES_NETTEST_LOOPBACK) && defined(CONFIG_SCHED_WAITPID) + printf("main: Waiting for the server to exit\n"); + (void)waitpid(child, &statloc, 0); +#endif + return EXIT_SUCCESS; } diff --git a/examples/nettest/nettest_server.c b/examples/nettest/nettest_server.c index d2087a7ef..990168a5b 100644 --- a/examples/nettest/nettest_server.c +++ b/examples/nettest/nettest_server.c @@ -178,6 +178,7 @@ void recv_server(void) printf("server: The client broke the connection\n"); goto errout_with_acceptsd; } + printf("Received %d bytes\n", nbytesread); } #else @@ -245,9 +246,10 @@ void recv_server(void) #if 1 /* Do it for all platforms */ printf("server: Wait before closing\n"); - sleep(60); + sleep(2); #endif + printf("server: Terminating\n"); close(listensd); close(acceptsd); free(buffer);