mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-20 04:26:04 +08:00
nsh/script: support rc.sysinit script
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:

committed by
Petro Karashchenko

parent
768a21b587
commit
9f79bf183a
@@ -700,8 +700,9 @@ config NSH_ROMFSETC
|
|||||||
default n
|
default n
|
||||||
depends on FS_ROMFS
|
depends on FS_ROMFS
|
||||||
---help---
|
---help---
|
||||||
Mount a ROMFS filesystem at /etc and provide a startup script
|
Mount a ROMFS filesystem at /etc and provide a system init
|
||||||
at /etc/init.d/rcS. The default startup script will mount
|
script at /etc/init.d/rc.sysinit and a startup script
|
||||||
|
at /etc/init.d/rcS. The default system init script will mount
|
||||||
a FAT FS RAMDISK at /tmp but the logic is easily extensible.
|
a FAT FS RAMDISK at /tmp but the logic is easily extensible.
|
||||||
|
|
||||||
if NSH_ROMFSETC
|
if NSH_ROMFSETC
|
||||||
@@ -711,8 +712,9 @@ config NSH_CROMFSETC
|
|||||||
default n
|
default n
|
||||||
depends on FS_CROMFS
|
depends on FS_CROMFS
|
||||||
---help---
|
---help---
|
||||||
Mount a CROMFS filesystem at /etc and provide a compressed startup
|
Mount a CROMFS filesystem at /etc and provide a compressed system
|
||||||
script at /etc/init.d/rcS.
|
init script at /etc/init.d/rc.sysinit and a startup script
|
||||||
|
at /etc/init.d/rcS.
|
||||||
|
|
||||||
config NSH_ROMFSRC
|
config NSH_ROMFSRC
|
||||||
bool "Support ROMFS login script"
|
bool "Support ROMFS login script"
|
||||||
@@ -734,6 +736,14 @@ config NSH_ROMFSMOUNTPT
|
|||||||
can be changed with this setting. This must be a absolute path
|
can be changed with this setting. This must be a absolute path
|
||||||
beginning with '/'.
|
beginning with '/'.
|
||||||
|
|
||||||
|
config NSH_SYSINITSCRIPT
|
||||||
|
string "Relative path to sysinit script"
|
||||||
|
default "init.d/rc.sysinit"
|
||||||
|
---help---
|
||||||
|
This is the relative path to the sysinit script within the mountpoint.
|
||||||
|
The default is init.d/rc.sysinit. This is a relative path and must not
|
||||||
|
start with '/'.
|
||||||
|
|
||||||
config NSH_INITSCRIPT
|
config NSH_INITSCRIPT
|
||||||
string "Relative path to startup script"
|
string "Relative path to startup script"
|
||||||
default "init.d/rcS"
|
default "init.d/rcS"
|
||||||
|
@@ -176,21 +176,28 @@ the `echo $PWD` command.
|
|||||||
- `PWD` - The current working directory
|
- `PWD` - The current working directory
|
||||||
- `OLDPWD` - The previous working directory
|
- `OLDPWD` - The previous working directory
|
||||||
|
|
||||||
## NSH Start-Up Script
|
## NSH System-init And Start-Up Script
|
||||||
|
|
||||||
NSH supports options to provide a start up script for NSH. In general this
|
NSH supports options to provide a system init script and start up script for NSH.
|
||||||
capability is enabled with `CONFIG_NSH_ROMFSETC`, but has several other related
|
In general this capability is enabled with `CONFIG_NSH_ROMFSETC`, but has
|
||||||
configuration options as described in the final section of this README. This
|
several other related configuration options as described in the final section
|
||||||
capability also depends on:
|
of this README. This capability also depends on:
|
||||||
|
|
||||||
- `CONFIG_DISABLE_MOUNTPOINT` not set
|
- `CONFIG_DISABLE_MOUNTPOINT` not set
|
||||||
- `CONFIG_FS_ROMFS`
|
- `CONFIG_FS_ROMFS`
|
||||||
|
|
||||||
### Default Start-Up Behavior
|
### Default Script Behavior
|
||||||
|
|
||||||
The implementation that is provided is intended to provide great flexibility for
|
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
|
the use of script files, include system init file and start-up file. This
|
||||||
all of the configuration options are set to the default values.
|
paragraph will discuss the general behavior when all of the configuration
|
||||||
|
options are set to the default values.
|
||||||
|
|
||||||
|
System-init script is executed before Start-up script. The system-init script
|
||||||
|
is mainly used for file system mounting and core system service startup, and the
|
||||||
|
start-up script is used for application and other system service startup. So,
|
||||||
|
Between them, some initialize can use filesystem and core system service,
|
||||||
|
Examples: Peripheral driver initialize at `boardctl(BOARDIOC_FINALINIT, 0)`.
|
||||||
|
|
||||||
In this default case, enabling `CONFIG_NSH_ROMFSETC` will cause NSH to behave as
|
In this default case, enabling `CONFIG_NSH_ROMFSETC` will cause NSH to behave as
|
||||||
follows at NSH startup time:
|
follows at NSH startup time:
|
||||||
@@ -201,9 +208,11 @@ 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`, resulting in:
|
- NSH will then mount the ROMFS file system at `/etc`, resulting in:
|
||||||
|
|
||||||
@@ -213,9 +222,10 @@ 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:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
# Create a RAMDISK and mount it at XXXRDMOUNTPOINTXXX
|
# Create a RAMDISK and mount it at XXXRDMOUNTPOINTXXX
|
||||||
@@ -225,8 +235,9 @@ follows at NSH startup time:
|
|||||||
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 (before the first
|
- NSH will execute the script at `/etc/init.d/rc.sysinit` at system init
|
||||||
NSH prompt. After execution of the script, the root FS will look like:
|
before the first NSH prompt. After execution of the script, the root
|
||||||
|
FS will look like:
|
||||||
|
|
||||||
```
|
```
|
||||||
|--dev/
|
|--dev/
|
||||||
@@ -235,6 +246,7 @@ follows at NSH startup time:
|
|||||||
|--etc/
|
|--etc/
|
||||||
| `--init.d/
|
| `--init.d/
|
||||||
| `-- rcS
|
| `-- rcS
|
||||||
|
| `-- rc.sysinit
|
||||||
`--tmp/
|
`--tmp/
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -262,21 +274,27 @@ there are three things to study:
|
|||||||
- The file `apps/nshlib/rcS.template` (OR, if `CONFIG_NSH_ARCHROMFS` is
|
- The file `apps/nshlib/rcS.template` (OR, if `CONFIG_NSH_ARCHROMFS` is
|
||||||
defined, `include/arch/board/rcs.template`)
|
defined, `include/arch/board/rcs.template`)
|
||||||
|
|
||||||
3. `rcS.template`. The file `apps/nshlib/rcS.template` contains the general form
|
3. `rc.sysinit.template`. The file `apps/nshlib/rc.sysinit.template` contains
|
||||||
|
the general form of the `rc.sysinit.template` 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 this template file to
|
of the `rcS` file; configured values are plugged into this template file to
|
||||||
produce the final `rcS` file.
|
produce the final `rcS` file.
|
||||||
|
|
||||||
**Note**: `apps/nshlib/rcS.template` generates the standard, default
|
**Note**: `apps/nshlib/rc.sysinit.template` and ` apps/nshlib/rcS.template`
|
||||||
`nsh_romfsimg.h` file. If `CONFIG_NSH_ARCHROMFS` is defined in the NuttX
|
generates the standard, default `nsh_romfsimg.h` file. If `CONFIG_NSH_ARCHROMFS`
|
||||||
configuration file, then a custom, board-specific `nsh_romfsimg.h` file residing
|
is defined in the NuttX configuration file, then a custom, board-specific
|
||||||
in `boards/<arch>/<chip>/<board>/include` will be used. **Note** when the OS is
|
`nsh_romfsimg.h` file residing in `boards/<arch>/<chip>/<board>/include` will be
|
||||||
configured, `include/arch/board` will be linked to
|
used. **Note** when the OS 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 of
|
All of the startup-behavior is contained in `rc.sysinit.template` and
|
||||||
`mkromfsimg.sh` is to (1) apply the specific configuration settings to
|
`rcS.template`. The role of `mkromfsimg.sh` is to (1) apply the specific
|
||||||
`rcS.template` to create the final `rcS`, and (2) to generate the header file
|
configuration settings to `rc.sysinit.template` to create the final
|
||||||
`nsh_romfsimg.h` containing the ROMFS file system image.
|
`rc.sysinit.template`, and `rcS.template` to create the final `rcS` and
|
||||||
|
(2) to generate the header file `nsh_romfsimg.h` containing the ROMFS file
|
||||||
|
system image.
|
||||||
|
|
||||||
## Simple Commands
|
## Simple Commands
|
||||||
|
|
||||||
@@ -1803,8 +1821,9 @@ The behavior of NSH can be modified with the following settings in the
|
|||||||
`/dev/mmcsdN` where `N` is the minor number. Default is zero.
|
`/dev/mmcsdN` where `N` is the minor number. Default is zero.
|
||||||
|
|
||||||
- `CONFIG_NSH_ROMFSETC` – Mount a ROMFS file system at `/etc` and provide a
|
- `CONFIG_NSH_ROMFSETC` – Mount a ROMFS file system at `/etc` and provide a
|
||||||
startup script at `/etc/init.d/rcS`. The default startup script will mount a
|
system init script at `/etc/init.d/rc.sysinit` and a startup script at
|
||||||
FAT FS RAMDISK at `/tmp` but the logic is easily extensible.
|
`/etc/init.d/rcS`. The default system init script will mount a FAT FS RAMDISK
|
||||||
|
at `/tmp` but the logic is easily extensible.
|
||||||
|
|
||||||
- `CONFIG_NSH_CONSOLE`
|
- `CONFIG_NSH_CONSOLE`
|
||||||
|
|
||||||
@@ -1944,6 +1963,10 @@ configuration setting apply:
|
|||||||
`/etc`, but that can be changed with this setting. This must be a absolute
|
`/etc`, but that can be changed with this setting. This must be a absolute
|
||||||
path beginning with `/`.
|
path beginning with `/`.
|
||||||
|
|
||||||
|
- `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 `/`.
|
||||||
|
|
||||||
- `CONFIG_NSH_INITSCRIPT` – This is the relative path to the startup script
|
- `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 path
|
within the mountpoint. The default is `init.d/rcS`. This is a relative path
|
||||||
and must not start with `/`.
|
and must not start with `/`.
|
||||||
|
@@ -340,10 +340,17 @@
|
|||||||
# define CONFIG_NSH_ROMFSMOUNTPT "/etc"
|
# define CONFIG_NSH_ROMFSMOUNTPT "/etc"
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# ifndef CONFIG_NSH_SYSINITSCRIPT
|
||||||
|
# define CONFIG_NSH_SYSINITSCRIPT "init.d/rc.sysinit"
|
||||||
|
# endif
|
||||||
|
|
||||||
# ifndef CONFIG_NSH_INITSCRIPT
|
# ifndef CONFIG_NSH_INITSCRIPT
|
||||||
# define CONFIG_NSH_INITSCRIPT "init.d/rcS"
|
# define CONFIG_NSH_INITSCRIPT "init.d/rcS"
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
# undef NSH_SYSINITPATH
|
||||||
|
# define NSH_SYSINITPATH CONFIG_NSH_ROMFSMOUNTPT "/" CONFIG_NSH_SYSINITSCRIPT
|
||||||
|
|
||||||
# undef NSH_INITPATH
|
# undef NSH_INITPATH
|
||||||
# define NSH_INITPATH CONFIG_NSH_ROMFSMOUNTPT "/" CONFIG_NSH_INITSCRIPT
|
# define NSH_INITPATH CONFIG_NSH_ROMFSMOUNTPT "/" CONFIG_NSH_INITSCRIPT
|
||||||
|
|
||||||
@@ -829,6 +836,7 @@ int nsh_usbconsole(void);
|
|||||||
int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
||||||
FAR const char *path);
|
FAR const char *path);
|
||||||
#ifdef CONFIG_NSH_ROMFSETC
|
#ifdef CONFIG_NSH_ROMFSETC
|
||||||
|
int nsh_sysinitscript(FAR struct nsh_vtbl_s *vtbl);
|
||||||
int nsh_initscript(FAR struct nsh_vtbl_s *vtbl);
|
int nsh_initscript(FAR struct nsh_vtbl_s *vtbl);
|
||||||
#ifdef CONFIG_NSH_ROMFSRC
|
#ifdef CONFIG_NSH_ROMFSRC
|
||||||
int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl);
|
int nsh_loginscript(FAR struct nsh_vtbl_s *vtbl);
|
||||||
|
@@ -78,9 +78,9 @@ int nsh_consolemain(int argc, FAR char *argv[])
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
||||||
/* Execute the start-up script */
|
/* Execute the system init script */
|
||||||
|
|
||||||
nsh_initscript(&pstate->cn_vtbl);
|
nsh_sysinitscript(&pstate->cn_vtbl);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NSH_NETINIT
|
#ifdef CONFIG_NSH_NETINIT
|
||||||
@@ -95,6 +95,12 @@ int nsh_consolemain(int argc, FAR char *argv[])
|
|||||||
boardctl(BOARDIOC_FINALINIT, 0);
|
boardctl(BOARDIOC_FINALINIT, 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_NSH_ROMFSETC) && !defined(CONFIG_NSH_DISABLESCRIPT)
|
||||||
|
/* Execute the start-up script */
|
||||||
|
|
||||||
|
nsh_initscript(&pstate->cn_vtbl);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Execute the session */
|
/* Execute the session */
|
||||||
|
|
||||||
ret = nsh_session(pstate, true, argc, argv);
|
ret = nsh_session(pstate, true, argc, argv);
|
||||||
|
@@ -145,6 +145,22 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nsh_sysinitscript
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Attempt to execute the configured system initialization script. This
|
||||||
|
* script should be executed once when NSH starts.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_NSH_ROMFSETC
|
||||||
|
int nsh_sysinitscript(FAR struct nsh_vtbl_s *vtbl)
|
||||||
|
{
|
||||||
|
return nsh_script(vtbl, "sysinit", NSH_SYSINITPATH);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: nsh_initscript
|
* Name: nsh_initscript
|
||||||
*
|
*
|
||||||
|
5
nshlib/rc.sysinit.template
Normal file
5
nshlib/rc.sysinit.template
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Create a RAMDISK and mount it at XXXRDMOUNTPOINTXXX
|
||||||
|
|
||||||
|
mkrd -m XXXMKRDMINORXXX -s XXMKRDSECTORSIZEXXX XXMKRDBLOCKSXXX
|
||||||
|
mkfatfs /dev/ramXXXMKRDMINORXXX
|
||||||
|
mount -t vfat /dev/ramXXXMKRDMINORXXX XXXRDMOUNTPOINTXXX
|
@@ -1,5 +0,0 @@
|
|||||||
# Create a RAMDISK and mount it at XXXRDMOUNTPOINTXXX
|
|
||||||
|
|
||||||
mkrd -m XXXMKRDMINORXXX -s XXMKRDSECTORSIZEXXX XXMKRDBLOCKSXXX
|
|
||||||
mkfatfs /dev/ramXXXMKRDMINORXXX
|
|
||||||
mount -t vfat /dev/ramXXXMKRDMINORXXX XXXRDMOUNTPOINTXXX
|
|
||||||
|
Reference in New Issue
Block a user