推荐使用Ubuntu20.04,自带Python3.8。18.04版本Python版本是3.6.9,安装3.8.0后终端打不开。如果不想使用Ubuntu的桌面环境,那么使用Ubuntu18.04也可以。
下载镜像:https://mirrors.tuna.tsinghua.edu.cn/ubuntu-releases/20.04.3/
安装系统时,不要联网更新。否则可能有一些编译所需的依赖被更新成高版本,导致一些必要的工具安装不了,只能一一卸载高版本,安装为依赖的指定版本。
安装成功后,可以将软件源切换为HUAWEI镜像源,这样下载软件可以很快。在软件和更新中选择Ubuntu软件标签,点击下载自 其他站点,选择mirrors.huaweicloud.com
即可。
安装必要工具
sudo apt install git git-lfs curl build-essential gcc g++ make zlib* libffi-dev e2fsprogs pkg-config flex bison perl bc openssl libssl-dev libelf-dev libc6-dev-amd64 binutils binutils-dev libdwarf-dev u-boot-tools mtd-utils gcc-arm-linux-gnueabi virtualenv python3-dev python3.8-venv libdbus-glib-1-dev libgirepository1.0-dev libcairo2-dev dosfstools mtools default-jre default-jdk authbind
设置Python和Python3都指向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
安装码云repo工具
curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > /usr/local/bin/repo #如果没有权限,可下载至其他目录,并将其配置到环境变量中
chmod a+x /usr/local/bin/repo
pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests
配置git环境
git config --global user.name "yourname"
git config --global user.email "your-email-address"
git config --global credential.helper store
ssh-keygen -t rsa -C "your-email-address" #生成公私密钥
cat ~/.ssh/id_rsa.pub #查看公钥,公钥需要添加到码云网站中
repo init -u [email protected]:openharmony/manifest.git -b master --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'
以ipcamera_hispark_taurus_linux
产品为例,执行编译
hb set #根路径选择代码路径;设备选择ipcamera_hispark_taurus_linux
hb env #查看当前配置
#hb clean #清除编译中间件
hb build #开始编译
#hb build -f #清除编译中间件,然后编译
编译出的镜像在out/hispark_taurus/ipcamera_hispark_taurus_linux
。
按照码云的官方文档操作,遇到了一些问题:
编译时脚本出现[OHOS ERROR] build.sh: 7: [: clang: unexpected operator
之类的语法错误,可以检查sh
ls -l /bin/sh
如果sh指向dash,需要更改为bash
sudo dpkg-reconfigure dash
提示选择Yes/No? No
编译时报错No package 'dbus-1' found
,需要安装一些依赖
sudo apt install virtualenv build-essential python3-dev libdbus-glib-1-dev libgirepository1.0-dev libcairo2-dev
编译时报错"FileNotFoundError: [Errno 2] No such file or directory: 'java'"
,需要安装JDK
sudo apt install default-jre default-jdk
已经下载代码、编译了,接下来执行烧录。
下载地址:http://www.hihope.org/download/download.aspx?mtt=12
Windows平台和Linux平台均可烧录。
Windows平台使用HiTool烧录。HiTool下载链接:http://www.hihope.org/download/download.aspx?mtt=33
#!/bin/bashPROJECT_PATH=~/code/OpenHarmony/OpenHarmonyWINDOWS_PATH=/media/lidw/File/temp/imgcp $PROJECT_PATH/device/hisilicon/hi3516dv300/sdk_linux/open_source/bin/u-boot-hi3516dv300_emmc.bin $WINDOWS_PATH/cp $PROJECT_PATH/out/hispark_taurus/ipcamera_hispark_taurus_linux/uImage_hi3516dv300_smp $WINDOWS_PATH/cp $PROJECT_PATH/out/hispark_taurus/ipcamera_hispark_taurus_linux/rootfs_ext4.img $WINDOWS_PATH/cp $PROJECT_PATH/out/hispark_taurus/ipcamera_hispark_taurus_linux/userfs_ext4.img $WINDOWS_PATH/cp $PROJECT_PATH/out/hispark_taurus/ipcamera_hispark_taurus_linux/userdata_ext4.img $WINDOWS_PATH/
创建配置文件3516DV300_linux.xml
<Partition_Info ProgrammerFile=""><Part Sel="0" PartitionName="fastboot" FlashType="emmc" FileSystem="none" Start="0" Length="1M" SelectFile="D:\temp\img\u-boot-hi3516dv300_emmc.bin"/><Part Sel="1" PartitionName="smp" FlashType="emmc" FileSystem="none" Start="1M" Length="9M" SelectFile="D:\temp\img\uImage_hi3516dv300_smp"/><Part Sel="1" PartitionName="roots" FlashType="emmc" FileSystem="ext3/4" Start="10M" Length="50M" SelectFile="D:\temp\img\rootfs_ext4.img"/><Part Sel="1" PartitionName="users" FlashType="emmc" FileSystem="ext3/4" Start="60M" Length="50M" SelectFile="D:\temp\img\userfs_ext4.img"/><Part Sel="1" PartitionName="userdata" FlashType="emmc" FileSystem="ext3/4" Start="110M" Length="1024M" SelectFile="D:\temp\img\userdata_ext4.img"/>Partition_Info>
开发板选择Hi3516DV300
,在emmc烧录
标签下加载xml文件,执行烧录即可。
新开发板第一次烧录时,需要修改启动引导参数,如不修改,无法正常进入系统,则设备不亮。
如果不是第一次烧录,设备正常亮屏,那么不需执行这一步。
烧录完成后,点击Monitor可连接串口,下电重新上电时,会加载U-boot引导文件,这时有2s的等待时间。注意观察Monitor命令行的输出信息,按照提示按下回车,可以进入命令行:
hisilicon #
输入命令:
setenv bootargs "mem=128M console=ttyAMA0,115200 root=/dev/mmcblk0p3 rw rootfstype=ext4 rootwait blkdevparts=mmcblk0:1M(boot),9M(kernel),50M(rootfs),50M(userfs),1024M(userdata)"setenv bootcmd "mmc read 0x0 0x82000000 0x800 0x4800;mw 0x10FF0044 0X600;mw 0x120D2010 0x00000000;mw 0x120D2400 0x000000ff;mw 0x120D2010 0x00000000;bootm 0x82000000"saveenvreset
Linux平台使用Visual Studio Code和DevEco Device Tool开发和烧录,安装配置参考《Ubuntu开发环境准备》操作即可。
开发板选择Hi3516DV300
。工程路径选择下载代码的路径,framework选择Hb
。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Pb19ZfaM-1635563851084)(.assets/OpenHarmony轻量和小型系统开发指导/image-20211005235534179.png)]
在工程页签中,选择烧录方式,Linux平台支持串口烧录、网口烧录。
各镜像的烧录参数在对应的页签中配置,配置参数和Windows平台烧录参数一致。对照修改即可。
串口方式只需选择好串口号,传输协议选择hiburn-serial
。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OlbyrHgu-1635563851087)(.assets/OpenHarmony轻量和小型系统开发指导/image-20211006010847300.png)]
或者可以直接修改配置文件.deveco/deveco.ini
。
; DevEco Project Configuration File; Version: 2.0.2; Core Version: 2.2.0+300.38affcf6[deveco][env]framework = hb[env:hi3516dv300_linux]platform = hisilicon_armboard = hi3516dv300upload_partitions = partition:hi3516dv300_linux_fastboot partition:hi3516dv300_linux_kernel partition:hi3516dv300_linux_rootfs partition:hi3516dv300_linux_userfsacts_option = testsuite:user_1_hi3516dv300_testbuild_type = releaseupload_port = /dev/ttyUSB0upload_protocol = hiburn-serialupload_net_server_ip = upload_net_client_mask = upload_net_client_gw = upload_net_client_ip = debug_client = debug_extra_cmds = [partition:hi3516dv300_linux_fastboot]partition_type = fastbootpartition_board = hi3516dv300partition_platform = hisilicon_armpartition_bin = device/hisilicon/hi3516dv300/sdk_linux/open_source/bin/u-boot-hi3516dv300_emmc.binpartition_fs = none[partition:hi3516dv300_linux_kernel]partition_type = kernelpartition_board = hi3516dv300partition_platform = hisilicon_armpartition_bin = out/hispark_taurus/ipcamera_hispark_taurus_linux/uImage_hi3516dv300_smppartition_fs = none[partition:hi3516dv300_linux_rootfs]partition_type = rootfspartition_board = hi3516dv300partition_platform = hisilicon_armpartition_length = 0x3200000partition_fs = ext3/4partition_bin = out/hispark_taurus/ipcamera_hispark_taurus_linux/rootfs_ext4.img[partition:hi3516dv300_linux_userfs]partition_type = userfspartition_board = hi3516dv300partition_platform = hisilicon_armpartition_addr = 0x3c00000partition_bin = out/hispark_taurus/ipcamera_hispark_taurus_linux/userfs_ext4.img[testsuite:hi3516dv300_linux_test]test_port = nfs_server_ip = nfs_server_dir = test_modules =
网口烧录也需要连接串口,传输协议选择hiburn-net
。此外需要额外配置开发板网口IP信息。
ifconfig #查看开发板网口信息sudo ifconfig enx000ec686c5a6 192.168.1.2 netmask 255.255.255.0 #配置IP信息#ifconfig # 检查是否配置成功
然后在工程中设置开发板网口IP。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-iNocEDzr-1635563851089)(.assets/OpenHarmony轻量和小型系统开发指导/image-20211008012151000.png)]
或者可以直接修改配置文件.deveco/deveco.ini
。
; DevEco Project Configuration File; Version: 2.0.2; Core Version: 2.2.0+300.38affcf6[deveco][env]framework = hb[env:hi3516dv300_linux]platform = hisilicon_armboard = hi3516dv300upload_partitions = partition:hi3516dv300_linux_fastboot partition:hi3516dv300_linux_kernel partition:hi3516dv300_linux_rootfs partition:hi3516dv300_linux_userfsacts_option = testsuite:user_1_hi3516dv300_testbuild_type = releaseupload_port = /dev/ttyUSB0upload_protocol = hiburn-netupload_net_server_ip = 192.168.1.2upload_net_client_mask = 255.255.255.0upload_net_client_gw = 192.168.1.1upload_net_client_ip = 192.168.1.3debug_client = debug_extra_cmds = [partition:hi3516dv300_linux_fastboot]partition_type = fastbootpartition_board = hi3516dv300partition_platform = hisilicon_armpartition_bin = device/hisilicon/hi3516dv300/sdk_linux/open_source/bin/u-boot-hi3516dv300_emmc.binpartition_fs = none[partition:hi3516dv300_linux_kernel]partition_type = kernelpartition_board = hi3516dv300partition_platform = hisilicon_armpartition_bin = out/hispark_taurus/ipcamera_hispark_taurus_linux/uImage_hi3516dv300_smppartition_fs = none[partition:hi3516dv300_linux_rootfs]partition_type = rootfspartition_board = hi3516dv300partition_platform = hisilicon_armpartition_length = 0x3200000partition_fs = ext3/4partition_bin = out/hispark_taurus/ipcamera_hispark_taurus_linux/rootfs_ext4.img[partition:hi3516dv300_linux_userfs]partition_type = userfspartition_board = hi3516dv300partition_platform = hisilicon_armpartition_addr = 0x3c00000partition_bin = out/hispark_taurus/ipcamera_hispark_taurus_linux/userfs_ext4.img[testsuite:hi3516dv300_linux_test]test_port = nfs_server_ip = nfs_server_dir = test_modules =
保存好配置文件后重新打开工程,可以看到工程中包含两套配置。点击Upload
执行烧录即可。烧录过程中需要上下电,按照命令行提示操作即可。
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-I9uGQhwg-1635563851090)(.assets/OpenHarmony轻量和小型系统开发指导/image-20211006011734124.png)]
新开发板第一次烧录时,需要修改启动引导参数,如不修改,无法正常进入系统,则设备不亮。
如果不是第一次烧录,设备正常亮屏,那么不需执行这一步。
烧录完成后,点击Monitor可连接串口,下电重新上电时,会加载U-boot引导文件,这时有2s的等待时间。注意观察Monitor命令行的输出信息,按照提示按下回车,可以进入命令行:
hisilicon #
输入命令:
setenv bootargs "mem=128M console=ttyAMA0,115200 root=/dev/mmcblk0p3 rw rootfstype=ext4 rootwait blkdevparts=mmcblk0:1M(boot),9M(kernel),50M(rootfs),50M(userfs),1024M(userdata)"setenv bootcmd "mmc read 0x0 0x82000000 0x800 0x4800;mw 0x10FF0044 0X600;mw 0x120D2010 0x00000000;mw 0x120D2400 0x000000ff;mw 0x120D2010 0x00000000;bootm 0x82000000"saveenvreset
之后设备正常亮屏,可以正常使用。
轻量和小型系统开发指导
Ubuntu编译环境准备
源码获取
解决 linux下编译.sh文件报错 “[: XXXX: unexpected operator” 问题]
Installation failed: No package ‘dbus-1’ found
HUAWEI DevEco Device Tool使用指南——Ubuntu开发环境准备
Hi3516DV300开发板烧录
Ubuntu 开启NFS服务