[文章]OpenHarmony 平头哥玄铁架构 轻量系统移植—润和W800移植分享

阅读量0
0
4
本方案基于OpenHarmony LiteOS-M内核,使用联盛德W800芯片的润和软件海王星系列Neptune100开发板,进行开发移植。移植架构采用Board与SoC分离方案,支持通过Kconfig图形化配置编译选项,增加玄铁ck804ef架构移植,实现了HDF、XTS等子系统及组件的适配。

适配准备

准备ubuntu20.04系统环境,安装csky-abiv2-elf-gcc交叉编译工具链。

编译构建目录规划
本方案的目录结构使用Board和Soc解耦的思路:
芯片适配目录规划为:
  1. device
  2. ├── board                                --- 单板厂商目录
  3. │   └── hihope                           --- 单板厂商名字:HiHope
  4. │       └── neptune100                   --- 单板名:Neptune100
  5. └── soc                                  --- SoC厂商目录
  6.     └── winnermicro                      --- SoC厂商名字:联盛德
  7.         └── wm800                        --- SoC Series名:w800系列芯片
复制代码
产品样例目录规划为:
  1. vendor
  2. └── hihope                               --- 开发产品样例厂商目录,润和软件的产品样例
  3.     ├── neptune_iotlink_demo             --- 产品名字:Neptune100产品样例代码
  4.     └── ...
复制代码
产品定义
vendor/hihope/neptune_iotlink_demo/config.json文件下,描述了产品使用的内核、单板、子系统等信息。其中,内核、单板型号、单板厂商需提前规划好,是预编译指令hb set关注的。例如:

  1. <pre><span id="LC1" class="line">{</span>
  2. <span id="LC2" class="line">  "product_name": "neptune_iotlink_demo",   --- 产品名</span>
  3. <span id="LC3" class="line">  "ohos_version": "OpenHarmony 3.1",        --- 使用的OS版本</span>
  4. <span id="LC4" class="line">  "type":"mini",                            --- 系统类型: mini</span>
  5. <span id="LC5" class="line">  "version": "3.0",                         --- 系统版本: 3.0</span>
  6. <span id="LC6" class="line">  "device_company": "hihope",               --- 单板厂商:hihope</span>
  7. <span id="LC7" class="line">  "board": "neptune100",                    --- 单板名:neptune100</span>
  8. <span id="LC8" class="line">  "kernel_type": "liteos_m",                --- 内核类型:liteos_m</span>
  9. <span id="LC9" class="line">  "kernel_version": "3.0.0",                --- 内核版本:3.0.0</span>
  10. <span id="LC10" class="line">  "subsystems": []                          --- 子系统</span>
  11. <span id="LC11" class="line">}</span></pre>

  12. <!--StartFragment--><!--EndFragment-->
复制代码

填入的信息与规划的目录相对应,其中device_company和board用于关联出device/board/<device_company>/目录。

单板配置关联到的目录下,在device/board/hihope/neptune100/liteos_m目录下放置config.gni文件,该配置文件用于描述该单板信息,包括CPU型号、交叉编译工具链及全局编译、链接参数等重要信息:
  1. <pre><span id="LC1" class="line"># Kernel type, e.g. "linux", "liteos_a", "liteos_m".</span>
  2. <span id="LC2" class="line">kernel_type = "liteos_m"</span>
  3. <span id="LC3" class="line"></span>
  4. <span id="LC4" class="line"># Kernel version.</span>
  5. <span id="LC5" class="line">kernel_version = "3.0.0"</span>
  6. <span id="LC6" class="line"></span>
  7. <span id="LC7" class="line"># Board CPU type, e.g. "cortex-a7", "riscv32".</span>
  8. <span id="LC8" class="line">board_cpu = "ck804ef"</span>
  9. <span id="LC9" class="line"></span>
  10. <span id="LC10" class="line"># Board arch, e.g.  "armv7-a", "rv32imac".</span>
  11. <span id="LC11" class="line">board_arch = "ck803"</span>
  12. <span id="LC12" class="line"></span>
  13. <span id="LC13" class="line"># Toolchain name used for system compiling.</span>
  14. <span id="LC14" class="line"># E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang,  riscv32-unknown-elf.</span>
  15. <span id="LC15" class="line"># Note: The default toolchain is "ohos-clang". It's not mandatory if you use the default toolchain.</span>
  16. <span id="LC16" class="line">board_toolchain = "csky-elfabiv2-gcc"</span>
  17. <span id="LC17" class="line"></span>
  18. <span id="LC18" class="line">#use_board_toolchain = true</span>
  19. <span id="LC19" class="line"></span>
  20. <span id="LC20" class="line"># The toolchain path installed, it's not mandatory if you have added toolchain path to your ~/.bashrc.</span>
  21. <span id="LC21" class="line">board_toolchain_path = ""</span>
  22. <span id="LC22" class="line"></span>
  23. <span id="LC23" class="line"># Compiler prefix.</span>
  24. <span id="LC24" class="line">board_toolchain_prefix = "csky-elfabiv2-"</span>
  25. <span id="LC25" class="line"></span>
  26. <span id="LC26" class="line"># Compiler type, "gcc" or "clang".</span>
  27. <span id="LC27" class="line">board_toolchain_type = "gcc"</span>
  28. <span id="LC28" class="line"></span>
  29. <span id="LC29" class="line"># config.json parse</span>
  30. <span id="LC30" class="line">if (product_path != "") {</span>
  31. <span id="LC31" class="line">  product_conf = read_file("${product_path}/config.json", "json")</span>
  32. <span id="LC32" class="line">  product_name = product_conf.product_name</span>
  33. <span id="LC33" class="line">  bin_list = product_conf.bin_list</span>
  34. <span id="LC34" class="line">}</span>
  35. <span id="LC35" class="line"></span>
  36. <span id="LC36" class="line"># Board related common compile flags.</span>
  37. <span id="LC37" class="line">board_cflags = [</span>
  38. <span id="LC38" class="line">  "-mcpu=ck804ef",</span>
  39. <span id="LC39" class="line">  "-mhard-float",</span>
  40. <span id="LC40" class="line">  "-DGCC_COMPILE=1",</span>
  41. <span id="LC41" class="line">  "-DTLS_CONFIG_CPU_XT804=1",</span>
  42. <span id="LC42" class="line">  "-DNIMBLE_FTR=1",</span>
  43. <span id="LC43" class="line">  "-D__CSKY_V2__=1",</span>
  44. <span id="LC44" class="line">  "-DCPU_CK804",</span>
  45. <span id="LC45" class="line">  "-O2",</span>
  46. <span id="LC46" class="line">  "-g3",</span>
  47. <span id="LC47" class="line">  "-Wall",</span>
  48. <span id="LC48" class="line">  "-ffunction-sections",</span>
  49. <span id="LC49" class="line">  "-MMD",</span>
  50. <span id="LC50" class="line">  "-MP",</span>
  51. <span id="LC51" class="line">]</span>
  52. <span id="LC52" class="line"></span>
  53. <span id="LC53" class="line">board_cxx_flags = board_cflags</span>
  54. <span id="LC54" class="line"></span>
  55. <span id="LC55" class="line">board_asmflags = [</span>
  56. <span id="LC56" class="line">  "-mcpu=ck804ef",</span>
  57. <span id="LC57" class="line">  "-DCPU_CK804",</span>
  58. <span id="LC58" class="line">]</span>
  59. <span id="LC59" class="line"></span>
  60. <span id="LC60" class="line">board_ld_flags = []</span>
  61. <span id="LC61" class="line"></span>
  62. <span id="LC62" class="line"># Board related headfiles search path.</span>
  63. <span id="LC63" class="line">board_include_dirs = []</span>
  64. <span id="LC64" class="line"></span>
  65. <span id="LC65" class="line"># Board adapter dir for OHOS components.</span>
  66. <span id="LC66" class="line">board_adapter_dir = ""</span>
  67. <span id="LC67" class="line"></span>
  68. <span id="LC68" class="line"># Sysroot path.</span>
  69. <span id="LC69" class="line">board_configed_sysroot = ""</span>
  70. <span id="LC70" class="line"></span>
  71. <span id="LC71" class="line"># Board storage type, it used for file system generation.</span>
  72. <span id="LC72" class="line">storage_type = ""</span></pre>

  73. <!--StartFragment--><!--EndFragment-->
