boards/sim: support rc.sysinit

Follow: http://glennastory.net/boot/sysinit.html

This is first script that init runs is rc.sysinit. This
script does serval initialization tasks about basic service.

The boot sequence currently provided to the board level is:
board_earlyinitialize->
    board_lateinitialize(Peripherals driver, core driver, ...)->
	run rcS script(mount fs, run service) ->
	    board_appinitialize->

After this patch:
The boot sequence currently provided to the board level is:
board_earlyinitialize->
    board_lateinitialize(core driver,...)->
	run rc.sysinit script(mount fs, run core service) ->
	    board_appinitialize(Peripherals driver)->
		run rcS script(run other service)->

So, Peripheral drivers can do more with the file system and
core services.

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-04-15 21:56:00 +08:00 committed by Petro Karashchenko
parent c29a3b7bd8
commit de1c184e6c
23 changed files with 314 additions and 138 deletions

View File

@ -298,9 +298,10 @@ Configuration Description
registered as ``/dev/mmcsd``\ *N* where *N* is the minor number. registered as ``/dev/mmcsd``\ *N* where *N* is the minor number.
Default is zero. Default is zero.
``CONFIG_NSH_ROMFSETC`` Mount a ROMFS file system at ``/etc`` and provide a startup ``CONFIG_NSH_ROMFSETC`` Mount a ROMFS file system at ``/etc`` and provide a system init
script at ``/etc/init.d/rcS``. script at ``/etc/init.d.rc.sysinit`` and a startup script at
The default startup script will mount a FAT FS RAMDISK at ``/etc/init.d/rcS``.
The default system init script will mount a FAT FS RAMDISK at
``/tmp`` but the logic is `easily extensible <#startupscript>`__. ``/tmp`` but the logic is `easily extensible <#startupscript>`__.
``CONFIG_NSH_CONSOLE`` If ``CONFIG_NSH_CONSOLE`` is set to *y*, then a serial console ``CONFIG_NSH_CONSOLE`` If ``CONFIG_NSH_CONSOLE`` is set to *y*, then a serial console
@ -462,6 +463,9 @@ Configuration Description
``CONFIG_NSH_ROMFSMOUNTPT`` The default mountpoint for the ROMFS volume is ``"/etc"``, ``CONFIG_NSH_ROMFSMOUNTPT`` The default mountpoint for the ROMFS volume is ``"/etc"``,
but that can be changed with this setting. This must be a but that can be changed with this setting. This must be a
absolute path beginning with '``/``' and enclosed in quotes. absolute path beginning with '``/``' and enclosed in quotes.
``CONFIG_NSH_SYSINITSCRIPT`` This is the relative path to the system init script within the
mountpoint. The default is ``"init.d/rc.sysinit"``. This is a relative
path and must not start with '``/``' but must be enclosed in quotes.
``CONFIG_NSH_INITSCRIPT`` This is the relative path to the startup script within the ``CONFIG_NSH_INITSCRIPT`` This is the relative path to the startup script within the
mountpoint. The default is ``"init.d/rcS"``. This is a relative mountpoint. The default is ``"init.d/rcS"``. This is a relative
path and must not start with '``/``' but must be enclosed in quotes. path and must not start with '``/``' but must be enclosed in quotes.
@ -473,7 +477,7 @@ Configuration Description
Any value selected must be a power of 2. Any value selected must be a power of 2.
============================== ============================================================== ============================== ==============================================================
When the default ``rcS`` file used when ``CONFIG_NSH_ROMFSETC`` is When the default ``rc.sysinit`` file used when ``CONFIG_NSH_ROMFSETC`` is
selected, it will mount a FAT FS under ``/tmp``. The following selected, it will mount a FAT FS under ``/tmp``. The following
selections describe that FAT FS. selections describe that FAT FS.

View File

