Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/fdpicxip/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/fdpicxip_blobs.c
36 changes: 35 additions & 1 deletion examples/fdpicxip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,40 @@
#
# ##############################################################################

nuttx_add_subdirectory()

if(CONFIG_EXAMPLES_FDPICXIP)
nuttx_add_application(NAME fdpicxip SRCS fdpicxip_main.c)

# The modules are built in modules/, and embedded here after they are linked

set(BLOBSRC ${CMAKE_CURRENT_BINARY_DIR}/fdpicxip_blobs.c)
set(BLOBFILES)
set(BLOBTARGETS)

foreach(blob qsorter libcounter.so user libshape.so cxxuser lazymod)
list(APPEND BLOBFILES ${NUTTX_BINARY_DIR}/bin/${blob})

if(CMAKE_C_ELF_COMPILER)
list(APPEND BLOBTARGETS ${blob})
else()
list(APPEND BLOBTARGETS ELF_${blob})
endif()
endforeach()

add_custom_command(
OUTPUT ${BLOBSRC}
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/modules/mkblobs.sh g_fdpicxip
${BLOBFILES} > ${BLOBSRC}
DEPENDS ${BLOBTARGETS})

add_custom_target(fdpicxip_blobs DEPENDS ${BLOBSRC})

nuttx_add_application(
NAME
fdpicxip
SRCS
fdpicxip_main.c
${BLOBSRC}
DEPENDS
fdpicxip_blobs)
endif()
7 changes: 3 additions & 4 deletions examples/fdpicxip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ config EXAMPLES_FDPICXIP

With no subcommand, qsort runs.

The modules are embedded in the image as C headers. Their
sources are in modules/, which rebuilds the headers on an
explicit 'make regen': linking one needs arm-uclinuxfdpiceabi
binutils, which this build does not.
The modules are built from modules/ with the module flags of the
tree, and embedded in the image. Linking them needs the
arm-uclinuxfdpiceabi linker that CONFIG_FDPIC needs.

This demonstrates; it does not assert. For the assertions see
the fdpic and reject sections of CONFIG_TESTING_FS_XIPFS.
Expand Down
2 changes: 2 additions & 0 deletions examples/fdpicxip/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@
ifneq ($(CONFIG_EXAMPLES_FDPICXIP),)
CONFIGURED_APPS += $(APPDIR)/examples/fdpicxip
endif

include $(APPDIR)/examples/fdpicxip/modules/Make.defs
27 changes: 23 additions & 4 deletions examples/fdpicxip/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@

include $(APPDIR)/Make.defs

# FDPIC modules executed in place from xipfs. The modules are embedded as
# headers, built from the sources in modules/ by an explicit 'make regen'
# there: linking one needs arm-uclinuxfdpiceabi binutils, which this build
# does not.
# FDPIC modules executed in place from xipfs. The modules are built in
# modules/, and embedded here after they are linked.

MAINSRC = fdpicxip_main.c

Expand All @@ -34,4 +32,25 @@ PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = $(CONFIG_DEFAULT_TASK_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_FDPICXIP)

BLOBS = qsorter libcounter.so user libshape.so cxxuser lazymod
BLOBSRC = fdpicxip_blobs.c
BLOBOBJ = $(BLOBSRC:.c=$(OBJEXT))

$(BLOBSRC): $(addprefix $(BINDIR)$(DELIM),$(BLOBS))
$(Q) modules$(DELIM)mkblobs.sh g_fdpicxip $^ > $@.tmp
$(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)

$(BLOBOBJ): %$(OBJEXT): %.c
$(call COMPILE, $<, $@)

postinstall:: $(BLOBOBJ)
$(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^)

clean::
$(Q) $(MAKE) -C modules clean APPDIR="$(APPDIR)" TOPDIR="$(TOPDIR)"

distclean::
$(Q) $(MAKE) -C modules distclean APPDIR="$(APPDIR)" TOPDIR="$(TOPDIR)"
$(call DELFILE, $(BLOBSRC) $(BLOBOBJ))

include $(APPDIR)/Application.mk
400 changes: 0 additions & 400 deletions examples/fdpicxip/cxxuser_bin.h

This file was deleted.

51 changes: 34 additions & 17 deletions examples/fdpicxip/fdpicxip_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,31 @@
#include <nuttx/fs/ioctl.h>
#include <nuttx/fs/xipfs.h>

#include "qsorter_bin.h"
#include "libcounter_bin.h"
#include "user_bin.h"
#include "libshape_bin.h"
#include "cxxuser_bin.h"
#include "lazymod_bin.h"

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/

#define MOUNTPT CONFIG_EXAMPLES_FDPICXIP_MOUNTPT

/****************************************************************************
* Public Data
****************************************************************************/

/* The modules in modules/, which mkblobs.sh embeds after they are linked */

