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

commit bb492e789d5d3742efbf54dc03b3c3fa71a59691
Author: anjiahao <anjia...@xiaomi.com>
AuthorDate: Tue Apr 30 15:41:35 2024 +0800

    sotest & chardev:change elf loading method
    
    Signed-off-by: anjiahao <anjia...@xiaomi.com>
---
 .gitignore                          |  1 +
 examples/module/.gitignore          |  1 +
 examples/module/CMakeLists.txt      | 22 +++++++++++++++
 examples/module/chardev/.gitignore  |  1 +
 examples/module/chardev/chardev.c   | 18 ++++--------
 examples/module/main/.gitignore     |  1 +
 examples/module/main/Kconfig        |  1 +
 examples/module/main/Makefile       | 18 ++++++++++--
 examples/sotest/.gitignore          |  1 +
 examples/sotest/CMakeLists.txt      | 22 +++++++++++++++
 examples/sotest/modprint/.gitignore |  1 +
 examples/sotest/modprint/modprint.c | 52 +----------------------------------
 examples/sotest/sotest/.gitignore   |  1 +
 examples/sotest/sotest/sotest.c     | 55 +++++++------------------------------
 14 files changed, 85 insertions(+), 110 deletions(-)

diff --git a/.gitignore b/.gitignore
index 2eea7e537..c30e7faea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,6 +20,7 @@
 *.swp
 *.sym
 *.su
+*.map
 *~
 .built
 .context
diff --git a/examples/module/.gitignore b/examples/module/.gitignore
index 9e1d2593e..8e29db973 100644
--- a/examples/module/.gitignore
+++ b/examples/module/.gitignore
@@ -1 +1,2 @@
 /Kconfig
+lib/
diff --git a/examples/module/CMakeLists.txt b/examples/module/CMakeLists.txt
new file mode 100644
index 000000000..54e5a388b
--- /dev/null
+++ b/examples/module/CMakeLists.txt
@@ -0,0 +1,22 @@
+# 
##############################################################################
+# apps/examples/module/CMakeLists.txt
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+# license agreements.  See the NOTICE file distributed with this work for
+# additional information regarding copyright ownership.  The ASF licenses this
+# file to you under the Apache License, Version 2.0 (the "License"); you may 
not
+# use this file except in compliance with the License.  You may obtain a copy 
of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations under
+# the License.
+#
+# 
##############################################################################
+
+nuttx_add_subdirectory()
+nuttx_generate_kconfig(MENUDESC "Module")
diff --git a/examples/module/chardev/.gitignore 
b/examples/module/chardev/.gitignore
new file mode 100644
index 000000000..c7de605bd
--- /dev/null
+++ b/examples/module/chardev/.gitignore
@@ -0,0 +1 @@
+*.map
diff --git a/examples/module/chardev/chardev.c 
b/examples/module/chardev/chardev.c
index dcc816a60..5291a13cc 100644
--- a/examples/module/chardev/chardev.c
+++ b/examples/module/chardev/chardev.c
@@ -101,12 +101,12 @@ static ssize_t chardev_write(FAR struct file *filep, FAR 
const char *buffer,
  * Name: module_uninitialize
  ****************************************************************************/
 
-static int module_uninitialize(FAR void *arg)
+destructor_function void module_uninitialize(void)
 {
   /* TODO: Check if there are any open references to the driver */
 
-  syslog(LOG_INFO, "module_uninitialize: arg=%p\n", arg);
-  return unregister_driver("/dev/chardev");
+  syslog(LOG_INFO, "module_uninitialize\n");
+  unregister_driver("/dev/chardev");
 }
 
 /****************************************************************************
@@ -121,14 +121,8 @@ static int module_uninitialize(FAR void *arg)
  *
  ****************************************************************************/
 
-int module_initialize(FAR struct mod_info_s *modinfo)
+constructor_fuction void module_initialize(void)
 {
-  syslog(LOG_INFO, "module_initialize:\n");
-
-  modinfo->uninitializer = module_uninitialize;
-  modinfo->arg           = NULL;
-  modinfo->exports       = NULL;
-  modinfo->nexports      = 0;
-
-  return register_driver("/dev/chardev", &g_chardev_fops, 0666, NULL);
+  syslog(LOG_INFO, "module_initialize\n");
+  register_driver("/dev/chardev", &g_chardev_fops, 0666, NULL);
 }
diff --git a/examples/module/main/.gitignore b/examples/module/main/.gitignore
index 03d6e064e..a23661bdf 100644
--- a/examples/module/main/.gitignore
+++ b/examples/module/main/.gitignore
@@ -3,3 +3,4 @@
 /cromfs.c
 /chardev_mod_symtab.c
 /mod_symtab.c
+/chardev
diff --git a/examples/module/main/Kconfig b/examples/module/main/Kconfig
index d51461d8d..28a9c5f26 100644
--- a/examples/module/main/Kconfig
+++ b/examples/module/main/Kconfig
@@ -8,6 +8,7 @@ config EXAMPLES_MODULE
        default n
        depends on MODULE && BOARDCTL
        select BOARDCTL_OS_SYMTAB
+       select MODULES
        ---help---
                Enable the module example
 
diff --git a/examples/module/main/Makefile b/examples/module/main/Makefile
index c731bade5..ceacd6abc 100644
--- a/examples/module/main/Makefile
+++ b/examples/module/main/Makefile
@@ -30,6 +30,12 @@ MAINSRC = module_main.c
 SYMTABSRC = mod_symtab.c
 SYMTABOBJ = $(SYMTABSRC:.c=$(OBJEXT))
 
+
+ifneq ($(CONFIG_BUILD_FLAT),y)
+  PASS1_SYMTAB = $(TOPDIR)/pass1/mod_symtab.c
+  MODLUE_NAME = chardev
+endif
+
 $(SYMTABSRC):
        $(Q) $(APPDIR)$(DELIM)tools$(DELIM)mksymtab.sh $(BINDIR) g_mod >$@.tmp
        $(Q) $(call TESTANDREPLACEFILE, $@.tmp, $@)
@@ -79,11 +85,19 @@ endif
 
 endif
 
-postinstall:: $(ROMFSOBJ) $(SYMTABOBJ) $(FSIMG_OBJ)
+# Copy the symbol table into the kernel pass1/ build directory
+
+ifneq ($(CONFIG_BUILD_FLAT),y)
+$(PASS1_SYMTAB): $(SYMTABSRC)
+       $(Q) install -m 0644 $(SYMTABSRC) $(PASS1_SYMTAB)
+       $(Q) mv $(BINDIR)$(DELIM)$(MODLUE_NAME) .
+endif
+
+postinstall:: $(ROMFSOBJ) $(SYMTABOBJ) $(FSIMG_OBJ) $(PASS1_SYMTAB)
        $(call ARLOCK, $(call CONVERT_PATH,$(BIN)), $^)
 
 distclean::
-       $(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) 
$(ROMFSOBJ))
+       $(Q) $(call DELFILE, $(SYMTABSRC) $(SYMTABOBJ) $(ROMFSSRC) $(ROMFSIMG) 
$(ROMFSOBJ) $(MODLUE_NAME))
 
 
 include $(APPDIR)/Application.mk
