1# Porting the Startup Subsystem 2 3 4The startup subsystem is responsible for starting key system processes and services after the kernel is started and before applications are started. 5 6 7## Procedure 8 9For the mini system, the startup entry identifiers of services and functions are provided. When SAMGR is started, the entry function identified by bootstrap is called and system services are started. 10 11After the adaptation is complete, call the **OHOS_SystemInit()** API to start the system. 12 13Path: **base/startup/bootstrap_lite/services/source/system_init.c** 14 15 16``` 17void OHOS_SystemInit(void) 18{ 19 MODULE_INIT(bsp); // Execute the function in the .zinitcall.bspX.init section. 20 MODULE_INIT(device); // Execute the function in the .zinitcall.deviceX.init section. 21 MODULE_INIT(core); // Execute the function in the .zinitcall.coreX.init section. 22 SYS_INIT(service); // Execute the function in the .zinitcall.sys.serviceX.init section. 23 SYS_INIT(feature); // Execute the function in the .zinitcall.sys.featureX.init section. 24 MODULE_INIT(run); // Execute the function in the .zinitcall.runX.init section. 25 SAMGR_Bootstrap(); // Initialize the SAMGR service. 26} 27``` 28 29 30## Example 31 321. Add the startup subsystem to the **config.json** file. 33 34 Path: **vendor/MyVendorCompany/MyProduct/config.json** 35 36 The sample code is as follows: 37 38 39 ``` 40 { 41 subsystem": "startup", 42 components": [ 43 { "component": "bootstrap_lite", "features":[] }, 44 { "component": "syspara_lite", "features":[] } 45 ] 46 }, 47 ``` 48 49 Some components (such as syspara_lite) in the startup subsystem depend on the modules in **$ohos_product_adapter_dir/utils**. In the preceding information, **ohos_product_adapter_dir** is the value of **product_adapter_dir** configured in the **config.json** file. Generally, **ohos_product_adapter_dir** is set to **vendor/MyVendorCompany/MyProduct/hals**. 50 511. Add the **zinitcall** and **run** definitions. 52 53 Add the following code to the **.text** section in the vendor **.ld** linking script: 54 55 56 ``` 57 __zinitcall_bsp_start = .; 58 KEEP (*(.zinitcall.bsp0.init)) 59 KEEP (*(.zinitcall.bsp1.init)) 60 KEEP (*(.zinitcall.bsp2.init)) 61 KEEP (*(.zinitcall.bsp3.init)) 62 KEEP (*(.zinitcall.bsp4.init)) 63 __zinitcall_bsp_end = .; 64 __zinitcall_device_start = .; 65 KEEP (*(.zinitcall.device0.init)) 66 KEEP (*(.zinitcall.device1.init)) 67 KEEP (*(.zinitcall.device2.init)) 68 KEEP (*(.zinitcall.device3.init)) 69 KEEP (*(.zinitcall.device4.init)) 70 __zinitcall_device_end = .; 71 __zinitcall_core_start = .; 72 KEEP (*(.zinitcall.core0.init)) 73 KEEP (*(.zinitcall.core1.init)) 74 KEEP (*(.zinitcall.core2.init)) 75 KEEP (*(.zinitcall.core3.init)) 76 KEEP (*(.zinitcall.core4.init)) 77 __zinitcall_core_end = .; 78 __zinitcall_sys_service_start = .; 79 KEEP (*(.zinitcall.sys.service0.init)) 80 KEEP (*(.zinitcall.sys.service1.init)) 81 KEEP (*(.zinitcall.sys.service2.init)) 82 KEEP (*(.zinitcall.sys.service3.init)) 83 KEEP (*(.zinitcall.sys.service4.init)) 84 __zinitcall_sys_service_end = .; 85 __zinitcall_sys_feature_start = .; 86 KEEP (*(.zinitcall.sys.feature0.init)) 87 KEEP (*(.zinitcall.sys.feature1.init)) 88 KEEP (*(.zinitcall.sys.feature2.init)) 89 KEEP (*(.zinitcall.sys.feature3.init)) 90 KEEP (*(.zinitcall.sys.feature4.init)) 91 __zinitcall_sys_feature_end = .; 92 __zinitcall_run_start = .; 93 KEEP (*(.zinitcall.run0.init)) 94 KEEP (*(.zinitcall.run1.init)) 95 KEEP (*(.zinitcall.run2.init)) 96 KEEP (*(.zinitcall.run3.init)) 97 KEEP (*(.zinitcall.run4.init)) 98 __zinitcall_run_end = .; 99 __zinitcall_app_service_start = .; // SAMGR executes the function in the .zinitcall.app.featureX.init section. 100 KEEP (*(.zinitcall.app.service0.init)) 101 KEEP (*(.zinitcall.app.service1.init)) 102 KEEP (*(.zinitcall.app.service2.init)) 103 KEEP (*(.zinitcall.app.service3.init)) 104 KEEP (*(.zinitcall.app.service4.init)) 105 __zinitcall_app_service_end = .; 106 __zinitcall_app_feature_start = .; // SAMGR executes the function in the .zinitcall.app.featureX.init section. 107 KEEP (*(.zinitcall.app.feature0.init)) 108 KEEP (*(.zinitcall.app.feature1.init)) 109 KEEP (*(.zinitcall.app.feature2.init)) 110 KEEP (*(.zinitcall.app.feature3.init)) 111 KEEP (*(.zinitcall.app.feature4.init)) 112 __zinitcall_app_feature_end = .; 113 __zinitcall_test_start = .; 114 KEEP (*(.zinitcall.test0.init)) 115 KEEP (*(.zinitcall.test1.init)) 116 KEEP (*(.zinitcall.test2.init)) 117 KEEP (*(.zinitcall.test3.init)) 118 KEEP (*(.zinitcall.test4.init)) 119 __zinitcall_test_end = .; 120 __zinitcall_exit_start = .; 121 KEEP (*(.zinitcall.exit0.init)) 122 KEEP (*(.zinitcall.exit1.init)) 123 KEEP (*(.zinitcall.exit2.init)) 124 KEEP (*(.zinitcall.exit3.init)) 125 KEEP (*(.zinitcall.exit4.init)) 126 __zinitcall_exit_end = .; 127 ``` 128 1291. The chip SDK creates a task. 130 131 Set task parameters. After the system is started, start the task. The following is an example: 132 133 134 ``` 135 void mainTask(void) { 136 // Vendor-defined function 137 OHOS_SystemInit(); // Initialize the startup subsystem. 138 printf("MainTask running...\n"); 139 } 140 141 void main(VOID) { 142 // Initialize the hardware and redirect the printf output to the debug serial port. 143 if (LOS_KernelInit() == 0) { // Initialize the kernel. 144 task_init_param.usTaskPrio = 10; // Task priority. 145 task_init_param.pcName = "mainTask"; // Task process name. 146 task_init_param.pfnTaskEntry = (TSK_ENTRY_FUNC)mainTask; // Task entry function. 147 task_init_param.uwStackSize = 8192; // Size of the task stack. 148 LOS_TaskCreate(&tid, &task_init_param); // Create a task. 149 LOS_Start(); // Start the task. 150 } 151 else { 152 printf("[BUG] LOS_KernelInit fail\n"); 153 } 154 printf("[BUG] reach to unexpected code\n"); 155 while (1); 156 } 157 ``` 158