extern const unsigned char g_fdpicxip_qsorter[];
extern const unsigned int g_fdpicxip_qsorter_len;
extern const unsigned char g_fdpicxip_libcounter_so[];
extern const unsigned int g_fdpicxip_libcounter_so_len;
extern const unsigned char g_fdpicxip_user[];
extern const unsigned int g_fdpicxip_user_len;
extern const unsigned char g_fdpicxip_libshape_so[];
extern const unsigned int g_fdpicxip_libshape_so_len;
extern const unsigned char g_fdpicxip_cxxuser[];
extern const unsigned int g_fdpicxip_cxxuser_len;
extern const unsigned char g_fdpicxip_lazymod[];
extern const unsigned int g_fdpicxip_lazymod_len;

/****************************************************************************
* Private Functions
****************************************************************************/
Expand Down Expand Up @@ -174,14 +186,15 @@ static int qsorter_main(void)
syslog(LOG_INFO,
"\n=== FDPIC module executed in place from xipfs ===\n\n");

ret = stage_blob(MOUNTPT "/qsorter", g_qsorter_nxf, g_qsorter_nxf_len);
ret = stage_blob(MOUNTPT "/qsorter", g_fdpicxip_qsorter,
g_fdpicxip_qsorter_len);
if (ret < 0)
{
syslog(LOG_INFO, "staging the module failed: %d\n", ret);
return EXIT_FAILURE;
}

syslog(LOG_INFO, "staged qsorter (%u bytes)\n", g_qsorter_nxf_len);
syslog(LOG_INFO, "staged qsorter (%u bytes)\n", g_fdpicxip_qsorter_len);

if (extent_info_path(MOUNTPT "/qsorter", &info) == 0)
{
Expand Down Expand Up @@ -254,22 +267,23 @@ static int solib_main(void)

syslog(LOG_INFO, "\n=== FDPIC shared library, executed in place ===\n\n");

ret = stage_blob(MOUNTPT "/libcounter.so", g_libcounter, g_libcounter_len);
ret = stage_blob(MOUNTPT "/libcounter.so", g_fdpicxip_libcounter_so,
g_fdpicxip_libcounter_so_len);
if (ret < 0)
{
syslog(LOG_INFO, "staging the library failed: %d\n", ret);
return EXIT_FAILURE;
}

ret = stage_blob(MOUNTPT "/user", g_user, g_user_len);
ret = stage_blob(MOUNTPT "/user", g_fdpicxip_user, g_fdpicxip_user_len);
if (ret < 0)
{
syslog(LOG_INFO, "staging the module failed: %d\n", ret);
return EXIT_FAILURE;
}

syslog(LOG_INFO, "staged libcounter.so (%u bytes) and user (%u bytes)\n",
g_libcounter_len, g_user_len);
g_fdpicxip_libcounter_so_len, g_fdpicxip_user_len);

if (extent_info_path(MOUNTPT "/libcounter.so", &li) == 0 &&
extent_info_path(MOUNTPT "/user", &ui) == 0)
Expand Down Expand Up @@ -359,22 +373,24 @@ static int cxx_main(void)
syslog(LOG_INFO, "\n=== C++ module and shared library, executed in"
" place ===\n\n");

ret = stage_blob(MOUNTPT "/libshape.so", g_libshape, g_libshape_len);
ret = stage_blob(MOUNTPT "/libshape.so", g_fdpicxip_libshape_so,
g_fdpicxip_libshape_so_len);
if (ret < 0)
{
syslog(LOG_INFO, "staging the library failed: %d\n", ret);
return EXIT_FAILURE;
}

ret = stage_blob(MOUNTPT "/cxxuser", g_cxxuser, g_cxxuser_len);
ret = stage_blob(MOUNTPT "/cxxuser", g_fdpicxip_cxxuser,
g_fdpicxip_cxxuser_len);
if (ret < 0)
{
syslog(LOG_INFO, "staging the module failed: %d\n", ret);
return EXIT_FAILURE;
}

syslog(LOG_INFO, "staged libshape.so (%u bytes) and cxxuser (%u bytes)\n",
g_libshape_len, g_cxxuser_len);
g_fdpicxip_libshape_so_len, g_fdpicxip_cxxuser_len);

if (extent_info_path(MOUNTPT "/libshape.so", &li) == 0 &&
extent_info_path(MOUNTPT "/cxxuser", &ui) == 0)
Expand Down Expand Up @@ -474,15 +490,16 @@ static int jmprel_main(void)

syslog(LOG_INFO, "\n=== FDPIC module bound through DT_JMPREL ===\n\n");

ret = stage_blob(MOUNTPT "/lazymod", g_lazymod, g_lazymod_len);
ret = stage_blob(MOUNTPT "/lazymod", g_fdpicxip_lazymod,
g_fdpicxip_lazymod_len);
if (ret < 0)
{
syslog(LOG_INFO, "staging the module failed: %d\n", ret);
return EXIT_FAILURE;
}

syslog(LOG_INFO, "staged lazymod (%u bytes), all imports in DT_JMPREL\n\n",
g_lazymod_len);
g_fdpicxip_lazymod_len);

args[0] = (FAR char *)"lazymod";
args[1] = (FAR char *)"42";
Expand Down
Loading
Loading