You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ha...@apache.org on 2022/10/16 19:39:16 UTC

[incubator-nuttx-apps] branch master updated (893387b2c -> 8e460e7e1)

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

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


    from 893387b2c Fix the minor style issue
     new cf70d8f95 nshlib: Call nsh_sysinitscript in usb or alt console like normal one
     new 964747dd3 nshlib: Call nsh_telnetstart in nsh_initialize to avoid the dupliation
     new 0d210c322 nshlib: Move commoin initialization from console_main to nsh_initialize
     new 8e460e7e1 nshlib: Move symbol table initialization from nsh_main to nsh_initialize

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 examples/nxterm/nxterm_main.c    |  16 -------
 graphics/nxwm/src/cnxterm.cxx    |  14 ------
 graphics/twm4nx/apps/cnxterm.cxx |  14 ------
 nshlib/nsh_altconsole.c          |  29 -----------
 nshlib/nsh_consolemain.c         |  32 -------------
 nshlib/nsh_init.c                | 101 +++++++++++++++++++++++++++++++++++++--
 nshlib/nsh_telnetd.c             |  38 ---------------
 nshlib/nsh_usbconsole.c          |  24 ----------
 system/nsh/nsh_main.c            |  77 ++---------------------------
 9 files changed, 101 insertions(+), 244 deletions(-)


[incubator-nuttx-apps] 01/04: nshlib: Call nsh_sysinitscript in usb or alt console like normal one

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit cf70d8f95bccb265ba84acc5e3957ada64cdf379
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Oct 15 16:31:12 2022 +0800

    nshlib: Call nsh_sysinitscript in usb or alt console like normal one
    
    forget in the pull request:
    https://github.com/apache/incubator-nuttx-apps/pull/1142
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh_altconsole.c | 17 +++++++++++------
 nshlib/nsh_usbconsole.c | 12 +++++++++---
 2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/nshlib/nsh_altconsole.c b/nshlib/nsh_altconsole.c
index f003f4276..f407ceffd 100644
--- a/nshlib/nsh_altconsole.c
+++ b/nshlib/nsh_altconsole.c
@@ -257,12 +257,10 @@ int nsh_consolemain(int argc, FAR char *argv[])
   usbtrace_enable(TRACE_BITSET);
 #endif
 
-  /* Execute the one-time start-up script.
-   * Any output will go to /dev/console.
-   */
+#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
+  /* Execute the system init script */
 
-#ifdef CONFIG_NSH_ROMFSETC
-  nsh_initscript(&pstate->cn_vtbl);
+  nsh_sysinitscript(&pstate->cn_vtbl);
 #endif
 
 #ifdef CONFIG_NSH_NETINIT
@@ -277,10 +275,17 @@ int nsh_consolemain(int argc, FAR char *argv[])
   boardctl(BOARDIOC_FINALINIT, 0);
 #endif
 
+  /* Execute the one-time start-up script.
+   * Any output will go to /dev/console.
+   */
+
+#ifdef CONFIG_NSH_ROMFSETC
+  nsh_initscript(&pstate->cn_vtbl);
+#endif
+
   /* First map stderr and stdout to alternative devices */
 
   ret = nsh_clone_console(pstate);
