Navigation

    全志在线开发者论坛

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • 在线文档
    • 社区主页

    【全志D1哪吒开发板开源鸿蒙系统适配】ohos-riscv三方库移植

    MR Series
    ohos riscv 鸿蒙 鸿蒙 ohos
    1
    1
    1311
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Z
      zhangpeng123 LV 2 last edited by xiaowenge

      https://hrdc1ycb27.feishu.cn/docs/doccnNZD1KvrxRTl24OFMxIwWId?from=from_copylink
      一、背景

      • 背景:ohos-riscv三方库移植
      • 整体思路:
        1.在烧写镜像时就把三方库一起编译进去(验证成功)
        2.烧写镜像时调用CMAKE或者MAKE(上次没有成功)
        3.在系统外编译完再复制进去(还没试)
        4.本地编译(还没试)
        二、操作步骤
        编写.gn
      • 对于三方库.gn主要作用就是链接代码,指定编译参数,生成目标文件。
      • 以tree为例,基于ohos-riscv项目精简后感觉最小模板为下。
      # Copyright (c) 2022 AIRCAS
      import("//build/ohos.gni")
      
      # This is the configuration needed to use tree.
      config("tree_config") {
        include_dirs = [
          "debian",
          "doc",
        ]
        cflags = [ 
            "-Wno-unused-parameter" ,
            "-Wno-incompatible-pointer-types",
            "-D_GNU_SOURCE",
            "-D_POSIX_C_SOURCE=200112",  
        ]
      }
      common_source = [
            "color.c",
            "file.c",
            "filter.c",
            "hash.c",
            "html.c",
            "info.c",
            "json.c",
            "list.c",
            "strverscmp.c",
            "tree.c",
            "unix.c",
            "xml.c",
      ]
      
      # This is the configuration used to build tree itself.
      # It should not be needed outside of this library.
      config("tree_private_config") {
        visibility = [ ":*" ]
        include_dirs = [ ]
      }
      
      ohos_source_set("tree_source") {
        configs = [ ":tree_config" ]
        sources = common_source
      
        if (is_ohos) {
        sources += [ ]
        } 
      }
      
      # target files
      
      ohos_static_library("tree_static") {
        deps = [ ":tree_source" ]
        public_configs = [ ":tree_config" ]
      }
      
      ohos_shared_library("tree_share") {
        deps = [ ":tree_source" ]
        public_configs = [ ":tree_config" ]
      }
      
      ohos_executable("tree") {
        include_dirs = [
          "debian",
          "doc",
        ]
        deps = [ ":tree_source" ]
        public_configs = [ ":tree_config" ]
      }
      
      • 链接三方库
      • 根据原三方库改写完gn文件后,需要在ohos-build系统中进行指定
      • common子系统common组件已经测试为确定会参与系统编译,路径及代码示例如下:
      • 修改行号为25、26、27
      /home/zhangpeng/OpenHarmony/build/common/BUILD.gn
      
      # Copyright (c) 2021 Huawei Device Co., Ltd.
      # Licensed under the Apache License, Version 2.0 (the "License");
      # you may not use this file except in compliance with the License.
      # You may obtain a copy of the License at
      #
      #     http://www.apache.org/licenses/LICENSE-2.0
      #
      # Unless required by applicable law or agreed to in writing, software
      # distributed under the License is distributed on an "AS IS" BASIS,
      # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      # See the License for the specific language governing permissions and
      # limitations under the License.
      
      import("//build/config/ohos/config.gni")
      import("//build/config/sanitizers/sanitizers.gni")
      import("//build/ohos.gni")
      
      group("common_packages") {
        deps = []
        deps += [
          "//third_party/giflib:libgif",
          "//third_party/libpng:libpng",
          "//third_party/sqlite:sqlite",
          "//third_party/zlib:libz",  
          "//third_party/tree:tree",
          "//third_party/tree:tree_share",
          "//third_party/tree:tree_static",
        ]
      
        deps += [ "musl:musl_install" ]
      
        if (is_asan) {
          deps += [
            "asan:asan.options",
            "asan:libclang_rt.asan.so",
          ]
        }
      

      编译打包
      接下来可以进行编译、打包及烧写。
      编译需要在docker下,打包在docker外OpenHarmony下,烧写采用PhoneixCard烧写启动卡。参考编译

      #编译
      sudo docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.4
      ./build.sh --product-name sunxi_d1 --ccache
      #打包
      sudo ./device/sunxi/build/pack -e
      

      测试
      烧写完成后采用串口连接进入Ohos-riscv系统,进入system文件夹进行查看,已确定bin中存放excu,lib64中存放.so,也可以实际执行进行测试。

      有做ohos-riscv的欢迎一起交流。

      1 Reply Last reply Reply Quote Share 1
      • 1 / 1
      • First post
        Last post

      Copyright © 2024 深圳全志在线有限公司 粤ICP备2021084185号 粤公网安备44030502007680号

      行为准则 | 用户协议 | 隐私权政策