1. 程式人生 > 實用技巧 >IMX6ULL開發板體驗Harmony LiteOS-A核心

IMX6ULL開發板體驗Harmony LiteOS-A核心

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 "[email protected]"
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