-
   if (ret < 0)
     {
       return ret;
diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index 5ec2ac4c9..bdde01986 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -284,10 +284,10 @@ int nsh_consolemain(int argc, FAR char *argv[])
   nsh_nullstdio();
 #endif
 
-  /* Execute the one-time start-up script (output may go to /dev/null) */
+#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
+  /* Execute the system init script */
 
-#ifdef CONFIG_NSH_ROMFSETC
-  nsh_initscript(&pstate->cn_vtbl);
+  nsh_sysinitscript(&pstate->cn_vtbl);
 #endif
 
 #ifdef CONFIG_NSH_NETINIT
@@ -302,6 +302,12 @@ int nsh_consolemain(int argc, FAR char *argv[])
   boardctl(BOARDIOC_FINALINIT, 0);
 #endif
 
+  /* Execute the one-time start-up script (output may go to /dev/null) */
+
+#ifdef CONFIG_NSH_ROMFSETC
+  nsh_initscript(&pstate->cn_vtbl);
+#endif
+
   /* Now loop, executing creating a session for each USB connection */
 
   for (; ; )


[incubator-nuttx-apps] 03/04: nshlib: Move commoin initialization from console_main to nsh_initialize

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 0d210c3227f2b49955e59e04d0f9c674223c9066
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Oct 15 17:31:04 2022 +0800

    nshlib: Move commoin initialization from console_main to nsh_initialize
    
    to avoid the code duplication
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh_altconsole.c  | 34 ----------------------------------
 nshlib/nsh_consolemain.c | 32 --------------------------------
 nshlib/nsh_init.c        | 43 +++++++++++++++++++++++++++++++++++++++++--
 nshlib/nsh_telnetd.c     | 38 --------------------------------------
 nshlib/nsh_usbconsole.c  | 30 ------------------------------
 system/nsh/nsh_main.c    |  7 +++----
 6 files changed, 44 insertions(+), 140 deletions(-)

diff --git a/nshlib/nsh_altconsole.c b/nshlib/nsh_altconsole.c
index f407ceffd..750fc845f 100644
--- a/nshlib/nsh_altconsole.c
+++ b/nshlib/nsh_altconsole.c
@@ -34,8 +34,6 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
-#include "netutils/netinit.h"
-
 #if defined(CONFIG_NSH_ALTCONDEV) && !defined(HAVE_USB_CONSOLE)
 
 /****************************************************************************
@@ -251,38 +249,6 @@ int nsh_consolemain(int argc, FAR char *argv[])
 
   DEBUGASSERT(pstate);
 
-  /* Initialize any USB tracing options that were requested */
-
-#ifdef CONFIG_NSH_USBDEV_TRACE
-  usbtrace_enable(TRACE_BITSET);
-#endif
-
-#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
-  /* Execute the system init script */
-
-  nsh_sysinitscript(&pstate->cn_vtbl);
-#endif
-
-#ifdef CONFIG_NSH_NETINIT
-  /* Bring up the network */
-
-  netinit_bringup();
-#endif
-
-#if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
-  /* Perform architecture-specific final-initialization (if configured) */
-
-  boardctl(BOARDIOC_FINALINIT, 0);
-#endif
-
-  /* Execute the one-time start-up script.
-   * Any output will go to /dev/console.
-   */
-
-#ifdef CONFIG_NSH_ROMFSETC
-  nsh_initscript(&pstate->cn_vtbl);
-#endif
-
   /* First map stderr and stdout to alternative devices */
 
   ret = nsh_clone_console(pstate);
diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index 13cb6eb94..463c30b02 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -32,8 +32,6 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
-#include "netutils/netinit.h"
-
 #if !defined(CONFIG_NSH_ALTCONDEV) && !defined(HAVE_USB_CONSOLE) && \
     !defined(HAVE_USB_KEYBOARD)
 
@@ -71,36 +69,6 @@ int nsh_consolemain(int argc, FAR char *argv[])
 
   DEBUGASSERT(pstate != NULL);
 
-#ifdef CONFIG_NSH_USBDEV_TRACE
-  /* Initialize any USB tracing options that were requested */
-
-  usbtrace_enable(TRACE_BITSET);
-#endif
-
-#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
-  /* Execute the system init script */
-
-  nsh_sysinitscript(&pstate->cn_vtbl);
-#endif
-
-#ifdef CONFIG_NSH_NETINIT
-  /* Bring up the network */
-
-  netinit_bringup();
-#endif
-
-#if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
-  /* Perform architecture-specific final-initialization (if configured) */
-
-  boardctl(BOARDIOC_FINALINIT, 0);
-#endif
-
-#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
-  /* Execute the start-up script */
-
-  nsh_initscript(&pstate->cn_vtbl);
-#endif
-
   /* Execute the session */
 
   ret = nsh_session(pstate, true, argc, argv);
diff --git a/nshlib/nsh_init.c b/nshlib/nsh_init.c
index 251e6c452..fdd9a9208 100644
--- a/nshlib/nsh_init.c
+++ b/nshlib/nsh_init.c
@@ -27,9 +27,11 @@
 #include <sys/boardctl.h>
 
 #include "system/readline.h"
+#include "netutils/netinit.h"
 #include "nshlib/nshlib.h"
 
 #include "nsh.h"
+#include "nsh_console.h"
 
 /****************************************************************************
  * Private Data
@@ -66,28 +68,65 @@ static const struct extmatch_vtable_s g_nsh_extmatch =
 
 void nsh_initialize(void)
 {
+#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
+  FAR struct console_stdio_s *pstate;
+#endif
+
 #if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION)
   /* Configure the NSH prompt */
 
   readline_prompt(g_nshprompt);
 
-#ifdef CONFIG_READLINE_HAVE_EXTMATCH
+#  ifdef CONFIG_READLINE_HAVE_EXTMATCH
   /* Set up for tab completion on NSH commands */
 
   readline_extmatch(&g_nsh_extmatch);
-#endif
+#  endif
 #endif
 
   /* Mount the /etc filesystem */
 
   (void)nsh_romfsetc();
 
+#ifdef CONFIG_NSH_USBDEV_TRACE
+  /* Initialize any USB tracing options that were requested */
+
+  usbtrace_enable(TRACE_BITSET);
+#endif
+
 #ifdef CONFIG_NSH_ARCHINIT
   /* Perform architecture-specific initialization (if configured) */
 
   boardctl(BOARDIOC_INIT, 0);
 #endif
 
+#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
+  pstate = nsh_newconsole(false);
+
+  /* Execute the system init script */
+
+  nsh_sysinitscript(&pstate->cn_vtbl);
+#endif
+
+#ifdef CONFIG_NSH_NETINIT
+  /* Bring up the network */
+
+  netinit_bringup();
+#endif
+
+#if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
+  /* Perform architecture-specific final-initialization (if configured) */
+
+  boardctl(BOARDIOC_FINALINIT, 0);
+#endif
+
+#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
+  /* Execute the start-up script */
+
+  nsh_initscript(&pstate->cn_vtbl);
+  nsh_release(&pstate->cn_vtbl);
+#endif
+
 #if defined(CONFIG_NSH_TELNET) && !defined(CONFIG_NSH_DISABLE_TELNETSTART) && \
   !defined(CONFIG_NETINIT_NETLOCAL)
   /* If the Telnet console is selected as a front-end, then start the
diff --git a/nshlib/nsh_telnetd.c b/nshlib/nsh_telnetd.c
index a7bd99790..47f86d6b8 100644
--- a/nshlib/nsh_telnetd.c
+++ b/nshlib/nsh_telnetd.c
@@ -31,7 +31,6 @@
 
 #include <arpa/inet.h>
 
-#include "netutils/netinit.h"
 #include "netutils/telnetd.h"
 
 #ifdef CONFIG_TELNET_CHARACTER_MODE
@@ -225,9 +224,6 @@ int nsh_telnetstart(sa_family_t family)
 
   if (state == TELNETD_NOTRUNNING)
     {
-#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_CONSOLE)
-      FAR struct console_stdio_s *pstate;
-#endif
       struct telnetd_config_s config;
 
       /* There is a tiny race condition here if two tasks were to try to
@@ -236,40 +232,6 @@ int nsh_telnetstart(sa_family_t family)
 
       state = TELNETD_STARTED;
 
-      /* Initialize any USB tracing options that were requested.  If
-       * standard console is also defined, then we will defer this step to
-       * the standard console.
-       */
-
-#if defined(CONFIG_NSH_USBDEV_TRACE) && !defined(CONFIG_NSH_CONSOLE)
-      usbtrace_enable(TRACE_BITSET);
-#endif
-
-      /* Execute the startup script.  If standard console is also defined,
-       * then we will not bother with the initscript here (although it is
-       * safe to call nsh_initscript multiple times).
-       */
-
-#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_CONSOLE)
-      pstate = nsh_newconsole();
-      nsh_initscript(&pstate->cn_vtbl);
-      nsh_release(&pstate->cn_vtbl);
-#endif
-
-#if defined(CONFIG_NSH_NETINIT) && !defined(CONFIG_NSH_CONSOLE)
-      /* Bring up the network */
-
-      netinit_bringup();
-#endif
-
-      /* Perform architecture-specific final-initialization(if configured) */
-
-#if defined(CONFIG_NSH_ARCHINIT) && \
-    defined(CONFIG_BOARDCTL_FINALINIT) && \
-    !defined(CONFIG_NSH_CONSOLE)
-      boardctl(BOARDIOC_FINALINIT, 0);
-#endif
-
       /* Configure the telnet daemon */
 
       config.d_port      = HTONS(CONFIG_NSH_TELNETD_PORT);
diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index bdde01986..47512a953 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -248,12 +248,6 @@ int nsh_consolemain(int argc, FAR char *argv[])
 
   DEBUGASSERT(pstate);
 
-  /* Initialize any USB tracing options that were requested */
-
-#ifdef CONFIG_NSH_USBDEV_TRACE
-  usbtrace_enable(TRACE_BITSET);
-#endif
-
   /* Initialize the USB serial driver */
 
 #if defined(CONFIG_PL2303) || defined(CONFIG_CDCACM)
@@ -284,30 +278,6 @@ int nsh_consolemain(int argc, FAR char *argv[])
   nsh_nullstdio();
 #endif
 
-#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
-  /* Execute the system init script */
-
-  nsh_sysinitscript(&pstate->cn_vtbl);
-#endif
-
-#ifdef CONFIG_NSH_NETINIT
-  /* Bring up the network */
-
-  netinit_bringup();
-#endif
-
-#if defined(CONFIG_NSH_ARCHINIT) && defined(CONFIG_BOARDCTL_FINALINIT)
-  /* Perform architecture-specific final-initialization (if configured) */
-
-  boardctl(BOARDIOC_FINALINIT, 0);
-#endif
-
-  /* Execute the one-time start-up script (output may go to /dev/null) */
-
-#ifdef CONFIG_NSH_ROMFSETC
-  nsh_initscript(&pstate->cn_vtbl);
-#endif
-
   /* Now loop, executing creating a session for each USB connection */
 
   for (; ; )
diff --git a/system/nsh/nsh_main.c b/system/nsh/nsh_main.c
index 7212fccbe..44d93cb73 100644
--- a/system/nsh/nsh_main.c
+++ b/system/nsh/nsh_main.c
@@ -100,8 +100,7 @@ int main(int argc, FAR char *argv[])
   struct boardioc_symtab_s symdesc;
 #endif
   struct sched_param param;
-  int exitval = 0;
-  int ret;
+  int ret = 0;
 
   /* Check the task priority that we were started with */
 
@@ -137,8 +136,8 @@ int main(int argc, FAR char *argv[])
    */
 
   fprintf(stderr, "ERROR: nsh_consolemain() returned: %d\n", ret);
-  exitval = 1;
+  ret = 1;
 #endif
 
-  return exitval;
+  return ret;
 }


