OpenHarmony RISC-V 轻量系统移植—润和 W800 移植分享 第一章 适配准备和编译构建(转载)
本文转自51CTO.COM开源基础软件社区,原文链接请点击文章结尾的“阅读原文”。
本方案基于OpenHarmony LiteOS-M内核,使用联盛德W800芯片的润和软件海王星系列Neptune100开发板,进行开发移植。
移植架构采用Board
与SoC
分离方案,支持通过Kconfig图形化配置编译选项,增加玄铁ck804ef
架构移植,实现了HDF
、XTS
等子系统及组件的适配。
适配准备和编译构建
适配准备
准备ubuntu20.04系统环境,安装csky-abiv2-elf-gcc交叉编译工具链。
目录规划
本方案的目录结构使用Board和Soc解耦的思路。
芯片适配目录规划为:
device
├── board --- 单板厂商目录
│ └── hihope --- 单板厂商名字:HiHope
│ └── neptune100 --- 单板名:Neptune100
└── soc --- SoC厂商目录
└── winnermicro --- SoC厂商名字:联盛德
└── wm800 --- SoC Series名:w800系列芯片
产品样例目录规划为:
vendor
└── hihope --- 开发产品样例厂商目录,润和软件的产品样例
├── neptune_iotlink_demo --- 产品名字:Neptune100产品样例代码
└── ...
产品定义
vendor/hihope/neptune_iotlink_demo/config.json
文件下,描述了产品使用的内核、单板、子系统等信息。其中,内核、单板型号、单板厂商需提前规划好,是预编译指令hb set
关注的。例如:
{
"product_name": "neptune_iotlink_demo", --- 产品名
"ohos_version": "OpenHarmony 3.1", --- 使用的OS版本
"type":"mini", --- 系统类型: mini
"version": "3.0", --- 系统版本: 3.0
"device_company": "hihope", --- 单板厂商:hihope
"board": "neptune100", --- 单板名:neptune100
"kernel_type": "liteos_m", --- 内核类型:liteos_m
"kernel_version": "3.0.0", --- 内核版本:3.0.0
"subsystems": [] --- 子系统
}
填入的信息与规划的目录相对应,其中device_company
和board
用于关联出device/board/<device_company>/
目录。
单板配置
关联到的<board>目录下,在device/board/hihope/neptune100/liteos_m
目录下放置config.gni
文件,该配置文件用于描述该单板信息,包括CPU型号、交叉编译工具链及全局编译、链接参数等重要信息:
# Kernel type, e.g. "linux", "liteos_a", "liteos_m".
kernel_type = "liteos_m"
# Kernel version.
kernel_version = "3.0.0"
# Board CPU type, e.g. "cortex-a7", "riscv32".
board_cpu = "ck804ef"
# Board arch, e.g. "armv7-a", "rv32imac".
board_arch = "ck803"
# 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 toolchain.
board_toolchain = "csky-elfabiv2-gcc"
#use_board_toolchain = true
# The toolchain path installed, it's not mandatory if you have added toolchain path to your ~/.bashrc.
board_toolchain_path = ""
# Compiler prefix.
board_toolchain_prefix = "csky-elfabiv2-"
# Compiler type, "gcc" or "clang".
board_toolchain_type = "gcc"
# config.json parse
if (product_path != "") {
product_conf = read_file("${product_path}/config.json", "json")
product_name = product_conf.product_name
bin_list = product_conf.bin_list
}
# Board related common compile flags.
board_cflags = [
"-mcpu=ck804ef",
"-mhard-float",
"-DGCC_COMPILE=1",
"-DTLS_CONFIG_CPU_XT804=1",
"-DNIMBLE_FTR=1",
"-D__CSKY_V2__=1",
"-DCPU_CK804",
"-O2",
"-g3",
"-Wall",
"-ffunction-sections",
"-MMD",
"-MP",
]
board_cxx_flags = board_cflags
board_asmflags = [
"-mcpu=ck804ef",
"-DCPU_CK804",
]
board_ld_flags = []
# Board related headfiles search path.
board_include_dirs = []
# 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 = ""
预编译
在工程根目录下输入预编译指令hb set
可显示相关产品信息,如下:
hb set
OHOS Which product do you need? (Use arrow keys)
hihope
> neptune_iotlink_demo
OHOS Which product do you need? neptune_iotlink_demo
执行hb set
后,会在根目录下自动生成ohos_config.json
文件,文件中会列出待编译的产品信息。通过hb env可以查看选择出来的预编译环境变量。
[OHOS INFO] root path: /home/xxxx/openharmony_w800
[OHOS INFO] board: neptune100
[OHOS INFO] kernel: liteos_m
[OHOS INFO] product: neptune_iotlink_demo
[OHOS INFO] product path: /home/xxxx/openharmony_w800/vendor/hihope/neptune_iotlink_demo
[OHOS INFO] device path: /home/xxxx/openharmony_w800/device/board/hihope/neptune100/liteos_m
[OHOS INFO] device company: hihope
至此,预编译适配完成,但工程还不能执行hb build进行编译,还需要准备好后续的LiteOS-M内核移植。
后篇预告
第二章 OpenHarmony RISC-V轻量系统移植之内核移植
第三章 OpenHarmony RISC-V轻量系统移植之OpenHarmony子系统适配
写在最后
我们最近正带着大家玩嗨OpenHarmony。如果你有好玩的东东,欢迎投稿,让我们一起嗨起来!有点子,有想法,有Demo,立刻联系我们:
合作邮箱:zzliang@atomsource.org