复制代码

预编译在工程根目录下输入预编译指令hb set可显示相关产品信息,如下:
  1. <pre><span id="LC1" class="line">hb set</span>
  2. <span id="LC2" class="line">OHOS Which product do you need?  (Use arrow keys)</span>
  3. <span id="LC3" class="line"></span>
  4. <span id="LC4" class="line">hihope</span>
  5. <span id="LC5" class="line"> > neptune_iotlink_demo</span>
  6. <span id="LC6" class="line"></span>
  7. <span id="LC7" class="line">OHOS Which product do you need?  neptune_iotlink_demo</span></pre>

  8. <!--StartFragment--><!--EndFragment-->
复制代码

执行hb set后,会在根目录下自动生成ohos_config.json文件,文件中会列出待编译的产品信息。

通过hb env可以查看选择出来的预编译环境变量。
  1. <pre><span id="LC1" class="line">[OHOS INFO] root path: /home/xxxx/openharmony_w800</span>
  2. <span id="LC2" class="line">[OHOS INFO] board: neptune100</span>
  3. <span id="LC3" class="line">[OHOS INFO] kernel: liteos_m</span>
  4. <span id="LC4" class="line">[OHOS INFO] product: neptune_iotlink_demo</span>
  5. <span id="LC5" class="line">[OHOS INFO] product path: /home/xxxx/openharmony_w800/vendor/hihope/neptune_iotlink_demo</span>
  6. <span id="LC6" class="line">[OHOS INFO] device path: /home/xxxx/openharmony_w800/device/board/hihope/neptune100/liteos_m</span>
  7. <span id="LC7" class="line">[OHOS INFO] device company: hihope</span></pre>

  8. <!--StartFragment--><!--EndFragment-->
复制代码

至此,预编译适配完成,但工程还不能执行hb build进行编译,还需要准备好后续的LiteOS-M内核移植。


内核移植Kconfig适配在kernel/liteos_m的编译中,需要在相应的单板以及SoC目录下使用Kconfig文件进行索引。
  • 在vendor/hihope/neptune_iotlink_demo目录下创建kernel_configs目录,并创建debug.config空文件。
  • 打开kernel/liteos_m/Kconfig文件,可以看到在该文件通过orsource命令导入了device/board和device/soc下多个Kconfig文件,后续需要创建并修改这些文件:
  1. <pre><span id="LC1" class="line">orsource "../../device/board/*/Kconfig.liteos_m.shields"</span>
  2. <span id="LC2" class="line">orsource "../../device/board/$(BOARD_COMPANY)/Kconfig.liteos_m.defconfig.boards"</span>
  3. <span id="LC3" class="line">orsource "../../device/board/$(BOARD_COMPANY)/Kconfig.liteos_m.boards"</span>
  4. <span id="LC4" class="line">orsource "../../device/soc/*/Kconfig.liteos_m.defconfig"</span>
  5. <span id="LC5" class="line">orsource "../../device/soc/*/Kconfig.liteos_m.series"</span>
  6. <span id="LC6" class="line">orsource "../../device/soc/*/Kconfig.liteos_m.soc"</span></pre>

  7. <!--StartFragment--><!--EndFragment-->
复制代码


在device/board/hihope下创建相应的的Kconfig文件:

  1. ├──  neptune100                                  --- neptune100单板配置目录
  2. │   ├── Kconfig.liteos_m.board                   --- 单板的配置选项
  3. │   ├── Kconfig.liteos_m.defconfig.board         --- 单板的默认配置项
  4. │   └── liteos_m
  5. │       └── config.gni                           --- 单板的配置文件
  6. ├── Kconfig.liteos_m.boards                      --- 单板厂商下Boards配置信息
  7. └── Kconfig.liteos_m.defconfig.boards            --- 单板厂商下Boards默认配置信息