[incubator-nuttx-apps] 02/04: nshlib: Call nsh_telnetstart in nsh_initialize to avoid the dupliation

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 964747dd36db46428bd767d13aaee6f60f32d0b5
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Oct 15 17:00:22 2022 +0800

    nshlib: Call nsh_telnetstart in nsh_initialize to avoid the dupliation
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 examples/nxterm/nxterm_main.c    | 16 ----------------
 graphics/nxwm/src/cnxterm.cxx    | 14 --------------
 graphics/twm4nx/apps/cnxterm.cxx | 14 --------------
 nshlib/nsh_init.c                | 14 +++++++++++++-
 system/nsh/nsh_main.c            | 21 ---------------------
 5 files changed, 13 insertions(+), 66 deletions(-)

diff --git a/examples/nxterm/nxterm_main.c b/examples/nxterm/nxterm_main.c
index 57c19576b..8555980c5 100644
--- a/examples/nxterm/nxterm_main.c
+++ b/examples/nxterm/nxterm_main.c
@@ -223,22 +223,6 @@ int main(int argc, FAR char *argv[])
   printf("nxterm_main: Initialize NSH\n");
   nsh_initialize();
 
-  /* If the Telnet console is selected as a front-end, then start the
-   * Telnet daemon.
-   */
-
-#ifdef CONFIG_NSH_TELNET
-  ret = nsh_telnetstart(AF_UNSPEC);
-  if (ret < 0)
-    {
-      /* The daemon is NOT running.  Report the error then fail...
-       * either with the serial console up or just exiting.
-       */
-
-      fprintf(stderr, "ERROR: Failed to start TELNET daemon: %d\n", ret);
-    }
-#endif
-
   /* NX Initialization ******************************************************/
 
   /* Initialize NX */
