• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Qemu RISC-V virt 教程
2
3## 1. 简介
4`riscv32_virt/` 子目录包含部分Qemu RISC-V虚拟化平台验证的OpenHarmony kernel\_liteos\_m的代码,目录名为*riscv32_virt*。
5RISC-V 虚拟化平台是一个 `qemu-system-riscv32` 的目标设备,通过它来模拟一个通用的、基于RISC-V架构的单板。
6
7这次模拟的配置是:RISC-V架构,1个CPU,128M内存。
8
9提示: 系统内存硬编码为128MB。
10
11## 2. 环境搭建
12
13[环境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/porting/Readme-CN.md)
14
15[编译器安装:gcc_riscv32](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-pkg-3861-tool.md),
16提示: [可直接下载](https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz)
17
18## 3. 获取源码
19
20[代码获取](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/get-code/sourcecode-acquire.md)
21
22提示: 可以使用 `repo` 命令来获取源码。
23
24## 4. 源码构建
25
26在已经获取的源码根目录,请输入:
27
28```
29hb set
30```
31
32选择ohemu下的`qemu_riscv_mini_system_demo`选项。
33
34
35然后执行构建命令如下:
36
37```
38hb build
39```
40
41这个命令构建会产生 `OHOS_Image` 的镜像文件。
42
43在构建完成之后,对应的镜像文件在如下目录:
44```
45out/riscv32_virt/qemu_riscv_mini_system_demo/
46```
47
48## 5. 在Qemu中运行镜像
49
50a) 如果没有安装 `qemu-system-riscv32` ,安装请参考链接:[Qemu安装指导](https://gitee.com/openharmony/device_qemu/blob/HEAD/README_zh.md)
51
52b) 运行
53
54(1). qemu 版本 < 5.0.0
55
56```
57cd device/qemu/riscv32_virt
58qemu-system-riscv32 -machine virt -m 128M -kernel ../../../out/riscv32_virt/qemu_riscv_mini_system_demo/OHOS_Image -nographic -append "root=dev/vda or console=ttyS0"
59```
60
61(2). qemu 版本 >= 5.0.0
62
63执行`./qemu-run --help`提示如下:
64
65```
66Usage: qemu-run [OPTION]...
67Run a OHOS image in qemu according to the options.
68
69    Options:
70
71    -e, --exec file_name     kernel exec file name
72    -n, --net-enable         enable net
73    -l, --local-desktop      no VNC
74    -g, --gdb                enable gdb for kernel
75    -t, --test               test mode, exclusive with -g
76    -h, --help               print help info
77
78    By default, the kernel exec file is: out/riscv32_virt/qemu_riscv_mini_system_demo/OHOS_Image,
79    and net will not be enabled, gpu enabled and waiting for VNC connection at port 5920.
80```
81默认不加参数的情况下,网络不会自动配置,并使用默认镜像文件,若需更改默认镜像文件,可以利用 `./qemu-run -e [file_name]` 指定
82
83## 6. gdb调试
84
85```
86cd device/qemu/riscv32_virt
87vim liteos_m/config.gni
88```
89
90将 `board_opt_flags` 中的
91
92```
93board_opt_flags = []
94```
95
96编译选项修改为:
97
98```
99board_opt_flags = [ "-g" ]
100```
101
102保存并退出,在OHOS根目录重新编译:
103
104```
105hb build -f
106```
107
108在一个窗口中输入命令:
109
110```
111./qemu-run -g
112```
113
114在另一个窗口中输入命令:
115
116```
117riscv32-unknown-elf-gdb out/riscv32_virt/qemu_riscv_mini_system_demo/OHOS_Image
118(gdb) target remote localhost:1234
119(gdb) b main
120```
121
122更多gdb相关的调试可以查阅:[gdb指导手册](https://sourceware.org/gdb/current/onlinedocs/gdb)123
124## 7. 用法示例
125
126- [用FAT映像传递文件](example.md#sectionfatfs)
127