复制代码
  • 修改Board目录下Kconfig文件内容:
在 neptune100/Kconfig.liteos_m.board中添加,
  1. <pre><span id="LC1" class="line">config BOARD_NEPTUNE100</span>
  2. <span id="LC2" class="line">    bool "select board neptune100"</span>
  3. <span id="LC3" class="line">    depends on SOC_WM800</span></pre>

  4. <!--StartFragment--><!--EndFragment-->
复制代码

配置只有SOC_WM800被选后,BOARD_NEPTUNE100才可被选。
在 neptune100/Kconfig.liteos_m.defconfig.board中添加,
  1. if BOARD_NEPTUNE100

  2. endif #BOARD_NEPTUNE100
复制代码
用于添加 BOARD_NEPTUNE100默认配置
  • 在device/soc/winnermicro下创建相应的的Kconfig文件:
  1. ├── wm800                                        --- W800系列
  2. │   ├── Kconfig.liteos_m.defconfig.wm800         --- W800芯片默认配置
  3. │   ├── Kconfig.liteos_m.defconfig.series        --- W800系列默认配置
  4. │   ├── Kconfig.liteos_m.series                  --- W800系列配置
  5. │   └── Kconfig.liteos_m.soc                     --- W800芯片配置
  6. ├── Kconfig.liteos_m.defconfig                   --- SoC默认配置
  7. ├── Kconfig.liteos_m.series                      --- Series配置
  8. └── Kconfig.liteos_m.soc                         --- SoC配置
复制代码
  • 修改Soc目录下Kconfig文件内容:
在wm800/Kconfig.liteos_m.defconfig.wm800中添加:

  1. <pre><span id="LC1" class="line">config SOC</span>
  2. <span id="LC2" class="line">    string</span>
  3. <span id="LC3" class="line">    default "wm800"</span>
  4. <span id="LC4" class="line">    depends on SOC_WM800</span></pre>

  5. <!--StartFragment--><!--EndFragment-->
复制代码

在wm800/Kconfig.liteos_m.defconfig.series中添加:
  1. <pre><span id="LC1" class="line">if SOC_SERIES_WM800</span>
  2. <span id="LC2" class="line"></span>
  3. <span id="LC3" class="line">rsource "Kconfig.liteos_m.defconfig.wm800"</span>
  4. <span id="LC4" class="line"></span>
  5. <span id="LC5" class="line">config SOC_SERIES</span>
  6. <span id="LC6" class="line">    string</span>
  7. <span id="LC7" class="line">    default "wm800"</span>
  8. <span id="LC8" class="line"></span>
  9. <span id="LC9" class="line">endif</span></pre>

  10. <!--StartFragment--><!--EndFragment-->
复制代码

在 wm800/Kconfig.liteos_m.series中添加:

  1. <pre><span id="LC1" class="line">config SOC_SERIES_WM800</span>
  2. <span id="LC2" class="line">    bool "winnermicro 800 Series"</span>
  3. <span id="LC3" class="line">    select ARM</span>
  4. <span id="LC4" class="line">    select SOC_COMPANY_WINNERMICRO              --- 选择 SOC_COMPANY_WINNERMICRO</span>
  5. <span id="LC5" class="line">    select CPU_XT804</span>
  6. <span id="LC6" class="line">    help</span>
  7. <span id="LC7" class="line">        Enable support for winnermicro 800 series</span></pre>

  8. <!--StartFragment--><!--EndFragment-->
复制代码

在选择了 SOC_SERIES_WM800之后,才可选 wm800/Kconfig.liteos_m.soc文件中的 SOC_WM800:

  1. <pre><span id="LC1" class="line">choice</span>
  2. <span id="LC2" class="line">    prompt "Winnermicro 800 series SoC"</span>
  3. <span id="LC3" class="line">    depends on SOC_SERIES_WM800</span>
  4. <span id="LC4" class="line"></span>
  5. <span id="LC5" class="line">config SOC_WM800                         --- 选择 SOC_WM800</span>
  6. <span id="LC6" class="line">    bool "SoC WM800"</span>
  7. <span id="LC7" class="line"></span>
  8. <span id="LC8" class="line">endchoice</span></pre>

  9. <!--StartFragment--><!--EndFragment-->
复制代码

综上所述,要编译单板BOARD_NEPTUNE100,则要分别选中:SOC_COMPANY_WINNERMICRO、SOC_SERIES_WM800、SOC_WM800 7. 在kernel/liteos_m中执行make menuconfig进行选择配置,能够对SoC Series进行选择:

配置后的文件会默认保存在vendor/hihope/neptune_iotlink_demo/kernel_configs/debug.config,也可以直接填写debug.config:
  1. LOSCFG_PLATFORM_QEMU_CSKY_SMARTL=y
  2. LOSCFG_SOC_SERIES_WM800=y
复制代码
模块化编译
Board和SoC的编译采用模块化的编译方法,从kernel/liteos_m/BUILD.gn开始逐级向下递增。本方案的适配过程如下:
  • 在device/board/hihope中新建文件BUILD.gn,新增内容如下:

  1. <pre><span id="LC1" class="line">if (ohos_kernel_type == "liteos_m") {</span>
  2. <span id="LC2" class="line">  import("//kernel/liteos_m/liteos.gni")</span>
  3. <span id="LC3" class="line">  module_name = get_path_info(rebase_path("."), "name")</span>
  4. <span id="LC4" class="line">  module_group(module_name) {</span>
  5. <span id="LC5" class="line">    modules = [</span>
  6. <span id="LC6" class="line">      "neptune100",                     --- 单板模块</span>
  7. <span id="LC7" class="line">      "shields",</span>
  8. <span id="LC8" class="line">    ]</span>
  9. <span id="LC9" class="line">  }</span>
  10. <span id="LC10" class="line">}</span></pre>

  11. <!--StartFragment--><!--EndFragment-->