diff --git a/graphics/nxwm/src/cnxterm.cxx b/graphics/nxwm/src/cnxterm.cxx
index 1143f0032..d84fd1b03 100644
--- a/graphics/nxwm/src/cnxterm.cxx
+++ b/graphics/nxwm/src/cnxterm.cxx
@@ -653,19 +653,5 @@ bool NxWM::nshlibInitialize(void)
   // Initialize the NSH library
 
   nsh_initialize();
-
-  // If the Telnet console is selected as a front-end, then start the
-  // Telnet daemon.
-
-#ifdef CONFIG_NSH_TELNET
-  int ret = nsh_telnetstart(AF_UNSPEC);
-  if (ret < 0)
-    {
-      // The daemon is NOT running!
-
-      return false;
-   }
-#endif
-
   return true;
 }
diff --git a/graphics/twm4nx/apps/cnxterm.cxx b/graphics/twm4nx/apps/cnxterm.cxx
index 3bd9821e6..d3cbd99d0 100644
--- a/graphics/twm4nx/apps/cnxterm.cxx
+++ b/graphics/twm4nx/apps/cnxterm.cxx
@@ -574,20 +574,6 @@ bool CNxTermFactory::nshlibInitialize(void)
   // Initialize the NSH library
 
   nsh_initialize();
