summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/examples/elf/Kconfig3
-rw-r--r--apps/examples/elf/elf_main.c4
-rw-r--r--nuttx/ChangeLog2
-rw-r--r--nuttx/Documentation/README.html5
-rw-r--r--nuttx/README.txt3
-rw-r--r--nuttx/binfmt/libpcode/Kconfig32
-rw-r--r--nuttx/binfmt/libpcode/Make.defs15
-rw-r--r--nuttx/binfmt/libpcode/README.txt51
-rw-r--r--nuttx/binfmt/libpcode/hello.pas5
-rw-r--r--nuttx/binfmt/libpcode/hello.pexbin0 -> 232 bytes
-rw-r--r--nuttx/binfmt/libpcode/romfs.h139
-rw-r--r--nuttx/binfmt/libpcode/romfs.imgbin0 -> 1024 bytes
-rw-r--r--nuttx/binfmt/pcode.c147
13 files changed, 389 insertions, 17 deletions
diff --git a/apps/examples/elf/Kconfig b/apps/examples/elf/Kconfig
index c62a98486..5346e14d5 100644
--- a/apps/examples/elf/Kconfig
+++ b/apps/examples/elf/Kconfig
@@ -10,6 +10,7 @@ config EXAMPLES_ELF
Enable the ELF loader example
if EXAMPLES_ELF
+
config EXAMPLES_ELF_DEVMINOR
int "ROMFS Minor Device Number"
default 0
@@ -19,7 +20,7 @@ config EXAMPLES_ELF_DEVMINOR
containing the ELF executables to be tested. Default: 0
config EXAMPLES_ELF_DEVPATH
- string "ROMFS Devie Path"
+ string "ROMFS Device Path"
default "/dev/ram0"
---help---
The path to the ROMFS block driver device. This must match EXAMPLES_ELF_DEVMINOR.
diff --git a/apps/examples/elf/elf_main.c b/apps/examples/elf/elf_main.c
index ce43c241f..e1bdb4aa5 100644
--- a/apps/examples/elf/elf_main.c
+++ b/apps/examples/elf/elf_main.c
@@ -86,10 +86,6 @@
# error "You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT in your configuration file"
#endif
-#ifdef CONFIG_BINFMT_DISABLE
-# error "You must not disable loadable modules via CONFIG_BINFMT_DISABLE in your configuration file"
-#endif
-
/* Describe the ROMFS file system */
#define SECTORSIZE 512
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 33e198172..5ce7417cb 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -7312,5 +7312,5 @@
From Jussi Kivilinna (2014-5-8).
* arch/arm/include/stm32 and src/stm32: Add support for the STM32152 and
STM32162 Medium+ density parts (plus miscellaneous other improvements to
- the original STM32151 logi). From Jussi Kivilinna and Sami Pelkonen
+ the original STM32151 logic). From Jussi Kivilinna and Sami Pelkonen
(2014-5-8).
diff --git a/nuttx/Documentation/README.html b/nuttx/Documentation/README.html
index 1fe8757bf..d7775a255 100644
--- a/nuttx/Documentation/README.html
+++ b/nuttx/Documentation/README.html
@@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec"><i>NuttX README Files</i></font></big></h1>
- <p>Last Updated: April 20, 2014</p>
+ <p>Last Updated: May 8, 2014</p>
</td>
</tr>
</table>
@@ -45,6 +45,9 @@
| | | |- <a href="http://sourceforge.net/p/nuttx/git/ci/master/tree/nuttx/arch/z80/src/z180/README.txt">README.txt</a>
| | | `- <a href="http://sourceforge.net/p/nuttx/git/ci/master/tree/nuttx/arch/z80/src/z180/z180_mmu.txt">z180_mmu.txt</a>
| | `- <a href="http://sourceforge.net/p/nuttx/git/ci/master/tree/nuttx/arch/README.txt"><b><i>README.txt</i></b></a>
+ | |- binfmt/
+ | | |- libpcode/
+ | | `- <a href="http://sourceforge.net/p/nuttx/git/ci/master/tree/nuttx/binfmt/libpcode/README.txt"><b><i>README.txt</i></b></a>
| |- audio/
| | `- <a href="http://sourceforge.net/p/nuttx/git/ci/master/tree/nuttx/audio/README.txt"><b><i>README.txt</i></b></a>
| |- configs/
diff --git a/nuttx/README.txt b/nuttx/README.txt
index 60e234e16..78da10b9a 100644
--- a/nuttx/README.txt
+++ b/nuttx/README.txt
@@ -914,6 +914,9 @@ nuttx
| `- README.txt
|- audio/
| `-README.txt
+ |- binfmt/
+ | `-libpcode/
+ | `-README.txt
|- configs/
| |- 16z/
| | `- README.txt
diff --git a/nuttx/binfmt/libpcode/Kconfig b/nuttx/binfmt/libpcode/Kconfig
index 4845eab31..03255ffab 100644
--- a/nuttx/binfmt/libpcode/Kconfig
+++ b/nuttx/binfmt/libpcode/Kconfig
@@ -15,6 +15,38 @@ config PCODE_PRIORITY
---help---
This is the task_priority that will be used when starting P-code interpreter.
+config PCODE_TEST_FS
+ bool "Mount a test file system"
+ depends on FS_ROMFS && !DISABLE_MOUNTPOINT
+ ---help---
+ Mount a test file system. This test file system was used to verify the P-Code binary format.
+
+if PCODE_TEST_FS
+
+config PCODE_TEST_DEVMINOR
+ int "Test file system minor device number"
+ default 0
+ ---help---
+ 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 P-code files to be tested. Default: 0
+
+config PCODE_TEST_DEVPATH
+ string "Test file system device Path"
+ default "/dev/ram0"
+ ---help---
+ The path to the ROMFS block driver device. This must match PCODE_TEST_DEVMINOR.
+ Used for registering the RAM block driver that will hold the ROMFS file system
+ containing the P-code files to be tested. Default: "/dev/ram0"
+
+config PCODE_TEST_MOUNTPOINT
+ string "Test file system mount point"
+ default "/bin"
+ ---help---
+ Location where the test file system will be mounted
+
+endif # PCODE_TEST_FS
+
config PCODE_DUMPBUFFER
bool "Dump P-code buffers"
default n
diff --git a/nuttx/binfmt/libpcode/Make.defs b/nuttx/binfmt/libpcode/Make.defs
index a5d2fdc12..e84d0d325 100644
--- a/nuttx/binfmt/libpcode/Make.defs
+++ b/nuttx/binfmt/libpcode/Make.defs
@@ -37,16 +37,21 @@ ifeq ($(CONFIG_PCODE),y)
# P-code application interfaces
-# BINFMT_CSRCS +=
+BINFMT_CSRCS += pcode.c
# P-code library interfaces
# BINFMT_CSRCS +=
-# Hook the libbuiltin subdirectory into the build
+# Add an include path so that P-Code related header files may reside in
+# the libpcode sub-directory
+
+CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" "$(TOPDIR)$(DELIM)binfmt$(DELIM)libpcode"}
+
+# Hook the libpcode subdirectory into the build
-#VPATH += libbuiltin
-#SUBDIRS += libbuiltin
-#DEPPATH += --dep-path libbuiltin
+#VPATH += libpcode
+#SUBDIRS += libpcode
+#DEPPATH += --dep-path libpcode
endif
diff --git a/nuttx/binfmt/libpcode/README.txt b/nuttx/binfmt/libpcode/README.txt
new file mode 100644
index 000000000..b7f896da0
--- /dev/null
+++ b/nuttx/binfmt/libpcode/README.txt
@@ -0,0 +1,51 @@
+libpcode README
+===============
+
+Configuration Dependencies
+--------------------------
+In order to use this module, you must first install the P-Code virtual
+machine. You can get this from the Pascal package or from misc/pascal in
+the GIT repository. See the README.txt file at misc/pascal for installation
+instructions. The correct location to install the P-code virtual machine is
+at apps/interpreters.
+
+Other required configuration settings:
+
+ CONFIG_NFILE_DESCRIPTORS > 3
+ CONFIG_BINFMT_DISABLE=n
+ CONFIG_PCODE=y
+
+Directory Contents
+------------------
+This directory holds support files for the P-Code binary format. For other
+binary formats, the library directory contains critical logic for the binary
+format. But this is not the case with the P-code binary format; since the
+binary file is interpreted, little additional support is necessary. As a
+result, this directory includes only a few files needed by the binfmt build
+logic and to support unit-level testing of the P-Code binary format.
+
+Files include in this directory include:
+
+1. This README.txt file
+
+2. Build support file:
+
+ Kconfig, Make.defs
+
+3. Unit test support files:
+
+ hello.pas -- Pascal "Hello, World!" source file
+ hello.pex -- P-Code POFF format file created by compiling hello.pas
+ romfs.img -- A ROMFS filsystem image created by:
+
+ make image
+ cp hello.pex image/.
+ genromfs -f romfs.img -d image -V pofftest
+ rm -rf image
+
+ romfs.h -- a C header file containing the ROMFS file system in an
+ initialized C structure. This file was created via:
+
+ xxd -g 1 -i romfs.img >romfs.h
+
+ then cleaned up with an editor to conform with NuttX coding standards.
diff --git a/nuttx/binfmt/libpcode/hello.pas b/nuttx/binfmt/libpcode/hello.pas
new file mode 100644
index 000000000..fe137f1b6
--- /dev/null
+++ b/nuttx/binfmt/libpcode/hello.pas
@@ -0,0 +1,5 @@
+program hello(output);
+begin
+ writeln('Hello world!!!');
+end.
+
diff --git a/nuttx/binfmt/libpcode/hello.pex b/nuttx/binfmt/libpcode/hello.pex
new file mode 100644
index 000000000..c23610598
--- /dev/null
+++ b/nuttx/binfmt/libpcode/hello.pex
Binary files differ
diff --git a/nuttx/binfmt/libpcode/romfs.h b/nuttx/binfmt/libpcode/romfs.h
new file mode 100644
index 000000000..833acceeb
--- /dev/null
+++ b/nuttx/binfmt/libpcode/romfs.h
@@ -0,0 +1,139 @@
+/****************************************************************************
+ * binfmt/libpcode/romfs.h
+ *
+ * Copyright (C) 2014 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_LIBPCODE_ROMF_H
+#define __BINFMT_LIBPCODE_ROMF_H 1
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ROMFS_IMG_LEN 1024
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static unsigned char romfs_img[] =
+{
+ 0x2d, 0x72, 0x6f, 0x6d, 0x31, 0x66, 0x73, 0x2d, 0x00, 0x00, 0x01, 0x70,
+ 0xd0, 0x89, 0x79, 0xd8, 0x70, 0x6f, 0x66, 0x66, 0x74, 0x65, 0x73, 0x74,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49,
+ 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0xd1, 0xff, 0xff, 0x97,
+ 0x2e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00, 0x20,
+ 0x00, 0x00, 0x00, 0x00, 0xd1, 0xd1, 0xff, 0x80, 0x2e, 0x2e, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe8,
+ 0xb0, 0x6c, 0x22, 0x45, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x65,
+ 0x78, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x4f, 0x46, 0x46,
+ 0x01, 0x01, 0x00, 0x00, 0x00, 0x14, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x01, 0x06, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7c,
+ 0x00, 0x00, 0x00, 0x11, 0x01, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8d, 0x00, 0x00, 0x00, 0x0f,
+ 0x05, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00, 0x04, 0x06, 0x00, 0x00, 0x08,
+ 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa0,
+ 0x00, 0x00, 0x00, 0x10, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb0, 0x00, 0x00, 0x00, 0x38,
+ 0xb1, 0x00, 0x00, 0x74, 0x0e, 0xf9, 0x00, 0x00, 0x25, 0xb5, 0xff, 0xfc,
+ 0xf9, 0x00, 0x00, 0x20, 0x3f, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77,
+ 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x21, 0x21, 0x00, 0x07, 0x00, 0x00, 0x00,
+ 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
+ 0x10, 0x00, 0x00, 0x00, 0x00, 0x48, 0x45, 0x4c, 0x4c, 0x4f, 0x00, 0x68,
+ 0x65, 0x6c, 0x6c, 0x6f, 0x2e, 0x70, 0x61, 0x73, 0x00, 0x2e, 0x74, 0x65,
+ 0x78, 0x74, 0x00, 0x2e, 0x72, 0x6f, 0x64, 0x61, 0x74, 0x61, 0x00, 0x2e,
+ 0x66, 0x69, 0x6c, 0x65, 0x74, 0x61, 0x62, 0x00, 0x2e, 0x6c, 0x69, 0x6e,
+ 0x65, 0x6e, 0x6f, 0x00, 0x2e, 0x73, 0x74, 0x72, 0x74, 0x61, 0x62, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00
+};
+
+#endif /* __BINFMT_LIBPCODE_ROMF_H */
diff --git a/nuttx/binfmt/libpcode/romfs.img b/nuttx/binfmt/libpcode/romfs.img
new file mode 100644
index 000000000..04237dd04
--- /dev/null
+++ b/nuttx/binfmt/libpcode/romfs.img
Binary files differ
diff --git a/nuttx/binfmt/pcode.c b/nuttx/binfmt/pcode.c
index c5963b672..44ff16201 100644
--- a/nuttx/binfmt/pcode.c
+++ b/nuttx/binfmt/pcode.c
@@ -39,12 +39,16 @@
#include <nuttx/config.h>
-#include <fcntl.h>
+#include <sys/mount.h>
#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/poff.h>
+#include <nuttx/fs/ramdisk.h>
#include <nuttx/binfmt/binfmt.h>
#include <nuttx/binfmt/pcode.h>
@@ -53,6 +57,48 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+/* Check configuration. This is not all of the configuration settings that
+ * are required -- only the more obvious.
+ */
+
+#if CONFIG_NFILE_DESCRIPTORS < 1
+# error "You must provide file descriptors via CONFIG_NFILE_DESCRIPTORS in your configuration file"
+#endif
+
+#ifdef CONFIG_BINFMT_DISABLE
+# error "The binary loader is disabled (CONFIG_BINFMT_DISABLE)!"
+#endif
+
+#ifndef CONFIG_PCODE
+# error "You must select CONFIG_PCODE in your configuration file"
+#endif
+
+#ifdef CONFIG_PCODE_TEST_FS
+# ifndef CONFIG_FS_ROMFS
+# error "You must select CONFIG_FS_ROMFS in your configuration file"
+# endif
+
+# ifdef CONFIG_DISABLE_MOUNTPOINT
+# error "You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT in your configuration file"
+# endif
+
+# ifndef CONFIG_PCODE_TEST_DEVMINOR
+# define CONFIG_PCODE_TEST_DEVMINOR 0
+# endif
+
+# ifndef CONFIG_PCODE_TEST_DEVPATH
+# define CONFIG_PCODE_TEST_DEVPATH "/dev/ram0"
+# endif
+
+# ifndef CONFIG_PCODE_TEST_MOUNTPOINT
+# define CONFIG_PCODE_TEST_MOUNTPOINT "/bin"
+# endif
+#endif
+
+/* Describe the ROMFS file system */
+
+#define SECTORSIZE 512
+#define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
/****************************************************************************
* Private Function Prototypes
@@ -70,11 +116,71 @@ static struct binfmt_s g_pcode_binfmt =
pcode_loadbinary, /* load */
};
+#ifdef CONFIG_PCODE_TEST_FS
+# include "romfs.h"
+#endif
+
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
+ * Name: pcode_mount_testfs
+ *
+ * Description:
+ * If so configured, then mount the P-Code test file system
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_PCODE_TEST_FS
+static int pcode_mount_testfs(void)
+{
+ int ret;
+
+ /* Create a ROM disk for the ROMFS filesystem */
+
+ bvdbg("Registering romdisk at /dev/ram%d\n", CONFIG_PCODE_TEST_DEVMINOR);
+ ret = romdisk_register(CONFIG_PCODE_TEST_DEVMINOR, (FAR uint8_t *)romfs_img,
+ NSECTORS(ROMFS_IMG_LEN), SECTORSIZE);
+ if (ret < 0)
+ {
+ bdbg("ERROR: romdisk_register failed: %d\n", ret);
+ return ret;
+ }
+
+ /* Mount the test file system */
+
+ bvdbg("Mounting ROMFS filesystem at target=%s with source=%s\n",
+ CONFIG_PCODE_TEST_MOUNTPOINT, CONFIG_PCODE_TEST_DEVPATH);
+
+ ret = mount(CONFIG_PCODE_TEST_DEVPATH, CONFIG_PCODE_TEST_MOUNTPOINT,
+ "romfs", MS_RDONLY, NULL);
+ if (ret < 0)
+ {
+ int errval = errno;
+ DEBUGASSERT(errval > 0);
+
+ bdbg("ERROR: mount(%s,%s,romfs) failed: %d\n",
+ CONFIG_PCODE_TEST_DEVPATH, CONFIG_PCODE_TEST_MOUNTPOINT, errval);
+ return -errval;
+ }
+
+ /* Does the system support the PATH variable? Has the PATH variable
+ * already been set? If YES and NO, then set the PATH variable to
+ * the ROMFS mountpoint.
+ */
+
+#if defined(CONFIG_BINFMT_EXEPATH) && !defined(CONFIG_PATH_INITIAL)
+ (void)setenv("PATH", CONFIG_PCODE_TEST_MOUNTPOINT, 1);
+#endif
+
+ return OK;
+}
+#else
+# define pcode_mount_testfs() (OK)
+#endif
+
+/****************************************************************************
* Name: pcode_proxy
*
* Description:
@@ -105,7 +211,6 @@ static int pcode_proxy(int argc, char **argv)
static int pcode_loadbinary(struct binary_s *binp)
{
FAR struct poff_fileheader_s hdr;
- FAR const struct pcode_s *b;
FAR uint8_t *ptr;
size_t remaining;
ssize_t nread;
@@ -154,7 +259,7 @@ static int pcode_loadbinary(struct binary_s *binp)
{
/* Set up for the next gulp */
- DEBUASSERT(nread > 0 && nread <=remaining);
+ DEBUGASSERT(nread > 0 && nread <=remaining);
remaining -= nread;
ptr += nread;
}
@@ -213,6 +318,15 @@ int pcode_initialize(void)
{
int ret;
+ /* Mount the test file system */
+
+ ret = pcode_mount_testfs();
+ if (ret < 0)
+ {
+ bdbg("ERROR: Failed to mount test file system: %d\n", ret);
+ return ret;
+ }
+
/* Register ourselves as a binfmt loader */
bvdbg("Registering P-Code Loader\n");
@@ -239,8 +353,31 @@ int pcode_initialize(void)
void pcode_uninitialize(void)
{
- unregister_binfmt(&g_pcode_binfmt);
+ int ret;
+
+ /* Unregister the binary format */
+
+ ret = unregister_binfmt(&g_pcode_binfmt);
+ if (ret < 0)
+ {
+ int errval = errno;
+ DEBUGASSERT(errval > 0);
+
+ bdbg("ERROR: unregister_binfmt() failed: %d\n", errval);
+ UNUSED(errval);
+ }
+
+#ifdef CONFIG_PCODE_TEST_FS
+ ret = umount(CONFIG_PCODE_TEST_MOUNTPOINT);
+ if (ret < 0)
+ {
+ int errval = errno;
+ DEBUGASSERT(errval > 0);
+
+ bdbg("ERROR: umount(%s) failed: %d\n", CONFIG_PCODE_TEST_MOUNTPOINT, errval);
+ UNUSED(errval);
+ }
+#endif
}
#endif /* CONFIG_PCODE */
-