OpenHarmony移植案例与原理:如何适配服务启动引导部件bootstrap_lite

x33g5p2x  于2022-02-24 转载在 Harmony  
字(15.7k)|赞(0)|评价(0)|浏览(498)

**摘要:**本文介绍移植开发板时如何适配服务启动引导部件bootstrap_lite,并介绍相关的运行机制原理。

本文分享自华为云社区《OpenHarmony移植案例与原理 - startup子系统之bootstrap_lite服务启动引导部件(1)》,作者:zhushy。

bootstrap_lite服务启动引导组件提供了各服务和功能的启动入口标识。在SAMGR(System ability manager,系统服务管理)启动时,会调用bootstrap_lite标识的入口函数,并启动系统服务。本文介绍下移植开发板时如何适配服务启动引导部件bootstrap_lite,并介绍下相关的运行机制原理。bootstrap_lite启动引导部件定义在build\lite\components\startup.json。bootstrap_lite启动引导部件源代码目录如下:

  1. base/startup/bootstrap_lite/ # 启动引导组件
  2. └── services
  3. └── source # 启动引导组件源文件目录

1、bootstrap_lite服务启动引导部件适配示例

1.1 产品解决方案配置启用部件

移植开发板适配startup子系统之bootstrap_lite服务启动引导部件时,需要在产品解决方案的config.json增加下述配置项,可以参考vendor\bestechnic\display_demo\config.json中的配置示例:

  1. {
  2. "subsystem": "startup",
  3. "components": [
  4. {
  5. "component": "bootstrap_lite"
  6. },
  7. ......
  8. ]
  9. },

1.2 使用bootstrap服务启动部件提供的初始化宏函数

然后就可以使用bootstrap服务启动部件提供的初始化宏函数SYS_SERVICE_INIT、APP_SERVICE_INIT等来自动初始化服务,示例代码可以参考device\board\fnlink\v200zr\liteos_m\at\at_wifi.c中的用法,片段如下,可以看到调用了宏函数来初始化RegisterCustomATCmd函数实现的服务。device\board\bearpi\bearpi_hm_nano\app\目录下有更多的使用示例。下文分析实现机制原理。

  1. static void RegisterCustomATCmd()
  2. {
  3. cmd_tbl_t cmd_list[] = {
  4. {"AT+IFCFG", 8, at_lwip_ifconfig, "AT+IFCFG - ifconfig\n"},
  5. {"AT+STARTAP", 7, at_start_softap, "AT+STARTAP - start wifi softap\n"},
  6. {"AT+STOPAP", 1, at_stop_softap, "AT+STOPAP - stop wifi softap\n"},
  7. {"AT+STARTSTA", 1, at_start_wifista, "AT+STARTSTA - start wifi sta\n"},
  8. {"AT+STOPSTA", 1, at_stop_wifista, "AT+STOPSTA - stop wifi sta\n"},
  9. {"AT+DHCP", 3, at_setup_dhcp, "AT+DHCP - dhcp\n"},
  10. {"AT+DHCPS", 3, at_setup_dhcps, "AT+DHCPS - dhcps\n"},
  11. };
  12. for (int i = 0; i < sizeof(cmd_list) / sizeof(cmd_tbl_t); i++) {
  13. console_cmd_add(&cmd_list[i]);
  14. }
  15. }
  16. SYS_SERVICE_INIT(RegisterCustomATCmd);

1.3 链接脚本中增加zInit代码段