复制代码

  • 在上述BUILD.gn中,neptune100以及shields即是按目录层级组织的模块名。
  • 在device/soc/winnermicro中,新建文件BUILD.gn,按目录层级组织,新增内容如下:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;if (ohos_kernel_type == &quot;liteos_m&quot;) {&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;  import(&quot;//kernel/liteos_m/liteos.gni&quot;)&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;  module_name = get_path_info(rebase_path(&quot;.&quot;), &quot;name&quot;)&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;  module_group(module_name) {&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;    modules = [&lt;/span&gt;
  6. &lt;span id=&quot;LC6&quot; class=&quot;line&quot;&gt;     &quot;hals&quot;,&lt;/span&gt;
  7. &lt;span id=&quot;LC7&quot; class=&quot;line&quot;&gt;     &quot;wm800&quot;,&lt;/span&gt;
  8. &lt;span id=&quot;LC8&quot; class=&quot;line&quot;&gt;    ]&lt;/span&gt;
  9. &lt;span id=&quot;LC9&quot; class=&quot;line&quot;&gt;  }&lt;/span&gt;
  10. &lt;span id=&quot;LC10&quot; class=&quot;line&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;

  11. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
在device/soc/winnermicro各个层级模块下,同样新增文件BUILD.gn,将该层级模块加入编译。以device/soc/winnermicro/wm800/board/platform/sys/BUILD.gn为例:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;import(&quot;//kernel/liteos_m/liteos.gni&quot;)&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;module_name = get_path_info(rebase_path(&quot;.&quot;), &quot;name&quot;)&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;kernel_module(module_name) {             --- 编译的模块&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;  sources = [                            --- 编译的源文件&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;    &quot;wm_main.c&quot;,&lt;/span&gt;
  6. &lt;span id=&quot;LC6&quot; class=&quot;line&quot;&gt;  ]&lt;/span&gt;
  7. &lt;span id=&quot;LC7&quot; class=&quot;line&quot;&gt;  include_dirs = [                       --- 模块内使用到的头文件&lt;/span&gt;
  8. &lt;span id=&quot;LC8&quot; class=&quot;line&quot;&gt;    &quot;.&quot;,&lt;/span&gt;
  9. &lt;span id=&quot;LC9&quot; class=&quot;line&quot;&gt;  ]&lt;/span&gt;
  10. &lt;span id=&quot;LC10&quot; class=&quot;line&quot;&gt;}&lt;/span&gt;
  11. &lt;span id=&quot;LC11&quot; class=&quot;line&quot;&gt;&lt;/span&gt;&lt;/pre&gt;

  12. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
