startup.md 21.2 KB
Newer Older
L
liudongmiao 已提交
1 2 3 4 5 6 7
# Startup<a name="EN-US_TOPIC_0000001130845219"></a>

-   [Introduction](#section11660541593)
-   [Directory Structure](#section161941989596)
-   [Constraints](#section1718733212019)
-   [Usage](#section8533192617117)
-   [Repositories Involved](#section1371113476307)
W
wenjun 已提交
8 9 10

## Introduction<a name="section11660541593"></a>

L
liudongmiao 已提交
11
The startup subsystem is responsible for starting key system processes and services after the kernel is started and before applications are started. The subsystem consists of the following modules:
W
wenjun 已提交
12

L
liudongmiao 已提交
13
-   init\_lite
W
wenjun 已提交
14

L
liudongmiao 已提交
15
    This module can be used on the Hi3516D V300 and Hi3518E V300 platforms powered by LiteOS Cortex-A.
W
wenjun 已提交
16

L
liudongmiao 已提交
17
    It starts system service processes from the time the kernel loads the first user-space process to the time the first application is started. In addition to loading key system processes, the module needs to configure their permissions during the startup and keep the specified process alive after sub-processes are started. If a process exits abnormally, the module needs to restart it, and to perform system reset for a special process.
W
wenjun 已提交
18 19


L
liudongmiao 已提交
20
-   appspawn\_lite
W
wenjun 已提交
21

L
liudongmiao 已提交
22
    This module can be used on the Hi3516D V300 and Hi3518E V300 platforms powered by LiteOS Cortex-A.
W
wenjun 已提交
23

L
liudongmiao 已提交
24
    This module spawns application processes upon receiving commands from the application framework, configures permissions for new processes, and calls the entry function of the application framework.
W
wenjun 已提交
25

L
liudongmiao 已提交
26
-   bootstrap\_lite
W
wenjun 已提交
27

L
liudongmiao 已提交
28
    This module can be used on the Hi3861 platform powered by LiteOS Cortex-M.
W
wenjun 已提交
29

L
liudongmiao 已提交
30
    This module provides entry identifiers for starting services and features. When Samgr starts, it will call the entry function identified by bootstrap\_lite and start system services.
W
wenjun 已提交
31

L
liudongmiao 已提交
32
-   syspara\_lite
W
wenjun 已提交
33

L
liudongmiao 已提交
34
    This module obtains and sets system attributes.
W
wenjun 已提交
35

L
liudongmiao 已提交
36
    It can be used on the Hi3861, Hi3516D V300, and Hi3518E V300 platforms powered by LiteOS Cortex-M and LiteOS Cortex-A. Supported system attributes consist of default, OEM-specified, and custom system attributes. OEM-specified system attributes provide only default values. The specific values need to be adjusted as required. For details, see  [Usage](#section8533192617117).
W
wenjun 已提交
37 38


L
liudongmiao 已提交
39
## Directory Structure<a name="section161941989596"></a>
W
wenjun 已提交
40

L
liudongmiao 已提交
41
**Table  1**  Directory structure of the source code for the startup subsystem
W
wenjun 已提交
42 43

<a name="table2977131081412"></a>
L
liudongmiao 已提交
44
<table><thead align="left"><tr id="row7977610131417"><th class="cellrowborder" valign="top" width="20.880000000000003%" id="mcps1.2.4.1.1"><p id="p18792459121314"><a name="p18792459121314"></a><a name="p18792459121314"></a>Name</p>
W
wenjun 已提交
45
</th>
L
liudongmiao 已提交
46
<th class="cellrowborder" valign="top" width="65.2%" id="mcps1.2.4.1.2"><p id="p77921459191317"><a name="p77921459191317"></a><a name="p77921459191317"></a>Description</p>
W
wenjun 已提交
47 48 49 50 51
</th>
<th class="cellrowborder" valign="top" width="13.919999999999998%" id="mcps1.2.4.1.3"><p id="p101617019356"><a name="p101617019356"></a><a name="p101617019356"></a>Applicable Platform</p>
</th>
</tr>
</thead>
L
liudongmiao 已提交
52
<tbody><tr id="row17977171010144"><td class="cellrowborder" valign="top" width="20.880000000000003%" headers="mcps1.2.4.1.1 "><p id="p2793159171311"><a name="p2793159171311"></a><a name="p2793159171311"></a>base/startup/appspawn_lite</p>
W
wenjun 已提交
53
</td>
L
liudongmiao 已提交
54
<td class="cellrowborder" valign="top" width="65.2%" headers="mcps1.2.4.1.2 "><p id="p879375920132"><a name="p879375920132"></a><a name="p879375920132"></a>appspawn_lite module for spawning application processes. It receives Ability Manager Service (AMS) messages via IPC, parses the messages, starts application processes based on the parsing result, and grants permissions to them.</p>
W
wenjun 已提交
55 56 57 58 59
</td>
<td class="cellrowborder" valign="top" width="13.919999999999998%" headers="mcps1.2.4.1.3 "><p id="p63463619360"><a name="p63463619360"></a><a name="p63463619360"></a>Hi3516DV300</p>
<p id="p141611802359"><a name="p141611802359"></a><a name="p141611802359"></a>Hi3518EV300</p>
</td>
</tr>
L
liudongmiao 已提交
60
<tr id="row6978161091412"><td class="cellrowborder" valign="top" width="20.880000000000003%" headers="mcps1.2.4.1.1 "><p id="p37931659101311"><a name="p37931659101311"></a><a name="p37931659101311"></a>base/startup/bootstrap_lite</p>
W
wenjun 已提交
61
</td>
L
liudongmiao 已提交
62
<td class="cellrowborder" valign="top" width="65.2%" headers="mcps1.2.4.1.2 "><p id="p6793059171318"><a name="p6793059171318"></a><a name="p6793059171318"></a>bootstrap_lite module for starting all services except core system services.</p>
W
wenjun 已提交
63 64 65 66
</td>
<td class="cellrowborder" valign="top" width="13.919999999999998%" headers="mcps1.2.4.1.3 "><p id="p101610019353"><a name="p101610019353"></a><a name="p101610019353"></a>Hi3861</p>
</td>
</tr>
L
liudongmiao 已提交
67
<tr id="row6978201031415"><td class="cellrowborder" align="left" valign="top" width="20.880000000000003%" headers="mcps1.2.4.1.1 "><p id="p117935599130"><a name="p117935599130"></a><a name="p117935599130"></a>base/startup/init_lite</p>
W
wenjun 已提交
68
</td>
L
liudongmiao 已提交
69
<td class="cellrowborder" valign="top" width="65.2%" headers="mcps1.2.4.1.2 "><p id="p0793185971316"><a name="p0793185971316"></a><a name="p0793185971316"></a>init_lite module for implementing the init process, which is the first user-space process loaded after the kernel is initialized. Upon startup, the process parses the configuration file in <strong id="b53451945016"><a name="b53451945016"></a><a name="b53451945016"></a>/etc/init.cfg</strong>. Based on the parsing result, the process then starts other key system processes and grants required permissions to them.</p>
W
wenjun 已提交
70 71 72 73 74
</td>
<td class="cellrowborder" valign="top" width="13.919999999999998%" headers="mcps1.2.4.1.3 "><p id="p2176757193619"><a name="p2176757193619"></a><a name="p2176757193619"></a>Hi3516DV300</p>
<p id="p51611013358"><a name="p51611013358"></a><a name="p51611013358"></a>Hi3518EV300</p>
</td>
</tr>
L
liudongmiao 已提交
75
<tr id="row1897841071415"><td class="cellrowborder" valign="top" width="20.880000000000003%" headers="mcps1.2.4.1.1 "><p id="p469782418557"><a name="p469782418557"></a><a name="p469782418557"></a>base/startup/syspara_lite</p>
W
wenjun 已提交
76
</td>
L
liudongmiao 已提交
77
<td class="cellrowborder" valign="top" width="65.2%" headers="mcps1.2.4.1.2 "><p id="p15697102412558"><a name="p15697102412558"></a><a name="p15697102412558"></a>syspara_lite module that provides APIs to obtain device information, including the product name, brand name, category name, and manufacturer name.</p>
W
wenjun 已提交
78
</td>
L
liudongmiao 已提交
79
<td class="cellrowborder" valign="top" width="13.919999999999998%" headers="mcps1.2.4.1.3 "><p id="p1956516512380"><a name="p1956516512380"></a><a name="p1956516512380"></a>Hi3861</p>
W
wenjun 已提交
80 81 82 83 84 85 86 87
<p id="p2670195353812"><a name="p2670195353812"></a><a name="p2670195353812"></a>Hi3516DV300</p>
<p id="p116118053518"><a name="p116118053518"></a><a name="p116118053518"></a>Hi3518EV300</p>
</td>
</tr>
</tbody>
</table>

```
L
liudongmiao 已提交
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
base/startup/
├── appspawn_lite             # appspawn_lite module
│   └── services
│       ├── include          # Header files for the appspawn_lite module
│       ├── src              # Source files for the appspawn_lite module
│       └── test             # Source files of the test cases for the appspawn_lite module
├── bootstrap_lite           # bootstrap_lite module
│   └── services
│       ├── source           # Source files for the bootstrap_lite module
├── init_lite                 # init_lite module
│   └── services
│       ├── include          # Header files for the init_lite module
│       ├── src              # Source files for the init_lite module
│       └── test             # Source files of the test cases for the init_lite module
└── syspara_lite              # syspara_lite module
    ├── frameworks            # Source files for the syspara_lite module
    ├── hals                  # Header files for the hardware abstraction layer of the syspara_lite module
    └── interfaces            # External APIs for the syspara_lite module
W
wenjun 已提交
106 107 108 109
```

## Constraints<a name="section1718733212019"></a>

L
liudongmiao 已提交
110
OEM-specified system attributes provide only default values. The specific values need to be adjusted as required.
W
wenjun 已提交
111

L
liudongmiao 已提交
112
## Usage<a name="section8533192617117"></a>
W
wenjun 已提交
113

L
liudongmiao 已提交
114
-   Configuration file of the init\_lite module
W
wenjun 已提交
115

L
liudongmiao 已提交
116 117 118
    The configuration file  **init.cfg**  of the init\_lite module contains service names, executable file paths, permissions, and other attributes of all key system services that need to be started by the init process. The file is stored in  **/vendor/hisilicon/hispark\_aries/init\_configs/**  under  **/etc/**. It is in JSON format, and its size cannot exceed 100 KB.

    After the init process starts, it reads the  **/etc/init.cfg**  file, parses the JSON content, and loads system services in sequence based on the parsing result. The format and content of the  **init.cfg**  file are described as follows:
W
wenjun 已提交
119 120 121 122 123


```
{
    "jobs" : [{
L
liudongmiao 已提交
124 125 126 127 128 129
            "name" : "pre-init",      -------- Job executed before the initialization. It can be used to store some operations (for example, creating a directory) performed before the init process is started.
            "cmds" : [                -------- Commands supported by the current job. Currently, only start, mkdir, chmod, chown, and mount are supported.
                                      -------- The command name and the parameters (128 bytes or less) must be separated by only one space.
                 "mkdir /testdir",      -------- Command for creating a directory. mkdir and the target directory must be separated by only one space.
                "chmod 0700 /testdir", -------- Command for modifying the permission. chmod, permission, and the target directory must be separated by only one space. The permission must be in the 0xxx format.
                "chown 99 99 /testdir",-------- Command for modifying the owner group. chown, UID, GID, and the target directory must be separated by only one space.
W
wenjun 已提交
130 131
                "mkdir /testdir2",
                "mount vfat /dev/mmcblk0p0 /testdir2 noexec nosuid" -------- mount command in the following format: mount file system type source target flags data
L
liudongmiao 已提交
132
                                                                    -------- Supported flags include only nodev, noexec, nosuid, and rdonly, which are separated by a space.
W
wenjun 已提交
133 134
            ]
        }, {
L
liudongmiao 已提交
135 136 137 138
            "name" : "init",          -------- Job name, which currently supports only pre-init, init, and post-init.
            "cmds" : [                -------- A single job currently supports a maximum of 30 commands.
                "start service1",     -------- Service startup command 1.
                "start service2"      -------- Service startup command 2. The sequence of the commands in the array can be adjusted as required. The init process then executes the commands in the same sequence as they are parsed.
W
wenjun 已提交
139 140 141 142 143 144
             ]
        }, {
             "name" : "post-init",    -------- Job executed after the initialization. It can be used to store some operations performed after the init process is started.
             "cmds" : []
        }
    ],
L
liudongmiao 已提交
145
    "services" : [{                         -------- Service set (in an array), including all system services that need to be started by the init process. Currently, a maximum of 100 services are supported.
W
wenjun 已提交
146 147
            "name" : "service1",            -------- Name of the current service. A maximum of 32 bytes must be specified for the name.
            "path" : "/bin/process1"        -------- Full path of the executable file of the current service. A maximum of 64 bytes must be specified for the path.
L
liudongmiao 已提交
148 149 150 151 152 153 154 155 156
            "uid" : 1,                      -------- UID of the current service process.
            "gid" : 1,                      -------- GID of the current service process.
            "once" : 0,                     -------- Whether the current service process is a one-off process.
                                                     0 --- The current service process is not a one-off process. If the process exits for a certain reason, the init_lite module restarts the service process upon receiving the SIGCHLD signal.
                                                   non-0 --- The current service process is a one-off process. If the process exits for a certain reason, the init_lite module does not restart the service process.
            "importance" : 1,               -------- Whether the current service process is a key system process
                                                     0 --- The current service process is not a key system process. If the process exits due to any reason, the init_lite module does not reset the system.
                                                   non-0 --- The current service process is a key system process. If the process exits due to any reason, the init_lite module resets and restarts the system upon receiving the SIGCHLD signal.
            "caps" : [0, 1, 2, 5]           -------- Capabilities required by the current service. They are determined by the capabilities supported by the security subsystem and configured in accordance with the principle of least permission. (Currently, a maximum of 100 values can be configured.)
W
wenjun 已提交
157
    }, {
L
liudongmiao 已提交
158
            "name" : "service2",            -------- Next service that needs to be started by the init_lite module. The service sequence is irrelevant to the startup sequence, which is determined by the command sequence in the previous job.
W
wenjun 已提交
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
            "path" : "/bin/process2",
            "uid" : 2,
            "gid" : 2,
            "once" : 1,
            "importance" : 0,
            "caps" : [ ]
        }
    ]
}
```

**Table  2**  Supported commands

<a name="table9623104414018"></a>
<table><thead align="left"><tr id="row5623144194017"><th class="cellrowborder" valign="top" width="12.5%" id="mcps1.2.4.1.1"><p id="p56231449404"><a name="p56231449404"></a><a name="p56231449404"></a>Name</p>
</th>
<th class="cellrowborder" valign="top" width="31.05%" id="mcps1.2.4.1.2"><p id="p962313447401"><a name="p962313447401"></a><a name="p962313447401"></a>Syntax</p>
</th>
<th class="cellrowborder" valign="top" width="56.45%" id="mcps1.2.4.1.3"><p id="p88724434113"><a name="p88724434113"></a><a name="p88724434113"></a>Description</p>
</th>
</tr>
</thead>
<tbody><tr id="row962344416405"><td class="cellrowborder" valign="top" width="12.5%" headers="mcps1.2.4.1.1 "><p id="p66231144104011"><a name="p66231144104011"></a><a name="p66231144104011"></a>start</p>
</td>
L
liudongmiao 已提交
183
<td class="cellrowborder" valign="top" width="31.05%" headers="mcps1.2.4.1.2 "><p id="p862384484010"><a name="p862384484010"></a><a name="p862384484010"></a>start ServiceName (Only one space is allowed.)</p>
W
wenjun 已提交
184
</td>
L
liudongmiao 已提交
185
<td class="cellrowborder" valign="top" width="56.45%" headers="mcps1.2.4.1.3 "><p id="p17872104184113"><a name="p17872104184113"></a><a name="p17872104184113"></a>Starts a service. The service name must be the same as that in the <strong id="b16534202920209"><a name="b16534202920209"></a><a name="b16534202920209"></a>services</strong> array in the file.</p>
W
wenjun 已提交
186 187 188 189
</td>
</tr>
<tr id="row962311443404"><td class="cellrowborder" valign="top" width="12.5%" headers="mcps1.2.4.1.1 "><p id="p13837142094117"><a name="p13837142094117"></a><a name="p13837142094117"></a>mkdir</p>
</td>
L
liudongmiao 已提交
190
<td class="cellrowborder" valign="top" width="31.05%" headers="mcps1.2.4.1.2 "><p id="p2624244204019"><a name="p2624244204019"></a><a name="p2624244204019"></a>mkdir /xxxx/xxx (Only one space is allowed.)</p>
W
wenjun 已提交
191 192 193 194 195 196
</td>
<td class="cellrowborder" valign="top" width="56.45%" headers="mcps1.2.4.1.3 "><p id="p158722484112"><a name="p158722484112"></a><a name="p158722484112"></a>Creates a directory.</p>
</td>
</tr>
<tr id="row662404414406"><td class="cellrowborder" valign="top" width="12.5%" headers="mcps1.2.4.1.1 "><p id="p3624444154011"><a name="p3624444154011"></a><a name="p3624444154011"></a>chmod</p>
</td>
L
liudongmiao 已提交
197
<td class="cellrowborder" valign="top" width="31.05%" headers="mcps1.2.4.1.2 "><p id="p7624344134020"><a name="p7624344134020"></a><a name="p7624344134020"></a>chmod 0xxx /xxx/xx (Only one space is allowed.)</p>
W
wenjun 已提交
198 199 200 201 202 203
</td>
<td class="cellrowborder" valign="top" width="56.45%" headers="mcps1.2.4.1.3 "><p id="p18872945418"><a name="p18872945418"></a><a name="p18872945418"></a>Changes the permission. The permission value must be in 0xxx format, for example, 0755 and 0600. This configuration must comply with the principle of least permission.</p>
</td>
</tr>
<tr id="row1462404494017"><td class="cellrowborder" valign="top" width="12.5%" headers="mcps1.2.4.1.1 "><p id="p136241144144013"><a name="p136241144144013"></a><a name="p136241144144013"></a>chown</p>
</td>
L
liudongmiao 已提交
204
<td class="cellrowborder" valign="top" width="31.05%" headers="mcps1.2.4.1.2 "><p id="p1624144194011"><a name="p1624144194011"></a><a name="p1624144194011"></a>chown uid gid /xxx/xx (Only one space is allowed.)</p>
W
wenjun 已提交
205 206 207 208 209 210 211 212 213
</td>
<td class="cellrowborder" valign="top" width="56.45%" headers="mcps1.2.4.1.3 "><p id="p9872246417"><a name="p9872246417"></a><a name="p9872246417"></a>Changes the owner group.</p>
</td>
</tr>
<tr id="row1285512468412"><td class="cellrowborder" valign="top" width="12.5%" headers="mcps1.2.4.1.1 "><p id="p1385515468413"><a name="p1385515468413"></a><a name="p1385515468413"></a>mount</p>
</td>
<td class="cellrowborder" valign="top" width="31.05%" headers="mcps1.2.4.1.2 "><p id="p358535124815"><a name="p358535124815"></a><a name="p358535124815"></a>mount fileSysType source target flags data</p>
<p id="p178550463412"><a name="p178550463412"></a><a name="p178550463412"></a>Only one space is allowed.</p>
</td>
L
liudongmiao 已提交
214
<td class="cellrowborder" valign="top" width="56.45%" headers="mcps1.2.4.1.3 "><p id="p1085544611415"><a name="p1085544611415"></a><a name="p1085544611415"></a>Mounts data. Currently, <strong id="b14763949182111"><a name="b14763949182111"></a><a name="b14763949182111"></a>flags</strong> supports only <strong id="b476864919213"><a name="b476864919213"></a><a name="b476864919213"></a>nodev</strong>, <strong id="b1276813498215"><a name="b1276813498215"></a><a name="b1276813498215"></a>noexec</strong>, <strong id="b18769104917216"><a name="b18769104917216"></a><a name="b18769104917216"></a>nosuid</strong>, and <strong id="b6769114932118"><a name="b6769114932118"></a><a name="b6769114932118"></a>rdonly</strong>, and other strings are considered as <strong id="b97691749142112"><a name="b97691749142112"></a><a name="b97691749142112"></a>data</strong>.</p>
W
wenjun 已提交
215 216 217 218 219 220 221 222 223 224
</td>
</tr>
</tbody>
</table>

It is worth noting that the modified  **init.cfg**  file must be in JSON format. Otherwise, the init process fails to parse the file, and no service will be started. The configured service permission  **uid/gid/capability**  must meet the requirements imposed by the security subsystem and comply with the principle of least permission. In addition, if the values of  **once**  and  **importance**  of a service are both  **0**  and the service exits for more than four consecutive times within four minutes, the init process will stop restarting the service.

-   System parameters
    -   OEM-specific system attributes

L
liudongmiao 已提交
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
        For Hi3516D V300 and Hi3518E V300 development boards, you need to modify the source files in the  **vendor/hisilicon/hispark\_aries/hals/utils/sys\_param**  directory.

        ```
        static const char HOS_PRODUCT_TYPE[] = {"****"};
        static const char HOS_MANUFACTURE[] = {"****"};
        static const char HOS_BRAND[] = {"****"};
        static const char HOS_MARKET_NAME[] = {"****"};
        static const char HOS_PRODUCT_SERIES[] = {"****"};
        static const char HOS_PRODUCT_MODEL[] = {"****"};
        static const char HOS_SOFTWARE_MODEL[] = {"****"};
        static const char HOS_HARDWARE_MODEL[] = {"****"};
        static const char HOS_HARDWARE_PROFILE[] = {"aout:true,display:true"};
        static const char HOS_BOOTLOADER_VERSION[] = {"bootloader"};
        static const char HOS_SECURE_PATCH_LEVEL[] = {"2020-6-5"};
        static const char HOS_ABI_LIST[] = {"****"};
        ```

        For Hi3861 development boards, you need to modify the source files in the  **vendor/hisilicon/hispark\_pegasus/hals/utils/sys\_param**  directory.

        ```
        static const char HOS_PRODUCT_TYPE[] = {"****"};
        static const char HOS_MANUFACTURE[] = {"****"};
        static const char HOS_BRAND[] = {"****"};
        static const char HOS_MARKET_NAME[] = {"****"};
        static const char HOS_PRODUCT_SERIES[] = {"****"};
        static const char HOS_PRODUCT_MODEL[] = {"****"};
        static const char HOS_SOFTWARE_MODEL[] = {"****"};
        static const char HOS_HARDWARE_MODEL[] = {"****"};
        static const char HOS_HARDWARE_PROFILE[] = {"aout:true,display:true"};
        static const char HOS_BOOTLOADER_VERSION[] = {"bootloader"};
        static const char HOS_SECURE_PATCH_LEVEL[] = {"2020-6-5"};
        static const char HOS_ABI_LIST[] = {"****"};
        ```

    -   Default system attributes

        ```
        char* value1 = GetProductType();
        printf("Product type =%s\n", value1);
        free(value1);
        char* value2 = GetManufacture();
        printf("Manufacture =%s\n", value2);
        free(value2);
        char* value3 = GetBrand();
        printf("GetBrand =%s\n", value3);
        free(value3);
        ```

    -   Custom system attributes

        ```
        const char* defSysParam = "data of sys param ***...";
        char key[] = "rw.parameter.key";
        char value[] = "OEM-hisi-10.1.0";
        int ret = SetParameter(key, value);
        char valueGet[128] = {0};
        ret = GetParameter(key, defSysParam, valueGet, 128);
        printf("value = %s\n", valueGet);
        ```



## Repositories Involved<a name="section1371113476307"></a>

Startup subsystem

hmf/startup/syspara\_lite

hmf/startup/appspawn\_lite

hmf/startup/bootstrap\_lite

hmf/startup/init\_lite
W
wenjun 已提交
298