1e41f4b71Sopenharmony_ci# Component-based Startup
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## Overview
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci### Function Introduction
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ciThis subsystem provides the following functions:
8e41f4b71Sopenharmony_ci- Builds four basic component images and provides component-based directories, including:
9e41f4b71Sopenharmony_ci  - System component: **system**
10e41f4b71Sopenharmony_ci  - Common product configuration component: **sys_prod**
11e41f4b71Sopenharmony_ci  - Chipset component: **chipset**
12e41f4b71Sopenharmony_ci  - Hardware configuration component: **chip_prod**
13e41f4b71Sopenharmony_ci- Ensures that system parameters and startup scripts can be scanned and initialized by component priority.
14e41f4b71Sopenharmony_ci- Independently compiles and builds the **system** component and **chipset** component.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ci### Basic Concepts
17e41f4b71Sopenharmony_ci- Basic Components
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci   **system**: serves as the file system mount point, and functions as a platform service irrelevant to the chipset and hardware.
20e41f4b71Sopenharmony_ci   **sys_prod**: extends and customizes capabilities of the **system** component, bears product-level differentiated capabilities, and stores product-related configuration files.
21e41f4b71Sopenharmony_ci   **chipset**: serves as the file system mount point, and offers unified hardware abstraction services for the **system** component. Same chipset platforms can use the same **chipset** component.
22e41f4b71Sopenharmony_ci   **chip_prod**: offers specific hardware capabilities of a peripheral board and product-level differentiated hardware configurations, as well as chipset-related configuration files.
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci- Component-based compilation and building
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci  Use **target_cpu** to specify the instruction set of the **system** component. Use **inherit** to inherit the common component set such as **base**, **headless**, and **rich**. Use **subsystems** to define more components for a specific product type.
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci- System parameters and startup scripts scanned and initialized by component priority
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci  System parameters and startup scripts include the CFG configuration file, PARAM file, sandbox JSON configuration file, and module plugin library file of a service. The following are related files that are in ascending order in terms of priority: **/system**, **/chipset**, **/sys_prod**, and **/chip_prod**. A file with a higher priority replaces and updates the configuration file with a lower priority.
31e41f4b71Sopenharmony_ci
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci### Constraints
34e41f4b71Sopenharmony_ciStandard and small systems support component-based compilation and building. System parameters and startup scripts are scanned and initialized by component priority.
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_ci## How to Develop
37e41f4b71Sopenharmony_ci### When to Use
38e41f4b71Sopenharmony_ciComponent-based startup enables vendors and hardware platforms to quickly develop products through modular combination. The following uses RK3568 as an example to illustrate component-based startup in detail.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci### Building and Compiling RK3568 Based on Components
41e41f4b71Sopenharmony_ciThe **//vendor/hihope/rk3568/config.json** configuration file implements components required for building the product:
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci        {
44e41f4b71Sopenharmony_ci          "product_name": "rk3568",
45e41f4b71Sopenharmony_ci          "device_company": "rockchip",
46e41f4b71Sopenharmony_ci          ...
47e41f4b71Sopenharmony_ci          "target_cpu": "arm",
48e41f4b71Sopenharmony_ci          ...
49e41f4b71Sopenharmony_ci          "inherit": [ "productdefine/common/inherit/rich.json", "productdefine/common/inherit/chipset_common.json" ],
50e41f4b71Sopenharmony_ci          "subsystems": [
51e41f4b71Sopenharmony_ci            {
52e41f4b71Sopenharmony_ci              "subsystem": "security",
53e41f4b71Sopenharmony_ci              "components": [
54e41f4b71Sopenharmony_ci                {
55e41f4b71Sopenharmony_ci                  "component": "selinux",
56e41f4b71Sopenharmony_ci                  "features": []
57e41f4b71Sopenharmony_ci                }
58e41f4b71Sopenharmony_ci              ]
59e41f4b71Sopenharmony_ci            }
60e41f4b71Sopenharmony_ci          ...
61e41f4b71Sopenharmony_ci        }
62e41f4b71Sopenharmony_ci
63e41f4b71Sopenharmony_ciThe example above indicates the product name, chipset vendor, supported instruction set, and more. **inherit** indicates the dependent common components, and **subsystems** indicates other components.
64e41f4b71Sopenharmony_ciThe following illustrates the configuration of the **system** component in the **//productdefine/common/inherit/rich.json** file. The **system** component can also include **base.json** (list of minimal components that all products must contain) and **headless.json** (list of minimal components with which products having no UI allow for application installation and management).
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci    {
67e41f4b71Sopenharmony_ci      "version": "3.0",
68e41f4b71Sopenharmony_ci      "subsystems": [
69e41f4b71Sopenharmony_ci      {
70e41f4b71Sopenharmony_ci        "subsystem": "arkui",
71e41f4b71Sopenharmony_ci        "components": [
72e41f4b71Sopenharmony_ci          {
73e41f4b71Sopenharmony_ci            "component": "ace_engine",
74e41f4b71Sopenharmony_ci            "features": []
75e41f4b71Sopenharmony_ci          },
76e41f4b71Sopenharmony_ci          {
77e41f4b71Sopenharmony_ci            "component": "napi",
78e41f4b71Sopenharmony_ci            "features": []
79e41f4b71Sopenharmony_ci          }
80e41f4b71Sopenharmony_ci        ]
81e41f4b71Sopenharmony_ci      },
82e41f4b71Sopenharmony_ci      {
83e41f4b71Sopenharmony_ci        "subsystem": "account",
84e41f4b71Sopenharmony_ci        "components": [
85e41f4b71Sopenharmony_ci          {
86e41f4b71Sopenharmony_ci            "component": "os_account",
87e41f4b71Sopenharmony_ci            "features": []
88e41f4b71Sopenharmony_ci          }
89e41f4b71Sopenharmony_ci        ]
90e41f4b71Sopenharmony_ci      },
91e41f4b71Sopenharmony_ci      ...
92e41f4b71Sopenharmony_ci    }
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci### Scanning and Initializing System Parameters by Priority
95e41f4b71Sopenharmony_ciThe following are CFG files of a service, which are in ascending order in terms of priority: **/system/etc**, **/system/etc/init**, and **/chipset/etc**. A file with a higher priority replaces and updates the configuration file with a lower priority. The following uses **/system/etc/init/camera_service.cfg** as an example:
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci      {
98e41f4b71Sopenharmony_ci        "services" : [{
99e41f4b71Sopenharmony_ci            "name" : "camera_service",
100e41f4b71Sopenharmony_ci            "path" : ["/system/bin/sa_main", "/system/profile/camera_service.xml"],
101e41f4b71Sopenharmony_ci            "uid" : "cameraserver",
102e41f4b71Sopenharmony_ci            "gid" : ["system", "shell"],
103e41f4b71Sopenharmony_ci            "secon" : "u:r:camera_service:s0",
104e41f4b71Sopenharmony_ci            "permission" : ["ohos.permission.GET_SENSITIVE_PERMISSIONS"],
105e41f4b71Sopenharmony_ci            "permission_acls" : ["ohos.permission.GET_SENSITIVE_PERMISSIONS"]
106e41f4b71Sopenharmony_ci        }]
107e41f4b71Sopenharmony_ci      }  
108e41f4b71Sopenharmony_ci
109e41f4b71Sopenharmony_ci**/chipset/etc/camera_B_service.cfg** exists at the same time.
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci       {
112e41f4b71Sopenharmony_ci        "services" : [{
113e41f4b71Sopenharmony_ci            "name" : "camera_service",
114e41f4b71Sopenharmony_ci            "path" : ["/system/bin/sa_main", "/system/profile/camera_B_service.xml"],
115e41f4b71Sopenharmony_ci            "uid" : "cameraserver",
116e41f4b71Sopenharmony_ci            "gid" : ["system", "shell"],
117e41f4b71Sopenharmony_ci            "secon" : "u:r:camera_service:s0",
118e41f4b71Sopenharmony_ci            "permission" : ["ohos.permission.GET_SENSITIVE_PERMISSIONS"],
119e41f4b71Sopenharmony_ci            "permission_acls" : ["ohos.permission.GET_SENSITIVE_PERMISSIONS"],
120e41f4b71Sopenharmony_ci            "disabled" : 1
121e41f4b71Sopenharmony_ci        }]
122e41f4b71Sopenharmony_ci      }  
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ciBased on the priority requirement, the **path** attribute of the **camera_service** service will be replaced by **["/system/bin/sa_main", "/system/profile/camera_B_service.xml"]** that has a higher priority, and the **disabled** attribute is added.
125