为了组织链接以及一些编译选项,在device/soc/winnermicro/wm800/board/BUILD.gn下的config("board_config")填入了相应的参数:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;config(&quot;board_config&quot;) {&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;  ldflags = []                            --- 链接参数,包括ld文件&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;  libs = []                               --- 链接库&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;  include_dirs = []                       --- 公共头文件&lt;/span&gt;&lt;/pre&gt;

  5. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
为了组织一些产品侧的应用,需要强制链接到产品工程中来,本方案在vendor相应的config.json加入了相应的list来组织,在vendor/hihope/neptune_iotlink_demo/config.json增加对应的list:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt; &quot;bin_list&quot;: [                       --- demo list&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;   {&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;     &quot;elf_name&quot;: &quot;hihope&quot;,&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;     &quot;enable&quot;: &quot;false&quot;,                 --- list开关&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;     &quot;force_link_libs&quot;: [&lt;/span&gt;
  6. &lt;span id=&quot;LC6&quot; class=&quot;line&quot;&gt;       &quot;bootstrap&quot;,&lt;/span&gt;
  7. &lt;span id=&quot;LC7&quot; class=&quot;line&quot;&gt;       &quot;broadcast&quot;,&lt;/span&gt;
  8. &lt;span id=&quot;LC8&quot; class=&quot;line&quot;&gt;       ...&lt;/span&gt;
  9. &lt;span id=&quot;LC9&quot; class=&quot;line&quot;&gt;     ]&lt;/span&gt;
  10. &lt;span id=&quot;LC10&quot; class=&quot;line&quot;&gt;   }&lt;/span&gt;&lt;/pre&gt;

  11. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
将demo应用作为模块库来管理,开启/关闭某个demo,在bin_list中增减相应库文件即可。bin_list在gn中可以直接被读取,在device/board/hihope/neptune100/liteos_m/config.gni新增内容:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;# config.json parse&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;if (product_path != &quot;&quot;) {&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;  product_conf = read_file(&quot;${product_path}/config.json&quot;, &quot;json&quot;)&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;  product_name = product_conf.product_name&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;  bin_list = product_conf.bin_list&lt;/span&gt;
  6. &lt;span id=&quot;LC6&quot; class=&quot;line&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;

  7. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
读取list后即可在相应的链接选项上加入相关的组件库,在//device/soc/winnermicro/wm800/BUILD.gn添加内容:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;foreach(bin_file, bin_list) {&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;   build_enable = bin_file.enable&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;   ...&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;   if(build_enable == &quot;true&quot;)&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;   {&lt;/span&gt;
  6. &lt;span id=&quot;LC6&quot; class=&quot;line&quot;&gt;     ...&lt;/span&gt;
  7. &lt;span id=&quot;LC7&quot; class=&quot;line&quot;&gt;     foreach(force_link_lib, bin_file.force_link_libs) {&lt;/span&gt;
  8. &lt;span id=&quot;LC8&quot; class=&quot;line&quot;&gt;     ldflags += [ &quot;-l${force_link_lib}&quot; ]&lt;/span&gt;
  9. &lt;span id=&quot;LC9&quot; class=&quot;line&quot;&gt;     }&lt;/span&gt;
  10. &lt;span id=&quot;LC10&quot; class=&quot;line&quot;&gt;     ...&lt;/span&gt;
  11. &lt;span id=&quot;LC11&quot; class=&quot;line&quot;&gt;   }&lt;/span&gt;
  12. &lt;span id=&quot;LC12&quot; class=&quot;line&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;

  13. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
内核子系统适配
在vendor/hihope/neptune_iotlink_demo/config.json添加内核子系统及相关配置,如下:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;&quot;subsystems&quot;: [&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt; {&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;   &quot;subsystem&quot;: &quot;kernel&quot;,&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;   &quot;components&quot;: [&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;     { &quot;component&quot;: &quot;liteos_m&quot;, &quot;features&quot;:[]&lt;/span&gt;
  6. &lt;span id=&quot;LC6&quot; class=&quot;line&quot;&gt;     }&lt;/span&gt;
  7. &lt;span id=&quot;LC7&quot; class=&quot;line&quot;&gt;   ]&lt;/span&gt;
  8. &lt;span id=&quot;LC8&quot; class=&quot;line&quot;&gt;},&lt;/span&gt;&lt;/pre&gt;

  9. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
内核启动适配
由于Neptune100开发板的芯片架构为Openharmony不支持的ck804ef架构,需要进行ck804ef架构移植。适配 kernelliteos_marchinclude中定义的通用的文件以及函数列表,并放在了 kernelliteos_marchcskyv2ck804gcc文件夹下。
内核初始化示例如下:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;osStatus_t ret = osKernelInitialize();                    --- 内核初始化&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;if(ret == osOK)&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;{&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt; threadId = osThreadNew((osThreadFunc_t)sys_init,NULL,&amp;g_main_task); --- 创建init线程&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt; if(threadId!=NULL)&lt;/span&gt;
  6. &lt;span id=&quot;LC6&quot; class=&quot;line&quot;&gt; {&lt;/span&gt;
  7. &lt;span id=&quot;LC7&quot; class=&quot;line&quot;&gt;     osKernelStart();                                          --- 线程调度&lt;/span&gt;
  8. &lt;span id=&quot;LC8&quot; class=&quot;line&quot;&gt; }&lt;/span&gt;
  9. &lt;span id=&quot;LC9&quot; class=&quot;line&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;

  10. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
board_main在启动OHOS_SystemInit之前,需要初始化必要的动作,如下:
  1. ...
  2. UserMain();         --- 启动OpenHarmony  OHOS_SystemInit的之前完成驱动的初始化
  3. ...
  4. OHOS_SystemInit();  --- 启动OpenHarmony服务,以及组件初始化
  5. ...
复制代码
UserMain函数在device/soc/winnermicro/wm800/board/app/main.c文件中,如下:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;...&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;if (DeviceManagerStart()) {                                      --- HDF初始化&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;    printf(&quot;[%s] No drivers need load by hdf manager!&quot;,__func__);&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;}&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;...&lt;/span&gt;&lt;/pre&gt;

  6. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
HDF驱动框架适配

HDF驱动框架提供了一套应用访问硬件的统一接口,可以简化应用开发,添加HDF组件需要在//vendor/hihope/neptune_iotlink_demo/kernel_configs添加:
  1. LOSCFG_DRIVERS_HDF=y
  2. LOSCFG_DRIVERS_HDF_PLATFORM=y
复制代码
驱动适配相关文件放置在drivers/adapter/platform中,对应有gpio,i2c,pwm,spi,uart,watchdog,都是通过HDF机制加载,本章节以GPIO和UART为例进行详细说明。
GPIO适配
  • 芯片驱动适配文件位于drivers/adapter/platform目录,在gpio目录增加gpio_wm.c文件,在BUILD.gn文件中,描述了W800驱动的编译适配。如下:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;...&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) {&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;  sources += [ &quot;gpio_wm.c&quot; ]&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;}&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;...&lt;/span&gt;&lt;/pre&gt;

  6. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
gpio_wm.c中驱动描述文件如下:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;/* HdfDriverEntry definitions */&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;struct HdfDriverEntry g_GpioDriverEntry = {&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;    .moduleVersion = 1,&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;    .moduleName = &quot;WM_GPIO_MODULE_HDF&quot;,&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;    .Bind = GpioDriverBind,&lt;/span&gt;
  6. &lt;span id=&quot;LC6&quot; class=&quot;line&quot;&gt;    .Init = GpioDriverInit,&lt;/span&gt;
  7. &lt;span id=&quot;LC7&quot; class=&quot;line&quot;&gt;    .Release = GpioDriverRelease,&lt;/span&gt;
  8. &lt;span id=&quot;LC8&quot; class=&quot;line&quot;&gt;};&lt;/span&gt;
  9. &lt;span id=&quot;LC9&quot; class=&quot;line&quot;&gt;HDF_INIT(g_GpioDriverEntry);&lt;/span&gt;&lt;/pre&gt;

  10. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
在device/board/hihope/shields/neptune100/neptune100.hcs添加gpio硬件描述信息, 添加内容如下:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;root {&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;    platform {&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;     gpio_config {&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;         match_attr = &quot;gpio_config&quot;;&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;         groupNum = 1;&lt;/span&gt;
  6. &lt;span id=&quot;LC6&quot; class=&quot;line&quot;&gt;         pinNum = 48;&lt;/span&gt;
  7. &lt;span id=&quot;LC7&quot; class=&quot;line&quot;&gt;     }&lt;/span&gt;
  8. &lt;span id=&quot;LC8&quot; class=&quot;line&quot;&gt;    }&lt;/span&gt;
  9. &lt;span id=&quot;LC9&quot; class=&quot;line&quot;&gt;}&lt;/span&gt;&lt;/pre&gt;

  10. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
在GpioDriverInit获取hcs参数进行初始化,如下:

  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt; ...&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt; gpioCntlr = GpioCntlrFromHdfDev(device);        --- gpioCntlr节点变量获取具体gpio配置&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt; if (gpioCntlr == NULL) {&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;     HDF_LOGE(&quot;GpioCntlrFromHdfDev fail
  5. &quot;);&lt;/span&gt;
  6. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;     return HDF_DEV_ERR_NO_DEVICE_SERVICE;&lt;/span&gt;
  7. &lt;span id=&quot;LC6&quot; class=&quot;line&quot;&gt; }&lt;/span&gt;
  8. &lt;span id=&quot;LC7&quot; class=&quot;line&quot;&gt; ...&lt;/span&gt;&lt;/pre&gt;

  9. &lt;!--StartFragment--&gt;&lt;!--EndFragment--&gt;
复制代码
UART适配
  • 芯片驱动适配文件位于drivers/adapter/platform目录,在uart目录增加uart_wm.c文件,在BUILD.gn文件中,描述了W800驱动的编译适配。如下:


  1. &lt;pre&gt;&lt;span id=&quot;LC1&quot; class=&quot;line&quot;&gt;...&lt;/span&gt;
  2. &lt;span id=&quot;LC2&quot; class=&quot;line&quot;&gt;if (defined(LOSCFG_SOC_COMPANY_WINNERMICRO)) {&lt;/span&gt;
  3. &lt;span id=&quot;LC3&quot; class=&quot;line&quot;&gt;  sources += [ &quot;uart_wm.c&quot; ]&lt;/span&gt;
  4. &lt;span id=&quot;LC4&quot; class=&quot;line&quot;&gt;}&lt;/span&gt;
  5. &lt;span id=&quot;LC5&quot; class=&quot;line&quot;&gt;...&lt;/span&gt; &lt;/pre&gt;
复制代码
uart_wm.c中驱动描述文件如下:
  1. /* HdfDriverEntry definitions */
  2. struct HdfDriverEntry g_UartDriverEntry = {
  3.     .moduleVersion = 1,
  4.     .moduleName = &amp;amp;amp;quot;W800_UART_MODULE_HDF&amp;amp;amp;quot;,
  5.     .Bind = UartDriverBind,
  6.     .Init = UartDriverInit,
  7.     .Release = UartDriverRelease,
  8. };

  9. /* Initialize HdfDriverEntry */
  10. HDF_INIT(g_UartDriverEntry);
复制代码
  • 在device/board/hihope/shields/neptune100/neptune100.hcs添加uart硬件描述信息, 添加内容如下:
  1. root {
  2.     platform {
  3.      uart_config {
  4.      /*
  5.          uart0 {
  6.              match_attr = &amp;amp;amp;quot;uart0_config&amp;amp;amp;quot;;
  7.              num = 0;
  8.              baudrate = 115200;
  9.              parity = 0;
  10.              stopBit = 1;
  11.              data = 8;
  12.          }*/
  13.          uart1 {
  14.              match_attr = &amp;amp;amp;quot;uart1_config&amp;amp;amp;quot;;
  15.              num = 1;
  16.              baudrate = 115200;
  17.              parity = 0;
  18.              stopBit = 1;
  19.              data = 8;
  20.          }
  21.       }
  22.    }
  23. }
复制代码
在UartDriverInit获取hcs参数进行初始化,如下:
  1. ...
  2. host = UartHostFromDevice(device);
  3. if (host == NULL) {
  4.      HDF_LOGE(&amp;amp;amp;quot;%s: host is NULL&amp;amp;amp;quot;, __func__);
  5.      return HDF_ERR_INVALID_OBJECT;
  6. }
  7. ...
复制代码
Openharmony子系统适配
子系统的编译选项入口在相应产品config.json下,如:vendor/hihope/neptune_iotlink_demo/config.json。

wifi_lite组件

首先,在config.json文件中,增加communication子系统的wifi_lite部件,如下:
  1. {
  2.   &amp;amp;amp;quot;subsystem&amp;amp;amp;quot;: &amp;amp;amp;quot;communication&amp;amp;amp;quot;,
  3.   &amp;amp;amp;quot;components&amp;amp;amp;quot;: [
  4.     {
  5.       &amp;amp;amp;quot;component&amp;amp;amp;quot;: &amp;amp;amp;quot;wifi_lite&amp;amp;amp;quot;,
  6.       &amp;amp;amp;quot;optional&amp;amp;amp;quot;: &amp;amp;amp;quot;true&amp;amp;amp;quot;
  7.     }
  8.   ]
  9. },
复制代码
wifi_lite部件在 build/lite/components/communication.json文件中,描述如下:
  1. {
  2.   &amp;amp;amp;quot;component&amp;amp;amp;quot;: &amp;amp;amp;quot;wifi_lite&amp;amp;amp;quot;,
  3.   &amp;amp;amp;quot;targets&amp;amp;amp;quot;: [
  4.     &amp;amp;amp;quot;//foundation/communication/wifi_lite:wifi&amp;amp;amp;quot;       --- wifi_lite的编译目标
  5.   ],
  6. },
复制代码

在本案例中,wifi适配源码可见device/soc/winnermicro/wm800/board/src/wifi/wm_wifi.c,如下:
  1. int tls_wifi_netif_add_status_event(tls_wifi_netif_status_event_fn event_fn)   ---用于增加wifi事件功能
  2. {
  3.   u32 cpu_sr;
  4.   struct tls_wifi_netif_status_event *evt;
  5.   //if exist, remove from event list first.
  6.   tls_wifi_netif_remove_status_event(event_fn);
  7.   evt = tls_mem_alloc(sizeof(struct tls_wifi_netif_status_event));
  8.   if(evt==NULL)
  9.       return -1;
  10.   memset(evt, 0, sizeof(struct tls_wifi_netif_status_event));
  11.   evt-&amp;amp;amp;gt;status_callback = event_fn;
  12.   cpu_sr = tls_os_set_critical();
  13.   dl_list_add_tail(&amp;amp;amp;amp;wifi_netif_status_event.list, &amp;amp;amp;amp;evt-&amp;amp;amp;gt;list);
  14.   tls_os_release_critical(cpu_sr);

  15.   return 0;
  16. }
复制代码
系统服务管理子系统适配

系统服务管理子系统适配添加samgr_lite部件,直接在config.json配置,如下:
  1. {
  2.   &amp;amp;amp;quot;subsystem&amp;amp;amp;quot;: &amp;amp;amp;quot;distributedschedule&amp;amp;amp;quot;,
  3.   &amp;amp;amp;quot;components&amp;amp;amp;quot;: [
  4.     {
  5.       &amp;amp;amp;quot;component&amp;amp;amp;quot;: &amp;amp;amp;quot;samgr_lite&amp;amp;amp;quot;
  6.     }
  7.   ]
  8. },
复制代码
公共基础库子系统适配

公共基础库子系统适配添加了kv_store、file部件,直接在config.json配置,如下:
  1. {
  2.   &amp;amp;amp;quot;subsystem&amp;amp;amp;quot;: &amp;amp;amp;quot;utils&amp;amp;amp;quot;,
  3.   &amp;amp;amp;quot;components&amp;amp;amp;quot;: [
  4.     {
  5.       &amp;amp;amp;quot;component&amp;amp;amp;quot;: &amp;amp;amp;quot;kv_store&amp;amp;amp;quot;,
  6.       &amp;amp;amp;quot;features&amp;amp;amp;quot;: [
  7.         &amp;amp;amp;quot;enable_ohos_utils_native_lite_kv_store_use_posix_kv_api = true&amp;amp;amp;quot;
  8.       ]
  9.     },
  10.     { &amp;amp;amp;quot;component&amp;amp;amp;quot;: &amp;amp;amp;quot;file&amp;amp;amp;quot;, &amp;amp;amp;quot;features&amp;amp;amp;quot;:[] }
  11.   ]
  12. },
复制代码
适配kv_store部件时,键值对会写到文件中。在轻量系统中,文件操作相关接口有POSIX接口与HalFiles接口这两套实现。 因为对接内核的文件系统,采用POSIX相关的接口,所以features需要增加enable_ohos_utils_native_lite_kv_store_use_posix_kv_api = true。
启动恢复子系统适配

启动恢复子系统适配添加了bootstrap_lite、syspara_lite部件,直接在config.json配置,如下:
  1. {
  2.   &amp;amp;amp;quot;subsystem&amp;amp;amp;quot;: &amp;amp;amp;quot;startup&amp;amp;amp;quot;,
  3.   &amp;amp;amp;quot;components&amp;amp;amp;quot;: [
  4.     {
  5.       &amp;amp;amp;quot;component&amp;amp;amp;quot;: &amp;amp;amp;quot;bootstrap_lite&amp;amp;amp;quot;
  6.     },
  7.     {
  8.       &amp;amp;amp;quot;component&amp;amp;amp;quot;: &amp;amp;amp;quot;syspara_lite&amp;amp;amp;quot;,
  9.       &amp;amp;amp;quot;features&amp;amp;amp;quot;: [
  10.         &amp;amp;amp;quot;enable_ohos_startup_syspara_lite_use_posix_file_api = true&amp;amp;amp;quot;,
  11.         &amp;amp;amp;quot;config_ohos_startup_syspara_lite_data_path = &amp;amp;amp;quot;/data/&amp;amp;amp;quot;&amp;amp;amp;quot;
  12.       ]
  13.     }
  14.   ]
  15. },
复制代码
适配bootstrap_lite部件时,需要在链接脚本文件device/soc/winnermicro/wm800/board/ld/w800/gcc_csky.ld中手动新增如下段:
  1. .zinitcall_array :
  2. {
  3. . = ALIGN(0x4) ;
  4. PROVIDE_HIDDEN (__zinitcall_core_start = .);
  5. KEEP (*(SORT(.zinitcall.core*)))
  6. KEEP (*(.zinitcall.core*))
  7. PROVIDE_HIDDEN (__zinitcall_core_end = .);
  8. . = ALIGN(0x4) ;
  9. PROVIDE_HIDDEN (__zinitcall_device_start = .);
  10. KEEP (*(SORT(.zinitcall.device*)))
  11. KEEP (*(.zinitcall.device*))
  12. PROVIDE_HIDDEN (__zinitcall_device_end = .);
  13. . = ALIGN(0x4) ;
  14. PROVIDE_HIDDEN (__zinitcall_bsp_start = .);
  15. KEEP (*(SORT(.zinitcall.bsp*)))
  16. KEEP (*(.zinitcall.bsp*))
  17. PROVIDE_HIDDEN (__zinitcall_bsp_end = .);
  18. . = ALIGN(0x4) ;
  19. PROVIDE_HIDDEN (__zinitcall_sys_service_start = .);
  20. KEEP (*(SORT(.zinitcall.sys.service*)))
  21. KEEP (*(.zinitcall.sys.service*))
  22. PROVIDE_HIDDEN (__zinitcall_sys_service_end = .);
  23. . = ALIGN(0x4) ;
  24. PROVIDE_HIDDEN (__zinitcall_app_service_start = .);
  25. KEEP (*(SORT(.zinitcall.app.service*)))
  26. KEEP (*(.zinitcall.app.service*))
  27. PROVIDE_HIDDEN (__zinitcall_app_service_end = .);
  28. . = ALIGN(0x4) ;
  29. PROVIDE_HIDDEN (__zinitcall_sys_feature_start = .);
  30. KEEP (*(SORT(.zinitcall.sys.feature*)))
  31. KEEP (*(.zinitcall.sys.feature*))
  32. PROVIDE_HIDDEN (__zinitcall_sys_feature_end = .);
  33. . = ALIGN(0x4) ;
  34. PROVIDE_HIDDEN (__zinitcall_app_feature_start = .);
  35. KEEP (*(SORT(.zinitcall.app.feature*)))
  36. KEEP (*(.zinitcall.app.feature*))
  37. PROVIDE_HIDDEN (__zinitcall_app_feature_end = .);
  38. . = ALIGN(0x4) ;
  39. PROVIDE_HIDDEN (__zinitcall_run_start = .);
  40. KEEP (*(SORT(.zinitcall.run*)))
  41. KEEP (*(.zinitcall.run*))
  42. PROVIDE_HIDDEN (__zinitcall_run_end = .);
  43. . = ALIGN(0x4) ;
  44. PROVIDE_HIDDEN (__zinitcall_test_start = .);
  45. KEEP (*(SORT(.zinitcall.test*)))
  46. KEEP (*(.zinitcall.test*))
  47. PROVIDE_HIDDEN (__zinitcall_test_end = .);
  48. . = ALIGN(0x4) ;
  49. PROVIDE_HIDDEN (__zinitcall_exit_start = .);
  50. KEEP (*(SORT(.zinitcall.exit*)))
  51. KEEP (*(.zinitcall.exit*))
  52. PROVIDE_HIDDEN (__zinitcall_exit_end = .);
  53. } &amp;amp;amp;gt; REGION_RODATA
复制代码
需要新增上述段是因为bootstrap_init提供的对外接口,见utils/native/lite/include/ohos_init.h文件,采用的是灌段的形式,最终会保存到上述链接段中。主要的服务自动初始化宏如下表格所示:

通过上面加载的组件编译出来的lib文件需要手动加入强制链接。
如在 vendor/hihope/neptune_iotlink_demo/config.json 中配置了bootstrap_lite 部件
  1. {
  2.   &amp;amp;amp;quot;subsystem&amp;amp;amp;quot;: &amp;amp;amp;quot;startup&amp;amp;amp;quot;,
  3.   &amp;amp;amp;quot;components&amp;amp;amp;quot;: [
  4.     {
  5.       &amp;amp;amp;quot;component&amp;amp;amp;quot;: &amp;amp;amp;quot;bootstrap_lite&amp;amp;amp;quot;
  6.     },
  7.     ...
  8.   ]
  9. },
复制代码
​bootstrap_lite部件会编译base/startup/bootstrap_lite/services/source/bootstrap_service.c,该文件中,通过SYS_SERVICE_INIT将Init函数符号灌段到__zinitcall_sys_service_start和__zinitcall_sys_service_end中,由于Init函数是没有显式调用它,所以需要将它强制链接到最终的镜像。如下:

  1. static void Init(void)
  2. {
  3.     static Bootstrap bootstrap;
  4.     bootstrap.GetName = GetName;
  5.     bootstrap.Initialize = Initialize;
  6.     bootstrap.MessageHandle = MessageHandle;
  7.     bootstrap.GetTaskConfig = GetTaskConfig;
  8.     bootstrap.flag = FALSE;
  9.     SAMGR_GetInstance()-&amp;amp;amp;gt;RegisterService((Service *)&amp;amp;amp;amp;bootstrap);
  10. }
  11. SYS_SERVICE_INIT(Init);   --- 通过SYS启动即SYS_INIT启动就需要强制链接生成的lib
复制代码
​在base/startup/bootstrap_lite/services/source/BUILD.gn文件中,描述了在out/neptune100/neptune_iotlink_demo/libs 生成 libbootstrap.a,如下:
  1. static_library(&amp;amp;amp;quot;bootstrap&amp;amp;amp;quot;) {
  2.   sources = [
  3.     &amp;amp;amp;quot;bootstrap_service.c&amp;amp;amp;quot;,
  4.     &amp;amp;amp;quot;system_init.c&amp;amp;amp;quot;,
  5.   ]
  6.   ...
复制代码

适配syspara_lite部件时,系统参数会最终写到文件中进行持久化保存。在轻量系统中,文件操作相关接口有POSIX接口与HalFiles接口这两套实现。

因为对接内核的文件系统,采用POSIX相关的接口,所以features字段中需要增加enable_ohos_startup_syspara_lite_use_posix_file_api = true。

XTS子系统适配

XTS子系统的适配,直接在config.json中加入组件选项:
  1. {
  2. &amp;amp;amp;quot;subsystem&amp;amp;amp;quot;: &amp;amp;amp;quot;xts&amp;amp;amp;quot;,
  3. &amp;amp;amp;quot;components&amp;amp;amp;quot;: [
  4.    {
  5.      &amp;amp;amp;quot;component&amp;amp;amp;quot;: &amp;amp;amp;quot;xts_acts&amp;amp;amp;quot;,
  6.      &amp;amp;amp;quot;features&amp;amp;amp;quot;:
  7.         [
  8.        &amp;amp;amp;quot;config_ohos_xts_acts_utils_lite_kv_store_data_path = &amp;amp;amp;quot;/data&amp;amp;amp;quot;&amp;amp;amp;quot;,
  9.        &amp;amp;amp;quot;enable_ohos_test_xts_acts_use_thirdparty_lwip = true&amp;amp;amp;quot;
  10.      ]
  11.    },
  12.    { &amp;amp;amp;quot;component&amp;amp;amp;quot;: &amp;amp;amp;quot;xts_tools&amp;amp;amp;quot;, &amp;amp;amp;quot;features&amp;amp;amp;quot;:[] }
  13. ]
  14. }
复制代码
另外,XTS功能也使用了list来组织,在config.json文件中增减相应模块:
  1. &amp;amp;amp;quot;bin_list&amp;amp;amp;quot;: [
  2.   {
  3.     &amp;amp;amp;quot;enable&amp;amp;amp;quot;: &amp;amp;amp;quot;true&amp;amp;amp;quot;,
  4.     &amp;amp;amp;quot;force_link_libs&amp;amp;amp;quot;: [
  5.        &amp;amp;amp;quot;module_ActsParameterTest&amp;amp;amp;quot;,
  6.        &amp;amp;amp;quot;module_ActsBootstrapTest&amp;amp;amp;quot;,
  7.        &amp;amp;amp;quot;module_ActsDfxFuncTest&amp;amp;amp;quot;,
  8.        &amp;amp;amp;quot;module_ActsHieventLiteTest&amp;amp;amp;quot;,
  9.        &amp;amp;amp;quot;module_ActsSamgrTest&amp;amp;amp;quot;,
  10.        &amp;amp;amp;quot;module_ActsUtilsFileTest&amp;amp;amp;quot;,
  11.        &amp;amp;amp;quot;module_ActsKvStoreTest&amp;amp;amp;quot;,
  12.        &amp;amp;amp;quot;module_ActsWifiServiceTest&amp;amp;amp;quot;
  13.     ]
  14.   }
  15. ],
复制代码
其它组件的适配过程与官方以及其它厂商的过程类似,不再赘述。


回帖

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容图片侵权或者其他问题,请联系本站作侵删。 侵权投诉
链接复制成功,分享给好友