【鸿蒙开发】win10 Ubuntu 20.04 WSL子系统开
2021-02-28 本文已影响0人
Geekero
小熊派交叉编译的原理:

一、让win10支持WSL
- 开发者模式中选择WSL选项(这个简单,有需要的话可以百度,这里不啰嗦)
二、机器支持虚拟化



三、选择安装的linux子系统的发行版
由于教程用的是Ubuntu,自己用的是centos7,所以又装了Ubuntu子系统。结果惊讶地发现,win10可以安装多个子系统

四、更换apt的源并更新系统
sudo vi /etc/apt/sources.list
将http://archive.ubuntu.com/
修改成https:mirrors.aliyun.com
更新系统:
sudo apt update
sudo apt upgrade
五、更换默认shell为bash
sudo dpkg-reconfigure dash
ls -l /bin/sh
lrwxrwxrwx 1 root root 9 Feb 26 00:00 /bin/sh -> /bin/bash
选择no
六、正式搭建编译环境
Linux安装:

windows安装:

6.1 Linux Python环境:
安装Python开发 环境
由于我的ubuntu是20.04,默认已经安装了python3.8
$ sudo apt-get install python3.8
$ python3 --version
Python 3.8.5
$ sudo ln -s /usr/bin/python3 /usr/bin/python
$ which python3.8
/usr/bin/python3.8
#安装pip工具
$ sudo apt-get install python3-setuptools python3-pip -y
$ sudo pip3 install --upgrade pip
$ pip3 install setuptools
配置一下源:
$ sudo pip3 config set global.index-url https://mirrors.aliyun.com/pypi/simple/
接续安装:
sudo pip3 install kconfiglib #GUI menuconfig工具:
sudo pip3 install pycryptodome
sudo pip3 install launchpadlib==1.10.13
sudo pip3 install six --upgrade --ignore-installed six
sudo pip3 install ecdsa
sudo apt install scons -y #安装Scons
scons -v #检查
6.2 在Linux中安装交叉编译器、gn 和 ninjia
gn工具下载
ninjia工具下载
risc-v交叉编译器下载
安装:
#解压到home目录:
tar -xvf gn.1523.tar -C ~/
tar -xvf ninja.1.9.0.tar -C ~/
tar -xvf gcc_riscv32-linux-7.3.0.tar.gz -C ~/
将工具路径添加~/.barshrc
sudo vim ~/.bashrc
## 文件最后一行添加以下语句:
export PATH=~/gn:$PATH
export PATH=~/ninja:$PATH
export PATH=~/gcc_riscv32/bin:$PATH
刷新环境配置
source ~/.bashrc
# 检查
riscv32-unknown-elf-gcc -v
win10中下载安装烧录工具:
- USB转串口驱动:CH341SER.EXE
- 代码烧录工具: Hiburn 密码:1234
安装并检查端口即可

七、下载源码并且烧录
7.1 Linux安装node.js
wget https://nodejs.org/dist/v14.15.1/node-v14.15.1-linux-x64.tar.xz
tar -xvf node-v14.15.1-linux-x64.tar.xz -C ~/
sudo ln -s ~/node-v14.15.1-linux-x64/bin/npm /usr/bin/
sudo ln -s ~/node-v14.15.1-linux-x64/bin/node /usr/bin/
node -v
7.2 安装hpm
npm install -g @ohos/hpm-cli
sudo ln -s ~/node-v14.15.1-linux-x64/bin/hpm /usr/bin
hpm --version
7.3 配置git
git config --global user.name "yourname"
git config --global user.email "your-email-address"
7.4 下载源码(有四种方法,这里只选择一种)
hpm init -t default
hpm i @bearpi/bearpi_hm_nano
hpm install
hpm dist
源码目录说明:


开启VSCODE的remote WSL,登录Linux子系统:


#include <stdio.h>
#include "ohos_init.h"
void Hello_World(void)
{
print("Hello World!\r\n");
}
//运行函数
APP_FEATURE_INIT(Hello_World); //#函数名
编写编译构建文件

static_library("myapp"){
sources = [
"hello_wolrd.c"
]
include_dirs = [
"//utils/native/lite/include"
]
}
-
static_library
中制定业务模块的编译结果,为静态库文件libmyapp.a, 开发者根据实际情况完成填写; -
sources
中制定静态库.a所依赖的.c文件及其路径,若路径中包含“//”则表明绝对路径(此处为代码根目录),若不包含"//"则表示相对路径 -
include_dirs
中制定sources所依赖的.h文件路径。
编译模块编译文件

lite_component("app") {
features = [
my_app:"myapp",
]
}
编译文件

hpm dist
烧录
打开hiburn 波特率设置为961200

选择烧录文件:D:\harmonyOS\bearpi\code\out\BearPi-HM_Nano

选择自动烧录和连接

按动开发板上的复位按键进行烧录