-
-  // If the Telnet console is selected as a front-end, then start the
-  // Telnet daemon.
-
-#ifdef CONFIG_NSH_TELNET
-  int ret = nsh_telnetstart(AF_UNSPEC);
-  if (ret < 0)
-    {
-      // The daemon is NOT running!
-
-      return false;
-   }
-#endif
-
   return true;
 }
 
diff --git a/nshlib/nsh_init.c b/nshlib/nsh_init.c
index 2cf68035e..251e6c452 100644
--- a/nshlib/nsh_init.c
+++ b/nshlib/nsh_init.c
@@ -54,7 +54,7 @@ static const struct extmatch_vtable_s g_nsh_extmatch =
  * Description:
  *   This interface is used to initialize the NuttShell (NSH).
  *   nsh_initialize() should be called once during application start-up prior
- *   to executing either nsh_consolemain() or nsh_telnetstart().
+ *   to executing nsh_consolemain().
  *
  * Input Parameters:
  *   None
@@ -87,4 +87,16 @@ void nsh_initialize(void)
 
   boardctl(BOARDIOC_INIT, 0);
 #endif
+
+#if defined(CONFIG_NSH_TELNET) && !defined(CONFIG_NSH_DISABLE_TELNETSTART) && \
+  !defined(CONFIG_NETINIT_NETLOCAL)
+  /* If the Telnet console is selected as a front-end, then start the
+   * Telnet daemon UNLESS network initialization is deferred via
+   * CONFIG_NETINIT_NETLOCAL.  In that case, the telnet daemon must be
+   * started manually with the telnetd command after the network has
+   * been initialized
+   */
+
+  nsh_telnetstart(AF_UNSPEC);
+#endif
 }