diff --git a/examples/sotest/.gitignore b/examples/sotest/.gitignore
index 9e1d2593e..8e29db973 100644
--- a/examples/sotest/.gitignore
+++ b/examples/sotest/.gitignore
@@ -1 +1,2 @@
 /Kconfig
+lib/
diff --git a/examples/sotest/CMakeLists.txt b/examples/sotest/CMakeLists.txt
new file mode 100644
index 000000000..bab18517a
--- /dev/null
+++ b/examples/sotest/CMakeLists.txt
@@ -0,0 +1,22 @@
+# 
##############################################################################
+# apps/examples/sotest/CMakeLists.txt
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more 
contributor
+# license agreements.  See the NOTICE file distributed with this work for
+# additional information regarding copyright ownership.  The ASF licenses this
+# file to you under the Apache License, Version 2.0 (the "License"); you may 
not
+# use this file except in compliance with the License.  You may obtain a copy 
of
+# the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations under
+# the License.
+#
+# 
##############################################################################
+
+nuttx_add_subdirectory()
+nuttx_generate_kconfig(MENUDESC "Sotest")
diff --git a/examples/sotest/modprint/.gitignore 
b/examples/sotest/modprint/.gitignore
new file mode 100644
index 000000000..c7de605bd
--- /dev/null
+++ b/examples/sotest/modprint/.gitignore
@@ -0,0 +1 @@
+*.map
diff --git a/examples/sotest/modprint/modprint.c 
b/examples/sotest/modprint/modprint.c
index 5b48df6c6..e5e89f79f 100644
--- a/examples/sotest/modprint/modprint.c
+++ b/examples/sotest/modprint/modprint.c
@@ -32,23 +32,6 @@
 #include <nuttx/symtab.h>
 #include <nuttx/lib/modlib.h>
 
-/****************************************************************************
- * Private Function Prototypes
- ****************************************************************************/
-
-static void modprint(FAR const char *fmt, ...) printf_like(1, 2);
-
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-static const struct symtab_s g_modprint_exports[1] =
-{
-  {
-    "modprint", (FAR const void *)modprint,
-  }
-};
-
 /****************************************************************************
  * Private Functions
  ****************************************************************************/
@@ -57,7 +40,7 @@ static const struct symtab_s g_modprint_exports[1] =
  * Name: modprint
  ****************************************************************************/
 
-static void modprint(FAR const char *fmt, ...)
+visibility_default void modprint(FAR const char *fmt, ...)
 {
   va_list ap;
 
@@ -66,36 +49,3 @@ static void modprint(FAR const char *fmt, ...)
   va_end(ap);
 }
 
