• Home
Name Date Size #Lines LOC

..--

liteos_m/12-May-2024-8,4485,861

BUILD.gnD12-May-20241.6 KiB3230

README.mdD12-May-20243.5 KiB13286

README_zh.mdD12-May-20243.2 KiB12782

example.mdD12-May-20241.2 KiB4230

ohos.buildD12-May-2024174 1010

README.md

1### Qemu RISC-V virt HOWTO
2
3#### 1. Brief introduction
4`riscv32_virt/` subdirectory contains part of the OpenHarmony LiteOS demonstration support for Qemu risc-v virt Platform,
5here called *riscv32_virt*.
6RISC-V Virtual platform is a `qemu-system-riscv32` machine target that provides emulation
7for a generic, riscv-based board.
8
9Introduced functionality adds support for RISC-V (1 CPU with security extensions), 128MB memory virtual platform.
10
11Note: System memory size is hard-coded to 128MB.
12
13#### 2. Setting up environment
14
15[Setting up a development environment](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/Readme-EN.md)
16
17[Compiler install:gcc_riscv32](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/quickstart-pkg-3861-tool.md),
18Note: [Downloadable directly](https://repo.huaweicloud.com/harmonyos/compiler/gcc_riscv32/7.3.0/linux/gcc_riscv32-linux-7.3.0.tar.gz)
19
20#### 3. Code acquisition
21
22[Code acquisition](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/get-code/sourcecode-acquire.md)
23
24Note: One can use `repo` to fetch code in a straightforward manner.
25
26#### 4. Building from sources
27
28In the root directory of the obtained source code, run the following command:
29
30```
31hb set
32```
33
34Select `qemu_riscv_mini_system_demo` under **ohemu**.
35
36Run the following build command:
37
38```
39hb build
40```
41
42This will build `OHOS_Image` for Qemu RISC-V virt machine.
43
44After build is finished, the resulting image can be found in:
45```
46out/riscv32_virt/qemu_riscv_mini_system_demo/
47```
48
49#### 5. Running image in Qemu
50
51a) If not installed, please install `qemu-system-riscv32`
52For details, please refer to the HOWTO: [Qemu installation](https://gitee.com/openharmony/device_qemu/blob/HEAD/README.md)
53
54b) Run
55
56(1) qemu version < 5.0.0
57
58```
59cd device/qemu/riscv32_virt
60qemu-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"
61```
62
63(2). qemu version >= 5.0.0
64
65Run the `./qemu-run --help` command. The following information is displayed:
66
67```
68Usage: ./qemu-run [OPTION]...
69Run a OHOS image in qemu according to the options.
70
71    Options:
72
73    -e, --exec file_name     kernel exec file name
74    -n, --net-enable         enable net
75    -l, --local-desktop      no VNC
76    -g, --gdb                enable gdb for kernel
77    -t, --test               test mode, exclusive with -g
78    -h, --help               print help info
79
80    By default, the kernel exec file is: out/riscv32_virt/qemu_riscv_mini_system_demo/OHOS_Image,
81    and net will not be enabled, gpu enabled and waiting for VNC connection at port 5920.
82```
83By default, the network will not be automatically configured if no parameter is specified, and the default kernel exec file will be used.
84If you want to use other kernel exec file, please try `./qemu-run -e [file_name]` to change it.
85
86#### 6. gdb debug
87
88```
89cd device/qemu/riscv32_virt
90vim liteos_m/config.gni
91```
92
93In the modified `board_opt_flags` compiler options:
94
95```
96board_opt_flags = []
97```
98
99to:
100
101```
102board_opt_flags = [ "-g" ]
103```
104
105Save and exit, recompile under OHOS root directory:
106
107```
108hb build -f
109```
110
111In a window to enter the command:
112
113```
114./qemu-run -g
115```
116
117In another window to enter the command:
118
119```
120riscv32-unknown-elf-gdb out/riscv32_virt/qemu_riscv_mini_system_demo/OHOS_Image
121(gdb) target remote localhost:1234
122(gdb) b main
123```
124
125More GDB related debugging can refer to [GDB instruction manual](https://sourceware.org/gdb/current/onlinedocs/gdb).
126
127## 7. Example
128
129- [Transferring Files Using FAT Images](example.md#sectionfatfs)
130
131
132

README_zh.md

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