2012-02-05 18:36:13 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* apps/nshlib/nsh_init.c
|
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* 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
|
2012-02-05 18:36:13 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-02-05 18:36:13 +01:00
|
|
|
*
|
2021-06-10 16:34:12 +02:00
|
|
|
* 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.
|
2012-02-05 18:36:13 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2015-03-31 20:14:16 +02:00
|
|
|
#include <sys/boardctl.h>
|
2022-10-15 11:53:09 +02:00
|
|
|
#include <nuttx/symtab.h>
|
2015-07-30 20:11:58 +02:00
|
|
|
|
2016-07-11 18:11:18 +02:00
|
|
|
#include "system/readline.h"
|
|
|
|
#include "nshlib/nshlib.h"
|
2014-01-14 20:30:22 +01:00
|
|
|
|
2012-02-05 18:36:13 +01:00
|
|
|
#include "nsh.h"
|
2022-10-15 11:31:04 +02:00
|
|
|
#include "nsh_console.h"
|
2012-02-05 18:36:13 +01:00
|
|
|
|
2023-03-08 14:57:31 +01:00
|
|
|
#ifdef CONFIG_NSH_NETINIT
|
|
|
|
# include "netutils/netinit.h"
|
|
|
|
#endif
|
|
|
|
|
2022-10-15 11:53:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Symbol table is not needed if loadable binary modules are not supported */
|
|
|
|
|
|
|
|
#if !defined(CONFIG_LIBC_EXECFUNCS)
|
2022-10-15 12:19:09 +02:00
|
|
|
# undef CONFIG_NSH_SYMTAB
|
2022-10-15 11:53:09 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* boardctl() support is also required for application-space symbol table
|
|
|
|
* support.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(CONFIG_BOARDCTL) || !defined(CONFIG_BOARDCTL_APP_SYMTAB)
|
2022-10-15 12:19:09 +02:00
|
|
|
# undef CONFIG_NSH_SYMTAB
|
2022-10-15 11:53:09 +02:00
|
|
|
#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
|
2022-10-15 12:19:09 +02:00
|
|
|
# undef CONFIG_NSH_SYMTAB
|
2022-10-15 11:53:09 +02:00
|
|
|
#endif
|
|
|
|
|
2012-02-05 18:36:13 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-07-30 20:11:58 +02:00
|
|
|
#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION) && \
|
|
|
|
defined(CONFIG_READLINE_HAVE_EXTMATCH)
|
|
|
|
static const struct extmatch_vtable_s g_nsh_extmatch =
|
|
|
|
{
|
|
|
|
nsh_extmatch_count, /* count_matches */
|
|
|
|
nsh_extmatch_getname /* getname */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2022-10-15 12:19:09 +02:00
|
|
|
#if defined(CONFIG_NSH_SYMTAB)
|
|
|
|
extern const struct symtab_s CONFIG_NSH_SYMTAB_ARRAYNAME[];
|
|
|
|
extern const int CONFIG_NSH_SYMTAB_COUNTNAME;
|
2022-10-15 11:53:09 +02:00
|
|
|
#endif
|
|
|
|
|
2012-02-05 18:36:13 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nsh_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2021-08-26 14:36:43 +02:00
|
|
|
* This interface is used to initialize the NuttShell (NSH).
|
|
|
|
* nsh_initialize() should be called once during application start-up prior
|
2022-10-15 11:00:22 +02:00
|
|
|
* to executing nsh_consolemain().
|
2012-02-05 18:36:13 +01:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2015-04-07 20:18:08 +02:00
|
|
|
|
2012-02-05 18:36:13 +01:00
|
|
|
void nsh_initialize(void)
|
|
|
|
{
|
2022-10-15 12:19:09 +02:00
|
|
|
#if defined (CONFIG_NSH_SYMTAB)
|
2022-10-15 11:53:09 +02:00
|
|
|
struct boardioc_symtab_s symdesc;
|
|
|
|
#endif
|
2023-11-26 05:10:46 +01:00
|
|
|
#if defined(CONFIG_ETC_ROMFS) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
2022-10-15 11:31:04 +02:00
|
|
|
FAR struct console_stdio_s *pstate;
|
|
|
|
#endif
|
|
|
|
|
2015-11-01 09:41:01 +01:00
|
|
|
#if defined(CONFIG_NSH_READLINE) && defined(CONFIG_READLINE_TABCOMPLETION)
|
|
|
|
/* Configure the NSH prompt */
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
readline_prompt(g_nshprompt);
|
2015-11-01 09:41:01 +01:00
|
|
|
|
2022-10-15 11:31:04 +02:00
|
|
|
# ifdef CONFIG_READLINE_HAVE_EXTMATCH
|
2015-11-01 09:41:01 +01:00
|
|
|
/* Set up for tab completion on NSH commands */
|
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
readline_extmatch(&g_nsh_extmatch);
|
2022-10-15 11:31:04 +02:00
|
|
|
# endif
|
2015-11-01 09:41:01 +01:00
|
|
|
#endif
|
|
|
|
|
2022-10-15 11:31:04 +02:00
|
|
|
#ifdef CONFIG_NSH_USBDEV_TRACE
|
|
|
|
/* Initialize any USB tracing options that were requested */
|
|
|
|
|
|
|
|
usbtrace_enable(TRACE_BITSET);
|
|
|
|
#endif
|
|
|
|
|
2022-10-15 12:19:09 +02:00
|
|
|
#if defined(CONFIG_NSH_SYMTAB)
|
2022-10-15 11:53:09 +02:00
|
|
|
/* Make sure that we are using our symbol table */
|
|
|
|
|
2023-07-02 18:23:55 +02:00
|
|
|
symdesc.symtab = CONFIG_NSH_SYMTAB_ARRAYNAME;
|
2022-10-15 12:19:09 +02:00
|
|
|
symdesc.nsymbols = CONFIG_NSH_SYMTAB_COUNTNAME;
|
2022-10-15 11:53:09 +02:00
|
|
|
|
|
|
|
boardctl(BOARDIOC_APP_SYMTAB, (uintptr_t)&symdesc);
|
|
|
|
#endif
|
|
|
|
|
2015-03-31 20:14:16 +02:00
|
|
|
#ifdef CONFIG_NSH_ARCHINIT
|
|
|
|
/* Perform architecture-specific initialization (if configured) */
|
2012-02-05 18:36:13 +01:00
|
|
|
|
2020-01-02 13:09:50 +01:00
|
|
|
boardctl(BOARDIOC_INIT, 0);
|
2015-03-31 20:14:16 +02:00
|
|
|
#endif
|
2022-10-15 11:00:22 +02:00
|
|
|
|
2023-11-26 05:10:46 +01:00
|
|
|
#if defined(CONFIG_ETC_ROMFS) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
2022-10-15 11:31:04 +02:00
|
|
|
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
|
|
|
|
|
2023-11-26 05:10:46 +01:00
|
|
|
#if defined(CONFIG_ETC_ROMFS) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
2022-10-15 11:31:04 +02:00
|
|
|
/* Execute the start-up script */
|
|
|
|
|
|
|
|
nsh_initscript(&pstate->cn_vtbl);
|
|
|
|
nsh_release(&pstate->cn_vtbl);
|
|
|
|
#endif
|
|
|
|
|
2022-10-15 11:00:22 +02:00
|
|
|
#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
|
2012-02-05 18:36:13 +01:00
|
|
|
}
|