1 Star 0 Fork 4.9K

fish / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
bootstrap-module.md 4.28 KB
一键复制 编辑 原始数据 按行查看 历史
NEEN 提交于 2021-04-08 16:33 . fixed bugs

bootstrap Module

This module implements automatic service initialization. That is, the initialization function does not need to be explicitly called. Instead, it is declared using the macro definition and is automatically executed when the system is started. Specifically, after the function for starting a service is declared using a macro, it is placed in the predefined zInit code segment. During system startup, the OHOS_SystemInit API is called to traverse the code segment and call the functions in the code segment. Therefore, you need to include the zInit code segment in the linker script and call the OHOS_SystemInit API in the main function.

For details about how to include the zInit code segment, see the Hi3861 linker script in vendor/hisi/hi3861/hi3861/build/link/link.ld.S.

For details about the macros used by the bootstrap module to implement automatic service initialization, see API document the startup subsystem.

Available APIs

The following table describes the major macros used by the bootstrap module to implement automatic service initialization.

Table 1 Major macros for the bootstrap module

Macro Name

Description

SYS_SERVICE_INIT(func)

Entry for initializing and starting a core system service

SYS_FEATURE_INIT(func)

Entry for initializing and starting a core system feature

APP_SERVICE_INIT(func)

Entry for initializing and starting an application-layer service

APP_FEATURE_INIT(func)

Entry for initializing and starting an application-layer feature

How to Use

The following is an example of using macros to automatically initialize services.

void SystemServiceInit(void) {
    printf("Init System Service\n");
}
SYS_SERVICE_INIT(SystemServiceInit);

void SystemFeatureInit(void) {
    printf("Init System Feature\n");
}
SYS_FEATURE_INIT(SystemFeatureInit);

void AppServiceInit(void) {
    printf("Init App Service\n");
}
APP_SERVICE_INIT(AppServiceInit);

void AppFeatureInit(void) {
    printf("Init App Feature\n");
}
APP_FEATURE_INIT(AppFeatureInit);

// Logs are printed in the following sequence:
// Init System Service
// Init System Feature
// Init App Service
// Init App Feature
1
https://gitee.com/fish_neil/docs.git
git@gitee.com:fish_neil/docs.git
fish_neil
docs
docs
master

搜索帮助