适配bootstrap_lite部件时,还需要在链接脚本文件中手动新增如下段,链接脚本示例可以参考//device/soc/bestechnic/bes2600/liteos_m/sdk/bsp/out/best2600w_liteos/_best2001.lds,还可以参考device\soc\hisilicon\hi3861v100\sdk_liteos\build\link\link.ld.S。从链接脚本片段中可以看出,有.zinitcall.bsp、.zinitcall.device、.zinitcall.core、.zinitcall.sys.service、.zinitcall.sys.feature、.zinitcall.run、.zinitcall.app.service、.zinitcall.app.feature、.zinitcall.test和.zinitcall.exit等几种类型的段。

  1. /* zInit code and data - will be freed after init */
  2. .zInit (.) :
  3. {
  4. __zinitcall_bsp_start = .;
  5. KEEP (*(.zinitcall.bsp0.init))
  6. KEEP (*(.zinitcall.bsp1.init))
  7. KEEP (*(.zinitcall.bsp2.init))
  8. KEEP (*(.zinitcall.bsp3.init))
  9. KEEP (*(.zinitcall.bsp4.init))
  10. __zinitcall_bsp_end = .;
  11. . = ALIGN(4);
  12. __zinitcall_device_start = .;
  13. KEEP (*(.zinitcall.device0.init))
  14. KEEP (*(.zinitcall.device1.init))
  15. KEEP (*(.zinitcall.device2.init))
  16. KEEP (*(.zinitcall.device3.init))
  17. KEEP (*(.zinitcall.device4.init))
  18. __zinitcall_device_end = .;
  19. . = ALIGN(4);
  20. __zinitcall_core_start = .;
  21. KEEP (*(.zinitcall.core0.init))
  22. KEEP (*(.zinitcall.core1.init))
  23. KEEP (*(.zinitcall.core2.init))
  24. KEEP (*(.zinitcall.core3.init))
  25. KEEP (*(.zinitcall.core4.init))
  26. __zinitcall_core_end = .;
  27. . = ALIGN(4);
  28. __zinitcall_sys_service_start = .;
  29. KEEP (*(.zinitcall.sys.service0.init))
  30. KEEP (*(.zinitcall.sys.service1.init))
  31. KEEP (*(.zinitcall.sys.service2.init))
  32. KEEP (*(.zinitcall.sys.service3.init))
  33. KEEP (*(.zinitcall.sys.service4.init))
  34. __zinitcall_sys_service_end = .;
  35. . = ALIGN(4);
  36. __zinitcall_sys_feature_start = .;
  37. KEEP (*(.zinitcall.sys.feature0.init))
  38. KEEP (*(.zinitcall.sys.feature1.init))
  39. KEEP (*(.zinitcall.sys.feature2.init))
  40. KEEP (*(.zinitcall.sys.feature3.init))
  41. KEEP (*(.zinitcall.sys.feature4.init))
  42. __zinitcall_sys_feature_end = .;
  43. . = ALIGN(4);
  44. __zinitcall_run_start = .;
  45. KEEP (*(.zinitcall.run0.init))
  46. KEEP (*(.zinitcall.run1.init))
  47. KEEP (*(.zinitcall.run2.init))
  48. KEEP (*(.zinitcall.run3.init))
  49. KEEP (*(.zinitcall.run4.init))
  50. __zinitcall_run_end = .;
  51. . = ALIGN(4);
  52. __zinitcall_app_service_start = .;
  53. KEEP (*(.zinitcall.app.service0.init))
  54. KEEP (*(.zinitcall.app.service1.init))
  55. KEEP (*(.zinitcall.app.service2.init))
  56. KEEP (*(.zinitcall.app.service3.init))
  57. KEEP (*(.zinitcall.app.service4.init))
  58. __zinitcall_app_service_end = .;
  59. . = ALIGN(4);
  60. __zinitcall_app_feature_start = .;
  61. KEEP (*(.zinitcall.app.feature0.init))
  62. KEEP (*(.zinitcall.app.feature1.init))
  63. KEEP (*(.zinitcall.app.feature2.init))
  64. KEEP (*(.zinitcall.app.feature3.init))
  65. KEEP (*(.zinitcall.app.feature4.init))
  66. __zinitcall_app_feature_end = .;
  67. . = ALIGN(4);
  68. __zinitcall_test_start = .;
  69. KEEP (*(.zinitcall.test0.init))
  70. KEEP (*(.zinitcall.test1.init))
  71. KEEP (*(.zinitcall.test2.init))
  72. KEEP (*(.zinitcall.test3.init))
  73. KEEP (*(.zinitcall.test4.init))
  74. __zinitcall_test_end = .;
  75. . = ALIGN(4);
  76. __zinitcall_exit_start = .;
  77. KEEP (*(.zinitcall.exit0.init))
  78. KEEP (*(.zinitcall.exit1.init))
  79. KEEP (*(.zinitcall.exit2.init))
  80. KEEP (*(.zinitcall.exit3.init))
  81. KEEP (*(.zinitcall.exit4.init))
  82. __zinitcall_exit_end = .;
  83. . = ALIGN(4);
  84. } > FLASH

