blob: c0c4acdbf952c7b241fa28621a3c7ef695ea27f4 [file] [log] [blame]
<!--
Documentation/_templates/layout.html
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.
-->
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Customizing NSH Initialization &mdash; NuttX latest documentation</title>
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="../../_static/tabs.css" type="text/css" />
<link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
<!--[if lt IE 9]>
<script src="../../_static/js/html5shiv.min.js"></script>
<![endif]-->
<script src="../../_static/jquery.js"></script>
<script src="../../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
<script src="../../_static/doctools.js"></script>
<script src="../../_static/sphinx_highlight.js"></script>
<script src="../../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../../genindex.html" />
<link rel="search" title="Search" href="../../search.html" />
<link rel="next" title="Shell Login" href="login.html" />
<link rel="prev" title="NSH “Built-In” Applications" href="builtin.html" />
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >
<a href="../../index.html" class="icon icon-home"> NuttX
</a>
<!-- this version selector is quite ugly, should be probably replaced by something
more modern -->
<div class="version-selector">
<select onchange="javascript:location.href = this.value;">
<option value="../../../latest" selected="selected">latest</option>
<option value="../../../10.0.0" >10.0.0</option>
<option value="../../../10.0.1" >10.0.1</option>
<option value="../../../10.1.0" >10.1.0</option>
<option value="../../../10.2.0" >10.2.0</option>
<option value="../../../10.3.0" >10.3.0</option>
<option value="../../../11.0.0" >11.0.0</option>
<option value="../../../12.0.0" >12.0.0</option>
<option value="../../../12.1.0" >12.1.0</option>
<option value="../../../12.2.0" >12.2.0</option>
<option value="../../../12.2.1" >12.2.1</option>
<option value="../../../12.3.0" >12.3.0</option>
<option value="../../../12.4.0" >12.4.0</option>
<option value="../../../12.5.0" >12.5.0</option>
<option value="../../../12.5.1" >12.5.1</option>
</select>
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Table of Contents</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../introduction/index.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../quickstart/index.html">Getting Started</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../contributing/index.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../introduction/inviolables.html">The Inviolable Principles of NuttX</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../platforms/index.html">Supported Platforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../components/index.html">OS Components</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../index.html">Applications</a><ul class="current">
<li class="toctree-l2 current"><a class="reference internal" href="index.html">NuttShell (NSH)</a><ul class="current">
<li class="toctree-l3"><a class="reference internal" href="nsh.html">Overview</a></li>
<li class="toctree-l3"><a class="reference internal" href="commands.html">Commands</a></li>
<li class="toctree-l3"><a class="reference internal" href="config.html">Configuration Settings</a></li>
<li class="toctree-l3"><a class="reference internal" href="customizing.html">Customizing the NuttShell</a></li>
<li class="toctree-l3"><a class="reference internal" href="builtin.html">NSH “Built-In” Applications</a></li>
<li class="toctree-l3 current"><a class="current reference internal" href="#">Customizing NSH Initialization</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#nuttshell-start-up-scripts">NuttShell Start up Scripts</a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="login.html">Shell Login</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../../reference/index.html">API Reference</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../faq/index.html">FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../guides/index.html">Guides</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">NuttX</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="../index.html">Applications</a></li>
<li class="breadcrumb-item"><a href="index.html">NuttShell (NSH)</a></li>
<li class="breadcrumb-item active">Customizing NSH Initialization</li>
<li class="wy-breadcrumbs-aside">
<a href="../../_sources/applications/nsh/installation.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="customizing-nsh-initialization">
<h1>Customizing NSH Initialization<a class="headerlink" href="#customizing-nsh-initialization" title="Permalink to this heading"></a></h1>
<p><strong>Ways to Customize NSH Initialization</strong>. There are three ways to
customize the NSH start-up behavior. Here they are presented in order of
increasing difficulty:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>You can extend the initialization logic in
<code class="docutils literal notranslate"><span class="pre">boards/arm/stm32/stm3240g-eval/src/stm32_appinit.c</span></code>. The logic
there is called each time that NSH is started and is good place in
particular for any device-related initialization.</p></li>
<li><p>You replace the sample code at <code class="docutils literal notranslate"><span class="pre">apps/examples/nsh/nsh_main.c</span></code> with
whatever start-up logic that you want. NSH is a library at
<code class="docutils literal notranslate"><span class="pre">apps/nshlib</span></code>. <code class="docutils literal notranslate"><span class="pre">apps.examples/nsh</span></code> is just a tiny, example
start-up function (<code class="docutils literal notranslate"><span class="pre">CONFIG_USER_ENTRYPOINT</span></code>()) that that runs
immediately and illustrates how to start NSH If you want something
else to run immediately then you can write your write your own custom
<code class="docutils literal notranslate"><span class="pre">CONFIG_USER_ENTRYPOINT</span></code>() function and then start other tasks
from your custom <code class="docutils literal notranslate"><span class="pre">CONFIG_USER_ENTRYPOINT</span></code>().</p></li>
<li><p>NSH also supports a start-up script that executed when NSH first
runs. This mechanism has the advantage that the start-up script can
contain any NSH commands and so can do a lot of work with very little
coding. The disadvantage is that is is considerably more complex to
create the start-up script. It is sufficiently complex that is
deserves its own paragraph</p></li>
</ol>
</div></blockquote>
<section id="nuttshell-start-up-scripts">
<h2>NuttShell Start up Scripts<a class="headerlink" href="#nuttshell-start-up-scripts" title="Permalink to this heading"></a></h2>
<p>First of all you should look at <a class="reference external" href="#startupscript">NSH Start-Up Script</a>
paragraph. Most everything you need to know can be found there. That
information will be repeated and extended here for completeness.</p>
<p><strong>NSH Start-Up Script</strong>. NSH supports options to provide a start up
script for NSH. The start-up script contains any command support by NSH
(i.e., that you see when you enter ‘nsh&gt; help’). In general this
capability is enabled with <code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ROMFSETC=y</span></code>, but has several
other related configuration options as described with the <a class="reference external" href="#nshconfiguration">NSH-specific
configuration settings</a> paragraph. This capability
also depends on:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">CONFIG_DISABLE_MOUNTPOINT=n</span></code>. If mount point support is disabled,
then you cannot mount <em>any</em> file systems.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">CONFIG_FS_ROMFS</span></code> enabled. This option enables ROMFS file system
support.</p></li>
</ul>
</div></blockquote>
<p><strong>Default Start-Up Behavior</strong>. The implementation that is provided is
intended to provide great flexibility for the use of Start-Up files.
This paragraph will discuss the general behavior when all of the
configuration options are set to the default values.</p>
<p>In this default case, enabling <code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ROMFSETC</span></code> will cause NSH to
behave as follows at NSH start-up time:</p>
<blockquote>
<div><ul>
<li><p>NSH will create a read-only RAM disk (a ROM disk), containing a tiny
ROMFS file system containing the following:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>`--init.d/
`-- rcS
</pre></div>
</div>
<p>Where <code class="docutils literal notranslate"><span class="pre">rcS</span></code> is the NSH start-up script.</p>
</li>
<li><p>NSH will then mount the ROMFS file system at <code class="docutils literal notranslate"><span class="pre">/etc</span></code>, resulting in:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>|--dev/
| `-- ram0
`--etc/
`--init.d/
`-- rcS
</pre></div>
</div>
</li>
<li><p>By default, the contents of <code class="docutils literal notranslate"><span class="pre">rcS</span></code> script are:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span># Create a RAMDISK and mount it at /tmp
mkrd -m 1 -s 512 1024
mkfatfs /dev/ram1
mount -t vfat /dev/ram1 /tmp
</pre></div>
</div>
</li>
<li><p>NSH will execute the script at <code class="docutils literal notranslate"><span class="pre">/etc/init.d/rcS</span></code> at start-up
(before the first NSH prompt). After execution of the script, the
root FS will look like:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>|--dev/
| |-- ram0
| `-- ram1
|--etc/
| `--init.d/
| `-- rcS
`--tmp/
</pre></div>
</div>
</li>
</ul>
</div></blockquote>
<p><strong>Example Configurations</strong>. Here are some configurations that have
<code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ROMFSETC=y</span></code> in the NuttX configuration file. They might
provide useful examples:</p>
<blockquote>
<div><ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">boards/arm/stm32/hymini-stm32v/nsh2</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">boards/arm/dm320/ntosd-dm320/nsh</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">boards/sim/sim/sim/nsh</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">boards/sim/sim/sim/nsh2</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">boards/sim/sim/sim/nx</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">boards/sim/sim/sim/nx11</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">boards/sim/sim/sim/touchscreen</span></code></p></li>
</ul>
</div></blockquote>
<p>In most of these cases, the configuration sets up the <em>default</em>
<code class="docutils literal notranslate"><span class="pre">/etc/init.d/rcS</span></code> script. The default script is here:
<code class="docutils literal notranslate"><span class="pre">apps/nshlib/rcS.template</span></code>. (The funny values in the template like
<code class="docutils literal notranslate"><span class="pre">XXXMKRDMINORXXX</span></code> get replaced via <code class="docutils literal notranslate"><span class="pre">sed</span></code> at build time). This
default configuration creates a ramdisk and mounts it at <code class="docutils literal notranslate"><span class="pre">/tmp</span></code> as
discussed above.</p>
<p>If that default behavior is not what you want, then you can provide your
own custom <code class="docutils literal notranslate"><span class="pre">rcS</span></code> script by defining <code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARCHROMFS=y</span></code> in the
configuration file.</p>
<p><strong>Modifying the ROMFS Image</strong>. The contents of the <code class="docutils literal notranslate"><span class="pre">/etc</span></code> directory
are retained in the file <code class="docutils literal notranslate"><span class="pre">apps/nshlib/nsh_romfsimg.h</span></code> OR, if
<code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARCHROMFS</span></code> is defined,
<code class="docutils literal notranslate"><span class="pre">include/arch/board/nsh_romfsimg.h</span></code>. In order to modify the start-up
behavior, there are three things to study:</p>
<blockquote>
<div><ol class="arabic">
<li><p><strong>Configuration Options.</strong> The additional <code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ROMFSETC</span></code>
configuration options discussed with the other <a class="reference external" href="#nshconfiguration">NSH-specific
configuration settings</a>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">tools/mkromfsimg.sh</span></code> <strong>Script</strong>. The script
<code class="docutils literal notranslate"><span class="pre">tools/mkromfsimg.sh</span></code> creates <code class="docutils literal notranslate"><span class="pre">nsh_romfsimg.h</span></code>. It is not
automatically executed. If you want to change the configuration
settings associated with creating and mounting the <code class="docutils literal notranslate"><span class="pre">/tmp</span></code>
directory, then it will be necessary to re-generate this header file
using the <code class="docutils literal notranslate"><span class="pre">tools/mkromfsimg.sh</span></code> script.</p>
<p>The behavior of this script depends upon several things:</p>
<ol class="arabic simple">
<li><p>The configuration settings then installed configuration.</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">genromfs</span></code> tool(available from
<a class="reference external" href="http://romfs.sourceforge.net/">http://romfs.sourceforge.net</a>)
or included within the NuttX buildroot toolchain. There is also a
snapshot available in the NuttX tools repository
<a class="reference external" href="https://bitbucket.org/nuttx/tools/src/master/genromfs-0.5.2.tar.gz">here</a>.</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">xxd</span></code> tool that is used to generate the C header files (xxd
is a normal part of a complete Linux or Cygwin installation,
usually as part of the <code class="docutils literal notranslate"><span class="pre">vi</span></code> package).</p></li>
<li><p>The file <code class="docutils literal notranslate"><span class="pre">apps/nshlib/rcS.template</span></code> (OR, if
<code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARCHROMFS</span></code> is defined
<code class="docutils literal notranslate"><span class="pre">include/arch/board/rcs.template</span></code>.</p></li>
</ol>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">rcS.template</span></code>. The file <code class="docutils literal notranslate"><span class="pre">apps/nshlib/rcS.template</span></code> contains the
general form of the <code class="docutils literal notranslate"><span class="pre">rcS</span></code> file; configured values are plugged into
this template file to produce the final <code class="docutils literal notranslate"><span class="pre">rcS</span></code> file.</p>
<p>To generate a custom <code class="docutils literal notranslate"><span class="pre">rcS</span></code> file a copy of <code class="docutils literal notranslate"><span class="pre">rcS.template</span></code> needs to
be placed at <code class="docutils literal notranslate"><span class="pre">tools/</span></code> and changed according to the desired start-up
behaviour. Running <code class="docutils literal notranslate"><span class="pre">tools/mkromfsimg.h</span></code> creates <code class="docutils literal notranslate"><span class="pre">nsh_romfsimg.h</span></code>
which needs to be copied to <code class="docutils literal notranslate"><span class="pre">apps/nshlib</span></code> OR if
<code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARCHROMFS</span></code> is defined to
<code class="docutils literal notranslate"><span class="pre">boards/&lt;arch&gt;/&lt;chip&gt;/&lt;board&gt;/include</span></code>.</p>
</li>
</ol>
</div></blockquote>
<p><code class="docutils literal notranslate"><span class="pre">rcS.template</span></code>. The default <code class="docutils literal notranslate"><span class="pre">rcS.template</span></code>,
<code class="docutils literal notranslate"><span class="pre">apps/nshlib/rcS.template</span></code>, generates the standard, default
<code class="docutils literal notranslate"><span class="pre">apps/nshlib/nsh_romfsimg.h</span></code> file.</p>
<p>If <code class="docutils literal notranslate"><span class="pre">CONFIG_NSH_ARCHROMFS</span></code> is defined in the NuttX configuration file,
then a custom, board-specific <code class="docutils literal notranslate"><span class="pre">nsh_romfsimg.h</span></code> file residing in
<code class="docutils literal notranslate"><span class="pre">boards/&lt;arch&gt;/&lt;chip&gt;/&lt;board&gt;/include</span></code>will be used. NOTE when the OS
is configured, <code class="docutils literal notranslate"><span class="pre">include/arch/board</span></code> will be linked to
<code class="docutils literal notranslate"><span class="pre">boards/&lt;arch&gt;/&lt;chip&gt;/&lt;board&gt;/include</span></code>.</p>
<p>All of the startup-behavior is contained in <code class="docutils literal notranslate"><span class="pre">rcS.template</span></code>. The role
of <code class="docutils literal notranslate"><span class="pre">mkromfsimg.sh</span></code> script is to (1) apply the specific configuration
settings to <code class="docutils literal notranslate"><span class="pre">rcS.template</span></code> to create the final <code class="docutils literal notranslate"><span class="pre">rcS</span></code>, and (2) to
generate the header file <code class="docutils literal notranslate"><span class="pre">nsh_romfsimg.h</span></code> containing the ROMFS file
system image. To do this, <code class="docutils literal notranslate"><span class="pre">mkromfsimg.sh</span></code> uses two tools that must be
installed in your system:</p>
<blockquote>
<div><ol class="arabic simple">
<li><p>The <code class="docutils literal notranslate"><span class="pre">genromfs</span></code> tool that is used to generate the ROMFS file system
image.</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">xxd</span></code> tool that is used to create the C header file.</p></li>
</ol>
</div></blockquote>
</section>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="builtin.html" class="btn btn-neutral float-left" title="NSH “Built-In” Applications" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="login.html" class="btn btn-neutral float-right" title="Shell Login" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright 2020, The Apache Software Foundation.</p>
</div>
</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>