This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new 61194fe6c examples/elf: add possibility to create romfs image
61194fe6c is described below

commit 61194fe6c003dcc7425936d494970f98b25fe1f3
Author: Laczen JMS <laczen...@gmail.com>
AuthorDate: Thu Apr 17 15:17:31 2025 +0200

    examples/elf: add possibility to create romfs image
    
    Add the possibility to create a romfs image for an "external" file
    system. The romfs.img can directly be written to a configurable
    mtdblock device.
    
    Signed-off-by: Laczen JMS <laczen...@gmail.com>
---
 examples/elf/Kconfig          |  7 +++++--
 examples/elf/elf_main.c       |  8 ++++++--
 examples/elf/tests/.gitignore |  1 +
 examples/elf/tests/Makefile   | 34 ++++++++++++++++++++++++++++++++--
 4 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/examples/elf/Kconfig b/examples/elf/Kconfig
index 3c1a69a39..ee285b091 100644
--- a/examples/elf/Kconfig
+++ b/examples/elf/Kconfig
@@ -39,7 +39,7 @@ config EXAMPLES_ELF_EXTERN
                The file system is assumed to reside on some external media
                such as an SD card or a USB FLASH drive.  In this case, that
                external file system must be created manually by copying the
-               files in apps/examples/elf/tests/romfs to the volume.
+               files in apps/examples/elf/tests/extfs to the volume.
 
                The external volume can optionally be mounted by the test if
                the CONFIG_EXAMPLES_FSMOUNT option is also selected.
@@ -81,7 +81,10 @@ config EXAMPLES_ELF_FSTYPE
        depends on EXAMPLES_ELF_FSMOUNT
        ---help---
                The type of the external file system as will be used in the 
mount()
-               command.  Default: "vfat"
+               command.  Default: "vfat".
+               If the type of the external file system is set to "romfs" a 
romfs.img
+               is created in apps/examples/elf/tests/ this can be copied to an
+               internal block device.
 
 config EXAMPLES_ELF_DEVPATH
        string "Block driver device path"
diff --git a/examples/elf/elf_main.c b/examples/elf/elf_main.c
index 160d1e233..befa256e3 100644
--- a/examples/elf/elf_main.c
+++ b/examples/elf/elf_main.c
@@ -215,7 +215,11 @@ int main(int argc, FAR char *argv[])
 
   mm_initmonitor();
 
+#if defined(CONFIG_EXAMPLES_ELF_FSMOUNT)
+  sprintf(devname, CONFIG_EXAMPLES_ELF_DEVPATH);
+#else
   sprintf(devname, ELF_DEVPATH_FMT, CONFIG_EXAMPLES_ELF_DEVMINOR);
+#endif
 
 #if defined(CONFIG_EXAMPLES_ELF_ROMFS)
 
@@ -298,8 +302,8 @@ int main(int argc, FAR char *argv[])
 
   /* Mount the external file system */
 
-  message("Mounting %s filesystem at target=%s\n",
-          CONFIG_EXAMPLES_ELF_FSTYPE, MOUNTPT);
+  message("Mounting %s filesystem at target=%s on %s\n",
+          CONFIG_EXAMPLES_ELF_FSTYPE, MOUNTPT, devname);
 
   ret = mount(devname, MOUNTPT, CONFIG_EXAMPLES_ELF_FSTYPE, MS_RDONLY, NULL);
   if (ret < 0)
diff --git a/examples/elf/tests/.gitignore b/examples/elf/tests/.gitignore
index abf82cfea..416f7e66e 100644
--- a/examples/elf/tests/.gitignore
+++ b/examples/elf/tests/.gitignore
@@ -4,4 +4,5 @@
 /cromfs
 /cromfs.c
 /dirlist.c
+/extfs
 /symtab.c
diff --git a/examples/elf/tests/Makefile b/examples/elf/tests/Makefile
index ca78d8d5d..f73d31fc9 100644
--- a/examples/elf/tests/Makefile
+++ b/examples/elf/tests/Makefile
@@ -51,7 +51,9 @@ ifeq ($(CONFIG_EXAMPLES_ELF_ROMFS),y)
   FSIMG_DIR = $(TESTS_DIR)/$(FSIMG_SUBDIR)
   ROMFS_IMG = $(TESTS_DIR)/romfs.img
   FSIMG_SRC = $(TESTS_DIR)/romfs.c
-else
+endif
+
+ifeq ($(CONFIG_EXAMPLES_ELF_CROMFS),y)
   NXTOOLDIR = $(TOPDIR)/tools
   GENCROMFSSRC = gencromfs.c
   GENCROMFSEXE = gencromfs$(HOSTEXEEXT)
@@ -61,6 +63,19 @@ else
   FSIMG_SRC = $(TESTS_DIR)/cromfs.c
 endif
 
+ifeq ($(CONFIG_EXAMPLES_ELF_EXTERN),y)
+  FSIMG_SUBDIR = extfs
+  FSIMG_DIR = $(TESTS_DIR)/$(FSIMG_SUBDIR)
+endif
+
+# generate the romfs image in case the fs type is romfs
+# the FSIMG_SRC is not actually generated.
+
+ifeq ($(CONFIG_EXAMPLES_ELF_FSTYPE), "romfs")
+  ROMFS_IMG = $(TESTS_DIR)/romfs.img
+  FSIMG_SRC = $(TESTS_DIR)/romfs.c
+endif
+
 define DIR_template
 $(1)_$(2):
        +$(Q) $(MAKE) -C $(1) $(2) TOPDIR="$(TOPDIR)" APPDIR="$(APPDIR)" 
FSIMG_DIR="$(FSIMG_DIR)" CROSSDEV=$(CROSSDEV)
@@ -90,7 +105,9 @@ $(FSIMG_SRC): $(ROMFS_IMG)
                xxd -i romfs.img | sed -e "s/^unsigned char/const unsigned char 
aligned_data(4)/g" | \
                sed -e "s/romfs_img/elf_romfs_img/g" >>$@)
 
-else
+endif
+
+ifeq ($(CONFIG_EXAMPLES_ELF_CROMFS),y)
 # Make sure that the NuttX gencromfs tool has been built
 
 $(NXTOOLDIR)/$(GENCROMFSEXE): $(NXTOOLDIR)/$(GENCROMFSSRC)
@@ -104,6 +121,19 @@ $(FSIMG_SRC): install $(NXTOOLDIR)/$(GENCROMFSEXE)
 
 endif
 
+ifeq ($(CONFIG_EXAMPLES_ELF_FSTYPE),"romfs")
+# Create the romfs.img file from the populated romfs directory
+
+$(ROMFS_IMG): install
+       $(Q) genromfs -f $@.tmp -d $(FSIMG_DIR) -V "ELFTEST"
+       $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
+
+# Create the romfs.c file from the romfs.img file
+
+$(FSIMG_SRC): $(ROMFS_IMG)
+
+endif
+
 # Create the dirlist.h header file from the file system image directory
 
 $(DIRLIST_SRC): install

Reply via email to