1.4 配置编译时链接bootstrap库

另外,bootstrap_lite部件会编译//base/startup/bootstrap_lite/services/source/bootstrap_service.c,该文件中,通过SYS_SERVICE_INIT将Init函数符号指定到__zinitcall_sys_service_start和__zinitcall_sys_service_end段中,由于没有显式调用Init函数,所以需要将它强制链接到最终的镜像。可以参考device\board\goodix\gr5515_sk\liteos_m\config.gni文件中的链接选项。恒玄的开发板适配时,是配置到vendor\bestechnic\display_demo\config.json文件中的自己定义的配置项force_link_libs里,该配置项在device\soc\bestechnic\bes2600\BUILD.gn中被解析、链接。

  1. board_ld_flags = [
  2. ....
  3. "-lbootstrap",

1.5 调用OHOS_SystemInit接口

函数void OHOS_SystemInit(void)定义在文件base\startup\bootstrap_lite\services\source\system_init.c中,在移植适配时,需要调用该接口。可以参考文件device\soc\bestechnic\bes2600\liteos_m\sdk\bsp\rtos\liteos\liteos_m\board.c中的使用示例。

  1. int main(void);
  2. extern void OHOS_SystemInit(void);
  3. ......
  4. OHOS_SystemInit();
  5. ......
  6. while (1) {
  7. osDelay(1000);
  8. TRACE(0, "main idle");
  9. }
  10. }

2、bootstrap_lite服务启动引导部件实现原理之system_init

bootstrap_lite服务启动部件实现了服务的自动初始化,即服务的初始化函数无需显式调用,它是使用宏定义的方式申明,在系统启动时自动被执行。实现原理是将服务启动的函数通过宏申明之后,放在预定义好的zInit代码段中,系统启动的时候调用OHOS_SystemInit接口,遍历该代码段并调用其中的函数。因此在适配移植时,需要在device/soc/下面具体的芯片的链接脚本中添加zInit段,并且在main函数里调用OHOS_SystemInit接口。

2.1 bootstrap_lite服务启动引导部件的初始化宏

bootstrap_lite服务启动引导部件的初始化宏定义在文件utils\native\lite\include\ohos_init.h,片段如下。初始化函数宏SYS_SERVICE_INIT(func)用于标识核心系统服务的初始化入口,该宏识别的函数在启动过程中核心系统服务优先级2阶段被调用;初始化宏SYS_SERVICE_INIT_PRI(func, priority)可以指定优先级数值,优先级的取值范围为[0,5),调用顺序为0, 1, 2, 3, 4。

  1. /**
  2. * @brief Identifies the entry for initializing and starting a core system service by the
  3. * priority 2.
  4. *
  5. * This macro is used to identify the entry called at the priority 2 in the core system
  6. * service phase of the startup process. \n
  7. *
  8. * @param func Indicates the entry function for initializing and starting a core system service.
  9. * The type is void (*)(void).
  10. */
  11. #define SYS_SERVICE_INIT(func) LAYER_INITCALL_DEF(func, sys_service, "sys.service")
  12. /**
  13. * @brief Identifies the entry for initializing and starting a core system service by the
  14. * specified priority.
  15. *
  16. * This macro is used to identify the entry called at the specified priority in the core system
  17. * service phase of the startup process. \n
  18. *
  19. * @param func Indicates the entry function for initializing and starting a core system service.
  20. * The type is void (*)(void).
  21. * @param priority Indicates the calling priority when starting the core system service in the
  22. * startup phase. The value range is [0,5), and the calling sequence is 0, 1, 2, 3, and 4.
  23. */
  24. #define SYS_SERVICE_INIT_PRI(func, priority) LAYER_INITCALL(func, sys_service, "sys.service", priority)

