0. 前言
出于個人興趣,也出于對國產操作系統(tǒng)的好奇,想嘗試一下以LiteOS為內核的Openharmony。但過程相當不順利,主要原因是官方文檔內容組織的不敢恭維。挺好的東西,不把說明書寫好,讓用戶怎么用?我研究的核心問題就一個:如何在基于Qemu仿真的Openharmony中輸出一個hello world。大家可以看看這個官方網站:https://www.openharmony.cn/mainPlay,看看能不能找到教程,能不能找到從安裝環(huán)境到用Qemu仿真的教程。
你不能讓只是好奇的用戶直接去買板子吧。可看看官方教程寫的,全是各種設備的操作。這是文檔組織者的傲慢。如果Openharmony官方文檔寫得足夠好,這篇博客本不該存在。
好,牢騷發(fā)完了。說一下這篇博客大致在干什么事。這篇博客基于在VMware上新創(chuàng)建的Ubuntu 20.04.1,搭建Openharmony的運行環(huán)境,如何正確編譯并進入Qemu的仿真。
1. 安裝Ubuntu
版本為20.04.1
1.1 更換華為源
這一步本身不是必須,但為了未雨綢繆,還是把ubuntu的源換成huawei源,和他們開發(fā)人員保持一致。
sudo gedit /etc/apt/sources.list
替換為以下內容
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://repo.huaweicloud.com/ubuntu/ focal main restricted
# deb-src http://repo.huaweicloud.com/ubuntu/ focal main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://repo.huaweicloud.com/ubuntu/ focal-updates main restricted
# deb-src http://repo.huaweicloud.com/ubuntu/ focal-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://repo.huaweicloud.com/ubuntu/ focal universe
# deb-src http://repo.huaweicloud.com/ubuntu/ focal universe
deb http://repo.huaweicloud.com/ubuntu/ focal-updates universe
# deb-src http://repo.huaweicloud.com/ubuntu/ focal-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://repo.huaweicloud.com/ubuntu/ focal multiverse
# deb-src http://repo.huaweicloud.com/ubuntu/ focal multiverse
deb http://repo.huaweicloud.com/ubuntu/ focal-updates multiverse
# deb-src http://repo.huaweicloud.com/ubuntu/ focal-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://repo.huaweicloud.com/ubuntu/ focal-backports main restricted universe multiverse
# deb-src http://repo.huaweicloud.com/ubuntu/ focal-backports main restricted universe multiverse
## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu focal partner
# deb-src http://archive.canonical.com/ubuntu focal partner
deb http://repo.huaweicloud.com/ubuntu/ focal-security main restricted
# deb-src http://repo.huaweicloud.com/ubuntu/ focal-security main restricted
deb http://repo.huaweicloud.com/ubuntu/ focal-security universe
# deb-src http://repo.huaweicloud.com/ubuntu/ focal-security universe
deb http://repo.huaweicloud.com/ubuntu/ focal-security multiverse
# deb-src http://repo.huaweicloud.com/ubuntu/ focal-security multiverse
sudo apt update
1.2 安裝必要工具
sudo apt install ssh net-tools tree vim
2. 下載代碼
Openharmony v3.0.6 下載地址: https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.0.6%2Fcode-v3.0.6-LTS.tar.gz
說明文檔:https://gitee.com/openharmony/docs/blob/master/zh-cn/release-notes/OpenHarmony-v3.0.6-LTS.md
2.1 解壓與目錄設置
sudo chmod 777 code-v3.0.6-LTS.tar.gz
tar -xvzf code-v3.0.6-LTS.tar.gz -C /home/liteos/
3. 配置環(huán)境
3.1 安裝庫和工具
sudo apt update
sudo apt install binutils binutils-dev gcc g++ git git-lfs gnupg flex bison gperf build-essential zip curl zlib1g-dev
sudo apt install libc6-dev-amd64 x11proto-core-dev libx11-dev ccache libgl1-mesa-dev libxml2-utils xsltproc unzip m4 bc gnutls-bin python3.8 python3-pip python3.8-distutils qemu-system-arm
sudo apt install ruby genext2fs device-tree-compiler make libffi-dev e2fsprogs pkg-config perl openssl libssl-dev libelf-dev libdwarf-dev u-boot-tools mtd-utils cpio doxygen liblz4-tool openjdk-8-jre texinfo dosfstools mtools default-jre default-jdk libncurses5 apt-utils wget scons tar rsync git-core libxml2-dev lib32z-dev grsync xxd libglib2.0-dev libpixman-1-dev kmod jfsutils reiserfsprogs xfsprogs squashfs-tools pcmciautils quota ppp libtinfo-dev libtinfo5 libncurses5-dev libncursesw5 libstdc++6 gcc-arm-none-eabi vim ssh locales libxinerama-dev libxcursor-dev libxrandr-dev libxi-dev
sudo apt install gcc-arm-linux-gnueabi lib32ncurses5-dev lib32z1-dev
注:與官方文檔相比,少安裝libc6-dev-i386
(在安裝gcc-arm-linux-gnueabi時自動安裝)。gcc-multilib
和g++-multilib
放棄安裝,原因在問題1中分析。多了qemu-system-arm。
3.2 設置python版本
# 查看Python 3.8的位置, 我這里是/usr/bin/python3.8
# 因此下面也用這個地址
which python3.8
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
# 驗證
python --version
3.3 安裝編譯工具hb
pip3 install --user build/lite
vim ~/.bashrc
# .bashrc 中寫入 export PATH=~/.local/bin:$PATH
source ~/.bashrc
查看 hb 工具
hb -h
打印以下內容
usage: hb
OHOS build system
positional arguments:
{build,set,env,clean}
build Build source code
set OHOS build settings
env Show OHOS build env
clean Clean output
optional arguments:
-h, --help show this help message and exit
卸載 hb 工具
pip3 uninstall ohos-build
3.4 切換dash為bash
sudo dpkg-reconfigure dash # 選擇 no
這一步很重要,否則可能在后續(xù)編譯中會出現
[2158/2644] ACTION //kernel/liteos_a:make(//build/lite/toolchain:linux_x86_64_ohos_clang)
FAILED: obj/kernel/liteos_a/make_build_ext_components.txt
/usr/bin/python3 ../../../build/lite/build_ext_components.py .........
4. 編譯
4.1 hb構建
# (第一次時)輸入文件路徑
# 并選擇 qemu_small_system_demo 對應 LiteOS-A
hb set
hb build -f
4.2 啟動qemu
./qemu-run -f
輸出
01-01 00:00:10.446 9 43 I 015C0/dsoftbus_standard: [COMM]LoopTask[Loop-default], stop ==1
01-01 00:00:10.446 9 43 I 015C0/dsoftbus_standard: [COMM]LoopTask[Loop-default], running =0
01-01 00:00:10.447 9 16 I 015C0/dsoftbus_standard: [COMM][Loop-default] get running = 0
01-01 00:00:10.447 9 16 I 015C0/dsoftbus_standard: [COMM][Loop-default] destroy
01-01 00:00:10.447 9 16 E 015C0/dsoftbus_standard: [COMM]softbus framework init failed. # 此時需要按一下回車進入OHOS
OHOS:/$
注意:
- 輸出無更新時,按一下回車,進入OHOS
- 退出qemu仿真環(huán)境,先按
ctrl+a
再按x
5. 第二種環(huán)境配置方案
5.1 前置步驟
依次執(zhí)行:
- 2 下載代碼
- 按照3.1中的軟件包列表,或者
OpenHarmony/docs/docker/Dockerfile
中的軟件包列表進行安裝
5.2 更改環(huán)境變量
sudo vim ~/.bashrc
添加以下內容
export PATH=/home/wh/code/code-v3.0.6-LTS/OpenHarmony/prebuilts/clang/ohos/linux-x86_64/llvm/bin:$PATH
export PATH=~/.local/bin:$PATH
export PATH=/home/wh/code/code-v3.0.6-LTS/OpenHarmony/prebuilts/build-tools/linux-x86/bin:$PATH
export PATH=/home/wh/code/code-v3.0.6-LTS/OpenHarmony/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/bin:$PATH
export PATH=/home/wh/code/code-v3.0.6-LTS/OpenHarmony/prebuilts/cmake/linux-x86/bin:$PATH
source ~/.bashrc
沒錯,這一步的目的主要是使用代碼包中已有的各種關鍵工具。
5.3 后續(xù)步驟
從 3.2 設置python版本開始,繼續(xù)執(zhí)行
6. 問題
問題1: gcc-multilib和gcc-arm-linux-gnueabi沖突
wh@ubuntu:/home/liteos$ sudo apt install gcc-arm-linux-gnueabi
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libc6-dev:i386 libcrypt-dev:i386 linux-libc-dev:i386
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
binutils-arm-linux-gnueabi cpp-9-arm-linux-gnueabi cpp-arm-linux-gnueabi gcc-10-cross-base gcc-9-arm-linux-gnueabi
gcc-9-arm-linux-gnueabi-base gcc-9-cross-base libasan5-armel-cross libatomic1-armel-cross libc6-armel-cross libc6-dev-armel-cross
libgcc-9-dev-armel-cross libgcc-s1-armel-cross libgomp1-armel-cross libstdc++6-armel-cross libubsan1-armel-cross
linux-libc-dev-armel-cross
Suggested packages:
binutils-doc gcc-9-locales cpp-doc gcc-9-multilib-arm-linux-gnueabi gcc-9-doc autoconf automake libtool gdb-arm-linux-gnueabi
gcc-doc
The following packages will be REMOVED:
gcc-multilib
The following NEW packages will be installed:
binutils-arm-linux-gnueabi cpp-9-arm-linux-gnueabi cpp-arm-linux-gnueabi gcc-10-cross-base gcc-9-arm-linux-gnueabi
gcc-9-arm-linux-gnueabi-base gcc-9-cross-base gcc-arm-linux-gnueabi libasan5-armel-cross libatomic1-armel-cross libc6-armel-cross
libc6-dev-armel-cross libgcc-9-dev-armel-cross libgcc-s1-armel-cross libgomp1-armel-cross libstdc++6-armel-cross
libubsan1-armel-cross linux-libc-dev-armel-cross
0 upgraded, 18 newly installed, 1 to remove and 0 not upgraded.
Need to get 26.0 MB of archives.
After this operation, 90.9 MB of additional disk space will be used.
Do you want to continue? [Y/n]
方案:考慮到安裝gcc-arm-linux-gnueabi后,可以安裝gcc-9-multilib-arm-linux-gnueabi,放棄gcc-multilib
sudo apt install gcc-arm-linux-gnueabi -y
sudo apt install gcc-9-multilib-arm-linux-gnueabi -y
7. 參考文獻
-
https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/Readme-CN.md#/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-pkg-prepare.md文章來源:http://www.zghlxwxcb.cn/news/detail-485700.html
-
同時也感謝L同學的大力支持文章來源地址http://www.zghlxwxcb.cn/news/detail-485700.html
到了這里,關于基于Ubuntu20.04搭建OpenHarmony v3.0.6的qemu仿真環(huán)境的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!