diff --git a/system/nsh/nsh_main.c b/system/nsh/nsh_main.c
index 5db22980f..7212fccbe 100644
--- a/system/nsh/nsh_main.c
+++ b/system/nsh/nsh_main.c
@@ -127,27 +127,6 @@ int main(int argc, FAR char *argv[])
 
   nsh_initialize();
 
-#if defined(CONFIG_NSH_TELNET) && !defined(CONFIG_NSH_DISABLE_TELNETSTART) && \
-  !defined(CONFIG_NETINIT_NETLOCAL)
-  /* If the Telnet console is selected as a front-end, then start the
-   * Telnet daemon UNLESS network initialization is deferred via
-   * CONFIG_NETINIT_NETLOCAL.  In that case, the telnet daemon must be
-   * started manually with the telnetd command after the network has
-   * been initialized
-   */
-
-  ret = nsh_telnetstart(AF_UNSPEC);
-  if (ret < 0)
-    {
-      /* The daemon is NOT running.  Report the error then fail...
-       * either with the serial console up or just exiting.
-       */
-
-      fprintf(stderr, "ERROR: Failed to start TELNET daemon: %d\n", ret);
-      exitval = 1;
-    }
-#endif
-
 #ifdef CONFIG_NSH_CONSOLE
   /* If the serial console front end is selected, run it on this thread */
 


[incubator-nuttx-apps] 04/04: nshlib: Move symbol table initialization from nsh_main to nsh_initialize

Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 8e460e7e19747ff8cb148f7bde5492cd118f20fd
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Oct 15 17:53:09 2022 +0800

    nshlib: Move symbol table initialization from nsh_main to nsh_initialize
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 nshlib/nsh_init.c     | 44 ++++++++++++++++++++++++++++++++++++++++++++
 system/nsh/nsh_main.c | 49 -------------------------------------------------
 2 files changed, 44 insertions(+), 49 deletions(-)

diff --git a/nshlib/nsh_init.c b/nshlib/nsh_init.c
index fdd9a9208..c49bdfd34 100644
--- a/nshlib/nsh_init.c
+++ b/nshlib/nsh_init.c
@@ -25,6 +25,7 @@
 #include <nuttx/config.h>
 
 #include <sys/boardctl.h>
+#include <nuttx/symtab.h>
 
 #include "system/readline.h"
 #include "netutils/netinit.h"
@@ -33,6 +34,32 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Symbol table is not needed if loadable binary modules are not supported */
+
+#if !defined(CONFIG_LIBC_EXECFUNCS)
+#  undef CONFIG_SYSTEM_NSH_SYMTAB
+#endif
+
+/* boardctl() support is also required for application-space symbol table
+ * support.
+ */
+
+#if !defined(CONFIG_BOARDCTL) || !defined(CONFIG_BOARDCTL_APP_SYMTAB)
+#  undef CONFIG_SYSTEM_NSH_SYMTAB
+#endif
+
+/* If a symbol table is provided by board-specific logic, then we do not
+ * need to do anything from the application space.
+ */
+
+#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
+#  undef CONFIG_SYSTEM_NSH_SYMTAB
+#endif
+
 /****************************************************************************
  * Private Data
  ****************************************************************************/
@@ -46,6 +73,11 @@ static const struct extmatch_vtable_s g_nsh_extmatch =
 };
 #endif
 