更多的初始化宏见下文的列表,处理这些初始化宏,还有可以指定优先级的版本XXX_PRI。

2.2 LAYER_INITCALL宏定义

从上文已知,bootstrap_lite服务启动引导部件的初始化宏会调用LAYER_INITCALL_DEF和LAYER_INITCALL宏。这些宏的定义在文件utils\native\lite\include\ohos_init.h,代码片段如下。⑴处声明函数类型,无参无返回值。⑵处处理定义分层初始化共享库宏LAYER_INIT_SHARED_LIB的情况,如果没有定义该宏,则执行⑹。在文件foundation/distributedschedule/samgr_lite/samgr/BUILD.gn中定义了该宏,在移植适配芯片开发板时,没有定义这个宏。⑶处定义5个分层初始化级别,⑷处定义7个构建值(constructor value,简称CTOR Value)。⑸处是宏LAYER_INITCALL的定义,该宏需要4个参数,分别是初始化服务或功能函数func;layer是分层名称,支持的取值为device、core、sys_service、sys_feature、app_service、app_feature和run,拼装为CTOR_VALUE_XXX;clayer参数在定义宏LAYER_INIT_SHARED_LIB时未使用;priority是优先级参数。attribute((constructor))表示这段代码将在main函数前调用。当传入参数为(myFunc, sys_feature, “sys.feature”, 2)时,函数宏替换为:static attribute((constructor(130 + 2))) void BOOT_sys_featurer2myFunc {myFunc();}。等于定义个一个新的启动引导函数BOOT_sys_featurer2myFunc()。

