device                                      
    └── company                         # 芯片解决方案厂商
        └── board                       # 开发板名称
            ├── BUILD.gn                # 编译脚本
            ├── hals                    # OS南向接口适配
            ├── linux                   # 可选,linux内核版本
            │   └── config.gni          # linux版本编译配置
            └── liteos_a                # 可选,liteos内核版本
                └── config.gni          # liteos_a版本编译配置
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

以hispark_taurus移植linux内核为例,目录树应该如下:

    device                  
    └── hisilicon             
        └── hispark_taurus          
            ├── BUILD.gn    
            ├── hals        
            ├── ......      
            └── linux    
                └── config.gni  
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

目录树建立后开发板相关的源码放到hispark_taurus目录下。

  1. 配置开发板编译选项

步骤1中的config.gni可配置开发板相关的编译选项,编译构建框架将会遵照该配置文件中的参数编译所有用户态OS组件。其中关键的字段说明如下:

    kernel_type:            开发板使用的内核类型,例如:“liteos_a”, “liteos_m”, “linux”。
    kernel_version:         开发板使用的内核版本,例如:“4.19”。
    board_cpu:              开发板CPU类型,例如:“cortex-a7”, “riscv32”。
    board_arch:             开发板芯片arch, 例如: “armv7-a”, “rv32imac”。
    board_toolchain:        开发板自定义的编译工具链名称,例如:“gcc-arm-none-eabi”。若为空,则使用默认为ohos-clang。
    board_toolchain_prefix:编译工具链前缀,例如:“gcc-arm-none-eabi”。
    board_toolchain_type:  编译工具链类型,目前支持gcc和clang。例如:“gcc” ,“clang”。
    board_cflags:          开发板配置的c文件编译选项。
    board_cxx_flags:       开发板配置的cpp文件编译选项。
    board_ld_flags:        开发板配置的链接选项。
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">

还以海思的hispark_taurus开发板为例,对应的device/hisilicon/hispark_taurus/config.gni内容如下:

    # Board CPU type, e.g. "cortex-a7", "riscv32".
    board_cpu = "cortex-a7"

    # Toolchain name used for system compiling.
    # E.g. gcc-arm-none-eabi, arm-linux-harmonyeabi-gcc, ohos-clang,  riscv32-unknown-elf.
    # Note: The default toolchain is "ohos-clang". It's not mandatory if you use the default toochain.
    board_toolchain = "mips-linux-gnu-gcc"

    # The toolchain path installed, it's not mandatory if you have added toolchain path to your ~/.bashrc.
    board_toolchain_path = 
        rebase_path("//prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc/bin",
                    root_build_dir)

    # Compiler prefix.
    board_toolchain_prefix = "arm-linux-ohoseabi-"

    # Compiler type, "gcc" or "clang".
    board_toolchain_type = "gcc"

    # Board related common compile flags.
    board_cflags = [
    ]
    board_cxx_flags = [
    ]
    board_ld_flags = []

    # Board related headfiles search path.
    board_include_dirs = []
    board_include_dirs += [ rebase_path(
            "//prebuilts/gcc/linux-x86/arm/arm-linux-ohoseabi-gcc/target/usr/include",
            root_build_dir) ]

    # Board adapter dir for OHOS components.
    board_adapter_dir = ""

    # Sysroot path.
    board_configed_sysroot = ""

    # Board storage type, it used for file system generation.
    storage_type = "emmc"
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}"> class="hide-preCode-box">
  1. 编写开发板编译脚本

步骤1中的BUILD.gn为新增的开发板的编译入口,主要用于编译开发板相关的代码,主要为设备侧驱动、设备侧接口适配(媒体,图形等)和开发板的SDK等等。

海思的hispark_taurus开发板的device/hisilicon/hispark_taurus/BUILD.gn可写成:

    # group名称建议与开发板名称一致
    group("hispark_taurus") {   
      deps = [ "//kernel/linux/patches:linux_kernel" ] # 拉起内核编译
      deps += [
      ...... # 开发板其他编译单元
      ]
    }
 class="hljs-button signin active" data-title="登录复制" data-report-click="{"spm":"1001.2101.3001.4334"}">
  1. 编译调试

在开发板目录下执行hb sethb build即可启动芯片解决方案的编译,编译框架会以开发板下的BUILD.gn为入口启动编译。

如果大家想更加深入的学习 OpenHarmony(鸿蒙南向) 开发的全栈内容,不妨可以参考以下相关学习文档进行学习,助你快速提升自己:

OpenHarmony 开发环境搭建:https://qr18.cn/CgxrRy

《OpenHarmony源码解析》:https://qr18.cn/CgxrRy

系统架构分析:https://qr18.cn/CgxrRy

OpenHarmony 设备开发学习手册:https://qr18.cn/CgxrRy

在这里插入图片描述

OpenHarmony面试题(内含参考答案):https://qr18.cn/CgxrRy

写在最后

data-report-view="{"mod":"1585297308_001","spm":"1001.2101.3001.6548","dest":"https://blog.csdn.net/maniuT/article/details/140827886","extend1":"pc","ab":"new"}">> id="blogExtensionBox" style="width:400px;margin:auto;margin-top:12px" class="blog-extension-box"> class="blog_extension blog_extension_type2" id="blog_extension"> class="extension_official" data-report-click="{"spm":"1001.2101.3001.6471"}" data-report-view="{"spm":"1001.2101.3001.6471"}"> class="blog_extension_card_left"> class="blog_extension_card_cont"> 鸿蒙开发学习资料领取!!! class="blog_extension_card_cont_r"> 微信名片
注:本文转载自blog.csdn.net的沧海一笑-dj的文章"https://blog.csdn.net/dengjin20104042056/article/details/95658891"。版权归原作者所有,此博客不拥有其著作权,亦不承担相应法律责任。如有侵权,请联系我们删除。
复制链接

评论记录:

未查询到任何数据!