@ -46,18 +46,18 @@ does the following:
~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~
The NSH initialization function, ``nsh_initialize()``, be found in The NSH initialization function, ``nsh_initialize()``, be found in
``apps/nshlib/nsh_init.c``. It does only three things: ``apps/nshlib/nsh_init.c``. It does only four things:
#. ``nsh_romfsetc()``: If so configured, it executes an NSH start-up #. ``nsh_romfsetc()``: If so configured, it executes NSH system init and
script that can be found at ``/etc/init.d/rcS`` in the target file start-up script that can be found at ``/etc/init.d/rc.sysinit`` and
system. The ``nsh_romfsetc()`` function can be found in ``/etc/init.d/rcS`` in the target file system. The ``nsh_romfsetc()``
``apps/nshlib/nsh_romfsetc.c``. This function will (1) register a function can be found in ``apps/nshlib/nsh_romfsetc.c``.
ROMFS file system, then (2) mount the ROMFS file system. ``/etc`` is This function will (1) register a ROMFS file system, then (2) mount
the default location where a read-only, ROMFS file system is mounted the ROMFS file system. ``/etc`` is the default location where a
by ``nsh_romfsetc()``. read-only, ROMFS file system is mounted by ``nsh_romfsetc()``.
The ROMFS image is, itself, just built into the firmware. By default, The ROMFS image is, itself, just built into the firmware. By default,
this ``rcS`` start-up script contains the following logic:: this ``rc.sysinit`` system init script contains the following logic::
# Create a RAMDISK and mount it at XXXRDMOUNTPOINTXXX # Create a RAMDISK and mount it at XXXRDMOUNTPOINTXXX
@ -79,7 +79,7 @@ The NSH initialization function, ``nsh_initialize()``, be found in
- ``XXXRDMOUNTPOINTXXX`` will become the configured mount point. - ``XXXRDMOUNTPOINTXXX`` will become the configured mount point.
Default: ``/etc`` Default: ``/etc``
By default, the substituted values would yield an ``rcS`` file like:: By default, the substituted values would yield an ``rc.sysinit`` file like::
# Create a RAMDISK and mount it at /tmp # Create a RAMDISK and mount it at /tmp
@ -96,8 +96,8 @@ The NSH initialization function, ``nsh_initialize()``, be found in
- Mount the FAT file system at a configured mountpoint, ``/tmp``. - Mount the FAT file system at a configured mountpoint, ``/tmp``.
This ``rcS`` template file can be found at This ``rc.sysinit.template`` template file can be found at
``apps/nshlib/rcS.template``. The resulting ROMFS file system can be ``apps/nshlib/rc.sysinit.template``. The resulting ROMFS file system can be
found in ``apps/nshlib/nsh_romfsimg.h``. found in ``apps/nshlib/nsh_romfsimg.h``.
#. ``board_app_initialize()``: Next any architecture-specific NSH #. ``board_app_initialize()``: Next any architecture-specific NSH
@ -110,6 +110,13 @@ The NSH initialization function, ``nsh_initialize()``, be found in
#. ``nsh_netinit()``: The ``nsh_netinit()`` function can be found in #. ``nsh_netinit()``: The ``nsh_netinit()`` function can be found in
``apps/nshlib/nsh_netinit.c``. ``apps/nshlib/nsh_netinit.c``.
#. The start-up script ``rcS`` is executed after the system-init script
to startup some application and other system service.
This ``rcS`` template file can be found at
``apps/nshlib/rcS.template``. The resulting ROMFS file system can be
found in ``apps/nshlib/nsh_romfsimg.h``.
NSH Commands NSH Commands
************ ************

View File

