1 概述
鴻蒙系統開發有兩個方向:
- 北向:APP
- 南向:內核
一直覺得很懵,鴻蒙到底是什么,是整個系統還是單個內核,直到看完教程還是很迷。嘗試用安卓來對比:
鴻蒙 | 安卓 | |
---|---|---|
內核 | Linux/LiteOS | Linux |
系統語言 | C、C++ | C、C++、JAVA |
APP語言 | C、C++ | JAVA、Kotlin |
IDE | HUAWEI DevEco Device Tool | Android Studio、Eclipse |
場景 | 手機/平板/車載系統/可穿戴設備/電視…… | 同左 |
技術架構:
鴻蒙指的是這一整套東西,而這篇文章只用到了內核層的LiteOS,沒有涉及分布式軟總線和桌面APP等部分。
2 快速開始
環境:
- Win10
- Hyper虛擬機 Ubuntu 18.04
- 100ASK_IMX6ULL開發板
- OpenHarmony 1.0
- MobaXterm 20.3
- 100ask imx6ull flashing tool 4.0
資料:
- gitee: 鴻蒙內核Liteos-a開發手冊.docx,鴻蒙開發板100ASK_IMX6ULL使用手冊.pdf,APP、patch源碼,燒寫工具。
- 百度網盤:開發板資料,開發工具
- 視頻:百問網,b站
把開發板設置為 USB 啟動,接好 2 條 USB 線,裝好驅動程序后,運行燒寫工具100ask_imx6ull_flashing_tool。點下載到內存並啟動。串口115200,MobaXterm看到有輸出,啟動成功。重置后要重新下載運行。
重啟,點擊燒寫到存儲介質,設置默認系統是HMOS,點確認。關機,設置EMMC啟動,開機,成功。一次燒錄多次運行。
運行電子相冊,韋老師自己寫的
./bin/digitpic
錯位了,應該在正中間。
3 編譯LiteOS-a
3.1 配置環境
遠程登錄Ubuntu虛擬機,執行命令
wget --no-check-certificate -O Configuring_ubuntu.sh https://weidongshan.coding.net/p/DevelopmentEnvConf/d/DevelopmentEnvConf/git/raw/master/Configuring_ubuntu.sh && sudo chmod +x Configuring_ubuntu.sh && sudo ./Configuring_ubuntu.sh
選1
python版本必須在3.7以上
/bin/sh必須指向/bin/bash
配置Git
git config --global user.name "100ask"
git config --global user.email "weidongshan@qq.com"
git config --global credential.helper store
安裝repo(repo是用來管理多個git倉庫的)
curl https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > repo
sudo cp repo /usr/local/bin/repo && sudo chmod a+x /usr/local/bin/repo
sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
這個提示不用管
The directory '/home/rong/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/rong/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
3.2 下載源碼
cd ~
mkdir openharmony
cd openharmony
repo init -u https://gitee.com/openharmony/manifest.git -b OpenHarmony-1.0
repo sync -c -j8
編譯官方版本
cd ~/openharmony
python build.py ipcamera_hi3518ev300 -b debug
必須要編譯成功一次,因為imx6ull的代碼沒改完,要借助官方版本來編譯一些庫,用於后面編譯運行電子相冊。
成功
3.3 下載補丁
cd ~
git clone https://gitee.com/weidongshan/openharmony_for_imx6ull.git
使用補丁文件修改代碼
cd ~/openharmony
patch -p1 < ~/openharmony_for_imx6ull/patch/hmos_v1.0_imx6ull.patch
編譯
cd ~/openharmony/kernel/liteos_a
cp tools/build/config/debug/imx6ull_clang.config .config // 配置
make clean // 先清除一下,否則會提示錯誤
make -j 8 // 編譯內核,可以得到out/imx6ull/liteos.bin
make rootfs // 編譯根文件系統,可以得到rootfs.img
cp out/imx6ull/rootfs.img out/imx6ull/rootfs.jffs2 // 改個名易辨認,燒寫工具使用rootfs.jffs2
4 編譯APP
cd /home/rong/openharmony_for_imx6ull/apps/hello
clang -target arm-liteos --sysroot=/home/rong/openharmony/prebuilts/lite/sysroot/ -o hello hello.c
或者修改Makefile后直接make
把執行文件放到kernel源碼
cp hello /home/rong/openharmony/kernel/liteos_a/out/imx6ull/rootfs/bin
重新制作rootfs.jffs2
cd /home/rong/openharmony/kernel/liteos_a/out/imx6ull/
mkfs.jffs2 -s 0x10000 -e 0x10000 -d rootfs -o rootfs.jffs2
把得到的liteos.bin和rootfs.jffs2放到燒寫工具的files目錄,就可以使用燒寫工具啟動了。
運行成功
源碼地址:https://gitee.com/obarong/myharmony
imx6ull分支
參考
【鴻蒙開發】韋東山手把手教你移植鴻蒙系統_基於IMX6ULL_嗶哩嗶哩 (゜-゜)つロ 干杯~-bilibili
https://www.bilibili.com/video/BV1ep4y1a7LH
openharmony_for_imx6ull: 支持IMX6ULL 系列開發板的鴻蒙系統補丁
https://gitee.com/weidongshan/openharmony_for_imx6ull
百問網Imx6ull開發板 - 百問網嵌入式Linux wiki
http://wiki.100ask.org/100ask_imx6ull
GitHub - LiteOS/LiteOS: code and manual
https://github.com/LiteOS/LiteOS