【鸿蒙】0x01-LiteOS-M基于Qemu Arm Cortex-m55运行


系列文章目录

【鸿蒙】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架构,1CPU16M内存。

提示: 系统内存硬编码为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

参考资料

  1. https://gitee.com/openharmony/device_qemu/blob/HEAD/arm_mps3_an547/README_zh.md

  2. https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/get-code/sourcecode-acquire.md

  3. https://blog.51cto.com/u_16099344/7957441

  4. hb报错参考: http://t.csdnimg.cn/f6DqG

鸿蒙编译qemu-arm-linux产品时,没有生成vendor.img可能是因为以下几个原因: 首先,鸿蒙系统在编译时需要进行多个步骤,其中包括生成各个分区(分区包括system、vendor、boot等)。编译时如果没有指定生成vendor分区的操作,就不会在编译完成后生成vendor.img。 其次,可能是在编译鸿蒙系统时选择了一些定制化的配置,导致vendor分区没有被包含在生成的镜像中。鸿蒙系统提供了一些定制化选项,可以根据具体需求选择生成的分区。 另外,如果在编译过程中出现了错误或警告,可能导致编译过程中断,进而无法生成完整的镜像文件,其中也包括vendor.img。 要解决这个问题,可以尝试以下方法: 1. 确认编译过程中是否选择了生成vendor分区的选项,如果没有,需要重新编译时指定生成vendor分区。 2. 检查编译过程中是否出现了错误或警告,并解决其中可能导致编译中断的问题,确保编译过程可以顺利完成。 3. 检查编译使用的鸿蒙源码是否完整,如果有缺失或损坏的文件可能会导致编译过程中断,无法生成完整的镜像文件。 总结来说,如果在编译鸿蒙系统时没有生成vendor.img,首先需要确认编译过程中是否选择了生成vendor分区的选项,并检查编译过程中是否出现了错误或警告。如果以上检查均无问题,可以尝试重新编译鸿蒙系统并确保使用完整的鸿蒙源码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值