@ -61,8 +61,10 @@ behave as follows at NSH start-up time:
`--init.d/ `--init.d/
`-- rcS `-- rcS
`-- rc.sysinit
Where ``rcS`` is the NSH start-up script. Where ``rcS`` is the NSH start-up script.
Where ``rc.sysinit`` is the NSH system-init script.
- NSH will then mount the ROMFS file system at ``/etc``, resulting in:: - NSH will then mount the ROMFS file system at ``/etc``, resulting in::
@ -71,8 +73,9 @@ behave as follows at NSH start-up time:
`--etc/ `--etc/
`--init.d/ `--init.d/
`-- rcS `-- rcS
`-- rc.sysinit
- By default, the contents of ``rcS`` script are:: - By default, the contents of ``rc.sysinit`` script are::
# Create a RAMDISK and mount it at /tmp # Create a RAMDISK and mount it at /tmp
@ -80,9 +83,9 @@ behave as follows at NSH start-up time:
mkfatfs /dev/ram1 mkfatfs /dev/ram1
mount -t vfat /dev/ram1 /tmp mount -t vfat /dev/ram1 /tmp
- NSH will execute the script at ``/etc/init.d/rcS`` at start-up - NSH will execute the script at ``/etc/init.d/rc.sysinit`` at system
(before the first NSH prompt). After execution of the script, the init (before the first NSH prompt). After execution of the script,
root FS will look like:: the root FS will look like::
|--dev/ |--dev/
| |-- ram0 | |-- ram0
@ -90,6 +93,7 @@ behave as follows at NSH start-up time:
|--etc/ |--etc/
| `--init.d/ | `--init.d/
| `-- rcS | `-- rcS
| `-- rc.sysinit
`--tmp/ `--tmp/
**Example Configurations**. Here are some configurations that have **Example Configurations**. Here are some configurations that have
@ -105,15 +109,16 @@ provide useful examples:
- ``boards/sim/sim/sim/touchscreen`` - ``boards/sim/sim/sim/touchscreen``
In most of these cases, the configuration sets up the *default* In most of these cases, the configuration sets up the *default*
``/etc/init.d/rcS`` script. The default script is here: ``/etc/init.d/rc.sysinit`` and ``/etc/init.d/rcS`` script. The default
``apps/nshlib/rcS.template``. (The funny values in the template like script is here: ``apps/nshlib/rc.sysinit.template`` and
``XXXMKRDMINORXXX`` get replaced via ``sed`` at build time). This ``apps/nshlib/rcS.template``. (The funny values in the rc.sysinit.template
like ``XXXMKRDMINORXXX`` get replaced via ``sed`` at build time). This
default configuration creates a ramdisk and mounts it at ``/tmp`` as default configuration creates a ramdisk and mounts it at ``/tmp`` as
discussed above. discussed above.
If that default behavior is not what you want, then you can provide your If that default behavior is not what you want, then you can provide your
own custom ``rcS`` script by defining ``CONFIG_NSH_ARCHROMFS=y`` in the own custom ``rc.sysinit`` and ``rcS`` script by defining
configuration file. ``CONFIG_NSH_ARCHROMFS=y`` in the configuration file.
**Modifying the ROMFS Image**. The contents of the ``/etc`` directory **Modifying the ROMFS Image**. The contents of the ``/etc`` directory
are retained in the file ``apps/nshlib/nsh_romfsimg.h`` OR, if are retained in the file ``apps/nshlib/nsh_romfsimg.h`` OR, if
@ -146,21 +151,34 @@ behavior, there are three things to study:
is a normal part of a complete Linux or Cygwin installation, is a normal part of a complete Linux or Cygwin installation,
usually as part of the ``vi`` package). usually as part of the ``vi`` package).
#. The file ``apps/nshlib/rcS.template`` (OR, if #. The file ``apps/nshlib/rc.sysinit.template`` (OR, if
``CONFIG_NSH_ARCHROMFS`` is defined
``include/arch/board/rc.sysinit.template``.
The file ``apps/nshlib/rcS.template`` (OR, if
``CONFIG_NSH_ARCHROMFS`` is defined ``CONFIG_NSH_ARCHROMFS`` is defined
``include/arch/board/rcs.template``. ``include/arch/board/rcs.template``.
#. ``rcS.template``. The file ``apps/nshlib/rcS.template`` contains the #. ``rc.sysinit.template``. The file ``apps/nshlib/rc.sysinit.template``
contains the general form of the ``rc.sysinit`` file; configured values
are plugged into this template file to produce the final ``rc.sysinit`` file.
``rcS.template``. The file ``apps/nshlib/rcS.template`` contains the
general form of the ``rcS`` file; configured values are plugged into general form of the ``rcS`` file; configured values are plugged into
this template file to produce the final ``rcS`` file. this template file to produce the final ``rcS`` file.
To generate a custom ``rcS`` file a copy of ``rcS.template`` needs to To generate a custom ``rc.sysinit`` and ``rcS`` file a copy of
``rc.sysinit.template`` and ``rcS.template`` needs to
be placed at ``tools/`` and changed according to the desired start-up be placed at ``tools/`` and changed according to the desired start-up
behaviour. Running ``tools/mkromfsimg.h`` creates ``nsh_romfsimg.h`` behaviour. Running ``tools/mkromfsimg.h`` creates ``nsh_romfsimg.h``
which needs to be copied to ``apps/nshlib`` OR if which needs to be copied to ``apps/nshlib`` OR if
``CONFIG_NSH_ARCHROMFS`` is defined to ``CONFIG_NSH_ARCHROMFS`` is defined to
``boards/<arch>/<chip>/<board>/include``. ``boards/<arch>/<chip>/<board>/include``.
``rc.sysinit.template``. The default ``rc.sysinit.template``,
``apps/nshlib/rc.sysinit.template``, generates the standard, default
``apps/nshlib/nsh_romfsimg.h`` file.
``rcS.template``. The default ``rcS.template``, ``rcS.template``. The default ``rcS.template``,
``apps/nshlib/rcS.template``, generates the standard, default ``apps/nshlib/rcS.template``, generates the standard, default
``apps/nshlib/nsh_romfsimg.h`` file. ``apps/nshlib/nsh_romfsimg.h`` file.
@ -171,10 +189,11 @@ then a custom, board-specific ``nsh_romfsimg.h`` file residing in
is configured, ``include/arch/board`` will be linked to is configured, ``include/arch/board`` will be linked to
``boards/<arch>/<chip>/<board>/include``. ``boards/<arch>/<chip>/<board>/include``.
All of the startup-behavior is contained in ``rcS.template``. The role All of the startup-behavior is contained in ``rc.sysinit.template`` and
of ``mkromfsimg.sh`` script is to (1) apply the specific configuration ``rcS.template``. The role of ``mkromfsimg.sh`` script is to (1) apply
settings to ``rcS.template`` to create the final ``rcS``, and (2) to the specific configuration settings to ``rc.sysinit.template`` to create
generate the header file ``nsh_romfsimg.h`` containing the ROMFS file the final ``rc.sysinit``, and ``rcS.template`` to create the final ``rcS``,
and (2) to generate the header file ``nsh_romfsimg.h`` containing the ROMFS file
system image. To do this, ``mkromfsimg.sh`` uses two tools that must be system image. To do this, ``mkromfsimg.sh`` uses two tools that must be
installed in your system: installed in your system:

View File

@ -164,9 +164,11 @@ and containing the password file, ``passwd`` like::
/etc/init.d: /etc/init.d:
dr-xr-xr-x 0 .. dr-xr-xr-x 0 ..
-r--r--r-- 110 rcS -r--r--r-- 110 rcS
-r--r--r-- 110 rc.sysinit
nsh> nsh>
Where ``/etc/init.d/rcS`` is the start-up script; ``/etc/passwd`` is a Where ``/etc/init.d/rc.sysinit`` is the system init script and
``/etc/init.d/rcS`` is the start-up script; ``/etc/passwd`` is a
the password file. Note that here we assume that you are already using a the password file. Note that here we assume that you are already using a
start-up script. We can then piggyback the passwd file into the ``/etc`` start-up script. We can then piggyback the passwd file into the ``/etc``
file system already mounted for the NSH start up file as described above file system already mounted for the NSH start up file as described above

View File

@ -276,8 +276,10 @@ NSH to behave as follows at NSH startup time:
`--init.d/ `--init.d/
`-- rcS `-- rcS
`-- rc.sysinit
Where rcS is the NSH start-up script. Where rcS is the NSH start-up script.
Where rc.sysinit is the NSH system init script.
- NSH will then mount the ROMFS file system at ``/etc``, - NSH will then mount the ROMFS file system at ``/etc``,
resulting in:: resulting in::
@ -287,8 +289,9 @@ NSH to behave as follows at NSH startup time:
`--etc/ `--etc/
`--init.d/ `--init.d/
`-- rcS `-- rcS
`-- rc.sysinit
- By default, the contents of rcS script are:: - By default, the contents of rc.sysinit script are::
# Create a RAMDISK and mount it at XXXRDMOUNTPOINTXXX # Create a RAMDISK and mount it at XXXRDMOUNTPOINTXXX
@ -296,9 +299,9 @@ NSH to behave as follows at NSH startup time:
mkfatfs /dev/ram1 mkfatfs /dev/ram1
mount -t vfat /dev/ram1 /tmp mount -t vfat /dev/ram1 /tmp
- NSH will execute the script at ``/etc/init.d/rcS`` at start-up - NSH will execute the script at ``/etc/init.d/rc.sysinit`` at
(before the first NSH prompt). After execution of the script, system init script(before the first NSH prompt). After
the root FS will look like:: execution of the script, the root FS will look like::
|--dev/ |--dev/
| |-- ram0 | |-- ram0
@ -306,6 +309,7 @@ NSH to behave as follows at NSH startup time:
|--etc/ |--etc/
| `--init.d/ | `--init.d/
| `-- rcS | `-- rcS
| `-- rc.sysinit
`--tmp/ `--tmp/
**Modifying the ROMFS Image**. The contents of the ``/etc`` **Modifying the ROMFS Image**. The contents of the ``/etc``
@ -330,28 +334,37 @@ start-up behavior, there are three things to study:
- The configuration settings then installed configuration. - The configuration settings then installed configuration.
- The ``genromfs`` tool (available from - The ``genromfs`` tool (available from
http://romfs.sourceforge.net). http://romfs.sourceforge.net).
- The file ``apps/nshlib/rcS.template`` (OR, if - The file ``apps/nshlib/rc.sysinit.template`` (OR, if
``CONFIG_NSH_ARCHROMFS`` is defined
``include/arch/board/rc.sysinit.template``.
The file ``apps/nshlib/rcS.template`` (OR, if
``CONFIG_NSH_ARCHROMFS`` is defined ``CONFIG_NSH_ARCHROMFS`` is defined
``include/arch/board/rcs.template``. ``include/arch/board/rcs.template``.
#. ``rcS.template``: The file ``apps/nshlib/rcS.template`` #. ``rc.sysinit.template``: The file ``apps/nshlib/rc.sysinit.template``
contains the general form of the ``rc.sysinit`` file; configured
values are plugged into this template file to produce the final
``rc.sysinit`` file.
``rcS.template``: The file ``apps/nshlib/rcS.template``
contains the general form of the ``rcS`` file; configured contains the general form of the ``rcS`` file; configured
values are plugged into this template file to produce the final values are plugged into this template file to produce the final
``rcS`` file. ``rcS`` file.
.. note:: .. note::
``apps/nshlib/rcS.template`` generates the standard, ``apps/nshlib/rcS.template`` and ``apps/nshlib/rc.sysinit.template``
default ``nsh_romfsimg.h`` file. If ``CONFIG_NSH_ARCHROMFS`` is generates the standard, default ``nsh_romfsimg.h`` file.
defined in the NuttX configuration file, then a custom, If ``CONFIG_NSH_ARCHROMFS`` is defined in the NuttX configuration
board-specific ``nsh_romfsimg.h`` file residing in the file, then a custom, board-specific ``nsh_romfsimg.h`` file residing
``boards/<arch>/<chip>/<board>/include`` directory will be used. in the ``boards/<arch>/<chip>/<board>/include`` directory will be
NOTE when the OS is configured, ``include/arch/board`` will be used. NOTE when the OS is configured, ``include/arch/board`` will be
linked to ``boards/<arch>/<chip>/<board>/include``. linked to ``boards/<arch>/<chip>/<board>/include``.
All of the startup-behavior is contained in ``rcS.template``. The All of the startup-behavior is contained in ``rc.sysinit.template``
role of ``mkromfsimg.sh`` is to (1) apply the specific and ``rcS.template``. The role of ``mkromfsimg.sh`` is to (1) apply
configuration settings to ``rcS.template`` to create the final the specific configuration settings to ``rc.sysinit.template`` to create
``rcS``, and (2) to generate the header file ``nsh_romfsimg.h`` the final ``rc.sysinit``, and ``rc.sysinit.template`` to create the final
``rcS`` and (2) to generate the header file ``nsh_romfsimg.h``
containing the ROMFS file system image. containing the ROMFS file system image.
**Further Information**. See the section on `Customizing the **Further Information**. See the section on `Customizing the

View File

@ -0,0 +1,12 @@
# Mount the procfs file system at /proc
mount -t procfs /proc
echo "rc.sysinit: Mounted /proc"
# Create a RAMDISK at /dev/ram1, size 0.5MiB, format it with a FAT
# file system and mount it at /tmp
mkrd -m 1 -s 512 1024
mkfatfs /dev/ram1
mount -t vfat /dev/ram1 /tmp
echo "rc.sysinit: Mounted /tmp"

View File

@ -1,12 +0,0 @@
# Mount the procfs file system at /proc
mount -t procfs /proc
echo "rcS: Mounted /proc"
# Create a RAMDISK at /dev/ram1, size 0.5MiB, format it with a FAT
# file system and mount it at /tmp
mkrd -m 1 -s 512 1024
mkfatfs /dev/ram1
mount -t vfat /dev/ram1 /tmp
echo "rcS: Mounted /tmp"

View File

@ -0,0 +1,2 @@
# sample rc.sysinit file; you must run tools/genromfs <nuttx dir> from within this
# location to convert this file to nsh_romfsimg.h for inclusion in the build

View File

@ -0,0 +1,2 @@
# sample rc.sysinit file; you must run tools/genromfs <nuttx dir> from within this
# location to convert this file to nsh_romfsimg.h for inclusion in the build

View File

@ -3,13 +3,13 @@ README
Overview Overview
-------- --------
This directory contains logic to support a custom ROMFS start-up script. This directory contains logic to support a custom ROMFS system-init script
This startup script is used by by the NSH when it starts provided that and start-up script. These scripts are used by by the NSH when it starts
CONFIG_NSH_ARCHROMFS=y. The script provides a ROMFS volume that will be provided that CONFIG_NSH_ARCHROMFS=y. These scripts provide a ROMFS volume
mounted at /etc and will look like this at run-time: that will be mounted at /etc and will look like this at run-time:
NuttShell (NSH) NuttX-8.2 NuttShell (NSH) NuttX-8.2
nsh> ls -l /etc nsh> ls -Rl /etc
/etc: /etc:
dr-xr-xr-x 0 . dr-xr-xr-x 0 .
-r--r--r-- 20 group -r--r--r-- 20 group
@ -18,10 +18,11 @@ README
/etc/init.d: /etc/init.d:
dr-xr-xr-x 0 .. dr-xr-xr-x 0 ..
-r--r--r-- 110 rcS -r--r--r-- 110 rcS
-r--r--r-- 110 rc.sysinit
nsh> nsh>
/etc/init.d/rcS is the start-up script; /etc/passwd is a the password /etc/init.d/rc.sysinit is system init script; /etc/init.d/rcS is the start-up
file. It supports a single user: script; /etc/passwd is a the password file. It supports a single user:
USERNAME: admin USERNAME: admin
PASSWORD: Adminstrator PASSWORD: Adminstrator

View File

@ -3,10 +3,10 @@ README
Overview Overview
-------- --------
This directory contains logic to support a custom ROMFS start-up script. This directory contains logic to support a custom ROMFS system-init script
This startup script is used by by the NSH when it starts provided that and start-up script. These scripts are used by by the NSH when it starts
CONFIG_NSH_ARCHROMFS=y. The script provides a ROMFS volume that will be provided that CONFIG_NSH_ARCHROMFS=y. These scripts provide a ROMFS volume
mounted at /etc and will look like this at run-time: that will be mounted at /etc and will look like this at run-time:
NuttShell (NSH) NuttX-8.2 NuttShell (NSH) NuttX-8.2
nsh> ls -l /etc nsh> ls -l /etc
@ -18,10 +18,11 @@ README
/etc/init.d: /etc/init.d:
dr-xr-xr-x 0 .. dr-xr-xr-x 0 ..
-r--r--r-- 110 rcS -r--r--r-- 110 rcS
-r--r--r-- 110 rc.sysinit
nsh> nsh>
/etc/init.d/rcS is the start-up script; /etc/passwd is a the password /etc/init.d/rc.sysinit is system init script; /etc/init.d/rcS is the start-up
file. It supports a single user: script; /etc/passwd is a the password file. It supports a single user:
USERNAME: admin USERNAME: admin
PASSWORD: Adminstrator PASSWORD: Adminstrator

View File

@ -108,7 +108,7 @@ endif
ifeq ($(CONFIG_NSH_ROMFSETC),y) ifeq ($(CONFIG_NSH_ROMFSETC),y)
ifneq ($(CONFIG_NSH_CUSTOMROMFS),y) ifneq ($(CONFIG_NSH_CUSTOMROMFS),y)
RCSRCS = etc/init.d/rcS RCSRCS = etc/init.d/rc.sysinit etc/init.d/rcS
RCRAWS = etc/group etc/passwd RCRAWS = etc/group etc/passwd
endif endif
endif endif

View File

@ -3,10 +3,10 @@ README
Overview Overview
-------- --------
This directory contains logic to support a custom ROMFS start-up script. This directory contains logic to support a custom ROMFS system-init script
This startup script is used by by the NSH when it starts provided that and start-up script. These scripts are used by by the NSH when it starts
CONFIG_NSH_ARCHROMFS=y. The script provides a ROMFS volume that will be provided that CONFIG_NSH_ARCHROMFS=y. These scripts provide a ROMFS volume
mounted at /etc and will look like this at run-time: that will be mounted at /etc and will look like this at run-time:
NuttShell (NSH) NuttX-10.1.0-RC1 NuttShell (NSH) NuttX-10.1.0-RC1
MOTD: username=admin password=Administrator MOTD: username=admin password=Administrator
@ -19,10 +19,11 @@ README
/etc/init.d: /etc/init.d:
dr-xr-xr-x 0 .. dr-xr-xr-x 0 ..
-r--r--r-- 110 rcS -r--r--r-- 110 rcS
-r--r--r-- 110 rc.sysinit
nsh> nsh>
/etc/init.d/rcS is the start-up script; /etc/passwd is a the password /etc/init.d/rc.sysinit is system init script; /etc/init.d/rcS is the start-up
file. It supports a single user: script; /etc/passwd is a the password file. It supports a single user:
USERNAME: admin USERNAME: admin
PASSWORD: Administrator PASSWORD: Administrator

View File

@ -0,0 +1,36 @@
/****************************************************************************
* boards/risc-v/esp32c3/esp32c3-devkit/src/etc/init.d/rc.sysinit
*
* 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.
*
****************************************************************************/
#include <nuttx/config.h>
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#ifdef CONFIG_NSH_ROMFSETC
#ifdef CONFIG_FS_FAT
/* Create a RAMDISK and mount it at /tmp */
mkrd -m CONFIG_NSH_FATDEVNO -s CONFIG_NSH_FATSECTSIZE CONFIG_NSH_FATNSECTORS
mkfatfs CONCAT(/dev/ram, CONFIG_NSH_FATDEVNO)
mount -t vfat CONCAT(/dev/ram, CONFIG_NSH_FATDEVNO) CONFIG_NSH_FATMOUNTPT
#endif /* CONFIG_FS_FAT */
#endif /* CONFIG_NSH_ROMFSETC */

View File

@ -17,20 +17,3 @@
* under the License. * under the License.
* *
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h>
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#ifdef CONFIG_NSH_ROMFSETC
#ifdef CONFIG_FS_FAT
/* Create a RAMDISK and mount it at /tmp */
mkrd -m CONFIG_NSH_FATDEVNO -s CONFIG_NSH_FATSECTSIZE CONFIG_NSH_FATNSECTORS
mkfatfs CONCAT(/dev/ram, CONFIG_NSH_FATDEVNO)
mount -t vfat CONCAT(/dev/ram, CONFIG_NSH_FATDEVNO) CONFIG_NSH_FATMOUNTPT
#endif /* CONFIG_FS_FAT */
#endif /* CONFIG_NSH_ROMFSETC */

View File

@ -20,7 +20,7 @@
include $(TOPDIR)/Make.defs include $(TOPDIR)/Make.defs
RCSRCS = etc/init.d/rcS RCSRCS = etc/init.d/rc.sysinit etc/init.d/rcS
CSRCS = qemu_rv_appinit.c CSRCS = qemu_rv_appinit.c

View File

@ -0,0 +1,19 @@
/****************************************************************************
* boards/risc-v/qemu-rv/rv-virt/src/etc/init.d/rc.sysinit
*
* 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.
*
****************************************************************************/

View File

@ -0,0 +1,19 @@
/****************************************************************************
* boards/risc-v/qemu-rv/rv-virt/src/etc/init.d/rcS
*
* 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.
*
****************************************************************************/

View File

@ -54,7 +54,7 @@ endif
ifeq ($(CONFIG_NSH_ROMFSETC),y) ifeq ($(CONFIG_NSH_ROMFSETC),y)
ifneq ($(CONFIG_NSH_CUSTOMROMFS),y) ifneq ($(CONFIG_NSH_CUSTOMROMFS),y)
RCSRCS = etc/init.d/rcS RCSRCS = etc/init.d/rc.sysinit etc/init.d/rcS
RCRAWS = etc/group etc/passwd RCRAWS = etc/group etc/passwd
endif endif
endif endif

View File

@ -3,10 +3,10 @@ README
Overview Overview
-------- --------
This directory contains logic to support a custom ROMFS start-up script. This directory contains logic to support a custom ROMFS system-init script
This startup script is used by by the NSH when it starts provided that and start-up script. These scripts are used by by the NSH when it starts
CONFIG_NSH_ARCHROMFS=y. The script provides a ROMFS volume that will be provided that CONFIG_NSH_ARCHROMFS=y. These scripts provide a ROMFS volume
mounted at /etc and will look like this at run-time: that will be mounted at /etc and will look like this at run-time:
NuttShell (NSH) NuttX-7.31 NuttShell (NSH) NuttX-7.31
MOTD: username=admin password=Administrator MOTD: username=admin password=Administrator
@ -19,10 +19,11 @@ README
/etc/init.d: /etc/init.d:
dr-xr-xr-x 0 .. dr-xr-xr-x 0 ..
-r--r--r-- 110 rcS -r--r--r-- 110 rcS
-r--r--r-- 110 rc.sysinit
nsh> nsh>
/etc/init.d/rcS is the start-up script; /etc/passwd is a the password /etc/init.d/rc.sysinit is system init script; /etc/init.d/rcS is the start-up
file. It supports a single user: script; /etc/passwd is a the password file. It supports a single user:
USERNAME: admin USERNAME: admin
PASSWORD: Administrator PASSWORD: Administrator

View File

@ -0,0 +1,36 @@
/****************************************************************************
* boards/sim/sim/sim/src/etc/init.d/rc.sysinit
*
* 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.
*
****************************************************************************/
#include <nuttx/config.h>
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#ifdef CONFIG_NSH_ROMFSETC
#ifdef CONFIG_FS_FAT
/* Create a RAMDISK and mount it at /tmp */
mkrd -m CONFIG_NSH_FATDEVNO -s CONFIG_NSH_FATSECTSIZE CONFIG_NSH_FATNSECTORS
mkfatfs CONCAT(/dev/ram, CONFIG_NSH_FATDEVNO)
mount -t vfat CONCAT(/dev/ram, CONFIG_NSH_FATDEVNO) CONFIG_NSH_FATMOUNTPT
#endif /* CONFIG_FS_FAT */
#endif /* CONFIG_NSH_ROMFSETC */

View File

@ -17,20 +17,3 @@
* under the License. * under the License.
* *
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h>
#define CONCAT_(x, y) x##y
#define CONCAT(x, y) CONCAT_(x, y)
#ifdef CONFIG_NSH_ROMFSETC
#ifdef CONFIG_FS_FAT
/* Create a RAMDISK and mount it at /tmp */
mkrd -m CONFIG_NSH_FATDEVNO -s CONFIG_NSH_FATSECTSIZE CONFIG_NSH_FATNSECTORS
mkfatfs CONCAT(/dev/ram, CONFIG_NSH_FATDEVNO)
mount -t vfat CONCAT(/dev/ram, CONFIG_NSH_FATDEVNO) CONFIG_NSH_FATMOUNTPT
#endif /* CONFIG_FS_FAT */
#endif /* CONFIG_NSH_ROMFSETC */

View File

@ -23,6 +23,8 @@
wd=`pwd` wd=`pwd`
workingdir=$wd/img workingdir=$wd/img
rcsysinitfile=rc.sysinit
rcsysinittemplate=$rcsysinitfile.template
rcsfile=rcS rcsfile=rcS
rcstemplate=$rcsfile.template rcstemplate=$rcsfile.template
romfsimg=romfs.img romfsimg=romfs.img
@ -33,8 +35,9 @@ headerfile=nsh_romfsimg.h
nofat=$1 nofat=$1
usefat=true usefat=true
topdir=$2 topdir=$2
rcs_fname=$3 rcsysinit_fname=$3
usage="USAGE: $0 [-nofat] <topdir> [<rcsfile>]" rcs_fname=$4
usage="USAGE: $0 [-nofat] <topdir> [rcsysinitfile] [<rcsfile>]"
# Verify if we have the optional "-nofat" # Verify if we have the optional "-nofat"
@ -43,7 +46,8 @@ if [ "$nofat" == "-nofat" ]; then
usefat=false usefat=false
else else
topdir=$1 topdir=$1
rcs_fname=$2 rcsysinit_fname=$2
rcs_fname=$3
fi fi
if [ -z "$topdir" -o ! -d "$topdir" ]; then if [ -z "$topdir" -o ! -d "$topdir" ]; then
@ -52,7 +56,12 @@ if [ -z "$topdir" -o ! -d "$topdir" ]; then
exit 1 exit 1
fi fi
# Verify if we have the optional "rcs_fname" # Verify if we have the optional "rcsysinit_fname" and "rcs_fname"
if [ ! -z "$rcsysinit_fname" ]; then
rcsysinittemplate=$rcsysinit_fname
echo "Target template is $rcsysinittemplate"
fi
if [ ! -z "$rcs_fname" ]; then if [ ! -z "$rcs_fname" ]; then
rcstemplate=$rcs_fname rcstemplate=$rcs_fname
@ -77,6 +86,7 @@ devconsole=`grep CONFIG_DEV_CONSOLE= $topdir/.config | cut -d'=' -f2`
romfs=`grep CONFIG_FS_ROMFS= $topdir/.config | cut -d'=' -f2` romfs=`grep CONFIG_FS_ROMFS= $topdir/.config | cut -d'=' -f2`
romfsmpt=`grep CONFIG_NSH_ROMFSMOUNTPT= $topdir/.config | cut -d'=' -f2` romfsmpt=`grep CONFIG_NSH_ROMFSMOUNTPT= $topdir/.config | cut -d'=' -f2`
initscript=`grep CONFIG_NSH_INITSCRIPT= $topdir/.config | cut -d'=' -f2` initscript=`grep CONFIG_NSH_INITSCRIPT= $topdir/.config | cut -d'=' -f2`
sysinitscript=`grep CONFIG_NSH_SYSINITSCRIPT= $topdir/.config | cut -d'=' -f2`
romfsdevno=`grep CONFIG_NSH_ROMFSDEVNO= $topdir/.config | cut -d'=' -f2` romfsdevno=`grep CONFIG_NSH_ROMFSDEVNO= $topdir/.config | cut -d'=' -f2`
romfssectsize=`grep CONFIG_NSH_ROMFSSECTSIZE= $topdir/.config | cut -d'=' -f2` romfssectsize=`grep CONFIG_NSH_ROMFSSECTSIZE= $topdir/.config | cut -d'=' -f2`
@ -140,6 +150,9 @@ fi
if [ -z "$initscript" ]; then if [ -z "$initscript" ]; then
initscript=\"init.d/rcS\" initscript=\"init.d/rcS\"
fi fi
if [ -z "$sysinitscript" ]; then
sysinitscript=\"init.d/rc.sysinit\"
fi
if [ -z "$romfsdevno" ]; then if [ -z "$romfsdevno" ]; then
romfsdevno=0 romfsdevno=0
fi fi
@ -217,11 +230,51 @@ if [ "X$uinitscript" = "." -o ${uinitscript:0:2} = "./" -o \
exit 1 exit 1
fi fi
if [ ${sysinitscript:0:1} != "\"" ]; then
echo "CONFIG_NSH_SYSINITSCRIPT must be a string"
echo "Change it so that it is enclosed in quotes."
exit 1
fi
usysinitscript=`echo $sysinitscript | sed -e "s/\"//g"`
if [ ${usysinitscript:0:1} == "/" ]; then
echo "CONFIG_NSH_SYSINITSCRIPT must be an relative path in under $romfsmpt"
echo "Change it so that it begins with the character '/'. Eg. init.d/rc.sysinit. "
exit 1
fi
if [ "X$usysinitscript" = "." -o ${usysinitscript:0:2} = "./" -o \
"X$usysinitscript" = ".." -o ${usysinitscript:0:3} = "../" ]; then
echo "Invalid CONFIG_NSH_SYSINITSCRIPT selection. Must not begin with . or .."
exit 1
fi
# Create a working directory # Create a working directory
rm -rf $workingdir || { echo "Failed to remove the old $workingdir"; exit 1; } rm -rf $workingdir || { echo "Failed to remove the old $workingdir"; exit 1; }
mkdir -p $workingdir || { echo "Failed to created the new $workingdir"; exit 1; } mkdir -p $workingdir || { echo "Failed to created the new $workingdir"; exit 1; }
# Create the rc.sysinit file from the rc.sysinit.template
if [ ! -r $rcsysinittemplate ]; then
echo "$rcsysinittemplate does not exist"
rmdir $workingdir
exit 1
fi
# If we are using FAT FS with RAMDISK we need to setup it
if [ "$usefat" = true ]; then
cat $rcsysinittemplate | \
sed -e "s,XXXMKRDMINORXXX,$fatdevno,g" | \
sed -e "s,XXMKRDSECTORSIZEXXX,$fatsectsize,g" | \
sed -e "s,XXMKRDBLOCKSXXX,$fatnsectors,g" | \
sed -e "s,XXXRDMOUNTPOINTXXX,$fatmpt,g" >$rcsysinitfile
else
cp $rcsysinittemplate $rcsysinitfile
fi
# Create the rcS file from the rcS.template # Create the rcS file from the rcS.template
if [ ! -r $rcstemplate ]; then if [ ! -r $rcstemplate ]; then
@ -230,17 +283,7 @@ if [ ! -r $rcstemplate ]; then
exit 1 exit 1
fi fi
# If we are using FAT FS with RAMDISK we need to setup it cp $rcstemplate $rcsfile
if [ "$usefat" = true ]; then
cat $rcstemplate | \
sed -e "s,XXXMKRDMINORXXX,$fatdevno,g" | \
sed -e "s,XXMKRDSECTORSIZEXXX,$fatsectsize,g" | \
sed -e "s,XXMKRDBLOCKSXXX,$fatnsectors,g" | \
sed -e "s,XXXRDMOUNTPOINTXXX,$fatmpt,g" >$rcsfile
else
cp $rcstemplate $rcsfile
fi
# And install it at the specified relative location # And install it at the specified relative location
@ -248,6 +291,10 @@ fi
mkdir -p $workingdir/$uinitscript mkdir -p $workingdir/$uinitscript
rmdir $workingdir/$uinitscript rmdir $workingdir/$uinitscript
install -m 0755 $rcsysinitfile $workingdir/$usysinitscript || \
{ echo "Failed to install $rcsysinitfile at $workingdir/$usysinitscript"; rm -f $rcsysinitfile; exit 1; }
rm -f $rcsysinitfile
install -m 0755 $rcsfile $workingdir/$uinitscript || \ install -m 0755 $rcsfile $workingdir/$uinitscript || \
{ echo "Failed to install $rcsfile at $workingdir/$uinitscript"; rm -f $rcsfile; exit 1; } { echo "Failed to install $rcsfile at $workingdir/$uinitscript"; rm -f $rcsfile; exit 1; }
rm -f $rcsfile rm -f $rcsfile