- Minor changes to RTOS to support position independent code, and
- A linker to bind ELF binaries to produce the NXFLAT binary format
(See GIT).
Background
----------
NXFLAT is derived from `XFLAT <http://xflat.sourceforge.net/>`__. XFLAT
is a toolchain add that provides full shared library and XIP executable
support for processors that have no Memory Management Unit
(MMU:sup:`1`). NXFLAT is greatly simplified for the deeply embedded
environment targeted by Nuttx:
- NXFLAT does not support shared libraries, because
- NXFLAT does not support *exportation* of symbol values from a module
Rather, the NXFLAT module only *imports* symbol values. In the NXFLAT
model, the (PIC:sup:`2`) NXFLAT module resides in a FLASH file system
and when it is loaded at run time, it is dynamically linked only to the
(non-PIC) base NuttX code: The base NuttX *exports* a symbol table; the
NXFLAT module *imports* those symbol value to dynamically bind the
module to the base code.
Limitations
-----------
-**ROMFS (or RAM mapping) Only**:
The current NXFLAT release will work only with either (1) NXFLAT
executable modules residing on a ROMFS file system, or (2) executables
residing on other file systems provided that CONFIG_FS_RAMMAP is
defined. This limitation is because the loader depends on the capability
to mmap() the code segment. See the NuttX User Guide for further information.
NUTTX does not provide any general kind of file mapping capability.
In fact, true file mapping is only possible with MCUs that provide an MMU1.
Without an MMU, file system may support eXecution In Place (XIP) to mimic
file mapping. Only the ROMFS file system supports that kind of XIP execution
need by NXFLAT.
It is also possible to simulate file mapping by allocating memory, copying
the NXFLAT binary file into memory, and executing from the copy of the
executable file in RAM. That capability can be enabled with the CONFIG_FS_RAMMAP
configuration option. With that option enabled, NXFLAT will work that kind
of file system but will require copying of all NXFLAT executables to RAM.
-**GCC/ARM/Cortex-M3/4 Only**:
At present, the NXFLAT toolchain is only available for ARM and Cortex-M3/4 (thumb2) targets.
-**Read-Only Data in RAM**:
With older GCC compilers (at least up to 4.3.3), read-only data must
reside in RAM. In code generated by GCC, all data references are
indexed by the PIC2 base register (that is usually R10 or sl for the
ARM processors). The includes read-only data (.rodata). Embedded
firmware developers normally like to keep .rodata in FLASH with
the code sections. But because all data is referenced with the
PIC base register, all of that data must lie in RAM. A NXFLAT
change to work around this is under investigation3.
Newer GCC compilers (at least from 4.6.3), read-only data is
no long GOT-relative, but is now accessed PC-relative.
With PC relative addressing, read-only data must reside in the I-Space.
-**Globally Scoped Function Function Pointers**:
If a function pointer is taken to a statically defined function,
then (at least for ARM) GCC will generate a relocation that NXFLAT
cannot handle. The workaround is make all such functions global in
scope. A fix would involve a change to the GCC compiler as described
in Appendix B.
-**Special Handling of Callbacks**:
Callbacks through function pointers must be avoided or, when
then cannot be avoided, handled very specially. The reason
for this is that the PIC module requires setting of a special
value in a PIC register. If the callback does not set the PIC
register, then the called back function will fail because it
will be unable to correctly access data memory. Special logic
is in place to handle some NuttX callbacks: Signal callbacks
and watchdog timer callbacks. But other callbacks (like those
used with qsort() must be avoided in an NXFLAT module.
Supported Processors
--------------------
As mentioned `above <#limitations>`__, the NXFLAT toolchain is only
available for ARM and Cortex-M3 (thumb2) targets. Furthermore, NXFLAT
has only been tested on the Eagle-100 LMS6918 Cortex-M3 board.
Development Status
------------------
The initial release of NXFLAT was made in NuttX version 0.4.9. Testing
is limited to the tests found under ``apps/examples/nxflat`` in the
source tree. Some known problems exist (see the
`TODO <https://bitbucket.org/nuttx/nuttx/src/master/TODO>`__ list). As
such, NXFLAT is currently in an early alpha phase.
NXFLAT Toolchain
================
Building the NXFLAT Toolchain
-----------------------------
In order to use NXFLAT, you must use special NXFLAT tools to create the
binary module in FLASH. To do this, you will need to download the
buildroot package and build it on your Linux or Cygwin machine. The
buildroot can be downloaded from
`Bitbucket.org <https://bitbucket.org/nuttx/buildroot/downloads>`__. You
will need version 0.1.7 or later.
Here are some general build instructions:
- You must have already configured Nuttx in ``<some-dir>/nuttx``
- Download the buildroot package ``buildroot-0.x.y`` into
``<some-dir>``
- Unpack ``<some-dir>/buildroot-0.x.y.tar.gz`` using a command like ``tar zxf buildroot-0.x.y``. This will result in a new directory like ``<some-dir>/buildroot-0.x.y``