mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-05-18 00:27:34 +08:00
Merge branch 'master' into nuttx-merge-5447
This commit is contained in:
+69
-2
@@ -33,7 +33,7 @@
|
||||
|
||||
6.3 2011-05-15 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/interpreter: Add a directory to hold interpreters. The Pascal add-
|
||||
* apps/interpreter: Add a directory to hold interpreters. The Pascal add-
|
||||
on module now installs and builds under this directory.
|
||||
* apps/interpreter/ficl: Added logic to build Ficl (the "Forth Inspired
|
||||
Command Language"). See http://ficl.sourceforge.net/.
|
||||
@@ -349,7 +349,7 @@
|
||||
* apps/NxWidgets/Kconfig: Add option to turn on the memory monitor
|
||||
feature of the NxWidgets/NxWM unit tests.
|
||||
|
||||
6.23 2012-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
||||
6.23 2012-11-05 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* vsn: Moved all NSH commands from vsn/ to system/. Deleted the vsn/
|
||||
directory.
|
||||
@@ -368,3 +368,70 @@
|
||||
recent check-ins (Darcy Gong).
|
||||
* apps/netutils/webclient/webclient.c: Fix another but that I introduced
|
||||
when I was trying to add correct handling for loss of connection (Darcy Gong)
|
||||
* apps/nshlib/nsh_telnetd.c: Add support for login to Telnet session via
|
||||
username and password (Darcy Gong).
|
||||
* apps/netutils/resolv/resolv.c (and files using the DNS resolver): Various
|
||||
DNS address resolution improvements from Darcy Gong.
|
||||
* apps/nshlib/nsh_netcmds.c: The ping command now passes a maximum round
|
||||
trip time to uip_icmpping(). This allows pinging of hosts on complex
|
||||
networks where the ICMP ECHO round trip time may exceed the ping interval.
|
||||
* apps/examples/nxtext/nxtext_main.c: Fix bad conditional compilation
|
||||
when CONFIG_NX_KBD is not defined. Submitted by Petteri Aimonen.
|
||||
* apps/examples/nximage/nximage_main.c: Add a 5 second delay after the
|
||||
NX logo is presented so that there is time for the image to be verified.
|
||||
Suggested by Petteri Aimonen.
|
||||
* apps/Makefile: Small change that reduces the number of shell invocations
|
||||
by one (Mike Smith).
|
||||
* apps/examples/elf: Test example for the ELF loader.
|
||||
* apps/examples/elf: The ELF module test example appears fully functional.
|
||||
* apps/netutils/json: Add a snapshot of the cJSON project. Contributed by
|
||||
Darcy Gong.
|
||||
* apps/examples/json: Test example for cJSON from Darcy Gong
|
||||
* apps/nshlib/nsh_netinit.c: Fix static IP DNS problem (Darcy Gong)
|
||||
* apps/netutils/resolv/resolv.c: DNS fixes from Darcy Gong.
|
||||
* COPYING: Licensing information added.
|
||||
* apps/netutils/codec and include/netutils/urldecode.h, base64.h, and md5.h:
|
||||
A port of the BASE46, MD5 and URL CODEC library from Darcy Gong.
|
||||
* nsnlib/nsh_codeccmd.c: NSH commands to use the CODEC library.
|
||||
Contributed by Darcy Gong.
|
||||
* apps/examples/wgetjson: Test example contributed by Darcy Gong
|
||||
* apps/examples/cxxtest: A test for the uClibc++ library provided by
|
||||
Qiang Yu and the RGMP team.
|
||||
* apps/netutils/webclient, apps/netutils.codes, and apps/examples/wgetjson:
|
||||
Add support for wget POST interface. Contributed by Darcy Gong.
|
||||
* apps/examples/relays: A relay example contributed by Darcy Gong.
|
||||
* apps/nshlib/nsh_netcmds: Add ifup and ifdown commands (from Darcy
|
||||
Gong).
|
||||
* apps/nshlib/nsh_netcmds: Extend the ifconfig command so that it
|
||||
supports setting IP addresses, network masks, name server addresses,
|
||||
and hardware address (from Darcy Gong).
|
||||
|
||||
6.24 2012-12-20 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* apps/examples/ostest/roundrobin.c: Replace large tables with
|
||||
algorithmic prime number generation. This allows the roundrobin
|
||||
test to run on platforms with minimal SRAM (Freddie Chopin).
|
||||
* apps/nshlib/nsh_dbgcmds.c: Add hexdump command to dump the contents
|
||||
of a file (or character device) to the console Contributed by Petteri
|
||||
Aimonen.
|
||||
* apps/examples/modbus: Fixes from Freddie Chopin
|
||||
* apps/examples/modbus/Kconfig: Kconfig logic for FreeModBus contributed
|
||||
by Freddie Chopin.
|
||||
* Makefile, */Makefile: Various fixes for Windows native build. Now uses
|
||||
make foreach loops instead of shell loops.
|
||||
* apps/examples/elf/test/*/Makefile: OSX doesn't support install -D, use
|
||||
mkdir -p then install without the -D. From Mike Smith.
|
||||
* apps/examples/relays/Makefile: Reduced stack requirement (Darcy Gong).
|
||||
* apps/nshlib and apps/netutils/dhcpc: Extend the NSH ifconfig command plus
|
||||
various DHCPC improvements(Darcy Gong).
|
||||
* apps/nshlib/nsh_apps.c: Fix compilation errors when CONFIG_NSH_DISABLEBG=y.
|
||||
From Freddie Chopin.
|
||||
* Rename CONFIG_PCODE and CONFIG_FICL as CONFIG_INTERPRETERS_PCODE and
|
||||
CONFIG_INTERPRETERS_FICL for consistency with other configuration naming.
|
||||
* apps/examples/keypadtest: A keypad test example contributed by Denis
|
||||
Carikli.
|
||||
* apps/examples/elf and nxflat: If CONFIG_BINFMT_EXEPATH is defined, these
|
||||
tests will now use a relative path to the program and expect the binfmt/
|
||||
logic to find the absolute path to the program using the PATH variable.
|
||||
|
||||
6.25 2013-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
+6
-152
@@ -3,206 +3,60 @@
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
menu "ADC Example"
|
||||
source "$APPSDIR/examples/adc/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Buttons Example"
|
||||
source "$APPSDIR/examples/buttons/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "CAN Example"
|
||||
source "$APPSDIR/examples/can/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "USB CDC/ACM Class Driver Example"
|
||||
source "$APPSDIR/examples/cdcacm/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "USB composite Class Driver Example"
|
||||
source "$APPSDIR/examples/composite/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "DHCP Server Example"
|
||||
source "$APPSDIR/examples/cxxtest/Kconfig"
|
||||
source "$APPSDIR/examples/dhcpd/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "FTP Client Example"
|
||||
source "$APPSDIR/examples/elf/Kconfig"
|
||||
source "$APPSDIR/examples/ftpc/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "FTP Server Example"
|
||||
source "$APPSDIR/examples/ftpd/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "\"Hello, World!\" Example"
|
||||
source "$APPSDIR/examples/hello/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "\"Hello, World!\" C++ Example"
|
||||
source "$APPSDIR/examples/helloxx/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "USB HID Keyboard Example"
|
||||
source "$APPSDIR/examples/json/Kconfig"
|
||||
source "$APPSDIR/examples/hidkbd/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "IGMP Example"
|
||||
source "$APPSDIR/examples/keypadtest/Kconfig"
|
||||
source "$APPSDIR/examples/igmp/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "LCD Read/Write Example"
|
||||
source "$APPSDIR/examples/lcdrw/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Memory Management Example"
|
||||
source "$APPSDIR/examples/mm/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "File System Mount Example"
|
||||
source "$APPSDIR/examples/mount/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "FreeModBus Example"
|
||||
source "$APPSDIR/examples/modbus/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Network Test Example"
|
||||
source "$APPSDIR/examples/nettest/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NuttShell (NSH) Example"
|
||||
source "$APPSDIR/examples/nsh/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NULL Example"
|
||||
source "$APPSDIR/examples/null/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NX Graphics Example"
|
||||
source "$APPSDIR/examples/nx/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NxConsole Example"
|
||||
source "$APPSDIR/examples/nxconsole/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NXFFS File System Example"
|
||||
source "$APPSDIR/examples/nxffs/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NXFLAT Example"
|
||||
source "$APPSDIR/examples/nxflat/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NX Graphics \"Hello, World!\" Example"
|
||||
source "$APPSDIR/examples/nxhello/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NX Graphics image Example"
|
||||
source "$APPSDIR/examples/nximage/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NX Graphics lines Example"
|
||||
source "$APPSDIR/examples/nxlines/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "NX Graphics Text Example"
|
||||
source "$APPSDIR/examples/nxtext/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "OS Test Example"
|
||||
source "$APPSDIR/examples/ostest/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Pascal \"Hello, World!\"example"
|
||||
source "$APPSDIR/examples/pashello/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Pipe Example"
|
||||
source "$APPSDIR/examples/pipe/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Poll Example"
|
||||
source "$APPSDIR/examples/poll/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Pulse Width Modulation (PWM) Example"
|
||||
source "$APPSDIR/examples/pwm/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Quadrature Encoder Example"
|
||||
source "$APPSDIR/examples/qencoder/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "RGMP Example"
|
||||
source "$APPSDIR/examples/relays/Kconfig"
|
||||
source "$APPSDIR/examples/rgmp/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "ROMFS Example"
|
||||
source "$APPSDIR/examples/romfs/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "sendmail Example"
|
||||
source "$APPSDIR/examples/sendmail/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Serial Loopback Example"
|
||||
source "$APPSDIR/examples/serloop/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Telnet Daemon Example"
|
||||
source "$APPSDIR/examples/telnetd/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "THTTPD Web Server Example"
|
||||
source "$APPSDIR/examples/thttpd/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "TIFF Generation Example"
|
||||
source "$APPSDIR/examples/tiff/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Touchscreen Example"
|
||||
source "$APPSDIR/examples/touchscreen/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "UDP Example"
|
||||
source "$APPSDIR/examples/udp/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "UDP Discovery Daemon Example"
|
||||
source "$APPSDIR/examples/discover/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "uIP Web Server Example"
|
||||
source "$APPSDIR/examples/uip/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "USB Serial Test Example"
|
||||
source "$APPSDIR/examples/usbserial/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "USB Mass Storage Class Example"
|
||||
source "$APPSDIR/examples/usbstorage/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "USB Serial Terminal Example"
|
||||
source "$APPSDIR/examples/usbterm/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "Watchdog timer Example"
|
||||
source "$APPSDIR/examples/watchdog/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "wget Example"
|
||||
source "$APPSDIR/examples/wget/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "WLAN Example"
|
||||
source "$APPSDIR/examples/wgetjson/Kconfig"
|
||||
source "$APPSDIR/examples/wlan/Kconfig"
|
||||
endmenu
|
||||
|
||||
menu "XML RPC Example"
|
||||
source "$APPSDIR/examples/xmlrpc/Kconfig"
|
||||
endmenu
|
||||
|
||||
@@ -54,6 +54,10 @@ ifeq ($(CONFIG_EXAMPLES_COMPOSITE),y)
|
||||
CONFIGURED_APPS += examples/composite
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_CXXTEST),y)
|
||||
CONFIGURED_APPS += examples/cxxtest
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_DHCPD),y)
|
||||
CONFIGURED_APPS += examples/dhcpd
|
||||
endif
|
||||
@@ -62,6 +66,10 @@ ifeq ($(CONFIG_EXAMPLES_DISCOVER),y)
|
||||
CONFIGURED_APPS += examples/discover
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_ELF),y)
|
||||
CONFIGURED_APPS += examples/elf
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_FTPC),y)
|
||||
CONFIGURED_APPS += examples/ftpc
|
||||
endif
|
||||
@@ -86,6 +94,14 @@ ifeq ($(CONFIG_EXAMPLES_IGMP),y)
|
||||
CONFIGURED_APPS += examples/igmp
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_JSON),y)
|
||||
CONFIGURED_APPS += examples/json
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_KEYPADTEST),y)
|
||||
CONFIGURED_APPS += examples/keypadtest
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_LCDRW),y)
|
||||
CONFIGURED_APPS += examples/lcdrw
|
||||
endif
|
||||
@@ -94,6 +110,10 @@ ifeq ($(CONFIG_EXAMPLES_MM),y)
|
||||
CONFIGURED_APPS += examples/mm
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_MODBUS),y)
|
||||
CONFIGURED_APPS += examples/modbus
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_MOUNT),y)
|
||||
CONFIGURED_APPS += examples/mount
|
||||
endif
|
||||
@@ -166,6 +186,10 @@ ifeq ($(CONFIG_EXAMPLES_QENCODER),y)
|
||||
CONFIGURED_APPS += examples/qencoder
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_RELAYS),y)
|
||||
CONFIGURED_APPS += examples/relays
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_RGMP),y)
|
||||
CONFIGURED_APPS += examples/rgmp
|
||||
endif
|
||||
@@ -226,6 +250,10 @@ ifeq ($(CONFIG_EXAMPLES_WGET),y)
|
||||
CONFIGURED_APPS += examples/wget
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_WGETJSON),y)
|
||||
CONFIGURED_APPS += examples/wgetjson
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_WLAN),y)
|
||||
CONFIGURED_APPS += examples/wlan
|
||||
endif
|
||||
|
||||
+22
-27
@@ -37,12 +37,12 @@
|
||||
|
||||
# Sub-directories
|
||||
|
||||
SUBDIRS = adc buttons can cdcacm composite dhcpd discover ftpc ftpd hello
|
||||
SUBDIRS += helloxx hidkbd igmp lcdrw mm modbus mount nettest nsh null nx
|
||||
SUBDIRS += nxconsole nxffs nxflat nxhello nximage nxlines nxtext ostest
|
||||
SUBDIRS += pashello pipe poll pwm qencoder rgmp romfs serloop telnetd
|
||||
SUBDIRS += thttpd tiff touchscreen udp uip usbserial sendmail usbstorage
|
||||
SUBDIRS += usbterm watchdog wget wlan
|
||||
SUBDIRS = adc buttons can cdcacm composite cxxtest dhcpd discover elf ftpc
|
||||
SUBDIRS += ftpd hello helloxx hidkbd igmp json keypadtest lcdrw mm modbus mount
|
||||
SUBDIRS += nettest nsh null nx nxconsole nxffs nxflat nxhello nximage
|
||||
SUBDIRS += nxlines nxtext ostest pashello pipe poll pwm qencoder relays
|
||||
SUBDIRS += rgmp romfs serloop telnetd thttpd tiff touchscreen udp uip
|
||||
SUBDIRS += usbserial sendmail usbstorage usbterm watchdog wget wgetjson wlan
|
||||
|
||||
# Sub-directories that might need context setup. Directories may need
|
||||
# context setup for a variety of reasons, but the most common is because
|
||||
@@ -57,8 +57,8 @@ SUBDIRS += usbterm watchdog wget wlan
|
||||
CNTXTDIRS = pwm
|
||||
|
||||
ifeq ($(CONFIG_NSH_BUILTIN_APPS),y)
|
||||
CNTXTDIRS += adc can cdcacm composite discover ftpd dhcpd modbus nettest
|
||||
CNTXTDIRS += qencoder telnetd watchdog
|
||||
CNTXTDIRS += adc can cdcacm composite cxxtest dhcpd discover ftpd json keypadtest
|
||||
CNTXTDIRS += modbus nettest nxlines relays qencoder telnetd watchdog wgetjson
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_HELLO_BUILTIN),y)
|
||||
@@ -79,9 +79,6 @@ endif
|
||||
ifeq ($(CONFIG_EXAMPLES_NXIMAGE_BUILTIN),y)
|
||||
CNTXTDIRS += nximage
|
||||
endif
|
||||
ifeq ($(CONFIG_EXAMPLES_LINES_BUILTIN),y)
|
||||
CNTXTDIRS += nxlines
|
||||
endif
|
||||
ifeq ($(CONFIG_EXAMPLES_NXTEXT_BUILTIN),y)
|
||||
CNTXTDIRS += nxtext
|
||||
endif
|
||||
@@ -105,27 +102,25 @@ all: nothing
|
||||
|
||||
.PHONY: nothing context depend clean distclean
|
||||
|
||||
define SDIR_template
|
||||
$(1)_$(2):
|
||||
$(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"
|
||||
endef
|
||||
|
||||
$(foreach SDIR, $(CNTXTDIRS), $(eval $(call SDIR_template,$(SDIR),context)))
|
||||
$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),depend)))
|
||||
$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),clean)))
|
||||
$(foreach SDIR, $(SUBDIRS), $(eval $(call SDIR_template,$(SDIR),distclean)))
|
||||
|
||||
nothing:
|
||||
|
||||
context:
|
||||
@for dir in $(CNTXTDIRS) ; do \
|
||||
$(MAKE) -C $$dir context TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
|
||||
done
|
||||
context: $(foreach SDIR, $(CNTXTDIRS), $(SDIR)_context)
|
||||
|
||||
depend:
|
||||
@for dir in $(SUBDIRS) ; do \
|
||||
$(MAKE) -C $$dir depend TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
|
||||
done
|
||||
depend: $(foreach SDIR, $(SUBDIRS), $(SDIR)_depend)
|
||||
|
||||
clean:
|
||||
@for dir in $(SUBDIRS) ; do \
|
||||
$(MAKE) -C $$dir clean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
|
||||
done
|
||||
clean: $(foreach SDIR, $(SUBDIRS), $(SDIR)_clean)
|
||||
|
||||
distclean: clean
|
||||
@for dir in $(SUBDIRS) ; do \
|
||||
$(MAKE) -C $$dir distclean TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)"; \
|
||||
done
|
||||
distclean: clean $(foreach SDIR, $(SUBDIRS), $(SDIR)_distclean)
|
||||
|
||||
-include Make.dep
|
||||
|
||||
|
||||
+161
-13
@@ -239,6 +239,29 @@ examples/composite
|
||||
CONFIG_EXAMPLES_COMPOSITE_TRACEINTERRUPTS
|
||||
Show interrupt-related events.
|
||||
|
||||
examples/cxxtest
|
||||
^^^^^^^^^^^^^^^^
|
||||
|
||||
This is a test of the C++ standard library. At present a port of the uClibc++
|
||||
C++ library is available. Due to licensinging issues, the uClibc++ C++ library
|
||||
is not included in the NuttX source tree by default, but must be installed
|
||||
(see misc/uClibc++/README.txt for installation).
|
||||
|
||||
The NuttX setting that are required include:
|
||||
|
||||
CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_UCLIBCXX=y
|
||||
|
||||
Additional uClibc++ settings may be required in your build environment.
|
||||
|
||||
The uClibc++ test includes simple test of:
|
||||
|
||||
- iostreams,
|
||||
- STL,
|
||||
- RTTI, and
|
||||
- Exceptions
|
||||
|
||||
examples/dhcpd
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
@@ -297,6 +320,68 @@ examples/discover
|
||||
CONFIG_EXAMPLES_DISCOVER_DRIPADDR - Router IP address
|
||||
CONFIG_EXAMPLES_DISCOVER_NETMASK - Network Mask
|
||||
|
||||
examples/elf
|
||||
^^^^^^^^^^^^
|
||||
|
||||
This example builds a small ELF loader test case. This includes several
|
||||
test programs under examples/elf tests. These tests are build using
|
||||
the relocatable ELF format and installed in a ROMFS file system. At run time,
|
||||
each program in the ROMFS file system is executed. Requires CONFIG_ELF.
|
||||
Other configuration options:
|
||||
|
||||
CONFIG_EXAMPLES_ELF_DEVMINOR - The minor device number of the ROMFS block.
|
||||
For example, the N in /dev/ramN. Used for registering the RAM block driver
|
||||
that will hold the ROMFS file system containing the ELF executables to be
|
||||
tested. Default: 0
|
||||
|
||||
CONFIG_EXAMPLES_ELF_DEVPATH - The path to the ROMFS block driver device. This
|
||||
must match EXAMPLES_ELF_DEVMINOR. Used for registering the RAM block driver
|
||||
that will hold the ROMFS file system containing the ELF executables to be
|
||||
tested. Default: "/dev/ram0"
|
||||
|
||||
NOTES:
|
||||
|
||||
1. CFLAGS should be provided in CELFFLAGS. RAM and FLASH memory regions
|
||||
may require long allcs. For ARM, this might be:
|
||||
|
||||
CELFFLAGS = $(CFLAGS) -mlong-calls
|
||||
|
||||
Similarly for C++ flags which must be provided in CXXELFFLAGS.
|
||||
|
||||
2. Your top-level nuttx/Make.defs file must alos include an approproate definition,
|
||||
LDELFFLAGS, to generate a relocatable ELF object. With GNU LD, this should
|
||||
include '-r' and '-e main' (or _main on some platforms).
|
||||
|
||||
LDELFFLAGS = -r -e main
|
||||
|
||||
If you use GCC to link, you make also need to include '-nostdlib' or
|
||||
'-nostartfiles' and '-nodefaultlibs'.
|
||||
|
||||
3. This example also requires genromfs. genromfs can be build as part of the
|
||||
nuttx toolchain. Or can built from the genromfs sources that can be found
|
||||
at misc/tools/genromfs-0.5.2.tar.gz. In any event, the PATH variable must
|
||||
include the path to the genromfs executable.
|
||||
|
||||
4. ELF size: The ELF files in this example are, be default, quite large
|
||||
because they include a lot of "build garbage". You can greatly reduce the
|
||||
size of the ELF binaries are using the 'objcopy --strip-unneeded' command to
|
||||
remove un-necessary information from the ELF files.
|
||||
|
||||
5. Simulator. You cannot use this example with the the NuttX simulator on
|
||||
Cygwin. That is because the Cygwin GCC does not generate ELF file but
|
||||
rather some Windows-native binary format.
|
||||
|
||||
If you really want to do this, you can create a NuttX x86 buildroot toolchain
|
||||
and use that be build the ELF executables for the ROMFS file system.
|
||||
|
||||
6. Linker scripts. You might also want to use a linker scripts to combine
|
||||
sections better. An example linker script is at nuttx/binfmt/libelf/gnu-elf.ld.
|
||||
That example might have to be tuned for your particular linker output to
|
||||
position additional sections correctly. The GNU LD LDELFFLAGS then might
|
||||
be:
|
||||
|
||||
LDELFFLAGS = -r -e main -T$(TOPDIR)/binfmt/libelf/gnu-elf.ld
|
||||
|
||||
examples/ftpc
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
@@ -482,6 +567,32 @@ examples/igmp
|
||||
|
||||
CONFIGURED_APPS += uiplib
|
||||
|
||||
examples/json
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
This example exercises the cJSON implementation at apps/netutils/json.
|
||||
This example contains logic taken from the cJSON project:
|
||||
|
||||
http://sourceforge.net/projects/cjson/
|
||||
|
||||
The example corresponds to SVN revision r42 (with lots of changes for
|
||||
NuttX coding standards). As of r42, the SVN repository was last updated
|
||||
on 2011-10-10 so I presume that the code is stable and there is no risk
|
||||
of maintaining duplicate logic in the NuttX repository.
|
||||
|
||||
examples/keypadtest
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This is a generic keypad test example. It is similar to the USB hidkbd
|
||||
example, but makes no assumptions about the underlying keyboard interface.
|
||||
It uses the interfaces of include/nuttx/input/keypad.h.
|
||||
|
||||
CONFIG_EXAMPLES_KEYPADTEST - Selects the keypadtest example (only need
|
||||
if the mconf/Kconfig tool is used.
|
||||
|
||||
CONFIG_EXAMPLES_KEYPAD_DEVNAME - The name of the keypad device that will
|
||||
be opened in order to perform the keypad test. Default: "/dev/keypad"
|
||||
|
||||
examples/lcdrw
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
@@ -496,6 +607,11 @@ examples/lcdrw
|
||||
* CONFIG_EXAMPLES_LDCRW_YRES
|
||||
LCD Y resolution. Default: 320
|
||||
|
||||
NOTE: This test exercises internal lcd driver interfaces. As such, it
|
||||
relies on internal OS interfaces that are not normally available to a
|
||||
user-space program. As a result, this example cannot be used if a
|
||||
NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL).
|
||||
|
||||
examples/mm
|
||||
^^^^^^^^^^^
|
||||
|
||||
@@ -838,8 +954,6 @@ examplex/nxlines
|
||||
|
||||
The following configuration options can be selected:
|
||||
|
||||
CONFIG_EXAMPLES_NXLINES_BUILTIN -- Build the NXLINES example as a "built-in"
|
||||
that can be executed from the NSH command line
|
||||
CONFIG_EXAMPLES_NXLINES_VPLANE -- The plane to select from the frame-
|
||||
buffer driver for use in the test. Default: 0
|
||||
CONFIG_EXAMPLES_NXLINES_DEVNO - The LCD device to select from the LCD
|
||||
@@ -877,6 +991,9 @@ examplex/nxlines
|
||||
FAR struct fb_vtable_s *up_nxdrvinit(unsigned int devno);
|
||||
#endif
|
||||
|
||||
CONFIG_NSH_BUILTIN_APPS - Build the NX lines examples as an NSH built-in
|
||||
function.
|
||||
|
||||
examples/nxtext
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
@@ -984,6 +1101,17 @@ examples/ostest
|
||||
Specifies the number of threads to create in the barrier
|
||||
test. The default is 8 but a smaller number may be needed on
|
||||
systems without sufficient memory to start so many threads.
|
||||
* CONFIG_EXAMPLES_OSTEST_RR_RANGE
|
||||
During round-robin scheduling test two threads are created. Each of the threads
|
||||
searches for prime numbers in the configurable range, doing that configurable
|
||||
number of times.
|
||||
This value specifies the end of search range and together with number of runs
|
||||
allows to configure the length of this test - it should last at least a few
|
||||
tens of seconds. Allowed values [1; 32767], default 10000
|
||||
* CONFIG_EXAMPLES_OSTEST_RR_RUNS
|
||||
During round-robin scheduling test two threads are created. Each of the threads
|
||||
searches for prime numbers in the configurable range, doing that configurable
|
||||
number of times.
|
||||
|
||||
examples/pashello
|
||||
^^^^^^^^^^^^^^^^^
|
||||
@@ -1110,17 +1238,28 @@ examples/qencoder
|
||||
|
||||
Specific configuration options for this example include:
|
||||
|
||||
CONFIG_EXAMPLES_QENCODER_DEVPATH - The path to the QE device. Default:
|
||||
/dev/qe0
|
||||
CONFIG_EXAMPLES_QENCODER_NSAMPLES - If CONFIG_NSH_BUILTIN_APPS
|
||||
is defined, then the number of samples is provided on the command line
|
||||
and this value is ignored. Otherwise, this number of samples is
|
||||
collected and the program terminates. Default: Samples are collected
|
||||
indefinitely.
|
||||
CONFIG_EXAMPLES_QENCODER_DELAY - This value provides the delay (in
|
||||
milliseonds) between each sample. If CONFIG_NSH_BUILTIN_APPS
|
||||
is defined, then this value is the default delay if no other delay is
|
||||
provided on the command line. Default: 100 milliseconds
|
||||
CONFIG_EXAMPLES_QENCODER_DEVPATH - The path to the QE device. Default:
|
||||
/dev/qe0
|
||||
CONFIG_EXAMPLES_QENCODER_NSAMPLES - If CONFIG_NSH_BUILTIN_APPS
|
||||
is defined, then the number of samples is provided on the command line
|
||||
and this value is ignored. Otherwise, this number of samples is
|
||||
collected and the program terminates. Default: Samples are collected
|
||||
indefinitely.
|
||||
CONFIG_EXAMPLES_QENCODER_DELAY - This value provides the delay (in
|
||||
milliseonds) between each sample. If CONFIG_NSH_BUILTIN_APPS
|
||||
is defined, then this value is the default delay if no other delay is
|
||||
provided on the command line. Default: 100 milliseconds
|
||||
|
||||
examples/relays
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
Requires CONFIG_ARCH_RELAYS.
|
||||
Contributed by Darcy Gong.
|
||||
|
||||
NOTE: This test exercises internal relay driver interfaces. As such, it
|
||||
relies on internal OS interfaces that are not normally available to a
|
||||
user-space program. As a result, this example cannot be used if a
|
||||
NuttX is built as a protected, supervisor kernel (CONFIG_NUTTX_KERNEL).
|
||||
|
||||
examples/rgmp
|
||||
^^^^^^^^^^^^^
|
||||
@@ -1672,7 +1811,16 @@ examples/wget
|
||||
CONFIGURED_APPS += resolv
|
||||
CONFIGURED_APPS += webclient
|
||||
|
||||
examples/wget
|
||||
^^^^^^^^^^^^^
|
||||
|
||||
Uses wget to get a JSON encoded file, then decodes the file.
|
||||
|
||||
CONFIG_EXAMPLES_WDGETJSON_MAXSIZE - Max. JSON Buffer Size
|
||||
CONFIG_EXAMPLES_EXAMPLES_WGETJSON_URL - wget URL
|
||||
|
||||
examples/xmlrpc
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
This example exercises the "Embeddable Lightweight XML-RPC Server" which
|
||||
is discussed at:
|
||||
|
||||
@@ -7,7 +7,7 @@ comment "Interpreters"
|
||||
|
||||
source "$APPSDIR/interpreters/ficl/Kconfig"
|
||||
|
||||
config PCODE
|
||||
config INTERPRETERS_PCODE
|
||||
bool "Pascal p-code interpreter"
|
||||
default n
|
||||
---help---
|
||||
@@ -16,6 +16,6 @@ config PCODE
|
||||
configuration implies that you have performed the required installation of the
|
||||
Pascal run-time code.
|
||||
|
||||
if PCODE
|
||||
if INTERPRETERS_PCODE
|
||||
endif
|
||||
|
||||
|
||||
@@ -34,10 +34,10 @@
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_PCODE),y)
|
||||
ifeq ($(CONFIG_INTERPRETERS_PCODE),y)
|
||||
CONFIGURED_APPS += interpreters/pcode
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_FICL),y)
|
||||
ifeq ($(CONFIG_INTERPRETERS_FICL),y)
|
||||
CONFIGURED_APPS += interpreters/ficl
|
||||
endif
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
config FICL
|
||||
config INTERPRETERS_FICL
|
||||
bool "Ficl Forth interpreter"
|
||||
default n
|
||||
---help---
|
||||
@@ -11,6 +11,6 @@ config FICL
|
||||
apps/interpreters/ficl directory. Use of this configuration assumes
|
||||
that you have performed the required installation of the Ficl run-time code.
|
||||
|
||||
if FICL
|
||||
if INTERPRETERS_FICL
|
||||
endif
|
||||
|
||||
|
||||
+59
-15
@@ -235,6 +235,10 @@ o test <expression>
|
||||
integer -gt integer | integer -le integer |
|
||||
integer -lt integer | integer -ne integer
|
||||
|
||||
o base64dec [-w] [-f] <string or filepath>
|
||||
|
||||
o base64dec [-w] [-f] <string or filepath>
|
||||
|
||||
o cat <path> [<path> [<path> ...]]
|
||||
|
||||
This command copies and concatentates all of the files at <path>
|
||||
@@ -381,7 +385,11 @@ o help [-v] [<cmd>]
|
||||
<cmd>
|
||||
Show full command usage only for this command
|
||||
|
||||
o ifconfig
|
||||
o hexdump <file or device>
|
||||
|
||||
Dump data in hexadecimal format from a file or character device.
|
||||
|
||||
o ifconfig [nic_name [<ip-address>|dhcp]] [dr|gw|gateway <dr-address>] [netmask <net-mask>] [dns <dns-address>] [hw <hw-mac>]
|
||||
|
||||
Show the current configuration of the network, for example:
|
||||
|
||||
@@ -392,6 +400,22 @@ o ifconfig
|
||||
if uIP statistics are enabled (CONFIG_NET_STATISTICS), then
|
||||
this command will also show the detailed state of uIP.
|
||||
|
||||
o ifdown <nic-name>
|
||||
|
||||
Take down the interface identified by the name <nic-name>.
|
||||
|
||||
Example:
|
||||
|
||||
ifdown eth0
|
||||
|
||||
o ifup <nic-name>
|
||||
|
||||
Bring up down the interface identified by the name <nic-name>.
|
||||
|
||||
Example:
|
||||
|
||||
ifup eth0
|
||||
|
||||
o kill -<signal> <pid>
|
||||
|
||||
Send the <signal> to the task identified by <pid>.
|
||||
@@ -449,6 +473,8 @@ o ls [-lRs] <dir-path>
|
||||
-l Show size and mode information along with the filenames
|
||||
in the listing.
|
||||
|
||||
o md5 [-f] <string or filepath>
|
||||
|
||||
o mb <hex-address>[=<hex-value>][ <hex-byte-count>]
|
||||
o mh <hex-address>[=<hex-value>][ <hex-byte-count>]
|
||||
o mw <hex-address>[=<hex-value>][ <hex-byte-count>]
|
||||
@@ -781,6 +807,10 @@ o unset <name>
|
||||
|
||||
nsh>
|
||||
|
||||
o urldecode [-f] <string or filepath>
|
||||
|
||||
o urlencode [-f] <string or filepath>
|
||||
|
||||
o usleep <usec>
|
||||
|
||||
Pause execution (sleep) of <usec> microseconds.
|
||||
@@ -826,6 +856,8 @@ Command Dependencies on Configuration Settings
|
||||
Command Depends on Configuration
|
||||
---------- --------------------------
|
||||
[ !CONFIG_NSH_DISABLESCRIPT
|
||||
base64dec CONFIG_NETUTILS_CODECS && CONFIG_CODECS_BASE64
|
||||
base64enc CONFIG_NETUTILS_CODECS && CONFIG_CODECS_BASE64
|
||||
cat CONFIG_NFILE_DESCRIPTORS > 0
|
||||
cd !CONFIG_DISABLE_ENVIRON && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
cp CONFIG_NFILE_DESCRIPTORS > 0
|
||||
@@ -837,10 +869,14 @@ Command Dependencies on Configuration Settings
|
||||
free --
|
||||
get CONFIG_NET && CONFIG_NET_UDP && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NET_BUFSIZE >= 558 (see note 1)
|
||||
help --
|
||||
hexdump CONFIG_NFILE_DESCRIPTORS > 0
|
||||
ifconfig CONFIG_NET
|
||||
ifdown CONFIG_NET
|
||||
ifup CONFIG_NET
|
||||
kill !CONFIG_DISABLE_SIGNALS
|
||||
losetup !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
ls CONFIG_NFILE_DESCRIPTORS > 0
|
||||
md5 CONFIG_NETUTILS_CODECS && CONFIG_CODECS_HASH_MD5
|
||||
mb,mh,mw ---
|
||||
mkdir !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_WRITABLE (see note 4)
|
||||
mkfatfs !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_FAT
|
||||
@@ -861,6 +897,8 @@ Command Dependencies on Configuration Settings
|
||||
test !CONFIG_NSH_DISABLESCRIPT
|
||||
umount !CONFIG_DISABLE_MOUNTPOINT && CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_FS_READABLE
|
||||
unset !CONFIG_DISABLE_ENVIRON
|
||||
urldecode CONFIG_NETUTILS_CODECS && CONFIG_CODECS_URLCODE
|
||||
urlencode CONFIG_NETUTILS_CODECS && CONFIG_CODECS_URLCODE
|
||||
usleep !CONFIG_DISABLE_SIGNALS
|
||||
get CONFIG_NET && CONFIG_NET_TCP && CONFIG_NFILE_DESCRIPTORS > 0
|
||||
xd ---
|
||||
@@ -880,20 +918,22 @@ In addition, each NSH command can be individually disabled via one of the follow
|
||||
settings. All of these settings make the configuration of NSH potentially complex but
|
||||
also allow it to squeeze into very small memory footprints.
|
||||
|
||||
CONFIG_NSH_DISABLE_CAT, CONFIG_NSH_DISABLE_CD, CONFIG_NSH_DISABLE_CP,
|
||||
CONFIG_NSH_DISABLE_DD, CONFIG_NSH_DISABLE_DF, CONFIG_NSH_DISABLE_ECHO,
|
||||
CONFIG_NSH_DISABLE_EXEC, CONFIG_NSH_DISABLE_EXIT, CONFIG_NSH_DISABLE_FREE,
|
||||
CONFIG_NSH_DISABLE_GET, CONFIG_NSH_DISABLE_HELP, CONFIG_NSH_DISABLE_IFCONFIG,
|
||||
CONFIG_NSH_DISABLE_KILL, CONFIG_NSH_DISABLE_LOSETUP, CONFIG_NSH_DISABLE_LS,
|
||||
CONFIG_NSH_DISABLE_MB, CONFIG_NSH_DISABLE_MKDIR, CONFIG_NSH_DISABLE_MKFATFS,
|
||||
CONFIG_NSH_DISABLE_MKFIFO, CONFIG_NSH_DISABLE_MKRD, CONFIG_NSH_DISABLE_MH,
|
||||
CONFIG_NSH_DISABLE_MOUNT, CONFIG_NSH_DISABLE_MW, CONFIG_NSH_DISABLE_MV,
|
||||
CONFIG_NSH_DISABLE_NFSMOUNT, CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING,
|
||||
CONFIG_NSH_DISABLE_PUT, CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_RM,
|
||||
CONFIG_NSH_DISABLE_RMDIR, CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH,
|
||||
CONFIG_NSH_DISABLE_SLEEP, CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT,
|
||||
CONFIG_NSH_DISABLE_UNSET, CONFIG_NSH_DISABLE_USLEEP, CONFIG_NSH_DISABLE_WGET,
|
||||
CONFIG_NSH_DISABLE_XD
|
||||
CONFIG_NSH_DISABLE_BASE64DEC, CONFIG_NSH_DISABLE_BASE64ENC, CONFIG_NSH_DISABLE_CAT,
|
||||
CONFIG_NSH_DISABLE_CD, CONFIG_NSH_DISABLE_CP, CONFIG_NSH_DISABLE_DD,
|
||||
CONFIG_NSH_DISABLE_DF, CONFIG_NSH_DISABLE_ECHO, CONFIG_NSH_DISABLE_EXEC,
|
||||
CONFIG_NSH_DISABLE_EXIT, CONFIG_NSH_DISABLE_FREE, CONFIG_NSH_DISABLE_GET,
|
||||
CONFIG_NSH_DISABLE_HELP, CONFIG_NSH_DISABLE_HEXDUMP, CONFIG_NSH_DISABLE_IFCONFIG,
|
||||
CONFIG_NSH_DISABLE_IFUPDOWN, CONFIG_NSH_DISABLE_KILL, CONFIG_NSH_DISABLE_LOSETUP,
|
||||
CONFIG_NSH_DISABLE_LS, CONFIG_NSH_DISABLE_MD5 CONFIG_NSH_DISABLE_MB,
|
||||
CONFIG_NSH_DISABLE_MKDIR, CONFIG_NSH_DISABLE_MKFATFS, CONFIG_NSH_DISABLE_MKFIFO,
|
||||
CONFIG_NSH_DISABLE_MKRD, CONFIG_NSH_DISABLE_MH, CONFIG_NSH_DISABLE_MOUNT,
|
||||
CONFIG_NSH_DISABLE_MW, CONFIG_NSH_DISABLE_MV, CONFIG_NSH_DISABLE_NFSMOUNT,
|
||||
CONFIG_NSH_DISABLE_PS, CONFIG_NSH_DISABLE_PING, CONFIG_NSH_DISABLE_PUT,
|
||||
CONFIG_NSH_DISABLE_PWD, CONFIG_NSH_DISABLE_RM, CONFIG_NSH_DISABLE_RMDIR,
|
||||
CONFIG_NSH_DISABLE_SET, CONFIG_NSH_DISABLE_SH, CONFIG_NSH_DISABLE_SLEEP,
|
||||
CONFIG_NSH_DISABLE_TEST, CONFIG_NSH_DISABLE_UMOUNT, CONFIG_NSH_DISABLE_UNSET,
|
||||
CONFIG_NSH_DISABLE_URLDECODE, CONFIG_NSH_DISABLE_URLENCODE, CONFIG_NSH_DISABLE_USLEEP,
|
||||
CONFIG_NSH_DISABLE_WGET, CONFIG_NSH_DISABLE_XD
|
||||
|
||||
Verbose help output can be suppressed by defining CONFIG_NSH_HELP_TERSE. In that
|
||||
case, the help command is still available but will be slightly smaller.
|
||||
@@ -1084,6 +1124,10 @@ NSH-Specific Configuration Settings
|
||||
Set if your ethernet hardware has no built-in MAC address.
|
||||
If set, a bogus MAC will be assigned.
|
||||
|
||||
* CONFIG_NSH_MAX_ROUNDTRIP
|
||||
This is the maximum round trip for a response to a ICMP ECHO request.
|
||||
It is in units of deciseconds. The default is 20 (2 seconds).
|
||||
|
||||
If you use DHCPC, then some special configuration network options are
|
||||
required. These include:
|
||||
|
||||
|
||||
+37
-4
@@ -122,13 +122,28 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
ret = exec_namedapp(cmd, (FAR const char **)argv);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* The application was successfully started (but still blocked because the
|
||||
* scheduler is locked). If the application was not backgrounded, then we
|
||||
* need to wait here for the application to exit.
|
||||
/* The application was successfully started (but still blocked because
|
||||
* the scheduler is locked). If the application was not backgrounded,
|
||||
* then we need to wait here for the application to exit. These really
|
||||
* only works works with the following options:
|
||||
*
|
||||
* - CONFIG_NSH_DISABLEBG - Do not run commands in background
|
||||
* - CONFIG_SCHED_WAITPID - Required to run external commands in
|
||||
* foreground
|
||||
*
|
||||
* These concepts do not apply cleanly to the external applications.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_SCHED_WAITPID
|
||||
|
||||
/* CONFIG_SCHED_WAITPID is selected, so we may run the command in
|
||||
* foreground unless we were specifically requested to run the command
|
||||
* in background (and running commands in background is enabled).
|
||||
*/
|
||||
|
||||
# ifndef CONFIG_NSH_DISABLEBG
|
||||
if (vtbl->np.np_bg == false)
|
||||
# endif /* CONFIG_NSH_DISABLEBG */
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
@@ -155,8 +170,25 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
*/
|
||||
}
|
||||
}
|
||||
# ifndef CONFIG_NSH_DISABLEBG
|
||||
else
|
||||
#endif
|
||||
# endif /* CONFIG_NSH_DISABLEBG */
|
||||
#endif /* CONFIG_SCHED_WAITPID */
|
||||
|
||||
/* We get here if either:
|
||||
*
|
||||
* - CONFIG_SCHED_WAITPID is not selected meaning that all commands
|
||||
* have to be run in background, or
|
||||
* - CONFIG_SCHED_WAITPID and CONFIG_NSH_DISABLEBG are both selected, but the
|
||||
* user requested to run the command in background.
|
||||
*
|
||||
* NOTE that the case of a) CONFIG_SCHED_WAITPID is not selected and
|
||||
* b) CONFIG_NSH_DISABLEBG selected cannot be supported. In that event, all
|
||||
* commands will have to run in background. The waitpid() API must be
|
||||
* available to support running the command in foreground.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_SCHED_WAITPID) || !defined(CONFIG_NSH_DISABLEBG)
|
||||
{
|
||||
struct sched_param param;
|
||||
sched_getparam(0, ¶m);
|
||||
@@ -168,6 +200,7 @@ int nsh_execapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||
|
||||
ret = OK;
|
||||
}
|
||||
#endif /* !CONFIG_SCHED_WAITPID || !CONFIG_NSH_DISABLEBG */
|
||||
}
|
||||
|
||||
sched_unlock();
|
||||
|
||||
@@ -160,11 +160,11 @@ int nsh_consolemain(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
/* Clean up */
|
||||
/* Clean up. We do not get here, but this is necessary to keep some
|
||||
* compilers happy. But others will complain that this code is not
|
||||
* reachable.
|
||||
*/
|
||||
|
||||
nsh_exit(&pstate->cn_vtbl, 0);
|
||||
|
||||
/* We do not get here, but this is necessary to keep some compilers happy */
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
|
||||
pcvalue++;
|
||||
|
||||
lvalue = (unsigned long)strtol(pcvalue, NULL, 16);
|
||||
if (lvalue > 0xffffffff)
|
||||
if (lvalue > 0xffffffffL)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
@@ -127,6 +127,7 @@ int mem_parse(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv,
|
||||
{
|
||||
mem->dm_count = 1;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
+307
-20
@@ -51,6 +51,7 @@
|
||||
#include <fcntl.h> /* Needed for open */
|
||||
#include <libgen.h> /* Needed for basename */
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/clock.h>
|
||||
@@ -80,6 +81,15 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
|
||||
# ifdef CONFIG_HAVE_GETHOSTBYNAME
|
||||
# include <netdb.h>
|
||||
# else
|
||||
# include <apps/netutils/resolv.h>
|
||||
# endif
|
||||
# include <apps/netutils/dhcpc.h>
|
||||
#endif
|
||||
|
||||
#include "nsh.h"
|
||||
#include "nsh_console.h"
|
||||
|
||||
@@ -87,8 +97,16 @@
|
||||
* Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Size of the ECHO data */
|
||||
|
||||
#define DEFAULT_PING_DATALEN 56
|
||||
|
||||
/* Get the larger value */
|
||||
|
||||
#ifndef MAX
|
||||
# define MAX(a,b) (a > b ? a : b)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@@ -262,14 +280,34 @@ int ifconfig_callback(FAR struct uip_driver_s *dev, void *arg)
|
||||
{
|
||||
struct nsh_vtbl_s *vtbl = (struct nsh_vtbl_s*)arg;
|
||||
struct in_addr addr;
|
||||
bool is_running = false;
|
||||
int ret;
|
||||
|
||||
ret = uip_getifstatus(dev->d_ifname,&is_running);
|
||||
if (ret != OK)
|
||||
{
|
||||
nsh_output(vtbl, "\tGet %s interface flags error: %d\n",
|
||||
dev->d_ifname, ret);
|
||||
}
|
||||
|
||||
nsh_output(vtbl, "%s\tHWaddr %s at %s\n",
|
||||
dev->d_ifname, ether_ntoa(&dev->d_mac), (is_running)?"UP":"DOWN");
|
||||
|
||||
nsh_output(vtbl, "%s\tHWaddr %s\n", dev->d_ifname, ether_ntoa(&dev->d_mac));
|
||||
addr.s_addr = dev->d_ipaddr;
|
||||
nsh_output(vtbl, "\tIPaddr:%s ", inet_ntoa(addr));
|
||||
|
||||
addr.s_addr = dev->d_draddr;
|
||||
nsh_output(vtbl, "DRaddr:%s ", inet_ntoa(addr));
|
||||
|
||||
addr.s_addr = dev->d_netmask;
|
||||
nsh_output(vtbl, "Mask:%s\n\n", inet_ntoa(addr));
|
||||
nsh_output(vtbl, "Mask:%s\n", inet_ntoa(addr));
|
||||
|
||||
#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
|
||||
resolv_getserver(&addr);
|
||||
nsh_output(vtbl, "\tDNSaddr:%s\n", inet_ntoa(addr));
|
||||
#endif
|
||||
|
||||
nsh_output(vtbl, "\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -468,6 +506,54 @@ int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_ifup
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NSH_DISABLE_IFUPDOWN
|
||||
int cmd_ifup(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
FAR char *intf = NULL;
|
||||
int ret;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
nsh_output(vtbl, "Please select nic_name:\n");
|
||||
netdev_foreach(ifconfig_callback, vtbl);
|
||||
return OK;
|
||||
}
|
||||
|
||||
intf = argv[1];
|
||||
ret = uip_ifup(intf);
|
||||
nsh_output(vtbl, "ifup %s...%s\n", intf, (ret == OK) ? "OK" : "Failed");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_ifdown
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NSH_DISABLE_IFUPDOWN
|
||||
int cmd_ifdown(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
FAR char *intf = NULL;
|
||||
int ret;
|
||||
|
||||
if (argc != 2)
|
||||
{
|
||||
nsh_output(vtbl, "Please select nic_name:\n");
|
||||
netdev_foreach(ifconfig_callback, vtbl);
|
||||
return OK;
|
||||
}
|
||||
|
||||
intf = argv[1];
|
||||
ret = uip_ifdown(intf);
|
||||
nsh_output(vtbl, "ifdown %s...%s\n", intf, (ret == OK) ? "OK" : "Failed");
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: cmd_ifconfig
|
||||
****************************************************************************/
|
||||
@@ -476,7 +562,20 @@ int cmd_get(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
{
|
||||
struct in_addr addr;
|
||||
in_addr_t ip;
|
||||
in_addr_t gip;
|
||||
int i;
|
||||
FAR char *intf = NULL;
|
||||
FAR char *hostip = NULL;
|
||||
FAR char *gwip = NULL;
|
||||
FAR char *mask = NULL;
|
||||
FAR char *tmp = NULL;
|
||||
FAR char *hw = NULL;
|
||||
FAR char *dns = NULL;
|
||||
bool badarg = false;
|
||||
uint8_t mac[IFHWADDRLEN];
|
||||
#if defined(CONFIG_NSH_DHCPC)
|
||||
FAR void *handle;
|
||||
#endif
|
||||
|
||||
/* With one or no arguments, ifconfig simply shows the status of ethernet
|
||||
* device:
|
||||
@@ -498,24 +597,201 @@ int cmd_ifconfig(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
* ifconfig nic_name ip_address
|
||||
*/
|
||||
|
||||
/* Set host ip address */
|
||||
if (argc > 2)
|
||||
{
|
||||
for(i = 0; i < argc; i++)
|
||||
{
|
||||
if (i == 1)
|
||||
{
|
||||
intf = argv[i];
|
||||
}
|
||||
else if (i == 2)
|
||||
{
|
||||
hostip = argv[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = argv[i];
|
||||
if (!strcmp(tmp, "dr") || !strcmp(tmp, "gw") || !strcmp(tmp, "gateway"))
|
||||
{
|
||||
if (argc-1 >= i+1)
|
||||
{
|
||||
gwip = argv[i+1];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
badarg = true;
|
||||
}
|
||||
}
|
||||
else if(!strcmp(tmp, "netmask"))
|
||||
{
|
||||
if (argc-1 >= i+1)
|
||||
{
|
||||
mask = argv[i+1];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
badarg = true;
|
||||
}
|
||||
}
|
||||
else if(!strcmp(tmp, "hw"))
|
||||
{
|
||||
if (argc-1>=i+1)
|
||||
{
|
||||
hw = argv[i+1];
|
||||
i++;
|
||||
badarg = !uiplib_hwmacconv(hw, mac);
|
||||
}
|
||||
else
|
||||
{
|
||||
badarg = true;
|
||||
}
|
||||
}
|
||||
else if(!strcmp(tmp, "dns"))
|
||||
{
|
||||
if (argc-1 >= i+1)
|
||||
{
|
||||
dns = argv[i+1];
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
badarg = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ip = addr.s_addr = inet_addr(argv[2]);
|
||||
uip_sethostaddr(argv[1], &addr);
|
||||
if (badarg)
|
||||
{
|
||||
nsh_output(vtbl, g_fmtargrequired, argv[0]);
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/* Set Hardware ethernet MAC addr */
|
||||
|
||||
if (hw)
|
||||
{
|
||||
ndbg("HW MAC: %s\n", hw);
|
||||
uip_setmacaddr(intf, mac);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_NSH_DHCPC)
|
||||
if (!strcmp(hostip, "dhcp"))
|
||||
{
|
||||
/* Set DHCP addr */
|
||||
|
||||
ndbg("DHCPC Mode\n");
|
||||
gip = addr.s_addr = 0;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* Set host IP address */
|
||||
|
||||
ndbg("Host IP: %s\n", hostip);
|
||||
gip = addr.s_addr = inet_addr(hostip);
|
||||
}
|
||||
|
||||
uip_sethostaddr(intf, &addr);
|
||||
|
||||
/* Set gateway */
|
||||
|
||||
ip = NTOHL(ip);
|
||||
ip &= ~0x000000ff;
|
||||
ip |= 0x00000001;
|
||||
if (gwip)
|
||||
{
|
||||
ndbg("Gateway: %s\n", gwip);
|
||||
gip = addr.s_addr = inet_addr(gwip);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (gip)
|
||||
{
|
||||
ndbg("Gateway: default\n");
|
||||
gip = NTOHL(gip);
|
||||
gip &= ~0x000000ff;
|
||||
gip |= 0x00000001;
|
||||
gip = HTONL(gip);
|
||||
}
|
||||
|
||||
addr.s_addr = HTONL(ip);
|
||||
uip_setdraddr(argv[1], &addr);
|
||||
addr.s_addr = gip;
|
||||
}
|
||||
|
||||
/* Set netmask */
|
||||
uip_setdraddr(intf, &addr);
|
||||
|
||||
addr.s_addr = inet_addr("255.255.255.0");
|
||||
uip_setnetmask(argv[1], &addr);
|
||||
/* Set network mask */
|
||||
|
||||
if (mask)
|
||||
{
|
||||
ndbg("Netmask: %s\n",mask);
|
||||
addr.s_addr = inet_addr(mask);
|
||||
}
|
||||
else
|
||||
{
|
||||
ndbg("Netmask: Default\n");
|
||||
addr.s_addr = inet_addr("255.255.255.0");
|
||||
}
|
||||
|
||||
uip_setnetmask(intf, &addr);
|
||||
|
||||
#if defined(CONFIG_NSH_DHCPC) || defined(CONFIG_NSH_DNS)
|
||||
if (dns)
|
||||
{
|
||||
ndbg("DNS: %s\n", dns);
|
||||
addr.s_addr = inet_addr(dns);
|
||||
}
|
||||
else
|
||||
{
|
||||
ndbg("DNS: Default\n");
|
||||
addr.s_addr = gip;
|
||||
}
|
||||
|
||||
resolv_conf(&addr);
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NSH_DHCPC)
|
||||
/* Get the MAC address of the NIC */
|
||||
|
||||
if (!gip)
|
||||
{
|
||||
uip_getmacaddr("eth0", mac);
|
||||
|
||||
/* Set up the DHCPC modules */
|
||||
|
||||
handle = dhcpc_open(&mac, IFHWADDRLEN);
|
||||
|
||||
/* Get an IP address. Note that there is no logic for renewing the IP address in this
|
||||
* example. The address should be renewed in ds.lease_time/2 seconds.
|
||||
*/
|
||||
|
||||
if (handle)
|
||||
{
|
||||
struct dhcpc_state ds;
|
||||
|
||||
(void)dhcpc_request(handle, &ds);
|
||||
uip_sethostaddr("eth0", &ds.ipaddr);
|
||||
|
||||
if (ds.netmask.s_addr != 0)
|
||||
{
|
||||
uip_setnetmask("eth0", &ds.netmask);
|
||||
}
|
||||
|
||||
if (ds.default_router.s_addr != 0)
|
||||
{
|
||||
uip_setdraddr("eth0", &ds.default_router);
|
||||
}
|
||||
|
||||
if (ds.dnsaddr.s_addr != 0)
|
||||
{
|
||||
resolv_conf(&ds.dnsaddr);
|
||||
}
|
||||
|
||||
dhcpc_close(handle);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
@@ -536,6 +812,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
uint32_t start;
|
||||
uint32_t next;
|
||||
uint32_t dsec = 10;
|
||||
uint32_t maxwait;
|
||||
uint16_t id;
|
||||
bool badarg = false;
|
||||
int count = 10;
|
||||
@@ -599,7 +876,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
if (optind == argc-1)
|
||||
{
|
||||
staddr = argv[optind];
|
||||
if (!uiplib_ipaddrconv(staddr, (FAR unsigned char*)&ipaddr))
|
||||
if (dns_gethostip(staddr, &ipaddr) < 0)
|
||||
{
|
||||
goto errout;
|
||||
}
|
||||
@@ -619,16 +896,26 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
|
||||
id = ping_newid();
|
||||
|
||||
/* The maximum wait for a response will be the larger of the inter-ping time and
|
||||
* the configured maximum round-trip time.
|
||||
*/
|
||||
|
||||
maxwait = MAX(dsec, CONFIG_NSH_MAX_ROUNDTRIP);
|
||||
|
||||
/* Loop for the specified count */
|
||||
|
||||
nsh_output(vtbl, "PING %s %d bytes of data\n", staddr, DEFAULT_PING_DATALEN);
|
||||
nsh_output(vtbl, "PING %d.%d.%d.%d %d bytes of data\n",
|
||||
(ipaddr ) & 0xff, (ipaddr >> 8 ) & 0xff,
|
||||
(ipaddr >> 16 ) & 0xff, (ipaddr >> 24 ) & 0xff,
|
||||
DEFAULT_PING_DATALEN);
|
||||
|
||||
start = g_system_timer;
|
||||
for (i = 1; i <= count; i++)
|
||||
{
|
||||
/* Send the ECHO request and wait for the response */
|
||||
|
||||
next = g_system_timer;
|
||||
seqno = uip_ping(ipaddr, id, i, DEFAULT_PING_DATALEN, dsec);
|
||||
seqno = uip_ping(ipaddr, id, i, DEFAULT_PING_DATALEN, maxwait);
|
||||
|
||||
/* Was any response returned? We can tell if a non-negative sequence
|
||||
* number was returned.
|
||||
@@ -636,7 +923,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
|
||||
if (seqno >= 0 && seqno <= i)
|
||||
{
|
||||
/* Get the elpased time from the time that the request was
|
||||
/* Get the elapsed time from the time that the request was
|
||||
* sent until the response was received. If we got a response
|
||||
* to an earlier request, then fudge the elpased time.
|
||||
*/
|
||||
@@ -644,7 +931,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
elapsed = TICK2MSEC(g_system_timer - next);
|
||||
if (seqno < i)
|
||||
{
|
||||
elapsed += 100*dsec*(i - seqno);
|
||||
elapsed += 100 * dsec * (i - seqno);
|
||||
}
|
||||
|
||||
/* Report the receipt of the reply */
|
||||
@@ -662,7 +949,7 @@ int cmd_ping(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
|
||||
elapsed = TICK2DSEC(g_system_timer - next);
|
||||
if (elapsed < dsec)
|
||||
{
|
||||
usleep(100000*dsec);
|
||||
usleep(100000 * (dsec - elapsed));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ int nsh_netinit(void)
|
||||
{
|
||||
struct dhcpc_state ds;
|
||||
(void)dhcpc_request(handle, &ds);
|
||||
uip_sethostaddr("eth1", &ds.ipaddr);
|
||||
uip_sethostaddr("eth0", &ds.ipaddr);
|
||||
if (ds.netmask.s_addr != 0)
|
||||
{
|
||||
uip_setnetmask("eth0", &ds.netmask);
|
||||
|
||||
+49
-14
@@ -73,19 +73,19 @@
|
||||
/* Argument list size
|
||||
*
|
||||
* argv[0]: The command name.
|
||||
* argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS)
|
||||
* argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS)
|
||||
* argv[argc-3]: Possibly '>' or '>>'
|
||||
* argv[argc-2]: Possibly <file>
|
||||
* argv[argc-1]: Possibly '&' (if pthreads are enabled)
|
||||
* argv[argc]: NULL terminating pointer
|
||||
*
|
||||
* Maximum size is NSH_MAX_ARGUMENTS+5
|
||||
* Maximum size is CONFIG_NSH_MAXARGUMENTS+5
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_NSH_DISABLEBG
|
||||
# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+5)
|
||||
# define MAX_ARGV_ENTRIES (CONFIG_NSH_MAXARGUMENTS+5)
|
||||
#else
|
||||
# define MAX_ARGV_ENTRIES (NSH_MAX_ARGUMENTS+4)
|
||||
# define MAX_ARGV_ENTRIES (CONFIG_NSH_MAXARGUMENTS+4)
|
||||
#endif
|
||||
|
||||
/* Help command summary layout */
|
||||
@@ -146,16 +146,25 @@ static const char g_failure[] = "1";
|
||||
static const struct cmdmap_s g_cmdmap[] =
|
||||
{
|
||||
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
|
||||
{ "[", cmd_lbracket, 4, NSH_MAX_ARGUMENTS, "<expression> ]" },
|
||||
{ "[", cmd_lbracket, 4, CONFIG_NSH_MAXARGUMENTS, "<expression> ]" },
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_NSH_DISABLE_HELP
|
||||
{ "?", cmd_help, 1, 1, NULL },
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_BASE64)
|
||||
# ifndef CONFIG_NSH_DISABLE_BASE64DEC
|
||||
{ "base64dec", cmd_base64decode, 2, 4, "[-w] [-f] <string or filepath>" },
|
||||
# endif
|
||||
# ifndef CONFIG_NSH_DISABLE_BASE64ENC
|
||||
{ "base64enc", cmd_base64encode, 2, 4, "[-w] [-f] <string or filepath>" },
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
# ifndef CONFIG_NSH_DISABLE_CAT
|
||||
{ "cat", cmd_cat, 2, NSH_MAX_ARGUMENTS, "<path> [<path> [<path> ...]]" },
|
||||
{ "cat", cmd_cat, 2, CONFIG_NSH_MAXARGUMENTS, "<path> [<path> [<path> ...]]" },
|
||||
# endif
|
||||
#ifndef CONFIG_DISABLE_ENVIRON
|
||||
# ifndef CONFIG_NSH_DISABLE_CD
|
||||
@@ -187,9 +196,9 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||
|
||||
#ifndef CONFIG_NSH_DISABLE_ECHO
|
||||
# ifndef CONFIG_DISABLE_ENVIRON
|
||||
{ "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string|$name> [<string|$name>...]]" },
|
||||
{ "echo", cmd_echo, 0, CONFIG_NSH_MAXARGUMENTS, "[<string|$name> [<string|$name>...]]" },
|
||||
# else
|
||||
{ "echo", cmd_echo, 0, NSH_MAX_ARGUMENTS, "[<string> [<string>...]]" },
|
||||
{ "echo", cmd_echo, 0, CONFIG_NSH_MAXARGUMENTS, "[<string> [<string>...]]" },
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -217,10 +226,20 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||
{ "help", cmd_help, 1, 3, "[-v] [<cmd>]" },
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
#ifndef CONFIG_NSH_DISABLE_HEXDUMP
|
||||
{ "hexdump", cmd_hexdump, 2, 2, "<file or device>" },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET
|
||||
# ifndef CONFIG_NSH_DISABLE_IFCONFIG
|
||||
{ "ifconfig", cmd_ifconfig, 1, 3, "[nic_name [ip]]" },
|
||||
{ "ifconfig", cmd_ifconfig, 1, 11, "[nic_name [<ip-address>|dhcp]] [dr|gw|gateway <dr-address>] [netmask <net-mask>] [dns <dns-address>] [hw <hw-mac>]" },
|
||||
# endif
|
||||
# ifndef CONFIG_NSH_DISABLE_IFUPDOWN
|
||||
{ "ifdown", cmd_ifdown, 2, 2, "<nic_name>" },
|
||||
{ "ifup", cmd_ifup, 2, 2, "<nic_name>" },
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -246,6 +265,12 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||
{ "mb", cmd_mb, 2, 3, "<hex-address>[=<hex-value>][ <hex-byte-count>]" },
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_HASH_MD5)
|
||||
# ifndef CONFIG_NSH_DISABLE_MD5
|
||||
{ "md5", cmd_md5, 2, 3, "[-f] <string or filepath>" },
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_WRITABLE)
|
||||
# ifndef CONFIG_NSH_DISABLE_MKDIR
|
||||
{ "mkdir", cmd_mkdir, 2, 2, "<path>" },
|
||||
@@ -348,7 +373,7 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
|
||||
{ "test", cmd_test, 3, NSH_MAX_ARGUMENTS, "<expression>" },
|
||||
{ "test", cmd_test, 3, CONFIG_NSH_MAXARGUMENTS, "<expression>" },
|
||||
#endif
|
||||
|
||||
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && CONFIG_NFILE_DESCRIPTORS > 0 && defined(CONFIG_FS_READABLE)
|
||||
@@ -363,6 +388,15 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NETUTILS_CODECS) && defined(CONFIG_CODECS_URLCODE)
|
||||
# ifndef CONFIG_NSH_DISABLE_URLDECODE
|
||||
{ "urldecode", cmd_urldecode, 2, 3, "[-f] <string or filepath>" },
|
||||
# endif
|
||||
# ifndef CONFIG_NSH_DISABLE_URLENCODE
|
||||
{ "urlencode", cmd_urlencode, 2, 3, "[-f] <string or filepath>" },
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_DISABLE_SIGNALS
|
||||
# ifndef CONFIG_NSH_DISABLE_USLEEP
|
||||
{ "usleep", cmd_usleep, 2, 2, "<usec>" },
|
||||
@@ -378,6 +412,7 @@ static const struct cmdmap_s g_cmdmap[] =
|
||||
#ifndef CONFIG_NSH_DISABLE_XD
|
||||
{ "xd", cmd_xd, 3, 3, "<hex-address> <byte-count>" },
|
||||
#endif
|
||||
|
||||
{ NULL, NULL, 1, 1, NULL }
|
||||
};
|
||||
|
||||
@@ -711,7 +746,7 @@ static int nsh_execute(FAR struct nsh_vtbl_s *vtbl, int argc, char *argv[])
|
||||
*
|
||||
* argv[0]: The command name. This is argv[0] when the arguments
|
||||
* are, finally, received by the command vtblr
|
||||
* argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS)
|
||||
* argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS)
|
||||
* argv[argc]: NULL terminating pointer
|
||||
*/
|
||||
|
||||
@@ -1318,13 +1353,13 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
|
||||
* of argv is:
|
||||
*
|
||||
* argv[0]: The command name.
|
||||
* argv[1]: The beginning of argument (up to NSH_MAX_ARGUMENTS)
|
||||
* argv[1]: The beginning of argument (up to CONFIG_NSH_MAXARGUMENTS)
|
||||
* argv[argc-3]: Possibly '>' or '>>'
|
||||
* argv[argc-2]: Possibly <file>
|
||||
* argv[argc-1]: Possibly '&'
|
||||
* argv[argc]: NULL terminating pointer
|
||||
*
|
||||
* Maximum size is NSH_MAX_ARGUMENTS+5
|
||||
* Maximum size is CONFIG_NSH_MAXARGUMENTS+5
|
||||
*/
|
||||
|
||||
argv[0] = cmd;
|
||||
@@ -1398,7 +1433,7 @@ int nsh_parse(FAR struct nsh_vtbl_s *vtbl, char *cmdline)
|
||||
|
||||
/* Check if the maximum number of arguments was exceeded */
|
||||
|
||||
if (argc > NSH_MAX_ARGUMENTS)
|
||||
if (argc > CONFIG_NSH_MAXARGUMENTS)
|
||||
{
|
||||
nsh_output(vtbl, g_fmttoomanyargs, cmd);
|
||||
}
|
||||
|
||||
+331
-1
@@ -3453,7 +3453,7 @@
|
||||
* net/uip/uip_icmpping.c: Fix problem that prevented ping from
|
||||
going outside of local network. Submitted by Darcy Gong
|
||||
|
||||
6.23 2012-09-29 Gregory Nutt <gnutt@nuttx.org>
|
||||
6.23 2012-11-05 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* arch/arm/src/stm32/stm32_rng.c, chip/stm32_rng.h, and other files:
|
||||
Implementation of /dev/random using the STM32 Random Number
|
||||
@@ -3470,4 +3470,334 @@
|
||||
* configs/shenzhou/*/Make.defs: Now uses the new buildroot 4.6.3
|
||||
EABI toolchain.
|
||||
* lib/stdio/lib_libdtoa.c: Another dtoa() fix from Mike Smith.
|
||||
* configs/shenzhou/src/up_adc.c: Add ADC support for the Shenzhou
|
||||
board (Darcy Gong).
|
||||
* configs/shenzhou/thttpd: Add a THTTPD configuration for the
|
||||
Shenzhou board (Darcy Gong).
|
||||
* include/termios.h and lib/termios/libcf*speed.c: The non-standard,
|
||||
"hidden" c_speed cannot be type const or else static instantiations
|
||||
of termios will be required to initialize it (Mike Smith).
|
||||
* drivers/input/max11802.c/h, and include/nuttx/input max11802.h: Adds
|
||||
support for the Maxim MAX11802 touchscreen controller (contributed by
|
||||
Petteri Aimonen).
|
||||
* graphics/nxtk/nxtk_events.c: Missing implementation of the blocked
|
||||
method. This is a critical bugfix for graphics support (contributed
|
||||
by Petteri Aimonen).
|
||||
* drivers/usbdev/pl2303.c, drivers/usbdev/usbmsc.h, and
|
||||
include/nuttx/usb/cdcacm.h: USB_CONFIG_ATTR_SELFPOWER vs.
|
||||
USB_CONFIG_ATT_SELFPOWER (contributed by Petteri Aimonen).
|
||||
* arch/arm/src/armv7-m/up_memcpy.S: An optimized memcpy() function for
|
||||
the ARMv7-M family contributed by Mike Smith.
|
||||
* lib/strings/lib_vikmemcpy.c: As an option, the larger but faster
|
||||
implemementation of memcpy from Daniel Vik is now available (this is
|
||||
from http://www.danielvik.com/2010/02/fast-memcpy-in-c.html).
|
||||
* lib/strings/lib_memset.c: CONFIG_MEMSET_OPTSPEED will select a
|
||||
version of memset() optimized for speed. By default, memset() is
|
||||
optimized for size.
|
||||
* lib/strings/lib_memset.c: CONFIG_MEMSET_64BIT will perform 64-bit
|
||||
aligned memset() operations.
|
||||
* arch/arm/src/stm32/stm32_adc.c: Need to put the ADC back into the
|
||||
initial reset in the open/setup logic. Opening the ADC driver works
|
||||
the first time, but not the second because the device is left in a
|
||||
powered down state on the last close.
|
||||
* configs/olimex-lpc1766stck/scripts: Replace all of the identical
|
||||
ld.script files with the common one in this directory.
|
||||
* configs/stm3220g-eval/scripts: Replace all of the identical
|
||||
ld.script files with the common one in this directory.
|
||||
* configs/hymini-stm32v/scripts: Replace all of the identical
|
||||
ld.script files with the common one in this directory.
|
||||
* configs/lpcxpresso-lpc1768/scripts: Replace all of the identical
|
||||
ld.script files with the common one in this directory.
|
||||
* binfmt/elf.c, binfmt/libelf, include/elf.h, include/nuttx/elf.h: Add
|
||||
basic framework for loadable ELF module support. The initial check-
|
||||
in is non-functional and is simply the framework for ELF support.
|
||||
* include/nuttx/binfmt.h, nxflat.h, elf.h, and symtab.h: Moved to
|
||||
include/nuttx/binfmt/.
|
||||
* arch/sim/src/up_elf.c and arch/x86/src/common/up_elf.c: Add
|
||||
for ELF modules.
|
||||
* arch/arm/include/elf.h: Added ARM ELF header file.
|
||||
* include/elf32.h: Renamed elf.h to elf32.h.
|
||||
* configs/stm32f4discovery/ostest: Converted to use the new
|
||||
Kconfig-based configuration system.
|
||||
* configs/stm32f4discovery/elf and configs/stm32f4discovery/scripts/gnu-elf.ld
|
||||
Add a configuration for testing the ARM ELF loader.
|
||||
* binfmt/libelf: Can't use fstat(). NuttX does not yet support it. Damn!
|
||||
* binfmt/libelf: The basic ELF module execution appears fully functional.
|
||||
* configs/shenzhou/src/up_relays.c: Add support for relays from the
|
||||
Shenzhou board. Contributed by Darcy Gong.
|
||||
* lib/fixedmath: Moved the old lib/math to lib/fixedmath to make room for
|
||||
the math library from the Rhombus OS
|
||||
* lib/math: Now contains the math library from the Rhombus OS by Nick Johnson
|
||||
(submitted by Darcy Gong).
|
||||
* include/float.h: Add a first cut at the float.h header file. This
|
||||
really should be an architecture/toolchain-specific header file. It
|
||||
is only used if CONFIG_ARCH_FLOAT_H is defined.
|
||||
* lib/math: Files now conform to coding standards. Separated float,
|
||||
double, and long double versions of code into separate files so that
|
||||
they don't draw in so much un-necessary code when doing a dumb link.
|
||||
* binfmt/libelf: The ELF loader is working correctly with C++ static
|
||||
constructors and destructors and all.
|
||||
* Documentation/NuttXBinfmt.html: Add documentation of the binary loader.
|
||||
* configs/sim/ostest: Converted to use the mconf configuration tool.
|
||||
* configs/sim/cxxtest: New test that will be used to verify the uClibc++
|
||||
port (eventually).
|
||||
* include/nuttx/fs/fs.h, lib/stdio/lib_libfread.c, lib_ferror.c,
|
||||
lib_feof.c, and lib_clearerr.c: Add support for ferror(), feof(),
|
||||
and clearerror(). ferror() support is bogus at the moment (it
|
||||
is equivalent to !feof()); the others should be good.
|
||||
* configs/stm32f4discovery/include/board.h: Correct timer 2-7
|
||||
base frequency (provided by Freddie Chopin).
|
||||
* include/nuttx/sched.h, sched/atexit.c, and sched/task_deletehook.c:
|
||||
If both atexit() and on_exit() are enabled, then implement atexit()
|
||||
as just a special caseof on_exit(). This assumes that the ABI can
|
||||
handle receipt of more call parameters than the receiving function
|
||||
expects. That is usually the case if parameters are passed in
|
||||
registers.
|
||||
* libxx/libxx_cxa_atexit(): Implements __cxa_atexit()
|
||||
* configs/stm32f4discovery/cxxtest: New test that will be used to
|
||||
verify the uClibc++ port (eventually). The sim platform turned not
|
||||
to be a good platform for testing uClibc++. The sim example will not
|
||||
run because the simulator will attempt to execute the static
|
||||
constructors before main() starts. BUT... NuttX is not initialized
|
||||
and this results in a crash. On the STM324Discovery, I will have
|
||||
better control over when the static constructors run.
|
||||
* RGMP 4.0 updated from Qiany Yu.
|
||||
* configs/*/Make.defs and configs/*/ld.script: Massive clean-up
|
||||
and standardization of linker scripts from Freddie Chopin.
|
||||
* net/netdev_ioctl.c: Add interface state flags and ioctl calls
|
||||
to bring network interfaces up and down (from Darcy Gong).
|
||||
* config/stm32f4discovery: Enable C++ exceptions. Now the entire
|
||||
apps/examples/cxxtest works -- meaning the the uClibc++ is
|
||||
complete and verified for the STM32 platform.
|
||||
|
||||
6.24 2012-12-20 Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
* arch/arm/src/stm32: Support for STM32F100 high density chips
|
||||
added by Freddie Chopin.
|
||||
* configs/stm32f100_generic: Support for generic STM32F100RC board
|
||||
contributed by Freddie Chopin.
|
||||
* arch/arm/src/stm32_otgfsdev.c: Partial fix from Petteri Aimonen.
|
||||
* drivers/lcd/ug-2864ambag01.c and include/nuttx/lcd/ug_2864ambag01.h:
|
||||
LCD driver for the Univision OLED of the same name (untested on
|
||||
initial check-in).
|
||||
* configs/stm32f4discovery/nxlines: Configure to use mconf/Kconfig
|
||||
tool.
|
||||
* configs/stm32f4discovery/src/up_ug2864ambag01.c: Board-specific
|
||||
initialization for UG-2864AMBAG01 OLED connecte to STM32F4Disovery.
|
||||
* libxx/libxx_stdthrow.cxx: Exception stubs from Petteri Aimonen.
|
||||
* configs/stm32f4discovery/src/up_ug2864ambag01.c: Driver has been
|
||||
verified on the STM32F4Discovery platform. Some tuning of the
|
||||
configuration could improve the presentation. Lower resolution displays
|
||||
are also more subject to the "fat, flat line bug" that I need to fix
|
||||
someday. See http://www.nuttx.org/doku.php?id=wiki:graphics:nxgraphics
|
||||
for a description of the fat, flat line bug.
|
||||
* libc: Renamed nuttx/lib to nuttx/libc to make space for a true lib/
|
||||
directory that will be forthcoming. Also rename libraries: liblib.a -> libc.a,
|
||||
libulib.a -> libuc.a, libklib.a -> libkc.a, liblibxx.a ->libcxx.a.
|
||||
(I will probably, eventually rename libxx to libcxx for consistency)
|
||||
* Makefile, lib/: A new, empty directory that will hold generated libraries.
|
||||
This simplifies the library patch calculations and lets me get rid of some
|
||||
bash logic. The change is functional, but only partially complete;
|
||||
additional logic is needed in the arch/*/src/Makefile's as well. Right
|
||||
now that logic generate multiple library paths, all pointing to the lib/
|
||||
directory.
|
||||
* arch/*/src/Makefile: Now uses only the libraries in lib/
|
||||
Replace bash fragments that test for board/Makefile.
|
||||
* Makefile.win: The beginnings of a Windows-native build. This is just
|
||||
the beginning and not yet ready for prime time use.
|
||||
* configs/stm32f4discovery/winbuild: This is a version of the standard
|
||||
NuttX OS test, but configured to build natively on Windows. Its only
|
||||
real purpose is to very the native Windows build logic.
|
||||
* tools/mkdeps.bat and tools/mkdeps.c: mkdeps.bat is a failed attempt
|
||||
to leverage mkdeps.sh to CMD.exe. It fails because the are certain
|
||||
critical CFLAG values that cannot be passed on the CMD.exe command line
|
||||
(like '='). mkdeps.c is a work in progress that will, hopefully,
|
||||
replace both mkdeps.sh and mkdeps.bat.
|
||||
* tools/Config.mk: Centralize the definition of the script that will be
|
||||
used to generated header file include paths for the compiler. This
|
||||
needs to be centralized in order to support the Windows native build.
|
||||
* tools/incdir.bat: A replacement for tools/incdir.sh for use with the
|
||||
the Windows native build.
|
||||
* Makefile.unix: The existing top-level Makefile has been renamed
|
||||
Makefile.unix.
|
||||
* Makefile: This is a new top-level Makefile that just includes
|
||||
either Makefile.unix or Makefile.win
|
||||
* configs/stm3240g-eval/src: Qencoder fixes from Ryan Sundberg.
|
||||
* arch/arm/src/stm32/stm32_qencoder.c: TIM3 bug fix from Ryan Sundberg.
|
||||
* tools/mkromfsimg.sh: Correct typo in an error message (Ryan Sundberg)
|
||||
* arch/*/src/Makefile: Remove tftboot install and creation of System.map
|
||||
for Windows native build. The first is a necessary change, the second
|
||||
just needs re-implemented.
|
||||
* configs/mirtoo: Update Mirtoo pin definitions for Release 2. Provided
|
||||
by Konstantin Dimitrov.
|
||||
* Fixed an uninitialized variable in the file system that can cause
|
||||
assertions if DEBUG on (contributed by Lorenz Meier).
|
||||
* Config.mk: Defined DELIM to be either / or \, depending upon
|
||||
CONFIG_WINDOWS_NATIVE. This will allow me to eliminate a lot of
|
||||
conditional logic elsewhere.
|
||||
* nuttx/graphics: One a mouse button is pressed, continue to report all
|
||||
mouse button events to the first window that received the the initial
|
||||
button down event, even if the mouse attempts to drag outside the
|
||||
window. From Petteri Aimonen.
|
||||
* nuttx/graphics/nxmu/nx_block.c: One more fix to the NX block message
|
||||
logic from Petteri Aimonen.
|
||||
* include/nuttx/wqueue.h: Some basic definitions to support a user-
|
||||
space work queue (someday in the future).
|
||||
* graphics/nxmu: Add semaphores so buffers messages that send buffers
|
||||
will block until the buffer data has been acted upon.
|
||||
* graphics/nxmw: Extended the blocked messages to cover mouse movement
|
||||
and redraw events. These will also cause problems if sent to a window
|
||||
while it is closing.
|
||||
* arch/several: Change UARTs are enabled for i.MX, LM3S, ez80, and M16C to
|
||||
match how they are enabled for other architectures.
|
||||
* configs/ez80f910200kitg: Convert to use mconf configuration.
|
||||
* sched/pause.c: Implements the POSIX pause() function.
|
||||
* ez80: Lots of changes to ez80 configurations and build logic as I
|
||||
struggle to get a clean Windows build (still not working).
|
||||
* configs/cloudctrl: Darcy Gong's CloudController board. This is a
|
||||
small network relay development board. Based on the Shenzhou IV development
|
||||
board design. It is based on the STM32F107VC MCU.
|
||||
* arch/arm/src/stm32_serial.c and stm32_lowputc.c: Added optional RS-485
|
||||
direction bit control. From Freddie Chopin.
|
||||
* Lots of build files: ARMv7-M and MIPS32 Make.defs now include a common
|
||||
Toolchain.defs file that can be used to manage toolchains in a more
|
||||
configurable way. Contributed by Mike Smith
|
||||
* configs/stm32f4discovery/winbuild and configs/cloudctrl: Adapted to use
|
||||
Mike's Toolchain.defs.
|
||||
* tools/configure.sh: Adapted to handle paths and setenv.bat files correctly
|
||||
for native Windows builds.
|
||||
* More of build files: AVR and AVR32 Make.defs now include a common
|
||||
Toolchain.defs file that can be used to manage toolchains in a more
|
||||
configurable way. Contributed by Mike Smith
|
||||
* tools/incdir.sh and incdir.bat: Add -s option to generate system header
|
||||
file paths.
|
||||
* nuttx/arch/arm/src/arm/Toolchain.defs: Add support for more ARM toolchains
|
||||
(from Mike Smith).
|
||||
* arch/arm/src/stm32/stm32f40xxx_rcc.c: Enabled FLASH prefetch (from Petteri
|
||||
Aimonen).
|
||||
* graphics/nxtk/nxtk_filltrapwindow.c: Correct an offset problem (from
|
||||
Peterri Aimonen).
|
||||
* graphics/nxglib/nxglib_splitline.c: Fix error in drawing of near horizontal
|
||||
lines (from Peterri Aimonen).
|
||||
* sched/task_exithook.c: Missing right bracket with certain conditional
|
||||
compilation (thanks James Goppert).
|
||||
* arch/arm/srch/stm32/stm32_otgfshost.c: Replace timeout handling; use
|
||||
system tick instead of frame counter. The frame counter gets reset to
|
||||
zero at 0x3fff making it error prone.
|
||||
* arch/arm/src/stm32/stm32f20xx_rcc.c and stm32f40xx_rcc.c: Added option
|
||||
CONFIG_STM32_FLASH_PREFETCH. FLASH prefetch will now only be enabled
|
||||
if this option is selected.
|
||||
* confgs/ez80f910200zco/ostest: Now uses Kconfig/mconf configuration
|
||||
tool. Updated to build in native Windows environment. Other ez80f910200zco
|
||||
build scripts also updated.
|
||||
* configs/z8f64200100kit/ostest: Update to same level as ez80 configurations.
|
||||
* nuttx/configs/z8f64200100kit/scripts/setenv.bat: Add support for native
|
||||
Windows build.
|
||||
* nuttx/arch/arm/src/lpc17xx/lpc17_i2c.c: Resources not being released when
|
||||
I2C is uninitialized.
|
||||
* cloudctrl/src/up_chipid.c and shenzhou/src/up_chipid.c: Add functions to
|
||||
get chip ID. Contributed by Darcy Gong. These should not be board-dependent,
|
||||
but should be in arch/arm/src/stm32 where they can be used from any board.
|
||||
* sched/work_thread.c: Fix backward conditional compilation. This might
|
||||
has caused a memory leak. From Freddie Chopin.
|
||||
* configs/<many>/Make.defs: Fix typo -wstrict-prototypes should be
|
||||
-Wstrict-prototypes (From Denis Carilki).
|
||||
* arch/arm/src/calapyso/calypso_keypad.c: Add Calypso keypad driver. From
|
||||
Denis Carilki.
|
||||
* z8encore000zco/ostest and z8f64200100kit/ostest: Converted to use Kconfig/
|
||||
mconf configuration tool.
|
||||
* arch/arm/src/armv7-m/up_exception.S: missing curly braces for push/pop
|
||||
From Freddie Chopin.
|
||||
* z8encore000zco/ostest and z8f64200100kit/ostest: Can now be modified to
|
||||
support the Windows native builds (see corresponding README.txt files).
|
||||
* configs/z16f2800100zcog - All configurations updated to use the ZDS-II
|
||||
5.0.1 toolchain.
|
||||
* configs/z16f2800100zcog - All configurations updated to use Kconfig/mconf
|
||||
configuration tools.
|
||||
* configs/z16f2800100zcog/ostest - Now supports a native Windows build
|
||||
(other ZNEO configs may also support the native build, but this has not
|
||||
been verfiied).
|
||||
* include/nuttx/input/keypad.h, arch/arm/src/calypso/calypso_keypad.c, and
|
||||
configs/compal_e99/nsh_highram: First cut at a standard keypad interface
|
||||
definition. Contributed by Denis Carikli.
|
||||
* libc/stdlib/lib_rand.c: Always add one to result congruential generators
|
||||
to avoid the value zero. Suggested by Freddie Chopin.
|
||||
* tools/b16.c: Fixed precision math conversion utility.
|
||||
* graphics/nxglib/nxglib_splitline.c: Fix the "fat, flat line bug"
|
||||
* arch/z80/src/*/Toolchain.defs: Add dummy Toolchain.defs files for the
|
||||
z80 family.
|
||||
* configs/z80sim/ostest: Converted to build with the Kconfig/mconf tool.
|
||||
Current configuration failed to build for me (Ubuntu 12.10, SDCC 3.2.0
|
||||
pre-built for Linux) due to a glibc memory corruptionerror in SDCC.
|
||||
* configs/z80sim/ostest: Default is now the Windows native build. See
|
||||
configs/z80sim/README.txt for instructions to convert back to a Linux or
|
||||
or Cygwin build.
|
||||
* arch/z80/src/Makefile.sdccw: Renamed makefiles with extensions zdiil,
|
||||
zdiiw, sdccl, and sdccw for the ZDS-II vs SDCC compilers and for the
|
||||
POSIX vs Windows native builds.
|
||||
* nuttx/drivers/mtd/ftl.c: Fix for the flash translation layer. Short
|
||||
unaligned writes were buggy. From Petteri Aimonen.
|
||||
* nuttx/libc/math/lib_round*.c: Add rounding functions to the math
|
||||
library. Contributed by Petteri Aimonen.
|
||||
* include/cxx/cstdlib: Add stroul(). From Petteri Aimonen.
|
||||
* arch/*/include/limits.h: Change signed minimum values from, for example,
|
||||
(-128) to (-127 - 1) to avoid overflows under certain conditions. From
|
||||
Peterri Aimonen.
|
||||
* graphics/nxtk/nxtk_subwindowmove.c: Previously it was very difficult to
|
||||
do e.g. "scroll by dx, dy". When given the full window area, nxtk_subwindowmove
|
||||
would clip the offset always to 0,0. It makes more sense for it to clip the
|
||||
source area and not modify the offset. From Petteri Aimonen.
|
||||
* graphics/nxtk/nxtk_getwindow.c: Clipping would change the offset of returned
|
||||
data, and caller has no way to know what the new offset would be. This messes
|
||||
up font drawing when the text is partially out of window, e.g. when scrolling.
|
||||
Also from Petteri Aimonen.
|
||||
* include/stdbool.h: Can now be disabled for C++ files if CONFIG_C99_BOOL8 is
|
||||
defined. CONFIG_C99_BOOL8 indicates (1) that the sizeof(_Bool) is one in both
|
||||
C and C++, and (2) the the C compiler is C99 and supports the _Bool intrinsic
|
||||
type. Requested by Freddie Chopin.
|
||||
* include/stdlib/lib_rand.c: Various additional changes so that the integer
|
||||
value zero can be returned. Requested by Freddie Chopin.
|
||||
* arch/z80/src/Makefile.sdcc*, z80/up_mem.h: Redesign Z80 build so that it
|
||||
no longer depends on Bash scripts.
|
||||
* configs/z80sim/nsh and pashello: Converted to (1) use the kconfig-frontends
|
||||
configuration tool, and (2) to build natively under Windows. The NSH
|
||||
configuration is verified; the pashello configuration needs a more TLC.
|
||||
* tools/copydir.sh: Rename tools/winlink.sh to tools/copydir.sh
|
||||
* tools/link.bat, unlink.bat, and copydir.bat: Add Windows counterparts
|
||||
to the link.sh, unlink.sh, and copydir.sh Bash scripts.
|
||||
* configs/z80sim/pashello: Now builds correctly.
|
||||
* configs/xtrs/ostest, nsh, and pashello: Converted to (1) use the kconfig-
|
||||
frontends configuration tool, and (2) to build natively under Windows.
|
||||
* drivers/serial/Kconfig and sched/Kconfig: Two names for same configuration:
|
||||
CONFIG_LOWLEVEL_CONSOLE is bogus and CONFIG_DEV_LOWCONSOLE is in the wrong
|
||||
Kconfig file. Moved to drivers/serial/Kconfig replacing CONFIG_LOWLEVEL_CONSOLE.
|
||||
* arch/z80/include/z180: Add header files for z180 chips. Initial versions
|
||||
are just clones of z80 header files.
|
||||
* arch/z80/src/z180: Add source files for z180 chips. Initial versions
|
||||
are just clones of z80 source files.
|
||||
* include/nuttx/arch.h: Add address environment control interfaces (for use
|
||||
with CPUs the provide MCUs and support process-like address environments).
|
||||
* arch/z80/src/z180/z180_mmu.*: Add MMU support for z180 tasks.
|
||||
* configs/p112: Add very basic board support and an examples/ostest
|
||||
configuration for the venerable P112 board.
|
||||
* sched/os_bringup.c: If CONFIG_PATH_INITIAL is defined, then the initial
|
||||
environment of the task started by os_bringup() will have the PATH
|
||||
environment variable defined to be that string.
|
||||
* binfmt/binfmt_exepath.c: If CONFIG_BINFMT_EXEPATH is defined, then this
|
||||
file will be built. It contains logic to search for regular files at
|
||||
the absolutes paths found in the current PATH environment variable
|
||||
setting. This is untested and not yet hooked into the binfmt exec()
|
||||
logic on initial check-in
|
||||
* binfmt/binfmt_loadmodule.c: load_module() will now traverse the PATH
|
||||
variable to locate files from their relative path.
|
||||
* include/nuttx/arch.h and arch/z80/src/z180/z180_mmu.c: Restructure the
|
||||
address environment interfaces so that they will better integrate with
|
||||
binfmt/.
|
||||
* binfmt/libelf/*, binfmt/libnxflat/* and other files: Integrate the
|
||||
address environment interfaces. If CONFIG_ADDRENV=y, then binfmt/
|
||||
will now create an address environment for new tasks (instead of
|
||||
just malloc'ing the task memory).
|
||||
* configs/stm32f4discovery/elf: Enable support/test of the PATH
|
||||
to find executables using a relative path.
|
||||
|
||||
6.25 2013-xx-xx Gregory Nutt <gnutt@nuttx.org>
|
||||
|
||||
@@ -0,0 +1,749 @@
|
||||
############################################################################
|
||||
# Makefile.unix
|
||||
#
|
||||
# Copyright (C) 2007-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
TOPDIR := ${shell pwd | sed -e 's/ /\\ /g'}
|
||||
-include $(TOPDIR)/.config
|
||||
include $(TOPDIR)/tools/Config.mk
|
||||
-include $(TOPDIR)/Make.defs
|
||||
|
||||
# Control build verbosity
|
||||
|
||||
ifeq ($(V),1)
|
||||
export Q :=
|
||||
else
|
||||
export Q := @
|
||||
endif
|
||||
|
||||
# Default tools
|
||||
|
||||
ifeq ($(DIRLINK),)
|
||||
DIRLINK = $(TOPDIR)/tools/link.sh
|
||||
DIRUNLINK = $(TOPDIR)/tools/unlink.sh
|
||||
endif
|
||||
|
||||
# This define is passed as EXTRADEFINES for kernel-mode builds. It is also passed
|
||||
# during PASS1 (but not PASS2) context and depend targets.
|
||||
|
||||
KDEFINE = ${shell $(TOPDIR)/tools/define.sh "$(CC)" __KERNEL__}
|
||||
|
||||
# Process architecture and board-specific directories
|
||||
|
||||
ARCH_DIR = arch/$(CONFIG_ARCH)
|
||||
ARCH_SRC = $(ARCH_DIR)/src
|
||||
ARCH_INC = $(ARCH_DIR)/include
|
||||
BOARD_DIR = configs/$(CONFIG_ARCH_BOARD)
|
||||
|
||||
# Add-on directories. These may or may not be in place in the
|
||||
# NuttX source tree (they must be specifically installed)
|
||||
#
|
||||
# CONFIG_APPS_DIR can be over-ridden from the command line or in the .config file.
|
||||
# The default value of CONFIG_APPS_DIR is ../apps. Ultimately, the application
|
||||
# will be built if APPDIR is defined. APPDIR will be defined if a directory containing
|
||||
# a Makefile is found at the path provided by CONFIG_APPS_DIR
|
||||
|
||||
ifeq ($(CONFIG_APPS_DIR),)
|
||||
CONFIG_APPS_DIR = ../apps
|
||||
endif
|
||||
APPDIR := ${shell if [ -r $(CONFIG_APPS_DIR)/Makefile ]; then echo "$(CONFIG_APPS_DIR)"; fi}
|
||||
|
||||
# All add-on directories.
|
||||
#
|
||||
# NUTTX_ADDONS is the list of directories built into the NuttX kernel.
|
||||
# USER_ADDONS is the list of directories that will be built into the user application
|
||||
|
||||
NUTTX_ADDONS :=
|
||||
USER_ADDONS :=
|
||||
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
USER_ADDONS += $(APPDIR)
|
||||
else
|
||||
NUTTX_ADDONS += $(APPDIR)
|
||||
endif
|
||||
|
||||
# Lists of build directories.
|
||||
#
|
||||
# FSDIRS depend on file descriptor support; NONFSDIRS do not (except for parts
|
||||
# of FSDIRS). We will exclude FSDIRS from the build if file descriptor
|
||||
# support is disabled
|
||||
# CONTEXTDIRS include directories that have special, one-time pre-build
|
||||
# requirements. Normally this includes things like auto-generation of
|
||||
# configuration specific files or creation of configurable symbolic links
|
||||
# USERDIRS - When NuttX is build is a monolithic kernel, this provides the
|
||||
# list of directories that must be built
|
||||
# OTHERDIRS - These are directories that are not built but probably should
|
||||
# be cleaned to prevent garbarge from collecting in them when changing
|
||||
# configurations.
|
||||
|
||||
NONFSDIRS = sched $(ARCH_SRC) $(NUTTX_ADDONS)
|
||||
FSDIRS = fs drivers binfmt
|
||||
CONTEXTDIRS = $(APPDIR)
|
||||
USERDIRS =
|
||||
OTHERDIRS = lib
|
||||
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
|
||||
NONFSDIRS += syscall
|
||||
CONTEXTDIRS += syscall
|
||||
USERDIRS += syscall libc mm $(USER_ADDONS)
|
||||
ifeq ($(CONFIG_HAVE_CXX),y)
|
||||
USERDIRS += libxx
|
||||
endif
|
||||
|
||||
else
|
||||
|
||||
NONFSDIRS += libc mm
|
||||
OTHERDIRS += syscall $(USER_ADDONS)
|
||||
ifeq ($(CONFIG_HAVE_CXX),y)
|
||||
NONFSDIRS += libxx
|
||||
else
|
||||
OTHERDIRS += libxx
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NX),y)
|
||||
NONFSDIRS += graphics
|
||||
CONTEXTDIRS += graphics
|
||||
else
|
||||
OTHERDIRS += graphics
|
||||
endif
|
||||
|
||||
# CLEANDIRS are the directories that will clean in. These are
|
||||
# all directories that we know about.
|
||||
# KERNDEPDIRS are the directories in which we will build target dependencies.
|
||||
# If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL),
|
||||
# then this holds only the directories containing kernel files.
|
||||
# USERDEPDIRS. If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL),
|
||||
# then this holds only the directories containing user files.
|
||||
|
||||
CLEANDIRS = $(NONFSDIRS) $(FSDIRS) $(USERDIRS) $(OTHERDIRS)
|
||||
KERNDEPDIRS = $(NONFSDIRS)
|
||||
USERDEPDIRS = $(USERDIRS)
|
||||
|
||||
# Add file system directories to KERNDEPDIRS (they are already in CLEANDIRS)
|
||||
|
||||
ifeq ($(CONFIG_NFILE_DESCRIPTORS),0)
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
|
||||
KERNDEPDIRS += fs
|
||||
endif
|
||||
KERNDEPDIRS += drivers
|
||||
endif
|
||||
else
|
||||
KERNDEPDIRS += $(FSDIRS)
|
||||
endif
|
||||
|
||||
# Add networking directories to KERNDEPDIRS and CLEANDIRS
|
||||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
KERNDEPDIRS += net
|
||||
endif
|
||||
CLEANDIRS += net
|
||||
|
||||
#
|
||||
# Extra objects used in the final link.
|
||||
#
|
||||
# Pass 1 1ncremental (relative) link objects should be put into the
|
||||
# processor-specific source directory (where other link objects will
|
||||
# be created). If the pass1 obect is an archive, it could go anywhere.
|
||||
|
||||
ifeq ($(CONFIG_BUILD_2PASS),y)
|
||||
EXTRA_OBJS += $(CONFIG_PASS1_OBJECT)
|
||||
endif
|
||||
|
||||
# NUTTXLIBS is the list of NuttX libraries that is passed to the
|
||||
# processor-specific Makefile to build the final NuttX target.
|
||||
# Libraries in FSDIRS are excluded if file descriptor support
|
||||
# is disabled.
|
||||
# USERLIBS is the list of libraries used to build the final user-space
|
||||
# application
|
||||
|
||||
NUTTXLIBS = lib/libsched$(LIBEXT) lib/libarch$(LIBEXT)
|
||||
USERLIBS =
|
||||
|
||||
# Add libraries for syscall support. The C library will be needed by
|
||||
# both the kernel- and user-space builds. For now, the memory manager (mm)
|
||||
# is placed in user space (only).
|
||||
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
NUTTXLIBS += lib/libstubs$(LIBEXT) lib/libkc$(LIBEXT)
|
||||
USERLIBS += lib/libproxies$(LIBEXT) lib/libuc$(LIBEXT) lib/libmm$(LIBEXT)
|
||||
else
|
||||
NUTTXLIBS += lib/libmm$(LIBEXT) lib/libc$(LIBEXT)
|
||||
endif
|
||||
|
||||
# Add libraries for C++ support. CXX, CXXFLAGS, and COMPILEXX must
|
||||
# be defined in Make.defs for this to work!
|
||||
|
||||
ifeq ($(CONFIG_HAVE_CXX),y)
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
USERLIBS += lib/libcxx$(LIBEXT)
|
||||
else
|
||||
NUTTXLIBS += lib/libcxx$(LIBEXT)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Add library for application support.
|
||||
|
||||
ifneq ($(APPDIR),)
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
USERLIBS += lib/libapps$(LIBEXT)
|
||||
else
|
||||
NUTTXLIBS += lib/libapps$(LIBEXT)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Add libraries for network support
|
||||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
NUTTXLIBS += lib/libnet$(LIBEXT)
|
||||
endif
|
||||
|
||||
# Add libraries for file system support
|
||||
|
||||
ifeq ($(CONFIG_NFILE_DESCRIPTORS),0)
|
||||
ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
|
||||
NUTTXLIBS += lib/libfs$(LIBEXT)
|
||||
endif
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
NUTTXLIBS += lib/libdrivers$(LIBEXT)
|
||||
endif
|
||||
else
|
||||
NUTTXLIBS += lib/libfs$(LIBEXT) lib/libdrivers$(LIBEXT) lib/libbinfmt$(LIBEXT)
|
||||
endif
|
||||
|
||||
# Add libraries for the NX graphics sub-system
|
||||
|
||||
ifeq ($(CONFIG_NX),y)
|
||||
NUTTXLIBS += lib/libgraphics$(LIBEXT)
|
||||
endif
|
||||
|
||||
# LINKLIBS derives from NUTTXLIBS and is simply the same list with the subdirectory removed
|
||||
|
||||
LINKLIBS = $(patsubst lib/%,%,$(NUTTXLIBS))
|
||||
|
||||
# This is the name of the final target (relative to the top level directorty)
|
||||
|
||||
BIN = nuttx$(EXEEXT)
|
||||
|
||||
all: $(BIN)
|
||||
.PHONY: context clean_context check_context export subdir_clean clean subdir_distclean distclean apps_clean apps_distclean
|
||||
|
||||
# Target used to copy include/nuttx/math.h. If CONFIG_ARCH_MATH_H is
|
||||
# defined, then there is an architecture specific math.h header file
|
||||
# that will be included indirectly from include/math.h. But first, we
|
||||
# have to copy math.h from include/nuttx/. to include/. Logic within
|
||||
# include/nuttx/math.h will hand the redirection to the architecture-
|
||||
# specific math.h header file.
|
||||
#
|
||||
# If the CONFIG_LIBM is defined, the Rhombus libm will be built at libc/math.
|
||||
# Definitions and prototypes for the Rhombus libm are also contained in
|
||||
# include/nuttx/math.h and so the file must also be copied in that case.
|
||||
#
|
||||
# If neither CONFIG_ARCH_MATH_H nor CONFIG_LIBM is defined, then no math.h
|
||||
# header file will be provided. You would want that behavior if (1) you
|
||||
# don't use libm, or (2) you want to use the math.h and libm provided
|
||||
# within your toolchain.
|
||||
|
||||
ifeq ($(CONFIG_ARCH_MATH_H),y)
|
||||
NEED_MATH_H = y
|
||||
else
|
||||
ifeq ($(CONFIG_LIBM),y)
|
||||
NEED_MATH_H = y
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(NEED_MATH_H),y)
|
||||
include/math.h: include/nuttx/math.h
|
||||
$(Q) cp -f include/nuttx/math.h include/math.h
|
||||
else
|
||||
include/math.h:
|
||||
endif
|
||||
|
||||
# The float.h header file defines the properties of your floating point
|
||||
# implementation. It would always be best to use your toolchain's float.h
|
||||
# header file but if none is avaiable, a default float.h header file will
|
||||
# provided if this option is selected. However there is no assurance that
|
||||
# the settings in this float.h are actually correct for your platform!
|
||||
|
||||
ifeq ($(CONFIG_ARCH_FLOAT_H),y)
|
||||
include/float.h: include/nuttx/float.h
|
||||
$(Q) cp -f include/nuttx/float.h include/float.h
|
||||
else
|
||||
include/float.h:
|
||||
endif
|
||||
|
||||
# Target used to copy include/nuttx/stdarg.h. If CONFIG_ARCH_STDARG_H is
|
||||
# defined, then there is an architecture specific stdarg.h header file
|
||||
# that will be included indirectly from include/stdarg.h. But first, we
|
||||
# have to copy stdarg.h from include/nuttx/. to include/.
|
||||
|
||||
ifeq ($(CONFIG_ARCH_STDARG_H),y)
|
||||
include/stdarg.h: include/nuttx/stdarg.h
|
||||
$(Q) cp -f include/nuttx/stdarg.h include/stdarg.h
|
||||
else
|
||||
include/stdarg.h:
|
||||
endif
|
||||
|
||||
# Targets used to build include/nuttx/version.h. Creation of version.h is
|
||||
# part of the overall NuttX configuration sequence. Notice that the
|
||||
# tools/mkversion tool is built and used to create include/nuttx/version.h
|
||||
|
||||
tools/mkversion$(HOSTEXEEXT):
|
||||
$(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkversion$(HOSTEXEEXT)
|
||||
|
||||
$(TOPDIR)/.version:
|
||||
$(Q) if [ ! -f .version ]; then \
|
||||
echo "No .version file found, creating one"; \
|
||||
tools/version.sh -v 0.0 -b 0 .version; \
|
||||
chmod 755 .version; \
|
||||
fi
|
||||
|
||||
include/nuttx/version.h: $(TOPDIR)/.version tools/mkversion$(HOSTEXEEXT)
|
||||
$(Q) tools/mkversion $(TOPDIR) > include/nuttx/version.h
|
||||
|
||||
# Targets used to build include/nuttx/config.h. Creation of config.h is
|
||||
# part of the overall NuttX configuration sequence. Notice that the
|
||||
# tools/mkconfig tool is built and used to create include/nuttx/config.h
|
||||
|
||||
tools/mkconfig$(HOSTEXEEXT):
|
||||
$(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkconfig$(HOSTEXEEXT)
|
||||
|
||||
include/nuttx/config.h: $(TOPDIR)/.config tools/mkconfig$(HOSTEXEEXT)
|
||||
$(Q) tools/mkconfig $(TOPDIR) > include/nuttx/config.h
|
||||
|
||||
# Targets used to create dependencies
|
||||
|
||||
tools/mkdeps$(HOSTEXEEXT):
|
||||
$(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkdeps$(HOSTEXEEXT)
|
||||
|
||||
# dirlinks, and helpers
|
||||
#
|
||||
# Directories links. Most of establishing the NuttX configuration involves
|
||||
# setting up symbolic links with 'generic' directory names to specific,
|
||||
# configured directories.
|
||||
#
|
||||
# Link the apps/include directory to include/apps
|
||||
|
||||
include/apps: Make.defs
|
||||
ifneq ($(APPDIR),)
|
||||
@echo "LN: include/apps to $(APPDIR)/include"
|
||||
$(Q) if [ -d $(TOPDIR)/$(APPDIR)/include ]; then \
|
||||
$(DIRLINK) $(TOPDIR)/$(APPDIR)/include include/apps; \
|
||||
fi
|
||||
endif
|
||||
|
||||
# Link the arch/<arch-name>/include directory to include/arch
|
||||
|
||||
include/arch: Make.defs
|
||||
@echo "LN: include/arch to $(ARCH_DIR)/include"
|
||||
$(Q) $(DIRLINK) $(TOPDIR)/$(ARCH_DIR)/include include/arch
|
||||
|
||||
# Link the configs/<board-name>/include directory to include/arch/board
|
||||
|
||||
include/arch/board: include/arch Make.defs include/arch
|
||||
@echo "LN: include/arch/board to $(BOARD_DIR)/include"
|
||||
$(Q) $(DIRLINK) $(TOPDIR)/$(BOARD_DIR)/include include/arch/board
|
||||
|
||||
# Link the configs/<board-name>/src dir to arch/<arch-name>/src/board
|
||||
|
||||
$(ARCH_SRC)/board: Make.defs
|
||||
@echo "LN: $(ARCH_SRC)/board to $(BOARD_DIR)/src"
|
||||
$(Q) $(DIRLINK) $(TOPDIR)/$(BOARD_DIR)/src $(ARCH_SRC)/board
|
||||
|
||||
# Link arch/<arch-name>/include/<chip-name> to arch/<arch-name>/include/chip
|
||||
|
||||
$(ARCH_SRC)/chip: Make.defs
|
||||
ifneq ($(CONFIG_ARCH_CHIP),)
|
||||
@echo "LN: $(ARCH_SRC)/chip to $(ARCH_SRC)/$(CONFIG_ARCH_CHIP)"
|
||||
$(Q) $(DIRLINK) $(TOPDIR)/$(ARCH_SRC)/$(CONFIG_ARCH_CHIP) $(ARCH_SRC)/chip
|
||||
endif
|
||||
|
||||
# Link arch/<arch-name>/src/<chip-name> to arch/<arch-name>/src/chip
|
||||
|
||||
include/arch/chip: include/arch Make.defs
|
||||
ifneq ($(CONFIG_ARCH_CHIP),)
|
||||
@echo "LN: include/arch/chip to $(ARCH_INC)/$(CONFIG_ARCH_CHIP)"
|
||||
$(Q) $(DIRLINK) $(TOPDIR)/$(ARCH_INC)/$(CONFIG_ARCH_CHIP) include/arch/chip
|
||||
endif
|
||||
|
||||
dirlinks: include/arch include/arch/board include/arch/chip $(ARCH_SRC)/board $(ARCH_SRC)/chip include/apps
|
||||
|
||||
# context
|
||||
#
|
||||
# The context target is invoked on each target build to assure that NuttX is
|
||||
# properly configured. The basic configuration steps include creation of the
|
||||
# the config.h and version.h header files in the include/nuttx directory and
|
||||
# the establishment of symbolic links to configured directories.
|
||||
|
||||
context: check_context include/nuttx/config.h include/nuttx/version.h include/math.h include/float.h include/stdarg.h dirlinks
|
||||
$(Q) for dir in $(CONTEXTDIRS) ; do \
|
||||
$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" context; \
|
||||
done
|
||||
|
||||
# clean_context
|
||||
#
|
||||
# This is part of the distclean target. It removes all of the header files
|
||||
# and symbolic links created by the context target.
|
||||
|
||||
clean_context:
|
||||
$(call DELFILE, include/nuttx/config.h)
|
||||
$(call DELFILE, include/nuttx/version.h)
|
||||
$(call DELFILE, include/math.h)
|
||||
$(call DELFILE, include/stdarg.h)
|
||||
$(Q) $(DIRUNLINK) include/arch/board
|
||||
$(Q) $(DIRUNLINK) include/arch/chip
|
||||
$(Q) $(DIRUNLINK) include/arch
|
||||
$(Q) $(DIRUNLINK) $(ARCH_SRC)/board
|
||||
$(Q) $(DIRUNLINK) $(ARCH_SRC)/chip
|
||||
$(Q) $(DIRUNLINK) include/apps
|
||||
|
||||
# check_context
|
||||
#
|
||||
# This target checks if NuttX has been configured. NuttX is configured using
|
||||
# the script tools/configure.sh. That script will install certain files in
|
||||
# the top-level NuttX build directory. This target verifies that those
|
||||
# configuration files have been installed and that NuttX is ready to be built.
|
||||
|
||||
check_context:
|
||||
$(Q) if [ ! -e ${TOPDIR}/.config -o ! -e ${TOPDIR}/Make.defs ]; then \
|
||||
echo "" ; echo "Nuttx has not been configured:" ; \
|
||||
echo " cd tools; ./configure.sh <target>" ; echo "" ; \
|
||||
exit 1 ; \
|
||||
fi
|
||||
|
||||
# Archive targets. The target build sequency will first create a series of
|
||||
# libraries, one per configured source file directory. The final NuttX
|
||||
# execution will then be built from those libraries. The following targets
|
||||
# build those libraries.
|
||||
#
|
||||
# Possible kernel-mode builds
|
||||
|
||||
libc/libkc$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libkc$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib/libkc$(LIBEXT): libc/libkc$(LIBEXT)
|
||||
$(Q) install libc/libkc$(LIBEXT) lib/libkc$(LIBEXT)
|
||||
|
||||
sched/libsched$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C sched TOPDIR="$(TOPDIR)" libsched$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib/libsched$(LIBEXT): sched/libsched$(LIBEXT)
|
||||
$(Q) install sched/libsched$(LIBEXT) lib/libsched$(LIBEXT)
|
||||
|
||||
$(ARCH_SRC)/libarch$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" libarch$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib/libarch$(LIBEXT): $(ARCH_SRC)/libarch$(LIBEXT)
|
||||
$(Q) install $(ARCH_SRC)/libarch$(LIBEXT) lib/libarch$(LIBEXT)
|
||||
|
||||
net/libnet$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C net TOPDIR="$(TOPDIR)" libnet$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib/libnet$(LIBEXT): net/libnet$(LIBEXT)
|
||||
$(Q) install net/libnet$(LIBEXT) lib/libnet$(LIBEXT)
|
||||
|
||||
fs/libfs$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C fs TOPDIR="$(TOPDIR)" libfs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib/libfs$(LIBEXT): fs/libfs$(LIBEXT)
|
||||
$(Q) install fs/libfs$(LIBEXT) lib/libfs$(LIBEXT)
|
||||
|
||||
drivers/libdrivers$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C drivers TOPDIR="$(TOPDIR)" libdrivers$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib/libdrivers$(LIBEXT): drivers/libdrivers$(LIBEXT)
|
||||
$(Q) install drivers/libdrivers$(LIBEXT) lib/libdrivers$(LIBEXT)
|
||||
|
||||
binfmt/libbinfmt$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C binfmt TOPDIR="$(TOPDIR)" libbinfmt$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib/libbinfmt$(LIBEXT): binfmt/libbinfmt$(LIBEXT)
|
||||
$(Q) install binfmt/libbinfmt$(LIBEXT) lib/libbinfmt$(LIBEXT)
|
||||
|
||||
graphics/libgraphics$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C graphics TOPDIR="$(TOPDIR)" libgraphics$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib/libgraphics$(LIBEXT): graphics/libgraphics$(LIBEXT)
|
||||
$(Q) install graphics/libgraphics$(LIBEXT) lib/libgraphics$(LIBEXT)
|
||||
|
||||
syscall/libstubs$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C syscall TOPDIR="$(TOPDIR)" libstubs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib/libstubs$(LIBEXT): syscall/libstubs$(LIBEXT)
|
||||
$(Q) install syscall/libstubs$(LIBEXT) lib/libstubs$(LIBEXT)
|
||||
|
||||
# Possible user-mode builds
|
||||
|
||||
libc/libuc$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libuc$(LIBEXT)
|
||||
|
||||
lib/libuc$(LIBEXT): libc/libuc$(LIBEXT)
|
||||
$(Q) install libc/libuc$(LIBEXT) lib/libuc$(LIBEXT)
|
||||
|
||||
libxx/libcxx$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C libxx TOPDIR="$(TOPDIR)" libcxx$(LIBEXT)
|
||||
|
||||
lib/libcxx$(LIBEXT): libxx/libcxx$(LIBEXT)
|
||||
$(Q) install libxx/libcxx$(LIBEXT) lib/libcxx$(LIBEXT)
|
||||
|
||||
mm/libmm$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib/libmm$(LIBEXT): mm/libmm$(LIBEXT)
|
||||
$(Q) install mm/libmm$(LIBEXT) lib/libmm$(LIBEXT)
|
||||
|
||||
$(APPDIR)/libapps$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C $(APPDIR) TOPDIR="$(TOPDIR)" libapps$(LIBEXT)
|
||||
|
||||
lib/libapps$(LIBEXT): $(APPDIR)/libapps$(LIBEXT)
|
||||
$(Q) install $(APPDIR)/libapps$(LIBEXT) lib/libapps$(LIBEXT)
|
||||
|
||||
syscall/libproxies$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C syscall TOPDIR="$(TOPDIR)" libproxies$(LIBEXT)
|
||||
|
||||
lib/libproxies$(LIBEXT): syscall/libproxies$(LIBEXT)
|
||||
$(Q) install syscall/libproxies$(LIBEXT) lib/libproxies$(LIBEXT)
|
||||
|
||||
# Possible non-kernel builds
|
||||
|
||||
libc/libc$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libc$(LIBEXT)
|
||||
|
||||
lib/libc$(LIBEXT): libc/libc$(LIBEXT)
|
||||
$(Q) install libc/libc$(LIBEXT) lib/libc$(LIBEXT)
|
||||
|
||||
# pass1 and pass2
|
||||
#
|
||||
# If the 2 pass build option is selected, then this pass1 target is
|
||||
# configured to built before the pass2 target. This pass1 target may, as an
|
||||
# example, build an extra link object (CONFIG_PASS1_OBJECT) which may be an
|
||||
# incremental (relative) link object, but could be a static library (archive);
|
||||
# some modification to this Makefile would be required if CONFIG_PASS1_OBJECT
|
||||
# is an archive. Exactly what is performed during pass1 or what it generates
|
||||
# is unknown to this makefule unless CONFIG_PASS1_OBJECT is defined.
|
||||
|
||||
pass1deps: pass1dep $(USERLIBS)
|
||||
|
||||
pass1: pass1deps
|
||||
ifeq ($(CONFIG_BUILD_2PASS),y)
|
||||
$(Q) if [ -z "$(CONFIG_PASS1_BUILDIR)" ]; then \
|
||||
echo "ERROR: CONFIG_PASS1_BUILDIR not defined"; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(Q) if [ ! -d "$(CONFIG_PASS1_BUILDIR)" ]; then \
|
||||
echo "ERROR: CONFIG_PASS1_BUILDIR does not exist"; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(Q) if [ ! -f "$(CONFIG_PASS1_BUILDIR)/Makefile" ]; then \
|
||||
echo "ERROR: No Makefile in CONFIG_PASS1_BUILDIR"; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" LINKLIBS="$(LINKLIBS)" USERLIBS="$(USERLIBS)" "$(CONFIG_PASS1_TARGET)"
|
||||
endif
|
||||
|
||||
pass2deps: pass2dep $(NUTTXLIBS)
|
||||
|
||||
pass2: pass2deps
|
||||
$(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" EXTRA_OBJS="$(EXTRA_OBJS)" LINKLIBS="$(LINKLIBS)" EXTRADEFINES=$(KDEFINE) $(BIN)
|
||||
$(Q) if [ -w /tftpboot ] ; then \
|
||||
cp -f $(BIN) /tftpboot/$(BIN).${CONFIG_ARCH}; \
|
||||
fi
|
||||
ifeq ($(CONFIG_RRLOAD_BINARY),y)
|
||||
@echo "MK: $(BIN).rr"
|
||||
$(Q) $(TOPDIR)/tools/mkimage.sh --Prefix $(CROSSDEV) $(BIN) $(BIN).rr
|
||||
$(Q) if [ -w /tftpboot ] ; then \
|
||||
cp -f $(BIN).rr /tftpboot/$\(BIN).rr.$(CONFIG_ARCH); \
|
||||
fi
|
||||
endif
|
||||
ifeq ($(CONFIG_INTELHEX_BINARY),y)
|
||||
@echo "CP: $(BIN).hex"
|
||||
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex $(BIN) $(BIN).hex
|
||||
endif
|
||||
ifeq ($(CONFIG_MOTOROLA_SREC),y)
|
||||
@echo "CP: $(BIN).srec"
|
||||
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O srec $(BIN) $(BIN).srec
|
||||
endif
|
||||
ifeq ($(CONFIG_RAW_BINARY),y)
|
||||
@echo "CP: $(BIN).bin"
|
||||
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin
|
||||
endif
|
||||
|
||||
# $(BIN)
|
||||
#
|
||||
# Create the final NuttX executable in a two pass build process. In the
|
||||
# normal case, all pass1 and pass2 dependencies are created then pass1
|
||||
# and pass2 targets are built. However, in some cases, you may need to build
|
||||
# pass1 depenencies and pass1 first, then build pass2 dependencies and pass2.
|
||||
# in that case, execute 'make pass1 pass2' from the command line.
|
||||
|
||||
$(BIN): pass1deps pass2deps pass1 pass2
|
||||
|
||||
# download
|
||||
#
|
||||
# This is a helper target that will rebuild NuttX and download it to the target
|
||||
# system in one step. The operation of this target depends completely upon
|
||||
# implementation of the DOWNLOAD command in the user Make.defs file. It will
|
||||
# generate an error an error if the DOWNLOAD command is not defined.
|
||||
|
||||
download: $(BIN)
|
||||
$(call DOWNLOAD, $<)
|
||||
|
||||
# pass1dep: Create pass1 build dependencies
|
||||
# pass2dep: Create pass2 build dependencies
|
||||
|
||||
pass1dep: context tools/mkdeps$(HOSTEXEEXT)
|
||||
$(Q) for dir in $(USERDEPDIRS) ; do \
|
||||
$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" depend ; \
|
||||
done
|
||||
|
||||
pass2dep: context tools/mkdeps$(HOSTEXEEXT)
|
||||
$(Q) for dir in $(KERNDEPDIRS) ; do \
|
||||
$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" EXTRADEFINES=$(KDEFINE) depend; \
|
||||
done
|
||||
|
||||
# Configuration targets
|
||||
#
|
||||
# These targets depend on the kconfig-frontends packages. To use these, you
|
||||
# must first download and install the kconfig-frontends package from this
|
||||
# location: http://ymorin.is-a-geek.org/projects/kconfig-frontends. See
|
||||
# misc/tools/README.txt for additional information.
|
||||
|
||||
config:
|
||||
$(Q) APPSDIR=${CONFIG_APPS_DIR} conf Kconfig
|
||||
|
||||
oldconfig:
|
||||
$(Q) APPSDIR=${CONFIG_APPS_DIR} conf --oldconfig Kconfig
|
||||
|
||||
menuconfig:
|
||||
$(Q) APPSDIR=${CONFIG_APPS_DIR} mconf Kconfig
|
||||
|
||||
# export
|
||||
#
|
||||
# The export target will package the NuttX libraries and header files into
|
||||
# an exportable package. Caveats: (1) These needs some extension for the KERNEL
|
||||
# build; it needs to receive USERLIBS and create a libuser.a). (2) The logic
|
||||
# in tools/mkexport.sh only supports GCC and, for example, explicitly assumes
|
||||
# that the archiver is 'ar'
|
||||
|
||||
export: pass2deps
|
||||
$(Q) tools/mkexport.sh -w$(WINTOOL) -t "$(TOPDIR)" -l "$(NUTTXLIBS)"
|
||||
|
||||
# General housekeeping targets: dependencies, cleaning, etc.
|
||||
#
|
||||
# depend: Create both PASS1 and PASS2 dependencies
|
||||
# clean: Removes derived object files, archives, executables, and
|
||||
# temporary files, but retains the configuration and context
|
||||
# files and directories.
|
||||
# distclean: Does 'clean' then also removes all configuration and context
|
||||
# files. This essentially restores the directory structure
|
||||
# to its original, unconfigured stated.
|
||||
|
||||
depend: pass1dep pass2dep
|
||||
|
||||
subdir_clean:
|
||||
$(Q) for dir in $(CLEANDIRS) ; do \
|
||||
if [ -e $$dir/Makefile ]; then \
|
||||
$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" clean ; \
|
||||
fi \
|
||||
done
|
||||
$(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" clean
|
||||
$(Q) $(MAKE) -C mm -f Makefile.test TOPDIR="$(TOPDIR)" clean
|
||||
ifeq ($(CONFIG_BUILD_2PASS),y)
|
||||
$(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" clean
|
||||
endif
|
||||
|
||||
clean: subdir_clean
|
||||
$(call DELFILE, $(BIN))
|
||||
$(call DELFILE, nuttx.*)
|
||||
$(call DELFILE, mm_test)
|
||||
$(call DELFILE, *.map)
|
||||
$(call DELFILE, _SAVED_APPS_config)
|
||||
$(call DELFILE, nuttx-export*)
|
||||
$(call CLEAN)
|
||||
|
||||
subdir_distclean:
|
||||
$(Q) for dir in $(CLEANDIRS) ; do \
|
||||
if [ -e $$dir/Makefile ]; then \
|
||||
$(MAKE) -C $$dir TOPDIR="$(TOPDIR)" distclean ; \
|
||||
fi \
|
||||
done
|
||||
|
||||
distclean: clean subdir_distclean clean_context
|
||||
ifeq ($(CONFIG_BUILD_2PASS),y)
|
||||
$(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" distclean
|
||||
endif
|
||||
$(call DELFILE, Make.defs)
|
||||
$(call DELFILE, setenv.sh)
|
||||
$(call DELFILE, setenv.bat)
|
||||
$(call DELFILE, .config)
|
||||
$(call DELFILE, .config.old)
|
||||
|
||||
# Application housekeeping targets. The APPDIR variable refers to the user
|
||||
# application directory. A sample apps/ directory is included with NuttX,
|
||||
# however, this is not treated as part of NuttX and may be replaced with a
|
||||
# different application directory. For the most part, the application
|
||||
# directory is treated like any other build directory in this script. However,
|
||||
# as a convenience, the following targets are included to support housekeeping
|
||||
# functions in the user application directory from the NuttX build directory.
|
||||
#
|
||||
# apps_clean: Perform the clean operation only in the user application
|
||||
# directory
|
||||
# apps_distclean: Perform the distclean operation only in the user application
|
||||
# directory. Note that the apps/.config file (inf any) is
|
||||
# preserved so that this is not a "full" distclean but more of a
|
||||
# configuration "reset." (There willnot be an apps/.config
|
||||
# file if the configuration was generated via make menuconfig).
|
||||
|
||||
apps_clean:
|
||||
ifneq ($(APPDIR),)
|
||||
$(Q) $(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" clean
|
||||
endif
|
||||
|
||||
apps_distclean:
|
||||
ifneq ($(APPDIR),)
|
||||
$(Q) if [ -r "$(TOPDIR)/$(APPDIR)/.config" ]; then \
|
||||
cp "$(TOPDIR)/$(APPDIR)/.config" _SAVED_APPS_config || \
|
||||
{ echo "Copy of $(APPDIR)/.config failed" ; exit 1 ; } \
|
||||
else \
|
||||
rm -f _SAVED_APPS_config; \
|
||||
fi
|
||||
$(Q) $(MAKE) -C "$(TOPDIR)/$(APPDIR)" TOPDIR="$(TOPDIR)" distclean
|
||||
$(Q) if [ -r _SAVED_APPS_config ]; then \
|
||||
mv _SAVED_APPS_config "$(TOPDIR)/$(APPDIR)/.config" || \
|
||||
{ echo "Copy of _SAVED_APPS_config failed" ; exit 1 ; } \
|
||||
fi
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,740 @@
|
||||
############################################################################
|
||||
# Makefile.win
|
||||
#
|
||||
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
TOPDIR := ${shell echo %CD%}
|
||||
-include $(TOPDIR)\.config
|
||||
-include $(TOPDIR)\tools\Config.mk
|
||||
-include $(TOPDIR)\Make.defs
|
||||
|
||||
# Control build verbosity
|
||||
|
||||
ifeq ($(V),1)
|
||||
export Q :=
|
||||
else
|
||||
export Q := @
|
||||
endif
|
||||
|
||||
# This define is passed as EXTRADEFINES for kernel-mode builds. It is also passed
|
||||
# during PASS1 (but not PASS2) context and depend targets.
|
||||
|
||||
KDEFINE = ${shell $(TOPDIR)\tools\define.bat "$(CC)" __KERNEL__}
|
||||
|
||||
# Process architecture and board-specific directories
|
||||
|
||||
ARCH_DIR = arch\$(CONFIG_ARCH)
|
||||
ARCH_SRC = $(ARCH_DIR)\src
|
||||
ARCH_INC = $(ARCH_DIR)\include
|
||||
BOARD_DIR = configs\$(CONFIG_ARCH_BOARD)
|
||||
|
||||
# Add-on directories. These may or may not be in place in the
|
||||
# NuttX source tree (they must be specifically installed)
|
||||
#
|
||||
# CONFIG_APPS_DIR can be over-ridden from the command line or in the .config file.
|
||||
# The default value of CONFIG_APPS_DIR is ..\apps. Ultimately, the application
|
||||
# will be built if APPDIR is defined. APPDIR will be defined if a directory containing
|
||||
# a Makefile is found at the path provided by CONFIG_APPS_DIR
|
||||
|
||||
ifeq ($(CONFIG_APPS_DIR),)
|
||||
CONFIG_APPS_DIR = ..\apps
|
||||
endif
|
||||
APPDIR := ${shell if exist "$(CONFIG_APPS_DIR)\Makefile" echo $(CONFIG_APPS_DIR)}
|
||||
|
||||
# All add-on directories.
|
||||
#
|
||||
# NUTTX_ADDONS is the list of directories built into the NuttX kernel.
|
||||
# USER_ADDONS is the list of directories that will be built into the user application
|
||||
|
||||
NUTTX_ADDONS :=
|
||||
USER_ADDONS :=
|
||||
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
USER_ADDONS += $(APPDIR)
|
||||
else
|
||||
NUTTX_ADDONS += $(APPDIR)
|
||||
endif
|
||||
|
||||
# Lists of build directories.
|
||||
#
|
||||
# FSDIRS depend on file descriptor support; NONFSDIRS do not (except for parts
|
||||
# of FSDIRS). We will exclude FSDIRS from the build if file descriptor
|
||||
# support is disabled
|
||||
# CONTEXTDIRS include directories that have special, one-time pre-build
|
||||
# requirements. Normally this includes things like auto-generation of
|
||||
# configuration specific files or creation of configurable symbolic links
|
||||
# USERDIRS - When NuttX is build is a monolithic kernel, this provides the
|
||||
# list of directories that must be built
|
||||
# OTHERDIRS - These are directories that are not built but probably should
|
||||
# be cleaned to prevent garbarge from collecting in them when changing
|
||||
# configurations.
|
||||
|
||||
NONFSDIRS = sched $(ARCH_SRC) $(NUTTX_ADDONS)
|
||||
FSDIRS = fs drivers binfmt
|
||||
CONTEXTDIRS = $(APPDIR)
|
||||
USERDIRS =
|
||||
OTHERDIRS = lib
|
||||
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
|
||||
NONFSDIRS += syscall
|
||||
CONTEXTDIRS += syscall
|
||||
USERDIRS += syscall libc mm $(USER_ADDONS)
|
||||
ifeq ($(CONFIG_HAVE_CXX),y)
|
||||
USERDIRS += libxx
|
||||
endif
|
||||
|
||||
else
|
||||
|
||||
NONFSDIRS += libc mm
|
||||
OTHERDIRS += syscall $(USER_ADDONS)
|
||||
ifeq ($(CONFIG_HAVE_CXX),y)
|
||||
NONFSDIRS += libxx
|
||||
else
|
||||
OTHERDIRS += libxx
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NX),y)
|
||||
NONFSDIRS += graphics
|
||||
CONTEXTDIRS += graphics
|
||||
else
|
||||
OTHERDIRS += graphics
|
||||
endif
|
||||
|
||||
# CLEANDIRS are the directories that will clean in. These are
|
||||
# all directories that we know about.
|
||||
# KERNDEPDIRS are the directories in which we will build target dependencies.
|
||||
# If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL),
|
||||
# then this holds only the directories containing kernel files.
|
||||
# USERDEPDIRS. If NuttX and applications are built separately (CONFIG_NUTTX_KERNEL),
|
||||
# then this holds only the directories containing user files.
|
||||
|
||||
CLEANDIRS = $(NONFSDIRS) $(FSDIRS) $(USERDIRS) $(OTHERDIRS)
|
||||
KERNDEPDIRS = $(NONFSDIRS)
|
||||
USERDEPDIRS = $(USERDIRS)
|
||||
|
||||
# Add file system directories to KERNDEPDIRS (they are already in CLEANDIRS)
|
||||
|
||||
ifeq ($(CONFIG_NFILE_DESCRIPTORS),0)
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
|
||||
KERNDEPDIRS += fs
|
||||
endif
|
||||
KERNDEPDIRS += drivers
|
||||
endif
|
||||
else
|
||||
KERNDEPDIRS += $(FSDIRS)
|
||||
endif
|
||||
|
||||
# Add networking directories to KERNDEPDIRS and CLEANDIRS
|
||||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
KERNDEPDIRS += net
|
||||
endif
|
||||
CLEANDIRS += net
|
||||
|
||||
#
|
||||
# Extra objects used in the final link.
|
||||
#
|
||||
# Pass 1 1ncremental (relative) link objects should be put into the
|
||||
# processor-specific source directory (where other link objects will
|
||||
# be created). If the pass1 obect is an archive, it could go anywhere.
|
||||
|
||||
ifeq ($(CONFIG_BUILD_2PASS),y)
|
||||
EXTRA_OBJS += $(CONFIG_PASS1_OBJECT)
|
||||
endif
|
||||
|
||||
# NUTTXLIBS is the list of NuttX libraries that is passed to the
|
||||
# processor-specific Makefile to build the final NuttX target.
|
||||
# Libraries in FSDIRS are excluded if file descriptor support
|
||||
# is disabled.
|
||||
# USERLIBS is the list of libraries used to build the final user-space
|
||||
# application
|
||||
|
||||
NUTTXLIBS = lib\libsched$(LIBEXT) lib\libarch$(LIBEXT)
|
||||
USERLIBS =
|
||||
|
||||
# Add libraries for syscall support. The C library will be needed by
|
||||
# both the kernel- and user-space builds. For now, the memory manager (mm)
|
||||
# is placed in user space (only).
|
||||
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
NUTTXLIBS += lib\libstubs$(LIBEXT) lib\libkc$(LIBEXT)
|
||||
USERLIBS += lib\libproxies$(LIBEXT) lib\libuc$(LIBEXT) lib\libmm$(LIBEXT)
|
||||
else
|
||||
NUTTXLIBS += lib\libmm$(LIBEXT) lib\libc$(LIBEXT)
|
||||
endif
|
||||
|
||||
# Add libraries for C++ support. CXX, CXXFLAGS, and COMPILEXX must
|
||||
# be defined in Make.defs for this to work!
|
||||
|
||||
ifeq ($(CONFIG_HAVE_CXX),y)
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
USERLIBS += lib\libcxx$(LIBEXT)
|
||||
else
|
||||
NUTTXLIBS += lib\libcxx$(LIBEXT)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Add library for application support.
|
||||
|
||||
ifneq ($(APPDIR),)
|
||||
ifeq ($(CONFIG_NUTTX_KERNEL),y)
|
||||
USERLIBS += lib\libapps$(LIBEXT)
|
||||
else
|
||||
NUTTXLIBS += lib\libapps$(LIBEXT)
|
||||
endif
|
||||
endif
|
||||
|
||||
# Add libraries for network support
|
||||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
NUTTXLIBS += lib\libnet$(LIBEXT)
|
||||
endif
|
||||
|
||||
# Add libraries for file system support
|
||||
|
||||
ifeq ($(CONFIG_NFILE_DESCRIPTORS),0)
|
||||
ifneq ($(CONFIG_NSOCKET_DESCRIPTORS),0)
|
||||
NUTTXLIBS += lib\libfs$(LIBEXT)
|
||||
endif
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
NUTTXLIBS += lib\libdrivers$(LIBEXT)
|
||||
endif
|
||||
else
|
||||
NUTTXLIBS += lib\libfs$(LIBEXT) lib\libdrivers$(LIBEXT) lib\libbinfmt$(LIBEXT)
|
||||
endif
|
||||
|
||||
# Add libraries for the NX graphics sub-system
|
||||
|
||||
ifeq ($(CONFIG_NX),y)
|
||||
NUTTXLIBS += lib\libgraphics$(LIBEXT)
|
||||
endif
|
||||
|
||||
# LINKLIBS derives from NUTTXLIBS and is simply the same list with the subdirectory removed
|
||||
|
||||
LINKLIBS = $(patsubst lib\\%,%,$(NUTTXLIBS))
|
||||
|
||||
# This is the name of the final target (relative to the top level directorty)
|
||||
|
||||
BIN = nuttx$(EXEEXT)
|
||||
|
||||
all: $(BIN)
|
||||
.PHONY: context clean_context check_context export subdir_clean clean subdir_distclean distclean apps_clean apps_distclean
|
||||
|
||||
# Target used to copy include\nuttx\math.h. If CONFIG_ARCH_MATH_H is
|
||||
# defined, then there is an architecture specific math.h header file
|
||||
# that will be included indirectly from include\math.h. But first, we
|
||||
# have to copy math.h from include\nuttx\. to include\. Logic within
|
||||
# include\nuttx\math.h will hand the redirection to the architecture-
|
||||
# specific math.h header file.
|
||||
#
|
||||
# If the CONFIG_LIBM is defined, the Rhombus libm will be built at libc\math.
|
||||
# Definitions and prototypes for the Rhombus libm are also contained in
|
||||
# include\nuttx\math.h and so the file must also be copied in that case.
|
||||
#
|
||||
# If neither CONFIG_ARCH_MATH_H nor CONFIG_LIBM is defined, then no math.h
|
||||
# header file will be provided. You would want that behavior if (1) you
|
||||
# don't use libm, or (2) you want to use the math.h and libm provided
|
||||
# within your toolchain.
|
||||
|
||||
ifeq ($(CONFIG_ARCH_MATH_H),y)
|
||||
NEED_MATH_H = y
|
||||
else
|
||||
ifeq ($(CONFIG_LIBM),y)
|
||||
NEED_MATH_H = y
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(NEED_MATH_H),y)
|
||||
include\math.h: include\nuttx\math.h
|
||||
$(Q) cp -f include\nuttx\math.h include\math.h
|
||||
else
|
||||
include\math.h:
|
||||
endif
|
||||
|
||||
# The float.h header file defines the properties of your floating point
|
||||
# implementation. It would always be best to use your toolchain's float.h
|
||||
# header file but if none is avaiable, a default float.h header file will
|
||||
# provided if this option is selected. However there is no assurance that
|
||||
# the settings in this float.h are actually correct for your platform!
|
||||
|
||||
ifeq ($(CONFIG_ARCH_FLOAT_H),y)
|
||||
include\float.h: include\nuttx\float.h
|
||||
$(Q) cp -f include\nuttx\float.h include\float.h
|
||||
else
|
||||
include\float.h:
|
||||
endif
|
||||
|
||||
# Target used to copy include\nuttx\stdarg.h. If CONFIG_ARCH_STDARG_H is
|
||||
# defined, then there is an architecture specific stdarg.h header file
|
||||
# that will be included indirectly from include\stdarg.h. But first, we
|
||||
# have to copy stdarg.h from include\nuttx\. to include\.
|
||||
|
||||
ifeq ($(CONFIG_ARCH_STDARG_H),y)
|
||||
include\stdarg.h: include\nuttx\stdarg.h
|
||||
$(Q) cp -f include\nuttx\stdarg.h include\stdarg.h
|
||||
else
|
||||
include\stdarg.h:
|
||||
endif
|
||||
|
||||
# Targets used to build include\nuttx\version.h. Creation of version.h is
|
||||
# part of the overall NuttX configuration sequence. Notice that the
|
||||
# tools\mkversion tool is built and used to create include\nuttx\version.h
|
||||
|
||||
tools\mkversion$(HOSTEXEEXT):
|
||||
$(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkversion$(HOSTEXEEXT)
|
||||
|
||||
$(TOPDIR)\.version:
|
||||
$(Q) if [ ! -f .version ]; then \
|
||||
echo "No .version file found, creating one"; \
|
||||
tools\version.sh -v 0.0 -b 0 .version; \
|
||||
chmod 755 .version; \
|
||||
fi
|
||||
|
||||
include\nuttx\version.h: $(TOPDIR)\.version tools\mkversion$(HOSTEXEEXT)
|
||||
$(Q) tools\mkversion$(HOSTEXEEXT) $(TOPDIR) > include\nuttx\version.h
|
||||
|
||||
# Targets used to build include\nuttx\config.h. Creation of config.h is
|
||||
# part of the overall NuttX configuration sequence. Notice that the
|
||||
# tools\mkconfig tool is built and used to create include\nuttx\config.h
|
||||
|
||||
tools\mkconfig$(HOSTEXEEXT):
|
||||
$(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkconfig$(HOSTEXEEXT)
|
||||
|
||||
include\nuttx\config.h: $(TOPDIR)\.config tools\mkconfig$(HOSTEXEEXT)
|
||||
$(Q) tools\mkconfig$(HOSTEXEEXT) $(TOPDIR) > include\nuttx\config.h
|
||||
|
||||
# Targets used to create dependencies
|
||||
|
||||
tools\mkdeps$(HOSTEXEEXT):
|
||||
$(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" mkdeps$(HOSTEXEEXT)
|
||||
|
||||
# dirlinks, and helpers
|
||||
#
|
||||
# Directories links. Most of establishing the NuttX configuration involves
|
||||
# setting up symbolic links with 'generic' directory names to specific,
|
||||
# configured directories.
|
||||
#
|
||||
# Link the apps\include directory to include\apps
|
||||
|
||||
include\apps: Make.defs
|
||||
ifneq ($(APPDIR),)
|
||||
@echo LN: include\apps $(APPDIR)\include
|
||||
ifeq ($(CONFIG_WINDOWS_MKLINK),y)
|
||||
$(Q) /user:administrator mklink /d include\apps $(APPDIR)\include
|
||||
else
|
||||
$(Q) xcopy $(APPDIR)\include include\apps /c /q /s /e /y /i
|
||||
$(Q) echo FAKELNK > include\apps\.fakelnk
|
||||
endif
|
||||
endif
|
||||
|
||||
# Link the arch\<arch-name>\include directory to include\arch
|
||||
|
||||
include\arch: Make.defs
|
||||
@echo LN: include\arch to $(ARCH_DIR)\include
|
||||
ifeq ($(CONFIG_WINDOWS_MKLINK),y)
|
||||
$(Q) /user:administrator mklink /d include\arch $(TOPDIR)\$(ARCH_DIR)\include
|
||||
else
|
||||
$(Q) xcopy $(TOPDIR)\$(ARCH_DIR)\include include\arch /c /q /s /e /y /i
|
||||
$(Q) echo FAKELNK > include\arch\.fakelnk
|
||||
endif
|
||||
|
||||
# Link the configs\<board-name>\include directory to include\arch\board
|
||||
|
||||
include\arch\board: include\arch Make.defs include\arch
|
||||
@echo LN: include\arch\board to $(BOARD_DIR)\include
|
||||
ifeq ($(CONFIG_WINDOWS_MKLINK),y)
|
||||
$(Q) /user:administrator mklink /d include\arch\board $(TOPDIR)\$(BOARD_DIR)\include
|
||||
else
|
||||
$(Q) xcopy $(TOPDIR)\$(BOARD_DIR)\include include\arch\board /c /q /s /e /y /i
|
||||
$(Q) echo FAKELNK > include\arch\board\.fakelnk
|
||||
endif
|
||||
|
||||
# Link the configs\<board-name>\src dir to arch\<arch-name>\src\board
|
||||
|
||||
$(ARCH_SRC)\board: Make.defs
|
||||
@echo LN: $(ARCH_SRC)\board to $(BOARD_DIR)\src
|
||||
ifeq ($(CONFIG_WINDOWS_MKLINK),y)
|
||||
$(Q) /user:administrator mklink /d $(ARCH_SRC)\board $(TOPDIR)\$(BOARD_DIR)\src
|
||||
else
|
||||
$(Q) xcopy $(TOPDIR)\$(BOARD_DIR)\src $(ARCH_SRC)\board /c /q /s /e /y /i
|
||||
$(Q) echo FAKELNK > $(ARCH_SRC)\board\.fakelnk
|
||||
endif
|
||||
|
||||
# Link arch\<arch-name>\include\<chip-name> to arch\<arch-name>\include\chip
|
||||
|
||||
$(ARCH_SRC)\chip: Make.defs
|
||||
ifneq ($(CONFIG_ARCH_CHIP),)
|
||||
@echo LN: $(ARCH_SRC)\chip to $(ARCH_SRC)\$(CONFIG_ARCH_CHIP)
|
||||
ifeq ($(CONFIG_WINDOWS_MKLINK),y)
|
||||
$(Q) /user:administrator mklink /d $(ARCH_SRC)\chip $(TOPDIR)\$(ARCH_SRC)\$(CONFIG_ARCH_CHIP)
|
||||
else
|
||||
$(Q) xcopy $(TOPDIR)\$(ARCH_SRC)\$(CONFIG_ARCH_CHIP) $(ARCH_SRC)\chip /c /q /s /e /y /i
|
||||
$(Q) echo FAKELNK > $(ARCH_SRC)\chip\.fakelnk
|
||||
endif
|
||||
endif
|
||||
|
||||
# Link arch\<arch-name>\src\<chip-name> to arch\<arch-name>\src\chip
|
||||
|
||||
include\arch\chip: include\arch Make.defs
|
||||
ifneq ($(CONFIG_ARCH_CHIP),)
|
||||
@echo LN: include\arch\chip to $(ARCH_INC)\$(CONFIG_ARCH_CHIP)
|
||||
ifeq ($(CONFIG_WINDOWS_MKLINK),y)
|
||||
$(Q) /user:administrator mklink /d include\arch\chip $(TOPDIR)\$(ARCH_INC)\$(CONFIG_ARCH_CHIP)
|
||||
else
|
||||
$(Q) xcopy $(TOPDIR)\$(ARCH_INC)\$(CONFIG_ARCH_CHIP) include\arch\chip /c /q /s /e /y /i
|
||||
$(Q) echo FAKELNK > include\arch\chip\.fakelnk
|
||||
endif
|
||||
endif
|
||||
|
||||
dirlinks: include\arch include\arch\board include\arch\chip $(ARCH_SRC)\board $(ARCH_SRC)\chip include\apps
|
||||
|
||||
# context
|
||||
#
|
||||
# The context target is invoked on each target build to assure that NuttX is
|
||||
# properly configured. The basic configuration steps include creation of the
|
||||
# the config.h and version.h header files in the include\nuttx directory and
|
||||
# the establishment of symbolic links to configured directories.
|
||||
|
||||
context: check_context include\nuttx\config.h include\nuttx\version.h include\math.h include\float.h include\stdarg.h dirlinks
|
||||
$(Q) for %%G in ($(CONTEXTDIRS)) do ( $(MAKE) -C %%G TOPDIR="$(TOPDIR)" context )
|
||||
|
||||
# clean_context
|
||||
#
|
||||
# This is part of the distclean target. It removes all of the header files
|
||||
# and symbolic links created by the context target.
|
||||
|
||||
clean_context:
|
||||
$(call DELFILE, include\nuttx\config.h)
|
||||
$(call DELFILE, include\nuttx\version.h)
|
||||
$(call DELFILE, include\math.h)
|
||||
$(call DELFILE, include\stdarg.h)
|
||||
$(call DELDIR, include\arch\board)
|
||||
$(call DELDIR, include\arch\chip)
|
||||
$(call DELDIR, include\arch)
|
||||
$(call DELDIR, $(ARCH_SRC)\board)
|
||||
$(call DELDIR, $(ARCH_SRC)\chip)
|
||||
$(call DELDIR, include\apps)
|
||||
|
||||
# check_context
|
||||
#
|
||||
# This target checks if NuttX has been configured. NuttX is configured using
|
||||
# the script tools\configure.sh. That script will install certain files in
|
||||
# the top-level NuttX build directory. This target verifies that those
|
||||
# configuration files have been installed and that NuttX is ready to be built.
|
||||
|
||||
check_context:
|
||||
$(Q) if not exist $(TOPDIR)\.config echo "$(TOPDIR)\.config does not exist"
|
||||
$(Q) if not exist $(TOPDIR)\Make.defs echo "$(TOPDIR)\Make.defs does not exist"
|
||||
|
||||
# Archive targets. The target build sequency will first create a series of
|
||||
# libraries, one per configured source file directory. The final NuttX
|
||||
# execution will then be built from those libraries. The following targets
|
||||
# build those libraries.
|
||||
#
|
||||
# Possible kernel-mode builds
|
||||
|
||||
libc\libkc$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libkc$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib\libkc$(LIBEXT): libc\libkc$(LIBEXT)
|
||||
$(Q) install libc\libkc$(LIBEXT) lib\libkc$(LIBEXT)
|
||||
|
||||
sched\libsched$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C sched TOPDIR="$(TOPDIR)" libsched$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib\libsched$(LIBEXT): sched\libsched$(LIBEXT)
|
||||
$(Q) install sched\libsched$(LIBEXT) lib\libsched$(LIBEXT)
|
||||
|
||||
$(ARCH_SRC)\libarch$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" libarch$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib\libarch$(LIBEXT): $(ARCH_SRC)\libarch$(LIBEXT)
|
||||
$(Q) install $(ARCH_SRC)\libarch$(LIBEXT) lib\libarch$(LIBEXT)
|
||||
|
||||
net\libnet$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C net TOPDIR="$(TOPDIR)" libnet$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib\libnet$(LIBEXT): net\libnet$(LIBEXT)
|
||||
$(Q) install net\libnet$(LIBEXT) lib\libnet$(LIBEXT)
|
||||
|
||||
fs\libfs$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C fs TOPDIR="$(TOPDIR)" libfs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib\libfs$(LIBEXT): fs\libfs$(LIBEXT)
|
||||
$(Q) install fs\libfs$(LIBEXT) lib\libfs$(LIBEXT)
|
||||
|
||||
drivers\libdrivers$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C drivers TOPDIR="$(TOPDIR)" libdrivers$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib\libdrivers$(LIBEXT): drivers\libdrivers$(LIBEXT)
|
||||
$(Q) install drivers\libdrivers$(LIBEXT) lib\libdrivers$(LIBEXT)
|
||||
|
||||
binfmt\libbinfmt$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C binfmt TOPDIR="$(TOPDIR)" libbinfmt$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib\libbinfmt$(LIBEXT): binfmt\libbinfmt$(LIBEXT)
|
||||
$(Q) install binfmt\libbinfmt$(LIBEXT) lib\libbinfmt$(LIBEXT)
|
||||
|
||||
graphics\libgraphics$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C graphics TOPDIR="$(TOPDIR)" libgraphics$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib\libgraphics$(LIBEXT): graphics\libgraphics$(LIBEXT)
|
||||
$(Q) install graphics\libgraphics$(LIBEXT) lib\libgraphics$(LIBEXT)
|
||||
|
||||
syscall\libstubs$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C syscall TOPDIR="$(TOPDIR)" libstubs$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib\libstubs$(LIBEXT): syscall\libstubs$(LIBEXT)
|
||||
$(Q) install syscall\libstubs$(LIBEXT) lib\libstubs$(LIBEXT)
|
||||
|
||||
# Possible user-mode builds
|
||||
|
||||
libc\libuc$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libuc$(LIBEXT)
|
||||
|
||||
lib\libuc$(LIBEXT): libc\libuc$(LIBEXT)
|
||||
$(Q) install libc\libuc$(LIBEXT) lib\libuc$(LIBEXT)
|
||||
|
||||
libxx\libcxx$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C libxx TOPDIR="$(TOPDIR)" libcxx$(LIBEXT)
|
||||
|
||||
lib\libcxx$(LIBEXT): libxx\libcxx$(LIBEXT)
|
||||
$(Q) install libxx\libcxx$(LIBEXT) lib\libcxx$(LIBEXT)
|
||||
|
||||
mm\libmm$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C mm TOPDIR="$(TOPDIR)" libmm$(LIBEXT) EXTRADEFINES=$(KDEFINE)
|
||||
|
||||
lib\libmm$(LIBEXT): mm\libmm$(LIBEXT)
|
||||
$(Q) install mm\libmm$(LIBEXT) lib\libmm$(LIBEXT)
|
||||
|
||||
$(APPDIR)\libapps$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C $(APPDIR) TOPDIR="$(TOPDIR)" libapps$(LIBEXT)
|
||||
|
||||
lib\libapps$(LIBEXT): $(APPDIR)\libapps$(LIBEXT)
|
||||
$(Q) install $(APPDIR)\libapps$(LIBEXT) lib\libapps$(LIBEXT)
|
||||
|
||||
syscall\libproxies$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C syscall TOPDIR="$(TOPDIR)" libproxies$(LIBEXT)
|
||||
|
||||
lib\libproxies$(LIBEXT): syscall\libproxies$(LIBEXT)
|
||||
$(Q) install syscall\libproxies$(LIBEXT) lib\libproxies$(LIBEXT)
|
||||
|
||||
# Possible non-kernel builds
|
||||
|
||||
libc\libc$(LIBEXT): context
|
||||
$(Q) $(MAKE) -C libc TOPDIR="$(TOPDIR)" libc$(LIBEXT)
|
||||
|
||||
lib\libc$(LIBEXT): libc\libc$(LIBEXT)
|
||||
$(Q) install libc\libc$(LIBEXT) lib\libc$(LIBEXT)
|
||||
|
||||
# pass1 and pass2
|
||||
#
|
||||
# If the 2 pass build option is selected, then this pass1 target is
|
||||
# configured to built before the pass2 target. This pass1 target may, as an
|
||||
# example, build an extra link object (CONFIG_PASS1_OBJECT) which may be an
|
||||
# incremental (relative) link object, but could be a static library (archive);
|
||||
# some modification to this Makefile would be required if CONFIG_PASS1_OBJECT
|
||||
# is an archive. Exactly what is performed during pass1 or what it generates
|
||||
# is unknown to this makefule unless CONFIG_PASS1_OBJECT is defined.
|
||||
|
||||
pass1deps: pass1dep $(USERLIBS)
|
||||
|
||||
pass1: pass1deps
|
||||
ifeq ($(CONFIG_BUILD_2PASS),y)
|
||||
$(Q) if [ -z "$(CONFIG_PASS1_BUILDIR)" ]; then \
|
||||
echo "ERROR: CONFIG_PASS1_BUILDIR not defined"; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(Q) if [ ! -d "$(CONFIG_PASS1_BUILDIR)" ]; then \
|
||||
echo "ERROR: CONFIG_PASS1_BUILDIR does not exist"; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(Q) if [ ! -f "$(CONFIG_PASS1_BUILDIR)\Makefile" ]; then \
|
||||
echo "ERROR: No Makefile in CONFIG_PASS1_BUILDIR"; \
|
||||
exit 1; \
|
||||
fi
|
||||
$(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" LINKLIBS="$(LINKLIBS)" USERLIBS="$(USERLIBS)" "$(CONFIG_PASS1_TARGET)"
|
||||
endif
|
||||
|
||||
pass2deps: pass2dep $(NUTTXLIBS)
|
||||
|
||||
pass2: pass2deps
|
||||
$(Q) $(MAKE) -C $(ARCH_SRC) TOPDIR="$(TOPDIR)" EXTRA_OBJS="$(EXTRA_OBJS)" LINKLIBS="$(LINKLIBS)" EXTRADEFINES=$(KDEFINE) $(BIN)
|
||||
ifeq ($(CONFIG_RRLOAD_BINARY),y)
|
||||
@echo "MK: $(BIN).rr"
|
||||
$(Q) $(TOPDIR)\tools\mkimage.sh --Prefix $(CROSSDEV) $(BIN) $(BIN).rr
|
||||
endif
|
||||
ifeq ($(CONFIG_INTELHEX_BINARY),y)
|
||||
@echo "CP: $(BIN).hex"
|
||||
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O ihex $(BIN) $(BIN).hex
|
||||
endif
|
||||
ifeq ($(CONFIG_MOTOROLA_SREC),y)
|
||||
@echo "CP: $(BIN).srec"
|
||||
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O srec $(BIN) $(BIN).srec
|
||||
endif
|
||||
ifeq ($(CONFIG_RAW_BINARY),y)
|
||||
@echo "CP: $(BIN).bin"
|
||||
$(Q) $(OBJCOPY) $(OBJCOPYARGS) -O binary $(BIN) $(BIN).bin
|
||||
endif
|
||||
|
||||
# $(BIN)
|
||||
#
|
||||
# Create the final NuttX executable in a two pass build process. In the
|
||||
# normal case, all pass1 and pass2 dependencies are created then pass1
|
||||
# and pass2 targets are built. However, in some cases, you may need to build
|
||||
# pass1 depenencies and pass1 first, then build pass2 dependencies and pass2.
|
||||
# in that case, execute 'make pass1 pass2' from the command line.
|
||||
|
||||
$(BIN): pass1deps pass2deps pass1 pass2
|
||||
|
||||
# download
|
||||
#
|
||||
# This is a helper target that will rebuild NuttX and download it to the target
|
||||
# system in one step. The operation of this target depends completely upon
|
||||
# implementation of the DOWNLOAD command in the user Make.defs file. It will
|
||||
# generate an error an error if the DOWNLOAD command is not defined.
|
||||
|
||||
download: $(BIN)
|
||||
$(call DOWNLOAD, $<)
|
||||
|
||||
# pass1dep: Create pass1 build dependencies
|
||||
# pass2dep: Create pass2 build dependencies
|
||||
|
||||
pass1dep: context tools\mkdeps$(HOSTEXEEXT)
|
||||
$(Q) for %%G in ($(USERDEPDIRS)) do ( $(MAKE) -C %%G TOPDIR="$(TOPDIR)" depend )
|
||||
|
||||
pass2dep: context tools\mkdeps$(HOSTEXEEXT)
|
||||
$(Q) for %%G in ($(KERNDEPDIRS)) do ( $(MAKE) -C %%G TOPDIR="$(TOPDIR)" EXTRADEFINES=$(KDEFINE) depend )
|
||||
|
||||
# Configuration targets
|
||||
#
|
||||
# These targets depend on the kconfig-frontends packages. To use these, you
|
||||
# must first download and install the kconfig-frontends package from this
|
||||
# location: http://ymorin.is-a-geek.org/projects/kconfig-frontends. See
|
||||
# misc\tools\README.txt for additional information.
|
||||
|
||||
config:
|
||||
$(Q) APPSDIR=${CONFIG_APPS_DIR} conf Kconfig
|
||||
|
||||
oldconfig:
|
||||
$(Q) APPSDIR=${CONFIG_APPS_DIR} conf --oldconfig Kconfig
|
||||
|
||||
menuconfig:
|
||||
$(Q) APPSDIR=${CONFIG_APPS_DIR} mconf Kconfig
|
||||
|
||||
# export
|
||||
#
|
||||
# The export target will package the NuttX libraries and header files into
|
||||
# an exportable package. Caveats: (1) These needs some extension for the KERNEL
|
||||
# build; it needs to receive USERLIBS and create a libuser.a). (2) The logic
|
||||
# in tools\mkexport.sh only supports GCC and, for example, explicitly assumes
|
||||
# that the archiver is 'ar'
|
||||
|
||||
export: pass2deps
|
||||
$(Q) tools\mkexport.sh -w$(WINTOOL) -t "$(TOPDIR)" -l "$(NUTTXLIBS)"
|
||||
|
||||
# General housekeeping targets: dependencies, cleaning, etc.
|
||||
#
|
||||
# depend: Create both PASS1 and PASS2 dependencies
|
||||
# clean: Removes derived object files, archives, executables, and
|
||||
# temporary files, but retains the configuration and context
|
||||
# files and directories.
|
||||
# distclean: Does 'clean' then also removes all configuration and context
|
||||
# files. This essentially restores the directory structure
|
||||
# to its original, unconfigured stated.
|
||||
|
||||
depend: pass1dep pass2dep
|
||||
|
||||
subdir_clean:
|
||||
$(Q) for %%G in ($(CLEANDIRS)) do ( if exist %%G\Makefile $(MAKE) -C %%G TOPDIR="$(TOPDIR)" clean )
|
||||
$(Q) $(MAKE) -C tools -f Makefile.host TOPDIR="$(TOPDIR)" clean
|
||||
$(Q) $(MAKE) -C mm -f Makefile.test TOPDIR="$(TOPDIR)" clean
|
||||
ifeq ($(CONFIG_BUILD_2PASS),y)
|
||||
$(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" clean
|
||||
endif
|
||||
|
||||
clean: subdir_clean
|
||||
$(call DELFILE, $(BIN))
|
||||
$(call DELFILE, nuttx.*)
|
||||
$(call DELFILE, mm_test)
|
||||
$(call DELFILE, *.map)
|
||||
$(call DELFILE, _SAVED_APPS_config)
|
||||
$(call DELFILE, nuttx-export*)
|
||||
$(call CLEAN)
|
||||
|
||||
subdir_distclean:
|
||||
$(Q) for %%G in ($(CLEANDIRS)) do ( if exist %%G\Makefile $(MAKE) -C %%G TOPDIR="$(TOPDIR)" distclean )
|
||||
|
||||
distclean: clean subdir_distclean clean_context
|
||||
ifeq ($(CONFIG_BUILD_2PASS),y)
|
||||
$(Q) $(MAKE) -C $(CONFIG_PASS1_BUILDIR) TOPDIR="$(TOPDIR)" distclean
|
||||
endif
|
||||
$(call DELFILE, Make.defs)
|
||||
$(call DELFILE, setenv.sh)
|
||||
$(call DELFILE, setenv.bat)
|
||||
$(call DELFILE, .config)
|
||||
$(call DELFILE, .config.old)
|
||||
|
||||
# Application housekeeping targets. The APPDIR variable refers to the user
|
||||
# application directory. A sample apps\ directory is included with NuttX,
|
||||
# however, this is not treated as part of NuttX and may be replaced with a
|
||||
# different application directory. For the most part, the application
|
||||
# directory is treated like any other build directory in this script. However,
|
||||
# as a convenience, the following targets are included to support housekeeping
|
||||
# functions in the user application directory from the NuttX build directory.
|
||||
#
|
||||
# apps_clean: Perform the clean operation only in the user application
|
||||
# directory
|
||||
# apps_distclean: Perform the distclean operation only in the user application
|
||||
# directory. Note that the apps\.config file (inf any) is
|
||||
# preserved so that this is not a "full" distclean but more of a
|
||||
# configuration "reset." (There willnot be an apps\.config
|
||||
# file if the configuration was generated via make menuconfig).
|
||||
|
||||
apps_clean:
|
||||
ifneq ($(APPDIR),)
|
||||
$(Q) $(MAKE) -C "$(TOPDIR)\$(APPDIR)" TOPDIR="$(TOPDIR)" clean
|
||||
endif
|
||||
|
||||
apps_distclean:
|
||||
ifneq ($(APPDIR),)
|
||||
$(call DELFILE, _SAVED_APPS_config
|
||||
$(Q) if exist "$(TOPDIR)\$(APPDIR)\.config" ( cp "$(TOPDIR)\$(APPDIR)\.config" _SAVED_APPS_config )
|
||||
$(Q) $(MAKE) -C "$(TOPDIR)\$(APPDIR)" TOPDIR="$(TOPDIR)" distclean
|
||||
$(Q) if exist _SAVED_APPS_config ( mv _SAVED_APPS_config "$(TOPDIR)\$(APPDIR)\.config" )
|
||||
endif
|
||||
|
||||
+149
-14
@@ -18,6 +18,8 @@ README
|
||||
- Building
|
||||
- Re-building
|
||||
- Build Targets and Options
|
||||
- Native Windows Build
|
||||
- Installing GNUWin32
|
||||
o Cygwin Build Problems
|
||||
- Strange Path Problems
|
||||
- Window Native Toolchain Issues
|
||||
@@ -154,9 +156,15 @@ Notes about Header Files
|
||||
|
||||
Even though you should not use a foreign C-Library, you may still need
|
||||
to use other, external libraries with NuttX. In particular, you may
|
||||
need to use the math library, libm.a. The math libary header file,
|
||||
math.h, is a special case. If you do nothing, the standard math.h
|
||||
header file that is provided with your toolchain will be used.
|
||||
need to use the math library, libm.a. NuttX supports a generic, built-in
|
||||
math library that can be enabled using CONFIG_LIBM=y. However, you may
|
||||
still want to use a higher performance external math library that has
|
||||
been tuned for your CPU. Sometimes such such tuned math libraries are
|
||||
bundled with your toolchain.
|
||||
|
||||
The math libary header file, math.h, is a then special case. If you do
|
||||
nothing, the standard math.h header file that is provided with your
|
||||
toolchain will be used.
|
||||
|
||||
If you have a custom, architecture specific math.h header file, then
|
||||
that header file should be placed at arch/<cpu>/include/math.h. There
|
||||
@@ -171,6 +179,16 @@ Notes about Header Files
|
||||
than to include that archicture-specific math.h header file as the
|
||||
system math.h header file.
|
||||
|
||||
float.h
|
||||
|
||||
If you enable the generic, built-in math library, then that math library
|
||||
will expect your toolchain to provide the standard float.h header file.
|
||||
The float.h header file defines the properties of your floating point
|
||||
implementation. It would always be best to use your toolchain's float.h
|
||||
header file but if none is avaiable, a default float.h header file will
|
||||
provided if this option is selected. However, there is no assurance that
|
||||
the settings in this float.h are actually correct for your platform!
|
||||
|
||||
stdarg.h
|
||||
|
||||
In most cases, the correct version of stdarg.h is the version provided with your toolchain. However, sometimes there are issues with with using your toolchains stdarg.h. For example, it may attempt to draw in header files that do not exist in NuttX or perhaps the header files that is uses are not compatible with the NuttX header files. In those cases, you can use an architecture-specific stdarg.h header file by defining CONFIG_ARCH_STDARG_H=y.
|
||||
@@ -189,7 +207,8 @@ Instantiating "Canned" Configurations
|
||||
|
||||
Where <board-name> is the name of your development board and <config-dir>.
|
||||
Configuring NuttX requires only copying three files from the <config-dir>
|
||||
to the directly where you installed NuttX (TOPDIR):
|
||||
to the directory where you installed NuttX (TOPDIR) (and sometimes one
|
||||
additional file to the directory the NuttX application package (APPSDIR)):
|
||||
|
||||
Copy configs/<board-name>/<config-dir>/Make.def to ${TOPDIR}/Make.defs
|
||||
|
||||
@@ -211,6 +230,14 @@ to the directly where you installed NuttX (TOPDIR):
|
||||
included in the build and what is not. This file is also used
|
||||
to generate a C configuration header at include/nuttx/config.h.
|
||||
|
||||
Copy configs/<board-name>/<config-dir>/appconfig to ${APPSDIR}/.config
|
||||
|
||||
The appconfig file describes the applications that need to be
|
||||
built in the appliction directory (APPSDIR). Not all configurations
|
||||
have an appconfig file. This file is deprecated and will not be
|
||||
used with new defconfig files produced with the mconf configuration
|
||||
tool.
|
||||
|
||||
General information about configuring NuttX can be found in:
|
||||
|
||||
${TOPDIR}/configs/README.txt
|
||||
@@ -468,6 +495,97 @@ Build Targets and Options
|
||||
useful when adding new boards or tracking down compile time errors and
|
||||
warnings (Contributed by Richard Cochran).
|
||||
|
||||
Native Windows Build
|
||||
--------------------
|
||||
|
||||
The beginnings of a Windows native build are in place but still not full
|
||||
usable as of this writing. The windows native build logic initiatiated
|
||||
if CONFIG_WINDOWS_NATIVE=y is defined in the NuttX configuration file:
|
||||
|
||||
This build:
|
||||
|
||||
- Uses all Windows style paths
|
||||
- Uses primarily Windows batch commands from cmd.exe, with
|
||||
- A few extensions from GNUWin32
|
||||
|
||||
In this build, you cannot use a Cygwin or MSYS shell. Rather the build must
|
||||
be performed in a Windows CMD shell. Here is a better shell than than the
|
||||
standard issue, CMD shell: ConEmu which can be downloaded from:
|
||||
http://code.google.com/p/conemu-maximus5/
|
||||
|
||||
Build Tools. The build still relies on some Unix-like commands. I use
|
||||
the GNUWin32 tools that can be downloaded from http://gnuwin32.sourceforge.net/.
|
||||
|
||||
Host Compiler: I use the MingGW compiler which can be downloaded from
|
||||
http://www.mingw.org/. If you are using GNUWin32, then it is recommended
|
||||
the you not install the optional MSYS components as there may be conflicts.
|
||||
|
||||
Installing GNUWin32
|
||||
-------------------
|
||||
|
||||
The Windows native build will depend upon a few Unix-like tools that can be
|
||||
provided either by MSYS or GNUWin32. The GNUWin32 are available from
|
||||
http://gnuwin32.sourceforge.net/. GNUWin32 provides ports of tools with a
|
||||
GPL or similar open source license to modern MS-Windows (Microsoft Windows
|
||||
2000 / XP / 2003 / Vista / 2008 / 7). See
|
||||
http://gnuwin32.sourceforge.net/packages.html for a list of all of the tools
|
||||
available in the GNUWin32 package.
|
||||
|
||||
The SourceForge project is located here:
|
||||
http://sourceforge.net/projects/gnuwin32/. The project is still being
|
||||
actively supported (although some of the Windows ports have gotten very old).
|
||||
|
||||
Some commercial toolchains include a subset of the GNUWin32 tools in the
|
||||
installation. My recommendation is that you download the GNUWin32 tools
|
||||
directly from the sourceforge.net website so that you will know what you are
|
||||
using and can reproduce your build environment.
|
||||
|
||||
GNUWin32 Installation Steps:
|
||||
|
||||
The following steps will download and execute the GNUWin32 installer.
|
||||
|
||||
1. Download GetGNUWin32-x.x.x.exe from
|
||||
http://sourceforge.net/projects/getgnuwin32/files/. This is the
|
||||
installer. The current version as of this writing is 0.6.3.
|
||||
|
||||
2. Run the installer.
|
||||
|
||||
3. Accept the license.
|
||||
|
||||
4. Select the installation directory. My recommendation is the
|
||||
directory that contains this README file (<this-directory>).
|
||||
|
||||
5. After running GetGNUWin32-0.x.x.exe, you will have a new directory
|
||||
<this-directory>/GetGNUWin32
|
||||
|
||||
Note the the GNUWin32 installer didn't install GNUWin32. Instead, it
|
||||
installed another, smarter downloader. That downloader is the GNUWin32
|
||||
package management tool developed by the Open SSL project.
|
||||
|
||||
The following steps probably should be performed from inside a DOS shell.
|
||||
|
||||
6. Change to the directory created by GetGNUWin32-x.x.x.exe
|
||||
|
||||
cd GetGNUWin32
|
||||
|
||||
7. Execute the download.bat script. The download.bat script will download
|
||||
about 446 packages! Enough to have a very complete Linux-like environment
|
||||
under the DOS shell. This will take awhile. This step only downloads
|
||||
the packages and the next step will install the packages.
|
||||
|
||||
download
|
||||
|
||||
8. This step will install the downloaded packages. The argument of the
|
||||
install.bat script is the installation location. C:\gnuwin32 is the
|
||||
standard install location:
|
||||
|
||||
install C:\gnuwin32
|
||||
|
||||
NOTE: This installation step will install *all* GNUWin32 packages... far
|
||||
more than you will ever need. If disc space is a problem for you, you might
|
||||
need to perform a manual installation of the individual ZIP files that you
|
||||
will find in the <this directory>/GetGNUWin32/packages directory.
|
||||
|
||||
CYGWIN BUILD PROBLEMS
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
@@ -523,18 +641,16 @@ Window Native Toolchain Issues
|
||||
is not a long as you might think because there is no dependency checking
|
||||
if you are using a native Windows toolchain. That bring us to #3:
|
||||
|
||||
3. Dependencies are not made when using Windows versions of the GCC. This is
|
||||
because the dependencies are generated using Windows pathes which do not
|
||||
work with the Cygwin make.
|
||||
3. Dependencies are not made when using Windows versions of the GCC on a POSIX
|
||||
platform (i.e., Cygwin). This is because the dependencies are generated
|
||||
using Windows paths which do not work with the Cygwin make.
|
||||
|
||||
Support has been added for making dependencies with the windows-native toolchains.
|
||||
That support can be enabled by modifying your Make.defs file as follows:
|
||||
MKDEP = $(TOPDIR)/tools/mknulldeps.sh
|
||||
|
||||
- MKDEP = $(TOPDIR)/tools/mknulldeps.sh
|
||||
+ MKDEP = $(TOPDIR)/tools/mkdeps.sh --winpaths "$(TOPDIR)"
|
||||
If you are building natively on Windows, then no such conflict exists
|
||||
and the best selection is:
|
||||
|
||||
If you have problems with the dependency build (for example, if you are not
|
||||
building on C:), then you may need to modify tools/mkdeps.sh
|
||||
MKDEP = $(TOPDIR)/tools/mkdeps.exe
|
||||
|
||||
General Pre-built Toolchain Issues
|
||||
|
||||
@@ -629,7 +745,8 @@ nuttx
|
||||
| | `-README.txt
|
||||
| `- z80/
|
||||
| | `- src/
|
||||
| | `- z80/README.txt
|
||||
| | |- z80/README.txt
|
||||
| | `- z180/README.txt, z180_mmu.txt
|
||||
| `- README.txt
|
||||
|- configs/
|
||||
| |- amber/
|
||||
@@ -728,6 +845,8 @@ nuttx
|
||||
| | |- include/README.txt
|
||||
| | |- src/README.txt
|
||||
| | `- README.txt
|
||||
| |- p112/
|
||||
| | `- README.txt
|
||||
| |- pcblogic-pic32mx/
|
||||
| | `- README.txt
|
||||
| |- pic32-starterkit/
|
||||
@@ -765,6 +884,8 @@ nuttx
|
||||
| | `- README.txt
|
||||
| |- stm3240g-eval/
|
||||
| | `- README.txt
|
||||
| |- stm32f100rc_generic/
|
||||
| | `- README.txt
|
||||
| |- stm32f4discovery/
|
||||
| | `- README.txt
|
||||
| |- sure-pic32mx/
|
||||
@@ -817,6 +938,8 @@ nuttx
|
||||
| `- README.txt
|
||||
|- lib/
|
||||
| `- README.txt
|
||||
|- libc/
|
||||
| `- README.txt
|
||||
|- libxx/
|
||||
| `- README.txt
|
||||
|- mm/
|
||||
@@ -828,6 +951,7 @@ nuttx
|
||||
|
||||
apps
|
||||
|- examples/
|
||||
| |- json/README.txt
|
||||
| |- pashello/README.txt
|
||||
| `- README.txt
|
||||
|- graphics/
|
||||
@@ -843,6 +967,8 @@ apps
|
||||
| | `- README.txt
|
||||
| |- ftpc
|
||||
| | `- README.txt
|
||||
| |- json
|
||||
| | `- README.txt
|
||||
| |- telnetd
|
||||
| | `- README.txt
|
||||
| `- README.txt
|
||||
@@ -864,3 +990,12 @@ apps
|
||||
| `- sysinfo
|
||||
| `- README.txt
|
||||
`- README.txt
|
||||
|
||||
NxWidgets
|
||||
|- Doxygen
|
||||
| `- README.txt
|
||||
|- tools
|
||||
| `- README.txt
|
||||
|- UnitTests
|
||||
| `- README.txt
|
||||
`- README.txt
|
||||
|
||||
@@ -3171,3 +3171,272 @@ Bugfixes (see the change log for details). Some of these are very important
|
||||
Vainish). Fix some field-width handling issues in sscanf()
|
||||
|
||||
As well as other, less critical bugs (see the ChangeLog for details)
|
||||
|
||||
NuttX-6.23
|
||||
^^^^^^^^^^
|
||||
|
||||
The 90th release of NuttX, Version 6.23, was made on November 5, 2012,
|
||||
and is available for download from the SourceForge website. Note
|
||||
that release consists of two tarballs: nuttx-6.23.tar.gz and
|
||||
apps-6.23.tar.gz. Both may be needed (see the top-level nuttx/README.txt
|
||||
file for build information).
|
||||
|
||||
This release corresponds with SVN release number: r5313
|
||||
|
||||
Note that all SVN information has been stripped from the tarballs. If you
|
||||
need the SVN configuration, you should check out directly from SVN. Revision
|
||||
r5313 should equivalent to release 6.23 of NuttX 6.23:
|
||||
|
||||
svn checkout -r5313 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
|
||||
|
||||
Or
|
||||
|
||||
svn checkout -r5313 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
|
||||
|
||||
Additional new features and extended functionality:
|
||||
|
||||
* RTOS: If both atexit() and on_exit() are enabled, use on_exit() to
|
||||
implement atexit(). Updates for RGMP 4.0.
|
||||
|
||||
* Binfmt: Add support for loading and executing ELF binary modules from
|
||||
a file system.
|
||||
|
||||
* Drivers: Maxim MAX11802 touchscreen controller (Petteri Aimonen)
|
||||
|
||||
* STM32 Driver: Implementation of /dev/random using the STM32 Random Number
|
||||
Generator (RNG).
|
||||
|
||||
* STM32 Boards: ADC support for the Shenzhou IV board. Relay support for
|
||||
the Shenzhou IV board.
|
||||
|
||||
* C Library: Support is now included for the add-on uClibc++ C++
|
||||
standard library support. This includes support for iostreams, strings,
|
||||
STL, RTTI, exceptions -- the complete C++ environment. (uClibc++ is
|
||||
provided as a separate add-on package due to licensing issues).
|
||||
|
||||
Optimized generic and ARM-specific memcpy() function. Optimized
|
||||
memset() function.
|
||||
|
||||
Add support for ferror(), feof(), and clearerror(). Add support for
|
||||
__cxa_atexit().
|
||||
|
||||
Math Library: Port of the math library from Rhombus OS by Nick Johnson
|
||||
(Darcy Gong).
|
||||
|
||||
* Applications: New NSH commands: ifup, ifdown, urlencode, urldecode,
|
||||
base64enc, bas64dec, md5 (Darcy Gong). Add support for NSH telnet login
|
||||
(Darcy Gong). Enancements to NSH ping command to support pinging hosts
|
||||
with very long round-trip times. Extensions to the ifconfig command
|
||||
Darcy Gong),
|
||||
|
||||
Many extensions to the webclient/wget and DNS resolver logic from Darcy
|
||||
Gong. JSON, Base64, URL encoding, and MD5 libraries contributed by Darcy
|
||||
Gong.
|
||||
|
||||
New examples: ELF loader, JSON, wgetjson, cxxtest, relays.
|
||||
|
||||
Bugfixes (see the change log for details). Some of these are very important
|
||||
(marked *critical*):
|
||||
|
||||
* Drivers: W25 SPI FLASH
|
||||
|
||||
* STM32 Drivers: ADC reset
|
||||
|
||||
* Graphics: Missing implementation of the blocked method (*critical*,
|
||||
Petteri Aimonen).
|
||||
|
||||
* C Library: Floating point numbers in printf and related formatting functions
|
||||
(Mike Smith), cf[get|set]speed() (Mike Smith)
|
||||
|
||||
As well as other, less critical bugs (see the ChangeLog for details)
|
||||
|
||||
NuttX-6.24
|
||||
^^^^^^^^^^
|
||||
|
||||
The 91st release of NuttX, Version 6.24, was made on December 20, 2012,
|
||||
and is available for download from the SourceForge website. Note
|
||||
that release consists of two tarballs: nuttx-6.24.tar.gz and
|
||||
apps-6.24.tar.gz. Both may be needed (see the top-level nuttx/README.txt
|
||||
file for build information).
|
||||
|
||||
This release corresponds with SVN release number: r5447
|
||||
|
||||
Note that all SVN information has been stripped from the tarballs. If you
|
||||
need the SVN configuration information, you should check out directly from
|
||||
SVN. Revision r5447 should equivalent to release 6.24 of NuttX 6.24:
|
||||
|
||||
svn checkout -r5447 svn://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
|
||||
|
||||
Or (HTTP):
|
||||
|
||||
svn checkout -r5447 http://svn.code.sf.net/p/nuttx/code/trunk nuttx-code
|
||||
|
||||
Additional new features and extended functionality:
|
||||
|
||||
* RTOS:
|
||||
|
||||
- Implemented the POSIX pause() function (still has some compiance
|
||||
issues).
|
||||
- Tasking logic is extended to support the notion of address
|
||||
environments. An address environment is the key notion underlying
|
||||
"process" vs. tasks. If tasks are created with address environments
|
||||
(by binfmt), the OS will propogate that environment to child threads
|
||||
and will destroy the address environment when the "process" exists.
|
||||
- If support for the PATH variable is enabled, the OS start up logic
|
||||
will create an initial environment containing the default PATH
|
||||
setting (CONFIG_PATH_INITIAL). This initial PATH will then be
|
||||
inherited by all tasks.
|
||||
|
||||
* Binfmt
|
||||
|
||||
- The NuttX binary loaders have been updated to support the PATH
|
||||
environment variable. Now, if the PATH is properly defined, programs
|
||||
can be executed from mass storage using only the file name. This
|
||||
feature is added to support more standard behavior (eventually, NSH
|
||||
will support execution of programs in file systems by just entering
|
||||
the file name, perhaps in 6.25?).
|
||||
- The NXFLAT and ELF binary loaders have been extended to create
|
||||
address environments for any new tasks executed from the file system.
|
||||
This feature requires that the architecture support a memory management
|
||||
unit (MMU) and the address environment interfaces declared in
|
||||
include/nuttx/arch.h (currently, this is only supported by the z180).
|
||||
|
||||
* Drivers: LCD driver for the Univision UG-2864AMBAG01 OLED
|
||||
|
||||
* STM32: Support for STM32F100 high density chips contributed by Freddie
|
||||
Chopin.
|
||||
|
||||
* STM32 Drivers: Added optional RS-485 direction bit control (from
|
||||
Freddie Chopin).
|
||||
|
||||
* STM32 Boards:
|
||||
|
||||
- Support for generic STM32F100RC board contributed by Freddie Chopin.
|
||||
- stm32f4discovery/nxlines: STM32F4Discovery support for the
|
||||
UG-2864AMBAG01 OLED.
|
||||
- stm32f4discovery/winbuild: A version of the NuttX OS test
|
||||
configured to build natively on Windows.
|
||||
- stm32f4discovery/elf: Now uses the PATH variable to find ELF
|
||||
executables.
|
||||
- configs/cloudctrl: Added for Darcy Gong's CloudController board
|
||||
|
||||
* PIC32 Boards: Update the Mirtool configuration for Release 2 of the
|
||||
Mirtoo module.
|
||||
|
||||
* Calypso: Add Calypso keypad driver. From Denis Cariki.
|
||||
|
||||
* ZiLOG:
|
||||
|
||||
- Add support for the z180 chip family and, specifically, for
|
||||
the P112 retro hardware (see http://p112.feedle.net/).
|
||||
- All ZiLOG configurations updated to use the current ZDS-II
|
||||
and/or SDCC toolchains.
|
||||
|
||||
* Graphics:
|
||||
|
||||
- Add a semaphore handshake so that operations on buffers from
|
||||
the NXMU client will be blocked until the NX server operates on the
|
||||
buffer data (from Petteri Aimonen).
|
||||
- nxtk_subwindowmove() and nxtk_getwindow(): Improvements to clipping
|
||||
logic from Petteri Aimonen.
|
||||
|
||||
* C Library: lib/ sub-directory renamed libc/ (there is a new lib/ sub-
|
||||
directory that is used to hold all archives).
|
||||
|
||||
* C++: Exception stubs from Petteri Aimonen.
|
||||
|
||||
* Applications:
|
||||
|
||||
- Add NSH hexdump command to dump the contents of a file (or character
|
||||
device) to the console (contributed by Petteri Aimonen).
|
||||
- Extend the NSH ifconfig command plus various DHCPC improvements
|
||||
(from Darcy Gong).
|
||||
|
||||
* apps/examples:
|
||||
|
||||
- ostest: Replace large tables with algorithmic prime number
|
||||
generation. This allows the roundrobin test to run on platforms
|
||||
with minimal SRAM (Freddie Chopin).
|
||||
- keypadtest: A new keypad test example contributed by Denis Carikli.
|
||||
- elf and nxflat: If CONFIG_BINFMT_EXEPATH is defined, these examples
|
||||
will now use a relative path to the program and expect the binfmt/
|
||||
logic to find the absolute path to the program using the PATH
|
||||
variable.
|
||||
|
||||
* Build system:
|
||||
|
||||
- New top-level Makefiles: Makefile.unix and Makefile.win (along with
|
||||
numerous changes to other make-related files). This adds basic
|
||||
support for building NuttX natively under Windows from a CMD.exe
|
||||
window (rather than in a POSIX-like environment). This build: (1)
|
||||
Uses all Windows style paths, (2) Uses primarily Windows batch
|
||||
commands from cmd.exe, with (3) a few extensions from GNUWin32.
|
||||
|
||||
This capability should still be considered a work in progress
|
||||
because: (1) it has not been verfied on all targets and tools,
|
||||
and (2) still lacks some of the creature-comforts of the more
|
||||
mature environments (like a function configure.sh script and
|
||||
'make menuconfig' support).
|
||||
|
||||
- Example Windows native builds for STM32F4Discovery, eZ80, z16f, z8,
|
||||
Z80, and Z180.
|
||||
- Several configurations have been converted to work the kconfig-
|
||||
frontends mconf configuration tool: stm32f4discovery/nxlines, and
|
||||
all eZ80, z16f, z8, Z80, and Z180 configurations.
|
||||
- Architectures now include a common Toolchain.defs file that can be
|
||||
used to manage toolchains in a more configurable way (most of this
|
||||
contributed by Mike Smith).
|
||||
|
||||
* Build tools:
|
||||
|
||||
- Renamed tools/winlink.sh to tools/copydir.sh.
|
||||
- Several new tools/scripts to support the Windows native build:
|
||||
tools/mkdeps.bat, tools/mkdeps.c, tools/link.bat, unlink.bat, and
|
||||
copydir.bat.
|
||||
- tools/incdir.sh and incdir.bat now support an -s option to generate
|
||||
system header file paths.
|
||||
- tools/b16.c: Fixed precision math conversion utility.
|
||||
|
||||
Bugfixes (see the change log for details). Some of these are very important
|
||||
(marked *critical*):
|
||||
|
||||
* RTOS: Fix some backward conditional compilation in the work queue
|
||||
logic (Freddie Chopin).
|
||||
|
||||
* File System: Uninitialized variable caused assertions (from Lorenz
|
||||
Meier).
|
||||
|
||||
* Drivers: Partial fix for STM32 OTGFS device drivers and fix for short,
|
||||
unaligned writes in the flash translation layer (drivers/mtd/ftl.c),
|
||||
both from Petteri Aimonen.
|
||||
|
||||
* STM32 Drivers:
|
||||
|
||||
- Qencoder driver and TIM3 driver fixes from Ryan Sundberg.
|
||||
- Fix timeout delay calculation in the STM32 OTG FS host driver.
|
||||
|
||||
* LPC17xx Drivers: Resources not being properly released when I2C
|
||||
driver is un-initialized.
|
||||
|
||||
* Graphics:
|
||||
|
||||
- Fix logic when the mouse drags outside of the window; fix
|
||||
another "blocked message" handling case (both from Petteri Aimonen).
|
||||
- nxtk_filltrapwindow(): Correct an offset problem (also from Peterri
|
||||
Aimonen).
|
||||
- nxglib_splitline(): Correct the "fat flat line" bug.
|
||||
|
||||
* C Library:
|
||||
|
||||
- nrand() changes to prevent coefficients from becoming zero which
|
||||
would "lock up" the random number generate.
|
||||
- Add rounding functions to the math library (contributed by Petteri
|
||||
Aimonen).
|
||||
|
||||
* Build system: Changes to MIN definitions in all limit.h header files
|
||||
to avoid integer overflows. For example from (-128) to (-127 - 1)
|
||||
(from Petteri Aimonen).
|
||||
|
||||
* Applications: Modbus fixes from Freddie Chopin.
|
||||
|
||||
As well as other, less critical bugs (see the ChangeLog for details)
|
||||
|
||||
+82
-15
@@ -1,4 +1,4 @@
|
||||
NuttX TODO List (Last updated September 16, 2012)
|
||||
NuttX TODO List (Last updated November 25, 2012)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
This file summarizes known NuttX bugs, limitations, inconsistencies with
|
||||
@@ -20,7 +20,7 @@ nuttx/
|
||||
(5) Graphics subystem (graphics/)
|
||||
(1) Pascal add-on (pcode/)
|
||||
(1) Documentation (Documentation/)
|
||||
(6) Build system / Toolchains
|
||||
(8) Build system / Toolchains
|
||||
(5) Linux/Cywgin simulation (arch/sim)
|
||||
(6) ARM (arch/arm/)
|
||||
(1) ARM/C5471 (arch/arm/src/c5471/)
|
||||
@@ -35,12 +35,12 @@ nuttx/
|
||||
(7) ARM/STM32 (arch/arm/src/stm32/)
|
||||
(3) AVR (arch/avr)
|
||||
(0) Intel x86 (arch/x86)
|
||||
(4) 8051 / MCS51 (arch/8051/)
|
||||
(5) 8051 / MCS51 (arch/8051/)
|
||||
(3) MIPS/PIC32 (arch/mips)
|
||||
(1) Hitachi/Renesas SH-1 (arch/sh/src/sh1)
|
||||
(4) Renesas M16C/26 (arch/sh/src/m16c)
|
||||
(10) z80/z8/ez80 (arch/z80/)
|
||||
(8) z16 (arch/z16/)
|
||||
(9) z16 (arch/z16/)
|
||||
(1) mc68hc1x (arch/hc)
|
||||
|
||||
apps/
|
||||
@@ -890,23 +890,30 @@ o Build system
|
||||
Description: Need a NuttX configuration tool. The number of configuration
|
||||
settings has become quite large and difficult to manage manually.
|
||||
Update: This task is essentially completed. But probably not for
|
||||
all platforms and all features. When do we know that the the
|
||||
features is complete and that we can switch to exclusive use of
|
||||
the tool?
|
||||
all platforms and all features. When do we know that the feature
|
||||
is complete and that we can switch to exclusive use of the tool?
|
||||
Status: Open
|
||||
Priority: Medium-low
|
||||
|
||||
Title: NATIVE WINDOWS BUILD
|
||||
Description: At present, NuttX builds only under Linux or Cygwin.
|
||||
Investigate the possibility of a native Windows build using
|
||||
something like the GNUWin32 tools (coreutils+make+grep+sed+uname).
|
||||
Description: This effort is underway using MinGW-GCC and GNUWin32 tools
|
||||
for (coreutils+make+grep+sed+uname). Current status:
|
||||
|
||||
1. configs/stm32f4discovery/winbuild - builds okay natively
|
||||
2. configs/ez80f910200kitg - Can be reconfigured to build natively.
|
||||
Requires some manual intervention to get a clean build.
|
||||
See configs/ez80f910200kitg/README.txt.
|
||||
|
||||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
Title: WINDOWS DEPENDENCY GENERATION
|
||||
Description: Dependency generation is currently disabled when a Windows native
|
||||
toolchain is used. I think that the only issue is that all of the
|
||||
Windows dependencies needed to be quoted in the Make.dep files.
|
||||
toolchain is used in a POSIX-like enviornment (like Cygwin). The
|
||||
issue is that the Windows tool generates dependencies use Windows
|
||||
path formatting and this fails with the dependency file (Make.dep)
|
||||
is include). Perhaps the only issue is that all of the Windows
|
||||
dependencies needed to be quoted in the Make.dep files.
|
||||
Status: Open
|
||||
Priority: Low -- unless some dependency-related build issues is discovered.
|
||||
|
||||
@@ -962,6 +969,48 @@ o Build system
|
||||
Priority: Low -- the kernel build configuration is not fully fielded
|
||||
yet.
|
||||
|
||||
Title: mconf NOT AVAILABLE IN NATIVE WINDOWS BUILD
|
||||
Description: NuttX is migrating to the use of the kconfig-frontends mconf
|
||||
tool for all configurations. In NuttX 6.24, support for native
|
||||
Windows builds was added. However, the mconf tool does not
|
||||
build to run natively under Windows.
|
||||
|
||||
Some effort was spent trying to get a clean mconf build under
|
||||
Windows. This is documented in the message thread beginning
|
||||
here: http://tech.groups.yahoo.com/group/nuttx/message/2900.
|
||||
The build was successfully completed using: MinGW-GCC, MSYS,
|
||||
additional Windows libraries, and additional MSYS libraries
|
||||
(MSYS is a variant of Cygwin so, presumeably, Cygwin could
|
||||
have been used as well). However, on final testing, it was
|
||||
found that there are problems with text and numeric entry:
|
||||
http://tech.groups.yahoo.com/group/nuttx/message/2953. This
|
||||
was considered a show stopper and the changs were not checked
|
||||
in.
|
||||
|
||||
Options: (1) Use conf (not mconf). confis the text-only
|
||||
configuration tool, (2) fix mconf, (3) write another variant
|
||||
of the configuration tool for windows, or (4) do all configuration
|
||||
under Cygwin or MSYS. I am doing (4) now, but this is very
|
||||
awkward because I have to set the apps path to ../apps (vs
|
||||
..\apps) and CONFIG_WINDOWS_NATIVE=n for the 'make menuconfig'
|
||||
to run error free under windows. Very awkward!
|
||||
Status: Open, there are some workarounds, but none are good.
|
||||
Priority: High
|
||||
|
||||
Title: configure.sh NOT AVAILABLE IN NATIVE WINDOWS BUILD
|
||||
Description: configure.sh is a Bash script and cannot be used from a Windows
|
||||
CMD.exe window. I started a configure.bat script, but I do
|
||||
not have the batch file programming skills to duplicate some
|
||||
of the more complex operations.
|
||||
|
||||
I also considered adding a configure.c file that could be
|
||||
compiled and then executed by configure.bat (and configure.sh?).
|
||||
But I have not gone down that path yet.
|
||||
|
||||
The current work-around is to configure under Cygwin.
|
||||
Status: Open
|
||||
Priority: High
|
||||
|
||||
o Linux/Cywgin simulation (arch/sim)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
@@ -1507,6 +1556,16 @@ o 8051 / MCS51 (arch/8051/)
|
||||
Status: Open
|
||||
Priority: Low -- only because there as so many other issues with 8051
|
||||
|
||||
Title: 8051 BUILD BROKEN
|
||||
Description: The last time I tried to build the pjrc-8051 configurtion using
|
||||
the SDCC 3.2.1 toolchain (for Windows). I got compilation
|
||||
errors in sched/os_bringup.c. It complained about type
|
||||
mis-matches. What I gather from Googling, this is a problem
|
||||
with the --stack-auto option. At any rate, this problem will
|
||||
need to be fixed if you want to resurrect the 8051 NuttX port.
|
||||
Status: Open
|
||||
Priority: Low -- I don't think anyone uses the 8051 port.
|
||||
|
||||
o MIPS/PIC32(arch/mips)
|
||||
^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
@@ -1835,9 +1894,17 @@ o z16 (arch/z16)
|
||||
Internal Error(0503) On line 2504 of "MMCSD\MMCSD_SDIO.C"
|
||||
File <c3>, Args(562,46)
|
||||
|
||||
Status: Open. Recommended workaround: remove mmcsd_sdio.c from
|
||||
drivers/mmcsd/Make.defs. There is no SDIO support for the Z16 anyway
|
||||
Priority: Low
|
||||
Status: Open. Recommended workaround: remove mmcsd_sdio.c from
|
||||
drivers/mmcsd/Make.defs. There is no SDIO support for the Z16 anyway
|
||||
Priority: Low
|
||||
|
||||
Title: NATIVE BUILD PROBLEMS
|
||||
Description: When last tested (ca.12/12), there were some missing .obj files in
|
||||
arch/z16/src. A little additional TLC will be needed to get a
|
||||
reliable Windows native build. As of this writing, the Cygwin
|
||||
based build has not been re-verified.
|
||||
Status: Open
|
||||
Priority: Low -- I don't think anyone uses the Z16 port.
|
||||
|
||||
o mc68hc1x (arch/hc)
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
@@ -9,6 +9,7 @@ choice
|
||||
|
||||
config ARCH_8051
|
||||
bool "8051"
|
||||
select CUSTOM_STACK
|
||||
---help---
|
||||
Intel 8051 architectures and derivaties
|
||||
|
||||
@@ -111,12 +112,30 @@ config ARCH_DMA
|
||||
bool
|
||||
default n
|
||||
|
||||
config ARCH_IRQPRIO
|
||||
bool
|
||||
default n
|
||||
|
||||
config CUSTOM_STACK
|
||||
bool
|
||||
default n
|
||||
|
||||
config ADDRENV
|
||||
bool
|
||||
default n
|
||||
|
||||
config ARCH_STACKDUMP
|
||||
bool "Dump stack on assertions"
|
||||
default n
|
||||
---help---
|
||||
Enable to do stack dumps after assertions
|
||||
|
||||
config ENDIAN_BIG
|
||||
bool "Big Endian Architecture"
|
||||
default n
|
||||
---help---
|
||||
Select if architecture operates using big-endian byte ordering.
|
||||
|
||||
comment "Board Settings"
|
||||
|
||||
config BOARD_LOOPSPERMSEC
|
||||
|
||||
+26
-6
@@ -4,6 +4,8 @@
|
||||
#
|
||||
|
||||
if ARCH_ARM
|
||||
comment "ARM Options"
|
||||
|
||||
choice
|
||||
prompt "ARM chip selection"
|
||||
default ARCH_CHIP_STM32
|
||||
@@ -44,6 +46,7 @@ config ARCH_CHIP_KINETIS
|
||||
bool "Freescale Kinetis"
|
||||
select ARCH_CORTEXM4
|
||||
select ARCH_HAVE_MPU
|
||||
select ARCH_IRQPRIO
|
||||
---help---
|
||||
Freescale Kinetis Architectures (ARM Cortex-M4)
|
||||
|
||||
@@ -51,6 +54,7 @@ config ARCH_CHIP_LM3S
|
||||
bool "TI Stellaris"
|
||||
select ARCH_CORTEXM3
|
||||
select ARCH_HAVE_MPU
|
||||
select ARCH_IRQPRIO
|
||||
---help---
|
||||
TI Stellaris LMS3 architecutres (ARM Cortex-M3)
|
||||
|
||||
@@ -58,6 +62,7 @@ config ARCH_CHIP_LPC17XX
|
||||
bool "NXP LPC17xx"
|
||||
select ARCH_CORTEXM3
|
||||
select ARCH_HAVE_MPU
|
||||
select ARCH_IRQPRIO
|
||||
---help---
|
||||
NXP LPC17xx architectures (ARM Cortex-M3)
|
||||
|
||||
@@ -89,6 +94,7 @@ config ARCH_CHIP_LPC43XX
|
||||
select ARCH_HAVE_CMNVECTOR
|
||||
select ARMV7M_CMNVECTOR
|
||||
select ARCH_HAVE_MPU
|
||||
select ARCH_IRQPRIO
|
||||
---help---
|
||||
NPX LPC43XX architectures (ARM Cortex-M4).
|
||||
|
||||
@@ -96,6 +102,7 @@ config ARCH_CHIP_SAM3U
|
||||
bool "Atmel AT91SAM3U"
|
||||
select ARCH_CORTEXM3
|
||||
select ARCH_HAVE_MPU
|
||||
select ARCH_IRQPRIO
|
||||
---help---
|
||||
Atmel AT91SAM3U architectures (ARM Cortex-M3)
|
||||
|
||||
@@ -104,6 +111,7 @@ config ARCH_CHIP_STM32
|
||||
select ARCH_HAVE_CMNVECTOR
|
||||
select ARCH_HAVE_MPU
|
||||
select ARCH_HAVE_I2CRESET
|
||||
select ARCH_IRQPRIO
|
||||
---help---
|
||||
STMicro STM32 architectures (ARM Cortex-M3/4).
|
||||
|
||||
@@ -153,6 +161,9 @@ config ARCH_CHIP
|
||||
default "stm32" if ARCH_CHIP_STM32
|
||||
default "str71x" if ARCH_CHIP_STR71X
|
||||
|
||||
config ARCH_HAVE_CMNVECTOR
|
||||
bool
|
||||
|
||||
config ARMV7M_CMNVECTOR
|
||||
bool "Use common ARMv7-M vectors"
|
||||
default n
|
||||
@@ -217,12 +228,6 @@ config PAGING
|
||||
If set =y in your configation file, this setting will enable the on-demand
|
||||
paging feature as described in http://www.nuttx.org/NuttXDemandPaging.html.
|
||||
|
||||
config ARCH_IRQPRIO
|
||||
bool "Interrupt priority"
|
||||
default y if ARCH_CORTEXM3 || ARCH_CORTEXM4
|
||||
---help---
|
||||
Select if your board supports interrupt prioritization.
|
||||
|
||||
config BOARD_LOOPSPERMSEC
|
||||
int "Delay loops per millisecond"
|
||||
default 5000
|
||||
@@ -239,6 +244,21 @@ config ARCH_CALIBRATION
|
||||
watch to measure the 100 second delay then adjust BOARD_LOOPSPERMSEC until
|
||||
the delay actually is 100 seconds.
|
||||
|
||||
config DEBUG_HARDFAULT
|
||||
bool "Verbose Hard-Fault Debug"
|
||||
default n
|
||||
depends on DEBUG && (ARCH_CORTEXM3 || ARCH_CORTEXM4)
|
||||
---help---
|
||||
Enables verbose debug output when a hard fault is occurs. This verbose
|
||||
output is sometimes helpful when debugging difficult hard fault problems,
|
||||
but may be more than you typcially want to see.
|
||||
|
||||
if ARCH_CORTEXM3 || ARCH_CORTEXM4
|
||||
source arch/arm/src/armv7-m/Kconfig
|
||||
endif
|
||||
if ARCH_ARM7TDMI || ARCH_ARM926EJS
|
||||
source arch/arm/src/arm/Kconfig
|
||||
endif
|
||||
if ARCH_CHIP_C5471
|
||||
source arch/arm/src/c5471/Kconfig
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,266 @@
|
||||
############################################################################
|
||||
# arch/arm/src/armv7-m/Toolchain.defs
|
||||
#
|
||||
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
# Setup for the selected toolchain
|
||||
|
||||
#
|
||||
# Handle old-style chip-specific toolchain names in the absence of
|
||||
# a new-style toolchain specification, force the selection of a single
|
||||
# toolchain and allow the selected toolchain to be overridden by a
|
||||
# command-line selection.
|
||||
#
|
||||
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_LPC43_ATOLLIC_LITE) \
|
||||
$(CONFIG_STM32_ATOLLIC_LITE) \
|
||||
$(CONFIG_LPC43_ATOLLIC_PRO) \
|
||||
$(CONFIG_STM32_ATOLLIC_PRO) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_ATOLLIC) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= ATOLLIC
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_KINETIS_BUILDROOT) \
|
||||
$(CONFIG_LM3S_BUILDROOT) \
|
||||
$(CONFIG_LPC17_BUILDROOT) \
|
||||
$(CONFIG_LPC43_BUILDROOT) \
|
||||
$(CONFIG_SAM3U_BUILDROOT) \
|
||||
$(CONFIG_STM32_BUILDROOT) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_BUILDROOT) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= BUILDROOT
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_LPC17_CODEREDL) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_CODEREDL) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= CODEREDL
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_LPC17_CODEREDW) \
|
||||
$(CONFIG_LPC43_CODEREDW) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_CODEREDW) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= CODEREDW
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_KINETIS_CODESOURCERYL) \
|
||||
$(CONFIG_LM3S_CODESOURCERYL) \
|
||||
$(CONFIG_LPC17_CODESOURCERYL) \
|
||||
$(CONFIG_LPC43_CODESOURCERYL) \
|
||||
$(CONFIG_SAM3U_CODESOURCERYL) \
|
||||
$(CONFIG_STM32_CODESOURCERYL) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYL) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= CODESOURCERYL
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_KINETIS_CODESOURCERYW) \
|
||||
$(CONFIG_LM3S_CODESOURCERYW) \
|
||||
$(CONFIG_LPC17_CODESOURCERYW) \
|
||||
$(CONFIG_LPC43_CODESOURCERYW) \
|
||||
$(CONFIG_SAM3U_CODESOURCERYW) \
|
||||
$(CONFIG_STM32_CODESOURCERYW) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= CODESOURCERYW
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_KINETIS_DEVKITARM) \
|
||||
$(CONFIG_LM3S_DEVKITARM) \
|
||||
$(CONFIG_LPC17_DEVKITARM) \
|
||||
$(CONFIG_LPC43_DEVKITARM) \
|
||||
$(CONFIG_SAM3U_DEVKITARM) \
|
||||
$(CONFIG_STM32_DEVKITARM) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_DEVKITARM) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= DEVKITARM
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_GNU_EABI) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= GNU_EABI
|
||||
endif
|
||||
ifeq ($(filter y, \
|
||||
$(CONFIG_STM32_RAISONANCE) \
|
||||
$(CONFIG_ARMV7M_TOOLCHAIN_RAISONANCE) \
|
||||
),y)
|
||||
CONFIG_ARMV7M_TOOLCHAIN ?= RAISONANCE
|
||||
endif
|
||||
|
||||
#
|
||||
# Supported toolchains
|
||||
#
|
||||
# TODO - It's likely that all of these toolchains now support the
|
||||
# CortexM4. Since they are all GCC-based, we could almost
|
||||
# certainly simplify this further.
|
||||
#
|
||||
# Each toolchain definition should set:
|
||||
#
|
||||
# CROSSDEV The GNU toolchain triple (command prefix)
|
||||
# ARCROSSDEV If required, an alternative prefix used when
|
||||
# invoking ar and nm.
|
||||
# ARCHCPUFLAGS CPU-specific flags selecting the instruction set
|
||||
# FPU options, etc.
|
||||
# MAXOPTIMIZATION The maximum optimization level that results in
|
||||
# reliable code generation.
|
||||
#
|
||||
|
||||
# Atollic toolchain under Windows
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),ATOLLIC)
|
||||
CROSSDEV = arm-atollic-eabi-
|
||||
ARCROSSDEV = arm-atollic-eabi-
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
WINTOOL = y
|
||||
endif
|
||||
ifeq ($(CONFIG_ARCH_CORTEXM4),y)
|
||||
ifeq ($(CONFIG_ARCH_FPU),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||
else
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
|
||||
endif
|
||||
else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
endif
|
||||
|
||||
# NuttX buildroot under Linux or Cygwin
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),BUILDROOT)
|
||||
# OABI
|
||||
# CROSSDEV = arm-nuttx-elf-
|
||||
# ARCROSSDEV = arm-nuttx-elf-
|
||||
# ARCHCPUFLAGS = -mtune=cortex-m3 -march=armv7-m -mfloat-abi=soft
|
||||
# EABI
|
||||
CROSSDEV = arm-nuttx-eabi-
|
||||
ARCROSSDEV = arm-nuttx-eabi-
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
MAXOPTIMIZATION = -Os
|
||||
endif
|
||||
|
||||
# Code Red RedSuite under Linux
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODEREDL)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
ifeq ($(CONFIG_ARCH_CORTEXM4),y)
|
||||
ifeq ($(CONFIG_ARCH_FPU),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||
else
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
|
||||
endif
|
||||
else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
endif
|
||||
|
||||
# Code Red RedSuite under Windows
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODEREDW)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
WINTOOL = y
|
||||
endif
|
||||
ifeq ($(CONFIG_ARCH_CORTEXM4),y)
|
||||
ifeq ($(CONFIG_ARCH_FPU),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||
else
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
|
||||
endif
|
||||
else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
endif
|
||||
|
||||
# CodeSourcery under Linux
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODESOURCERYL)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
MAXOPTIMIZATION = -O2
|
||||
endif
|
||||
|
||||
# CodeSourcery under Windows
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),CODESOURCERYW)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
WINTOOL = y
|
||||
endif
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
|
||||
# devkitARM under Windows
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),DEVKITARM)
|
||||
CROSSDEV = arm-eabi-
|
||||
ARCROSSDEV = arm-eabi-
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
WINTOOL = y
|
||||
endif
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
|
||||
# Generic GNU EABI toolchain on OS X, Linux or any typical Posix system
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),GNU_EABI)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
MAXOPTIMIZATION = -O3
|
||||
ifeq ($(CONFIG_ARCH_CORTEXM4),y)
|
||||
ifeq ($(CONFIG_ARCH_FPU),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
|
||||
else
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfloat-abi=soft
|
||||
endif
|
||||
else ifeq ($(CONFIG_ARCH_CORTEXM3),y)
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
endif
|
||||
|
||||
# Raisonance RIDE7 under Windows
|
||||
|
||||
ifeq ($(CONFIG_ARMV7M_TOOLCHAIN),RAISONANCE)
|
||||
CROSSDEV = arm-none-eabi-
|
||||
ARCROSSDEV = arm-none-eabi-
|
||||
ifneq ($(CONFIG_WINDOWS_NATIVE),y)
|
||||
WINTOOL = y
|
||||
endif
|
||||
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
|
||||
endif
|
||||
@@ -134,9 +134,9 @@ exception_common:
|
||||
|
||||
#if CONFIG_ARCH_INTERRUPTSTACK > 3
|
||||
ldr sp, =g_intstackbase
|
||||
push r1 /* Save the MSP on the interrupt stack */
|
||||
push {r1} /* Save the MSP on the interrupt stack */
|
||||
bl up_doirq /* R0=IRQ, R1=register save area on stack */
|
||||
pop r1 /* Recover R1=main stack pointer */
|
||||
pop {r1} /* Recover R1=main stack pointer */
|
||||
#else
|
||||
msr msp, r1 /* We are using the main stack pointer */
|
||||
bl up_doirq /* R0=IRQ, R1=register save area on stack */
|
||||
|
||||
@@ -599,6 +599,15 @@ config STM32_ETH_REMAP
|
||||
|
||||
endmenu
|
||||
|
||||
config STM32_FLASH_PREFETCH
|
||||
bool "Enable FLASH Pre-fetch"
|
||||
depends on STM32_STM32F20XX || STM32_STM32F40XX
|
||||
default n
|
||||
---help---
|
||||
Enable FLASH prefetch and F2 and F4 parts (FLASH pre-fetch is always enabled
|
||||
on F1 parts). Some early revisions of F4 parts do not support FLASH pre-fetch
|
||||
properly and enabling this option may interfere with ADC accuracy.
|
||||
|
||||
choice
|
||||
prompt "JTAG Configuration"
|
||||
default STM32_JTAG_DISABLE
|
||||
|
||||
@@ -110,6 +110,7 @@
|
||||
# define FLASH_ACR_HLFCYA (1 << 3) /* FLASH half cycle access */
|
||||
# define FLASH_ACR_PRTFBE (1 << 4) /* FLASH prefetch enable */
|
||||
#elif defined(CONFIG_STM32_STM32F20XX) || defined(CONFIG_STM32_STM32F40XX)
|
||||
# define FLASH_ACR_PRFTEN (1 << 8) /* FLASH prefetch enable */
|
||||
# define FLASH_ACR_ICEN (1 << 9) /* Bit 9: Instruction cache enable */
|
||||
# define FLASH_ACR_DCEN (1 << 10) /* Bit 10: Data cache enable */
|
||||
# define FLASH_ACR_ICRST (1 << 11) /* Bit 11: Instruction cache reset */
|
||||
|
||||
@@ -51,6 +51,7 @@
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/clock.h>
|
||||
#include <nuttx/usb/usb.h>
|
||||
#include <nuttx/usb/usbhost.h>
|
||||
|
||||
@@ -149,8 +150,8 @@
|
||||
|
||||
#define STM32_READY_DELAY 200000 /* In loop counts */
|
||||
#define STM32_FLUSH_DELAY 200000 /* In loop counts */
|
||||
#define STM32_SETUP_DELAY 5000 /* In frames */
|
||||
#define STM32_DATANAK_DELAY 5000 /* In frames */
|
||||
#define STM32_SETUP_DELAY (5000 / MSEC_PER_TICK) /* 5 seconds in system ticks */
|
||||
#define STM32_DATANAK_DELAY (5000 / MSEC_PER_TICK) /* 5 seconds in system ticks */
|
||||
|
||||
/* Ever-present MIN/MAX macros */
|
||||
|
||||
@@ -305,7 +306,9 @@ static void stm32_chan_wakeup(FAR struct stm32_usbhost_s *priv,
|
||||
/* Control/data transfer logic *************************************************/
|
||||
|
||||
static void stm32_transfer_start(FAR struct stm32_usbhost_s *priv, int chidx);
|
||||
#if 0 /* Not used */
|
||||
static inline uint16_t stm32_getframe(void);
|
||||
#endif
|
||||
static int stm32_ctrl_sendsetup(FAR struct stm32_usbhost_s *priv,
|
||||
FAR const struct usb_ctrlreq_s *req);
|
||||
static int stm32_ctrl_senddata(FAR struct stm32_usbhost_s *priv,
|
||||
@@ -1182,14 +1185,18 @@ static void stm32_transfer_start(FAR struct stm32_usbhost_s *priv, int chidx)
|
||||
* Name: stm32_getframe
|
||||
*
|
||||
* Description:
|
||||
* Get the current frame number.
|
||||
* Get the current frame number. The frame number (FRNUM) field increments
|
||||
* when a new SOF is transmitted on the USB, and is cleared to 0 when it
|
||||
* reaches 0x3fff.
|
||||
*
|
||||
*******************************************************************************/
|
||||
|
||||
#if 0 /* Not used */
|
||||
static inline uint16_t stm32_getframe(void)
|
||||
{
|
||||
return (uint16_t)(stm32_getreg(STM32_OTGFS_HFNUM) & OTGFS_HFNUM_FRNUM_MASK);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
* Name: stm32_ctrl_sendsetup
|
||||
@@ -1203,14 +1210,14 @@ static int stm32_ctrl_sendsetup(FAR struct stm32_usbhost_s *priv,
|
||||
FAR const struct usb_ctrlreq_s *req)
|
||||
{
|
||||
FAR struct stm32_chan_s *chan;
|
||||
uint16_t start;
|
||||
uint16_t elapsed;
|
||||
uint32_t start;
|
||||
uint32_t elapsed;
|
||||
int ret;
|
||||
|
||||
/* Loop while the device reports NAK (and a timeout is not exceeded */
|
||||
|
||||
chan = &priv->chan[priv->ep0out];
|
||||
start = stm32_getframe();
|
||||
start = clock_systimer();
|
||||
|
||||
do
|
||||
{
|
||||
@@ -1258,7 +1265,7 @@ static int stm32_ctrl_sendsetup(FAR struct stm32_usbhost_s *priv,
|
||||
|
||||
/* Get the elapsed time (in frames) */
|
||||
|
||||
elapsed = stm32_getframe() - start;
|
||||
elapsed = clock_systimer() - start;
|
||||
}
|
||||
while (elapsed < STM32_SETUP_DELAY);
|
||||
|
||||
@@ -1367,8 +1374,8 @@ static int stm32_in_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
|
||||
FAR uint8_t *buffer, size_t buflen)
|
||||
{
|
||||
FAR struct stm32_chan_s *chan;
|
||||
uint16_t start;
|
||||
uint16_t elapsed;
|
||||
uint32_t start;
|
||||
uint32_t elapsed;
|
||||
int ret = OK;
|
||||
|
||||
/* Loop until the transfer completes (i.e., buflen is decremented to zero)
|
||||
@@ -1379,7 +1386,7 @@ static int stm32_in_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
|
||||
chan->buffer = buffer;
|
||||
chan->buflen = buflen;
|
||||
|
||||
start = stm32_getframe();
|
||||
start = clock_systimer();
|
||||
while (chan->buflen > 0)
|
||||
{
|
||||
/* Set up for the wait BEFORE starting the transfer */
|
||||
@@ -1447,7 +1454,7 @@ static int stm32_in_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
|
||||
* buffer pointer and buffer size will be unaltered.
|
||||
*/
|
||||
|
||||
elapsed = stm32_getframe() - start;
|
||||
elapsed = clock_systimer() - start;
|
||||
if (ret != -EAGAIN || /* Not a NAK condition OR */
|
||||
elapsed >= STM32_DATANAK_DELAY || /* Timeout has elapsed OR */
|
||||
chan->buflen != buflen) /* Data has been partially transferred */
|
||||
@@ -1474,8 +1481,8 @@ static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
|
||||
FAR uint8_t *buffer, size_t buflen)
|
||||
{
|
||||
FAR struct stm32_chan_s *chan;
|
||||
uint16_t start;
|
||||
uint16_t elapsed;
|
||||
uint32_t start;
|
||||
uint32_t elapsed;
|
||||
size_t xfrlen;
|
||||
int ret = OK;
|
||||
|
||||
@@ -1484,7 +1491,7 @@ static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
|
||||
*/
|
||||
|
||||
chan = &priv->chan[chidx];
|
||||
start = stm32_getframe();
|
||||
start = clock_systimer();
|
||||
|
||||
while (buflen > 0)
|
||||
{
|
||||
@@ -1569,7 +1576,7 @@ static int stm32_out_transfer(FAR struct stm32_usbhost_s *priv, int chidx,
|
||||
* buffer pointer and buffer size will be unaltered.
|
||||
*/
|
||||
|
||||
elapsed = stm32_getframe() - start;
|
||||
elapsed = clock_systimer() - start;
|
||||
if (ret != -EAGAIN || /* Not a NAK condition OR */
|
||||
elapsed >= STM32_DATANAK_DELAY || /* Timeout has elapsed OR */
|
||||
chan->buflen != xfrlen) /* Data has been partially transferred */
|
||||
@@ -3540,8 +3547,8 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr,
|
||||
{
|
||||
struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr;
|
||||
uint16_t buflen;
|
||||
uint16_t start;
|
||||
uint16_t elapsed;
|
||||
uint32_t start;
|
||||
uint32_t elapsed;
|
||||
int retries;
|
||||
int ret;
|
||||
|
||||
@@ -3573,7 +3580,7 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr,
|
||||
|
||||
/* Get the start time. Loop again until the timeout expires */
|
||||
|
||||
start = stm32_getframe();
|
||||
start = clock_systimer();
|
||||
do
|
||||
{
|
||||
/* Handle the IN data phase (if any) */
|
||||
@@ -3606,7 +3613,7 @@ static int stm32_ctrlin(FAR struct usbhost_driver_s *drvr,
|
||||
|
||||
/* Get the elapsed time (in frames) */
|
||||
|
||||
elapsed = stm32_getframe() - start;
|
||||
elapsed = clock_systimer() - start;
|
||||
}
|
||||
while (elapsed < STM32_DATANAK_DELAY);
|
||||
}
|
||||
@@ -3623,8 +3630,8 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr,
|
||||
{
|
||||
struct stm32_usbhost_s *priv = (struct stm32_usbhost_s *)drvr;
|
||||
uint16_t buflen;
|
||||
uint16_t start;
|
||||
uint16_t elapsed;
|
||||
uint32_t start;
|
||||
uint32_t elapsed;
|
||||
int retries;
|
||||
int ret;
|
||||
|
||||
@@ -3658,7 +3665,7 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr,
|
||||
|
||||
/* Get the start time. Loop again until the timeout expires */
|
||||
|
||||
start = stm32_getframe();
|
||||
start = clock_systimer();
|
||||
do
|
||||
{
|
||||
/* Handle the data OUT phase (if any) */
|
||||
@@ -3693,7 +3700,7 @@ static int stm32_ctrlout(FAR struct usbhost_driver_s *drvr,
|
||||
|
||||
/* Get the elapsed time (in frames) */
|
||||
|
||||
elapsed = stm32_getframe() - start;
|
||||
elapsed = clock_systimer() - start;
|
||||
}
|
||||
while (elapsed < STM32_DATANAK_DELAY);
|
||||
}
|
||||
|
||||
@@ -96,6 +96,19 @@
|
||||
# endif
|
||||
# endif
|
||||
|
||||
/* Currently RS-485 support cannot be enabled when RXDMA is in use due to lack
|
||||
* of testing - RS-485 support was developed on STM32F1x
|
||||
*/
|
||||
|
||||
# if (defined(CONFIG_USART1_RXDMA) && defined(CONFIG_USART1_RS485)) || \
|
||||
(defined(CONFIG_USART2_RXDMA) && defined(CONFIG_USART2_RS485)) || \
|
||||
(defined(CONFIG_USART3_RXDMA) && defined(CONFIG_USART3_RS485)) || \
|
||||
(defined(CONFIG_UART4_RXDMA) && defined(CONFIG_UART4_RS485)) || \
|
||||
(defined(CONFIG_UART5_RXDMA) && defined(CONFIG_UART5_RS485)) || \
|
||||
(defined(CONFIG_USART6_RXDMA) && defined(CONFIG_USART6_RS485))
|
||||
# error "RXDMA and RS-485 cannot be enabled at the same time for the same U[S]ART"
|
||||
# endif
|
||||
|
||||
/* For the F4, there are alternate DMA channels for USART1 and 6.
|
||||
* Logic in the board.h file make the DMA channel selection by defining
|
||||
* the following in the board.h file.
|
||||
@@ -185,15 +198,11 @@ struct up_dev_s
|
||||
uint8_t parity; /* 0=none, 1=odd, 2=even */
|
||||
uint8_t bits; /* Number of bits (7 or 8) */
|
||||
bool stopbits2; /* True: Configure with 2 stop bits instead of 1 */
|
||||
bool iflow; /* input flow control (RTS) enabled */
|
||||
bool oflow; /* output flow control (CTS) enabled */
|
||||
uint32_t baud; /* Configured baud */
|
||||
#else
|
||||
const uint8_t parity; /* 0=none, 1=odd, 2=even */
|
||||
const uint8_t bits; /* Number of bits (7 or 8) */
|
||||
const bool stopbits2; /* True: Configure with 2 stop bits instead of 1 */
|
||||
const bool iflow; /* input flow control (RTS) enabled */
|
||||
const bool oflow; /* output flow control (CTS) enabled */
|
||||
const uint32_t baud; /* Configured baud */
|
||||
#endif
|
||||
|
||||
@@ -219,13 +228,18 @@ struct up_dev_s
|
||||
uint32_t rxdmanext; /* Next byte in the DMA buffer to be read */
|
||||
char *const rxfifo; /* Receive DMA buffer */
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RS485
|
||||
const uint32_t rs485_dir_gpio; /* U[S]ART RS-485 DIR GPIO pin configuration */
|
||||
const bool rs485_dir_polarity; /* U[S]ART RS-485 DIR pin state for TX enabled */
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void up_set_format(struct uart_dev_s *dev);
|
||||
static void up_setspeed(struct uart_dev_s *dev);
|
||||
static int up_setup(struct uart_dev_s *dev);
|
||||
static void up_shutdown(struct uart_dev_s *dev);
|
||||
static int up_attach(struct uart_dev_s *dev);
|
||||
@@ -397,8 +411,6 @@ static struct up_dev_s g_usart1priv =
|
||||
.parity = CONFIG_USART1_PARITY,
|
||||
.bits = CONFIG_USART1_BITS,
|
||||
.stopbits2 = CONFIG_USART1_2STOP,
|
||||
.iflow = false,
|
||||
.oflow = false,
|
||||
.baud = CONFIG_USART1_BAUD,
|
||||
.apbclock = STM32_PCLK2_FREQUENCY,
|
||||
.usartbase = STM32_USART1_BASE,
|
||||
@@ -415,6 +427,15 @@ static struct up_dev_s g_usart1priv =
|
||||
.rxfifo = g_usart1rxfifo,
|
||||
#endif
|
||||
.vector = up_interrupt_usart1,
|
||||
|
||||
#ifdef CONFIG_USART1_RS485
|
||||
.rs485_dir_gpio = GPIO_USART1_RS485_DIR,
|
||||
# if (CONFIG_USART1_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -450,8 +471,6 @@ static struct up_dev_s g_usart2priv =
|
||||
.parity = CONFIG_USART2_PARITY,
|
||||
.bits = CONFIG_USART2_BITS,
|
||||
.stopbits2 = CONFIG_USART2_2STOP,
|
||||
.iflow = false,
|
||||
.oflow = false,
|
||||
.baud = CONFIG_USART2_BAUD,
|
||||
.apbclock = STM32_PCLK1_FREQUENCY,
|
||||
.usartbase = STM32_USART2_BASE,
|
||||
@@ -468,6 +487,15 @@ static struct up_dev_s g_usart2priv =
|
||||
.rxfifo = g_usart2rxfifo,
|
||||
#endif
|
||||
.vector = up_interrupt_usart2,
|
||||
|
||||
#ifdef CONFIG_USART2_RS485
|
||||
.rs485_dir_gpio = GPIO_USART2_RS485_DIR,
|
||||
# if (CONFIG_USART2_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -503,8 +531,6 @@ static struct up_dev_s g_usart3priv =
|
||||
.parity = CONFIG_USART3_PARITY,
|
||||
.bits = CONFIG_USART3_BITS,
|
||||
.stopbits2 = CONFIG_USART3_2STOP,
|
||||
.iflow = false,
|
||||
.oflow = false,
|
||||
.baud = CONFIG_USART3_BAUD,
|
||||
.apbclock = STM32_PCLK1_FREQUENCY,
|
||||
.usartbase = STM32_USART3_BASE,
|
||||
@@ -521,6 +547,15 @@ static struct up_dev_s g_usart3priv =
|
||||
.rxfifo = g_usart3rxfifo,
|
||||
#endif
|
||||
.vector = up_interrupt_usart3,
|
||||
|
||||
#ifdef CONFIG_USART3_RS485
|
||||
.rs485_dir_gpio = GPIO_USART3_RS485_DIR,
|
||||
# if (CONFIG_USART3_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -556,20 +591,31 @@ static struct up_dev_s g_uart4priv =
|
||||
.parity = CONFIG_UART4_PARITY,
|
||||
.bits = CONFIG_UART4_BITS,
|
||||
.stopbits2 = CONFIG_UART4_2STOP,
|
||||
.iflow = false,
|
||||
.oflow = false,
|
||||
.baud = CONFIG_UART4_BAUD,
|
||||
.apbclock = STM32_PCLK1_FREQUENCY,
|
||||
.usartbase = STM32_UART4_BASE,
|
||||
.tx_gpio = GPIO_UART4_TX,
|
||||
.rx_gpio = GPIO_UART4_RX,
|
||||
.cts_gpio = 0, /* flow control not supported on this port */
|
||||
.rts_gpio = 0, /* flow control not supported on this port */
|
||||
#ifdef GPIO_UART4_CTS
|
||||
.cts_gpio = GPIO_UART4_CTS,
|
||||
#endif
|
||||
#ifdef GPIO_UART4_RTS
|
||||
.rts_gpio = GPIO_UART4_RTS,
|
||||
#endif
|
||||
#ifdef CONFIG_UART4_RXDMA
|
||||
.rxdma_channel = DMAMAP_UART4_RX,
|
||||
.rxfifo = g_uart4rxfifo,
|
||||
#endif
|
||||
.vector = up_interrupt_uart4,
|
||||
|
||||
#ifdef CONFIG_UART4_RS485
|
||||
.rs485_dir_gpio = GPIO_UART4_RS485_DIR,
|
||||
# if (CONFIG_UART4_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -605,20 +651,31 @@ static struct up_dev_s g_uart5priv =
|
||||
.parity = CONFIG_UART5_PARITY,
|
||||
.bits = CONFIG_UART5_BITS,
|
||||
.stopbits2 = CONFIG_UART5_2STOP,
|
||||
.iflow = false,
|
||||
.oflow = false,
|
||||
.baud = CONFIG_UART5_BAUD,
|
||||
.apbclock = STM32_PCLK1_FREQUENCY,
|
||||
.usartbase = STM32_UART5_BASE,
|
||||
.tx_gpio = GPIO_UART5_TX,
|
||||
.rx_gpio = GPIO_UART5_RX,
|
||||
.cts_gpio = 0, /* flow control not supported on this port */
|
||||
.rts_gpio = 0, /* flow control not supported on this port */
|
||||
#ifdef GPIO_UART5_CTS
|
||||
.cts_gpio = GPIO_UART5_CTS,
|
||||
#endif
|
||||
#ifdef GPIO_UART5_RTS
|
||||
.rts_gpio = GPIO_UART5_RTS,
|
||||
#endif
|
||||
#ifdef CONFIG_UART5_RXDMA
|
||||
.rxdma_channel = DMAMAP_UART5_RX,
|
||||
.rxfifo = g_uart5rxfifo,
|
||||
#endif
|
||||
.vector = up_interrupt_uart5,
|
||||
|
||||
#ifdef CONFIG_UART5_RS485
|
||||
.rs485_dir_gpio = GPIO_UART5_RS485_DIR,
|
||||
# if (CONFIG_UART5_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -654,8 +711,6 @@ static struct up_dev_s g_usart6priv =
|
||||
.parity = CONFIG_USART6_PARITY,
|
||||
.bits = CONFIG_USART6_BITS,
|
||||
.stopbits2 = CONFIG_USART6_2STOP,
|
||||
.iflow = false,
|
||||
.oflow = false,
|
||||
.baud = CONFIG_USART6_BAUD,
|
||||
.apbclock = STM32_PCLK2_FREQUENCY,
|
||||
.usartbase = STM32_USART6_BASE,
|
||||
@@ -672,6 +727,15 @@ static struct up_dev_s g_usart6priv =
|
||||
.rxfifo = g_usart6rxfifo,
|
||||
#endif
|
||||
.vector = up_interrupt_usart6,
|
||||
|
||||
#ifdef CONFIG_USART6_RS485
|
||||
.rs485_dir_gpio = GPIO_USART6_RS485_DIR,
|
||||
# if (CONFIG_USART6_RS485_DIR_POLARITY == 0)
|
||||
.rs485_dir_polarity = false,
|
||||
# else
|
||||
.rs485_dir_polarity = true,
|
||||
# endif
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -744,8 +808,8 @@ static void up_restoreusartint(struct up_dev_s *priv, uint16_t ie)
|
||||
/* And restore the interrupt state (see the interrupt enable/usage table above) */
|
||||
|
||||
cr = up_serialin(priv, STM32_USART_CR1_OFFSET);
|
||||
cr &= ~(USART_CR1_RXNEIE|USART_CR1_TXEIE|USART_CR1_PEIE);
|
||||
cr |= (ie & (USART_CR1_RXNEIE|USART_CR1_TXEIE|USART_CR1_PEIE));
|
||||
cr &= ~(USART_CR1_USED_INTS);
|
||||
cr |= (ie & (USART_CR1_USED_INTS));
|
||||
up_serialout(priv, STM32_USART_CR1_OFFSET, cr);
|
||||
|
||||
cr = up_serialin(priv, STM32_USART_CR3_OFFSET);
|
||||
@@ -772,7 +836,7 @@ static inline void up_disableusartint(struct up_dev_s *priv, uint16_t *ie)
|
||||
* USART_CR1_IDLEIE 4 USART_SR_IDLE Idle Line Detected (not used)
|
||||
* USART_CR1_RXNEIE 5 USART_SR_RXNE Received Data Ready to be Read
|
||||
* " " USART_SR_ORE Overrun Error Detected
|
||||
* USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (not used)
|
||||
* USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (used only for RS-485)
|
||||
* USART_CR1_TXEIE 7 USART_SR_TXE Transmit Data Register Empty
|
||||
* USART_CR1_PEIE 8 USART_SR_PE Parity Error
|
||||
*
|
||||
@@ -791,7 +855,7 @@ static inline void up_disableusartint(struct up_dev_s *priv, uint16_t *ie)
|
||||
* overlap. This logic would fail if we needed the break interrupt!
|
||||
*/
|
||||
|
||||
*ie = (cr1 & (USART_CR1_RXNEIE|USART_CR1_TXEIE|USART_CR1_PEIE)) | (cr3 & USART_CR3_EIE);
|
||||
*ie = (cr1 & (USART_CR1_USED_INTS)) | (cr3 & USART_CR3_EIE);
|
||||
}
|
||||
|
||||
/* Disable all interrupts */
|
||||
@@ -820,22 +884,21 @@ static int up_dma_nextrx(struct up_dev_s *priv)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_set_format
|
||||
* Name: up_setspeed
|
||||
*
|
||||
* Description:
|
||||
* Set the serial line format and speed.
|
||||
* Set the serial line speed.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_SUPPRESS_UART_CONFIG
|
||||
static void up_set_format(struct uart_dev_s *dev)
|
||||
static void up_setspeed(struct uart_dev_s *dev)
|
||||
{
|
||||
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
|
||||
uint32_t usartdiv32;
|
||||
uint32_t mantissa;
|
||||
uint32_t fraction;
|
||||
uint32_t brr;
|
||||
uint32_t regval;
|
||||
|
||||
/* Configure the USART Baud Rate. The baud rate for the receiver and
|
||||
* transmitter (Rx and Tx) are both set to the same value as programmed
|
||||
@@ -853,64 +916,20 @@ static void up_set_format(struct uart_dev_s *dev)
|
||||
* usartdiv32 = 32 * usartdiv = fCK / (baud/2)
|
||||
*/
|
||||
|
||||
usartdiv32 = priv->apbclock / (priv->baud >> 1);
|
||||
usartdiv32 = priv->apbclock / (priv->baud >> 1);
|
||||
|
||||
/* The mantissa part is then */
|
||||
/* The mantissa part is then */
|
||||
|
||||
mantissa = usartdiv32 >> 5;
|
||||
brr = mantissa << USART_BRR_MANT_SHIFT;
|
||||
mantissa = usartdiv32 >> 5;
|
||||
brr = mantissa << USART_BRR_MANT_SHIFT;
|
||||
|
||||
/* The fractional remainder (with rounding) */
|
||||
|
||||
fraction = (usartdiv32 - (mantissa << 5) + 1) >> 1;
|
||||
brr |= fraction << USART_BRR_FRAC_SHIFT;
|
||||
up_serialout(priv, STM32_USART_BRR_OFFSET, brr);
|
||||
|
||||
/* Configure parity mode */
|
||||
|
||||
regval = up_serialin(priv, STM32_USART_CR1_OFFSET);
|
||||
regval &= ~(USART_CR1_PCE|USART_CR1_PS);
|
||||
|
||||
if (priv->parity == 1) /* Odd parity */
|
||||
{
|
||||
regval |= (USART_CR1_PCE|USART_CR1_PS);
|
||||
}
|
||||
else if (priv->parity == 2) /* Even parity */
|
||||
{
|
||||
regval |= USART_CR1_PCE;
|
||||
}
|
||||
|
||||
up_serialout(priv, STM32_USART_CR1_OFFSET, regval);
|
||||
|
||||
/* Configure STOP bits */
|
||||
|
||||
regval = up_serialin(priv, STM32_USART_CR2_OFFSET);
|
||||
regval &= ~(USART_CR2_STOP_MASK);
|
||||
|
||||
if (priv->stopbits2)
|
||||
{
|
||||
regval |= USART_CR2_STOP2;
|
||||
}
|
||||
up_serialout(priv, STM32_USART_CR2_OFFSET, regval);
|
||||
|
||||
/* Configure hardware flow control */
|
||||
|
||||
regval = up_serialin(priv, STM32_USART_CR3_OFFSET);
|
||||
regval &= ~(USART_CR3_CTSE|USART_CR3_RTSE);
|
||||
|
||||
if (priv->iflow && (priv->rts_gpio != 0))
|
||||
{
|
||||
regval |= USART_CR3_RTSE;
|
||||
}
|
||||
if (priv->oflow && (priv->cts_gpio != 0))
|
||||
{
|
||||
regval |= USART_CR3_CTSE;
|
||||
}
|
||||
|
||||
up_serialout(priv, STM32_USART_CR3_OFFSET, regval);
|
||||
/* The fractional remainder (with rounding) */
|
||||
|
||||
fraction = (usartdiv32 - (mantissa << 5) + 1) >> 1;
|
||||
brr |= fraction << USART_BRR_FRAC_SHIFT;
|
||||
up_serialout(priv, STM32_USART_BRR_OFFSET, brr);
|
||||
}
|
||||
#endif /* CONFIG_SUPPRESS_UART_CONFIG */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_setup
|
||||
@@ -946,29 +965,52 @@ static int up_setup(struct uart_dev_s *dev)
|
||||
stm32_configgpio(priv->rts_gpio);
|
||||
}
|
||||
|
||||
#if HAVE_RS485
|
||||
if (priv->rs485_dir_gpio != 0)
|
||||
{
|
||||
stm32_configgpio(priv->rs485_dir_gpio);
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio, !priv->rs485_dir_polarity);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Configure CR2 */
|
||||
/* Clear CLKEN, CPOL, CPHA, LBCL, and interrupt enable bits */
|
||||
/* Clear STOP, CLKEN, CPOL, CPHA, LBCL, and interrupt enable bits */
|
||||
|
||||
regval = up_serialin(priv, STM32_USART_CR2_OFFSET);
|
||||
regval &= ~(USART_CR2_CLKEN|USART_CR2_CPOL|
|
||||
regval &= ~(USART_CR2_STOP_MASK|USART_CR2_CLKEN|USART_CR2_CPOL|
|
||||
USART_CR2_CPHA|USART_CR2_LBCL|USART_CR2_LBDIE);
|
||||
|
||||
/* Configure STOP bits */
|
||||
|
||||
if (priv->stopbits2)
|
||||
{
|
||||
regval |= USART_CR2_STOP2;
|
||||
}
|
||||
up_serialout(priv, STM32_USART_CR2_OFFSET, regval);
|
||||
|
||||
/* Configure CR1 */
|
||||
/* Clear M, TE, REm and all interrupt enable bits */
|
||||
/* Clear M, PCE, PS, TE, REm and all interrupt enable bits */
|
||||
|
||||
regval = up_serialin(priv, STM32_USART_CR1_OFFSET);
|
||||
regval &= ~(USART_CR1_M|USART_CR1_TE|
|
||||
regval &= ~(USART_CR1_M|USART_CR1_PCE|USART_CR1_PS|USART_CR1_TE|
|
||||
USART_CR1_RE|USART_CR1_ALLINTS);
|
||||
|
||||
/* Configure word length */
|
||||
/* Configure word length and parity mode */
|
||||
|
||||
if (priv->bits == 9) /* Default: 1 start, 8 data, n stop */
|
||||
{
|
||||
regval |= USART_CR1_M; /* 1 start, 9 data, n stop */
|
||||
}
|
||||
|
||||
if (priv->parity == 1) /* Odd parity */
|
||||
{
|
||||
regval |= (USART_CR1_PCE|USART_CR1_PS);
|
||||
}
|
||||
else if (priv->parity == 2) /* Even parity */
|
||||
{
|
||||
regval |= USART_CR1_PCE;
|
||||
}
|
||||
|
||||
up_serialout(priv, STM32_USART_CR1_OFFSET, regval);
|
||||
|
||||
/* Configure CR3 */
|
||||
@@ -981,22 +1023,20 @@ static int up_setup(struct uart_dev_s *dev)
|
||||
|
||||
up_serialout(priv, STM32_USART_CR3_OFFSET, regval);
|
||||
|
||||
/* Configure the USART line format and speed. */
|
||||
/* Configure the USART Baud Rate. */
|
||||
|
||||
up_set_format(dev);
|
||||
up_setspeed(dev);
|
||||
|
||||
/* Enable Rx, Tx, and the USART */
|
||||
|
||||
regval = up_serialin(priv, STM32_USART_CR1_OFFSET);
|
||||
regval |= (USART_CR1_UE|USART_CR1_TE|USART_CR1_RE);
|
||||
up_serialout(priv, STM32_USART_CR1_OFFSET, regval);
|
||||
|
||||
#endif /* CONFIG_SUPPRESS_UART_CONFIG */
|
||||
#endif
|
||||
|
||||
/* Set up the cached interrupt enables value */
|
||||
|
||||
up_restoreusartint(priv, 0);
|
||||
|
||||
priv->ie = 0;
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -1016,15 +1056,12 @@ static int up_dma_setup(struct uart_dev_s *dev)
|
||||
int result;
|
||||
uint32_t regval;
|
||||
|
||||
/* Do the basic UART setup first, unless we are the console */
|
||||
/* Do the basic UART setup first */
|
||||
|
||||
if (!dev->isconsole)
|
||||
{
|
||||
result = up_setup(dev);
|
||||
if (result != OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
result = up_setup(dev);
|
||||
if (result != OK)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Acquire the DMA channel. This should always succeed. */
|
||||
@@ -1217,7 +1254,7 @@ static int up_interrupt_common(struct up_dev_s *priv)
|
||||
* USART_CR1_IDLEIE 4 USART_SR_IDLE Idle Line Detected (not used)
|
||||
* USART_CR1_RXNEIE 5 USART_SR_RXNE Received Data Ready to be Read
|
||||
* " " USART_SR_ORE Overrun Error Detected
|
||||
* USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (not used)
|
||||
* USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (used only for RS-485)
|
||||
* USART_CR1_TXEIE 7 USART_SR_TXE Transmit Data Register Empty
|
||||
* USART_CR1_PEIE 8 USART_SR_PE Parity Error
|
||||
*
|
||||
@@ -1232,6 +1269,21 @@ static int up_interrupt_common(struct up_dev_s *priv)
|
||||
* being used.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_RS485
|
||||
/* Transmission of whole buffer is over - TC is set, TXEIE is cleared.
|
||||
* Note - this should be first, to have the most recent TC bit value from
|
||||
* SR register - sending data affects TC, but without refresh we will not
|
||||
* know that...
|
||||
*/
|
||||
|
||||
if ((priv->sr & USART_SR_TC) != 0 && (priv->ie & USART_CR1_TCIE) != 0 &&
|
||||
(priv->ie & USART_CR1_TXEIE) == 0)
|
||||
{
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio, !priv->rs485_dir_polarity);
|
||||
up_restoreusartint(priv, priv->ie & ~USART_CR1_TCIE);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Handle incoming, receive bytes. */
|
||||
|
||||
if ((priv->sr & USART_SR_RXNE) != 0 && (priv->ie & USART_CR1_RXNEIE) != 0)
|
||||
@@ -1265,13 +1317,14 @@ static int up_interrupt_common(struct up_dev_s *priv)
|
||||
|
||||
if ((priv->sr & USART_SR_TXE) != 0 && (priv->ie & USART_CR1_TXEIE) != 0)
|
||||
{
|
||||
/* Transmit data regiser empty ... process outgoing bytes */
|
||||
/* Transmit data register empty ... process outgoing bytes */
|
||||
|
||||
uart_xmitchars(&priv->dev);
|
||||
handled = true;
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -1318,21 +1371,12 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg)
|
||||
break;
|
||||
}
|
||||
|
||||
cfsetispeed(termiosp, priv->baud);
|
||||
|
||||
/* Note that since we only support 8/9 bit modes and
|
||||
* there is no way to report 9-bit mode, we always claim 8.
|
||||
/* TODO: Other termios fields are not yet returned.
|
||||
* Note that only cfsetospeed is not necessary because we have
|
||||
* knowledge that only one speed is supported.
|
||||
*/
|
||||
|
||||
termiosp->c_cflag =
|
||||
((priv->parity != 0) ? PARENB : 0) |
|
||||
((priv->parity == 1) ? PARODD : 0) |
|
||||
((priv->stopbits2) ? CSTOPB : 0) |
|
||||
((priv->oflow) ? CCTS_OFLOW : 0) |
|
||||
((priv->iflow) ? CRTS_IFLOW : 0) |
|
||||
CS8;
|
||||
|
||||
/* TODO: CCTS_IFLOW, CCTS_OFLOW */
|
||||
cfsetispeed(termiosp, priv->baud);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1346,48 +1390,16 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Perform some sanity checks before accepting any changes */
|
||||
|
||||
if (((termiosp->c_cflag & CSIZE) != CS8) ||
|
||||
((termiosp->c_cflag & CCTS_OFLOW) && (priv->cts_gpio == 0)) ||
|
||||
((termiosp->c_cflag & CRTS_IFLOW) && (priv->rts_gpio == 0)))
|
||||
{
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
if (termiosp->c_cflag & PARENB)
|
||||
{
|
||||
priv->parity = (termiosp->c_cflag & PARODD) ? 1 : 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
priv->parity = 0;
|
||||
}
|
||||
|
||||
priv->stopbits2 = (termiosp->c_cflag & CSTOPB) != 0;
|
||||
priv->oflow = (termiosp->c_cflag & CCTS_OFLOW) != 0;
|
||||
priv->iflow = (termiosp->c_cflag & CRTS_IFLOW) != 0;
|
||||
|
||||
/* Note that since there is no way to request 9-bit mode
|
||||
* and no way to support 5/6/7-bit modes, we ignore them
|
||||
* all here.
|
||||
*/
|
||||
|
||||
/* Note that only cfgetispeed is used because we have knowledge
|
||||
/* TODO: Handle other termios settings.
|
||||
* Note that only cfgetispeed is used besued we have knowledge
|
||||
* that only one speed is supported.
|
||||
*/
|
||||
|
||||
priv->baud = cfgetispeed(termiosp);
|
||||
|
||||
/* effect the changes immediately - note that we do not implement
|
||||
* TCSADRAIN / TCSAFLUSH
|
||||
*/
|
||||
|
||||
up_set_format(dev);
|
||||
up_setspeed(dev);
|
||||
}
|
||||
break;
|
||||
#endif /* CONFIG_SERIAL_TERMIOS */
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_USART_BREAKS
|
||||
case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */
|
||||
@@ -1611,6 +1623,10 @@ static bool up_dma_rxavailable(struct uart_dev_s *dev)
|
||||
static void up_send(struct uart_dev_s *dev, int ch)
|
||||
{
|
||||
struct up_dev_s *priv = (struct up_dev_s*)dev->priv;
|
||||
#ifdef HAVE_RS485
|
||||
if (priv->rs485_dir_gpio != 0)
|
||||
stm32_gpiowrite(priv->rs485_dir_gpio, priv->rs485_dir_polarity);
|
||||
#endif
|
||||
up_serialout(priv, STM32_USART_DR_OFFSET, (uint32_t)ch);
|
||||
}
|
||||
|
||||
@@ -1631,7 +1647,7 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
|
||||
*
|
||||
* Enable Bit Status Meaning Usage
|
||||
* ------------------ --- --------------- ---------------------------- ----------
|
||||
* USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (not used)
|
||||
* USART_CR1_TCIE 6 USART_SR_TC Transmission Complete (used only for RS-485)
|
||||
* USART_CR1_TXEIE 7 USART_SR_TXE Transmit Data Register Empty
|
||||
* USART_CR3_CTSIE 10 USART_SR_CTS CTS flag (not used)
|
||||
*/
|
||||
@@ -1642,7 +1658,20 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
|
||||
/* Set to receive an interrupt when the TX data register is empty */
|
||||
|
||||
#ifndef CONFIG_SUPPRESS_SERIAL_INTS
|
||||
up_restoreusartint(priv, priv->ie | USART_CR1_TXEIE);
|
||||
uint16_t ie = priv->ie | USART_CR1_TXEIE;
|
||||
|
||||
/* If RS-485 is supported on this U[S]ART, then also enable the
|
||||
* transmission complete interrupt.
|
||||
*/
|
||||
|
||||
# ifdef HAVE_RS485
|
||||
if (priv->rs485_dir_gpio != 0)
|
||||
{
|
||||
ie |= USART_CR1_TCIE;
|
||||
}
|
||||
# endif
|
||||
|
||||
up_restoreusartint(priv, ie);
|
||||
|
||||
/* Fake a TX interrupt here by just calling uart_xmitchars() with
|
||||
* interrupts disabled (note this may recurse).
|
||||
@@ -1657,6 +1686,7 @@ static void up_txint(struct uart_dev_s *dev, bool enable)
|
||||
|
||||
up_restoreusartint(priv, priv->ie & ~USART_CR1_TXEIE);
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
}
|
||||
|
||||
|
||||
@@ -631,7 +631,11 @@ static void stm32_stdclockconfig(void)
|
||||
|
||||
/* Enable FLASH prefetch, instruction cache, data cache, and 5 wait states */
|
||||
|
||||
#ifdef STM32_FLASH_PREFETCH
|
||||
regval = (FLASH_ACR_LATENCY_5 | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_PRFTEN);
|
||||
#else
|
||||
regval = (FLASH_ACR_LATENCY_5 | FLASH_ACR_ICEN | FLASH_ACR_DCEN);
|
||||
#endif
|
||||
putreg32(regval, STM32_FLASH_ACR);
|
||||
|
||||
/* Select the main PLL as system clock source */
|
||||
|
||||
@@ -633,7 +633,11 @@ static void stm32_stdclockconfig(void)
|
||||
|
||||
/* Enable FLASH prefetch, instruction cache, data cache, and 5 wait states */
|
||||
|
||||
#ifdef STM32_FLASH_PREFETCH
|
||||
regval = (FLASH_ACR_LATENCY_5 | FLASH_ACR_ICEN | FLASH_ACR_DCEN | FLASH_ACR_PRFTEN);
|
||||
#else
|
||||
regval = (FLASH_ACR_LATENCY_5 | FLASH_ACR_ICEN | FLASH_ACR_DCEN);
|
||||
#endif
|
||||
putreg32(regval, STM32_FLASH_ACR);
|
||||
|
||||
/* Select the main PLL as system clock source */
|
||||
|
||||
@@ -2,3 +2,66 @@
|
||||
# For a description of the syntax of this configuration file,
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
config BINFMT_DISABLE
|
||||
bool "Disble BINFMT support"
|
||||
default n
|
||||
---help---
|
||||
By default, support for loadable binary formats is built. This logic
|
||||
may be suppressed be defining this setting.
|
||||
|
||||
if !BINFMT_DISABLE
|
||||
|
||||
config BINFMT_EXEPATH
|
||||
bool "Support PATH variable"
|
||||
default n
|
||||
depends on !DISABLE_ENVIRON
|
||||
---help---
|
||||
Use the contents of the PATH environment variable to locate executable
|
||||
files. Default: n
|
||||
|
||||
config PATH_INITIAL
|
||||
string "Initial PATH Value"
|
||||
default ""
|
||||
depends on BINFMT_EXEPATH
|
||||
---help---
|
||||
The initial value of the PATH variable. This is the colon-separated
|
||||
list of absolute paths. E.g., "/bin:/usr/bin:/sbin"
|
||||
|
||||
config NXFLAT
|
||||
bool "Enable the NXFLAT Binary Format"
|
||||
default n
|
||||
select PIC
|
||||
---help---
|
||||
Enable support for the NXFLAT binary format. Default: n
|
||||
|
||||
if NXFLAT
|
||||
source binfmt/libnxflat/Kconfig
|
||||
endif
|
||||
|
||||
config ELF
|
||||
bool "Enable the ELF Binary Format"
|
||||
default n
|
||||
---help---
|
||||
Enable support for the ELF binary format. Default: n
|
||||
|
||||
if ELF
|
||||
source binfmt/libelf/Kconfig
|
||||
endif
|
||||
|
||||
endif
|
||||
|
||||
config PIC
|
||||
bool
|
||||
default n
|
||||
|
||||
config BINFMT_CONSTRUCTORS
|
||||
bool "C++ Static Constructor Support"
|
||||
default n
|
||||
depends on HAVE_CXX && ELF # FIX ME: Currently only supported for ELF
|
||||
---help---
|
||||
Build in support for C++ constructors in loaded modules.
|
||||
|
||||
config SYMTAB_ORDEREDBYNAME
|
||||
bool "Symbol Tables Ordered by Name"
|
||||
default n
|
||||
|
||||
+38
-38
@@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# nxflat/Makefile
|
||||
#
|
||||
# Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2007-2009, 2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -34,69 +34,69 @@
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
DELIM ?= $(strip /)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
INCDIROPT = -w
|
||||
INCDIROPT = -w
|
||||
endif
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/sched}
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(TOPDIR)$(DELIM)sched"}
|
||||
|
||||
ifeq ($(CONFIG_NXFLAT),y)
|
||||
include libnxflat/Make.defs
|
||||
LIBNXFLAT_CSRCS += nxflat.c
|
||||
# Basic BINFMT source files
|
||||
|
||||
BINFMT_ASRCS =
|
||||
BINFMT_CSRCS = binfmt_globals.c binfmt_register.c binfmt_unregister.c
|
||||
BINFMT_CSRCS += binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c
|
||||
BINFMT_CSRCS += binfmt_exec.c binfmt_dumpmodule.c
|
||||
|
||||
ifeq ($(CONFIG_BINFMT_EXEPATH),y)
|
||||
BINFMT_CSRCS += binfmt_exepath.c
|
||||
endif
|
||||
|
||||
BINFMT_ASRCS =
|
||||
BINFMT_CSRCS = binfmt_globals.c binfmt_register.c binfmt_unregister.c \
|
||||
binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c \
|
||||
binfmt_exec.c binfmt_dumpmodule.c
|
||||
# Symbol table source files
|
||||
|
||||
SYMTAB_ASRCS =
|
||||
SYMTAB_CSRCS = symtab_findbyname.c symtab_findbyvalue.c \
|
||||
symtab_findorderedbyname.c symtab_findorderedbyvalue.c
|
||||
BINFMT_CSRCS += symtab_findbyname.c symtab_findbyvalue.c
|
||||
BINFMT_CSRCS += symtab_findorderedbyname.c symtab_findorderedbyvalue.c
|
||||
|
||||
SUBDIRS = libnxflat
|
||||
# Add configured binary modules
|
||||
|
||||
ASRCS = $(BINFMT_ASRCS) $(SYMTAB_ASRCS) $(LIBNXFLAT_ASRCS)
|
||||
AOBJS = $(ASRCS:.S=$(OBJEXT))
|
||||
VPATH =
|
||||
SUBDIRS =
|
||||
DEPPATH = --dep-path .
|
||||
|
||||
CSRCS = $(BINFMT_CSRCS) $(SYMTAB_CSRCS) $(LIBNXFLAT_CSRCS)
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
include libnxflat$(DELIM)Make.defs
|
||||
include libelf$(DELIM)Make.defs
|
||||
|
||||
SRCS = $(ASRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
BINFMT_AOBJS = $(BINFMT_ASRCS:.S=$(OBJEXT))
|
||||
BINFMT_COBJS = $(BINFMT_CSRCS:.c=$(OBJEXT))
|
||||
|
||||
BIN = libbinfmt$(LIBEXT)
|
||||
BINFMT_SRCS = $(BINFMT_ASRCS) $(BINFMT_CSRCS)
|
||||
BINFMT_OBJS = $(BINFMT_AOBJS) $(BINFMT_COBJS)
|
||||
|
||||
VPATH = libnxflat
|
||||
BIN = libbinfmt$(LIBEXT)
|
||||
|
||||
all: $(BIN)
|
||||
all: $(BIN)
|
||||
|
||||
$(AOBJS): %$(OBJEXT): %.S
|
||||
$(BINFMT_AOBJS): %$(OBJEXT): %.S
|
||||
$(call ASSEMBLE, $<, $@)
|
||||
|
||||
$(COBJS): %$(OBJEXT): %.c
|
||||
$(BINFMT_COBJS): %$(OBJEXT): %.c
|
||||
$(call COMPILE, $<, $@)
|
||||
|
||||
$(BIN): $(OBJS)
|
||||
@( for obj in $(OBJS) ; do \
|
||||
$(call ARCHIVE, $@, $${obj}); \
|
||||
done ; )
|
||||
$(BIN): $(BINFMT_OBJS)
|
||||
$(call ARCHIVE, $@, $(BINFMT_OBJS))
|
||||
|
||||
.depend: Makefile $(SRCS)
|
||||
@$(MKDEP) --dep-path . --dep-path libnxflat \
|
||||
$(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
|
||||
@touch $@
|
||||
.depend: Makefile $(BINFMT_SRCS)
|
||||
$(Q) $(MKDEP) $(DEPPATH) "$(CC)" -- $(CFLAGS) -- $(BINFMT_SRCS) >Make.dep
|
||||
$(Q) touch $@
|
||||
|
||||
depend: .depend
|
||||
|
||||
clean:
|
||||
@rm -f $(BIN) *~ .*.swp
|
||||
$(call DELFILE, $(BIN))
|
||||
$(call CLEAN)
|
||||
@( for dir in $(SUBDIRS); do \
|
||||
rm -f $${dir}/*~ $${dir}/.*.swp; \
|
||||
done ; )
|
||||
|
||||
distclean: clean
|
||||
@rm -f Make.dep .depend
|
||||
$(call DELFILE, Make.dep)
|
||||
$(call DELFILE, .depend)
|
||||
|
||||
-include Make.dep
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* binfmt/binfmt_dumpmodule.c
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -43,7 +43,7 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
#include "binfmt_internal.h"
|
||||
|
||||
@@ -70,7 +70,7 @@
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
* Name: load_module
|
||||
* Name: dump_module
|
||||
*
|
||||
* Description:
|
||||
* Load a module into memory and prep it for execution.
|
||||
@@ -90,8 +90,15 @@ int dump_module(FAR const struct binary_s *bin)
|
||||
bdbg(" filename: %s\n", bin->filename);
|
||||
bdbg(" argv: %p\n", bin->argv);
|
||||
bdbg(" entrypt: %p\n", bin->entrypt);
|
||||
bdbg(" ispace: %p size=%d\n", bin->ispace, bin->isize);
|
||||
bdbg(" dspace: %p\n", bin->dspace);
|
||||
bdbg(" mapped: %p size=%d\n", bin->mapped, bin->mapsize);
|
||||
bdbg(" alloc: %p %p %p\n", bin->alloc[0], bin->alloc[1], bin->alloc[2]);
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
bdbg(" ctors: %p nctors=%d\n", bin->ctors, bin->nctors);
|
||||
bdbg(" dtors: %p ndtors=%d\n", bin->dtors, bin->ndtors);
|
||||
#endif
|
||||
#ifdef CONFIG_ADDRENV
|
||||
bdbg(" addrenv: %p\n", bin->addrenv);
|
||||
#endif
|
||||
bdbg(" stacksize: %d\n", bin->stacksize);
|
||||
}
|
||||
return OK;
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/binfmt.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
#include "os_internal.h"
|
||||
#include "binfmt_internal.h"
|
||||
@@ -70,6 +70,62 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exec_ctors
|
||||
*
|
||||
* Description:
|
||||
* Execute C++ static constructors.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
static inline int exec_ctors(FAR const struct binary_s *binp)
|
||||
{
|
||||
binfmt_ctor_t *ctor = binp->ctors;
|
||||
#ifdef CONFIG_ADDRENV
|
||||
hw_addrenv_t oldenv;
|
||||
int ret;
|
||||
#endif
|
||||
int i;
|
||||
|
||||
/* Instantiate the address enviroment containing the constructors */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = up_addrenv_select(binp->addrenv, &oldenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("up_addrenv_select() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Execute each constructor */
|
||||
|
||||
for (i = 0; i < binp->nctors; i++)
|
||||
{
|
||||
bvdbg("Calling ctor %d at %p\n", i, (FAR void *)ctor);
|
||||
|
||||
(*ctor)();
|
||||
ctor++;
|
||||
}
|
||||
|
||||
/* Restore the address enviroment */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
return up_addrenv_restore(oldenv);
|
||||
#else
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -87,7 +143,7 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int exec_module(FAR const struct binary_s *bin, int priority)
|
||||
int exec_module(FAR const struct binary_s *binp, int priority)
|
||||
{
|
||||
FAR _TCB *tcb;
|
||||
#ifndef CONFIG_CUSTOM_STACK
|
||||
@@ -100,14 +156,14 @@ int exec_module(FAR const struct binary_s *bin, int priority)
|
||||
/* Sanity checking */
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!bin || !bin->ispace || !bin->entrypt || bin->stacksize <= 0)
|
||||
if (!binp || !binp->entrypt || binp->stacksize <= 0)
|
||||
{
|
||||
err = EINVAL;
|
||||
goto errout;
|
||||
}
|
||||
#endif
|
||||
|
||||
bdbg("Executing %s\n", bin->filename);
|
||||
bdbg("Executing %s\n", binp->filename);
|
||||
|
||||
/* Allocate a TCB for the new task. */
|
||||
|
||||
@@ -121,7 +177,7 @@ int exec_module(FAR const struct binary_s *bin, int priority)
|
||||
/* Allocate the stack for the new task */
|
||||
|
||||
#ifndef CONFIG_CUSTOM_STACK
|
||||
stack = (FAR uint32_t*)malloc(bin->stacksize);
|
||||
stack = (FAR uint32_t*)malloc(binp->stacksize);
|
||||
if (!tcb)
|
||||
{
|
||||
err = ENOMEM;
|
||||
@@ -130,11 +186,13 @@ int exec_module(FAR const struct binary_s *bin, int priority)
|
||||
|
||||
/* Initialize the task */
|
||||
|
||||
ret = task_init(tcb, bin->filename, priority, stack, bin->stacksize, bin->entrypt, bin->argv);
|
||||
ret = task_init(tcb, binp->filename, priority, stack,
|
||||
binp->stacksize, binp->entrypt, binp->argv);
|
||||
#else
|
||||
/* Initialize the task */
|
||||
|
||||
ret = task_init(tcb, bin->filename, priority, stack, bin->entrypt, bin->argv);
|
||||
ret = task_init(tcb, binp->filename, priority, stack,
|
||||
binp->entrypt, binp->argv);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -143,20 +201,46 @@ int exec_module(FAR const struct binary_s *bin, int priority)
|
||||
goto errout_with_stack;
|
||||
}
|
||||
|
||||
/* Add the DSpace address as the PIC base address */
|
||||
/* Add the D-Space address as the PIC base address. By convention, this
|
||||
* must be the first allocated address space.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_PIC
|
||||
tcb->dspace = bin->dspace;
|
||||
tcb->dspace = binp->alloc[0];
|
||||
|
||||
/* Re-initialize the task's initial state to account for the new PIC base */
|
||||
|
||||
up_initial_state(tcb);
|
||||
#endif
|
||||
|
||||
/* Assign the address environment to the task */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = up_addrenv_assign(binp->addrenv, tcb);
|
||||
if (ret < 0)
|
||||
{
|
||||
err = -ret;
|
||||
bdbg("up_addrenv_assign() failed: %d\n", ret);
|
||||
goto errout_with_stack;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Get the assigned pid before we start the task */
|
||||
|
||||
pid = tcb->pid;
|
||||
|
||||
/* Execute all of the C++ static constructors */
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
ret = exec_ctors(binp);
|
||||
if (ret < 0)
|
||||
{
|
||||
err = -ret;
|
||||
bdbg("exec_ctors() failed: %d\n", ret);
|
||||
goto errout_with_stack;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Then activate the task at the provided priority */
|
||||
|
||||
ret = task_activate(tcb);
|
||||
@@ -166,6 +250,7 @@ int exec_module(FAR const struct binary_s *bin, int priority)
|
||||
bdbg("task_activate() failed: %d\n", err);
|
||||
goto errout_with_stack;
|
||||
}
|
||||
|
||||
return (int)pid;
|
||||
|
||||
errout_with_stack:
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
/****************************************************************************
|
||||
* binfmt/binfmt_exepath.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct exepath_s
|
||||
{
|
||||
FAR char *next; /* Pointer to the next (unterminated) value in the PATH variable */
|
||||
char path[1];
|
||||
};
|
||||
#define SIZEOF_EXEPATH_S(n) (sizeof(struct exepath_s) + (n) - 1)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exepath_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize for the traversal of each value in the PATH variable. The
|
||||
* usage is sequence is as follows:
|
||||
*
|
||||
* 1) Call exepath_init() to initialize for the traversal. exepath_init()
|
||||
* will return an opaque handle that can then be provided to
|
||||
* exepath_next() and exepath_release().
|
||||
* 2) Call exepath_next() repeatedly to examine every file that lies
|
||||
* in the directories of the PATH variable
|
||||
* 3) Call exepath_release() to free resources set aside by exepath_init().
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, exepath_init() return a non-NULL, opaque handle that may
|
||||
* subsequently be used in calls to exepath_next() and exepath_release().
|
||||
* On error, a NULL handle value will be returned. The most likely cause
|
||||
* of an error would be that the there is no value associated with the
|
||||
* PATH variable.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXEPATH_HANDLE exepath_init(void)
|
||||
{
|
||||
FAR struct exepath_s *exepath;
|
||||
FAR char *path;
|
||||
|
||||
/* Get the value of the PATH variable */
|
||||
|
||||
path = getenv("PATH");
|
||||
if (!path)
|
||||
{
|
||||
/* getenv() will return a NULL value if the PATH variable does not
|
||||
* exist in the environment.
|
||||
*/
|
||||
|
||||
return (EXEPATH_HANDLE)NULL;
|
||||
}
|
||||
|
||||
/* Allocate a container for the PATH variable contents */
|
||||
|
||||
exepath = (FAR struct exepath_s *)kmalloc(SIZEOF_EXEPATH_S(strlen(path) + 1));
|
||||
if (!exepath)
|
||||
{
|
||||
/* Ooops.. we are out of memory */
|
||||
|
||||
return (EXEPATH_HANDLE)NULL;
|
||||
}
|
||||
|
||||
/* Populate the container */
|
||||
|
||||
strcpy(exepath->path, path);
|
||||
exepath->next = exepath->path;
|
||||
|
||||
/* And return the containing cast to an opaque handle */
|
||||
|
||||
return (EXEPATH_HANDLE)exepath;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exepath_next
|
||||
*
|
||||
* Description:
|
||||
* Traverse all possible values in the PATH variable in attempt to find
|
||||
* the full path to an executable file when only a relative path is
|
||||
* provided.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle value returned by exepath_init
|
||||
* relpath - The relative path to the file to be found.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a non-NULL pointer to a null-terminated string is provided.
|
||||
* This is the full path to a file that exists in the file system. This
|
||||
* function will verify that the file exists (but will not verify that it
|
||||
* is marked executable).
|
||||
*
|
||||
* NOTE: The string pointer return in the success case points to allocated
|
||||
* memory. This memory must be freed by the called by calling kfree().
|
||||
*
|
||||
* NULL is returned if no path is found to any file with the provided
|
||||
* 'relpath' from any absolute path in the PATH variable. In this case,
|
||||
* there is no point in calling exepath_next() further; exepath_release()
|
||||
* must be called to release resources set aside by expath_init().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath)
|
||||
{
|
||||
FAR struct exepath_s *exepath = (FAR struct exepath_s *)handle;
|
||||
struct stat buf;
|
||||
FAR char *endptr;
|
||||
FAR char *path;
|
||||
FAR char *fullpath;
|
||||
int pathlen;
|
||||
int ret;
|
||||
|
||||
/* Verify that a value handle and relative path were provided */
|
||||
|
||||
DEBUGASSERT(exepath && relpath);
|
||||
DEBUGASSERT(relpath[0] != '\0' && relpath[0] != '/');
|
||||
|
||||
/* Loop until (1) we find a file with this relative path from one of the
|
||||
* absolute paths in the PATH variable, or (2) all of the absolute paths
|
||||
* in the PATH variable have been considered.
|
||||
*/
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* Make sure that exepath->next points to the beginning of a string */
|
||||
|
||||
path = exepath->next;
|
||||
if (*path == '\0')
|
||||
{
|
||||
/* If it points to a NULL it means that either (1) the PATH varialbe
|
||||
* is empty, or (2) we have already examined all of the paths in the
|
||||
* path variable.
|
||||
*/
|
||||
|
||||
return (FAR char *)NULL;
|
||||
}
|
||||
|
||||
/* Okay... 'path' points to the beginning of the string. The string may
|
||||
* be termined either with (1) ':' which separates the path from the
|
||||
* next path in the list, or (2) NUL which marks the end of the list.
|
||||
*/
|
||||
|
||||
endptr = strchr(path, ':');
|
||||
if (!endptr)
|
||||
{
|
||||
/* If strchr returns NUL it means that ':' does not appear in the
|
||||
* string. Therefore, this must be the final path in the PATH
|
||||
* variable content.
|
||||
*/
|
||||
|
||||
endptr = &path[strlen(path)];
|
||||
exepath->next = endptr;
|
||||
DEBUGASSERT(*endptr == '\0');
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUGASSERT(*endptr == ':');
|
||||
exepath->next = endptr + 1;
|
||||
*endptr = '\0';
|
||||
}
|
||||
|
||||
pathlen = strlen(path) + strlen(relpath) + 2;
|
||||
fullpath = (FAR char *)kmalloc(pathlen);
|
||||
if (!fullpath)
|
||||
{
|
||||
/* Failed to allocate memory */
|
||||
|
||||
return (FAR char *)NULL;
|
||||
}
|
||||
|
||||
/* Construct the full path */
|
||||
|
||||
sprintf(fullpath, "%s/%s", path, relpath);
|
||||
|
||||
/* Verify that a regular file exists at this path */
|
||||
|
||||
ret = stat(fullpath, &buf);;
|
||||
if (ret == OK && S_ISREG(buf.st_mode))
|
||||
{
|
||||
return fullpath;
|
||||
}
|
||||
|
||||
/* Failed to stat the file. Just free the allocated memory and
|
||||
* continue to try the next path.
|
||||
*/
|
||||
|
||||
kfree(fullpath);
|
||||
}
|
||||
|
||||
/* We will not get here */
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exepath_release
|
||||
*
|
||||
* Description:
|
||||
* Release all resources set aside by exepath_init() when the handle value
|
||||
* was created. The handle value is invalid on return from this function.
|
||||
* Attempts to all exepath_next() or exepath_release() with such a 'stale'
|
||||
* handle will result in undefined (i.e., not good) behavior.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle value returned by exepath_init
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void exepath_release(EXEPATH_HANDLE handle)
|
||||
{
|
||||
kfree(handle);
|
||||
}
|
||||
|
||||
#endif /* !CONFIG_BINFMT_DISABLE && CONFIG_BINFMT_EXEPATH */
|
||||
|
||||
@@ -43,7 +43,8 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
#include "binfmt_internal.h"
|
||||
|
||||
@@ -65,6 +66,57 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: load_absmodule
|
||||
*
|
||||
* Description:
|
||||
* Load a module into memory, bind it to an exported symbol take, and
|
||||
* prep the module for execution. bin->filename is known to be an absolute
|
||||
* path to the file to be loaded.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success; a negated errno value is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int load_absmodule(FAR struct binary_s *bin)
|
||||
{
|
||||
FAR struct binfmt_s *binfmt;
|
||||
int ret = -ENOENT;
|
||||
|
||||
bdbg("Loading %s\n", bin->filename);
|
||||
|
||||
/* Disabling pre-emption should be sufficient protection while accessing
|
||||
* the list of registered binary format handlers.
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
|
||||
/* Traverse the list of registered binary format handlers. Stop
|
||||
* when either (1) a handler recognized and loads the format, or
|
||||
* (2) no handler recognizes the format.
|
||||
*/
|
||||
|
||||
for (binfmt = g_binfmts; binfmt; binfmt = binfmt->next)
|
||||
{
|
||||
/* Use this handler to try to load the format */
|
||||
|
||||
ret = binfmt->load(bin);
|
||||
if (ret == OK)
|
||||
{
|
||||
/* Successfully loaded -- break out with ret == 0 */
|
||||
|
||||
bvdbg("Successfully loaded module %s\n", bin->filename);
|
||||
dump_module(bin);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
sched_unlock();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -85,42 +137,72 @@
|
||||
|
||||
int load_module(FAR struct binary_s *bin)
|
||||
{
|
||||
FAR struct binfmt_s *binfmt;
|
||||
int ret = -ENOENT;
|
||||
int ret = -EINVAL;
|
||||
|
||||
/* Verify that we were provided something to work with */
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (bin && bin->filename)
|
||||
#endif
|
||||
{
|
||||
bdbg("Loading %s\n", bin->filename);
|
||||
|
||||
/* Disabling pre-emption should be sufficient protection while
|
||||
* accessing the list of registered binary format handlers.
|
||||
/* Were we given a relative path? Or an absolute path to the file to
|
||||
* be loaded? Absolute paths start with '/'.
|
||||
*/
|
||||
|
||||
sched_lock();
|
||||
|
||||
/* Traverse the list of registered binary format handlers. Stop
|
||||
* when either (1) a handler recognized and loads the format, or
|
||||
* (2) no handler recognizes the format.
|
||||
*/
|
||||
|
||||
for (binfmt = g_binfmts; binfmt; binfmt = binfmt->next)
|
||||
#ifdef CONFIG_BINFMT_EXEPATH
|
||||
if (bin->filename[0] != '/')
|
||||
{
|
||||
/* Use this handler to try to load the format */
|
||||
FAR const char *relpath;
|
||||
FAR char *fullpath;
|
||||
EXEPATH_HANDLE handle;
|
||||
|
||||
ret = binfmt->load(bin);
|
||||
if (ret == OK)
|
||||
/* Set aside the relative path */
|
||||
|
||||
relpath = bin->filename;
|
||||
ret = -ENOENT;
|
||||
|
||||
/* Initialize to traverse the PATH variable */
|
||||
|
||||
handle = exepath_init();
|
||||
if (handle)
|
||||
{
|
||||
/* Successfully loaded -- break out with ret == 0 */
|
||||
/* Get the next absolute file path */
|
||||
|
||||
bvdbg("Successfully loaded module %s\n", bin->filename);
|
||||
dump_module(bin);
|
||||
break;
|
||||
while ((fullpath = exepath_next(handle, relpath)) != NULL)
|
||||
{
|
||||
/* Try to load the file at this path */
|
||||
|
||||
bin->filename = fullpath;
|
||||
ret = load_absmodule(bin);
|
||||
|
||||
/* Free the allocated fullpath */
|
||||
|
||||
kfree(fullpath);
|
||||
|
||||
/* Break out of the loop with ret == OK on success */
|
||||
|
||||
if (ret == OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sched_unlock();
|
||||
/* Restore the relative path. This is not needed for anything
|
||||
* but debug output after the file has been loaded.
|
||||
*/
|
||||
|
||||
bin->filename = relpath;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* We already have the one and only absolute path to the file to
|
||||
* be loaded.
|
||||
*/
|
||||
|
||||
ret = load_absmodule(bin);
|
||||
}
|
||||
}
|
||||
|
||||
/* This is an end-user function. Return failures via errno */
|
||||
@@ -131,6 +213,7 @@ int load_module(FAR struct binary_s *bin)
|
||||
errno = -ret;
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* binfmt/binfmt_loadmodule.c
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -45,7 +45,7 @@
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
#include "binfmt_internal.h"
|
||||
|
||||
@@ -67,6 +67,62 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exec_dtors
|
||||
*
|
||||
* Description:
|
||||
* Execute C++ static constructors.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
static inline int exec_dtors(FAR const struct binary_s *binp)
|
||||
{
|
||||
binfmt_dtor_t *dtor = binp->dtors;
|
||||
#ifdef CONFIG_ADDRENV
|
||||
hw_addrenv_t oldenv;
|
||||
int ret;
|
||||
#endif
|
||||
int i;
|
||||
|
||||
/* Instantiate the address enviroment containing the destructors */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = up_addrenv_select(binp->addrenv, &oldenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("up_addrenv_select() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Execute each destructor */
|
||||
|
||||
for (i = 0; i < binp->ndtors; i++)
|
||||
{
|
||||
bvdbg("Calling dtor %d at %p\n", i, (FAR void *)dtor);
|
||||
|
||||
(*dtor)();
|
||||
dtor++;
|
||||
}
|
||||
|
||||
/* Restore the address enviroment */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
return up_addrenv_restore(oldenv);
|
||||
#else
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -76,7 +132,12 @@
|
||||
*
|
||||
* Description:
|
||||
* Unload a (non-executing) module from memory. If the module has
|
||||
* been started (via exec_module), calling this will be fatal.
|
||||
* been started (via exec_module) and has not exited, calling this will
|
||||
* be fatal.
|
||||
*
|
||||
* However, this function must be called after the module exist. How
|
||||
* this is done is up to your logic. Perhaps you register it to be
|
||||
* called by on_exit()?
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
@@ -85,22 +146,52 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int unload_module(FAR const struct binary_s *bin)
|
||||
int unload_module(FAR const struct binary_s *binp)
|
||||
{
|
||||
if (bin)
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
int ret;
|
||||
#endif
|
||||
int i;
|
||||
|
||||
if (binp)
|
||||
{
|
||||
if (bin->ispace)
|
||||
/* Execute C++ desctructors */
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
ret = exec_dtors(binp);
|
||||
if (ret < 0)
|
||||
{
|
||||
bvdbg("Unmapping ISpace: %p\n", bin->ispace);
|
||||
munmap(bin->ispace, bin->isize);
|
||||
bdbg("exec_ctors() failed: %d\n", ret);
|
||||
set_errno(-ret);
|
||||
return ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Unmap mapped address spaces */
|
||||
|
||||
if (binp->mapped)
|
||||
{
|
||||
bvdbg("Unmapping address space: %p\n", binp->mapped);
|
||||
|
||||
munmap(binp->mapped, binp->mapsize);
|
||||
}
|
||||
|
||||
if (bin->dspace)
|
||||
/* Free allocated address spaces */
|
||||
|
||||
for (i = 0; i < BINFMT_NALLOC; i++)
|
||||
{
|
||||
bvdbg("Freeing DSpace: %p\n", bin->dspace);
|
||||
free(bin->dspace);
|
||||
if (binp->alloc[i])
|
||||
{
|
||||
bvdbg("Freeing alloc[%d]: %p\n", i, binp->alloc[i]);
|
||||
free((FAR void *)binp->alloc[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/* Notice that the address environment is not destroyed. This should
|
||||
* happen automatically when the task exits.
|
||||
*/
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
/****************************************************************************
|
||||
* binfmt/elf.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <elf32.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#ifdef CONFIG_ELF
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
|
||||
* defined or CONFIG_ELF_DUMPBUFFER does nothing.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
|
||||
# undef CONFIG_ELF_DUMPBUFFER
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ELF_STACKSIZE
|
||||
# define CONFIG_ELF_STACKSIZE 2048
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ELF_DUMPBUFFER
|
||||
# define elf_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
|
||||
#else
|
||||
# define elf_dumpbuffer(m,b,n)
|
||||
#endif
|
||||
|
||||
#ifndef MIN
|
||||
# define MIN(a,b) (a < b ? a : b)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int elf_loadbinary(FAR struct binary_s *binp);
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
|
||||
static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static struct binfmt_s g_elfbinfmt =
|
||||
{
|
||||
NULL, /* next */
|
||||
elf_loadbinary, /* load */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_dumploadinfo
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_DEBUG) && defined(CONFIG_DEBUG_BINFMT)
|
||||
static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
int i;
|
||||
|
||||
bdbg("LOAD_INFO:\n");
|
||||
bdbg(" elfalloc: %08lx\n", (long)loadinfo->elfalloc);
|
||||
bdbg(" elfsize: %ld\n", (long)loadinfo->elfsize);
|
||||
bdbg(" filelen: %ld\n", (long)loadinfo->filelen);
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
bdbg(" ctoralloc: %08lx\n", (long)loadinfo->ctoralloc);
|
||||
bdbg(" ctors: %08lx\n", (long)loadinfo->ctors);
|
||||
bdbg(" nctors: %d\n", loadinfo->nctors);
|
||||
bdbg(" dtoralloc: %08lx\n", (long)loadinfo->dtoralloc);
|
||||
bdbg(" dtors: %08lx\n", (long)loadinfo->dtors);
|
||||
bdbg(" ndtors: %d\n", loadinfo->ndtors);
|
||||
#endif
|
||||
bdbg(" filfd: %d\n", loadinfo->filfd);
|
||||
bdbg(" symtabidx: %d\n", loadinfo->symtabidx);
|
||||
bdbg(" strtabidx: %d\n", loadinfo->strtabidx);
|
||||
|
||||
bdbg("ELF Header:\n");
|
||||
bdbg(" e_ident: %02x %02x %02x %02x\n",
|
||||
loadinfo->ehdr.e_ident[0], loadinfo->ehdr.e_ident[1],
|
||||
loadinfo->ehdr.e_ident[2], loadinfo->ehdr.e_ident[3]);
|
||||
bdbg(" e_type: %04x\n", loadinfo->ehdr.e_type);
|
||||
bdbg(" e_machine: %04x\n", loadinfo->ehdr.e_machine);
|
||||
bdbg(" e_version: %08x\n", loadinfo->ehdr.e_version);
|
||||
bdbg(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry);
|
||||
bdbg(" e_phoff: %d\n", loadinfo->ehdr.e_phoff);
|
||||
bdbg(" e_shoff: %d\n", loadinfo->ehdr.e_shoff);
|
||||
bdbg(" e_flags: %08x\n" , loadinfo->ehdr.e_flags);
|
||||
bdbg(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize);
|
||||
bdbg(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize);
|
||||
bdbg(" e_phnum: %d\n", loadinfo->ehdr.e_phnum);
|
||||
bdbg(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize);
|
||||
bdbg(" e_shnum: %d\n", loadinfo->ehdr.e_shnum);
|
||||
bdbg(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx);
|
||||
|
||||
if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0)
|
||||
{
|
||||
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
|
||||
bdbg("Sections %d:\n", i);
|
||||
bdbg(" sh_name: %08x\n", shdr->sh_name);
|
||||
bdbg(" sh_type: %08x\n", shdr->sh_type);
|
||||
bdbg(" sh_flags: %08x\n", shdr->sh_flags);
|
||||
bdbg(" sh_addr: %08x\n", shdr->sh_addr);
|
||||
bdbg(" sh_offset: %d\n", shdr->sh_offset);
|
||||
bdbg(" sh_size: %d\n", shdr->sh_size);
|
||||
bdbg(" sh_link: %d\n", shdr->sh_link);
|
||||
bdbg(" sh_info: %d\n", shdr->sh_info);
|
||||
bdbg(" sh_addralign: %d\n", shdr->sh_addralign);
|
||||
bdbg(" sh_entsize: %d\n", shdr->sh_entsize);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define elf_dumploadinfo(i)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loadbinary
|
||||
*
|
||||
* Description:
|
||||
* Verify that the file is an ELF binary and, if so, load the ELF
|
||||
* binary into memory
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int elf_loadbinary(struct binary_s *binp)
|
||||
{
|
||||
struct elf_loadinfo_s loadinfo; /* Contains globals for libelf */
|
||||
int ret;
|
||||
|
||||
bvdbg("Loading file: %s\n", binp->filename);
|
||||
|
||||
/* Initialize the xflat library to load the program binary. */
|
||||
|
||||
ret = elf_init(binp->filename, &loadinfo);
|
||||
elf_dumploadinfo(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
bdbg("Failed to initialize for load of ELF program: %d\n", ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Load the program binary */
|
||||
|
||||
ret = elf_load(&loadinfo);
|
||||
elf_dumploadinfo(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
bdbg("Failed to load ELF program binary: %d\n", ret);
|
||||
goto errout_with_init;
|
||||
}
|
||||
|
||||
/* Bind the program to the exported symbol table */
|
||||
|
||||
ret = elf_bind(&loadinfo, binp->exports, binp->nexports);
|
||||
if (ret != 0)
|
||||
{
|
||||
bdbg("Failed to bind symbols program binary: %d\n", ret);
|
||||
goto errout_with_load;
|
||||
}
|
||||
|
||||
/* Return the load information */
|
||||
|
||||
binp->entrypt = (main_t)(loadinfo.elfalloc + loadinfo.ehdr.e_entry);
|
||||
binp->stacksize = CONFIG_ELF_STACKSIZE;
|
||||
|
||||
/* Add the ELF allocation to the alloc[] only if there is no address
|
||||
* enironment. If there is an address environment, it will automatically
|
||||
* be freed when the function exits
|
||||
*
|
||||
* REVISIT: If the module is loaded then unloaded, wouldn't this cause
|
||||
* a memory leak?
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
# warning "REVISIT"
|
||||
#else
|
||||
binp->alloc[0] = (FAR void *)loadinfo.elfalloc;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
/* Save information about constructors. NOTE: desctructors are not
|
||||
* yet supported.
|
||||
*/
|
||||
|
||||
binp->alloc[1] = loadinfo.ctoralloc;
|
||||
binp->ctors = loadinfo.ctors;
|
||||
binp->nctors = loadinfo.nctors;
|
||||
|
||||
binp->alloc[2] = loadinfo.dtoralloc;
|
||||
binp->dtors = loadinfo.dtors;
|
||||
binp->ndtors = loadinfo.ndtors;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
/* Save the address environment. This will be needed when the module is
|
||||
* executed for the up_addrenv_assign() call.
|
||||
*/
|
||||
|
||||
binp->addrenv = loadinfo.addrenv;
|
||||
#endif
|
||||
|
||||
elf_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt,
|
||||
MIN(loadinfo.allocsize - loadinfo.ehdr.e_entry, 512));
|
||||
|
||||
elf_uninit(&loadinfo);
|
||||
return OK;
|
||||
|
||||
errout_with_load:
|
||||
elf_unload(&loadinfo);
|
||||
errout_with_init:
|
||||
elf_uninit(&loadinfo);
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_initialize
|
||||
*
|
||||
* Description:
|
||||
* ELF support is built unconditionally. However, it order to
|
||||
* use this binary format, this function must be called during system
|
||||
* format in order to register the ELF binary format.
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_initialize(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* Register ourselves as a binfmt loader */
|
||||
|
||||
bvdbg("Registering ELF\n");
|
||||
|
||||
ret = register_binfmt(&g_elfbinfmt);
|
||||
if (ret != 0)
|
||||
{
|
||||
bdbg("Failed to register binfmt: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_uninitialize
|
||||
*
|
||||
* Description:
|
||||
* Unregister the ELF binary loader
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void elf_uninitialize(void)
|
||||
{
|
||||
unregister_binfmt(&g_elfbinfmt);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ELF */
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
############################################################################
|
||||
# binfmt/libelf/Make.defs
|
||||
#
|
||||
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_ELF),y)
|
||||
|
||||
# ELF application interfaces
|
||||
|
||||
BINFMT_CSRCS += elf.c
|
||||
|
||||
# ELF library
|
||||
|
||||
BINFMT_CSRCS += libelf_bind.c libelf_init.c libelf_addrenv.c libelf_iobuffer.c
|
||||
BINFMT_CSRCS += libelf_load.c libelf_read.c libelf_sections.c libelf_symbols.c
|
||||
BINFMT_CSRCS += libelf_uninit.c libelf_unload.c libelf_verify.c
|
||||
|
||||
ifeq ($(CONFIG_BINFMT_CONSTRUCTORS),y)
|
||||
BINFMT_CSRCS += libelf_ctors.c libelf_dtors.c
|
||||
endif
|
||||
|
||||
# Hook the libelf subdirectory into the build
|
||||
|
||||
VPATH += libelf
|
||||
SUBDIRS += libelf
|
||||
DEPPATH += --dep-path libelf
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,341 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf.h
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __BINFMT_LIBELF_LIBELF_H
|
||||
#define __BINFMT_LIBELF_LIBELF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <elf32.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_verifyheader
|
||||
*
|
||||
* Description:
|
||||
* Given the header from a possible ELF executable, verify that it is
|
||||
* an ELF executable.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_verifyheader(FAR const Elf32_Ehdr *header);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_read
|
||||
*
|
||||
* Description:
|
||||
* Read 'readsize' bytes from the object file at 'offset'. The data is
|
||||
* read into 'buffer.' If 'buffer' is part of the ELF address environment,
|
||||
* then the caller is responsibile for assuring that that address
|
||||
* environment is in place before calling this function (i.e., that
|
||||
* elf_addrenv_select() has been called if CONFIG_ADDRENV=y).
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
|
||||
size_t readsize, off_t offset);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loadshdrs
|
||||
*
|
||||
* Description:
|
||||
* Loads section headers into memory.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_loadshdrs(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_findsection
|
||||
*
|
||||
* Description:
|
||||
* A section by its name.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* sectname - Name of the section to find
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, the index to the section is returned; A negated errno value
|
||||
* is returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_findsection(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const char *sectname);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_findsymtab
|
||||
*
|
||||
* Description:
|
||||
* Find the symbol table section.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_findsymtab(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_readsym
|
||||
*
|
||||
* Description:
|
||||
* Read the ELFT symbol structure at the specfied index into memory.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* index - Symbol table index
|
||||
* sym - Location to return the table entry
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_readsym(FAR struct elf_loadinfo_s *loadinfo, int index,
|
||||
FAR Elf32_Sym *sym);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_symvalue
|
||||
*
|
||||
* Description:
|
||||
* Get the value of a symbol. The updated value of the symbol is returned
|
||||
* in the st_value field of the symbol table entry.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* sym - Symbol table entry (value might be undefined)
|
||||
* exports - The symbol table to use for resolving undefined symbols.
|
||||
* nexports - Number of symbols in the symbol table.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_symvalue(FAR struct elf_loadinfo_s *loadinfo, FAR Elf32_Sym *sym,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_freebuffers
|
||||
*
|
||||
* Description:
|
||||
* Release all working buffers.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_freebuffers(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_allocbuffer
|
||||
*
|
||||
* Description:
|
||||
* Perform the initial allocation of the I/O buffer, if it has not already
|
||||
* been allocated.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_allocbuffer(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_reallocbuffer
|
||||
*
|
||||
* Description:
|
||||
* Increase the size of I/O buffer by the specified buffer increment.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_reallocbuffer(FAR struct elf_loadinfo_s *loadinfo, size_t increment);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_findctors
|
||||
*
|
||||
* Description:
|
||||
* Find C++ static constructors.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
int elf_loadctors(FAR struct elf_loadinfo_s *loadinfo);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loaddtors
|
||||
*
|
||||
* Description:
|
||||
* Load pointers to static destructors into an in-memory array.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
int elf_loaddtors(FAR struct elf_loadinfo_s *loadinfo);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_addrenv_alloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
|
||||
* elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
|
||||
* elfalloc will be allocated using up_addrenv_create(). In either case,
|
||||
* there will be a unique instance of elfalloc (and stack) for each
|
||||
* instance of a process.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* envsize - The size (in bytes) of the address environment needed for the
|
||||
* ELF image.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo, size_t envsize);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_addrenv_select
|
||||
*
|
||||
* Description:
|
||||
* Temporarity select the task's address environemnt.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
# define elf_addrenv_select(l) up_addrenv_select((l)->addrenv, &(l)->oldenv)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_addrenv_restore
|
||||
*
|
||||
* Description:
|
||||
* Restore the address environment before elf_addrenv_select() was called..
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
# define elf_addrenv_restore(l) up_addrenv_restore((l)->oldenv)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_addrenv_free
|
||||
*
|
||||
* Description:
|
||||
* Release the address environment previously created by
|
||||
* elf_addrenv_alloc(). This function is called only under certain error
|
||||
* conditions after the the module has been loaded but not yet started.
|
||||
* After the module has been started, the address environment will
|
||||
* automatically be freed when the module exits.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void elf_addrenv_free(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
#endif /* __BINFMT_LIBELF_LIBELF_H */
|
||||
@@ -0,0 +1,176 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_addrenv.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_addrenv_alloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
|
||||
* elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
|
||||
* elfalloc will be allocated using up_addrenv_create(). In either case,
|
||||
* there will be a unique instance of elfalloc (and stack) for each
|
||||
* instance of a process.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* envsize - The size (in bytes) of the address environment needed for the
|
||||
* ELF image.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_addrenv_alloc(FAR struct elf_loadinfo_s *loadinfo, size_t envsize)
|
||||
{
|
||||
#ifdef CONFIG_ADDRENV
|
||||
FAR void *vaddr;
|
||||
int ret;
|
||||
|
||||
/* Create an address environment for the new ELF task */
|
||||
|
||||
ret = up_addrenv_create(envsize, &loadinfo->addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: up_addrenv_create failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get the virtual address associated with the start of the address
|
||||
* environment. This is the base address that we will need to use to
|
||||
* access the ELF image (but only if the address environment has been
|
||||
* selected.
|
||||
*/
|
||||
|
||||
ret = up_addrenv_vaddr(loadinfo->addrenv, &vaddr);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: up_addrenv_vaddr failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
loadinfo->elfalloc = (uintptr_t)vaddr;
|
||||
return OK;
|
||||
#else
|
||||
/* Allocate memory to hold the ELF image */
|
||||
|
||||
loadinfo->elfalloc = (uintptr_t)kzalloc(envsize);
|
||||
if (!loadinfo->elfalloc)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_addrenv_free
|
||||
*
|
||||
* Description:
|
||||
* Release the address environment previously created by
|
||||
* elf_addrenv_create(). This function is called only under certain error
|
||||
* conditions after the the module has been loaded but not yet started.
|
||||
* After the module has been started, the address environment will
|
||||
* automatically be freed when the module exits.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void elf_addrenv_free(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int ret;
|
||||
|
||||
/* Free the address environemnt */
|
||||
|
||||
ret = up_addrenv_destroy(loadinfo->addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: up_addrenv_destroy failed: %d\n", ret);
|
||||
}
|
||||
|
||||
/* Clear out all indications of the allocated address environment */
|
||||
|
||||
loadinfo->elfalloc = 0;
|
||||
loadinfo->elfsize = 0;
|
||||
loadinfo->addrenv = 0;
|
||||
#else
|
||||
/* If there is an allocation for the ELF image, free it */
|
||||
|
||||
if (loadinfo->elfalloc != 0)
|
||||
{
|
||||
kfree((FAR void *)loadinfo->elfalloc);
|
||||
loadinfo->elfalloc = 0;
|
||||
}
|
||||
|
||||
loadinfo->elfsize = 0;
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,334 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_bind.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <elf32.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* CONFIG_DEBUG, CONFIG_DEBUG_VERBOSE, and CONFIG_DEBUG_BINFMT have to be
|
||||
* defined or CONFIG_ELF_DUMPBUFFER does nothing.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_DEBUG_VERBOSE) || !defined (CONFIG_DEBUG_BINFMT)
|
||||
# undef CONFIG_ELF_DUMPBUFFER
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ELF_BUFFERSIZE
|
||||
# define CONFIG_ELF_BUFFERSIZE 128
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ELF_DUMPBUFFER
|
||||
# define elf_dumpbuffer(m,b,n) bvdbgdumpbuffer(m,b,n)
|
||||
#else
|
||||
# define elf_dumpbuffer(m,b,n)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_readrel
|
||||
*
|
||||
* Description:
|
||||
* Read the ELF32_Rel structure into memory.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int elf_readrel(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const Elf32_Shdr *relsec,
|
||||
int index, FAR Elf32_Rel *rel)
|
||||
{
|
||||
off_t offset;
|
||||
|
||||
/* Verify that the symbol table index lies within symbol table */
|
||||
|
||||
if (index < 0 || index > (relsec->sh_size / sizeof(Elf32_Rel)))
|
||||
{
|
||||
bdbg("Bad relocation symbol index: %d\n", index);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* Get the file offset to the symbol table entry */
|
||||
|
||||
offset = relsec->sh_offset + sizeof(Elf32_Rel) * index;
|
||||
|
||||
/* And, finally, read the symbol table entry into memory */
|
||||
|
||||
return elf_read(loadinfo, (FAR uint8_t*)rel, sizeof(Elf32_Rel), offset);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_relocate and elf_relocateadd
|
||||
*
|
||||
* Description:
|
||||
* Perform all relocations associated with a section.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int elf_relocate(FAR struct elf_loadinfo_s *loadinfo, int relidx,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
|
||||
{
|
||||
FAR Elf32_Shdr *relsec = &loadinfo->shdr[relidx];
|
||||
FAR Elf32_Shdr *dstsec = &loadinfo->shdr[relsec->sh_info];
|
||||
Elf32_Rel rel;
|
||||
Elf32_Sym sym;
|
||||
uintptr_t addr;
|
||||
int symidx;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Examine each relocation in the section. 'relsec' is the section
|
||||
* containing the relations. 'dstsec' is the section containing the data
|
||||
* to be relocated.
|
||||
*/
|
||||
|
||||
for (i = 0; i < relsec->sh_size / sizeof(Elf32_Rel); i++)
|
||||
{
|
||||
/* Read the relocation entry into memory */
|
||||
|
||||
ret = elf_readrel(loadinfo, relsec, i, &rel);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Section %d reloc %d: Failed to read relocation entry: %d\n",
|
||||
relidx, i, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get the symbol table index for the relocation. This is contained
|
||||
* in a bit-field within the r_info element.
|
||||
*/
|
||||
|
||||
symidx = ELF32_R_SYM(rel.r_info);
|
||||
|
||||
/* Read the symbol table entry into memory */
|
||||
|
||||
ret = elf_readsym(loadinfo, symidx, &sym);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Section %d reloc %d: Failed to read symbol[%d]: %d\n",
|
||||
relidx, i, symidx, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Get the value of the symbol (in sym.st_value) */
|
||||
|
||||
ret = elf_symvalue(loadinfo, &sym, exports, nexports);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Section %d reloc %d: Failed to get value of symbol[%d]: %d\n",
|
||||
relidx, i, symidx, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Calculate the relocation address. */
|
||||
|
||||
if (rel.r_offset < 0 || rel.r_offset > dstsec->sh_size - sizeof(uint32_t))
|
||||
{
|
||||
bdbg("Section %d reloc %d: Relocation address out of range, offset %d size %d\n",
|
||||
relidx, i, rel.r_offset, dstsec->sh_size);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
addr = dstsec->sh_addr + rel.r_offset;
|
||||
|
||||
/* If CONFIG_ADDRENV=y, then 'addr' lies in a virtual address space that
|
||||
* may not be in place now. elf_addrenv_select() will temporarily
|
||||
* instantiate that address space.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = elf_addrenv_select(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: elf_addrenv_select() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now perform the architecture-specific relocation */
|
||||
|
||||
ret = arch_relocate(&rel, &sym, addr);
|
||||
if (ret < 0)
|
||||
{
|
||||
#ifdef CONFIG_ADDRENV
|
||||
(void)elf_addrenv_restore(loadinfo);
|
||||
#endif
|
||||
bdbg("ERROR: Section %d reloc %d: Relocation failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Restore the original address environment */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = elf_addrenv_restore(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: elf_addrenv_restore() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int elf_relocateadd(FAR struct elf_loadinfo_s *loadinfo, int relidx,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
{
|
||||
bdbg("Not implemented\n");
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_bind
|
||||
*
|
||||
* Description:
|
||||
* Bind the imported symbol names in the loaded module described by
|
||||
* 'loadinfo' using the exported symbol values provided by 'symtab'.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
{
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Find the symbol and string tables */
|
||||
|
||||
ret = elf_findsymtab(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Allocate an I/O buffer. This buffer is used by elf_symname() to
|
||||
* accumulate the variable length symbol name.
|
||||
*/
|
||||
|
||||
ret = elf_allocbuffer(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_allocbuffer failed: %d\n", ret);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
/* Process relocations in every allocated section */
|
||||
|
||||
for (i = 1; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
/* Get the index to the relocation section */
|
||||
|
||||
int infosec = loadinfo->shdr[i].sh_info;
|
||||
if (infosec >= loadinfo->ehdr.e_shnum)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Make sure that the section is allocated. We can't relocated
|
||||
* sections that were not loaded into memory.
|
||||
*/
|
||||
|
||||
if ((loadinfo->shdr[infosec].sh_flags & SHF_ALLOC) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Process the relocations by type */
|
||||
|
||||
if (loadinfo->shdr[i].sh_type == SHT_REL)
|
||||
{
|
||||
ret = elf_relocate(loadinfo, i, exports, nexports);
|
||||
}
|
||||
else if (loadinfo->shdr[i].sh_type == SHT_RELA)
|
||||
{
|
||||
ret = elf_relocateadd(loadinfo, i, exports, nexports);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Flush the instruction cache before starting the newly loaded module */
|
||||
|
||||
#ifdef CONFIG_ELF_ICACHE
|
||||
arch_flushicache((FAR void*)loadinfo->elfalloc, loadinfo->elfsize);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_load.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <elf32.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define ELF_ALIGN_MASK ((1 << CONFIG_ELF_ALIGN_LOG2) - 1)
|
||||
#define ELF_ALIGNUP(a) (((unsigned long)(a) + ELF_ALIGN_MASK) & ~ELF_ALIGN_MASK)
|
||||
#define ELF_ALIGNDOWN(a) ((unsigned long)(a) & ~ELF_ALIGN_MASK)
|
||||
|
||||
|
||||
#ifndef MAX
|
||||
#define MAX(x,y) ((x) > (y) ? (x) : (y))
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_elfsize
|
||||
*
|
||||
* Description:
|
||||
* Calculate total memory allocation for the ELF file.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void elf_elfsize(struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
size_t elfsize;
|
||||
int i;
|
||||
|
||||
/* Accumulate the size each section into memory that is marked SHF_ALLOC */
|
||||
|
||||
elfsize = 0;
|
||||
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
|
||||
|
||||
/* SHF_ALLOC indicates that the section requires memory during
|
||||
* execution.
|
||||
*/
|
||||
|
||||
if ((shdr->sh_flags & SHF_ALLOC) != 0)
|
||||
{
|
||||
elfsize += ELF_ALIGNUP(shdr->sh_size);
|
||||
}
|
||||
}
|
||||
|
||||
/* Save the allocation size */
|
||||
|
||||
loadinfo->elfsize = elfsize;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_loadfile
|
||||
*
|
||||
* Description:
|
||||
* Allocate memory for the file and read the section data into the
|
||||
* allocated memory. Section addresses in the shdr[] are updated to point
|
||||
* to the corresponding position in the allocated memory.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int elf_loadfile(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
FAR uint8_t *dest;
|
||||
int ret;
|
||||
int i;
|
||||
|
||||
/* Allocate (and zero) memory for the ELF file. */
|
||||
|
||||
ret = elf_addrenv_alloc(loadinfo, loadinfo->elfsize);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: elf_addrenv_alloc() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Read each section into memory that is marked SHF_ALLOC + SHT_NOBITS */
|
||||
|
||||
bvdbg("Loaded sections:\n");
|
||||
dest = (FAR uint8_t*)loadinfo->elfalloc;
|
||||
|
||||
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
|
||||
{
|
||||
FAR Elf32_Shdr *shdr = &loadinfo->shdr[i];
|
||||
|
||||
/* SHF_ALLOC indicates that the section requires memory during
|
||||
* execution */
|
||||
|
||||
if ((shdr->sh_flags & SHF_ALLOC) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
/* SHT_NOBITS indicates that there is no data in the file for the
|
||||
* section.
|
||||
*/
|
||||
|
||||
if (shdr->sh_type != SHT_NOBITS)
|
||||
{
|
||||
/* If CONFIG_ADDRENV=y, then 'dest' lies in a virtual address space
|
||||
* that may not be in place now. elf_addrenv_select() will
|
||||
* temporarily instantiate that address space.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = elf_addrenv_select(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: elf_addrenv_select() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Read the section data from sh_offset to dest */
|
||||
|
||||
ret = elf_read(loadinfo, dest, shdr->sh_size, shdr->sh_offset);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Failed to read section %d: %d\n", i, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Restore the original address environment */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = elf_addrenv_restore(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: elf_addrenv_restore() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Update sh_addr to point to copy in memory */
|
||||
|
||||
bvdbg("%d. %08x->%08x\n", i, (long)shdr->sh_addr, (long)dest);
|
||||
shdr->sh_addr = (uintptr_t)dest;
|
||||
|
||||
/* Setup the memory pointer for the next time through the loop */
|
||||
|
||||
dest += ELF_ALIGNUP(shdr->sh_size);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_load
|
||||
*
|
||||
* Description:
|
||||
* Loads the binary into memory, allocating memory, performing relocations
|
||||
* and inializing the data and bss segments.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_load(FAR struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
int ret;
|
||||
|
||||
bvdbg("loadinfo: %p\n", loadinfo);
|
||||
DEBUGASSERT(loadinfo && loadinfo->filfd >= 0);
|
||||
|
||||
/* Load section headers into memory */
|
||||
|
||||
ret = elf_loadshdrs(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_loadshdrs failed: %d\n", ret);
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
|
||||
/* Determine total size to allocate */
|
||||
|
||||
elf_elfsize(loadinfo);
|
||||
|
||||
/* Allocate memory and load sections into memory */
|
||||
|
||||
ret = elf_loadfile(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_loadfile failed: %d\n", ret);
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
|
||||
/* Load static constructors and destructors. */
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
ret = elf_loadctors(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_loadctors failed: %d\n", ret);
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
|
||||
ret = elf_loaddtors(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("elf_loaddtors failed: %d\n", ret);
|
||||
goto errout_with_buffers;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
|
||||
/* Error exits */
|
||||
|
||||
errout_with_buffers:
|
||||
elf_unload(loadinfo);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_read.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <elf32.h>
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#undef ELF_DUMP_READDATA /* Define to dump all file data read */
|
||||
#define DUMPER lib_rawprintf /* If ELF_DUMP_READDATA is defined, this
|
||||
* is the API used to dump data */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_dumpreaddata
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(ELF_DUMP_READDATA)
|
||||
static inline void elf_dumpreaddata(char *buffer, int buflen)
|
||||
{
|
||||
uint32_t *buf32 = (uint32_t*)buffer;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
for (i = 0; i < buflen; i += 32)
|
||||
{
|
||||
DUMPER("%04x:", i);
|
||||
for (j = 0; j < 32; j += sizeof(uint32_t))
|
||||
{
|
||||
DUMPER(" %08x", *buf32++);
|
||||
}
|
||||
DUMPER("\n");
|
||||
}
|
||||
}
|
||||
#else
|
||||
# define elf_dumpreaddata(b,n)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_read
|
||||
*
|
||||
* Description:
|
||||
* Read 'readsize' bytes from the object file at 'offset'. The data is
|
||||
* read into 'buffer.' If 'buffer' is part of the ELF address environment,
|
||||
* then the caller is responsibile for assuring that that address
|
||||
* environment is in place before calling this function (i.e., that
|
||||
* elf_addrenv_select() has been called if CONFIG_ADDRENV=y).
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
|
||||
size_t readsize, off_t offset)
|
||||
{
|
||||
ssize_t nbytes; /* Number of bytes read */
|
||||
off_t rpos; /* Position returned by lseek */
|
||||
|
||||
bvdbg("Read %ld bytes from offset %ld\n", (long)readsize, (long)offset);
|
||||
|
||||
/* Loop until all of the requested data has been read. */
|
||||
|
||||
while (readsize > 0)
|
||||
{
|
||||
/* Seek to the next read position */
|
||||
|
||||
rpos = lseek(loadinfo->filfd, offset, SEEK_SET);
|
||||
if (rpos != offset)
|
||||
{
|
||||
int errval = errno;
|
||||
bdbg("Failed to seek to position %ld: %d\n", (long)offset, errval);
|
||||
return -errval;
|
||||
}
|
||||
|
||||
/* Read the file data at offset into the user buffer */
|
||||
|
||||
nbytes = read(loadinfo->filfd, buffer, readsize);
|
||||
if (nbytes < 0)
|
||||
{
|
||||
int errval = errno;
|
||||
|
||||
/* EINTR just means that we received a signal */
|
||||
|
||||
if (errval != EINTR)
|
||||
{
|
||||
bdbg("Read of .data failed: %d\n", errval);
|
||||
return -errval;
|
||||
}
|
||||
}
|
||||
else if (nbytes == 0)
|
||||
{
|
||||
bdbg("Unexpected end of file\n");
|
||||
return -ENODATA;
|
||||
}
|
||||
else
|
||||
{
|
||||
readsize -= nbytes;
|
||||
buffer += nbytes;
|
||||
offset += nbytes;
|
||||
}
|
||||
}
|
||||
|
||||
elf_dumpreaddata(buffer, readsize);
|
||||
return OK;
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libelf/libelf_unload.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/elf.h>
|
||||
|
||||
#include "libelf.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_unload
|
||||
*
|
||||
* Description:
|
||||
* This function unloads the object from memory. This essentially undoes
|
||||
* the actions of elf_load. It is called only under certain error
|
||||
* conditions after the the module has been loaded but not yet started.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int elf_unload(struct elf_loadinfo_s *loadinfo)
|
||||
{
|
||||
/* Free all working buffers */
|
||||
|
||||
elf_freebuffers(loadinfo);
|
||||
|
||||
/* Release memory holding the relocated ELF image */
|
||||
|
||||
elf_addrenv_free(loadinfo);
|
||||
|
||||
/* Release memory used to hold static constructors and destructors */
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
if (loadinfo->ctoralloc != 0)
|
||||
{
|
||||
kfree(loadinfo->ctoralloc);
|
||||
loadinfo->ctoralloc = NULL;
|
||||
}
|
||||
|
||||
loadinfo->ctors = NULL;
|
||||
loadinfo->nctors = 0;
|
||||
|
||||
if (loadinfo->dtoralloc != 0)
|
||||
{
|
||||
kfree(loadinfo->dtoralloc);
|
||||
loadinfo->dtoralloc = NULL;
|
||||
}
|
||||
|
||||
loadinfo->dtors = NULL;
|
||||
loadinfo->ndtors = 0;
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
############################################################################
|
||||
# nxflat/lib/Make.defs
|
||||
# binfmt/libnxflat/Make.defs
|
||||
#
|
||||
# Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
@@ -33,7 +33,22 @@
|
||||
#
|
||||
############################################################################
|
||||
|
||||
LIBNXFLAT_ASRCS =
|
||||
LIBNXFLAT_CSRCS = libnxflat_init.c libnxflat_uninit.c libnxflat_load.c \
|
||||
libnxflat_unload.c libnxflat_verify.c libnxflat_read.c \
|
||||
libnxflat_bind.c
|
||||
ifeq ($(CONFIG_NXFLAT),y)
|
||||
|
||||
# NXFLAT application interfaces
|
||||
|
||||
BINFMT_CSRCS += nxflat.c
|
||||
|
||||
# NXFLAT library
|
||||
|
||||
BINFMT_CSRCS += libnxflat_init.c libnxflat_uninit.c libnxflat_addrenv.c
|
||||
BINFMT_CSRCS += libnxflat_load.c libnxflat_unload.c libnxflat_verify.c
|
||||
BINFMT_CSRCS += libnxflat_read.c libnxflat_bind.c
|
||||
|
||||
# Hook the libnxflat subdirectory into the build
|
||||
|
||||
VPATH += libnxflat
|
||||
SUBDIRS += libnxflat
|
||||
DEPPATH += --dep-path libnxflat
|
||||
|
||||
endif
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libnxflat/libnxflat.h
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __BINFMT_LIBNXFLAT_LIBNXFLAT_H
|
||||
#define __BINFMT_LIBNXFLAT_LIBNXFLAT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/binfmt/nxflat.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_addrenv_alloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
|
||||
* elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
|
||||
* elfalloc will be allocated using up_addrenv_create(). In either case,
|
||||
* there will be a unique instance of elfalloc (and stack) for each
|
||||
* instance of a process.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* envsize - The size (in bytes) of the address environment needed for the
|
||||
* ELF image.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nxflat_addrenv_alloc(FAR struct nxflat_loadinfo_s *loadinfo, size_t envsize);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_addrenv_select
|
||||
*
|
||||
* Description:
|
||||
* Temporarity select the task's address environemnt.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
# define nxflat_addrenv_select(l) up_addrenv_select((l)->addrenv, &(l)->oldenv)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_addrenv_restore
|
||||
*
|
||||
* Description:
|
||||
* Restore the address environment before nxflat_addrenv_select() was called..
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
# define nxflat_addrenv_restore(l) up_addrenv_restore((l)->oldenv)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_addrenv_free
|
||||
*
|
||||
* Description:
|
||||
* Release the address environment previously created by
|
||||
* nxflat_addrenv_create(). This function is called only under certain
|
||||
* error conditions after the the module has been loaded but not yet
|
||||
* started. After the module has been started, the address environment
|
||||
* will automatically be freed when the module exits.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void nxflat_addrenv_free(FAR struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
#endif /* __BINFMT_LIBNXFLAT_LIBNXFLAT_H */
|
||||
@@ -0,0 +1,235 @@
|
||||
/****************************************************************************
|
||||
* binfmt/libnxflat/libnxflat_addrenv.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
|
||||
#include "libnxflat.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_addrenv_alloc
|
||||
*
|
||||
* Description:
|
||||
* Allocate memory for the ELF image (elfalloc). If CONFIG_ADDRENV=n,
|
||||
* elfalloc will be allocated using kzalloc(). If CONFIG_ADDRENV-y, then
|
||||
* elfalloc will be allocated using up_addrenv_create(). In either case,
|
||||
* there will be a unique instance of elfalloc (and stack) for each
|
||||
* instance of a process.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
* envsize - The size (in bytes) of the address environment needed for the
|
||||
* ELF image.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int nxflat_addrenv_alloc(FAR struct nxflat_loadinfo_s *loadinfo, size_t envsize)
|
||||
{
|
||||
FAR struct dspace_s *dspace;
|
||||
#ifdef CONFIG_ADDRENV
|
||||
FAR void *vaddr;
|
||||
hw_addrenv_t oldenv;
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
DEBUGASSERT(!loadinfo->dspace);
|
||||
|
||||
/* Allocate the struct dspace_s container for the D-Space allocation */
|
||||
|
||||
dspace = (FAR struct dspace_s *)kmalloc(sizeof(struct dspace_s));
|
||||
if (dspace == 0)
|
||||
{
|
||||
bdbg("ERROR: Failed to allocate DSpace\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
/* Create a D-Space address environment for the new NXFLAT task */
|
||||
|
||||
ret = up_addrenv_create(envsize, &loadinfo->addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: up_addrenv_create failed: %d\n", ret);
|
||||
goto errout_with_dspace;
|
||||
}
|
||||
|
||||
/* Get the virtual address associated with the start of the address
|
||||
* environment. This is the base address that we will need to use to
|
||||
* access the D-Space region (but only if the address environment has been
|
||||
* selected.
|
||||
*/
|
||||
|
||||
ret = up_addrenv_vaddr(loadinfo->addrenv, &vaddr);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: up_addrenv_vaddr failed: %d\n", ret);
|
||||
goto errout_with_addrenv;
|
||||
}
|
||||
|
||||
/* Clear all of the allocated D-Space memory. We have to temporarily
|
||||
* selected the D-Space address environment to do this.
|
||||
*/
|
||||
|
||||
ret = up_addrenv_select(loadinfo->addrenv, &oldenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: up_addrenv_select failed: %d\n", ret);
|
||||
goto errout_with_addrenv;
|
||||
}
|
||||
|
||||
memset(vaddr, 0, envsize);
|
||||
|
||||
ret = up_addrenv_restore(oldenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: up_addrenv_restore failed: %d\n", ret);
|
||||
goto errout_with_addrenv;
|
||||
}
|
||||
|
||||
/* Success... save the fruits of our labor */
|
||||
|
||||
loadinfo->dspace = dspace;
|
||||
dspace->crefs = 1;
|
||||
dspace->region = (FAR uint8_t *)vaddr;
|
||||
return OK;
|
||||
|
||||
errout_with_addrenv:
|
||||
(void)up_addrenv_destroy(loadinfo->addrenv);
|
||||
loadinfo->addrenv = 0;
|
||||
|
||||
errout_with_dspace:
|
||||
kfree(dspace);
|
||||
return ret;
|
||||
#else
|
||||
/* Allocate (and zero) memory to hold the ELF image */
|
||||
|
||||
dspace->region = (FAR uint8_t *)kzalloc(envsize);
|
||||
if (!dspace->region)
|
||||
{
|
||||
kfree(dspace);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
loadinfo->dspace = dspace;
|
||||
dspace->crefs = 1;
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_addrenv_free
|
||||
*
|
||||
* Description:
|
||||
* Release the address environment previously created by
|
||||
* nxflat_addrenv_create(). This function is called only under certain
|
||||
* error conditions after the the module has been loaded but not yet
|
||||
* started. After the module has been started, the address environment
|
||||
* will automatically be freed when the module exits.
|
||||
*
|
||||
* Input Parameters:
|
||||
* loadinfo - Load state information
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void nxflat_addrenv_free(FAR struct nxflat_loadinfo_s *loadinfo)
|
||||
{
|
||||
FAR struct dspace_s *dspace;
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
DEBUGASSERT(loadinfo);
|
||||
dspace = loadinfo->dspace;
|
||||
|
||||
if (dspace)
|
||||
{
|
||||
#ifdef CONFIG_ADDRENV
|
||||
/* Destroy the address environment */
|
||||
|
||||
ret = up_addrenv_destroy(loadinfo->addrenv);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: up_addrenv_destroy failed: %d\n", ret);
|
||||
}
|
||||
|
||||
loadinfo->addrenv = 0;
|
||||
#else
|
||||
/* Free the allocated D-Space region */
|
||||
|
||||
if (dspace->region)
|
||||
{
|
||||
kfree(dspace->region);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now destroy the D-Space container */
|
||||
|
||||
DEBUGASSERT(dspace->crefs == 1);
|
||||
kfree(dspace);
|
||||
loadinfo->dspace = NULL;
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
@@ -47,8 +48,11 @@
|
||||
#include <debug.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <nuttx/nxflat.h>
|
||||
#include <nuttx/symtab.h>
|
||||
|
||||
#include <nuttx/binfmt/nxflat.h>
|
||||
#include <nuttx/binfmt/symtab.h>
|
||||
|
||||
#include "libnxflat.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@@ -229,8 +233,6 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
|
||||
|
||||
hdr = (FAR struct nxflat_hdr_s*)loadinfo->ispace;
|
||||
|
||||
/* From this, we can get the list of relocation entries. */
|
||||
|
||||
/* From this, we can get the offset to the list of relocation entries */
|
||||
|
||||
offset = ntohl(hdr->h_relocstart);
|
||||
@@ -247,11 +249,27 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
|
||||
DEBUGASSERT(offset + nrelocs * sizeof(struct nxflat_reloc_s)
|
||||
<= (loadinfo->isize + loadinfo->dsize));
|
||||
|
||||
relocs = (FAR struct nxflat_reloc_s*)
|
||||
relocs = (FAR struct nxflat_reloc_s *)
|
||||
(offset - loadinfo->isize + loadinfo->dspace->region);
|
||||
bvdbg("isize: %08lx dpsace: %p relocs: %p\n",
|
||||
(long)loadinfo->isize, loadinfo->dspace->region, relocs);
|
||||
|
||||
/* All relocations are performed within the D-Space allocation. If
|
||||
* CONFIG_ADDRENV=y, then that D-Space allocation lies in an address
|
||||
* environment that may not be in place. So, in that case, we must call
|
||||
* nxflat_addrenv_select to temporarily instantiate that address space
|
||||
* before the relocations can be performed.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = nxflat_addrenv_select(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now, traverse the relocation list of and bind each GOT relocation. */
|
||||
|
||||
ret = OK; /* Assume success */
|
||||
@@ -259,11 +277,16 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
|
||||
{
|
||||
/* Handle the relocation by the relocation type */
|
||||
|
||||
#ifdef CONFIG_CAN_PASS_STRUCTS
|
||||
reloc = *relocs++;
|
||||
#else
|
||||
memcpy(&reloc, relocs, sizeof(struct nxflat_reloc_s));
|
||||
relocs++;
|
||||
#endif
|
||||
|
||||
result = OK;
|
||||
switch (NXFLAT_RELOC_TYPE(reloc.r_info))
|
||||
{
|
||||
|
||||
/* NXFLAT_RELOC_TYPE_REL32I Meaning: Object file contains a 32-bit offset
|
||||
* into I-Space at the offset.
|
||||
* Fixup: Add mapped I-Space address to the offset.
|
||||
@@ -329,6 +352,17 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
|
||||
nxflat_dumpbuffer("GOT", (FAR const uint8_t*)relocs, nrelocs * sizeof(struct nxflat_reloc_s));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Restore the original address environment */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = nxflat_addrenv_restore(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -346,16 +380,19 @@ static inline int nxflat_gotrelocs(FAR struct nxflat_loadinfo_s *loadinfo)
|
||||
****************************************************************************/
|
||||
|
||||
static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
FAR const struct symtab_s *exports,
|
||||
int nexports)
|
||||
FAR const struct symtab_s *exports,
|
||||
int nexports)
|
||||
{
|
||||
FAR struct nxflat_import_s *imports;
|
||||
FAR struct nxflat_hdr_s *hdr;
|
||||
FAR const struct symtab_s *symbol;
|
||||
FAR const struct symtab_s *symbol;
|
||||
|
||||
char *symname;
|
||||
uint32_t offset;
|
||||
uint16_t nimports;
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int ret;
|
||||
#endif
|
||||
int i;
|
||||
|
||||
/* The NXFLAT header is the first thing at the beginning of the ISpace. */
|
||||
@@ -370,6 +407,22 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
nimports = ntohs(hdr->h_importcount);
|
||||
bvdbg("Imports offset: %08x nimports: %d\n", offset, nimports);
|
||||
|
||||
/* The import[] table resides within the D-Space allocation. If
|
||||
* CONFIG_ADDRENV=y, then that D-Space allocation lies in an address
|
||||
* environment that may not be in place. So, in that case, we must call
|
||||
* nxflat_addrenv_select to temporarily instantiate that address space
|
||||
* before the import[] table can be modified.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = nxflat_addrenv_select(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Verify that this module requires imported symbols */
|
||||
|
||||
if (offset != 0 && nimports > 0)
|
||||
@@ -388,7 +441,7 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
offset < loadinfo->isize + loadinfo->dsize);
|
||||
|
||||
imports = (struct nxflat_import_s*)
|
||||
(offset - loadinfo->isize + loadinfo->dspace->region);
|
||||
(offset - loadinfo->isize + loadinfo->dspace->region);
|
||||
|
||||
/* Now, traverse the list of imported symbols and attempt to bind
|
||||
* each symbol to the value exported by from the exported symbol
|
||||
@@ -396,41 +449,44 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
*/
|
||||
|
||||
for (i = 0; i < nimports; i++)
|
||||
{
|
||||
bvdbg("Import[%d] (%08p) offset: %08x func: %08x\n",
|
||||
i, &imports[i], imports[i].i_funcname, imports[i].i_funcaddress);
|
||||
{
|
||||
bvdbg("Import[%d] (%08p) offset: %08x func: %08x\n",
|
||||
i, &imports[i], imports[i].i_funcname, imports[i].i_funcaddress);
|
||||
|
||||
/* Get a pointer to the imported symbol name. The name itself
|
||||
* lies in the TEXT segment. But the reference to the name
|
||||
* lies in DATA segment. Therefore, the name reference should
|
||||
* have been relocated when the module was loaded.
|
||||
*/
|
||||
/* Get a pointer to the imported symbol name. The name itself
|
||||
* lies in the TEXT segment. But the reference to the name
|
||||
* lies in DATA segment. Therefore, the name reference should
|
||||
* have been relocated when the module was loaded.
|
||||
*/
|
||||
|
||||
offset = imports[i].i_funcname;
|
||||
DEBUGASSERT(offset < loadinfo->isize);
|
||||
|
||||
symname = (char*)(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s));
|
||||
symname = (char*)(offset + loadinfo->ispace + sizeof(struct nxflat_hdr_s));
|
||||
|
||||
/* Find the exported symbol value for this this symbol name. */
|
||||
/* Find the exported symbol value for this this symbol name. */
|
||||
|
||||
#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
|
||||
symbol = symtab_findorderedbyname(exports, symname, nexports);
|
||||
#else
|
||||
symbol = symtab_findbyname(exports, symname, nexports);
|
||||
#endif
|
||||
if (!symbol)
|
||||
{
|
||||
bdbg("Exported symbol \"%s\" not found\n", symname);
|
||||
if (!symbol)
|
||||
{
|
||||
bdbg("Exported symbol \"%s\" not found\n", symname);
|
||||
#ifdef CONFIG_ADDRENV
|
||||
(void)nxflat_addrenv_restore(loadinfo);
|
||||
#endif
|
||||
return -ENOENT;
|
||||
}
|
||||
}
|
||||
|
||||
/* And put this into the module's import structure. */
|
||||
/* And put this into the module's import structure. */
|
||||
|
||||
imports[i].i_funcaddress = (uint32_t)symbol->sym_value;
|
||||
imports[i].i_funcaddress = (uint32_t)symbol->sym_value;
|
||||
|
||||
bvdbg("Bound import[%d] (%08p) to export '%s' (%08x)\n",
|
||||
i, &imports[i], symname, imports[i].i_funcaddress);
|
||||
}
|
||||
bvdbg("Bound import[%d] (%08p) to export '%s' (%08x)\n",
|
||||
i, &imports[i], symname, imports[i].i_funcaddress);
|
||||
}
|
||||
}
|
||||
|
||||
/* Dump the relocation import table */
|
||||
@@ -441,7 +497,74 @@ static inline int nxflat_bindimports(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
nxflat_dumpbuffer("Imports", (FAR const uint8_t*)imports, nimports * sizeof(struct nxflat_import_s));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Restore the original address environment */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = nxflat_addrenv_restore(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_clearbss
|
||||
*
|
||||
* Description:
|
||||
* Clear uninitialized .bss memory
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline int nxflat_clearbss(FAR struct nxflat_loadinfo_s *loadinfo)
|
||||
{
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int ret;
|
||||
#endif
|
||||
|
||||
/* .bss resides within the D-Space allocation. If CONFIG_ADDRENV=y, then
|
||||
* that D-Space allocation lies in an address environment that may not be
|
||||
* in place. So, in that case, we must call nxflat_addrenv_select to
|
||||
* temporarily instantiate that address space before the .bss can be
|
||||
* accessed.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = nxflat_addrenv_select(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Zero the BSS area */
|
||||
|
||||
memset((void*)(loadinfo->dspace->region + loadinfo->datasize), 0,
|
||||
loadinfo->bsssize);
|
||||
|
||||
/* Restore the original address environment */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = nxflat_addrenv_restore(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
#else
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@@ -483,10 +606,10 @@ int nxflat_bind(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
* space in the loaded file.
|
||||
*/
|
||||
|
||||
memset((void*)(loadinfo->dspace->region + loadinfo->datasize),
|
||||
0, loadinfo->bsssize);
|
||||
ret = nxflat_clearbss(loadinfo);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <nxflat.h>
|
||||
@@ -48,7 +49,10 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <nuttx/nxflat.h>
|
||||
|
||||
#include <nuttx/binfmt/nxflat.h>
|
||||
|
||||
#include "libnxflat.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
@@ -62,24 +66,6 @@
|
||||
* Private Constant Data
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_DEBUG_VERBOSE) && defined(CONFIG_DEBUG_BINFMT)
|
||||
static const char g_relocrel32i[] = "RELOC_REL32I";
|
||||
static const char g_relocrel32d[] = "RELOC_REL32D";
|
||||
static const char g_relocabs32[] = "RELOC_AB32";
|
||||
static const char g_undefined[] = "UNDEFINED";
|
||||
|
||||
static const char *g_reloctype[] =
|
||||
{
|
||||
g_relocrel32i,
|
||||
g_relocrel32d,
|
||||
g_relocabs32,
|
||||
g_undefined
|
||||
};
|
||||
# define RELONAME(rl) g_reloctype[NXFLAT_RELOC_TYPE(rl)]
|
||||
#else
|
||||
# define RELONAME(rl) "(no name)"
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
@@ -161,7 +147,7 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
|
||||
*/
|
||||
|
||||
loadinfo->ispace = (uint32_t)mmap(NULL, loadinfo->isize, PROT_READ,
|
||||
MAP_SHARED|MAP_FILE, loadinfo->filfd, 0);
|
||||
MAP_SHARED|MAP_FILE, loadinfo->filfd, 0);
|
||||
if (loadinfo->ispace == (uint32_t)MAP_FAILED)
|
||||
{
|
||||
bdbg("Failed to map NXFLAT ISpace: %d\n", errno);
|
||||
@@ -170,23 +156,37 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
|
||||
|
||||
bvdbg("Mapped ISpace (%d bytes) at %08x\n", loadinfo->isize, loadinfo->ispace);
|
||||
|
||||
/* The following call will give a pointer to the allocated but
|
||||
* uninitialized ISpace memory.
|
||||
/* The following call allocate D-Space memory and will provide a pointer
|
||||
* to the allocated (but still uninitialized) D-Space memory.
|
||||
*/
|
||||
|
||||
loadinfo->dspace = (struct dspace_s *)malloc(SIZEOF_DSPACE_S(loadinfo->dsize));
|
||||
if (loadinfo->dspace == 0)
|
||||
ret = nxflat_addrenv_alloc(loadinfo, loadinfo->dsize);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("Failed to allocate DSpace\n");
|
||||
ret = -ENOMEM;
|
||||
goto errout;
|
||||
bdbg("ERROR: nxflat_addrenv_alloc() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
loadinfo->dspace->crefs = 1;
|
||||
|
||||
bvdbg("Allocated DSpace (%d bytes) at %p\n", loadinfo->dsize, loadinfo->dspace->region);
|
||||
bvdbg("Allocated DSpace (%d bytes) at %p\n",
|
||||
loadinfo->dsize, loadinfo->dspace->region);
|
||||
|
||||
/* Now, read the data into allocated DSpace at doffset into the
|
||||
* allocated DSpace memory.
|
||||
/* If CONFIG_ADDRENV=y, then the D-Space allocation lies in an address
|
||||
* environment that may not be in place. So, in that case, we must call
|
||||
* nxflat_addrenv_select to temporarily instantiate that address space
|
||||
* it can be initialized.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = nxflat_addrenv_select(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: nxflat_addrenv_select() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Now, read the data into allocated DSpace at doffset into the allocated
|
||||
* DSpace memory.
|
||||
*/
|
||||
|
||||
ret = nxflat_read(loadinfo, (char*)loadinfo->dspace->region, dreadsize, doffset);
|
||||
@@ -199,9 +199,23 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
|
||||
bvdbg("TEXT: %08x Entry point offset: %08x Data offset: %08x\n",
|
||||
loadinfo->ispace, loadinfo->entryoffs, doffset);
|
||||
|
||||
/* Restore the original address environment */
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
ret = nxflat_addrenv_restore(loadinfo);
|
||||
if (ret < 0)
|
||||
{
|
||||
bdbg("ERROR: nxflat_addrenv_restore() failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return OK;
|
||||
|
||||
errout:
|
||||
#ifdef CONFIG_ADDRENV
|
||||
(void)nxflat_addrenv_restore(loadinfo);
|
||||
#endif
|
||||
(void)nxflat_unload(loadinfo);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -40,10 +40,14 @@
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/nxflat.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/binfmt/nxflat.h>
|
||||
|
||||
#include "libnxflat.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
@@ -65,8 +69,9 @@
|
||||
* Name: nxflat_unload
|
||||
*
|
||||
* Description:
|
||||
* This function unloads the object from memory. This essentially
|
||||
* undoes the actions of nxflat_load.
|
||||
* This function unloads the object from memory. This essentially undoes
|
||||
* the actions of nxflat_load. It is called only under certain error
|
||||
* conditions after the the module has been loaded but not yet started.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
@@ -76,9 +81,8 @@
|
||||
|
||||
int nxflat_unload(struct nxflat_loadinfo_s *loadinfo)
|
||||
{
|
||||
/* Reset the contents of the info structure. */
|
||||
|
||||
/* Release the memory segments */
|
||||
/* Release the I-Space mmap'ed file */
|
||||
|
||||
if (loadinfo->ispace)
|
||||
{
|
||||
@@ -86,12 +90,8 @@ int nxflat_unload(struct nxflat_loadinfo_s *loadinfo)
|
||||
loadinfo->ispace = 0;
|
||||
}
|
||||
|
||||
if (loadinfo->dspace)
|
||||
{
|
||||
free((void*)loadinfo->dspace);
|
||||
loadinfo->dspace = 0;
|
||||
}
|
||||
/* Release the D-Space address environment */
|
||||
|
||||
nxflat_addrenv_free(loadinfo);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
+32
-9
@@ -47,8 +47,8 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <nuttx/binfmt.h>
|
||||
#include <nuttx/nxflat.h>
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
#include <nuttx/binfmt/nxflat.h>
|
||||
|
||||
#ifdef CONFIG_NXFLAT
|
||||
|
||||
@@ -158,7 +158,7 @@ static int nxflat_loadbinary(struct binary_s *binp)
|
||||
nxflat_dumploadinfo(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
bdbg("Failed to initialize for load of NXFLT program: %d\n", ret);
|
||||
bdbg("Failed to initialize for load of NXFLAT program: %d\n", ret);
|
||||
goto errout;
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ static int nxflat_loadbinary(struct binary_s *binp)
|
||||
nxflat_dumploadinfo(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
bdbg("Failed to load NXFLT program binary: %d\n", ret);
|
||||
bdbg("Failed to load NXFLAT program binary: %d\n", ret);
|
||||
goto errout_with_init;
|
||||
}
|
||||
|
||||
@@ -181,16 +181,39 @@ static int nxflat_loadbinary(struct binary_s *binp)
|
||||
goto errout_with_load;
|
||||
}
|
||||
|
||||
/* Return the load information */
|
||||
/* Return the load information. By convention, D-space address
|
||||
* space is stored as the first allocated memory.
|
||||
*/
|
||||
|
||||
binp->entrypt = (main_t)(loadinfo.ispace + loadinfo.entryoffs);
|
||||
binp->ispace = (void*)loadinfo.ispace;
|
||||
binp->dspace = (void*)loadinfo.dspace;
|
||||
binp->isize = loadinfo.isize;
|
||||
binp->mapped = (void*)loadinfo.ispace;
|
||||
binp->mapsize = loadinfo.isize;
|
||||
binp->stacksize = loadinfo.stacksize;
|
||||
|
||||
/* Add the ELF allocation to the alloc[] only if there is no address
|
||||
* enironment. If there is an address environment, it will automatically
|
||||
* be freed when the function exits
|
||||
*
|
||||
* REVISIT: If the module is loaded then unloaded, wouldn't this cause
|
||||
* a memory leak?
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
# warning "REVISIT"
|
||||
#else
|
||||
binp->alloc[0] = (void*)loadinfo.dspace;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
/* Save the address environment. This will be needed when the module is
|
||||
* executed for the up_addrenv_assign() call.
|
||||
*/
|
||||
|
||||
binp->addrenv = loadinfo.addrenv;
|
||||
#endif
|
||||
|
||||
nxflat_dumpbuffer("Entry code", (FAR const uint8_t*)binp->entrypt,
|
||||
MIN(binp->isize - loadinfo.entryoffs,512));
|
||||
MIN(loadinfo.isize - loadinfo.entryoffs, 512));
|
||||
|
||||
nxflat_uninit(&loadinfo);
|
||||
return OK;
|
||||
|
||||
@@ -151,6 +151,9 @@ defconfig -- This is a configuration file similar to the Linux
|
||||
CONFIG_ARCH_IRQPRIO
|
||||
Define if the architecture suports prioritizaton of interrupts
|
||||
and the up_prioritize_irq() API.
|
||||
CONFIG_ADDRENV
|
||||
The CPU supports an MMU and CPU port supports provision of address
|
||||
environments for tasks (making the, perhaps, processes).
|
||||
|
||||
Some architectures require a description of the RAM configuration:
|
||||
|
||||
@@ -1690,28 +1693,48 @@ configs/pcblogic-pic32mx
|
||||
STATUS: Code complete but testing has been stalled due to tool related problems
|
||||
(PICkit 2 does not work with the PIC32).
|
||||
|
||||
configs/pic32-starterkit
|
||||
configs/p112
|
||||
The P112 is notable because it was the first of the hobbyist single board
|
||||
computers to reach the production stage. The P112 hobbyist computers
|
||||
were relatively widespread and inspired other hobbyist centered home brew
|
||||
computing projects such as N8VEM home brew computing project. The P112
|
||||
project still maintains many devoted enthusiasts and has an online
|
||||
repository of software and other information.
|
||||
|
||||
The P112 computer originated as a commercial product of "D-X Designs Pty
|
||||
Ltd" of Australia. They describe the computer as "The P112 is a stand-alone
|
||||
8-bit CPU board. Typically running CP/M (tm) or a similar operating system,
|
||||
it provides a Z80182 (Z-80 upgrade) CPU with up to 1MB of memory, serial,
|
||||
parallel and diskette IO, and realtime clock, in a 3.5-inch drive form factor.
|
||||
Powered solely from 5V, it draws 150mA (nominal: not including disk drives)
|
||||
with a 16MHz CPU clock. Clock speeds up to 24.576MHz are possible."
|
||||
|
||||
The P112 board was last available new in 1996 by Dave Brooks. In late 2004
|
||||
on the Usenet Newsgroup comp.os.cpm, talk about making another run of P112
|
||||
boards was discussed. David Griffith decided to produce additional P112 kits
|
||||
with Dave Brooks blessing and the assistance of others. In addition Terry
|
||||
Gulczynski makes additional P112 derivative hobbyist home brew computers.
|
||||
Hal Bower was very active in the mid 1990's on the P112 project and ported
|
||||
the "Banked/Portable BIOS".
|
||||
|
||||
Dave Brooks was successfully funded through Kickstarter for and another
|
||||
run of P112 boards in November of 2012.
|
||||
|
||||
configs/pic32-starterkit
|
||||
This directory contains the port of NuttX to the Microchip PIC32 Ethernet
|
||||
Starter Kit (DM320004) with the Multimedia Expansion Board (MEB, DM320005).
|
||||
See www.microchip.com for further information.
|
||||
|
||||
configs/pic32mx7mmb
|
||||
|
||||
This directory will (eventually) contain the port of NuttX to the
|
||||
Mikroelektronika PIC32MX7 Multimedia Board (MMB). See
|
||||
http://www.mikroe.com/ for further information.
|
||||
|
||||
STATUS: Basic OS test configuration is in place, but the board does not boot.
|
||||
It looks like I will need an ICD3 in order to debug the code (PICkit3
|
||||
doesn't work for debug with this board). This effort is temporarily stalled.
|
||||
|
||||
configs/pjrc-8051
|
||||
8051 Microcontroller. This port uses the PJRC 87C52 development system
|
||||
and the SDCC toolchain. This port is not quite ready for prime time.
|
||||
|
||||
configs/qemu-i486
|
||||
|
||||
Port of NuttX to QEMU in i486 mode. This port will also run on real i486
|
||||
hardwared (Google the Bifferboard).
|
||||
|
||||
|
||||
+17
-16
@@ -34,6 +34,7 @@
|
||||
############################################################################
|
||||
|
||||
-include $(TOPDIR)/Make.defs
|
||||
DELIM ?= $(strip /)
|
||||
|
||||
ifeq ($(WINTOOL),y)
|
||||
INCDIROPT = -w
|
||||
@@ -48,22 +49,22 @@ VPATH = .
|
||||
# files to the source file list, add its DEPPATH info, and will add
|
||||
# the appropriate paths to the VPATH variable
|
||||
|
||||
include analog/Make.defs
|
||||
include bch/Make.defs
|
||||
include input/Make.defs
|
||||
include lcd/Make.defs
|
||||
include mmcsd/Make.defs
|
||||
include mtd/Make.defs
|
||||
include net/Make.defs
|
||||
include pipes/Make.defs
|
||||
include power/Make.defs
|
||||
include sensors/Make.defs
|
||||
include sercomm/Make.defs
|
||||
include serial/Make.defs
|
||||
include syslog/Make.defs
|
||||
include usbdev/Make.defs
|
||||
include usbhost/Make.defs
|
||||
include wireless/Make.defs
|
||||
include analog$(DELIM)Make.defs
|
||||
include bch$(DELIM)Make.defs
|
||||
include input$(DELIM)Make.defs
|
||||
include lcd$(DELIM)Make.defs
|
||||
include mmcsd$(DELIM)Make.defs
|
||||
include mtd$(DELIM)Make.defs
|
||||
include net$(DELIM)Make.defs
|
||||
include pipes$(DELIM)Make.defs
|
||||
include power$(DELIM)Make.defs
|
||||
include sensors$(DELIM)Make.defs
|
||||
include sercomm$(DELIM)Make.defs
|
||||
include serial$(DELIM)Make.defs
|
||||
include syslog$(DELIM)Make.defs
|
||||
include usbdev$(DELIM)Make.defs
|
||||
include usbhost$(DELIM)Make.defs
|
||||
include wireless$(DELIM)Make.defs
|
||||
|
||||
ifneq ($(CONFIG_NFILE_DESCRIPTORS),0)
|
||||
CSRCS += dev_null.c dev_zero.c loop.c
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# drivers/analog/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -76,12 +76,12 @@ endif
|
||||
ifeq ($(CONFIG_DAC),y)
|
||||
DEPPATH += --dep-path analog
|
||||
VPATH += :analog
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/analog}
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)analog}
|
||||
else
|
||||
ifeq ($(CONFIG_ADC),y)
|
||||
DEPPATH += --dep-path analog
|
||||
VPATH += :analog
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/analog}
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)analog}
|
||||
endif
|
||||
endif
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# drivers/bch/Make.defs
|
||||
#
|
||||
# Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -46,7 +46,7 @@ CSRCS += bchlib_setup.c bchlib_teardown.c bchlib_read.c bchlib_write.c \
|
||||
|
||||
DEPPATH += --dep-path bch
|
||||
VPATH += :bch
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/bch}
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)bch}
|
||||
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# drivers/input/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -47,6 +47,10 @@ ifeq ($(CONFIG_INPUT_ADS7843E),y)
|
||||
CSRCS += ads7843e.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_INPUT_MAX11802),y)
|
||||
CSRCS += max11802.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_INPUT_STMPE811),y)
|
||||
CSRCS += stmpe811_base.c
|
||||
ifneq ($(CONFIG_INPUT_STMPE811_TSC_DISABLE),y)
|
||||
@@ -67,6 +71,6 @@ endif
|
||||
|
||||
DEPPATH += --dep-path input
|
||||
VPATH += :input
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/input}
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)input}
|
||||
endif
|
||||
|
||||
|
||||
@@ -47,6 +47,10 @@ ifeq ($(CONFIG_LCD_NOKIA6100),y)
|
||||
CSRCS += nokia6100.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LCD_UG2864AMBAG01),y)
|
||||
CSRCS += ug-2864ambag01.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_LCD_UG9664HSWAG01),y)
|
||||
CSRCS += ug-9664hswag01.c
|
||||
endif
|
||||
@@ -63,6 +67,6 @@ endif
|
||||
|
||||
DEPPATH += --dep-path lcd
|
||||
VPATH += :lcd
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/lcd}
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)lcd}
|
||||
endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -215,7 +215,7 @@ static ssize_t loop_read(FAR struct inode *inode, unsigned char *buffer,
|
||||
size_t start_sector, unsigned int nsectors)
|
||||
{
|
||||
FAR struct loop_struct_s *dev;
|
||||
size_t nbytesread;
|
||||
ssize_t nbytesread;
|
||||
off_t offset;
|
||||
int ret;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# drivers/mmcsd/Make.defs
|
||||
#
|
||||
# Copyright (C) 2008, 2011 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,14 +33,24 @@
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_MMCSD),y)
|
||||
|
||||
# Include MMC/SD drivers
|
||||
|
||||
CSRCS += mmcsd_sdio.c mmcsd_spi.c mmcsd_debug.c
|
||||
ifeq ($(CONFIG_MMCSD_SDIO),y)
|
||||
CSRCS += mmcsd_sdio.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_MMCSD_SPI),y)
|
||||
CSRCS += mmcsd_spi.c mmcsd_debug.c
|
||||
endif
|
||||
|
||||
# Include MMC/SD driver build support
|
||||
|
||||
DEPPATH += --dep-path mmcsd
|
||||
VPATH += :mmcsd
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/mmcsd}
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)mmcsd}
|
||||
|
||||
endif
|
||||
|
||||
|
||||
|
||||
@@ -2597,7 +2597,8 @@ static int mmcsd_cardidentify(FAR struct mmcsd_state_s *priv)
|
||||
* operating condition. CMD 8 is reserved on SD version 1.0 and MMC.
|
||||
*
|
||||
* CMD8 Argument:
|
||||
* [31:12]: Reserved (shall be set to '0')
|
||||
* [31:12]: Reserved (shall be set to '0')
|
||||
* [11:8]: Supply Voltage (VHS) 0x1 (Range: 2.7-3.6 V)
|
||||
* [7:0]: Check Pattern (recommended 0xaa)
|
||||
* CMD8 Response: R7
|
||||
*/
|
||||
|
||||
@@ -51,6 +51,10 @@ ifeq ($(CONFIG_MTD_W25),y)
|
||||
CSRCS += w25.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_MTD_AT25),y)
|
||||
CSRCS += at25.c
|
||||
endif
|
||||
|
||||
# Include MTD driver support
|
||||
|
||||
DEPPATH += --dep-path mtd
|
||||
|
||||
@@ -0,0 +1,708 @@
|
||||
/************************************************************************************
|
||||
* drivers/mtd/at25.c
|
||||
* Driver for SPI-based AT25DF321 (32Mbit) flash.
|
||||
*
|
||||
* Copyright (C) 2009-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
* Petteri Aimonen <jpa@nx.mail.kapsi.fi>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/spi.h>
|
||||
#include <nuttx/mtd.h>
|
||||
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef CONFIG_AT25_SPIMODE
|
||||
# define CONFIG_AT25_SPIMODE SPIDEV_MODE0
|
||||
#endif
|
||||
|
||||
/* AT25 Registers *******************************************************************/
|
||||
/* Indentification register values */
|
||||
|
||||
#define AT25_MANUFACTURER 0x1F
|
||||
#define AT25_AT25DF321_TYPE 0x47 /* 32 M-bit */
|
||||
|
||||
/* AT25DF321 capacity is 4,194,304 bytes:
|
||||
* (64 sectors) * (65,536 bytes per sector)
|
||||
* (16384 pages) * (256 bytes per page)
|
||||
*/
|
||||
|
||||
#define AT25_AT25DF321_SECTOR_SHIFT 12 /* Sector size 1 << 12 = 4096 */
|
||||
#define AT25_AT25DF321_NSECTORS 1024
|
||||
#define AT25_AT25DF321_PAGE_SHIFT 9 /* Page size 1 << 9 = 512 */
|
||||
#define AT25_AT25DF321_NPAGES 8192
|
||||
|
||||
/* Instructions */
|
||||
/* Command Value N Description Addr Dummy Data */
|
||||
#define AT25_WREN 0x06 /* 1 Write Enable 0 0 0 */
|
||||
#define AT25_WRDI 0x04 /* 1 Write Disable 0 0 0 */
|
||||
#define AT25_RDID 0x9f /* 1 Read Identification 0 0 1-3 */
|
||||
#define AT25_RDSR 0x05 /* 1 Read Status Register 0 0 >=1 */
|
||||
#define AT25_WRSR 0x01 /* 1 Write Status Register 0 0 1 */
|
||||
#define AT25_READ 0x03 /* 1 Read Data Bytes 3 0 >=1 */
|
||||
#define AT25_FAST_READ 0x0b /* 1 Higher speed read 3 1 >=1 */
|
||||
#define AT25_PP 0x02 /* 1 Page Program 3 0 1-256 */
|
||||
#define AT25_SE 0x20 /* 1 Sector Erase 3 0 0 */
|
||||
#define AT25_BE 0xc7 /* 1 Bulk Erase 0 0 0 */
|
||||
#define AT25_DP 0xb9 /* 2 Deep power down 0 0 0 */
|
||||
#define AT25_RES 0xab /* 2 Read Electronic Signature 0 3 >=1 */
|
||||
|
||||
/* Status register bit definitions */
|
||||
|
||||
#define AT25_SR_WIP (1 << 0) /* Bit 0: Write in progress bit */
|
||||
#define AT25_SR_WEL (1 << 1) /* Bit 1: Write enable latch bit */
|
||||
#define AT25_SR_EPE (1 << 5) /* Bit 5: Erase/program error */
|
||||
#define AT25_SR_UNPROT 0x00 /* Global unprotect command */
|
||||
|
||||
#define AT25_DUMMY 0xa5
|
||||
|
||||
/************************************************************************************
|
||||
* Private Types
|
||||
************************************************************************************/
|
||||
|
||||
/* This type represents the state of the MTD device. The struct mtd_dev_s
|
||||
* must appear at the beginning of the definition so that you can freely
|
||||
* cast between pointers to struct mtd_dev_s and struct at25_dev_s.
|
||||
*/
|
||||
|
||||
struct at25_dev_s
|
||||
{
|
||||
struct mtd_dev_s mtd; /* MTD interface */
|
||||
FAR struct spi_dev_s *dev; /* Saved SPI interface instance */
|
||||
uint8_t sectorshift; /* 16 or 18 */
|
||||
uint8_t pageshift; /* 8 */
|
||||
uint16_t nsectors; /* 128 or 64 */
|
||||
uint32_t npages; /* 32,768 or 65,536 */
|
||||
};
|
||||
|
||||
/************************************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************************************/
|
||||
|
||||
/* Helpers */
|
||||
|
||||
static void at25_lock(FAR struct spi_dev_s *dev);
|
||||
static inline void at25_unlock(FAR struct spi_dev_s *dev);
|
||||
static inline int at25_readid(struct at25_dev_s *priv);
|
||||
static void at25_waitwritecomplete(struct at25_dev_s *priv);
|
||||
static void at25_writeenable(struct at25_dev_s *priv);
|
||||
static inline void at25_sectorerase(struct at25_dev_s *priv, off_t offset);
|
||||
static inline int at25_bulkerase(struct at25_dev_s *priv);
|
||||
static inline void at25_pagewrite(struct at25_dev_s *priv, FAR const uint8_t *buffer,
|
||||
off_t offset);
|
||||
|
||||
/* MTD driver methods */
|
||||
|
||||
static int at25_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks);
|
||||
static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR uint8_t *buf);
|
||||
static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
||||
size_t nblocks, FAR const uint8_t *buf);
|
||||
static ssize_t at25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
FAR uint8_t *buffer);
|
||||
static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
|
||||
|
||||
/************************************************************************************
|
||||
* Private Data
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_lock
|
||||
************************************************************************************/
|
||||
|
||||
static void at25_lock(FAR struct spi_dev_s *dev)
|
||||
{
|
||||
/* On SPI busses where there are multiple devices, it will be necessary to
|
||||
* lock SPI to have exclusive access to the busses for a sequence of
|
||||
* transfers. The bus should be locked before the chip is selected.
|
||||
*
|
||||
* This is a blocking call and will not return until we have exclusiv access to
|
||||
* the SPI buss. We will retain that exclusive access until the bus is unlocked.
|
||||
*/
|
||||
|
||||
(void)SPI_LOCK(dev, true);
|
||||
|
||||
/* After locking the SPI bus, the we also need call the setfrequency, setbits, and
|
||||
* setmode methods to make sure that the SPI is properly configured for the device.
|
||||
* If the SPI buss is being shared, then it may have been left in an incompatible
|
||||
* state.
|
||||
*/
|
||||
|
||||
SPI_SETMODE(dev, CONFIG_AT25_SPIMODE);
|
||||
SPI_SETBITS(dev, 8);
|
||||
(void)SPI_SETFREQUENCY(dev, 20000000);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_unlock
|
||||
************************************************************************************/
|
||||
|
||||
static inline void at25_unlock(FAR struct spi_dev_s *dev)
|
||||
{
|
||||
(void)SPI_LOCK(dev, false);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_readid
|
||||
************************************************************************************/
|
||||
|
||||
static inline int at25_readid(struct at25_dev_s *priv)
|
||||
{
|
||||
uint16_t manufacturer;
|
||||
uint16_t memory;
|
||||
uint16_t version;
|
||||
|
||||
fvdbg("priv: %p\n", priv);
|
||||
|
||||
/* Lock the SPI bus, configure the bus, and select this FLASH part. */
|
||||
|
||||
at25_lock(priv->dev);
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
|
||||
|
||||
/* Send the "Read ID (RDID)" command and read the first three ID bytes */
|
||||
|
||||
(void)SPI_SEND(priv->dev, AT25_RDID);
|
||||
manufacturer = SPI_SEND(priv->dev, AT25_DUMMY);
|
||||
memory = SPI_SEND(priv->dev, AT25_DUMMY);
|
||||
|
||||
/* Deselect the FLASH and unlock the bus */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
|
||||
at25_unlock(priv->dev);
|
||||
|
||||
fvdbg("manufacturer: %02x memory: %02x\n",
|
||||
manufacturer, memory);
|
||||
|
||||
/* Check for a valid manufacturer and memory type */
|
||||
|
||||
if (manufacturer == AT25_MANUFACTURER && memory == AT25_AT25DF321_TYPE)
|
||||
{
|
||||
priv->sectorshift = AT25_AT25DF321_SECTOR_SHIFT;
|
||||
priv->nsectors = AT25_AT25DF321_NSECTORS;
|
||||
priv->pageshift = AT25_AT25DF321_PAGE_SHIFT;
|
||||
priv->npages = AT25_AT25DF321_NPAGES;
|
||||
return OK;
|
||||
}
|
||||
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_waitwritecomplete
|
||||
************************************************************************************/
|
||||
|
||||
static void at25_waitwritecomplete(struct at25_dev_s *priv)
|
||||
{
|
||||
uint8_t status;
|
||||
|
||||
/* Are we the only device on the bus? */
|
||||
|
||||
#ifdef CONFIG_SPI_OWNBUS
|
||||
|
||||
/* Select this FLASH part */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
|
||||
|
||||
/* Send "Read Status Register (RDSR)" command */
|
||||
|
||||
(void)SPI_SEND(priv->dev, AT25_RDSR);
|
||||
|
||||
/* Loop as long as the memory is busy with a write cycle */
|
||||
|
||||
do
|
||||
{
|
||||
/* Send a dummy byte to generate the clock needed to shift out the status */
|
||||
|
||||
status = SPI_SEND(priv->dev, AT25_DUMMY);
|
||||
}
|
||||
while ((status & AT25_SR_WIP) != 0);
|
||||
|
||||
/* Deselect the FLASH */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
|
||||
|
||||
#else
|
||||
|
||||
/* Loop as long as the memory is busy with a write cycle */
|
||||
|
||||
do
|
||||
{
|
||||
/* Select this FLASH part */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
|
||||
|
||||
/* Send "Read Status Register (RDSR)" command */
|
||||
|
||||
(void)SPI_SEND(priv->dev, AT25_RDSR);
|
||||
|
||||
/* Send a dummy byte to generate the clock needed to shift out the status */
|
||||
|
||||
status = SPI_SEND(priv->dev, AT25_DUMMY);
|
||||
|
||||
/* Deselect the FLASH */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
|
||||
|
||||
/* Given that writing could take up to few tens of milliseconds, and erasing
|
||||
* could take more. The following short delay in the "busy" case will allow
|
||||
* other peripherals to access the SPI bus.
|
||||
*/
|
||||
|
||||
if ((status & AT25_SR_WIP) != 0)
|
||||
{
|
||||
at25_unlock(priv->dev);
|
||||
usleep(10000);
|
||||
at25_lock(priv->dev);
|
||||
}
|
||||
}
|
||||
while ((status & AT25_SR_WIP) != 0);
|
||||
#endif
|
||||
|
||||
if (status & AT25_SR_EPE)
|
||||
{
|
||||
fdbg("Write error, status: 0x%02x\n", status);
|
||||
}
|
||||
|
||||
fvdbg("Complete, status: 0x%02x\n", status);
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_writeenable
|
||||
************************************************************************************/
|
||||
|
||||
static void at25_writeenable(struct at25_dev_s *priv)
|
||||
{
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
|
||||
(void)SPI_SEND(priv->dev, AT25_WREN);
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
|
||||
fvdbg("Enabled\n");
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_sectorerase
|
||||
************************************************************************************/
|
||||
|
||||
static inline void at25_sectorerase(struct at25_dev_s *priv, off_t sector)
|
||||
{
|
||||
off_t offset = sector << priv->sectorshift;
|
||||
|
||||
fvdbg("sector: %08lx\n", (long)sector);
|
||||
|
||||
/* Wait for any preceding write to complete. We could simplify things by
|
||||
* perform this wait at the end of each write operation (rather than at
|
||||
* the beginning of ALL operations), but have the wait first will slightly
|
||||
* improve performance.
|
||||
*/
|
||||
|
||||
at25_waitwritecomplete(priv);
|
||||
|
||||
/* Send write enable instruction */
|
||||
|
||||
at25_writeenable(priv);
|
||||
|
||||
/* Select this FLASH part */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
|
||||
|
||||
/* Send the "Sector Erase (SE)" instruction */
|
||||
|
||||
(void)SPI_SEND(priv->dev, AT25_SE);
|
||||
|
||||
/* Send the sector offset high byte first. For all of the supported
|
||||
* parts, the sector number is completely contained in the first byte
|
||||
* and the values used in the following two bytes don't really matter.
|
||||
*/
|
||||
|
||||
(void)SPI_SEND(priv->dev, (offset >> 16) & 0xff);
|
||||
(void)SPI_SEND(priv->dev, (offset >> 8) & 0xff);
|
||||
(void)SPI_SEND(priv->dev, offset & 0xff);
|
||||
|
||||
/* Deselect the FLASH */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
|
||||
fvdbg("Erased\n");
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_bulkerase
|
||||
************************************************************************************/
|
||||
|
||||
static inline int at25_bulkerase(struct at25_dev_s *priv)
|
||||
{
|
||||
fvdbg("priv: %p\n", priv);
|
||||
|
||||
/* Wait for any preceding write to complete. We could simplify things by
|
||||
* perform this wait at the end of each write operation (rather than at
|
||||
* the beginning of ALL operations), but have the wait first will slightly
|
||||
* improve performance.
|
||||
*/
|
||||
|
||||
at25_waitwritecomplete(priv);
|
||||
|
||||
/* Send write enable instruction */
|
||||
|
||||
at25_writeenable(priv);
|
||||
|
||||
/* Select this FLASH part */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
|
||||
|
||||
/* Send the "Bulk Erase (BE)" instruction */
|
||||
|
||||
(void)SPI_SEND(priv->dev, AT25_BE);
|
||||
|
||||
/* Deselect the FLASH */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
|
||||
fvdbg("Return: OK\n");
|
||||
return OK;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_pagewrite
|
||||
************************************************************************************/
|
||||
|
||||
static inline void at25_pagewrite(struct at25_dev_s *priv, FAR const uint8_t *buffer,
|
||||
off_t page)
|
||||
{
|
||||
off_t offset = page << 8;
|
||||
|
||||
fvdbg("page: %08lx offset: %08lx\n", (long)page, (long)offset);
|
||||
|
||||
/* Wait for any preceding write to complete. We could simplify things by
|
||||
* perform this wait at the end of each write operation (rather than at
|
||||
* the beginning of ALL operations), but have the wait first will slightly
|
||||
* improve performance.
|
||||
*/
|
||||
|
||||
at25_waitwritecomplete(priv);
|
||||
|
||||
/* Enable the write access to the FLASH */
|
||||
|
||||
at25_writeenable(priv);
|
||||
|
||||
/* Select this FLASH part */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
|
||||
|
||||
/* Send "Page Program (PP)" command */
|
||||
|
||||
(void)SPI_SEND(priv->dev, AT25_PP);
|
||||
|
||||
/* Send the page offset high byte first. */
|
||||
|
||||
(void)SPI_SEND(priv->dev, (offset >> 16) & 0xff);
|
||||
(void)SPI_SEND(priv->dev, (offset >> 8) & 0xff);
|
||||
(void)SPI_SEND(priv->dev, offset & 0xff);
|
||||
|
||||
/* Then write the specified number of bytes */
|
||||
|
||||
SPI_SNDBLOCK(priv->dev, buffer, 256);
|
||||
|
||||
/* Deselect the FLASH: Chip Select high */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
|
||||
fvdbg("Written\n");
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_erase
|
||||
************************************************************************************/
|
||||
|
||||
static int at25_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks)
|
||||
{
|
||||
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
||||
size_t blocksleft = nblocks;
|
||||
|
||||
fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
||||
|
||||
/* Lock access to the SPI bus until we complete the erase */
|
||||
|
||||
at25_lock(priv->dev);
|
||||
while (blocksleft-- > 0)
|
||||
{
|
||||
/* Erase each sector */
|
||||
|
||||
at25_sectorerase(priv, startblock);
|
||||
startblock++;
|
||||
}
|
||||
|
||||
at25_unlock(priv->dev);
|
||||
return (int)nblocks;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_bread
|
||||
************************************************************************************/
|
||||
|
||||
static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks,
|
||||
FAR uint8_t *buffer)
|
||||
{
|
||||
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
||||
ssize_t nbytes;
|
||||
|
||||
fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
||||
|
||||
/* On this device, we can handle the block read just like the byte-oriented read */
|
||||
|
||||
nbytes = at25_read(dev, startblock << priv->pageshift, nblocks << priv->pageshift, buffer);
|
||||
if (nbytes > 0)
|
||||
{
|
||||
return nbytes >> priv->pageshift;
|
||||
}
|
||||
|
||||
return (int)nbytes;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_bwrite
|
||||
************************************************************************************/
|
||||
|
||||
static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks,
|
||||
FAR const uint8_t *buffer)
|
||||
{
|
||||
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
||||
size_t blocksleft = nblocks;
|
||||
|
||||
fvdbg("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
||||
|
||||
/* Lock the SPI bus and write each page to FLASH */
|
||||
|
||||
at25_lock(priv->dev);
|
||||
while (blocksleft-- > 0)
|
||||
{
|
||||
at25_pagewrite(priv, buffer, startblock * 2);
|
||||
at25_pagewrite(priv, buffer + 256, startblock * 2 + 1);
|
||||
buffer += 1 << priv->pageshift;
|
||||
startblock++;
|
||||
}
|
||||
|
||||
at25_unlock(priv->dev);
|
||||
return nblocks;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_read
|
||||
************************************************************************************/
|
||||
|
||||
static ssize_t at25_read(FAR struct mtd_dev_s *dev, off_t offset, size_t nbytes,
|
||||
FAR uint8_t *buffer)
|
||||
{
|
||||
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
||||
|
||||
fvdbg("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes);
|
||||
|
||||
/* Wait for any preceding write to complete. We could simplify things by
|
||||
* perform this wait at the end of each write operation (rather than at
|
||||
* the beginning of ALL operations), but have the wait first will slightly
|
||||
* improve performance.
|
||||
*/
|
||||
|
||||
at25_waitwritecomplete(priv);
|
||||
|
||||
/* Lock the SPI bus and select this FLASH part */
|
||||
|
||||
at25_lock(priv->dev);
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
|
||||
|
||||
/* Send "Read from Memory " instruction */
|
||||
|
||||
(void)SPI_SEND(priv->dev, AT25_READ);
|
||||
|
||||
/* Send the page offset high byte first. */
|
||||
|
||||
(void)SPI_SEND(priv->dev, (offset >> 16) & 0xff);
|
||||
(void)SPI_SEND(priv->dev, (offset >> 8) & 0xff);
|
||||
(void)SPI_SEND(priv->dev, offset & 0xff);
|
||||
|
||||
/* Then read all of the requested bytes */
|
||||
|
||||
SPI_RECVBLOCK(priv->dev, buffer, nbytes);
|
||||
|
||||
/* Deselect the FLASH and unlock the SPI bus */
|
||||
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
|
||||
at25_unlock(priv->dev);
|
||||
|
||||
fvdbg("return nbytes: %d\n", (int)nbytes);
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_ioctl
|
||||
************************************************************************************/
|
||||
|
||||
static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
||||
{
|
||||
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
||||
int ret = -EINVAL; /* Assume good command with bad parameters */
|
||||
|
||||
fvdbg("cmd: %d \n", cmd);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case MTDIOC_GEOMETRY:
|
||||
{
|
||||
FAR struct mtd_geometry_s *geo = (FAR struct mtd_geometry_s *)((uintptr_t)arg);
|
||||
if (geo)
|
||||
{
|
||||
/* Populate the geometry structure with information need to know
|
||||
* the capacity and how to access the device.
|
||||
*
|
||||
* NOTE: that the device is treated as though it where just an array
|
||||
* of fixed size blocks. That is most likely not true, but the client
|
||||
* will expect the device logic to do whatever is necessary to make it
|
||||
* appear so.
|
||||
*/
|
||||
|
||||
geo->blocksize = (1 << priv->pageshift);
|
||||
geo->erasesize = (1 << priv->sectorshift);
|
||||
geo->neraseblocks = priv->nsectors;
|
||||
ret = OK;
|
||||
|
||||
fvdbg("blocksize: %d erasesize: %d neraseblocks: %d\n",
|
||||
geo->blocksize, geo->erasesize, geo->neraseblocks);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case MTDIOC_BULKERASE:
|
||||
{
|
||||
/* Erase the entire device */
|
||||
|
||||
at25_lock(priv->dev);
|
||||
ret = at25_bulkerase(priv);
|
||||
at25_unlock(priv->dev);
|
||||
}
|
||||
break;
|
||||
|
||||
case MTDIOC_XIPBASE:
|
||||
default:
|
||||
ret = -ENOTTY; /* Bad command */
|
||||
break;
|
||||
}
|
||||
|
||||
fvdbg("return %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/************************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************************/
|
||||
|
||||
/************************************************************************************
|
||||
* Name: at25_initialize
|
||||
*
|
||||
* Description:
|
||||
* Create an initialize MTD device instance. MTD devices are not registered
|
||||
* in the file system, but are created as instances that can be bound to
|
||||
* other functions (such as a block or character driver front end).
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev)
|
||||
{
|
||||
FAR struct at25_dev_s *priv;
|
||||
int ret;
|
||||
|
||||
fvdbg("dev: %p\n", dev);
|
||||
|
||||
/* Allocate a state structure (we allocate the structure instead of using
|
||||
* a fixed, static allocation so that we can handle multiple FLASH devices.
|
||||
* The current implementation would handle only one FLASH part per SPI
|
||||
* device (only because of the SPIDEV_FLASH definition) and so would have
|
||||
* to be extended to handle multiple FLASH parts on the same SPI bus.
|
||||
*/
|
||||
|
||||
priv = (FAR struct at25_dev_s *)kmalloc(sizeof(struct at25_dev_s));
|
||||
if (priv)
|
||||
{
|
||||
/* Initialize the allocated structure */
|
||||
|
||||
priv->mtd.erase = at25_erase;
|
||||
priv->mtd.bread = at25_bread;
|
||||
priv->mtd.bwrite = at25_bwrite;
|
||||
priv->mtd.read = at25_read;
|
||||
priv->mtd.ioctl = at25_ioctl;
|
||||
priv->dev = dev;
|
||||
|
||||
/* Deselect the FLASH */
|
||||
|
||||
SPI_SELECT(dev, SPIDEV_FLASH, false);
|
||||
|
||||
/* Identify the FLASH chip and get its capacity */
|
||||
|
||||
ret = at25_readid(priv);
|
||||
if (ret != OK)
|
||||
{
|
||||
/* Unrecognized! Discard all of that work we just did and return NULL */
|
||||
|
||||
fdbg("Unrecognized\n");
|
||||
kfree(priv);
|
||||
priv = NULL;
|
||||
}
|
||||
|
||||
/* Unprotect all sectors */
|
||||
|
||||
at25_writeenable(priv);
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, true);
|
||||
(void)SPI_SEND(priv->dev, AT25_WRSR);
|
||||
(void)SPI_SEND(priv->dev, AT25_SR_UNPROT);
|
||||
SPI_SELECT(priv->dev, SPIDEV_FLASH, false);
|
||||
}
|
||||
|
||||
/* Return the implementation-specific state structure as the MTD device */
|
||||
|
||||
fvdbg("Return %p\n", priv);
|
||||
return (FAR struct mtd_dev_s *)priv;
|
||||
}
|
||||
+27
-4
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* drivers/mtd/ftl.c
|
||||
*
|
||||
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -229,6 +229,10 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
|
||||
remaining = nblocks;
|
||||
if (alignedblock > startblock)
|
||||
{
|
||||
/* Check if the write is shorter than to the end of the erase block */
|
||||
|
||||
bool short_write = (remaining < (alignedblock - startblock));
|
||||
|
||||
/* Read the full erase block into the buffer */
|
||||
|
||||
rwblock = startblock & ~mask;
|
||||
@@ -252,9 +256,19 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
|
||||
/* Copy the user data at the end of the buffered erase block */
|
||||
|
||||
offset = (startblock & mask) * dev->geo.blocksize;
|
||||
nbytes = dev->geo.erasesize - offset;
|
||||
|
||||
if (short_write)
|
||||
{
|
||||
nbytes = remaining * dev->geo.blocksize;
|
||||
}
|
||||
else
|
||||
{
|
||||
nbytes = dev->geo.erasesize - offset;
|
||||
}
|
||||
|
||||
fvdbg("Copy %d bytes into erase block=%d at offset=%d\n",
|
||||
nbytes, eraseblock, offset);
|
||||
|
||||
memcpy(dev->eblock + offset, buffer, nbytes);
|
||||
|
||||
/* And write the erase back to flash */
|
||||
@@ -268,8 +282,16 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
|
||||
|
||||
/* Then update for amount written */
|
||||
|
||||
remaining -= dev->blkper - (startblock & mask);
|
||||
buffer += nbytes;
|
||||
if (short_write)
|
||||
{
|
||||
remaining = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
remaining -= dev->blkper - (startblock & mask);
|
||||
}
|
||||
|
||||
buffer += nbytes;
|
||||
}
|
||||
|
||||
/* How handle full erase pages in the middle */
|
||||
@@ -290,6 +312,7 @@ static ssize_t ftl_flush(FAR void *priv, FAR const uint8_t *buffer,
|
||||
|
||||
fvdbg("Write %d bytes into erase block=%d at offset=0\n",
|
||||
dev->geo.erasesize, alignedblock);
|
||||
|
||||
nxfrd = MTD_BWRITE(dev->mtd, alignedblock, dev->blkper, buffer);
|
||||
if (nxfrd != dev->blkper)
|
||||
{
|
||||
|
||||
@@ -47,7 +47,7 @@ CSRCS += pm_activity.c pm_changestate.c pm_checkstate.c pm_initialize.c pm_regis
|
||||
|
||||
POWER_DEPPATH := --dep-path power
|
||||
POWER_VPATH := :power
|
||||
POWER_CFLAGS := ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/power}
|
||||
POWER_CFLAGS := ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)power}
|
||||
|
||||
endif
|
||||
|
||||
@@ -73,7 +73,7 @@ endif
|
||||
|
||||
POWER_DEPPATH := --dep-path power
|
||||
POWER_VPATH := :power
|
||||
POWER_CFLAGS := ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/power}
|
||||
POWER_CFLAGS := ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)power}
|
||||
|
||||
endif
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# drivers/sensors/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -57,4 +57,4 @@ endif
|
||||
|
||||
DEPPATH += --dep-path sensors
|
||||
VPATH += :sensors
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/sensors}
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)sensors}
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
# see misc/tools/kconfig-language.txt.
|
||||
#
|
||||
|
||||
config LOWLEVEL_CONSOLE
|
||||
config DEV_LOWCONSOLE
|
||||
bool "Low-level console support"
|
||||
default n
|
||||
depends on ARCH_LOWPUTC
|
||||
---help---
|
||||
Use the simple, low-level, write-only serial console driver (minimal support)
|
||||
|
||||
config 16550_UART
|
||||
bool "16550 UART Chip support"
|
||||
@@ -317,7 +319,7 @@ config STANDARD_SERIAL
|
||||
bool "Enable standard \"upper-half\" serial driver"
|
||||
default y if MCU_SERIAL
|
||||
default n if !MCU_SERIAL
|
||||
depends on !LOWLEVEL_CONSOLE
|
||||
depends on !DEV_LOWCONSOLE
|
||||
---help---
|
||||
Enable the standard, upper-half serial driver used by most MCU serial peripherals.
|
||||
|
||||
@@ -422,7 +424,7 @@ config UART_TXBUFSIZE
|
||||
|
||||
config UART_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the UART.
|
||||
|
||||
@@ -465,7 +467,7 @@ config UART0_TXBUFSIZE
|
||||
|
||||
config UART0_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the UART.
|
||||
|
||||
@@ -508,7 +510,7 @@ config USART0_TXBUFSIZE
|
||||
|
||||
config USART0_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the USART.
|
||||
|
||||
@@ -551,7 +553,7 @@ config UART1_TXBUFSIZE
|
||||
|
||||
config UART1_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the UART.
|
||||
|
||||
@@ -594,7 +596,7 @@ config USART1_TXBUFSIZE
|
||||
|
||||
config USART1_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the USART.
|
||||
|
||||
@@ -637,7 +639,7 @@ config UART2_TXBUFSIZE
|
||||
|
||||
config UART2_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the UART.
|
||||
|
||||
@@ -680,7 +682,7 @@ config USART2_TXBUFSIZE
|
||||
|
||||
config USART2_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the USART.
|
||||
|
||||
@@ -723,7 +725,7 @@ config UART3_TXBUFSIZE
|
||||
|
||||
config UART3_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the UART.
|
||||
|
||||
@@ -766,7 +768,7 @@ config USART3_TXBUFSIZE
|
||||
|
||||
config USART3_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the USART.
|
||||
|
||||
@@ -809,7 +811,7 @@ config UART4_TXBUFSIZE
|
||||
|
||||
config UART4_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the UART.
|
||||
|
||||
@@ -852,7 +854,7 @@ config USART4_TXBUFSIZE
|
||||
|
||||
config USART4_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the USART.
|
||||
|
||||
@@ -895,7 +897,7 @@ config UART5_TXBUFSIZE
|
||||
|
||||
config UART5_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the UART.
|
||||
|
||||
@@ -938,7 +940,7 @@ config USART5_TXBUFSIZE
|
||||
|
||||
config USART5_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the USART.
|
||||
|
||||
@@ -981,7 +983,7 @@ config USART6_TXBUFSIZE
|
||||
|
||||
config USART6_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the USART.
|
||||
|
||||
@@ -1024,7 +1026,7 @@ config UART6_TXBUFSIZE
|
||||
|
||||
config UART6_BAUD
|
||||
int "baud rate"
|
||||
default 11520
|
||||
default 115200
|
||||
help
|
||||
The configured BAUD of the UART.
|
||||
|
||||
|
||||
@@ -233,7 +233,9 @@ static int uart_putxmitchar(FAR uart_dev_t *dev, int ch)
|
||||
}
|
||||
}
|
||||
|
||||
/* We won't get here */
|
||||
/* We won't get here. Some compilers may complain that this code is
|
||||
* unreachable.
|
||||
*/
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -59,5 +59,5 @@ CSRCS += usbdev_trace.c usbdev_trprintf.c
|
||||
|
||||
DEPPATH += --dep-path usbdev
|
||||
VPATH += :usbdev
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/usbdev}
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)usbdev}
|
||||
endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# drivers/usbhost/Make.defs
|
||||
#
|
||||
# Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2010-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -45,7 +45,7 @@ CSRCS += usbhost_enumerate.c usbhost_storage.c usbhost_hidkbd.c
|
||||
# Include add-on USB host driver logic (see misc/drivers)
|
||||
|
||||
ifeq ($(CONFIG_NET),y)
|
||||
RTL8187_CSRC := ${shell if [ -f usbhost/rtl8187x.c ]; then echo "rtl8187x.c"; fi}
|
||||
RTL8187_CSRC := ${shell if [ -f usbhost$(DELIM)rtl8187x.c ]; then echo "rtl8187x.c"; fi}
|
||||
CSRCS += $(RTL8187_CSRC)
|
||||
endif
|
||||
endif
|
||||
@@ -54,4 +54,4 @@ endif
|
||||
|
||||
DEPPATH += --dep-path usbhost
|
||||
VPATH += :usbhost
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/usbhost}
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)usbhost}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# drivers/wireless/Make.defs
|
||||
#
|
||||
# Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,7 +41,7 @@ CSRCS += cc1101.c ISM1_868MHzGFSK100kbps.c ISM2_905MHzGFSK250kbps.c
|
||||
|
||||
# Include wireless build support
|
||||
|
||||
DEPPATH += --dep-path wireless/cc1101
|
||||
VPATH += :wireless/cc1101
|
||||
CFLAGS += ${shell $(TOPDIR)/tools/incdir.sh $(INCDIROPT) "$(CC)" $(TOPDIR)/drivers/wireless/cc1101}
|
||||
DEPPATH += --dep-path wireless$(DELIM)cc1101
|
||||
VPATH += :wireless$(DELIM)cc1101
|
||||
CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)wireless$(DELIM)cc1101}
|
||||
endif
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* graphics/nxglib/nxglib_splitline.c
|
||||
*
|
||||
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -41,6 +41,8 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/nx/nxglib.h>
|
||||
|
||||
@@ -48,12 +50,16 @@
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define SMALL_SIN 1966 /* 1966/65536 = 0.03 */
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct b16point_s
|
||||
{
|
||||
b16_t x;
|
||||
b16_t y;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
@@ -66,6 +72,12 @@
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static b16_t nxgl_interpolate(b16_t x, b16_t dy, b16_t dxdy)
|
||||
{
|
||||
b16_t dx = b16mulb16(dy, dxdy);
|
||||
return x + dx;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -116,15 +128,19 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
|
||||
struct nxgl_vector_s line;
|
||||
nxgl_coord_t iheight;
|
||||
nxgl_coord_t iwidth;
|
||||
nxgl_coord_t iy;
|
||||
nxgl_coord_t triheight;
|
||||
nxgl_coord_t halfheight;
|
||||
b16_t adjwidth;
|
||||
b16_t xoffset;
|
||||
b16_t halfoffset;
|
||||
nxgl_coord_t iyoffset;
|
||||
struct b16point_s quad[4];
|
||||
b16_t b16xoffset;
|
||||
b16_t b16yoffset;
|
||||
b16_t b16dxdy;
|
||||
b16_t angle;
|
||||
b16_t cosangle;
|
||||
b16_t sinangle;
|
||||
b16_t b16x;
|
||||
b16_t b16y;
|
||||
|
||||
gvdbg("vector: (%d,%d)->(%d,%d) linewidth: %d\n",
|
||||
vector->pt1.x, vector->pt1.y, vector->pt2.x, vector->pt2.y, linewidth);
|
||||
|
||||
/* First, check the linewidth */
|
||||
|
||||
@@ -152,7 +168,7 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
|
||||
line.pt2.x = vector->pt1.x;
|
||||
line.pt2.y = vector->pt1.y;
|
||||
}
|
||||
else
|
||||
else /* if (vector->pt1.y == vector->pt2.y) */
|
||||
{
|
||||
/* First degenerate case: The line is horizontal. */
|
||||
|
||||
@@ -173,6 +189,10 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
|
||||
|
||||
rect->pt1.y = vector->pt1.y - (linewidth >> 1);
|
||||
rect->pt2.y = rect->pt1.y + linewidth - 1;
|
||||
|
||||
gvdbg("Horizontal rect: (%d,%d),(%d,%d)\n",
|
||||
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -187,14 +207,21 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
|
||||
|
||||
rect->pt1.x = line.pt1.x - (linewidth >> 1);
|
||||
rect->pt2.x = rect->pt1.x + linewidth - 1;
|
||||
|
||||
gvdbg("Vertical rect: (%d,%d),(%d,%d)\n",
|
||||
rect->pt1.x, rect->pt1.y, rect->pt2.x, rect->pt2.y);
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* The final degenerate case */
|
||||
|
||||
if (linewidth == 1)
|
||||
if (linewidth == 1 &&
|
||||
abs(line.pt2.x - line.pt1.x) < (line.pt2.y - line.pt1.y))
|
||||
{
|
||||
/* A line of width 1 is basically a single parallelogram of width 1 */
|
||||
/* A close to vertical line of width 1 is basically
|
||||
* a single parallelogram of width 1.
|
||||
*/
|
||||
|
||||
traps[1].top.x1 = itob16(line.pt1.x);
|
||||
traps[1].top.x2 = traps[1].top.x1;
|
||||
@@ -203,6 +230,11 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
|
||||
traps[1].bot.x1 = itob16(line.pt2.x);
|
||||
traps[1].bot.x2 = traps[1].bot.x1;
|
||||
traps[1].bot.y = line.pt2.y;
|
||||
|
||||
gvdbg("Vertical traps[1]: (%08x,%08x,%d),(%08x,%08x, %d)\n",
|
||||
traps[1].top.x1, traps[1].top.x2, traps[1].top.y,
|
||||
traps[1].bot.x1, traps[1].bot.x2, traps[1].bot.y);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -222,103 +254,260 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
|
||||
iwidth = line.pt1.x - line.pt2.x + 1;
|
||||
}
|
||||
|
||||
/* Triangle height: linewidth * cosA
|
||||
* Adjusted width: triheight / sinA
|
||||
* X offset : linewidth * linewidth / adjusted line width
|
||||
/* Applying the line width to the line results in a rotated, rectangle.
|
||||
* Get the Y offset from an end of the original thin line to a corner of the fat line.
|
||||
*
|
||||
* Angle of line: angle = atan2(iheight, iwidth)
|
||||
* Y offset from line: b16yoffset = linewidth * cos(angle)
|
||||
*
|
||||
* For near verical lines, b16yoffset is be nearly zero. For near horizontal
|
||||
* lines, b16yOffset is be about the same as linewidth.
|
||||
*/
|
||||
|
||||
angle = b16atan2(itob16(iheight), itob16(iwidth));
|
||||
triheight = b16toi(linewidth * b16cos(angle) + b16HALF);
|
||||
halfheight = (triheight >> 1);
|
||||
angle = b16atan2(itob16(iheight), itob16(iwidth));
|
||||
cosangle = b16cos(angle);
|
||||
b16yoffset = (linewidth * cosangle + 1) >> 1;
|
||||
|
||||
/* If the sine of the angle is tiny (i.e., the line is nearly horizontal),
|
||||
* then we cannot compute the adjusted width. In this case, just use
|
||||
* the width of the line bounding box.
|
||||
/* Get the X offset from an end of the original thin line to a corner of the fat line.
|
||||
*
|
||||
* For near vertical lines, b16xoffset is about the same as linewidth. For near
|
||||
* horizontal lines, b16xoffset is nearly zero.
|
||||
*/
|
||||
|
||||
sinangle = b16sin(angle);
|
||||
if (sinangle < SMALL_SIN)
|
||||
{
|
||||
adjwidth = itob16(iwidth);
|
||||
xoffset = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
adjwidth = b16divb16(itob16(linewidth), sinangle);
|
||||
xoffset = itob16(linewidth * linewidth);
|
||||
xoffset = b16divb16(xoffset, adjwidth);
|
||||
}
|
||||
sinangle = b16sin(angle);
|
||||
b16xoffset = (linewidth * sinangle + 1) >> 1;
|
||||
|
||||
halfoffset = (xoffset >> 1);
|
||||
gvdbg("height: %d width: %d angle: %08x b16yoffset: %08x b16xoffset: %08x\n",
|
||||
iheight, iwidth, angle, b16yoffset, b16xoffset);
|
||||
|
||||
/* Return the top triangle (if there is one). NOTE that the horizontal
|
||||
* (z) positions are represented with 16 bits of fraction. The vertical
|
||||
* (y) positions, on the other hand, are integer.
|
||||
*/
|
||||
/* Now we know all four points of the rotated rectangle */
|
||||
|
||||
if (triheight > 0)
|
||||
iyoffset = b16toi(b16yoffset + b16HALF);
|
||||
if (iyoffset > 0)
|
||||
{
|
||||
/* Get the Y positions of each point */
|
||||
|
||||
b16y = itob16(line.pt1.y);
|
||||
quad[0].y = b16y - b16yoffset;
|
||||
quad[1].y = b16y + b16yoffset;
|
||||
|
||||
b16y = itob16(line.pt2.y);
|
||||
quad[2].y = b16y - b16yoffset;
|
||||
quad[3].y = b16y + b16yoffset;
|
||||
|
||||
if (line.pt1.x < line.pt2.x)
|
||||
{
|
||||
/* Line is going "south east" */
|
||||
/* Line is going "south east". Get the X positions of each point */
|
||||
|
||||
b16x = itob16(line.pt1.x) - halfoffset;
|
||||
iy = line.pt1.y + halfheight;
|
||||
b16x = itob16(line.pt1.x);
|
||||
quad[0].x = b16x + b16xoffset;
|
||||
quad[1].x = b16x - b16xoffset;
|
||||
|
||||
traps[0].top.x1 = b16x + xoffset;
|
||||
traps[0].top.x2 = traps[0].top.x1;
|
||||
traps[0].top.y = iy - triheight + 1;
|
||||
traps[0].bot.x1 = b16x;
|
||||
traps[0].bot.x2 = b16x + adjwidth - b16ONE;
|
||||
traps[0].bot.y = iy;
|
||||
b16x = itob16(line.pt2.x);
|
||||
quad[2].x = b16x + b16xoffset;
|
||||
quad[3].x = b16x - b16xoffset;
|
||||
|
||||
b16x = itob16(line.pt2.x) + halfoffset;
|
||||
iy = line.pt2.y - halfheight;
|
||||
gvdbg("Southeast: quad (%08x,%08x),(%08x,%08x),(%08x,%08x),(%08x,%08x)\n",
|
||||
quad[0].x, quad[0].y, quad[1].x, quad[1].y,
|
||||
quad[2].x, quad[2].y, quad[3].x, quad[3].y);
|
||||
|
||||
traps[2].top.x1 = b16x - adjwidth + b16ONE;
|
||||
traps[2].top.x2 = b16x;
|
||||
traps[2].top.y = iy;
|
||||
traps[2].bot.x1 = b16x - xoffset;
|
||||
traps[2].bot.x2 = traps[2].bot.x1;
|
||||
traps[2].bot.y = iy + triheight - 1;
|
||||
/* Now we can form the trapezoids. The top of the first trapezoid
|
||||
* (triangle) is at quad[0]
|
||||
*/
|
||||
|
||||
traps[0].top.x1 = quad[0].x;
|
||||
traps[0].top.x2 = quad[0].x;
|
||||
traps[0].top.y = b16toi(quad[0].y + b16HALF);
|
||||
|
||||
/* The bottom of the first trapezoid (triangle) may be either at
|
||||
* quad[1] or quad[2], depending upon orientation.
|
||||
*/
|
||||
|
||||
if (quad[1]. y < quad[2].y)
|
||||
{
|
||||
/* quad[1] is at the bottom left of the triangle. Interpolate
|
||||
* to get the corresponding point on the right side.
|
||||
*
|
||||
* Interpolation is from quad[0] along the line quad[0]->quad[2]
|
||||
* which as the same slope as the line (positive)
|
||||
*/
|
||||
|
||||
b16dxdy = itob16(iwidth) / iheight;
|
||||
|
||||
traps[0].bot.x1 = quad[1].x;
|
||||
traps[0].bot.x2 = nxgl_interpolate(quad[0].x, quad[1].y - quad[0].y, b16dxdy);
|
||||
traps[0].bot.y = b16toi(quad[1].y + b16HALF);
|
||||
|
||||
/* quad[1] is at the top left of the second trapezoid. quad[2} is
|
||||
* at the bottom right of the second trapezoid. Interpolate to get
|
||||
* corresponding point on the left side.
|
||||
*
|
||||
* Interpolation is from quad[1] along the line quad[1]->quad[3]
|
||||
* which as the same slope as the line (positive)
|
||||
*/
|
||||
|
||||
traps[1].top.x1 = traps[0].bot.x1;
|
||||
traps[1].top.x2 = traps[0].bot.x2;
|
||||
traps[1].top.y = traps[0].bot.y;
|
||||
|
||||
traps[1].bot.x1 = nxgl_interpolate(traps[1].top.x1, quad[2].y - quad[1].y, b16dxdy);
|
||||
traps[1].bot.x2 = quad[2].x;
|
||||
traps[1].bot.y = b16toi(quad[2].y + b16HALF);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* quad[2] is at the bottom right of the triangle. Interpolate
|
||||
* to get the corresponding point on the left side.
|
||||
*
|
||||
* Interpolation is from quad[0] along the line quad[0]->quad[1]
|
||||
* which orthogonal to the slope of the line (and negative)
|
||||
*/
|
||||
|
||||
b16dxdy = -itob16(iheight) / iwidth;
|
||||
|
||||
traps[0].bot.x1 = nxgl_interpolate(quad[0].x, quad[2].y - quad[0].y, b16dxdy);
|
||||
traps[0].bot.x2 = quad[2].x;
|
||||
traps[0].bot.y = b16toi(quad[2].y + b16HALF);
|
||||
|
||||
/* quad[2] is at the top right of the second trapezoid. quad[1} is
|
||||
* at the bottom left of the second trapezoid. Interpolate to get
|
||||
* corresponding point on the right side.
|
||||
*
|
||||
* Interpolation is from quad[2] along the line quad[2]->quad[3]
|
||||
* which as the same slope as the previous interpolation.
|
||||
*/
|
||||
|
||||
traps[1].top.x1 = traps[0].bot.x1;
|
||||
traps[1].top.x2 = traps[0].bot.x2;
|
||||
traps[1].top.y = traps[0].bot.y;
|
||||
|
||||
traps[1].bot.x1 = quad[1].x;
|
||||
traps[1].bot.x2 = nxgl_interpolate(traps[1].top.x2, quad[1].y - quad[2].y, b16dxdy);
|
||||
traps[1].bot.y = b16toi(quad[1].y + b16HALF);
|
||||
}
|
||||
|
||||
/* The final trapezond (triangle) at the bottom is new well defined */
|
||||
|
||||
traps[2].top.x1 = traps[1].bot.x1;
|
||||
traps[2].top.x2 = traps[1].bot.x2;
|
||||
traps[2].top.y = traps[1].bot.y;
|
||||
|
||||
traps[2].bot.x1 = quad[3].x;
|
||||
traps[2].bot.x2 = quad[3].x;
|
||||
traps[2].bot.y = b16toi(quad[3].y + b16HALF);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Line is going "south west" */
|
||||
/* Get the X positions of each point */
|
||||
|
||||
b16x = itob16(line.pt1.x) + halfoffset;
|
||||
iy = line.pt1.y + halfheight;
|
||||
b16x = itob16(line.pt1.x);
|
||||
quad[0].x = b16x - b16xoffset;
|
||||
quad[1].x = b16x + b16xoffset;
|
||||
|
||||
traps[0].top.x1 = b16x - xoffset;
|
||||
traps[0].top.x2 = traps[0].top.x1;
|
||||
traps[0].top.y = iy - triheight + 1;
|
||||
traps[0].bot.x1 = b16x - adjwidth + b16ONE;
|
||||
traps[0].bot.x2 = b16x;
|
||||
traps[0].bot.y = iy;
|
||||
b16x = itob16(line.pt2.x);
|
||||
quad[2].x = b16x - b16xoffset;
|
||||
quad[3].x = b16x + b16xoffset;
|
||||
|
||||
b16x = itob16(line.pt2.x) - halfoffset;
|
||||
iy = line.pt2.y - halfheight;
|
||||
gvdbg("Southwest: quad (%08x,%08x),(%08x,%08x),(%08x,%08x),(%08x,%08x)\n",
|
||||
quad[0].x, quad[0].y, quad[1].x, quad[1].y,
|
||||
quad[2].x, quad[2].y, quad[3].x, quad[3].y);
|
||||
|
||||
traps[2].top.x1 = b16x;
|
||||
traps[2].top.x2 = b16x + adjwidth - b16ONE;
|
||||
traps[2].top.y = iy;
|
||||
traps[2].bot.x1 = b16x + xoffset;
|
||||
traps[2].bot.x2 = traps[2].bot.x1;
|
||||
traps[2].bot.y = iy + triheight - 1;
|
||||
/* Now we can form the trapezoids. The top of the first trapezoid
|
||||
* (triangle) is at quad[0]
|
||||
*/
|
||||
|
||||
traps[0].top.x1 = quad[0].x;
|
||||
traps[0].top.x2 = quad[0].x;
|
||||
traps[0].top.y = b16toi(quad[0].y + b16HALF);
|
||||
|
||||
/* The bottom of the first trapezoid (triangle) may be either at
|
||||
* quad[1] or quad[2], depending upon orientation.
|
||||
*/
|
||||
|
||||
if (quad[1].y < quad[2].y)
|
||||
{
|
||||
/* quad[1] is at the bottom right of the triangle. Interpolate
|
||||
* to get the corresponding point on the left side.
|
||||
*
|
||||
* Interpolation is from quad[0] along the line quad[0]->quad[2]
|
||||
* which as the same slope as the line (negative)
|
||||
*/
|
||||
|
||||
b16dxdy = -itob16(iwidth) / iheight;
|
||||
|
||||
traps[0].bot.x1 = nxgl_interpolate(traps[0].top.x1, quad[1].y - quad[0].y, b16dxdy);
|
||||
traps[0].bot.x2 = quad[1].x;
|
||||
traps[0].bot.y = b16toi(quad[1].y + b16HALF);
|
||||
|
||||
/* quad[1] is at the top right of the second trapezoid. quad[2} is
|
||||
* at the bottom left of the second trapezoid. Interpolate to get
|
||||
* corresponding point on the right side.
|
||||
*
|
||||
* Interpolation is from quad[1] along the line quad[1]->quad[3]
|
||||
* which as the same slope as the line (negative)
|
||||
*/
|
||||
|
||||
traps[1].top.x1 = traps[0].bot.x1;
|
||||
traps[1].top.x2 = traps[0].bot.x2;
|
||||
traps[1].top.y = traps[0].bot.y;
|
||||
|
||||
traps[1].bot.x1 = quad[2].x;
|
||||
traps[1].bot.x2 = nxgl_interpolate(traps[1].top.x2, quad[2].y - quad[1].y, b16dxdy);
|
||||
traps[1].bot.y = b16toi(quad[2].y + b16HALF);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* quad[2] is at the bottom left of the triangle. Interpolate
|
||||
* to get the corresponding point on the right side.
|
||||
*
|
||||
* Interpolation is from quad[0] along the line quad[0]->quad[1]
|
||||
* which orthogonal to the slope of the line (and positive)
|
||||
*/
|
||||
|
||||
b16dxdy = itob16(iheight) / iwidth;
|
||||
|
||||
traps[0].bot.x1 = quad[2].x;
|
||||
traps[0].bot.x2 = nxgl_interpolate(traps[0].top.x2, quad[2].y - quad[0].y, b16dxdy);
|
||||
traps[0].bot.y = b16toi(quad[2].y + b16HALF);
|
||||
|
||||
/* quad[2] is at the top left of the second trapezoid. quad[1} is
|
||||
* at the bottom right of the second trapezoid. Interpolate to get
|
||||
* corresponding point on the left side.
|
||||
*
|
||||
* Interpolation is from quad[2] along the line quad[2]->quad[3]
|
||||
* which as the same slope as the previous interpolation.
|
||||
*/
|
||||
|
||||
traps[1].top.x1 = traps[0].bot.x1;
|
||||
traps[1].top.x2 = traps[0].bot.x2;
|
||||
traps[1].top.y = traps[0].bot.y;
|
||||
|
||||
traps[1].bot.x1 = nxgl_interpolate(traps[1].top.x1, quad[1].y - quad[2].y, b16dxdy);
|
||||
traps[1].bot.x2 = quad[1].x;
|
||||
traps[1].bot.y = b16toi(quad[1].y + b16HALF);
|
||||
}
|
||||
|
||||
/* The final trapezond (triangle) at the bottom is new well defined */
|
||||
|
||||
traps[2].top.x1 = traps[1].bot.x1;
|
||||
traps[2].top.x2 = traps[1].bot.x2;
|
||||
traps[2].top.y = traps[1].bot.y;
|
||||
|
||||
traps[2].bot.x1 = quad[3].x;
|
||||
traps[2].bot.x2 = quad[3].x;
|
||||
traps[2].bot.y = b16toi(quad[3].y + b16HALF);
|
||||
}
|
||||
|
||||
/* The center parallelogram is the horizontal edge of each triangle.
|
||||
* Note the minor inefficency: that horizontal edges are drawn twice.
|
||||
*/
|
||||
gvdbg("traps[0]: (%08x,%08x,%d),(%08x,%08x,%d)\n",
|
||||
traps[0].top.x1, traps[0].top.x2, traps[0].top.y,
|
||||
traps[0].bot.x1, traps[0].bot.x2, traps[0].bot.y);
|
||||
gvdbg("traps[1]: (%08x,%08x,%d),(%08x,%08x,%d)\n",
|
||||
traps[1].top.x1, traps[1].top.x2, traps[1].top.y,
|
||||
traps[1].bot.x1, traps[1].bot.x2, traps[1].bot.y);
|
||||
gvdbg("traps[2]: (%08x,%08x,%d),(%08x,%08x,%d)\n",
|
||||
traps[2].top.x1, traps[2].top.x2, traps[2].top.y,
|
||||
traps[2].bot.x1, traps[2].bot.x2, traps[2].bot.y);
|
||||
|
||||
traps[1].top.x1 = traps[0].bot.x1;
|
||||
traps[1].top.x2 = traps[0].bot.x2;
|
||||
traps[1].top.y = traps[0].bot.y;
|
||||
|
||||
traps[1].bot.x1 = traps[2].top.x1;
|
||||
traps[1].bot.x2 = traps[2].top.x2;
|
||||
traps[1].bot.y = traps[2].top.y;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -326,12 +515,18 @@ int nxgl_splitline(FAR struct nxgl_vector_s *vector,
|
||||
* bottom. Just return the center parallelogram.
|
||||
*/
|
||||
|
||||
traps[1].top.x1 = itob16(line.pt1.x) - halfoffset;
|
||||
traps[1].top.x2 = traps[1].top.x1 + adjwidth - 1;
|
||||
traps[1].top.x1 = itob16(line.pt1.x - (linewidth >> 1));
|
||||
traps[1].top.x2 = traps[1].top.x1 + itob16(linewidth - 1);
|
||||
traps[1].top.y = line.pt1.y;
|
||||
|
||||
traps[1].bot.x1 = itob16(line.pt2.x) - halfoffset;
|
||||
traps[1].bot.x2 = traps[1].bot.x1 + adjwidth - 1;
|
||||
|
||||
traps[1].bot.x1 = itob16(line.pt2.x - (linewidth >> 1));
|
||||
traps[1].bot.x2 = traps[1].bot.x1 + itob16(linewidth - 1);
|
||||
traps[1].bot.y = line.pt2.y;
|
||||
|
||||
gvdbg("Horizontal traps[1]: (%08x,%08x,%d),(%08x,%08x, %d)\n",
|
||||
traps[1].top.x1, traps[1].top.x2, traps[1].top.y,
|
||||
traps[1].bot.x1, traps[1].bot.x2, traps[1].bot.y);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,6 +94,7 @@ int nxtk_filltrapwindow(NXTKWINDOW hfwnd, FAR const struct nxgl_trapezoid_s *tra
|
||||
{
|
||||
FAR struct nxtk_framedwindow_s *fwnd = (FAR struct nxtk_framedwindow_s *)hfwnd;
|
||||
struct nxgl_rect_s relclip;
|
||||
struct nxgl_trapezoid_s reltrap;
|
||||
|
||||
#ifdef CONFIG_DEBUG
|
||||
if (!hfwnd || !trap || !color)
|
||||
@@ -103,8 +104,14 @@ int nxtk_filltrapwindow(NXTKWINDOW hfwnd, FAR const struct nxgl_trapezoid_s *tra
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Perform the fill, clipping to the client window */
|
||||
/* Move the trapezoid from window contents area to window area */
|
||||
|
||||
nxgl_trapoffset(&reltrap, trap,
|
||||
fwnd->fwrect.pt1.x - fwnd->wnd.bounds.pt1.x,
|
||||
fwnd->fwrect.pt1.y - fwnd->wnd.bounds.pt1.y);
|
||||
|
||||
/* Perform the fill, clipping to the client window */
|
||||
nxgl_rectoffset(&relclip, &fwnd->fwrect, -fwnd->wnd.bounds.pt1.x, -fwnd->wnd.bounds.pt1.y);
|
||||
return nx_filltrapezoid((NXWINDOW)hfwnd, &relclip, trap, color);
|
||||
|
||||
return nx_filltrapezoid((NXWINDOW)hfwnd, &relclip, &reltrap, color);
|
||||
}
|
||||
|
||||
@@ -110,12 +110,15 @@ int nxtk_getwindow(NXTKWINDOW hfwnd, FAR const struct nxgl_rect_s *rect,
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Clip the rectangle so that it lies within the sub-window bounds
|
||||
* then move the rectangle to that it is relative to the containing
|
||||
* window.
|
||||
/* Move the rectangle to that it is relative to the containing
|
||||
* window. If part of the rectangle lies outside the window,
|
||||
* it will contain garbage data, but the contained area will be
|
||||
* valid.
|
||||
*/
|
||||
|
||||
nxtk_subwindowclip(fwnd, &getrect, rect, &fwnd->fwrect);
|
||||
nxgl_rectoffset(&getrect, rect,
|
||||
fwnd->fwrect.pt1.x - fwnd->wnd.bounds.pt1.x,
|
||||
fwnd->fwrect.pt1.y - fwnd->wnd.bounds.pt1.y);
|
||||
|
||||
/* Then get it */
|
||||
|
||||
|
||||
@@ -112,21 +112,19 @@ void nxtk_subwindowmove(FAR struct nxtk_framedwindow_s *fwnd,
|
||||
|
||||
nxgl_rectintersect(&abssrc, &abssrc, &fwnd->fwrect);
|
||||
|
||||
/* Clip the offset so that the source rectangle does not move out of the
|
||||
* the client sub-window.
|
||||
*/
|
||||
/* Clip the source rectangle so that destination area is within the window. */
|
||||
|
||||
destoffset->x = srcoffset->x;
|
||||
if (destoffset->x < 0)
|
||||
{
|
||||
if (abssrc.pt1.x + destoffset->x < bounds->pt1.x)
|
||||
{
|
||||
destoffset->x = bounds->pt1.x - abssrc.pt1.x;
|
||||
abssrc.pt1.x = bounds->pt1.x - destoffset->x;
|
||||
}
|
||||
}
|
||||
else if (abssrc.pt2.x + destoffset->x > bounds->pt2.x)
|
||||
{
|
||||
destoffset->x = bounds->pt2.x - abssrc.pt2.x;
|
||||
abssrc.pt2.x = bounds->pt2.x - destoffset->x;
|
||||
}
|
||||
|
||||
destoffset->y = srcoffset->y;
|
||||
@@ -134,12 +132,12 @@ void nxtk_subwindowmove(FAR struct nxtk_framedwindow_s *fwnd,
|
||||
{
|
||||
if (abssrc.pt1.y + destoffset->y < bounds->pt1.y)
|
||||
{
|
||||
destoffset->y = bounds->pt1.y - abssrc.pt1.y;
|
||||
abssrc.pt1.y = bounds->pt1.y - destoffset->y;
|
||||
}
|
||||
}
|
||||
else if (abssrc.pt2.y + destoffset->y > bounds->pt2.y)
|
||||
{
|
||||
destoffset->y = bounds->pt2.y - abssrc.pt2.y;
|
||||
abssrc.pt2.y = bounds->pt2.y - destoffset->y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -40,6 +40,9 @@
|
||||
// Included Files
|
||||
//***************************************************************************
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
//***************************************************************************
|
||||
@@ -48,6 +51,34 @@
|
||||
|
||||
namespace std
|
||||
{
|
||||
#if CONFIG_HAVE_FLOAT
|
||||
using ::acosf;
|
||||
using ::asinf;
|
||||
using ::atanf;
|
||||
using ::atan2f;
|
||||
using ::ceilf;
|
||||
using ::cosf;
|
||||
using ::coshf;
|
||||
using ::expf;
|
||||
using ::fabsf;
|
||||
using ::floorf;
|
||||
using ::fmodf;
|
||||
using ::frexpf;
|
||||
using ::ldexpf;
|
||||
using ::logf;
|
||||
using ::log10f;
|
||||
using ::log2f;
|
||||
using ::modff;
|
||||
using ::roundf;
|
||||
using ::powf;
|
||||
using ::sinf;
|
||||
using ::sinhf;
|
||||
using ::sqrtf;
|
||||
using ::tanf;
|
||||
using ::tanhf;
|
||||
#endif
|
||||
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
using ::acos;
|
||||
using ::asin;
|
||||
using ::atan;
|
||||
@@ -63,13 +94,44 @@ namespace std
|
||||
using ::ldexp;
|
||||
using ::log;
|
||||
using ::log10;
|
||||
using ::log2;
|
||||
using ::modf;
|
||||
using ::round;
|
||||
using ::pow;
|
||||
using ::sin;
|
||||
using ::sinh;
|
||||
using ::sqrt;
|
||||
using ::tan;
|
||||
using ::tanh;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
using ::acosl;
|
||||
using ::asinl;
|
||||
using ::atanl;
|
||||
using ::atan2l;
|
||||
using ::ceill;
|
||||
using ::cosl;
|
||||
using ::coshl;
|
||||
using ::expl;
|
||||
using ::fabsl;
|
||||
using ::floorl;
|
||||
using ::fmodl;
|
||||
using ::frexpl;
|
||||
using ::ldexpl;
|
||||
using ::logl;
|
||||
using ::log10l;
|
||||
using ::log2l;
|
||||
using ::modfl;
|
||||
using ::roundl;
|
||||
using ::powl;
|
||||
using ::sinl;
|
||||
using ::sinhl;
|
||||
using ::sqrtl;
|
||||
using ::tanl;
|
||||
using ::tanhl;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif // __INCLUDE_CXX_CMATH
|
||||
|
||||
@@ -70,6 +70,7 @@ namespace std
|
||||
#endif
|
||||
|
||||
using ::strtol;
|
||||
using ::strtoul;
|
||||
using ::strtod;
|
||||
|
||||
using ::malloc;
|
||||
|
||||
+10
-15
@@ -571,12 +571,9 @@
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/* These low-level debug APIs are provided by the NuttX library. If the
|
||||
@@ -585,21 +582,20 @@ extern "C" {
|
||||
* or the other of the following.
|
||||
*/
|
||||
|
||||
EXTERN int lib_rawprintf(FAR const char *format, ...);
|
||||
int lib_rawprintf(FAR const char *format, ...);
|
||||
|
||||
#ifdef CONFIG_ARCH_LOWPUTC
|
||||
EXTERN int lib_lowprintf(FAR const char *format, ...);
|
||||
int lib_lowprintf(FAR const char *format, ...);
|
||||
#endif
|
||||
|
||||
/* Dump a buffer of data */
|
||||
|
||||
EXTERN void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer,
|
||||
unsigned int buflen);
|
||||
void lib_dumpbuffer(FAR const char *msg, FAR const uint8_t *buffer, unsigned int buflen);
|
||||
|
||||
/* Enable or disable debug output */
|
||||
|
||||
#ifdef CONFIG_DEBUG_ENABLE
|
||||
EXTERN void dbg_enable(bool enable);
|
||||
void dbg_enable(bool enable);
|
||||
#endif
|
||||
|
||||
/* If the cross-compiler's pre-processor does not support variable length
|
||||
@@ -608,23 +604,22 @@ EXTERN void dbg_enable(bool enable);
|
||||
|
||||
#ifndef CONFIG_CPP_HAVE_VARARGS
|
||||
#ifdef CONFIG_DEBUG
|
||||
EXTERN int dbg(const char *format, ...);
|
||||
int dbg(const char *format, ...);
|
||||
|
||||
# ifdef CONFIG_ARCH_LOWPUTC
|
||||
EXTERN int lldbg(const char *format, ...);
|
||||
int lldbg(const char *format, ...);
|
||||
# endif
|
||||
|
||||
# ifdef CONFIG_DEBUG_VERBOSE
|
||||
EXTERN int vdbg(const char *format, ...);
|
||||
int vdbg(const char *format, ...);
|
||||
|
||||
# ifdef CONFIG_ARCH_LOWPUTC
|
||||
EXTERN int llvdbg(const char *format, ...);
|
||||
int llvdbg(const char *format, ...);
|
||||
# endif
|
||||
#endif
|
||||
#endif /* CONFIG_DEBUG */
|
||||
#endif /* CONFIG_CPP_HAVE_VARARGS */
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
+259
-31
@@ -46,6 +46,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <sched.h>
|
||||
|
||||
#include <arch/arch.h>
|
||||
|
||||
/****************************************************************************
|
||||
@@ -67,10 +68,8 @@ typedef CODE void (*sig_deliver_t)(FAR _TCB *tcb);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -98,7 +97,7 @@ extern "C" {
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void up_initialize(void);
|
||||
void up_initialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_idle
|
||||
@@ -114,7 +113,7 @@ EXTERN void up_initialize(void);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void up_idle(void);
|
||||
void up_idle(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_initial_state
|
||||
@@ -130,7 +129,7 @@ EXTERN void up_idle(void);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void up_initial_state(FAR _TCB *tcb);
|
||||
void up_initial_state(FAR _TCB *tcb);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_create_stack
|
||||
@@ -155,7 +154,7 @@ EXTERN void up_initial_state(FAR _TCB *tcb);
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_CUSTOM_STACK
|
||||
EXTERN int up_create_stack(FAR _TCB *tcb, size_t stack_size);
|
||||
int up_create_stack(FAR _TCB *tcb, size_t stack_size);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -180,7 +179,7 @@ EXTERN int up_create_stack(FAR _TCB *tcb, size_t stack_size);
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_CUSTOM_STACK
|
||||
EXTERN int up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size);
|
||||
int up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -193,7 +192,7 @@ EXTERN int up_use_stack(FAR _TCB *tcb, FAR void *stack, size_t stack_size);
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_CUSTOM_STACK
|
||||
EXTERN void up_release_stack(FAR _TCB *dtcb);
|
||||
void up_release_stack(FAR _TCB *dtcb);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -216,7 +215,7 @@ EXTERN void up_release_stack(FAR _TCB *dtcb);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void up_unblock_task(FAR _TCB *tcb);
|
||||
void up_unblock_task(FAR _TCB *tcb);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_block_task
|
||||
@@ -242,7 +241,7 @@ EXTERN void up_unblock_task(FAR _TCB *tcb);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void up_block_task(FAR _TCB *tcb, tstate_t task_state);
|
||||
void up_block_task(FAR _TCB *tcb, tstate_t task_state);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_release_pending
|
||||
@@ -261,7 +260,7 @@ EXTERN void up_block_task(FAR _TCB *tcb, tstate_t task_state);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void up_release_pending(void);
|
||||
void up_release_pending(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_reprioritize_rtr
|
||||
@@ -287,7 +286,7 @@ EXTERN void up_release_pending(void);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority);
|
||||
void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: _exit
|
||||
@@ -349,7 +348,7 @@ EXTERN void up_reprioritize_rtr(FAR _TCB *tcb, uint8_t priority);
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_DISABLE_SIGNALS
|
||||
EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver);
|
||||
void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -363,7 +362,7 @@ EXTERN void up_schedule_sigaction(FAR _TCB *tcb, sig_deliver_t sigdeliver);
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_HEAP_BASE
|
||||
EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
|
||||
void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -382,6 +381,214 @@ EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
|
||||
# define up_getpicbase(ppicbase)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Address Environment Interfaces
|
||||
*
|
||||
* Low-level interfaces used in binfmt/ to instantiate tasks with address
|
||||
* environments. These interfaces all operate on type task_addrenv_t which
|
||||
* is an abstract representation of a task's address environment and must be
|
||||
* defined in arch/arch.h if CONFIG_ADDRENV is defined.
|
||||
*
|
||||
* up_addrenv_create - Create an address environment
|
||||
* up_addrenv_vaddr - Returns the virtual base address of the address
|
||||
* environment
|
||||
* up_addrenv_select - Instantiate an address environment
|
||||
* up_addrenv_restore - Restore an address environment
|
||||
* up_addrenv_destroy - Destroy an address environment.
|
||||
* up_addrenv_assign - Assign an address environment to a TCB
|
||||
*
|
||||
* Higher-level interfaces used by the tasking logic. These interfaces are
|
||||
* used by the functions in sched/ and all operate on the TCB which as been
|
||||
* assigned an address environment by up_addrenv_assign().
|
||||
*
|
||||
* up_addrenv_share - Clone the address environment assigned to one TCB
|
||||
* to another. This operation is done when a pthread
|
||||
* is created that share's the same address
|
||||
* environment.
|
||||
* up_addrenv_release - Release the TCBs reference to an address
|
||||
* environment when a task/thread exits.
|
||||
*
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: up_addrenv_create
|
||||
*
|
||||
* Description:
|
||||
* This function is called from the binary loader logic when a new
|
||||
* task is created in order to instantiate an address environment for the
|
||||
* task. up_addrenv_create is essentially the allocator of the physical
|
||||
* memory for the new task.
|
||||
*
|
||||
* Input Parameters:
|
||||
* envsize - The size (in bytes) of the address environment needed by the
|
||||
* task.
|
||||
* addrenv - The location to return the representation of the task address
|
||||
* environment.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int up_addrenv_create(size_t envsize, FAR task_addrenv_t *addrenv);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_addrenv_vaddr
|
||||
*
|
||||
* Description:
|
||||
* Return the virtual address associated with the newly create address
|
||||
* environment. This function is used by the binary loaders in order
|
||||
* get an address that can be used to initialize the new task.
|
||||
*
|
||||
* Input Parameters:
|
||||
* addrenv - The representation of the task address environment previously
|
||||
* returned by up_addrenv_create.
|
||||
* vaddr - The location to return the virtual address.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int up_addrenv_vaddr(FAR task_addrenv_t addrenv, FAR void **vaddr);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_addrenv_select
|
||||
*
|
||||
* Description:
|
||||
* After an address environment has been established for a task (via
|
||||
* up_addrenv_create(). This function may be called to to instantiate
|
||||
* that address environment in the virtual address space. this might be
|
||||
* necessary, for example, to load the code for the task from a file or
|
||||
* to access address environment private data.
|
||||
*
|
||||
* Input Parameters:
|
||||
* addrenv - The representation of the task address environment previously
|
||||
* returned by up_addrenv_create.
|
||||
* oldenv
|
||||
* The address environment that was in place before up_addrenv_select().
|
||||
* This may be used with up_addrenv_restore() to restore the original
|
||||
* address environment that was in place before up_addrenv_select() was
|
||||
* called. Note that this may be a task agnostic, hardware
|
||||
* representation that is different from task_addrenv_t.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int up_addrenv_select(task_addrenv_t addrenv, hw_addrenv_t *oldenv);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_addrenv_restore
|
||||
*
|
||||
* Description:
|
||||
* After an address environment has been temporarilty instantiated by
|
||||
* up_addrenv_select, this function may be called to to restore the
|
||||
* original address environment.
|
||||
*
|
||||
* Input Parameters:
|
||||
* oldenv - The hardware representation of the address environment
|
||||
* previously returned by up_addrenv_select.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int up_addrenv_restore(hw_addrenv_t oldenv);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_addrenv_destroy
|
||||
*
|
||||
* Description:
|
||||
* Called from the binary loader loader during error handling to destroy
|
||||
* the address environment previously created by up_addrenv_create().
|
||||
*
|
||||
* Input Parameters:
|
||||
* addrenv - The representation of the task address environment previously
|
||||
* returned by up_addrenv_create.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int up_addrenv_destroy(task_addrenv_t addrenv);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_addrenv_assign
|
||||
*
|
||||
* Description:
|
||||
* Assign an address environment to a TCB.
|
||||
*
|
||||
* Input Parameters:
|
||||
* addrenv - The representation of the task address environment previously
|
||||
* returned by up_addrenv_create.
|
||||
* tcb - The TCB of the task to receive the address environment.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int up_addrenv_assign(task_addrenv_t addrenv, FAR _TCB *tcb);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_addrenv_share
|
||||
*
|
||||
* Description:
|
||||
* This function is called from the core scheduler logic when a thread
|
||||
* is created that needs to share the address ennvironment of its parent
|
||||
* task. In this case, the parent's address environment needs to be
|
||||
* "cloned" for the child.
|
||||
*
|
||||
* Input Parameters:
|
||||
* ptcb - The TCB of the parent task that has the address environment.
|
||||
* ctcb - The TCB of the child thread needing the address environment.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int up_addrenv_share(FAR const _TCB *ptcb, FAR _TCB *ctcb);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_addrenv_release
|
||||
*
|
||||
* Description:
|
||||
* This function is called when a task or thread exits in order to release
|
||||
* its reference to an address environment. When there are no further
|
||||
* references to an address environment, that address environment should
|
||||
* be destroyed.
|
||||
*
|
||||
* Input Parameters:
|
||||
* tcb - The TCB of the task or thread whose the address environment will
|
||||
* be released.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
int up_addrenv_release(FAR _TCB *tcb);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_interrupt_context
|
||||
*
|
||||
@@ -391,7 +598,7 @@ EXTERN void up_allocate_heap(FAR void **heap_start, size_t *heap_size);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN bool up_interrupt_context(void);
|
||||
bool up_interrupt_context(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_enable_irq
|
||||
@@ -413,7 +620,7 @@ EXTERN bool up_interrupt_context(void);
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_ARCH_NOINTC
|
||||
EXTERN void up_enable_irq(int irq);
|
||||
void up_enable_irq(int irq);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -431,7 +638,7 @@ EXTERN void up_enable_irq(int irq);
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_ARCH_NOINTC
|
||||
EXTERN void up_disable_irq(int irq);
|
||||
void up_disable_irq(int irq);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -446,7 +653,7 @@ EXTERN void up_disable_irq(int irq);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_IRQPRIO
|
||||
EXTERN int up_prioritize_irq(int irq, int priority);
|
||||
int up_prioritize_irq(int irq, int priority);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -483,7 +690,7 @@ EXTERN int up_prioritize_irq(int irq, int priority);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_ROMGETC
|
||||
EXTERN char up_romgetc(FAR const char *ptr);
|
||||
char up_romgetc(FAR const char *ptr);
|
||||
#else
|
||||
# define up_romgetc(ptr) (*ptr)
|
||||
#endif
|
||||
@@ -497,8 +704,8 @@ EXTERN char up_romgetc(FAR const char *ptr);
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
EXTERN void up_mdelay(unsigned int milliseconds);
|
||||
EXTERN void up_udelay(useconds_t microseconds);
|
||||
void up_mdelay(unsigned int milliseconds);
|
||||
void up_udelay(useconds_t microseconds);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_cxxinitialize
|
||||
@@ -517,7 +724,7 @@ EXTERN void up_udelay(useconds_t microseconds);
|
||||
***************************************************************************/
|
||||
|
||||
#if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE)
|
||||
EXTERN void up_cxxinitialize(void);
|
||||
void up_cxxinitialize(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -537,7 +744,7 @@ EXTERN void up_cxxinitialize(void);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void sched_process_timer(void);
|
||||
void sched_process_timer(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: irq_dispatch
|
||||
@@ -549,7 +756,7 @@ EXTERN void sched_process_timer(void);
|
||||
*
|
||||
***************************************************************************/
|
||||
|
||||
EXTERN void irq_dispatch(int irq, FAR void *context);
|
||||
void irq_dispatch(int irq, FAR void *context);
|
||||
|
||||
/****************************************************************************
|
||||
* Board-specific button interfaces exported by the board-specific logic
|
||||
@@ -571,7 +778,7 @@ EXTERN void irq_dispatch(int irq, FAR void *context);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_BUTTONS
|
||||
EXTERN void up_buttoninit(void);
|
||||
void up_buttoninit(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -592,7 +799,7 @@ EXTERN void up_buttoninit(void);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_BUTTONS
|
||||
EXTERN uint8_t up_buttons(void);
|
||||
uint8_t up_buttons(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -613,7 +820,29 @@ EXTERN uint8_t up_buttons(void);
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
||||
EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
|
||||
xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
|
||||
#endif
|
||||
|
||||
/************************************************************************************
|
||||
* Relay control functions
|
||||
*
|
||||
* Description:
|
||||
* Non-standard functions for relay control.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_RELAYS
|
||||
void up_relaysinit(void);
|
||||
void relays_setstat(int relays, bool stat);
|
||||
bool relays_getstat(int relays);
|
||||
void relays_setstats(uint32_t relays_stat);
|
||||
uint32_t relays_getstats(void);
|
||||
void relays_onoff(int relays, uint32_t mdelay);
|
||||
void relays_onoffs(uint32_t relays_stat, uint32_t mdelay);
|
||||
void relays_resetmode(int relays);
|
||||
void relays_powermode(int relays);
|
||||
void relays_resetmodes(uint32_t relays_stat);
|
||||
void relays_powermodes(uint32_t relays_stat);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@@ -628,9 +857,8 @@ EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int up_putc(int ch);
|
||||
int up_putc(int ch);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/binfmt/binfmt.h
|
||||
*
|
||||
* Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_BINFMT_BINFMT_H
|
||||
#define __INCLUDE_NUTTX_BINFMT_BINFMT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <nxflat.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/sched.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define BINFMT_NALLOC 3
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
/* EXEPATH_HANDLE is an opaque handle used to traverse the absolute paths
|
||||
* assigned to the PATH environment variable.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
|
||||
typedef FAR void *EXEPATH_HANDLE;
|
||||
#endif
|
||||
|
||||
/* The type of one C++ constructor or destructor */
|
||||
|
||||
typedef FAR void (*binfmt_ctor_t)(void);
|
||||
typedef FAR void (*binfmt_dtor_t)(void);
|
||||
|
||||
/* This describes the file to be loaded.
|
||||
*
|
||||
* NOTE 1: The 'filename' must be the full, absolute path to the file to be
|
||||
* executed unless CONFIG_BINFMT_EXEPATH is defined. In that case,
|
||||
* 'filename' may be a relative path; a set of candidate absolute paths
|
||||
* will be generated using the PATH environment variable and load_module()
|
||||
* will attempt to load each file that is found at those absolute paths.
|
||||
*/
|
||||
|
||||
struct symtab_s;
|
||||
struct binary_s
|
||||
{
|
||||
/* Information provided to the loader to load and bind a module */
|
||||
|
||||
FAR const char *filename; /* Full path to the binary to be loaded (See NOTE 1 above) */
|
||||
FAR const char **argv; /* Argument list */
|
||||
FAR const struct symtab_s *exports; /* Table of exported symbols */
|
||||
int nexports; /* The number of symbols in exports[] */
|
||||
|
||||
/* Information provided from the loader (if successful) describing the
|
||||
* resources used by the loaded module.
|
||||
*/
|
||||
|
||||
main_t entrypt; /* Entry point into a program module */
|
||||
FAR void *mapped; /* Memory-mapped, address space */
|
||||
FAR void *alloc[BINFMT_NALLOC]; /* Allocated address spaces */
|
||||
|
||||
/* Constructors/destructors */
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */
|
||||
FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */
|
||||
uint16_t nctors; /* Number of constructors in the list */
|
||||
uint16_t ndtors; /* Number of destructors in the list */
|
||||
#endif
|
||||
|
||||
/* Address environment.
|
||||
*
|
||||
* addrenv - This is the handle created by up_addrenv_create() that can be
|
||||
* used to manage the tasks address space.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
task_addrenv_t addrenv; /* Task address environment */
|
||||
#endif
|
||||
|
||||
size_t mapsize; /* Size of the mapped address region (needed for munmap) */
|
||||
size_t stacksize; /* Size of the stack in bytes (unallocated) */
|
||||
};
|
||||
|
||||
/* This describes one binary format handler */
|
||||
|
||||
struct binfmt_s
|
||||
{
|
||||
FAR struct binfmt_s *next; /* Supports a singly-linked list */
|
||||
int (*load)(FAR struct binary_s *bin); /* Verify and load binary into memory */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: register_binfmt
|
||||
*
|
||||
* Description:
|
||||
* Register a loader for a binary format
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int register_binfmt(FAR struct binfmt_s *binfmt);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: unregister_binfmt
|
||||
*
|
||||
* Description:
|
||||
* Register a loader for a binary format
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int unregister_binfmt(FAR struct binfmt_s *binfmt);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: load_module
|
||||
*
|
||||
* Description:
|
||||
* Load a module into memory, bind it to an exported symbol take, and
|
||||
* prep the module for execution.
|
||||
*
|
||||
* Returned Value:
|
||||
* This is an end-user function, so it follows the normal convention:
|
||||
* Returns 0 (OK) on success. On failure, it returns -1 (ERROR) with
|
||||
* errno set appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int load_module(FAR struct binary_s *bin);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: unload_module
|
||||
*
|
||||
* Description:
|
||||
* Unload a (non-executing) module from memory. If the module has
|
||||
* been started (via exec_module) and has not exited, calling this will
|
||||
* be fatal.
|
||||
*
|
||||
* However, this function must be called after the module exist. How
|
||||
* this is done is up to your logic. Perhaps you register it to be
|
||||
* called by on_exit()?
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int unload_module(FAR const struct binary_s *bin);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exec_module
|
||||
*
|
||||
* Description:
|
||||
* Execute a module that has been loaded into memory by load_module().
|
||||
*
|
||||
* Returned Value:
|
||||
* This is an end-user function, so it follows the normal convention:
|
||||
* Returns the PID of the exec'ed module. On failure, it.returns
|
||||
* -1 (ERROR) and sets errno appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int exec_module(FAR const struct binary_s *bin, int priority);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exec
|
||||
*
|
||||
* Description:
|
||||
* This is a convenience function that wraps load_ and exec_module into
|
||||
* one call.
|
||||
*
|
||||
* Input Parameter:
|
||||
* filename - Fulll path to the binary to be loaded
|
||||
* argv - Argument list
|
||||
* exports - Table of exported symbols
|
||||
* nexports - The number of symbols in exports
|
||||
*
|
||||
* Returned Value:
|
||||
* This is an end-user function, so it follows the normal convention:
|
||||
* Returns the PID of the exec'ed module. On failure, it.returns
|
||||
* -1 (ERROR) and sets errno appropriately.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int exec(FAR const char *filename, FAR const char **argv,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exepath_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize for the traversal of each value in the PATH variable. The
|
||||
* usage is sequence is as follows:
|
||||
*
|
||||
* 1) Call exepath_init() to initialize for the traversal. exepath_init()
|
||||
* will return an opaque handle that can then be provided to
|
||||
* exepath_next() and exepath_release().
|
||||
* 2) Call exepath_next() repeatedly to examine every file that lies
|
||||
* in the directories of the PATH variable
|
||||
* 3) Call exepath_release() to free resources set aside by exepath_init().
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, exepath_init() return a non-NULL, opaque handle that may
|
||||
* subsequently be used in calls to exepath_next() and exepath_release().
|
||||
* On error, a NULL handle value will be returned. The most likely cause
|
||||
* of an error would be that the there is no value associated with the
|
||||
* PATH variable.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
|
||||
EXEPATH_HANDLE exepath_init(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exepath_next
|
||||
*
|
||||
* Description:
|
||||
* Traverse all possible values in the PATH variable in attempt to find
|
||||
* the full path to an executable file when only a relative path is
|
||||
* provided.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle value returned by exepath_init
|
||||
* relpath - The relative path to the file to be found.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a non-NULL pointer to a null-terminated string is provided.
|
||||
* This is the full path to a file that exists in the file system. This
|
||||
* function will verify that the file exists (but will not verify that it
|
||||
* is marked executable).
|
||||
*
|
||||
* NOTE: The string pointer return in the success case points to allocated
|
||||
* memory. This memory must be freed by the called by calling kfree().
|
||||
*
|
||||
* NULL is returned if no path is found to any file with the provided
|
||||
* 'relpath' from any absolute path in the PATH variable. In this case,
|
||||
* there is no point in calling exepath_next() further; exepath_release()
|
||||
* must be called to release resources set aside by expath_init().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
|
||||
FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exepath_release
|
||||
*
|
||||
* Description:
|
||||
* Release all resources set aside by exepath_init() when the handle value
|
||||
* was created. The handle value is invalid on return from this function.
|
||||
* Attempts to all exepath_next() or exepath_release() with such a 'stale'
|
||||
* handle will result in undefined (i.e., not good) behavior.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle value returned by exepath_init
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
|
||||
void exepath_release(EXEPATH_HANDLE handle);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_BINFMT_BINFMT_H */
|
||||
|
||||
@@ -0,0 +1,340 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/binfmt/elf.h
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_BINFMT_ELF_H
|
||||
#define __INCLUDE_NUTTX_BINFMT_ELF_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <elf32.h>
|
||||
|
||||
#include <nuttx/binfmt/binfmt.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
#ifndef CONFIG_ELF_ALIGN_LOG2
|
||||
# define CONFIG_ELF_ALIGN_LOG2 2
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ELF_STACKSIZE
|
||||
# define CONFIG_ELF_STACKSIZE 2048
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ELF_BUFFERSIZE
|
||||
# define CONFIG_ELF_BUFFERSIZE 128
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ELF_BUFFERINCR
|
||||
# define CONFIG_ELF_BUFFERINCR 32
|
||||
#endif
|
||||
|
||||
/* Allocation array size and indices */
|
||||
|
||||
#define LIBELF_ELF_ALLOC 0
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
# define LIBELF_CTORS_ALLOC 1
|
||||
# define LIBELF_CTPRS_ALLOC 2
|
||||
# define LIBELF_NALLOC 3
|
||||
#else
|
||||
# define LIBELF_NALLOC 1
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This struct provides a desciption of the currently loaded instantiation
|
||||
* of an ELF binary.
|
||||
*/
|
||||
|
||||
struct elf_loadinfo_s
|
||||
{
|
||||
/* elfalloc is the base address of the memory that is allocated to hold the
|
||||
* ELF program image.
|
||||
*
|
||||
* If CONFIG_ADDRENV=n, elfalloc will be allocated using kmalloc() (or
|
||||
* kzalloc()). If CONFIG_ADDRENV-y, then elfalloc will be allocated using
|
||||
* up_addrenv_create(). In either case, there will be a unique instance
|
||||
* of elfalloc (and stack) for each instance of a process.
|
||||
*
|
||||
* The alloc[] array in struct binary_s will hold memory that persists after
|
||||
* the ELF module has been loaded.
|
||||
*/
|
||||
|
||||
uintptr_t elfalloc; /* Memory allocated when ELF file was loaded */
|
||||
size_t elfsize; /* Size of the ELF memory allocation */
|
||||
off_t filelen; /* Length of the entire ELF file */
|
||||
Elf32_Ehdr ehdr; /* Buffered ELF file header */
|
||||
FAR Elf32_Shdr *shdr; /* Buffered ELF section headers */
|
||||
uint8_t *iobuffer; /* File I/O buffer */
|
||||
|
||||
/* Constructors and destructors */
|
||||
|
||||
#ifdef CONFIG_BINFMT_CONSTRUCTORS
|
||||
FAR void *ctoralloc; /* Memory allocated for ctors */
|
||||
FAR void *dtoralloc; /* Memory allocated dtors */
|
||||
FAR binfmt_ctor_t *ctors; /* Pointer to a list of constructors */
|
||||
FAR binfmt_dtor_t *dtors; /* Pointer to a list of destructors */
|
||||
uint16_t nctors; /* Number of constructors */
|
||||
uint16_t ndtors; /* Number of destructors */
|
||||
#endif
|
||||
|
||||
/* Address environment.
|
||||
*
|
||||
* addrenv - This is the handle created by up_addrenv_create() that can be
|
||||
* used to manage the tasks address space.
|
||||
* oldenv - This is a value returned by up_addrenv_select() that must be
|
||||
* used to restore the current hardware address environment.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
task_addrenv_t addrenv; /* Task address environment */
|
||||
hw_addrenv_t oldenv; /* Saved hardware address environment */
|
||||
#endif
|
||||
|
||||
uint16_t symtabidx; /* Symbol table section index */
|
||||
uint16_t strtabidx; /* String table section index */
|
||||
uint16_t buflen; /* size of iobuffer[] */
|
||||
int filfd; /* Descriptor for the file being loaded */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs exported by libelf (but are used only by the binfmt logic):
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_init
|
||||
*
|
||||
* Description:
|
||||
* This function is called to configure the library to process an ELF
|
||||
* program binary.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int elf_init(FAR const char *filename,
|
||||
FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_uninit
|
||||
*
|
||||
* Description:
|
||||
* Releases any resources committed by elf_init(). This essentially
|
||||
* undoes the actions of elf_init.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int elf_uninit(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_load
|
||||
*
|
||||
* Description:
|
||||
* Loads the binary into memory, allocating memory, performing relocations
|
||||
* and inializing the data and bss segments.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int elf_load(FAR struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_bind
|
||||
*
|
||||
* Description:
|
||||
* Bind the imported symbol names in the loaded module described by
|
||||
* 'loadinfo' using the exported symbol values provided by 'symtab'.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct symtab_s;
|
||||
EXTERN int elf_bind(FAR struct elf_loadinfo_s *loadinfo,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_unload
|
||||
*
|
||||
* Description:
|
||||
* This function unloads the object from memory. This essentially undoes
|
||||
* the actions of elf_load. It is called only under certain error
|
||||
* conditions after the the module has been loaded but not yet started.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int elf_unload(struct elf_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs used outside of binfmt by NuttX:
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: elf_initialize
|
||||
*
|
||||
* Description:
|
||||
* ELF support is built unconditionally. However, it order to
|
||||
* use this binary format, this function must be called during system
|
||||
* format in order to register the ELF binary format.
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int elf_initialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: elf_uninitialize
|
||||
*
|
||||
* Description:
|
||||
* Unregister the ELF binary loader
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void elf_uninitialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs must be provided by architecture-specific logic:
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: arch_checkarch
|
||||
*
|
||||
* Description:
|
||||
* Given the ELF header in 'hdr', verify that the ELF file is appropriate
|
||||
* for the current, configured architecture. Every architecture that uses
|
||||
* the ELF loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* hdr - The ELF header read from the ELF file.
|
||||
*
|
||||
* Returned Value:
|
||||
* True if the architecture supports this ELF file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN bool arch_checkarch(FAR const Elf32_Ehdr *hdr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arch_relocate and arch_relocateadd
|
||||
*
|
||||
* Description:
|
||||
* Perform on architecture-specific ELF relocation. Every architecture
|
||||
* that uses the ELF loader must provide this function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* rel - The relocation type
|
||||
* sym - The ELF symbol structure containing the fully resolved value.
|
||||
* addr - The address that requires the relocation.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the relocation was successful. Otherwise, a negated errno
|
||||
* value indicating the cause of the relocation failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int arch_relocate(FAR const Elf32_Rel *rel, FAR const Elf32_Sym *sym,
|
||||
uintptr_t addr);
|
||||
EXTERN int arch_relocateadd(FAR const Elf32_Rela *rel,
|
||||
FAR const Elf32_Sym *sym, uintptr_t addr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arch_flushicache
|
||||
*
|
||||
* Description:
|
||||
* Flush the instruction cache.
|
||||
*
|
||||
* Input Parameters:
|
||||
* addr - Start address to flush
|
||||
* len - Number of bytes to flush
|
||||
*
|
||||
* Returned Value:
|
||||
* True if the architecture supports this ELF file.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ELF_ICACHE
|
||||
EXTERN bool arch_flushicache(FAR void *addr, size_t len);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_BINFMT_ELF_H */
|
||||
@@ -0,0 +1,287 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/binfmt/nxflat.h
|
||||
*
|
||||
* Copyright (C) 2009, 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_BINFMT_NXFLAT_H
|
||||
#define __INCLUDE_NUTTX_BINFMT_NXFLAT_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <nxflat.h>
|
||||
|
||||
#include <nuttx/sched.h>
|
||||
#include <nuttx/arch.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This struct provides a desciption of the currently loaded instantiation
|
||||
* of an nxflat binary.
|
||||
*/
|
||||
|
||||
struct nxflat_loadinfo_s
|
||||
{
|
||||
/* Instruction Space (ISpace): This region contains the nxflat file header
|
||||
* plus everything from the text section.
|
||||
*
|
||||
* The ISpace region is allocated using mmap() and, thus, can be shared by
|
||||
* multiple tasks. Ideally, will have only one mmap'ed text section
|
||||
* instance in the system for each module.
|
||||
*/
|
||||
|
||||
uintptr_t ispace; /* Address where hdr/text is loaded */
|
||||
uint32_t entryoffs; /* Offset from ispace to entry point */
|
||||
uint32_t isize; /* Size of ispace. */
|
||||
|
||||
/* Data Space (DSpace): This region contains all information that is
|
||||
* referenced as data (other than the stack which is separately allocated).
|
||||
*
|
||||
* If CONFIG_ADDRENV=n, DSpace will be allocated using kmalloc() (or
|
||||
* kzalloc()). If CONFIG_ADDRENV-y, then DSpace will be allocated using
|
||||
* up_addrenv_create(). In either case, there will be a unique instance
|
||||
* of DSpace (and stack) for each instance of a process.
|
||||
*/
|
||||
|
||||
struct dspace_s *dspace; /* Allocated D-Space (data/bss/etc) */
|
||||
uint32_t datasize; /* Size of data segment in dspace */
|
||||
uint32_t bsssize; /* Size of bss segment in dspace */
|
||||
uint32_t stacksize; /* Size of stack (not allocated) */
|
||||
uint32_t dsize; /* Size of dspace (may be large than parts) */
|
||||
|
||||
/* This is temporary memory where relocation records will be loaded. */
|
||||
|
||||
uint32_t relocstart; /* Start of array of struct flat_reloc */
|
||||
uint16_t reloccount; /* Number of elements in reloc array */
|
||||
|
||||
/* Address environment.
|
||||
*
|
||||
* addrenv - This is the handle created by up_addrenv_create() that can be
|
||||
* used to manage the tasks address space.
|
||||
* oldenv - This is a value returned by up_addrenv_select() that must be
|
||||
* used to restore the current hardware address environment.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ADDRENV
|
||||
task_addrenv_t addrenv; /* Task address environment */
|
||||
hw_addrenv_t oldenv; /* Saved hardware address environment */
|
||||
#endif
|
||||
|
||||
/* File descriptors */
|
||||
|
||||
int filfd; /* Descriptor for the file being loaded */
|
||||
|
||||
/* This is a copy of the NXFLAT header (still in network order) */
|
||||
|
||||
struct nxflat_hdr_s header;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C" {
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs exported by libnxflat (and may be used outside of NuttX):
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_verifyheader
|
||||
*
|
||||
* Description:
|
||||
* Given the header from a possible NXFLAT executable, verify that it is
|
||||
* an NXFLAT executable.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_verifyheader(const struct nxflat_hdr_s *header);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_init
|
||||
*
|
||||
* Description:
|
||||
* This function is called to configure the library to process an NXFLAT
|
||||
* program binary.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_init(const char *filename,
|
||||
struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_uninit
|
||||
*
|
||||
* Description:
|
||||
* Releases any resources committed by nxflat_init(). This essentially
|
||||
* undoes the actions of nxflat_init.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_load
|
||||
*
|
||||
* Description:
|
||||
* Loads the binary specified by nxflat_init into memory, mapping
|
||||
* the I-space executable regions, allocating the D-Space region,
|
||||
* and inializing the data segment (relocation information is
|
||||
* temporarily loaded into the BSS region. BSS will be cleared
|
||||
* by nxflat_bind() after the relocation data has been processed).
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_load(struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_read
|
||||
*
|
||||
* Description:
|
||||
* Read 'readsize' bytes from the object file at 'offset'
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
|
||||
int readsize, int offset);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_bind
|
||||
*
|
||||
* Description:
|
||||
* Bind the imported symbol names in the loaded module described by
|
||||
* 'loadinfo' using the exported symbol values provided by 'symtab'
|
||||
* After binding the module, clear the BSS region (which held the relocation
|
||||
* data) in preparation for execution.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
struct symtab_s;
|
||||
EXTERN int nxflat_bind(FAR struct nxflat_loadinfo_s *loadinfo,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_unload
|
||||
*
|
||||
* Description:
|
||||
* This function unloads the object from memory. This essentially undoes
|
||||
* the actions of nxflat_load. It is called only under certain error
|
||||
* conditions after the the module has been loaded but not yet started.
|
||||
*
|
||||
* Returned Value:
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_unload(struct nxflat_loadinfo_s *loadinfo);
|
||||
|
||||
/****************************************************************************
|
||||
* These are APIs used internally only by NuttX:
|
||||
****************************************************************************/
|
||||
/****************************************************************************
|
||||
* Name: nxflat_initialize
|
||||
*
|
||||
* Description:
|
||||
* NXFLAT support is built unconditionally. However, it order to
|
||||
* use this binary format, this function must be called during system
|
||||
* format in order to register the NXFLAT binary format.
|
||||
*
|
||||
* Returned Value:
|
||||
* This is a NuttX internal function so it follows the convention that
|
||||
* 0 (OK) is returned on success and a negated errno is returned on
|
||||
* failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN int nxflat_initialize(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: nxflat_uninitialize
|
||||
*
|
||||
* Description:
|
||||
* Unregister the NXFLAT binary loader
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
EXTERN void nxflat_uninitialize(void);
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_BINFMT_NXFLAT_H */
|
||||
@@ -255,7 +255,7 @@
|
||||
* external RAM.
|
||||
*/
|
||||
|
||||
#if defined(__z80) || defined(__gbz80)
|
||||
#if defined(__SDCC_z80) || defined(__SDCC_z180) || defined(__SDCC_gbz80)
|
||||
# define FAR
|
||||
# define NEAR
|
||||
# define CODE
|
||||
|
||||
@@ -172,7 +172,7 @@ struct mountpt_operations
|
||||
|
||||
int (*statfs)(FAR struct inode *mountpt, FAR struct statfs *buf);
|
||||
|
||||
/* Operations on pathes */
|
||||
/* Operations on paths */
|
||||
|
||||
int (*unlink)(FAR struct inode *mountpt, FAR const char *relpath);
|
||||
int (*mkdir)(FAR struct inode *mountpt, FAR const char *relpath, mode_t mode);
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
/************************************************************************************
|
||||
* include/nuttx/input/keypad.h
|
||||
*
|
||||
* Copyright (C) 2012 Denis Carikli.
|
||||
* Author: Denis Carikli <GNUtoo@no-log.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_INPUT_KEYPAD_H
|
||||
#define __INCLUDE_NUTTX_INPUT_KEYPAD_H
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int keypad_kbdinit(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_INPUT_KEYPAD_H */
|
||||
|
||||
+268
-2
@@ -50,14 +50,280 @@
|
||||
|
||||
#ifdef CONFIG_ARCH_MATH_H
|
||||
# include <arch/math.h>
|
||||
#endif
|
||||
|
||||
/* If CONFIG_LIB is enabled, then the math library at lib/math will be
|
||||
* built. This library was taken from the math library developed for the
|
||||
* Rhombus OS by Nick Johnson (https://github.com/nickbjohnson4224/rhombus).
|
||||
* The port or the Rhombus math library was contributed by Darcy Gong.
|
||||
*/
|
||||
|
||||
#else if defined CONFIG_LIBM
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* General Constants ********************************************************/
|
||||
|
||||
#define INFINITY (1.0/0.0)
|
||||
#define NAN (0.0/0.0)
|
||||
#define HUGE_VAL INFINITY
|
||||
|
||||
#define isnan(x) ((x) != (x))
|
||||
#define isinf(x) (((x) == INFINITY) || ((x) == -INFINITY))
|
||||
|
||||
/* Exponential and Logarithmic constants ************************************/
|
||||
|
||||
#define M_E 2.7182818284590452353602874713526625
|
||||
#define M_SQRT2 1.4142135623730950488016887242096981
|
||||
#define M_SQRT1_2 0.7071067811865475244008443621048490
|
||||
#define M_LOG2E 1.4426950408889634073599246810018921
|
||||
#define M_LOG10E 0.4342944819032518276511289189166051
|
||||
#define M_LN2 0.6931471805599453094172321214581765
|
||||
#define M_LN10 2.3025850929940456840179914546843642
|
||||
|
||||
/* Trigonometric Constants **************************************************/
|
||||
|
||||
#define M_PI 3.1415926535897932384626433832795029
|
||||
#define M_PI_2 1.5707963267948966192313216916397514
|
||||
#define M_PI_4 0.7853981633974483096156608458198757
|
||||
#define M_1_PI 0.3183098861837906715377675267450287
|
||||
#define M_2_PI 0.6366197723675813430755350534900574
|
||||
#define M_2_SQRTPI 1.1283791670955125738961589031215452
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* General Functions ********************************************************/
|
||||
|
||||
float ceilf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double ceil (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double ceill (long double x);
|
||||
#endif
|
||||
|
||||
float floorf(float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double floor (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double floorl(long double x);
|
||||
#endif
|
||||
|
||||
float roundf(float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double round (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double roundl(long double x);
|
||||
#endif
|
||||
|
||||
float fabsf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double fabs (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double fabsl (long double x);
|
||||
#endif
|
||||
|
||||
float modff (float x, float *iptr);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double modf (double x, double *iptr);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double modfl (long double x, long double *iptr);
|
||||
#endif
|
||||
|
||||
float fmodf (float x, float div);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double fmod (double x, double div);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double fmodl (long double x, long double div);
|
||||
#endif
|
||||
|
||||
/* Exponential and Logarithmic Functions ************************************/
|
||||
|
||||
float powf (float b, float e);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double pow (double b, double e);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double powl (long double b, long double e);
|
||||
#endif
|
||||
|
||||
float expf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double exp (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double expl (long double x);
|
||||
#endif
|
||||
|
||||
float logf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double log (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double logl (long double x);
|
||||
#endif
|
||||
|
||||
float log10f(float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double log10 (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double log10l(long double x);
|
||||
#endif
|
||||
|
||||
float log2f (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double log2 (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double log2l (long double x);
|
||||
#endif
|
||||
|
||||
float sqrtf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double sqrt (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double sqrtl (long double x);
|
||||
#endif
|
||||
|
||||
float ldexpf(float x, int n);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double ldexp (double x, int n);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double ldexpl(long double x, int n);
|
||||
#endif
|
||||
|
||||
float frexpf(float x, int *exp);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double frexp (double x, int *exp);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double frexpl(long double x, int *exp);
|
||||
#endif
|
||||
|
||||
/* Trigonometric Functions **************************************************/
|
||||
|
||||
float sinf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double sin (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double sinl (long double x);
|
||||
#endif
|
||||
|
||||
float cosf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double cos (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double cosl (long double x);
|
||||
#endif
|
||||
|
||||
float tanf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double tan (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double tanl (long double x);
|
||||
#endif
|
||||
|
||||
float asinf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double asin (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double asinl (long double x);
|
||||
#endif
|
||||
|
||||
float acosf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double acos (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double acosl (long double x);
|
||||
#endif
|
||||
|
||||
float atanf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double atan (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double atanl (long double x);
|
||||
#endif
|
||||
|
||||
float atan2f(float y, float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double atan2 (double y, double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double atan2l(long double y, long double x);
|
||||
#endif
|
||||
|
||||
float sinhf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double sinh (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double sinhl (long double x);
|
||||
#endif
|
||||
|
||||
float coshf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double cosh (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double coshl (long double x);
|
||||
#endif
|
||||
|
||||
float tanhf (float x);
|
||||
#if CONFIG_HAVE_DOUBLE
|
||||
double tanh (double x);
|
||||
#endif
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double tanhl (long double x);
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_LIBM */
|
||||
#endif /* __INCLUDE_NUTTX_MATH_H */
|
||||
|
||||
@@ -220,7 +220,6 @@ EXTERN FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev);
|
||||
|
||||
EXTERN FAR struct mtd_dev_s *sst25_initialize(FAR struct spi_dev_s *dev);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: w25_initialize
|
||||
*
|
||||
@@ -233,6 +232,8 @@ EXTERN FAR struct mtd_dev_s *sst25_initialize(FAR struct spi_dev_s *dev);
|
||||
|
||||
EXTERN FAR struct mtd_dev_s *w25_initialize(FAR struct spi_dev_s *dev);
|
||||
|
||||
EXTERN FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -163,24 +163,40 @@ typedef struct environ_s environ_t;
|
||||
# define SIZEOF_ENVIRON_T(alloc) (sizeof(environ_t) + alloc - 1)
|
||||
#endif
|
||||
|
||||
/* This structure describes a reference counted D-Space region */
|
||||
/* This structure describes a reference counted D-Space region. This must be a
|
||||
* separately allocated "break-away" structure that can be owned by a task and
|
||||
* any pthreads created by the task.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_PIC
|
||||
struct dspace_s
|
||||
{
|
||||
uint32_t crefs; /* This is the number of pthreads that shared the
|
||||
* the same D-Space */
|
||||
uint8_t region[1]; /* Beginning of the allocated region */
|
||||
/* The life of the structure allocation is determined by this reference
|
||||
* count. This count is number of threads that shared the the same D-Space.
|
||||
* This includes the parent task as well as any pthreads created by the
|
||||
* parent task or any of its child threads.
|
||||
*/
|
||||
|
||||
uint16_t crefs;
|
||||
|
||||
/* This is the allocated D-Space memory region. This may be a physical
|
||||
* address allocated with kmalloc(), or it may be virtual address associated
|
||||
* with an address environment (if CONFIG_ADDRENV=y).
|
||||
*/
|
||||
|
||||
FAR uint8_t *region;
|
||||
};
|
||||
#endif
|
||||
|
||||
#define SIZEOF_DSPACE_S(n) (sizeof(struct dspace_s) - 1 + (n))
|
||||
|
||||
/* This is the task control block (TCB) */
|
||||
/* This is the task control block (TCB). Each task or thread is represented by
|
||||
* a TCB. The TCB is the heart of the NuttX task-control logic.
|
||||
*/
|
||||
|
||||
struct _TCB
|
||||
{
|
||||
/* Fields used to support list management *************************************/
|
||||
|
||||
FAR struct _TCB *flink; /* link in DQ of TCBs */
|
||||
FAR struct _TCB *flink; /* Doubly linked list */
|
||||
FAR struct _TCB *blink;
|
||||
|
||||
/* Task Management Fields *****************************************************/
|
||||
|
||||
@@ -179,8 +179,8 @@
|
||||
#define VT52_CLEAREOL {ASCII_ESC, 'K'} /* Erase to end of current line */
|
||||
#define VT52_CLEAREOS {ASCII_ESC, 'J'} /* Erase to end of screen */
|
||||
|
||||
#define VT52_IDENT {ASCII_ESC, 'Z'} /* dentify what the terminal is */
|
||||
#define VT52_IDENTRESP {ASCII_ESC, '/', 'Z'} /* Correct response to ident */
|
||||
#define VT52_IDENT {ASCII_ESC, 'Z'} /* Identify what the terminal is */
|
||||
#define VT52_IDENTRESP {ASCII_ESC, '/', 'Z'} /* Correct response to ident */
|
||||
|
||||
/* VT100 Special Key Codes
|
||||
*
|
||||
|
||||
+33
-2
@@ -42,10 +42,33 @@
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/* If CONFIG_ARCH_STDBOOL_H is set, then the archecture will provide its own
|
||||
* stdbool.h file. In this case, this header file will simply re-direct to
|
||||
* the architecture-specfiic stdbool.h header file.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_ARCH_STDBOOL_H
|
||||
# include <arch/stdbool.h>
|
||||
|
||||
/* NuttX will insist that the sizeof(bool) is 8-bits. The sizeof of _Bool
|
||||
* used by any specific compiler is implementation specific: It can vary from
|
||||
* compiler-to-compiler and even vary between different versions of the same
|
||||
* compiler. Compilers seems to be converging to sizeof(_Bool) == 1. If that
|
||||
* is true for your compiler, you should define CONFIG_C99_BOOL8 in your NuttX
|
||||
* configuration for better standards compatibility.
|
||||
*
|
||||
* CONFIG_C99_BOOL8 - Means (1) your C++ compiler has sizeof(_Bool) == 8,
|
||||
* (2) your C compiler supports the C99 _Bool intrinsic type, and (2) that
|
||||
* the C99 _Bool type also has size 1.
|
||||
*/
|
||||
|
||||
#else
|
||||
|
||||
/* nuttx/compiler.h may also define or undefine CONFIG_C99_BOOL8 */
|
||||
|
||||
# include <nuttx/compiler.h>
|
||||
|
||||
#if !defined(__cplusplus) || !defined(CONFIG_C99_BOOL8)
|
||||
# include <stdint.h>
|
||||
|
||||
/****************************************************************************
|
||||
@@ -58,10 +81,15 @@
|
||||
* NOTE: Under C99 'bool' is required to be defined to be the intrinsic type
|
||||
* _Bool. However, in this NuttX context, we need backward compatibility
|
||||
* to pre-C99 standards where _Bool is not an intrinsic type. Hence, we
|
||||
* use _Bool8 as the underlying type.
|
||||
* use _Bool8 as the underlying type (unless CONFIG_C99_BOOL8 is defined)
|
||||
*/
|
||||
|
||||
#define bool _Bool8
|
||||
#ifdef CONFIG_C99_BOOL8
|
||||
# define bool _Bool
|
||||
#else
|
||||
# define bool _Bool8
|
||||
#endif
|
||||
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
@@ -83,7 +111,10 @@
|
||||
* as the underlying type.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_C99_BOOL8
|
||||
typedef uint8_t _Bool8;
|
||||
#endif
|
||||
|
||||
#endif /* __cplusplus && CONFIG_C99_BOOL8 */
|
||||
#endif /* CONFIG_ARCH_STDBOOL_H */
|
||||
#endif /* __INCLUDE_STDBOOL_H */
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
############################################################################
|
||||
# libc/math/Make.defs
|
||||
#
|
||||
# Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# 1. Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# 2. Redistributions in binary form must reproduce the above copyright
|
||||
# notice, this list of conditions and the following disclaimer in
|
||||
# the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# 3. Neither the name NuttX nor the names of its contributors may be
|
||||
# used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
############################################################################
|
||||
|
||||
ifeq ($(CONFIG_LIBM),y)
|
||||
|
||||
# Add the floating point math C files to the build
|
||||
|
||||
CSRCS += lib_acosf.c lib_asinf.c lib_atan2f.c lib_atanf.c lib_ceilf.c lib_cosf.c
|
||||
CSRCS += lib_coshf.c lib_expf.c lib_fabsf.c lib_floorf.c lib_fmodf.c lib_frexpf.c
|
||||
CSRCS += lib_ldexpf.c lib_logf.c lib_log10f.c lib_log2f.c lib_modff.c lib_powf.c
|
||||
CSRCS += lib_roundf.c lib_sinf.c lib_sinhf.c lib_sqrtf.c lib_tanf.c lib_tanhf.c
|
||||
|
||||
CSRCS += lib_acos.c lib_asin.c lib_atan.c lib_atan2.c lib_ceil.c lib_cos.c
|
||||
CSRCS += lib_cosh.c lib_exp.c lib_fabs.c lib_floor.c lib_fmod.c lib_frexp.c
|
||||
CSRCS += lib_ldexp.c lib_log.c lib_log10.c lib_log2.c lib_modf.c lib_pow.c
|
||||
CSRCS += lib_round.c lib_sin.c lib_sinh.c lib_sqrt.c lib_tan.c lib_tanh.c
|
||||
|
||||
CSRCS += lib_acosl.c lib_asinl.c lib_atan2l.c lib_atanl.c lib_ceill.c lib_cosl.c
|
||||
CSRCS += lib_coshl.c lib_expl.c lib_fabsl.c lib_floorl.c lib_fmodl.c lib_frexpl.c
|
||||
CSRCS += lib_ldexpl.c lib_logl.c lib_log10l.c lib_log2l.c lib_modfl.c lib_powl.c
|
||||
CSRCS += lib_roundl.c lib_sinl.c lib_sinhl.c lib_sqrtl.c lib_tanl.c lib_tanhl.c
|
||||
|
||||
CSRCS += lib_libexpi.c lib_libsqrtapprox.c
|
||||
|
||||
# Add the floating point math directory to the build
|
||||
|
||||
DEPPATH += --dep-path math
|
||||
VPATH += :math
|
||||
|
||||
endif
|
||||
@@ -0,0 +1,40 @@
|
||||
/************************************************************************
|
||||
* lib/math/lib_round.c
|
||||
*
|
||||
* This file is a part of NuttX:
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* (C) 2012 Petteri Aimonen <jpa@nx.mail.kapsi.fi>
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************/
|
||||
|
||||
#ifdef CONFIG_HAVE_DOUBLE
|
||||
double round(double x)
|
||||
{
|
||||
double f = modf(x, &x);
|
||||
if (x <= 0.0 && f <= -0.5)
|
||||
{
|
||||
x -= 1.0;
|
||||
}
|
||||
|
||||
if (x >= 0.0 && f >= 0.5)
|
||||
{
|
||||
x += 1.0;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
/************************************************************************
|
||||
* lib/math/lib_roundf.c
|
||||
*
|
||||
* This file is a part of NuttX:
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* (C) 2012 Petteri Aimonen <jpa@nx.mail.kapsi.fi>
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************/
|
||||
|
||||
float roundf(float x)
|
||||
{
|
||||
float f = modff(x, &x);
|
||||
if (x <= 0.0f && f <= -0.5f)
|
||||
{
|
||||
x -= 1.0f;
|
||||
}
|
||||
|
||||
if (x >= 0.0f && f >= 0.5f)
|
||||
{
|
||||
x += 1.0f;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/************************************************************************
|
||||
* lib/math/lib_round.c
|
||||
*
|
||||
* This file is a part of NuttX:
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* (C) 2012 Petteri Aimonen <jpa@nx.mail.kapsi.fi>
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
/************************************************************************
|
||||
* Included Files
|
||||
************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/************************************************************************
|
||||
* Public Functions
|
||||
************************************************************************/
|
||||
|
||||
#ifdef CONFIG_HAVE_LONG_DOUBLE
|
||||
long double roundl(long double x)
|
||||
{
|
||||
long double f = modfl(x, &x);
|
||||
if (x <= 0.0 && f <= -0.5)
|
||||
{
|
||||
x -= 1.0;
|
||||
}
|
||||
|
||||
if (x >= 0.0 && f >= 0.5)
|
||||
{
|
||||
x += 1.0;
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,277 @@
|
||||
/****************************************************************************
|
||||
* libc/stdlib/lib_rand.c
|
||||
*
|
||||
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
/* First, second, and thired order congruential generators are supported */
|
||||
|
||||
#ifndef CONFIG_LIB_RAND_ORDER
|
||||
# define CONFIG_LIB_RAND_ORDER 1
|
||||
#endif
|
||||
|
||||
#if CONFIG_LIB_RAND_ORDER > 3
|
||||
# undef CONFIG_LIB_RAND_ORDER
|
||||
# define CONFIG_LIB_RAND_ORDER 3
|
||||
#endif
|
||||
|
||||
/* Values needed by the random number generator */
|
||||
|
||||
#define RND1_CONSTK 470001
|
||||
#define RND1_CONSTP 999563
|
||||
#define RND2_CONSTK1 366528
|
||||
#define RND2_CONSTK2 508531
|
||||
#define RND2_CONSTP 998917
|
||||
#define RND3_CONSTK1 360137
|
||||
#define RND3_CONSTK2 519815
|
||||
#define RND3_CONSTK3 616087
|
||||
#define RND3_CONSTP 997783
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static unsigned int nrand(unsigned int nLimit);
|
||||
|
||||
/* First order congruential generators */
|
||||
|
||||
static inline unsigned long fgenerate1(void);
|
||||
#if (CONFIG_LIB_RAND_ORDER == 1)
|
||||
static double_t frand1(void);
|
||||
#endif
|
||||
|
||||
/* Second order congruential generators */
|
||||
|
||||
#if (CONFIG_LIB_RAND_ORDER > 1)
|
||||
static inline unsigned long fgenerate2(void);
|
||||
#if (CONFIG_LIB_RAND_ORDER == 2)
|
||||
static double_t frand2(void);
|
||||
#endif
|
||||
|
||||
/* Third order congruential generators */
|
||||
|
||||
#if (CONFIG_LIB_RAND_ORDER > 2)
|
||||
static inline unsigned long fgenerate3(void);
|
||||
static double_t frand3(void);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static unsigned long g_randint1;
|
||||
#if (CONFIG_LIB_RAND_ORDER > 1)
|
||||
static unsigned long g_randint2;
|
||||
#if (CONFIG_LIB_RAND_ORDER > 2)
|
||||
static unsigned long g_randint3;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static unsigned int nrand(unsigned int nLimit)
|
||||
{
|
||||
unsigned long result;
|
||||
double_t ratio;
|
||||
|
||||
/* Loop to be sure a legal random number is generated */
|
||||
|
||||
do
|
||||
{
|
||||
/* Get a random integer in the requested range */
|
||||
|
||||
#if (CONFIG_LIB_RAND_ORDER == 1)
|
||||
ratio = frand1();
|
||||
#elif (CONFIG_LIB_RAND_ORDER == 2)
|
||||
ratio = frand2();
|
||||
#else /* if (CONFIG_LIB_RAND_ORDER > 2) */
|
||||
ratio = frand3();
|
||||
#endif
|
||||
|
||||
/* Then, produce the return-able value */
|
||||
|
||||
result = (unsigned long)(((double_t)nLimit) * ratio);
|
||||
}
|
||||
while (result >= (unsigned long)nLimit);
|
||||
|
||||
return (unsigned int)result;
|
||||
}
|
||||
|
||||
/* First order congruential generators */
|
||||
|
||||
static inline unsigned long fgenerate1(void)
|
||||
{
|
||||
unsigned long randint;
|
||||
|
||||
/* First order congruential generator. One may be added to the result of the
|
||||
* generated value to avoid the value zero. This would be fatal for the
|
||||
* first order random number generator.
|
||||
*/
|
||||
|
||||
randint = (RND1_CONSTK * g_randint1) % RND1_CONSTP;
|
||||
g_randint1 = (randint == 0 ? 1 : randint);
|
||||
return randint;
|
||||
}
|
||||
|
||||
#if (CONFIG_LIB_RAND_ORDER == 1)
|
||||
static double_t frand1(void)
|
||||
{
|
||||
/* First order congruential generator. */
|
||||
|
||||
unsigned long randint = fgenerate1();
|
||||
|
||||
/* Construct an floating point value in the range from 0.0 up to 1.0 */
|
||||
|
||||
return ((double_t)randint) / ((double_t)RND1_CONSTP);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Second order congruential generators */
|
||||
|
||||
#if (CONFIG_LIB_RAND_ORDER > 1)
|
||||
static inline unsigned long fgenerate2(void)
|
||||
{
|
||||
unsigned long randint;
|
||||
|
||||
/* Second order congruential generator. */
|
||||
|
||||
randint = (RND2_CONSTK1 * g_randint1 +
|
||||
RND2_CONSTK2 * g_randint2) % RND2_CONSTP;
|
||||
|
||||
g_randint2 = g_randint1;
|
||||
g_randint1 = randint;
|
||||
|
||||
/* We cannot permit both values to become zero. That would be fatal for the
|
||||
* second order random number generator.
|
||||
*/
|
||||
|
||||
if (g_randint2 == 0 && g_randint1 == 0)
|
||||
{
|
||||
g_randint2 = 1;
|
||||
}
|
||||
|
||||
return randint;
|
||||
}
|
||||
|
||||
#if (CONFIG_LIB_RAND_ORDER == 2)
|
||||
static double_t frand2(void)
|
||||
{
|
||||
/* Second order congruential generator */
|
||||
|
||||
unsigned long randint = fgenerate2();
|
||||
|
||||
/* Construct an floating point value in the range from 0.0 up to 1.0 */
|
||||
|
||||
return ((double_t)randint) / ((double_t)RND2_CONSTP);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Third order congruential generators */
|
||||
|
||||
#if (CONFIG_LIB_RAND_ORDER > 2)
|
||||
static inline unsigned long fgenerate3(void)
|
||||
{
|
||||
unsigned long randint;
|
||||
|
||||
/* Third order congruential generator. */
|
||||
|
||||
randint = (RND3_CONSTK1 * g_randint1 +
|
||||
RND3_CONSTK2 * g_randint2 +
|
||||
RND3_CONSTK2 * g_randint3) % RND3_CONSTP;
|
||||
|
||||
g_randint3 = g_randint2;
|
||||
g_randint2 = g_randint1;
|
||||
g_randint1 = randint;
|
||||
|
||||
/* We cannot permit all three values to become zero. That would be fatal for the
|
||||
* third order random number generator.
|
||||
*/
|
||||
|
||||
if (g_randint3 == 0 && g_randint2 == 0 && g_randint1 == 0)
|
||||
{
|
||||
g_randint3 = 1;
|
||||
}
|
||||
|
||||
return randint;
|
||||
}
|
||||
|
||||
static double_t frand3(void)
|
||||
{
|
||||
/* Third order congruential generator */
|
||||
|
||||
unsigned long randint = fgenerate3();
|
||||
|
||||
/* Construct an floating point value in the range from 0.0 up to 1.0 */
|
||||
|
||||
return ((double_t)randint) / ((double_t)RND3_CONSTP);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: srand, rand
|
||||
****************************************************************************/
|
||||
|
||||
void srand(unsigned int seed)
|
||||
{
|
||||
g_randint1 = seed;
|
||||
#if (CONFIG_LIB_RAND_ORDER > 1)
|
||||
g_randint2 = seed;
|
||||
(void)fgenerate1();
|
||||
#if (CONFIG_LIB_RAND_ORDER > 2)
|
||||
g_randint3 = seed;
|
||||
(void)fgenerate2();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
int rand(void)
|
||||
{
|
||||
return (int)nrand(32768);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/************************************************************
|
||||
* libc/string/lib_memcmp.c
|
||||
*
|
||||
* Copyright (C) 2007, 2011-2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/************************************************************
|
||||
* Global Functions
|
||||
************************************************************/
|
||||
|
||||
#ifndef CONFIG_ARCH_MEMCMP
|
||||
int memcmp(FAR const void *s1, FAR const void *s2, size_t n)
|
||||
{
|
||||
unsigned char *p1 = (unsigned char *)s1;
|
||||
unsigned char *p2 = (unsigned char *)s2;
|
||||
|
||||
while (n-- > 0)
|
||||
{
|
||||
if (*p1 < *p2)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
else if (*p1 > *p2)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
p1++;
|
||||
p2++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,77 @@
|
||||
/************************************************************
|
||||
* libc/string/lib_memmove.c
|
||||
*
|
||||
* Copyright (C) 2007, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Compilation Switches
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/************************************************************
|
||||
* Global Functions
|
||||
************************************************************/
|
||||
|
||||
#ifndef CONFIG_ARCH_MEMMOVE
|
||||
FAR void *memmove(FAR void *dest, FAR const void *src, size_t count)
|
||||
{
|
||||
char *tmp, *s;
|
||||
if (dest <= src)
|
||||
{
|
||||
tmp = (char*) dest;
|
||||
s = (char*) src;
|
||||
while (count--)
|
||||
{
|
||||
*tmp++ = *s++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (char*) dest + count;
|
||||
s = (char*) src + count;
|
||||
while (count--)
|
||||
{
|
||||
*--tmp = *--s;
|
||||
}
|
||||
}
|
||||
|
||||
return dest;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,136 @@
|
||||
/****************************************************************************
|
||||
* libc/string/lib_strstr.c
|
||||
*
|
||||
* Copyright (C) 2012 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use str 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 str binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer str
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static FAR char *strcasechr(FAR const char *s, int uc)
|
||||
{
|
||||
register char ch;
|
||||
|
||||
if (s)
|
||||
{
|
||||
for (; *s; s++)
|
||||
{
|
||||
ch = *s;
|
||||
if (toupper(ch) == uc)
|
||||
{
|
||||
return (FAR char*)s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Global Functions
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *strcasestr(FAR const char *str, FAR const char *substr)
|
||||
{
|
||||
const char *candidate; /* Candidate in str with matching start character */
|
||||
char ch; /* First character of the substring */
|
||||
int len; /* The length of the substring */
|
||||
|
||||
/* Special case the empty substring */
|
||||
|
||||
len = strlen(substr);
|
||||
ch = *substr;
|
||||
|
||||
if (!ch)
|
||||
{
|
||||
/* We'll say that an empty substring matches at the beginning of
|
||||
* the string
|
||||
*/
|
||||
|
||||
return (char*)str;
|
||||
}
|
||||
|
||||
/* Search for the substring */
|
||||
|
||||
candidate = str;
|
||||
ch = toupper(ch);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
/* strcasechr() will return a pointer to the next occurrence of the
|
||||
* character ch in the string (ignoring case)
|
||||
*/
|
||||
|
||||
candidate = strcasechr(candidate, ch);
|
||||
if (!candidate || strlen(candidate) < len)
|
||||
{
|
||||
/* First character of the substring does not appear in the string
|
||||
* or the remainder of the string is not long enough to contain the
|
||||
* substring.
|
||||
*/
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Check if this is the beginning of a matching substring (ignoring case) */
|
||||
|
||||
if (strncasecmp(candidate, substr, len) == 0)
|
||||
{
|
||||
/* Yes.. return the pointer to the first occurrence of the matching
|
||||
* substring.
|
||||
*/
|
||||
|
||||
return (char*)candidate;
|
||||
}
|
||||
|
||||
/* No, find the next candidate after this one */
|
||||
|
||||
candidate++;
|
||||
}
|
||||
|
||||
/* Won't get here, but some compilers might complain. Others might complain
|
||||
* about this code being unreachable too.
|
||||
*/
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user