编辑
2025-01-22
工作知识
0
请注意,本文编写于 135 天前,最后修改于 135 天前,其中某些信息可能已经过时。

目录

一、编译qemu
二、运行OH

根据qemu启动openharmony镜像(一) 下载或编译qemu(基于X86-64)的文章,可以发现都是基于x86-64平台的的qemu编译和运行,为了支持aarch64,这里提供一个方法来支持aarch64的qemu源码编译和启动

一、编译qemu

这里与上一个文章选用一致得qemu版本8.2.7,如下

wget https://download.qemu.org/qemu-8.2.7.tar.xz

解压后我们需要安装一些包,如下:

apt install libsdl2-image-dev libvirglrenderer-dev libslirp-dev libvde-dev

这样机器qemu支持了sdl2-image和virgl,这样我们开始编译

./configure && make -j123 && make install DESTDIR=out

等编译完成之后,我们打包qemu二进制

tar cvzf out.tar.gz build/out/

此时我们配置PATH即可正常使用

export PATH=$PATH:/home/kylin/out/usr/local/bin

此时显示如下则大功告成

root@kylin:/home/kylin# qemu-system-aarch64 --version QEMU emulator version 8.2.7 Copyright (c) 2003-2023 Fabrice Bellard and the QEMU Project developers

二、运行OH

为了运行OH,我们需要拷贝一下image到arm64的机器上,如下:

scp -r vendor/qemu/arm64_virt/images/ kylin@172.25.82.210:~/

此时我们需要一个qemu-run.sh的脚本,内容如下:

#!/bin/bash qemu-system-aarch64 \ -M virt \ -cpu cortex-a53 \ -smp 4 \ -m 8192 \ -nographic \ -drive if=none,file=./userdata.img,format=raw,id=userdata,index=3 \ -device virtio-blk-device,drive=userdata \ -drive if=none,file=./vendor.img,format=raw,id=vendor,index=2 \ -device virtio-blk-device,drive=vendor \ -drive if=none,file=./system.img,format=raw,id=system,index=1 \ -device virtio-blk-device,drive=system \ -drive if=none,file=./updater.img,format=raw,id=updater,index=0 \ -device virtio-blk-device,drive=updater \ -kernel ./Image \ -initrd ./ramdisk.img \ -vnc :20 \ -k en-us \ -net nic \ -net user,hostfwd=tcp::6666-:6666 \ -device virtio-gpu-pci,xres=486,yres=864 \ -display sdl,gl=on \ -append "loglevel=7 ip=192.168.137.2:192.168.137.1:192.168.137.1:255.255.255.0::eth0:off LIBGL_ALWAYS_SOFTWARE=true LIBGL_DEBUG=verbose EGL_LOG_LEVEL=debug sn=0023456789 console=ttyAMA0,115200 init=/bin/init ohos.boot.hardware=arm64_virt default_boot_device=a003e00.virtio_mmio root=/dev/ram0 rw ohos.required_mount.system=/dev/block/vdb@/usr@ext4@ro,barrier=1@wait,required ohos.required_mount.vendor=/dev/block/vdc@/vendor@ext4@ro,barrier=1@wait,required ohos.required_mount.misc=/dev/block/vda@/misc@none@none=@wait,required ohos.required_mount.data=/dev/block/vdd@/data/@ext4@nosuid,nodev,noatime,barrier=1,data=ordered,noauto_da_alloc@wait,reservedsize=104857600 sn=0023456789"

值得注意的是,这里指定gpu如果是virtio-gpu-gl,则会崩溃,所以需要指定为virtio-gpu-pci。(但是目前都是软渲染,非GPU实现)。

等待一会儿,鸿蒙系统正常运行如下:

image.png