在openharmony开发中常用的开发模式为在linux上编译然后使用samba映射镜像文件然后使用windows刷机工具刷机,本文介绍一种直接在linux平台上借助rockchip提供的upgrade_tool工具直接刷机,通过几条简单的脚本命令就可以快速实现编译自动刷机的功能,同时免去繁琐的wsl,虚拟机开发配置,直接在linux上开始进行rk3568的开发,助力开发者迅速提高开发效率。

    获取openharmony的代码并编译镜像

cd 
curl -s https://gitee.com/oschina/repo/raw/fork_flow/repo-py3 > repo
pip3 install -i https://repo.huaweicloud.com/repository/pypi/simple requests
chmod +x repo
../repo init -u https://gitee.com/openharmony/manifest -b OpenHarmony-4.1-Release --no-repo-verify
../repo sync -c
../repo sync -c -j4
../repo forall -c 'git lfs pull'
bash build/prebuilts_download.sh --skip-ssl
./build.sh --product-name rk3568 --ccache  --no-prebuilt-sdk

根据网络条件和机器的硬件配置可能需要比较长的时间请耐心等待编译完整。如果有编译错误可以在社区寻求帮助。

一切顺利的的话可以看到编译生存的结果

ls out/rk3568/packages/phone/images/

boot_linux.img  config.cfg         parameter.txt  sys_prod.img  updater.img
chip_ckm.img    eng_system.img     ramdisk.img    system.img    userdata.img
chip_prod.img   MiniLoaderAll.bin  resource.img   uboot.img     vendor.img
 

获取upgrade_tool的代码

upgrade_tool_v2.17  目前使用的是2.17版本,下载之后解压,复制到/usr/local/bin目录

 

unzip upgrade_tool_v2.17.zip
sudo cp upgrade_tool_v2.17_for_linux/upgrade_tool /usr/local/bin/upgrade_tool
sudo chmod +x /usr/local/bin/upgrade_tool

通过以下命令验证成功

upgrade_tool -v
Upgrade Tool v2.17
 

刷机

用upgrade_tool进行确认是刷机状态,注意所有的命令都要使用root权限

sudo upgrade_tool ld
List of rockusb connected(1)
DevNo=1    Vid=0x2207,Pid=0x350a,LocationID=17    Mode=Loader    SerialNo=eb29d5e30ad79187

也有可能是maskrom状态。

List of rockusb connected(1)
DevNo=1 Vid=0x2207,Pid=0x350a,LocationID=17     Mode=Maskrom    SerialNo=rockchip

如果状态不对,可能就会无法刷机。如果是第一次刷机可能需要手动按键进入刷机状态,如果是已经有系统可以通过reboot loader进入刷机状态。详细刷机命令如下,请根据自己的环境修改文件路径。

hdc shell reboot loader
sleep 5
sudo upgrade_tool db /home/ubuntu/openharmony/out/rk3568/packages/phone/images/MiniLoaderAll.bin
sudo upgrade_tool di -p /home/ubuntu/openharmony/out/rk3568/packages/phone/images/parameter.txt
sudo upgrade_tool di -uboot /home/ubuntu/openharmony/out/rk3568/packages/phone/images/uboot.img
sudo upgrade_tool di -resource /home/ubuntu/openharmony/out/rk3568/packages/phone/images/resource.img
sudo upgrade_tool di -boot_linux /home/ubuntu/openharmony/out/rk3568/packages/phone/images/boot_linux.img
sudo upgrade_tool di -ramdisk /home/ubuntu/openharmony/out/rk3568/packages/phone/images/ramdisk.img
sudo upgrade_tool di -system /home/ubuntu/openharmony/out/rk3568/packages/phone/images/system.img
sudo upgrade_tool di -vendor /home/ubuntu/openharmony/out/rk3568/packages/phone/images/vendor.img
sudo upgrade_tool di -sys-prod /home/ubuntu/openharmony/out/rk3568/packages/phone/images/sys_prod.img
sudo upgrade_tool di -chip-prod /home/ubuntu/openharmony/out/rk3568/packages/phone/images/chip_prod.img
sudo upgrade_tool di -updater /home/ubuntu/openharmony/out/rk3568/packages/phone/images/updater.img
sudo upgrade_tool di -eng_system /home/ubuntu/openharmony/out/rk3568/packages/phone/images/eng_system.img
#sudo upgrade_tool di -eng_chipset /home/ubuntu/openharmony/out/rk3568/packages/phone/images/eng_chipset.img
sudo upgrade_tool di -chip_ckm /home/ubuntu/openharmony/out/rk3568/packages/phone/images/chip_ckm.img
sudo upgrade_tool di -userdata /home/ubuntu/openharmony/out/rk3568/packages/phone/images/userdata.img
sudo upgrade_tool rd


