系列文章目录
【鸿蒙】0x00-OpenHarmony-4.1-Release DAYU200 RK3568开发环境总结(长文版)
【鸿蒙】0x01-LiteOS-M基于Qemu Arm Cortex-m55运行
Qemu Arm Cortex-m55 mps3-an547 教程
cortex-m55架构参考QEMU教程 for cortex-m55
更新日志
日期 | 变更内容 |
---|---|
2024-08-24 | 完成第一版 |
简介
arm_mps3_an547
/ 子目录包含部分Qemu arm cortex-m55
虚拟化平台验证的OpenHarmony kernel_liteos_m
的代码,目录名为arm_mps3_an547
。
Arm Cortex-m55
虚拟化平台是一个 qemu-system-arm
的目标设备,通过它来模拟一个通用的、基于arm cortex-m55
架构的单板。
这次模拟的配置是:arm cortex-m55
架构,1
个CPU
,16M
内存。
提示: 系统内存硬编码为16MB
。
环境准备
安装QEMU
sudo apt install build-essential zlib1g-dev pkg-config libglib2.0-dev binutils-dev libboost-all-dev autoconf libtool libssl-dev libpixman-1-dev virtualenv flex bison
- QEMU获取源码
wget https://download.qemu.org/qemu-6.2.0.tar.xz
- 编译安装QEMU
tar -xf qemu-6.2.0.tar.xz
cd qemu-6.2.0
mkdir build && cd build
../configure --prefix=qemu_installation_path
make -j16
等待编译结束, 执行安装命令:
make install
- 环境变量
最后将安装路径添加到环境变量中:
vim ~/.bashrc
在~/.bashrc最末尾加入:
export PATH=$PATH:qemu_installation_path
其他
python环境等, 建议参考: 【鸿蒙】0x00-OpenHarmony-4.1-Release DAYU200 RK3568开发环境总结(长文版)
代码获取
提示: 可以使用 repo
命令来获取源码。
repo init -u https://gitee.com/openharmony/manifest.git -b master --no-repo-verify
repo sync -c
repo forall -c 'git lfs pull'
./build/prebuilts_download.sh
======copy inside cxx finished!======
======update llvm ndk finished!======
编译
使用命令行方式
在开始正式编译之前,建议清空
~/.ccache
目录, 执行rm ~/.ccache
./build.sh --product-name=qemu_cm55_mini_system_demo --device-name=qemu_cm55_mini_system_demo --no-prebuilt-sdk --jobs=4 --ccache
[OHOS INFO] [671/671] STAMP obj/build/core/gn/images.stamp
[OHOS INFO] end hpm command
[OHOS INFO] The run time for _ninja is 11.35 s
[OHOS INFO] start run hpm command
[OHOS INFO] ccache_dir = /home/xxxx/.ccache, ccache_exec = /usr/bin/ccache
[OHOS INFO] --------------------------------------------
[OHOS INFO] ccache summary:
[OHOS INFO] ccache version: 4.5.1
[OHOS INFO] cache hit (direct): 0
[OHOS INFO] cache hit (preprocessed): 0
[OHOS INFO] cache miss: 499
[OHOS INFO] hit rate: 0.00%
[OHOS INFO] miss rate: 100.00%
[OHOS INFO] Cache size (GB): 0.00 / 100.00 (0.00 %)
[OHOS INFO] ---------------------------------------------
[OHOS INFO] end hpm command
[OHOS INFO] start run hpm command
[OHOS INFO] end hpm command
[OHOS INFO] start run hpm command
[OHOS INFO] unrecognized ninja log format, we need # ninja log v5
[OHOS INFO]
[OHOS INFO] end hpm command
[OHOS INFO] start run hpm command
[OHOS INFO] c targets overlap rate statistics
[OHOS INFO] subsystem files NO. percentage builds NO. percentage overlap rate
[OHOS INFO] hiviewdfx 12 2.4% 12 2.4% 1.00
[OHOS INFO] kernel 57 11.4% 57 11.4% 1.00
[OHOS INFO] security 71 14.2% 71 14.2% 1.00
[OHOS INFO] startup 26 5.2% 26 5.2% 1.00
[OHOS INFO] systemabilitymgr 15 3.0% 15 3.0% 1.00
[OHOS INFO] thirdparty 310 62.1% 310 62.1% 1.00
[OHOS INFO]
[OHOS INFO] c overall build overlap rate: 1.00
[OHOS INFO]
[OHOS INFO]
[OHOS INFO] end hpm command
[OHOS INFO] qemu_cm55_mini_system_demo build success
[OHOS INFO] Cost Time: 0:00:48
=====build successful=====
2024-08-24 00:15:36
++++++++++++++++++++++++++++++++++++++++
构建会产生 OHOS_Image
的镜像文件,在构建完成之后,对应的镜像文件在如下目录:
out/arm_mps3_an547/qemu_cm55_mini_system_demo/
在Qemu中运行镜像
提示:安装6.2.0
版本的qemu才能支持cortex-m55
处理器的MVE特性。
执行./qemu-run --help
提示如下:
Usage: qemu-run [OPTION]...
Run a OHOS image in qemu according to the options.
Options:
-e, --exec file_name kernel exec file name
-g, --gdb enable gdb for kernel
-t, --test test mode, exclusive with -g
-h, --help print help info
By default, the kernel exec file is: out/arm_mps3_an547/qemu_cm55_mini_system_demo/OHOS_Image.
开启gdb调试特性
cd device/qemu/arm_mps3_an547
vim liteos_m/config.gni
将 board_opt_flags
中的
board_opt_flags = []
编译选项修改为:
board_opt_flags = [ "-g" ]
保存并退出,在OHOS根目录重新编译:
./build.sh --product-name=qemu_cm55_mini_system_demo --device-name=qemu_cm55_mini_system_demo --no-prebuilt-sdk --jobs=4 --ccache
QEMU gdb 运行
gcc-arm-none-eabi环境准备
wget https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu-rm/10.3-2021.10/gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
1.命令安装
提示:命令安装的工具链无 arm-none-eabi-gdb
,无法进行gdb
调试
sudo apt install gcc-arm-none-eabi
2.安装包安装
提示:安装2020年后推出的交叉工具链才能支持cortex-m55
处理器的MVE
特性。如果已经通过命令安装了gcc-arm-none-eabi
, 可以通过命令:sudo apt remove gcc-arm-none-eabi
卸载之后,再进行安装。
下载工具链安装包。
chmod 777 gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2
tar -xvf gcc-arm-none-eabi-10.3-2021.10-x86_64-linux.tar.bz2 install_path
将安装路径添加到环境变量中:
vim ~/.bashrc
在~/.bashrc
最末尾加入:
export PATH=$PATH:/home/bigdark/Develop/soft/gcc-arm-none-eabi-10.3-2021.10/bin
qemu运行
- hb set
(py3_env) ➜ openHarmony hb set
[OHOS INFO] Input code path: .
OHOS Which product do you need? qemu_cm55_mini_system_demo
在一个窗口中输入命令:
(py3_env) ➜ openHarmony ./qemu-run -g
board: arm_mps3_an547
Qemu kernel gdb enable...
Enter to start qemu[y/n]:y
会卡主在这里
在另一个窗口中输入命令:
arm-none-eabi-gdb out/arm_mps3_an547/qemu_cm55_mini_system_demo/OHOS_Image
(gdb) target remote localhost:1234
(gdb) b main
详细信息
(py3_env) ➜ openHarmony arm-none-eabi-gdb out/arm_mps3_an547/qemu_cm55_mini_system_demo/OHOS_Image
GNU gdb (GNU Arm Embedded Toolchain 10.3-2021.10) 10.2.90.20210621-git
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from out/arm_mps3_an547/qemu_cm55_mini_system_demo/OHOS_Image...
(gdb) target remote localhost:1234
Remote debugging using localhost:1234
Reset_Handler () at ../../../device/qemu/arm_mps3_an547/liteos_m/board/startup.s:50
50 ldr r0, =__bss_start
(gdb) b main
Breakpoint 1 at 0x2100e940: file ../../../device/qemu/arm_mps3_an547/liteos_m/board/main.c, line 41.
(gdb) run
The "remote" target does not support "run". Try "help target" or "continue".
(gdb) continue
Continuing.
Breakpoint 1, main () at ../../../device/qemu/arm_mps3_an547/liteos_m/board/main.c:41
41 __asm volatile
(gdb) n
61 EPUInit();
(gdb) n
62 UartInit();
(gdb) n
64 ret = LOS_KernelInit();
(gdb) n
65 if (ret != LOS_OK) {
(gdb) n
70 Uart0RxIrqRegister();
(gdb) n
73 ret = LosShellInit();
(gdb) n
74 if (ret != LOS_OK) {
(gdb) n
79 ret = LosAppInit();
(gdb) n
80 if (ret != LOS_OK) {
(gdb) n
84 LOS_Start();
(gdb) n
同时第一控制台可以看到有TaskSample处于运行模式:
(py3_env) ➜ openHarmony ./qemu-run -g
board: arm_mps3_an547
Qemu kernel gdb enable...
Enter to start qemu[y/n]:y
entering kernel init...
Timer with period zero, disabling
Entering scheduler
OHOS # TaskSampleEntry1 running...
TaskSampleEntry2 running...
TaskSampleEntry1 running...
TaskSampleEntry2 running...
TaskSampleEntry1 running...
TaskSampleEntry2 running...
TaskSampleEntry1 running...
TaskSampleEntry2 running...
TaskSampleEntry1 running...
TaskSampleEntry2 running...
TaskSampleEntry1 running...
TaskSampleEntry2 running...
TaskSampleEntry1 running...
TaskSampleEntry2 running...
TaskSampleEntry1 running...
TaskSampleEntry2 running...
FAQ
error: function declaration isn’t a prototype
[OHOS ERROR] ../../../third_party/cmsis/CMSIS/Core/Include/mpu_armv8.h:193:26: error: function declaration isn't a prototype [-Werror=strict-prototypes]
[OHOS ERROR] 193 | __STATIC_INLINE uint32_t ARM_MPU_TYPE()
[OHOS ERROR] | ^~~~~~~~~~~~
[OHOS ERROR] cc1: all warnings being treated as errors
解决方法:
__STATIC_INLINE uint32_t ARM_MPU_TYPE()
改成
__STATIC_INLINE uint32_t ARM_MPU_TYPE(void)
显示将入参传入void
qemu-system-arm: command not found
解决方法:参考前面QEMU环境准备小结
ERROR: glib-2.56 gthread-2.0 is required to compile QEMU
sudo apt-get install libglib2.0-dev
arm-none-eabi-gdb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
arm-none-eabi-gdb: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
解决方法:
sudo apt install libncurses5
参考资料
-
https://gitee.com/openharmony/device_qemu/blob/HEAD/arm_mps3_an547/README_zh.md
-
https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/get-code/sourcecode-acquire.md
-
https://blog.51cto.com/u_16099344/7957441
-
hb报错参考: http://t.csdnimg.cn/f6DqG