当没有定义LAYER_INIT_SHARED_LIB宏时,执行⑹,当传入参数为(myFunc, sys_feature, “sys.feature”, 2)时,函数宏替换为:static const InitCall attribute((used)) __zinitcall_sys_feature_myFunc attribute((section(".zinitcall.sys.feature2.init"))) = myFunc,除了__attribute__部分,等于声明一个函数类型InitCall的变量__zinitcall_sys_feature_myFunc。该函数变量放入section段".zinitcall.sys.feature2.init"内,所以移植适配时,需要在芯片开发板的链接脚本里添加zInit代码段。

  1. typedef void (*InitCall)(void);
  2. #define USED_ATTR __attribute__((used))
  3. #ifdef LAYER_INIT_SHARED_LIB
  4. #define LAYER_INIT_LEVEL_0 0
  5. #define LAYER_INIT_LEVEL_1 1
  6. #define LAYER_INIT_LEVEL_2 2
  7. #define LAYER_INIT_LEVEL_3 3
  8. #define LAYER_INIT_LEVEL_4 4
  9. #define CTOR_VALUE_device 100
  10. #define CTOR_VALUE_core 110
  11. #define CTOR_VALUE_sys_service 120
  12. #define CTOR_VALUE_sys_feature 130
  13. #define CTOR_VALUE_app_service 140
  14. #define CTOR_VALUE_app_feature 150
  15. #define CTOR_VALUE_run 700
  16. #define LAYER_INITCALL(func, layer, clayer, priority) \
  17. static __attribute__((constructor(CTOR_VALUE_##layer + LAYER_INIT_LEVEL_##priority))) \
  18. void BOOT_##layer##priority##func() {func();}
  19. #else
  20. #define LAYER_INITCALL(func, layer, clayer, priority) \
  21. static const InitCall USED_ATTR __zinitcall_##layer##_##func \
  22. __attribute__((section(".zinitcall." clayer #priority ".init"))) = func
  23. #endif
  24. // Default priority is 2, priority range is [0, 4]
  25. #define LAYER_INITCALL_DEF(func, layer, clayer) \
  26. LAYER_INITCALL(func, layer, clayer, 2)

2.3 OHOS_SystemInit函数

函数OHOS_SystemInit()定义在文件base\startup\bootstrap_lite\services\source\system_init.c,代码如下。调用宏函数MODULE_INIT、SYS_INIT和函数SAMGR_Bootstrap()进行初始化启动。

  1. void OHOS_SystemInit(void)
  2. {
  3. MODULE_INIT(bsp);
  4. MODULE_INIT(device);
  5. MODULE_INIT(core);
  6. SYS_INIT(service);
  7. SYS_INIT(feature);
  8. MODULE_INIT(run);
  9. SAMGR_Bootstrap();
  10. }

我们详细分析下宏函数MODULE_INIT和SYS_INIT的源代码,这2个宏函数在文件base\startup\bootstrap_lite\services\source\core_main.h中定义,代码如下。这些宏函数的参数大都为name和step,name取值为bsp、device、core、service、feature、run,step取值为0。从⑺和⑻处可以看出,分别调用SYS_CALL、MODULE_CALL两个宏,第二个参数设置为0。⑸处定义的MODULE_BEGIN函数,用于返回链接脚本中定义的代码段的开始地址,当传入参数为bsp时,返回&__zinitcall_bsp_start,MODULE_BEGIN函数被展开为如下片段:

  1. { extern InitCall __zinitcall_sys_start; \
  2. InitCall *initCall = &__zinitcall_bsp_start; \
  3. (initCall); \
  4. }

⑹处定义的MODULE_END函数,用于返回链接脚本中定义的代码段的结束地址,当传入参数为bsp时,返回&__zinitcall_bsp_end,MODULE_END函数被展开为如下片段:

  1. { extern InitCall __zinitcall_bsp_end; \
  2. InitCall *initCall = &__zinitcall_bsp_end; \
  3. (initCall); \
  4. }

⑶和⑷处定义的SYS_BEGIN、SYS_END代码类似,分于返回链接脚本中定义的标记系统服务或特性的代码段的开始、结束地址,即&__zinitcall_sys_service_start、&__zinitcall_sys_service_end、&__zinitcall_sys_feature_start、&__zinitcall_sys_feature_end。⑴处定义的SYS_CALL函数,分别获取链接脚本中zInit代码段的开始initcall和结束地址initend,这些地址存放的是初始化函数的地址,语句 (*initcall)()会循环调用执行这些初始化函数。⑵处MODULE_CALL宏类似。

  1. #define SYS_CALL(name, step) \
  2. do { \
  3. InitCall *initcall = (InitCall *)(SYS_BEGIN(name, step)); \
  4. InitCall *initend = (InitCall *)(SYS_END(name, step)); \
  5. for (; initcall < initend; initcall++) { \
  6. (*initcall)(); \
  7. } \
  8. } while (0)
  9. #define MODULE_CALL(name, step) \
  10. do { \
  11. InitCall *initcall = (InitCall *)(MODULE_BEGIN(name, step)); \
  12. InitCall *initend = (InitCall *)(MODULE_END(name, step)); \
  13. for (; initcall < initend; initcall++) { \
  14. (*initcall)(); \
  15. } \
  16. } while (0)
  17. ......
  18. #define SYS_BEGIN(name, step) \
  19. ({ extern InitCall __zinitcall_sys_##name##_start; \
  20. InitCall *initCall = &__zinitcall_sys_##name##_start; \
  21. (initCall); \
  22. })
  23. #define SYS_END(name, step) \
  24. ({ extern InitCall __zinitcall_sys_##name##_end; \
  25. InitCall *initCall = &__zinitcall_sys_##name##_end; \
  26. (initCall); \
  27. })
  28. #define MODULE_BEGIN(name, step) \
  29. ({ extern InitCall __zinitcall_##name##_start; \
  30. InitCall *initCall = &__zinitcall_##name##_start; \
  31. (initCall); \
  32. })
  33. #define MODULE_END(name, step) \
  34. ({ extern InitCall __zinitcall_##name##_end; \
  35. InitCall *initCall = &__zinitcall_##name##_end; \
  36. (initCall); \
  37. })
  38. #define SYS_INIT(name) \
  39. do { \
  40. SYS_CALL(name, 0); \
  41. } while (0)
  42. #define MODULE_INIT(name) \
  43. do { \
  44. MODULE_CALL(name, 0); \
  45. } while (0)

3、 bootstrap_lite服务启动引导部件实现原理之bootstrap_service

在文件base\startup\bootstrap_lite\services\source\bootstrap_service.h中定义了2个宏函数INIT_APP_CALL和INIT_TEST_CALL,分别用来调用代码段&__zinitcall_app_XXX_start、&__zinitcall_app_XXX_end和&__zinitcall_test_start、&__zinitcall_test_end之间的初始化启动函数。bootstrap_service.h文件中的宏和base\startup\bootstrap_lite\services\source\core_main.h文件中的宏类似,不再一一分析。

3.1 结构体struct Bootstrap

在文件base\startup\bootstrap_lite\services\source\bootstrap_service.c中定义了结构体struct Bootstrap,如下代码⑵处。其中结构体中的INHERIT_SERVICE定义在文件foundation/distributedschedule/samgr_lite/interfaces/kits/samgr/service.h,见代码片段⑴处。

  1. #define INHERIT_SERVICE \
  2. const char *(*GetName)(Service * service); \
  3. BOOL (*Initialize)(Service * service, Identity identity); \
  4. BOOL (*MessageHandle)(Service * service, Request * request); \
  5. TaskConfig (*GetTaskConfig)(Service * service)
  6. ......
  7. typedef struct Bootstrap {
  8. INHERIT_SERVICE;
  9. Identity identity;
  10. uint8 flag;
  11. } Bootstrap;

结构体Identity定义在文件foundation\distributedschedule\samgr_lite\interfaces\kits\samgr\message.h中,用于标识一个服务或特性。

  1. /**
  2. * @brief Identifies a service and feature.
  3. *
  4. * You can use this structure to identity a {@link IUnknown} feature to which messages will be
  5. * sent through the asynchronous function of {@link IUnknown}. \n
  6. *
  7. */
  8. struct Identity {
  9. /** Service ID */
  10. int16 serviceId;
  11. /** Feature ID */
  12. int16 featureId;
  13. /** Message queue ID */
  14. MQueueId queueId;
  15. };

3.2 Init(void)函数

讲解移植适配示例时,我们已经知道,bootstrap_lite部件会编译//base/startup/bootstrap_lite/services/source/bootstrap_service.c,该文件通过函数宏SYS_SERVICE_INIT将Init()函数符号灌段到__zinitcall_sys_service_start和__zinitcall_sys_service_end代码段中,代码片段如下。下文再详细分析GetName、Initialize、MessageHandle和GetTaskConfig函数。

  1. static const char *GetName(Service *service);
  2. static BOOL Initialize(Service *service, Identity identity);
  3. static TaskConfig GetTaskConfig(Service *service);
  4. static BOOL MessageHandle(Service *service, Request *request);
  5. static void Init(void)
  6. {
  7. static Bootstrap bootstrap;
  8. bootstrap.GetName = GetName;
  9. bootstrap.Initialize = Initialize;
  10. bootstrap.MessageHandle = MessageHandle;
  11. bootstrap.GetTaskConfig = GetTaskConfig;
  12. bootstrap.flag = FALSE;
  13. SAMGR_GetInstance()->RegisterService((Service *)&bootstrap);
  14. }
  15. SYS_SERVICE_INIT(Init);

3.3 GetName和Initialize函数

GetName函数代码如下,其中BOOTSTRAP_SERVICE定义在文件foundation\distributedschedule\samgr_lite\interfaces\kits\samgr\samgr_lite.h中,取值为"Bootstrap",表示启动引导服务。

  1. static const char *GetName(Service *service)
  2. {
  3. (void)service;
  4. return BOOTSTRAP_SERVICE;
  5. }

Initialize函数定义如下,用于设置启动引导服务的标识信息。

  1. static BOOL Initialize(Service *service, Identity identity)
  2. {
  3. Bootstrap *bootstrap = (Bootstrap *)service;
  4. bootstrap->identity = identity;
  5. return TRUE;
  6. }

3.4 MessageHandle函数和GetTaskConfig函数

MessageHandle函数和GetTaskConfig函数代码如下,MessageHandle函数用于处理各种请求,请求消息编号定义request->msgId定义在文件foundation\distributedschedule\samgr_lite\interfaces\kits\samgr\samgr_lite.h中的枚举enum BootMessage,如下⑴处所示。在MessageHandle函数中,当请求的消息编号为BOOT_SYS_COMPLETED系统服务初始化完成时,检查应用服务是否加载。当应用没有加载时,执行INIT_APP_CALL宏函数调用zInit代码段上的应用服务和应用特性初始化函数。然后执行⑶,调用函数SAMGR_SendResponseByIdentity进行响应。GetTaskConfig函数用于获取任务配置。

  1. typedef enum BootMessage {
  2. /** Message indicating that the core system service is initialized */
  3. /** 标识核心系统服务初始化完成 */
  4. BOOT_SYS_COMPLETED,
  5. /** Message indicating that the system and application-layer services are initialized */
  6. /** 标识应用层服务初始化完成 */
  7. BOOT_APP_COMPLETED,
  8. /** Message indicating service registration during running */
  9. /** 标识运行时的服务注册 */
  10. BOOT_REG_SERVICE,
  11. /** Maximum number of message IDs */
  12. /** 标识消息最大值,butt是烟蒂;屁股;枪托的意思,表示尾部吧 */
  13. BOOTSTRAP_BUTT
  14. } BootMessage;
  15. ......
  16. static BOOL MessageHandle(Service *service, Request *request)
  17. {
  18. Bootstrap *bootstrap = (Bootstrap *)service;
  19. switch (request->msgId) {
  20. case BOOT_SYS_COMPLETED:
  21. if ((bootstrap->flag & LOAD_FLAG) != LOAD_FLAG) {
  22. INIT_APP_CALL(service);
  23. INIT_APP_CALL(feature);
  24. bootstrap->flag |= LOAD_FLAG;
  25. }
  26. (void)SAMGR_SendResponseByIdentity(&bootstrap->identity, request, NULL);
  27. break;
  28. case BOOT_APP_COMPLETED:
  29. (void)SAMGR_SendResponseByIdentity(&bootstrap->identity, request, NULL);
  30. break;
  31. case BOOT_REG_SERVICE:
  32. (void)SAMGR_SendResponseByIdentity(&bootstrap->identity, request, NULL);
  33. break;
  34. default:
  35. break;
  36. }
  37. return TRUE;
  38. }
  39. static TaskConfig GetTaskConfig(Service *service)
  40. {
  41. (void)service;
  42. // The bootstrap service uses a stack of 2 KB (0x800) in size and a queue of 20 elements.
  43. // You can adjust it according to the actual situation.
  44. TaskConfig config = {LEVEL_HIGH, PRI_NORMAL, 0x800, 20, SHARED_TASK};
  45. return config;
  46. }

参考站点

​​​​​​​

小结

本文介绍了startup子系统之bootstrap_lite服务启动引导部件的移植适配案例及原理。因为时间关系,仓促写作,或能力限制,若有失误之处,请各位读者多多指正。感谢阅读,有什么问题,请留言。

点击关注,第一时间了解华为云新鲜技术~​​​​​​​

相关文章