apps/examples/elf: Extend the ELF program module demo so that you can use compressed ELF programs with CROMFS.
This commit is contained in:
parent
28ce015fbb
commit
dbdfad8ff5
@ -7,12 +7,47 @@ config EXAMPLES_ELF
|
||||
bool "ELF Loader Example"
|
||||
default n
|
||||
select LIBC_EXECFUNCS
|
||||
depends on ELF && !BUILD_KERNEL
|
||||
depends on ELF && (FS_ROMFS || FS_CROMFS) && !BUILD_KERNEL
|
||||
---help---
|
||||
Enable the ELF loader example
|
||||
|
||||
if EXAMPLES_ELF
|
||||
|
||||
choice
|
||||
prompt "ROM File System"
|
||||
default EXAMPLES_ELF_ROMFS if FS_ROMFS
|
||||
default EXAMPLES_ELF_CROMFS if !FS_ROMFS && FS_CROMFS
|
||||
|
||||
config EXAMPLES_ELF_ROMFS
|
||||
bool "ROMFS"
|
||||
depends on FS_ROMFS
|
||||
|
||||
config EXAMPLES_ELF_CROMFS
|
||||
bool "CROMFS"
|
||||
depends on FS_CROMFS
|
||||
|
||||
endchoice # ROM File System
|
||||
|
||||
if EXAMPLES_ELF_ROMFS
|
||||
|
||||
config EXAMPLES_ELF_DEVMINOR
|
||||
int "ROMFS 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 ELF executables to be tested. Default: 0
|
||||
|
||||
config EXAMPLES_ELF_DEVPATH
|
||||
string "ROMFS Device Path"
|
||||
default "/dev/ram0"
|
||||
---help---
|
||||
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"
|
||||
|
||||
endif # EXAMPLES_ELF_ROMFS
|
||||
|
||||
config EXAMPLES_ELF_SYSCALL
|
||||
bool "Link with SYSCALL library"
|
||||
default n
|
||||
@ -39,22 +74,6 @@ config EXAMPLES_ELF_LIBC
|
||||
program greatly increasing the total code size. This option is
|
||||
primarily intended only for testing.
|
||||
|
||||
config EXAMPLES_ELF_DEVMINOR
|
||||
int "ROMFS 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 ELF executables to be tested. Default: 0
|
||||
|
||||
config EXAMPLES_ELF_DEVPATH
|
||||
string "ROMFS Device Path"
|
||||
default "/dev/ram0"
|
||||
---help---
|
||||
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"
|
||||
|
||||
config EXAMPLES_ELF_CXXINITIALIZE
|
||||
bool "C++ Initialization"
|
||||
default y
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* examples/elf/elf_main.c
|
||||
*
|
||||
* Copyright (C) 2012, 2017 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2012, 2017-2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -56,7 +56,14 @@
|
||||
|
||||
#include "platform/cxxinitialize.h"
|
||||
|
||||
#include "tests/romfs.h"
|
||||
#if defined(CONFIG_EXAMPLES_ELF_ROMFS)
|
||||
# include "tests/romfs.h"
|
||||
#elif defined(CONFIG_EXAMPLES_ELF_CROMFS)
|
||||
# include "tests/cromfs.h"
|
||||
#else
|
||||
# error "No file system selected"
|
||||
#endif
|
||||
|
||||
#include "tests/dirlist.h"
|
||||
|
||||
/****************************************************************************
|
||||
@ -79,26 +86,36 @@
|
||||
# error "You must select CONFIG_ELF in your configuration file"
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_FS_ROMFS
|
||||
# error "You must select CONFIG_FS_ROMFS in your configuration file"
|
||||
#if !defined(CONFIG_FS_ROMFS) && !defined(CONFIG_FS_CROMFS)
|
||||
# error "You must select CONFIG_FS_ROMFS or CONFIG_FS_CROMFS in your configuration file"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_DISABLE_MOUNTPOINT
|
||||
# error "You must not disable mountpoints via CONFIG_DISABLE_MOUNTPOINT in your configuration file"
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_ELF_ROMFS)
|
||||
|
||||
/* Describe the ROMFS file system */
|
||||
|
||||
#define SECTORSIZE 512
|
||||
#define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE)
|
||||
#define MOUNTPT "/mnt/romfs"
|
||||
# define SECTORSIZE 512
|
||||
# define NSECTORS(b) (((b) + SECTORSIZE - 1) / SECTORSIZE)
|
||||
# define MOUNTPT "/mnt/romfs"
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_ELF_DEVMINOR
|
||||
# define CONFIG_EXAMPLES_ELF_DEVMINOR 0
|
||||
#endif
|
||||
# ifndef CONFIG_EXAMPLES_ELF_DEVMINOR
|
||||
# define CONFIG_EXAMPLES_ELF_DEVMINOR 0
|
||||
# endif
|
||||
|
||||
#ifndef CONFIG_EXAMPLES_ELF_DEVPATH
|
||||
# define CONFIG_EXAMPLES_ELF_DEVPATH "/dev/ram0"
|
||||
# ifndef CONFIG_EXAMPLES_ELF_DEVPATH
|
||||
# define CONFIG_EXAMPLES_ELF_DEVPATH "/dev/ram0"
|
||||
# endif
|
||||
|
||||
/* Describe the CROMFS file system */
|
||||
|
||||
#elif defined(CONFIG_EXAMPLES_ELF_CROMFS)
|
||||
# define MOUNTPT "/mnt/cromfs"
|
||||
#else
|
||||
# error "No file system selected"
|
||||
#endif
|
||||
|
||||
/* If CONFIG_DEBUG_FEATURES is enabled, use info/err instead of printf so that the
|
||||
@ -107,25 +124,25 @@
|
||||
|
||||
#ifdef CONFIG_CPP_HAVE_VARARGS
|
||||
# ifdef CONFIG_DEBUG_INFO
|
||||
# define message(format, ...) syslog(LOG_INFO, format, ##__VA_ARGS__)
|
||||
# define message(format, ...) syslog(LOG_INFO, format, ##__VA_ARGS__)
|
||||
# else
|
||||
# define message(format, ...) printf(format, ##__VA_ARGS__)
|
||||
# define message(format, ...) printf(format, ##__VA_ARGS__)
|
||||
# endif
|
||||
# ifdef CONFIG_DEBUG_ERROR
|
||||
# define errmsg(format, ...) syslog(LOG_ERR, format, ##__VA_ARGS__)
|
||||
# define errmsg(format, ...) syslog(LOG_ERR, format, ##__VA_ARGS__)
|
||||
# else
|
||||
# define errmsg(format, ...) fprintf(stderr, format, ##__VA_ARGS__)
|
||||
# define errmsg(format, ...) fprintf(stderr, format, ##__VA_ARGS__)
|
||||
# endif
|
||||
#else
|
||||
# ifdef CONFIG_DEBUG_INFO
|
||||
# define message _info
|
||||
# define message _info
|
||||
# else
|
||||
# define message printf
|
||||
# define message printf
|
||||
# endif
|
||||
# ifdef CONFIG_DEBUG_ERROR
|
||||
# define errmsg _err
|
||||
# define errmsg _err
|
||||
# else
|
||||
# define errmsg printf
|
||||
# define errmsg printf
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@ -238,6 +255,7 @@ int elf_main(int argc, char *argv[])
|
||||
|
||||
mm_initmonitor();
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_ELF_ROMFS)
|
||||
/* Create a ROM disk for the ROMFS filesystem */
|
||||
|
||||
message("Registering romdisk at /dev/ram%d\n",
|
||||
@ -253,7 +271,7 @@ int elf_main(int argc, char *argv[])
|
||||
|
||||
mm_update(&g_mmstep, "after romdisk_register");
|
||||
|
||||
/* Mount the file system */
|
||||
/* Mount the ROMFS file system */
|
||||
|
||||
message("Mounting ROMFS filesystem at target=%s with source=%s\n",
|
||||
MOUNTPT, CONFIG_EXAMPLES_ELF_DEVPATH);
|
||||
@ -265,6 +283,20 @@ int elf_main(int argc, char *argv[])
|
||||
CONFIG_EXAMPLES_ELF_DEVPATH, MOUNTPT, errno);
|
||||
}
|
||||
|
||||
#elif defined(CONFIG_EXAMPLES_ELF_CROMFS)
|
||||
/* Mount the CROMFS file system */
|
||||
|
||||
message("Mounting CROMFS filesystem at target=%s\n", MOUNTPT);
|
||||
|
||||
ret = mount(NULL, MOUNTPT, "cromfs", MS_RDONLY, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
errmsg("ERROR: mount(%s,cromfs) failed: %s\n", MOUNTPT, errno);
|
||||
}
|
||||
#else
|
||||
# error "No file system selected"
|
||||
#endif
|
||||
|
||||
mm_update(&g_mmstep, "after mount");
|
||||
|
||||
#if defined(CONFIG_BINFMT_EXEPATH) && !defined(CONFIG_PATH_INITIAL)
|
||||
@ -311,6 +343,7 @@ int elf_main(int argc, char *argv[])
|
||||
*/
|
||||
|
||||
args[0] = NULL;
|
||||
printf("Calling exec(%s, %p, %p, %u\n", filename, args, exports, (unsigned int)nexports); // REMOVE ME
|
||||
ret = exec(filename, args, exports, nexports);
|
||||
|
||||
mm_update(&g_mmstep, "after exec");
|
||||
|
2
examples/elf/tests/.gitignore
vendored
2
examples/elf/tests/.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
/romfs
|
||||
/romfs.h
|
||||
/romfs.img
|
||||
/cromfs
|
||||
/cromfs.h
|
||||
/dirlist.h
|
||||
/symtab.c
|
||||
/varlist.tmp
|
||||
|
@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# apps/examples/elf/tests/Makefile
|
||||
#
|
||||
# Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2012, 2014, 2018 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@ -62,18 +62,28 @@ endif
|
||||
|
||||
ELF_DIR = $(APPDIR)/examples/elf
|
||||
TESTS_DIR = $(ELF_DIR)/tests
|
||||
ROMFS_DIR = $(TESTS_DIR)/romfs
|
||||
ROMFS_IMG = $(TESTS_DIR)/romfs.img
|
||||
ROMFS_HDR = $(TESTS_DIR)/romfs.h
|
||||
DIRLIST_HDR = $(TESTS_DIR)/dirlist.h
|
||||
SYMTAB_SRC = $(TESTS_DIR)/symtab.c
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y)
|
||||
FSIMG_DIR = $(TESTS_DIR)/romfs
|
||||
ROMFS_IMG = $(TESTS_DIR)/romfs.img
|
||||
FSIMG_HDR = $(TESTS_DIR)/romfs.h
|
||||
else
|
||||
NXTOOLDIR = $(TOPDIR)/tools
|
||||
GENCROMFSSRC = gencromfs.c
|
||||
GENCROMFSEXE = gencromfs$(EXEEXT)
|
||||
|
||||
FSIMG_DIR = $(TESTS_DIR)/cromfs
|
||||
FSIMG_HDR = $(TESTS_DIR)/cromfs.h
|
||||
endif
|
||||
|
||||
define DIR_template
|
||||
$(1)_$(2):
|
||||
$(Q) $(MAKE) -C $(1) $(3) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" ROMFS_DIR="$(ROMFS_DIR)" CROSSDEV=$(CROSSDEV)
|
||||
$(Q) $(MAKE) -C $(1) $(3) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" FSIMG_DIR="$(FSIMG_DIR)" CROSSDEV=$(CROSSDEV)
|
||||
endef
|
||||
|
||||
all: $(ROMFS_HDR) $(DIRLIST_HDR) $(SYMTAB_SRC)
|
||||
all: $(FSIMG_HDR) $(DIRLIST_HDR) $(SYMTAB_SRC)
|
||||
.PHONY: all build clean install populate
|
||||
.PRECIOUS: ../../../libapps$(LIBEXT)
|
||||
|
||||
@ -85,41 +95,55 @@ $(foreach DIR, $(BUILD_SUBDIRS), $(eval $(call DIR_template,$(DIR),install,insta
|
||||
|
||||
build: $(foreach DIR, $(BUILD_SUBDIRS), $(DIR)_build)
|
||||
|
||||
# Install each program in the romfs directory
|
||||
# Install each program in the file system image directory
|
||||
|
||||
install: $(foreach DIR, $(BUILD_SUBDIRS), $(DIR)_install)
|
||||
|
||||
# Create the romfs directory
|
||||
# Create the file system image directory
|
||||
|
||||
$(ROMFS_DIR):
|
||||
$(Q) mkdir $(ROMFS_DIR)
|
||||
$(FSIMG_DIR):
|
||||
$(Q) mkdir $(FSIMG_DIR)
|
||||
|
||||
# Populate the romfs directory
|
||||
# Populate the file system image directory
|
||||
|
||||
populate: $(ROMFS_DIR) build install
|
||||
populate: $(FSIMG_DIR) build install
|
||||
|
||||
ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y)
|
||||
# Create the romfs.img file from the populated romfs directory
|
||||
|
||||
$(ROMFS_IMG): populate
|
||||
$(Q) genromfs -f $@ -d $(ROMFS_DIR) -V "ELFTEST"
|
||||
$(Q) genromfs -f $@ -d $(FSIMG_DIR) -V "ELFTEST"
|
||||
|
||||
# Create the romfs.h header file from the romfs.img file
|
||||
|
||||
$(ROMFS_HDR) : $(ROMFS_IMG)
|
||||
$(FSIMG_HDR) : $(ROMFS_IMG)
|
||||
$(Q) (cd $(TESTS_DIR); xxd -i romfs.img | sed -e "s/^unsigned/static const unsigned/g" >$@)
|
||||
|
||||
# Create the dirlist.h header file from the romfs directory
|
||||
else
|
||||
# Make sure that the NuttX gencromfs tool has been built
|
||||
|
||||
$(NXTOOLDIR)$(DELIM)$(GENCROMFSEXE): $(NXTOOLDIR)$(DELIM)$(GENCROMFSSRC)
|
||||
$(Q) $(MAKE) -C $(NXTOOLDIR) -f Makefile.host $(GENCROMFSEXE)
|
||||
|
||||
# Create the cromfs.h header file from the populated cromfs directory
|
||||
|
||||
$(FSIMG_HDR) : populate $(NXTOOLDIR)$(DELIM)$(GENCROMFSEXE)
|
||||
$(Q) $(NXTOOLDIR)$(DELIM)$(GENCROMFSEXE) $(FSIMG_DIR) $(FSIMG_HDR)
|
||||
|
||||
endif
|
||||
|
||||
# Create the dirlist.h header file from the file system image directory
|
||||
|
||||
$(DIRLIST_HDR) : populate
|
||||
$(Q) $(TESTS_DIR)/mkdirlist.sh $(ROMFS_DIR) >$@
|
||||
$(Q) $(TESTS_DIR)/mkdirlist.sh $(FSIMG_DIR) >$@
|
||||
|
||||
# Create the exported symbol table
|
||||
|
||||
$(SYMTAB_SRC): build
|
||||
$(Q) $(TESTS_DIR)/mksymtab.sh $(ROMFS_DIR) >$@
|
||||
$(Q) $(TESTS_DIR)/mksymtab.sh $(FSIMG_DIR) >$@
|
||||
|
||||
# Clean each subdirectory
|
||||
|
||||
clean: $(foreach DIR, $(ALL_SUBDIRS), $(DIR)_clean)
|
||||
$(Q) rm -f $(ROMFS_HDR) $(DIRLIST_HDR) $(ROMFS_IMG) $(SYMTAB_SRC)
|
||||
$(Q) rm -rf $(ROMFS_DIR)
|
||||
$(Q) rm -f $(FSIMG_HDR) $(DIRLIST_HDR) $(ROMFS_IMG) $(SYMTAB_SRC)
|
||||
$(Q) rm -rf $(FSIMG_DIR)
|
||||
|
@ -88,5 +88,5 @@ clean:
|
||||
$(call CLEAN)
|
||||
|
||||
install:
|
||||
$(Q) mkdir -p $(ROMFS_DIR)
|
||||
$(Q) install $(BIN) $(ROMFS_DIR)/$(BIN)
|
||||
$(Q) mkdir -p $(FSIMG_DIR)
|
||||
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
|
||||
|
@ -88,5 +88,5 @@ clean:
|
||||
$(call CLEAN)
|
||||
|
||||
install:
|
||||
$(Q) mkdir -p $(ROMFS_DIR)
|
||||
$(Q) install $(BIN) $(ROMFS_DIR)/$(BIN)
|
||||
$(Q) mkdir -p $(FSIMG_DIR)
|
||||
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
|
||||
|
@ -157,13 +157,13 @@ clean:
|
||||
$(call CLEAN)
|
||||
|
||||
install: $(ALL_BIN)
|
||||
$(Q) mkdir -p $(ROMFS_DIR)
|
||||
$(Q) install $(BIN1) $(ROMFS_DIR)/$(BIN1)
|
||||
$(Q) install $(BIN2) $(ROMFS_DIR)/$(BIN2)
|
||||
$(Q) mkdir -p $(FSIMG_DIR)
|
||||
$(Q) install $(BIN1) $(FSIMG_DIR)/$(BIN1)
|
||||
$(Q) install $(BIN2) $(FSIMG_DIR)/$(BIN2)
|
||||
ifeq ($(CONFIG_BINFMT_CONSTRUCTORS),y)
|
||||
$(Q) install $(BIN3) $(ROMFS_DIR)/$(BIN3)
|
||||
$(Q) install $(BIN3) $(FSIMG_DIR)/$(BIN3)
|
||||
ifeq ($(CONFIG_EXAMPLES_ELF_UCLIBCXX),y)
|
||||
$(Q) install $(BIN4) $(ROMFS_DIR)/$(BIN4)
|
||||
$(Q) install $(BIN5) $(ROMFS_DIR)/$(BIN5)
|
||||
$(Q) install $(BIN4) $(FSIMG_DIR)/$(BIN4)
|
||||
$(Q) install $(BIN5) $(FSIMG_DIR)/$(BIN5)
|
||||
endif
|
||||
endif
|
||||
|
@ -88,5 +88,5 @@ clean:
|
||||
$(call CLEAN)
|
||||
|
||||
install:
|
||||
$(Q) mkdir -p $(ROMFS_DIR)
|
||||
$(Q) install $(BIN) $(ROMFS_DIR)/$(BIN)
|
||||
$(Q) mkdir -p $(FSIMG_DIR)
|
||||
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
|
||||
|
@ -88,5 +88,5 @@ clean:
|
||||
$(call CLEAN)
|
||||
|
||||
install:
|
||||
$(Q) mkdir -p $(ROMFS_DIR)
|
||||
$(Q) install $(BIN) $(ROMFS_DIR)/$(BIN)
|
||||
$(Q) mkdir -p $(FSIMG_DIR)
|
||||
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
|
||||
|
@ -88,5 +88,5 @@ clean:
|
||||
$(call CLEAN)
|
||||
|
||||
install:
|
||||
$(Q) mkdir -p $(ROMFS_DIR)
|
||||
$(Q) install $(BIN) $(ROMFS_DIR)/$(BIN)
|
||||
$(Q) mkdir -p $(FSIMG_DIR)
|
||||
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
|
||||
|
@ -88,5 +88,5 @@ clean:
|
||||
$(call CLEAN)
|
||||
|
||||
install:
|
||||
$(Q) mkdir -p $(ROMFS_DIR)
|
||||
$(Q) install $(BIN) $(ROMFS_DIR)/$(BIN)
|
||||
$(Q) mkdir -p $(FSIMG_DIR)
|
||||
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
|
||||
|
@ -89,5 +89,5 @@ clean:
|
||||
$(call CLEAN)
|
||||
|
||||
install:
|
||||
$(Q) mkdir -p $(ROMFS_DIR)
|
||||
$(Q) install $(BIN) $(ROMFS_DIR)/$(BIN)
|
||||
$(Q) mkdir -p $(FSIMG_DIR)
|
||||
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
|
||||
|
@ -88,5 +88,5 @@ clean:
|
||||
$(call CLEAN)
|
||||
|
||||
install:
|
||||
$(Q) mkdir -p $(ROMFS_DIR)
|
||||
$(Q) install $(BIN) $(ROMFS_DIR)/$(BIN)
|
||||
$(Q) mkdir -p $(FSIMG_DIR)
|
||||
$(Q) install $(BIN) $(FSIMG_DIR)/$(BIN)
|
||||
|
Loading…
Reference in New Issue
Block a user