OpenHarmony轻量系统编译手册
OpenHarmony轻量系统编译手册 1. 配置Linux环境 1.1 系统要求 系统环境要求:建议Ubuntu20.04版本及以上(若使用18.04版本,需将python3.6升级为python3.8) 系统镜像建议下载地址: 阿里云开源镜像站 配置步骤可参考OpenHarmony官方文档 1.2 更新Ubuntu源 打开sources.
1. 配置Linux环境
1.1 系统要求
系统环境要求:建议Ubuntu20.04版本及以上(若使用18.04版本,需将python3.6升级为python3.8)
系统镜像建议下载地址: 阿里云开源镜像站
配置步骤可参考OpenHarmony官方文档
1.2 更新Ubuntu源
- 打开
sources.list
文件
sudo gedit /etc/apt/sources.list
- 将与系统对应版本源复制并覆盖至上述打开的文件中,保存关闭,执行如下命令。(建议使用阿里源)
sudo apt update
1.3 安装依赖工具库
- 安装ccache(用于加速编译)
sudo apt install ccache
- 安装git工具并配置用户名和邮箱
sudo apt install git git-lfs
git config --global user.email "xxx"
git config --global user.name "xxx"
- 设置python软链接为python3.8
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
- 安装并升级Python包管理工具(pip3)
sudo apt-get install python3-setuptools python3-pip -y
sudo pip3 install --upgrade pip
1.4 安装Repo工具
如果已经安装并拉取过OpenHarmony代码,请忽略该步骤。
如果是通过apt install安装的repo,请卸载后按照下述步骤重新安装:
sudo apt install curl -y
curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > repo
chmod a+x repo
sudo mv repo /usr/local/bin/
2. 源码获取
- 下载OpenHarmony代码
mkdir arkui_lite && cd arkui_lite
repo init -u https://gitee.com/cooperation-team-L0UI/manifest.git -b OpenHarmony-3.2-Release --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'
- 执行prebuilts
bash build/prebuilts_download.sh --skip-ssl
- 安装hb工具
python3 -m pip uninstall ohos-build
# 在源码目录下安装hb
python3 -m pip install --user build/hb
3. 创建虚拟设备
3.1 创建虚拟设备
参考官方文档zh-cn/device-dev/porting/porting-minichip-prepare.md · OpenHarmony/docs - Gitee.com和virt_mini_system_demo配置,添加虚拟设备arkui_lite,创建新的vendor和新的device配置。
cp -rf arkui_lite_demo vendor/ohemu/arkui_lite
cp -rf arkui_lite_demo_virt device/qemu/arkui_lite
3.2 vendor仓配置
3.2.1 子系统裁剪
修改board为arkui_lite,kernel_type为liteos_m,根据实际情况裁剪子系统,以及其他配置。
参考vendor/ohemu/arkui_lite/config.json,该文件包含了所有必须的子系统配置。
更改product_name、device_company等。
{
"product_name": "arkui_lite",
"ohos_version": "OpenHarmony 1.0",
"type":"mini",
"version": "3.0",
"device_company": "qemu",
"board": "arkui_lite",
"kernel_type": "liteos_m",
"kernel_version": "3.0.0",
"subsystems": [
{
"subsystem": "hiviewdfx",
"components": [
{
"component": "hilog_lite",
"optional": "true"
},
{
"component": "hievent_lite",
"optional": "true"
}
]
},
{
"subsystem": "graphic",
"components": [
{
"component": "graphic_utils_lite",
"features": [
"enable_ohos_graphic_utils_product_config = true"
]
}
]
},
{
"subsystem": "arkui",
"components": [
{
"component": "ace_engine_lite",
"features": [
"enable_ohos_ace_engine_lite_product_config = true"
]
},
{
"component": "ui_lite"
}
]
},
{
"subsystem": "ability",
"components": [
{
"component": "ability_lite",
"features": [
"enable_ohos_appexecfwk_feature_ability = true",
"config_ohos_aafwk_ams_task_size = 4096",
"config_ohos_aafwk_aafwk_lite_task_stack_size = 32768"
]
}
]
},
{
"subsystem": "bundlemanager",
"components": [
{
"component": "bundle_framework_lite"
}
]
},
{
"subsystem": "systemabilitymgr",
"components": [
{
"component": "samgr_lite",
"features": [
"config_ohos_systemabilitymgr_samgr_lite_shared_task_size = 4096"
]
}
]
}
],
"third_party_dir": "//third_party",
"product_adapter_dir": "//vendor/ohemu/arkui_lite/hals"
}
3.2.2 hal层的适配接口
根据原生设备,进行hal层适配,已经子系统相关宏的配置,如graphic_config、ace_lite_config等.
3.3 device配置
3.3.1 配置交叉编译工具链
OpenHarmony编译系统支持三种编译工具链:gcc,clang,iccarm,并且当前不支持window系统下编译。
以arm-none-eabi-gcc为例,参考如下:
- 下载交叉编译工具链:
mkdir -p ~/arkui_lite_tools && cd ~/arkui_lite_tools
wget https://repo.huaweicloud.com/openharmony/compiler/gcc-arm-none-eabi/10.3/linux/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
sudo tar axvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 -C /opt/
- 将交叉编译工具添加至环境变量:
gedit ~/.bashrc
export PATH=/opt/gcc-arm-none-eabi-10.3-2021.10/bin:$PATH
source ~/.bashrc
- 配置工具链
修改device\qemu\arkui_lite\liteos_m\config.gni,该文件包含了板级编译配置,根据原生编译系统的编译设置来修改。
请确保OpenHarmony的编译选项和原生系统保持一致,否则可能出现链接问题。
# Copyright (c) 2020-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.
# 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 = "cortex-m4"
# Board arch, e.g. "armv7-a", "rv32imac".
board_arch = ""
# 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 = "arm-none-eabi-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 = "arm-none-eabi-"
# Compiler type, "gcc" or "clang".
board_toolchain_type = "gcc"
#Debug compiler optimization level options
board_opt_flags = []
# Board related common compile flags.
board_cflags = [
"-mthumb",
"-Wall",
"-fdata-sections",
"-ffunction-sections",
"-fno-builtin",
"-fno-strict-aliasing",
"-fsigned-char",
"-std=c99",
"-O2",
"-DUSE_HAL_DRIVER",
"-D__LITEOS_M__",
]
board_cflags += board_opt_flags
board_asmflags = [
"-mcpu=cortex-m4",
"-mthumb",
"-static",
"-O2",
]
board_asmflags += board_opt_flags
board_cxx_flags = board_cflags
board_ld_flags = []
# Newlib adapt.
board_ld_flags += [
"-Wl,--wrap=_free_r",
"-Wl,--wrap,_malloc_usable_size_r",
"-Wl,--wrap,_malloc_r",
"-Wl,--wrap,_memalign_r",
"-Wl,--wrap,_realloc_r",
"-Wl,--wrap,_calloc_r",
]
# Board related headfiles search path.
board_include_dirs = [ "//commonlibrary/utils_lite/include" ]
# Board adapter dir for OHOS components.
board_adapter_dir = "//device/qemu/arkui_lite_demo_virt/driver"
# Sysroot path.
board_configed_sysroot = ""
# Board storage type, it used for file system generation.
storage_type = "spinor"
3.3.2 板级驱动适配
参考适配相关驱动、文件系统、链接文件
3.4 编译生成
进入源码根目录,执行
hb set
命令并选择ohemu下项目
arkui_lite
执行
hb build -f
构建成功会提示类似如下信息:
[OHOS INFO] subsystem files NO. percentage builds NO. percentage overlap rate [OHOS INFO] aafwk 13 1.7% 13 1.7% 1.00 [OHOS INFO] ability 13 1.7% 13 1.7% 1.00 [OHOS INFO] arkui 106 14.1% 106 14.1% 1.00 [OHOS INFO] bundlemanager 19 2.5% 19 2.5% 1.00 [OHOS INFO] commonlibrary 8 1.1% 8 1.1% 1.00 [OHOS INFO] distributeddatamgr 2 0.3% 2 0.3% 1.00 [OHOS INFO] global 17 2.3% 17 2.3% 1.00 [OHOS INFO] graphic 133 17.7% 133 17.7% 1.00 [OHOS INFO] hiviewdfx 12 1.6% 12 1.6% 1.00 [OHOS INFO] startup 6 0.8% 6 0.8% 1.00 [OHOS INFO] systemabilitymgr 15 2.0% 15 2.0% 1.00 [OHOS INFO] third_party 417 55.6% 417 55.6% 1.00 [OHOS INFO] thirdparty 417 55.6% 417 55.6% 1.00 [OHOS INFO] [OHOS INFO] c overall build overlap rate: 1.00 [OHOS INFO] [OHOS INFO] [OHOS INFO] L0_xts_demo build success [OHOS INFO] cost time: 0:00:13
查看生成的静态库
ls -l out/arkui_lite/arkui_lite/libs/
更多推荐
所有评论(0)