Finishes first cut of examples/nxflat
git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@1922 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
parent
9efb63994a
commit
fac6f316c9
|
@ -40,10 +40,18 @@
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <pthread.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/binfmt.h>
|
||||||
#include "tests/romfs.h"
|
#include "tests/romfs.h"
|
||||||
#include "tests/dirlist.h"
|
#include "tests/dirlist.h"
|
||||||
|
#include "tests/symtab.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Definitions
|
* Definitions
|
||||||
|
@ -57,10 +65,22 @@
|
||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
static const char delimiter[] =
|
||||||
|
"****************************************************************************";
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: testheader
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static inline void testheader(FAR const char *progname)
|
||||||
|
{
|
||||||
|
printf("\n%s\n* Executing %s\n%s\n\n", delimiter, progname, delimiter);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -79,5 +99,32 @@ void user_initialize(void)
|
||||||
|
|
||||||
int user_start(int argc, char *argv[])
|
int user_start(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
struct binary_s bin;
|
||||||
|
int ret;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; dirlist[i]; i++)
|
||||||
|
{
|
||||||
|
testheader(dirlist[i]);
|
||||||
|
|
||||||
|
memset(&bin, 0, sizeof(struct binary_s));
|
||||||
|
bin.filename = dirlist[i];
|
||||||
|
bin.exports = exports;
|
||||||
|
bin.nexports = NEXPORTS;
|
||||||
|
|
||||||
|
ret = load_module(&bin);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: Failed to load program '%s'\n", dirlist[i]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = exec_module(&bin, 50);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "ERROR: Failed to execute program '%s'\n", dirlist[i]);
|
||||||
|
unload_module(&bin);
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,13 +43,14 @@ ROMFS_DIR = $(TESTS_DIR)/romfs
|
||||||
ROMFS_IMG = $(TESTS_DIR)/romfs.img
|
ROMFS_IMG = $(TESTS_DIR)/romfs.img
|
||||||
ROMFS_HDR = $(TESTS_DIR)/romfs.h
|
ROMFS_HDR = $(TESTS_DIR)/romfs.h
|
||||||
ROMFS_DIRLIST = $(TESTS_DIR)/dirlist.h
|
ROMFS_DIRLIST = $(TESTS_DIR)/dirlist.h
|
||||||
|
SYMTAB = $(TESTS_DIR)/symtab.h
|
||||||
|
|
||||||
define DIR_template
|
define DIR_template
|
||||||
$(1)_$(2):
|
$(1)_$(2):
|
||||||
@$(MAKE) -C $(1) $(3) TOPDIR=$(TOPDIR) ROMFS_DIR=$(ROMFS_DIR) CROSSDEV=$(CROSSDEV)
|
@$(MAKE) -C $(1) $(3) TOPDIR=$(TOPDIR) ROMFS_DIR=$(ROMFS_DIR) CROSSDEV=$(CROSSDEV)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
all: $(ROMFS_HDR) $(ROMFS_DIRLIST)
|
all: $(ROMFS_HDR) $(ROMFS_DIRLIST) $(SYMTAB)
|
||||||
.PHONY: all build clean install populate
|
.PHONY: all build clean install populate
|
||||||
|
|
||||||
$(foreach DIR, $(SUBDIRS), $(eval $(call DIR_template,$(DIR),build, all)))
|
$(foreach DIR, $(SUBDIRS), $(eval $(call DIR_template,$(DIR),build, all)))
|
||||||
|
@ -83,25 +84,20 @@ $(ROMFS_IMG): populate
|
||||||
$(ROMFS_HDR) : $(ROMFS_IMG)
|
$(ROMFS_HDR) : $(ROMFS_IMG)
|
||||||
@xxd -i $^ >$@
|
@xxd -i $^ >$@
|
||||||
|
|
||||||
|
# Create the dirlist.h header file from the romfs directory
|
||||||
|
|
||||||
$(ROMFS_DIRLIST) : populate
|
$(ROMFS_DIRLIST) : populate
|
||||||
@echo "#ifndef __EXAMPLES_NXFLAT_TESTS_DIRLIST_H" >$(ROMFS_DIRLIST)
|
@$(TESTS_DIR)/mkdirlist.sh $(ROMFS_DIR) >$@
|
||||||
@echo "#define __EXAMPLES_NXFLAT_TESTS_DIRLIST_H" >>$(ROMFS_DIRLIST)
|
|
||||||
@echo "" >>$(ROMFS_DIRLIST)
|
# Create the exported symbol table list from the derived *-thunk.S files
|
||||||
@echo "static const char *dirlist[] =" >>$(ROMFS_DIRLIST)
|
|
||||||
@echo "{" >>$(ROMFS_DIRLIST)
|
$(SYMTAB): build
|
||||||
@(\
|
@$(TESTS_DIR)/mksymtab.sh $(TESTS_DIR) >$@
|
||||||
for file in `ls $(ROMFS_DIR)`; do \
|
|
||||||
echo " \"$$file\"," >>$(ROMFS_DIRLIST); \
|
|
||||||
done; \
|
|
||||||
)
|
|
||||||
@echo "};" >>$(ROMFS_DIRLIST)
|
|
||||||
@echo "" >>$(ROMFS_DIRLIST)
|
|
||||||
@echo "#endif /* __EXAMPLES_NXFLAT_TESTS_DIRLIST_H */" >>$(ROMFS_DIRLIST)
|
|
||||||
|
|
||||||
# Clean each subdirectory
|
# Clean each subdirectory
|
||||||
|
|
||||||
clean: $(foreach DIR, $(SUBDIRS), $(DIR)_clean)
|
clean: $(foreach DIR, $(SUBDIRS), $(DIR)_clean)
|
||||||
@rm -f $(ROMFS_HDR) $(ROMFS_IMG)
|
@rm -f $(ROMFS_HDR) $(ROMFS_IMG) $(SYMTAB)
|
||||||
@rm -rf $(ROMFS_DIR)
|
@rm -rf $(ROMFS_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
usage="Usage: %0 <romfs-dir-path>"
|
||||||
|
|
||||||
|
dir=$1
|
||||||
|
if [ -z "$dir" ]; then
|
||||||
|
echo "ERROR: Missing <romfs-dir-path>"
|
||||||
|
echo ""
|
||||||
|
echo $usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$dir" ]; then
|
||||||
|
echo "ERROR: Directory $dir does not exist"
|
||||||
|
echo ""
|
||||||
|
echo $usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "#ifndef __EXAMPLES_NXFLAT_TESTS_DIRLIST_H"
|
||||||
|
echo "#define __EXAMPLES_NXFLAT_TESTS_DIRLIST_H"
|
||||||
|
echo ""
|
||||||
|
echo "static const char *dirlist[] ="
|
||||||
|
echo "{"
|
||||||
|
|
||||||
|
for file in `ls $dir`; do
|
||||||
|
echo " \"$file\","
|
||||||
|
done
|
||||||
|
|
||||||
|
echo " NULL"
|
||||||
|
echo "};"
|
||||||
|
echo ""
|
||||||
|
echo "#endif /* __EXAMPLES_NXFLAT_TESTS_DIRLIST_H */"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
usage="Usage: %0 <test-dir-path>"
|
||||||
|
|
||||||
|
dir=$1
|
||||||
|
if [ -z "$dir" ]; then
|
||||||
|
echo "ERROR: Missing <test-dir-path>"
|
||||||
|
echo ""
|
||||||
|
echo $usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$dir" ]; then
|
||||||
|
echo "ERROR: Directory $dir does not exist"
|
||||||
|
echo ""
|
||||||
|
echo $usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
varlist=`find $dir -name "*-thunk.S"| xargs grep -h asciz | cut -f3 | sort | uniq`
|
||||||
|
|
||||||
|
echo "#ifndef __EXAMPLES_NXFLAT_TESTS_SYMTAB_H"
|
||||||
|
echo "#define __EXAMPLES_NXFLAT_TESTS_SYMTAB_H"
|
||||||
|
echo ""
|
||||||
|
echo "#include <nuttx/symtab.h>"
|
||||||
|
echo ""
|
||||||
|
echo "static const struct symtab_s exports[] = "
|
||||||
|
echo "{"
|
||||||
|
for string in $varlist; do
|
||||||
|
var=`echo $string | sed -e "s/\"//g"`
|
||||||
|
echo " {$string, $var},"
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "};"
|
||||||
|
echo "#define NEXPORTS (sizeof(exports)/sizeof(struct symtab_s))"
|
||||||
|
echo ""
|
||||||
|
echo "#endif /* __EXAMPLES_NXFLAT_TESTS_SYMTAB_H */"
|
||||||
|
|
Loading…
Reference in New Issue