-/****************************************************************************
- * Name: module_uninitialize
- ****************************************************************************/
-
-static int module_uninitialize(FAR void *arg)
-{
-  syslog(LOG_INFO, "module_uninitialize: arg=%p\n", arg);
-  return OK;
-}
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: module_initialize
- *
- * Description:
- *   Register /dev/sotest
- *
- ****************************************************************************/
-
-int module_initialize(FAR struct mod_info_s *modinfo)
-{
-  syslog(LOG_INFO, "module_initialize:\n");
-
-  modinfo->uninitializer = module_uninitialize;
-  modinfo->arg           = NULL;
-  modinfo->exports       = g_modprint_exports;
-  modinfo->nexports      = 1;
-
-  return OK;
-}
diff --git a/examples/sotest/sotest/.gitignore 
b/examples/sotest/sotest/.gitignore
new file mode 100644
index 000000000..c7de605bd
--- /dev/null
+++ b/examples/sotest/sotest/.gitignore
@@ -0,0 +1 @@
+*.map
diff --git a/examples/sotest/sotest/sotest.c b/examples/sotest/sotest/sotest.c
index 9fe26c19c..47d99b621 100644
--- a/examples/sotest/sotest/sotest.c
+++ b/examples/sotest/sotest/sotest.c
@@ -44,40 +44,13 @@ void modprint(FAR const char *fmt, ...) printf_like(1, 2);
  * Private Function Prototypes
  ****************************************************************************/
 
-static void testfunc1(FAR const char *msg);
-static void testfunc2(FAR const char *msg);
-static void testfunc3(FAR const char *msg);
-static int module_uninitialize(FAR void *arg);
-
 /****************************************************************************
  * Private Data
  ****************************************************************************/
 
-static const char g_msg1[] = "Hello to you too!";
-static const char g_msg2[] = "Not so bad so far.";
-static const char g_msg3[] = "Yes, don't be a stranger!";
-
-static const struct symtab_s g_sotest_exports[6] =
-{
-  {
-    "testfunc1", (FAR const void *)testfunc1,
-  },
-  {
-    "testfunc2", (FAR const void *)testfunc2,
-  },
-  {
-    "testfunc3", (FAR const void *)testfunc3,
-  },
-  {
-    "g_msg1",    (FAR const void *)g_msg1,
-  },
-  {
-    "g_msg2",    (FAR const void *)g_msg2,
-  },
-  {
-    "g_msg3",    (FAR const void *)g_msg3,
-  },
-};
+visibility_default const char g_msg1[] = "Hello to you too!";
+visibility_default const char g_msg2[] = "Not so bad so far.";
+visibility_default const char g_msg3[] = "Yes, don't be a stranger!";
 
 /****************************************************************************
  * Private Functions
@@ -102,7 +75,7 @@ static void modprint(FAR const char *fmt, ...)
  * Name: testfunc1
  ****************************************************************************/
 
-static void testfunc1(FAR const char *msg)
+visibility_default void testfunc1(FAR const char *msg)
 {
   modprint("testfunc1: Hello, everyone!\n");
   modprint("   caller: %s\n", msg);
@@ -112,7 +85,7 @@ static void testfunc1(FAR const char *msg)
  * Name: testfunc2
  ****************************************************************************/
 
-static void testfunc2(FAR const char *msg)
+visibility_default void testfunc2(FAR const char *msg)
 {
   modprint("testfunc2: Hope you are having a great day!\n");
   modprint("   caller: %s\n", msg);
@@ -122,7 +95,7 @@ static void testfunc2(FAR const char *msg)
  * Name: testfunc3
  ****************************************************************************/
 
-static void testfunc3(FAR const char *msg)
+visibility_default void testfunc3(FAR const char *msg)
 {
   modprint("testfunc3: Let's talk again very soon\n");
   modprint("   caller: %s\n", msg);
@@ -132,10 +105,9 @@ static void testfunc3(FAR const char *msg)
  * Name: module_uninitialize
  ****************************************************************************/
 
-static int module_uninitialize(FAR void *arg)
+destructor_function static void module_uninitialize(void)
 {
-  modprint("module_uninitialize: arg=%p\n", arg);
-  return OK;
+  modprint("module_uninitialize\n");
 }
 
 /****************************************************************************
@@ -150,14 +122,7 @@ static int module_uninitialize(FAR void *arg)
  *
  ****************************************************************************/
 
-int module_initialize(FAR struct mod_info_s *modinfo)
+constructor_fuction static void module_initialize(void)
 {
-  modprint("module_initialize:\n");
-
-  modinfo->uninitializer = module_uninitialize;
-  modinfo->arg           = NULL;
-  modinfo->exports       = g_sotest_exports;
-  modinfo->nexports      = 6;
-
-  return OK;
+  modprint("module_initialize\n");
 }

Reply via email to