openharmony 笔记 --rk3568

0 git+repo下载源码命令


git config --global user.name "yourname"
git config --global user.email "your-email-address"
git config --global credential.helper store

生成公钥
ssh-keygen -t ed25519 -C "Gitee SSH Key"
敲三次回车会生成到提示的路径下
在gitee网页上添加公钥,公钥内容在刚才生成的路径中的id_ed25519.pub文件中
cat /root/.ssh/id_ed25519.pub
在本地绑定[email protected]
ssh -T [email protected]



mkdir bin
curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 -o ./bin/repo 
chmod a+x ./bin/repo
pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests

vim ~/.bashrc               # 编辑环境变量
export PATH=/.../bin:$PATH     # 在环境变量的最后添加一行repo路径信息
source ~/.bashrc            # 应用环境变量

下载5.0.2-release版本 对应api14  repo+https
# repo init -u https://gitee.com/openharmony/manifest -b OpenHarmony-5.0.2-Release --no-repo-verify
# repo sync -c
# repo forall -c 'git lfs pull'

下载5.0.2-release版本 对应api14  repo+ssh
repo init -u [email protected]:openharmony/manifest.git -b OpenHarmony-5.0.2-Release --no-repo-verify --depth=1
--depth=1是为了仅保留一层commit记录,防止过多的历史commit占用空间,如果你想保留历 史commit,那可以把这里的--depth=1去掉。
repo sync -c
repo forall -c 'git lfs pull'

repo init -u [email protected]:openharmony/manifest.git -b OpenHarmony-4.1-Release --no-repo-verify --depth=1


####关于docker 设置端口映射 可以直接ssh访问docker
$docker run -itd --name zd_openharmony_ubuntu20.04 -p 25002:25002 -v /home/repository/openharmony:/home/work ubuntu20.04:openharmony /bin/bash
$docker exec -it zd_openharmony_ubuntu20.04 /bin/bash

1.编译命令

如果是repo下载的需要执行sdk中的一个下载脚本下载一些库
./

./build.sh --product-name rk3568 --ccache

#生成镜像路径
out/rk3568/packages/phone/images

在调试驱动后可以只编译内核
./build.sh --product-name rk3568 --ccache --build-target kernel --gn-args linux_kernel_version="linux-5.10"


注意hcs文件的修改有可能导致编译不会进入内核镜像
需要删除几个文件重新编译内核
1. vendor/hihope/rk3568/hdf_config/khdf/hdf_test/hdf_hcs.hcb
2. out/kernel/vendor/hihope/rk3568/hdf_config/khdf/hdf_test/hdf_hcs_hex.o
3. out/kernel/OBJ 目录
4. out/rk3568/packages/phone/images/boot_linux.img


2.一些常用的模块配置规则

# C/C++模板
# 模板定义在build/templates/cxx/cxx.gni
ohos_shared_library #动态库
ohos_static_library #静态库
ohos_executable     #可执行文件
ohos_source_set    

# 预编译模板:
# 模板定义在build/templates/cxx/prebuilt.gni
ohos_prebuilt_executable
ohos_prebuilt_shared_library
ohos_prebuilt_static_library

# hap模板
# 
ohos_hap
ohos_app_scope
ohos_js_assets
ohos_resources


#配置文件
ohos_prebuilt_etc
#sa配置
ohos_sa_profile

3.harmony的编译分析

不管是build.sh  还是 build.py 最终调用的是下面的hb来构建的
build/hb/main.py build $args_list

4.加快编译的一些选项

  • 添加--ccache参数:
    • 原理:ccache会缓存c/c++编译的编译输出,下一次在编译输入不变的情况下,直接复用缓存的产物。
    • 安装:
      • 快速安装:执行sudo apt-get install ccache命令。
      • 官网下载,下载二进制文件,把ccache所在路径配置到环境变量。
    • 使用:执行./build.sh --product-name 产品名 --ccache命令。
  • 添加--fast-rebuild参数
    • 原理:编译流程主要分为:preloader->loader->gn->ninja这四个过程,在本地没有修改gn和产品配置相关文件的前提下,添加--fast-rebuild会让你直接从ninja编译开始。
    • 使用:执行./build.sh --product-name 产品名 --fast-rebuild命令。
  • 添加enable_notice_collection=false参数
    • 原理:省略掉收集开源软件模块的license的过程。
    • 使用:执行./build.sh --product-name 产品名 --gn-args --enable_notice_collection=false --ccache命令。
  • 添加--build-target参数
    • 该参数用于指定编译模块,如何找模块的名字:
      • 相关仓下BUILD.gn中关注group、ohos_shared_library、ohos_executable等关键字。
      • ./build.sh --product-name 产品名 --build-target 模块名 --build-only-gn生成build.ninja,然后去该文件中查找相关模块名。
    • 使用:执行./build.sh --product-name 产品名 --build-target ark_js_host_linux_tools_packages命令。

5.一些编译脚本分析

5.1 build_kernel.sh 

编译内核脚本
board/hihope/rk3568/kernel/build_kernel.sh
build_kernel.sh 是由编译配置文件device/board/hihope/rk3568/kernel/BUILD.gn中配置调用的


build_kernel.sh 运行是传入的参数
../../kernel/li

你可能感兴趣的:(笔记)