From 8e460e7e19747ff8cb148f7bde5492cd118f20fd Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 15 Oct 2022 17:53:09 +0800 Subject: [PATCH] nshlib: Move symbol table initialization from nsh_main to nsh_initialize Signed-off-by: Xiang Xiao --- 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 #include +#include #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 #include -#if defined(CONFIG_LIBC_EXECFUNCS) -# include -#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, ¶m); } -#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();