+#if defined(CONFIG_SYSTEM_NSH_SYMTAB)
+extern const struct symtab_s CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME[];
+extern const int CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME;
+#endif
+
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -68,6 +100,9 @@ static const struct extmatch_vtable_s g_nsh_extmatch =
 
 void nsh_initialize(void)
 {
+#if defined (CONFIG_SYSTEM_NSH_SYMTAB)
+  struct boardioc_symtab_s symdesc;
+#endif
 #if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
   FAR struct console_stdio_s *pstate;
 #endif
@@ -94,6 +129,15 @@ void nsh_initialize(void)
   usbtrace_enable(TRACE_BITSET);
 #endif
 
+#if defined(CONFIG_SYSTEM_NSH_SYMTAB)
+  /* Make sure that we are using our symbol table */
+
+  symdesc.symtab   = (FAR struct symtab_s *)CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME; /* Discard 'const' */
+  symdesc.nsymbols = CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME;
+
+  boardctl(BOARDIOC_APP_SYMTAB, (uintptr_t)&symdesc);
+#endif
+
 #ifdef CONFIG_NSH_ARCHINIT
   /* Perform architecture-specific initialization (if configured) */
 
diff --git a/system/nsh/nsh_main.c b/system/nsh/nsh_main.c
index 44d93cb73..ebf27d46c 100644
--- a/system/nsh/nsh_main.c
+++ b/system/nsh/nsh_main.c
@@ -31,55 +31,18 @@
 #include <sched.h>
 #include <errno.h>
 
-#if defined(CONFIG_LIBC_EXECFUNCS)
-#  include <nuttx/symtab.h>
-#endif
-
 #include "nshlib/nshlib.h"
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* Symbol table is not needed if loadable binary modules are not supported */
-
-#if !defined(CONFIG_LIBC_EXECFUNCS)
-#  undef CONFIG_SYSTEM_NSH_SYMTAB
-#endif
-
-/* boardctl() support is also required for application-space symbol table
- * support.
- */
-
-#if !defined(CONFIG_BOARDCTL) || !defined(CONFIG_BOARDCTL_APP_SYMTAB)
-#  undef CONFIG_SYSTEM_NSH_SYMTAB
-#endif
-
-/* If a symbol table is provided by board-specific logic, then we do not
- * need to do anything from the application space.
- */
-
-#ifdef CONFIG_EXECFUNCS_HAVE_SYMTAB
-#  undef CONFIG_SYSTEM_NSH_SYMTAB
-#endif
-
 /* The NSH telnet console requires networking support (and TCP/IP) */
 
 #ifndef CONFIG_NET
 #  undef CONFIG_NSH_TELNET
 #endif
 
-/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-#if defined(CONFIG_SYSTEM_NSH_SYMTAB)
-
-extern const struct symtab_s CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME[];
-extern const int CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME;
-
-#endif
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
@@ -96,9 +59,6 @@ extern const int CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME;
 
 int main(int argc, FAR char *argv[])
 {
-#if defined (CONFIG_SYSTEM_NSH_SYMTAB)
-  struct boardioc_symtab_s symdesc;
-#endif
   struct sched_param param;
   int ret = 0;
 
@@ -113,15 +73,6 @@ int main(int argc, FAR char *argv[])
       sched_setparam(0, &param);
     }
 
-#if defined(CONFIG_SYSTEM_NSH_SYMTAB)
-  /* Make sure that we are using our symbol table */
-
-  symdesc.symtab   = (FAR struct symtab_s *)CONFIG_SYSTEM_NSH_SYMTAB_ARRAYNAME; /* Discard 'const' */
-  symdesc.nsymbols = CONFIG_SYSTEM_NSH_SYMTAB_COUNTNAME;
-
-  boardctl(BOARDIOC_APP_SYMTAB, (uintptr_t)&symdesc);
-#endif
-
   /* Initialize the NSH library */
 
   nsh_initialize();