命令说明:

hdc shell reboot loader 

                  重启鸿蒙挤进入loader模式,然后slepp 5以便开发板进入刷机模式,可能根据实际情况调整。

 

sudo upgrade_tool db /home/ubuntu/openharmony/out/rk3568/packages/phone/images/MiniLoaderAll.bin

                 下载loader,如果是loader状态则可以省略,maskrom必须要使用此命令.

 

sudo upgrade_tool di -p /home/ubuntu/openharmony/out/rk3568/packages/phone/images/parameter.txt

                 下载分区表文件,注意要学会查看分分区表的文件,之后的命令就是按照分区表定义的分区进行刷机的。

 

sudo upgrade_tool di -resource /home/ubuntu/openharmony/out/rk3568/packages/phone/images/resource.img

                  下载resrouce分区,由于在分区表parameter.txt已经定义了分区的起始位置和长度,所以这个命令就不需要指定这些信息了。

                    -resource 为分区名字,在parameter.txt中定义的名称。后面的路径就是对应的img文件路径。

 

sudo upgrade_tool rd

                   重启设备

更新编译自动刷机

修改代码自己第二次编译就比较简答了,只要调整一下脚本就可以自动刷新了。

重启开发板到loader,然后编译再刷机就行了。只不过要注意的是可以根据自己修改的内容只刷发生变化的的分区,这样可以进一步提升开发效率。

hdc shell reboot loader
./build.sh --product-name rk3568 --ccache  --no-prebuilt-sdk
sudo upgrade_tool db /home/ubuntu/openharmony/out/rk3568/packages/phone/images/MiniLoaderAll.bin
sudo upgrade_tool di -p /home/ubuntu/openharmony/out/rk3568/packages/phone/images/parameter.txt
sudo upgrade_tool di -uboot /home/ubuntu/openharmony/out/rk3568/packages/phone/images/uboot.img
sudo upgrade_tool di -resource /home/ubuntu/openharmony/out/rk3568/packages/phone/images/resource.img
sudo upgrade_tool di -boot_linux /home/ubuntu/openharmony/out/rk3568/packages/phone/images/boot_linux.img
sudo upgrade_tool di -ramdisk /home/ubuntu/openharmony/out/rk3568/packages/phone/images/ramdisk.img
sudo upgrade_tool di -system /home/ubuntu/openharmony/out/rk3568/packages/phone/images/system.img
sudo upgrade_tool di -vendor /home/ubuntu/openharmony/out/rk3568/packages/phone/images/vendor.img
sudo upgrade_tool di -sys-prod /home/ubuntu/openharmony/out/rk3568/packages/phone/images/sys_prod.img
sudo upgrade_tool di -chip-prod /home/ubuntu/openharmony/out/rk3568/packages/phone/images/chip_prod.img
sudo upgrade_tool di -updater /home/ubuntu/openharmony/out/rk3568/packages/phone/images/updater.img
sudo upgrade_tool di -eng_system /home/ubuntu/openharmony/out/rk3568/packages/phone/images/eng_system.img
#sudo upgrade_tool di -eng_chipset /home/ubuntu/openharmony/out/rk3568/packages/phone/images/eng_chipset.img
sudo upgrade_tool di -chip_ckm /home/ubuntu/openharmony/out/rk3568/packages/phone/images/chip_ckm.img
sudo upgrade_tool di -userdata /home/ubuntu/openharmony/out/rk3568/packages/phone/images/userdata.img
sudo upgrade_tool rd

 

如果有问题欢迎提问,或者在社区寻求帮助。原则上其他rockchip系列芯片也可以按照此方法进行,目前只在3568上测试。

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