NSH Documentation: A justification for 3 ENTERs when using USB serial console.

This commit is contained in:
Gregory Nutt 2017-06-13 17:39:38 -06:00
parent 72ff151343
commit 466fccc494

View File

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec"><i>NuttShell (NSH)</i></font></big></h1>
<p>Last Updated: June 6, 2017</p>
<p>Last Updated: June 13, 2017</p>
</td>
</tr>
</table>
@ -305,7 +305,7 @@
<tr>
<td><br></td>
<td>
<a href="#cmdmkfatfs">2.37 Create a FAT Filesystem (mkfatfs)</a>
<a href="#cmdmkfatfs">2.37 Create a FAT File System (mkfatfs)</a>
</td>
</tr>
<tr>
@ -335,7 +335,7 @@
<tr>
<td><br></td>
<td>
<a href="#cmdnfsmount">2.42 Mount an NFS file system (nfsmount)</a>
<a href="#cmdnfsmount">2.42 Mount an NFS File System (nfsmount)</a>
</td>
</tr>
<tr>
@ -619,9 +619,35 @@
NuttShell (NSH)
nsh&gt;
</pre></ul>
The greating may also include NuttX versioning information if you are using a versioned copy of NuttX.
The greeting may also include NuttX versioning information if you are using a versioned copy of NuttX.
<code>nsh&gt;</code> is the NSH prompt and indicates that you may enter a command from the console.
</p>
<p>
<a name="usbstartup"><b>USB console startup</b></a>.
When using a USB console, the start-up sequence differs a little: In this case, you are required to press <i>ENTER</i> three times. Then NSH prompt will appear as described above.
This is required for the following reasons:
</p>
<ol>
<li>
This assures that the USB connection is stable.
The USB connection may be made, broken, and re-established a few times if the USB cable is not yet fully seated.
Waiting for <i>ENTER</i> to be pressed three times assures that the connection is stable.
</li>
<li>
The establishment of the connection is two step process: First, the USB serial connection is made with the host PC. Then the application that uses the serial interface is started on the host.
When the serial connection is established on the host, the host operating system may send several <i>AT</i> modem commands to the host depending upon how the host serial port is configured.
By waiting for <i>ENTER</i> to be pressed three consecutive times, all of these modem commands will go to the bit-bucket and will not be interpreted as NSH command input.
</li>
<li>
Similarly, in the second step when the applications is started, there may be additional <i>AT</i> modem commands sent out the serial port.
Most serial terminal programs will do this unless they are specifically configured to suppress the modem command output.
Waiting for the <i>ENTER</i> input eliminates the invalid command errors from both (2) and (3).
</li>
<li>
Finally, if NSH did not wait for some positive indication that the serial terminal program is up and running, then the output of the NSH greeting and initial NSH prompt would be lost.
</li>
</ol>
<p>
<a name="cle"><b>Extended Command Line Editing</b></a>.
By default, NuttX uses a simple command line editor that allows command entry after the <code>nsh&gt;</code> and supports only the <i>backspace</i> key for editing.
@ -752,7 +778,7 @@ nsh&gt;
<td><code>&lt;file&gt;</code></td>
<td>
is the full or relative path to any writable object
in the filesystem name space (file or character driver).
in the file system name space (file or character driver).
Such objects will be referred to simply as files throughout
this document.
</td>
@ -968,7 +994,7 @@ done
<ul>
<li>
NSH will create a read-only RAM disk (a ROM disk), containing a tiny
ROMFS filesystem containing the following:
ROMFS file system containing the following:
<ul><pre>
`--init.d/
`-- rcS
@ -976,7 +1002,7 @@ done
Where rcS is the NSH start-up script.
</li>
<li>
NSH will then mount the ROMFS filesystem at <code>/etc</code>, resulting in:
NSH will then mount the ROMFS file system at <code>/etc</code>, resulting in:
<ul><pre>
|--dev/
| `-- ram0
@ -1352,7 +1378,7 @@ cp &lt;source-path&gt; &lt;dest-path&gt;
<p>
<b>Synopsis</b>.
Copy of the contents of the file at <code>&lt;source-path&gt;</code> to the location
in the filesystem indicated by <code>&lt;dest-path&gt;</code>.
in the file system indicated by <code>&lt;dest-path&gt;</code>.
</p>
<table width ="100%">
@ -1726,7 +1752,7 @@ ifconfig [nic_name [&lt;ip-address&gt;|dhcp]] [dr|gw|gateway &lt;dr-address&gt;]
<li>
<p>
With one or no arguments, <code>ifconfig</code> will shows the
current configuration of the network and, perhaps, the status of ethernet
current configuration of the network and, perhaps, the status of Ethernet
device:
</p>
<ul><pre>
@ -1749,7 +1775,7 @@ eth0 HWaddr 00:18:11:80:10:06
<li>
<p>
If both the network interface name and an IP address are supplied as arguments,
then <code>ifconfig</code> will set the address of the ethernet device:
then <code>ifconfig</code> will set the address of the Ethernet device:
</p>
<ul><pre>
ifconfig nic_name ip_address
@ -1970,7 +1996,7 @@ ln [-s] &lt;target&gt; &lt;link&gt;
This implementation is simplified for use with NuttX in these ways:
</p>
<ul>
<li>Links may be created only within the NuttX top-level, <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> filesystem</a>.
<li>Links may be created only within the NuttX top-level, <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> file system</a>.
No file system currently supported by NuttX provides symbolic links.</li>
<li>For the same reason, only soft links are implemented.</li>
<li>File privileges are ignored.</li>
@ -1992,7 +2018,7 @@ ls [-lRs] &lt;dir-path&gt;
<p>
<b>Synopsis</b>.
Show the contents of the directory at <code>&lt;dir-path&gt;</code>. NOTE:
<code>&lt;dir-path&gt;</code> must refer to a directory and no other filesystem
<code>&lt;dir-path&gt;</code> must refer to a directory and no other file system
object.
</p>
<p><b>Options:</b></p>
@ -2172,10 +2198,10 @@ mkdir &lt;path&gt;
</p>
<p>
<b>Limited to Mounted File Systems</b>.
Recall that NuttX uses a <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> filesystem</a> for its root file
Recall that NuttX uses a <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> file system</a> for its root file
system.
The <code>mkdir</code> command can only be used to create directories in volumes set up with the
<a href="#cmdmount"><code>mount</code></a> command; it cannot be used to create directories in the <i>pseudo</i> filesystem.
<a href="#cmdmount"><code>mount</code></a> command; it cannot be used to create directories in the <i>pseudo</i> file system.
</p>
<p><b>Example:</b></p>
<ul><pre>
@ -2190,7 +2216,7 @@ nsh&gt;
<table width ="100%">
<tr bgcolor="#e4e4e4">
<td>
<a name="cmdmkfatfs"><h2>2.37 Create a FAT Filesystem (mkfatfs)</h2></a>
<a name="cmdmkfatfs"><h2>2.37 Create a FAT File System (mkfatfs)</h2></a>
</td>
</tr>
</table>
@ -2208,7 +2234,7 @@ mkfatfs [-F &lt;fatsize&gt;] &lt;block-driver&gt;
</p>
<p>
NSH provides this command to access the <a href="mkfatfs"><code>mkfatfs()</code></a> NuttX API.
This block device must reside in the NuttX <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> filesystem</a> and
This block device must reside in the NuttX <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> file system</a> and
must have been created by some call to <code>register_blockdriver()</code> (see <code>include/nuttx/fs/fs.h</code>).
</p>
@ -2323,22 +2349,22 @@ mount -t &lt;fstype&gt; [-o &lt;options&gt;] &lt;block-device&gt; <code>&lt;dir-
<code>mount</code> performs a three way association, binding:
</p>
<ol>
<li><b>File system.</b>
<li><b>File System.</b>
The '-t <code>&lt;fstype&gt;</code>' option identifies the type of
file system that has been formatted on the <code>&lt;block-device&gt;</code>.
As of this writing, <code>vfat</code> is the only supported value for <code>&lt;fstype&gt;</code>
</li>
<li><b>Block Device.</b>
The <code>&lt;block-device&gt;</code> argument is the full or relative
path to a block driver inode in the <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> filesystem</a>.
path to a block driver inode in the <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> file system</a>.
By convention, this is a name under the <code>/dev</code> sub-directory.
This <code>&lt;block-device&gt;</code> must have been previously formatted with the same file system
type as specified by <code>&lt;fstype&gt;</code>
</li>
<li><b>Mount Point.</b>
The mount point, <code>&lt;dir-path&gt;</code>, is the location in the
<a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> filesystem</a> where the mounted volume will appear.
This mount point can only reside in the NuttX <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> filesystem</a>.
<a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> file system</a> where the mounted volume will appear.
This mount point can only reside in the NuttX <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> file system</a>.
By convention, this mount point is a subdirectory under <code>/mnt</code>.
The mount command will create whatever pseudo directories that may be needed to complete the
full path but the full path must not already exist.
@ -2346,7 +2372,7 @@ mount -t &lt;fstype&gt; [-o &lt;options&gt;] &lt;block-device&gt; <code>&lt;dir-
</ol>
<p>
After the volume has been mounted in the NuttX
<a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> filesystem</a>,
<a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> file system</a>,
it may be access in the same way as other objects in the file system.
</p>
<p><b>Examples</b>:</p>
@ -2395,7 +2421,7 @@ mv &lt;old-path&gt; &lt;new-path&gt;
<p>
<b>Synopsis</b>.
Rename the file object at <code>&lt;old-path&gt;</code> to <code>&lt;new-path&gt;</code>.
Both paths must reside in the same mounted filesystem.
Both paths must reside in the same mounted file system.
</p>
<table width ="100%">
@ -2628,11 +2654,11 @@ rm &lt;file-path&gt;
<p>
<b>Synopsis</b>.
Remove the specified <code>&lt;file-path&gt;</code> name from the mounted file system.
Recall that NuttX uses a <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> filesystem</a> for its root file
Recall that NuttX uses a <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> file system</a> for its root file
system.
The <code>rm</code> command can only be used to remove (unlink) files in volumes set up with the
<a href="#cmdmount"><code>mount</code></a> command;
it cannot be used to remove names in the <i>pseudo</i> filesystem.
it cannot be used to remove names in the <i>pseudo</i> file system.
</p>
<p><b>Example:</b></p>
<ul><pre>
@ -2662,11 +2688,11 @@ rmdir &lt;dir-path&gt;
<p>
<b>Synopsis</b>.
Remove the specified <code>&lt;dir-path&gt;</code> directory from the mounted file system.
Recall that NuttX uses a <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> filesystem</a> for its root file
Recall that NuttX uses a <a href="NuttxUserGuide.html#FileSystemOverview"><i>pseudo</i> file system</a> for its root file
system.
The <code>rmdir</code> command can only be used to remove directories from volumes set up with the
<a href="#cmdmount"><code>mount</code></a> command;
it cannot be used to remove directories from the <i>pseudo</i> filesystem.
it cannot be used to remove directories from the <i>pseudo</i> file system.
</p>
<p><b>Example:</b></p>
<ul><pre>
@ -3563,11 +3589,11 @@ nsh&gt;
creation of files for the correct operation of the <code>put</code> command.</small><br>
<sup>3</sup><small>
<code>CONFIG_FS_READABLE</code> is not a user configuration but is set automatically
if any readable filesystem is selected. At present, this is either <code>CONFIG_FS_FAT</code>
if any readable file system is selected. At present, this is either <code>CONFIG_FS_FAT</code>
or <code>CONFIG_FS_ROMFS</code>.</small><br>
<sup>4</sup><small>
<code>CONFIG_FS_WRITABLE</code> is not a user configuration but is set automatically
if any writable filesystem is selected. At present, this is only <code>CONFIG_FS_FAT</code>.</small><br>
if any writable file system is selected. At present, this is only <code>CONFIG_FS_FAT</code>.</small><br>
<sup>5</sup><small>
Verbose help output can be suppressed by defining <code>CONFIG_NSH_HELP_TERSE</code>.
In that case, the help command is still available but will be slightly smaller.
@ -3625,7 +3651,7 @@ nsh&gt;
<td valign="top"><b><code>CONFIG_NSH_FILEIOSIZE</code></b></td>
<td>
Size of a static I/O buffer used for file access (ignored if
there is no filesystem). Default is 1024.
there is no file system). Default is 1024.
</td>
</tr>
<tr>
@ -3698,7 +3724,7 @@ set FOOBAR ABC_${FOO}_${BAR}
<td valign="top"><b><code>CONFIG_NSH_NESTDEPTH</code></b></td>
<td>
The maximum number of nested <a href="#conditional"><code>if-then[-else]-fi</code></a> sequences that
are permissable. Default: 3
are permissible. Default: 3
</td>
</tr>
<tr>
@ -3746,7 +3772,7 @@ set FOOBAR ABC_${FOO}_${BAR}
<tr>
<td valign="top"><b><code>CONFIG_NSH_ROMFSETC</code></b></td>
<td>
Mount a ROMFS filesystem at <code>/etc</code> and provide a startup script
Mount a ROMFS file system at <code>/etc</code> and provide a startup script
at <code>/etc/init.d/rcS</code>. The default startup script will mount
a FAT FS RAMDISK at <code>/tmp</code> but the logic is
<a href="#startupscript">easily extensible</a>.
@ -3975,7 +4001,7 @@ set FOOBAR ABC_${FOO}_${BAR}
<tr>
<td valign="top"><b><code>CONFIG_NSH_NOMAC</code></b></td>
<td>
Set if your ethernet hardware has no built-in MAC address.
Set if your Ethernet hardware has no built-in MAC address.
If set, a bogus MAC will be assigned.
</td>
</tr>
@ -4248,7 +4274,7 @@ mount -t vfat /dev/ram1 /tmp
</p>
<li>
<p>
Mount the FAT filesystem at a configured mountpoint, <code>/tmp</code>.
Mount the FAT file system at a configured mountpoint, <code>/tmp</code>.
</p>
</ul>
<p>
@ -4666,7 +4692,7 @@ CONFIG_SCHED_WAITPID=y
<p>
You replace the sample code at <code>apps/examples/nsh/nsh_main.c</code> with whatever start-up logic that you want.
NSH is a library at <code>apps/nshlib</code>.
<code>apps.examplex/nsh</code> is just a tiny, example start-up function (<code>CONFIG_USER_ENTRYPOINT</code>()) that that runs immediately and illustrates how to start NSH
<code>apps.examples/nsh</code> is just a tiny, example start-up function (<code>CONFIG_USER_ENTRYPOINT</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>CONFIG_USER_ENTRYPOINT</code>() function and then start other tasks from your custom <code>CONFIG_USER_ENTRYPOINT</code>().
</p>
<li>
@ -4723,7 +4749,7 @@ CONFIG_SCHED_WAITPID=y
<ul>
<li>
<p>
NSH will create a read-only RAM disk (a ROM disk), containing a tiny ROMFS filesystem containing the following:
NSH will create a read-only RAM disk (a ROM disk), containing a tiny ROMFS file system containing the following:
</p>
<ul><pre>
`--init.d/
@ -4734,7 +4760,7 @@ CONFIG_SCHED_WAITPID=y
</p>
<li>
<p>
NSH will then mount the ROMFS filesystem at <code>/etc</code>, resulting in:
NSH will then mount the ROMFS file system at <code>/etc</code>, resulting in:
</p>
<ul><pre>
|--dev/
@ -4841,7 +4867,7 @@ mount -t vfat /dev/ram1 /tmp
</p>
<p>
To generate a custom <code>rcS</code> file a copy of <code>rcS.template</code> needs to be placed at <code>tools/</code> and changed according to the desired start-up behaviour.
Running <code>tools/mkromfsimg.h</code> creates <code>nsh_romfsimg.h</code> which needs to be copied to <code>apps/nhslib</code> OR if <code>CONFIG_NSH_ARCHROMFS</code> is defined to <code>configs/&lt;board&gt;/include</code>.
Running <code>tools/mkromfsimg.h</code> creates <code>nsh_romfsimg.h</code> which needs to be copied to <code>apps/nshlib</code> OR if <code>CONFIG_NSH_ARCHROMFS</code> is defined to <code>configs/&lt;board&gt;/include</code>.
</p>
</ol>
@ -5343,10 +5369,10 @@ xxd -i romfs_img >nsh_romfsimg.h
<li><a href="#cmdmkrd"><code>mkrd</code></a></li>
<li><a href="#custinit"><code>mkromfsimg.sh</code></a></li>
<li><a href="#cmdmount"><code>mount</code></a></li>
<li><a href="#cmdmv"><code>mv</code></a></li>
</ul></td>
<td width="34%" valign="top">
<ul>
<li><a href="#cmdmv"><code>mv</code></a></li>
<li><a href="#cmdnfsmount"><code>nfsmount</code></a></li>
<li><a href="#cmdoverview"><code>nice</code></a></li>
<li><a href="#custonshlib">NSH library (<code>nshlib</code>)</a></li>
@ -5403,6 +5429,7 @@ xxd -i romfs_img >nsh_romfsimg.h
<li><a href="#custonshlib"><code>up_cxxinitialize()</code></a></li>
<li><a href="#cmdurldec"><code>urldecode</code></a></li>
<li><a href="#cmdurlencode"><code>urlencode</code></a></li>
<li><a href="#usbstartup">USB console startup</a></li>
<li><a href="#cmduseradd"><code>useradd</code></a></li>
<li><a href="#cmduserdel"><code>userdel</code></a></li>
<li><a href="#cmdusleep"><code>usleep</code></a></li>