• Home
Name Date Size #Lines LOC

..--

board/12-May-2024-1,233739

drivers/12-May-2024-4136

hdf_config/12-May-2024-348335

BUILD.gnD12-May-20241.8 KiB4441

README.mdD12-May-20247.9 KiB210139

README_zh.mdD12-May-20247 KiB214141

config.gniD12-May-20241.8 KiB6248

example.mdD12-May-20247.9 KiB290221

README.md

1# QEMU Arm Virt Tutorial - liteos_a
2
3## 1. Overview
4
5The `arm_virt/` directory contains code that has been verified on the QEMU Arm Virt platform for adapting to OpenHarmony kernel\_liteos\_a. The code includes the driver and board configurations.
6
7The Arm Virt platform is a `qemu-system-arm` target device that simulates a general-purpose board running on the Arm architecture.
8The board whose **machine** is **virt** in QEMU is configurable. For example, you can select the core type and quantity, memory size, and security extensions when configuring the board.
9
10This tutorial guides you through the configuration of a board based on the Cortex-A7 architecture, with one CPU, extended secure features, Generic Interrupt Controller versions 2 (GICv2), and 1 GB memory.
11The system memory is hardcoded to 64 MB.
12
13## 2. Setting Up the Environment
14
15For details, see [Environment Setup](https://gitee.com/openharmony/docs/blob/master/en/device-dev/quick-start/Readme-EN.md).
16
17## 3. Obtaining the Source Code
18
19For details, see [Source Code Acquisition](https://gitee.com/openharmony/docs/blob/HEAD/en/device-dev/get-code/sourcecode-acquire.md).
20
21## 4. Building the Source Code
22
23In the root directory of the obtained source code, run the following command:
24
25```
26hb set
27```
28
29Select `qemu_small_system_demo` under **ohemu**.
30
31Run the following build command:
32
33```
34hb build
35```
36
37After this command is executed, the result files are generated in out/arm_virt/qemu_small_system_demo/ directory.
38
39## 5. Running an Image in QEMU
40
41a) If `qemu-system-arm` has not been installed, install it. For details, see [Qemu Installation](https://gitee.com/openharmony/device_qemu/blob/HEAD/README.md).
42
43Note: The introduced functions have been tested on the target machine of virt-5.1, but are not available for all QEMU versions. Therefore, you must ensure that the qemu-system-arm version is 5.1 or later.
44
45b) Create and run an image.
46
47After the source code is built, the **qemu-run** script is generated in the root directory of the code. You can run the script to create and run an image as prompted.
48
49Run `./qemu-run --help` to get help.
50
51Simulated network interface is wireless card wlan0, but has no real wifi functions. By default, the network will not be automatically configured if no parameter is specified.
52
53If the image file **out/smallmmc.img** exists, the image will not be re-created by default. MMC image mainly for rootfs and userfs. The 1st partition is rootfs, 2nd is userfs and mounted at /userdata, 3rd is for user data and mounted at /userdata.
54
55c) Exit QEMU.
56
57Press `Ctrl-A + x` to exit the QEMU virtual environment.
58
59## 6. gdb debug
60
61Install `gdb-multiarch` package:
62```
63sudo apt install gdb-multiarch
64```
65Then,
66```
67cd ohos/vendor/ohemu/qemu_small_system_demo/kernel_configs
68vim debug.config
69```
70
71Modify `LOSCFG_CC_STACKPROTECTOR_ALL=y` to:
72
73```
74# LOSCFG_CC_STACKPROTECTOR_ALL is not set
75LOSCFG_COMPILE_DEBUG=y
76```
77
78Save and exit, recompile under OHOS root directory:
79
80```
81hb build -f
82```
83
84In a window to enter the command:
85
86```
87./qemu-run -g
88```
89
90In another window to enter the command:
91
92```
93gdb-multiarch out/arm_virt/qemu_small_system_demo/OHOS_Image
94(gdb) target remote localhost:1234
95```
96
97More GDB related debugging can refer to [GDB instruction manual](https://sourceware.org/gdb/current/onlinedocs/gdb).
98
99## 7. Example
100
101- [Transferring Parameters to the Kernel](example.md#sectiondebug)
102
103- [Transferring Files Using MMC Images](example.md#sectionfatfs)
104
105- [Adding a Hello World Program](example.md#addhelloworld)
106
107- [Running the Graphic Demo](example.md#simple_ui_demo)
108
109- [Observe dsoftbus Discovery](example.md#dsoftbus_discover)
110
111- [Hack A Sample Desktop](example.md#desktop)
112
113## FAQ:
1141. How do I locate a network configuration problem?
115
116   Manually configure a host network bridge. For Linux, run the following commands:
117
118   ```
119   sudo modprobe tun tap
120   sudo ip link add br0 type bridge
121   sudo ip address add 10.0.2.2/24 dev br0
122   sudo ip link set dev br0 up
123
124   # The following commands can be commented out after being executed:
125   sudo mkdir -p /etc/qemu
126   echo 'allow br0' | sudo tee -a /etc/qemu/bridge.conf
127   ```
128
129   Run the **ip addr** command to check the configuration. If **br0** does not exist or the value in the angle brackets is **DOWN**, check the configuration commands again.
130
131   ```
132   5: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
133       link/ether 2e:52:52:0e:21:44 brd ff:ff:ff:ff:ff:ff
134       inet 10.0.2.2/24 scope global br0
135          valid_lft forever preferred_lft forever
136   ```
137
138   If software such as Docker has been installed in the system, the system firewall may prevent the bridge from accessing the system. Run the following command:
139
140   `cat /proc/sys/net/bridge/bridge-nf-call-iptables`
141
142   **1** is displayed. Run the following command to allow the access from the network bridge:
143
144   ```
145   echo 0 | sudo tee /proc/sys/net/bridge/bridge-nf-call-iptables
146   ```
147
148   Note: The system is hardcoded to **10.0.2.0/24** for the sub-network, **10.0.2.2** for the gateway, and random IP address. Use different MAC addresses, IP addresses, and flash, MMC images for different client instances. The MAC address can be transferred using the QEMU command line. The IP address can be adjusted in the OHOS command line, for example, using `ifconfig wlan0 inet 10.0.2.30` or other methods.
149
1502. How do I troubleshoot the error when running `qemu-system-arm`?
151
152   The commands and parameters in the **qemu-run** script are as follows:
153
154   ```
155   qemu-system-arm -M virt,gic-version=2,secure=on -cpu cortex-a7 -smp cpus=1 -m 1G \
156        -bios out/arm_virt/qemu_small_system_demo/OHOS_Image.bin \
157        -drive if=none,file=out/smallmmc.img,format=raw,id=mmc
158        -device virtio-blk-device,drive=mmc \
159        -netdev bridge,id=net0 \
160        -device virtio-net-device,netdev=net0,mac=12:22:33:44:55:66 \
161        -device virtio-gpu-device,xres=960,yres=480 \
162        -device virtio-tablet-device \
163        -device virtio-rng-device \
164        -vnc :20 \
165        -s -S \
166        -global virtio-mmio.force-legacy=false
167   ```
168
169   ```
170   -M                           Virtual machine type, ARM virt, GICv2, and extended security features
171   -cpu                         CPU model
172   -smp                         SMP setting, single core
173   -m                           Maximum memory size that can be used by the virtual machines
174   -drive if=none               Block device image setting
175   -netdev                      [optional] NIC bridge type
176   -device virtio-blk-device    Block device
177   -device virtio-net-device    [optional] NIC device
178   -device virtio-gpu-device    GPU device
179   -device virtio-tablet-device Input device
180   -device virtio-rng-device    Random generator device
181   -vnc: 20                     [recommend] Remote desktop connection, port 5920
182   -s -S                        [optional] gdb single step debug
183   -global                      QEMU configuration parameter, which cannot be changed
184   ```
185
186   If the error message "failed to parse default acl file" is displayed when **qemu-run** is executed:
187
188   The error may be caused by the QEMU configuration file path, which varies with the QEMU installation mode. The default QEMU configuration file path is:
189
190   - **/usr/local/qemu/etc/qemu** if QEMU is installed from the source code.
191
192   - **/ect/qemu/** if QEMU is installed by using a Linux distribution installation tool.
193
194   Determine the configuration file path and run the following command:
195
196   ```
197   echo 'allow br0' | sudo tee -a <Configuration file path>
198   ```
199
200
2013. What do I do if there is no output after QEMU of LTS 1.1.0 is executed?
202
203   The LTS code has a kernel startup defect. You can try to resolve the problem by referring to the following:
204
205   https://gitee.com/openharmony/kernel_liteos_a/pulls/324
206
207
2084. VNC window has no cursor?
209
210   Virtio-tablet is an emulated tablet input device. Neither QEMU captures nor the virtual machine displays it. The cursor is displayed by VNC client. Please check VNC client options.

README_zh.md

1# Qemu ARM Virt 教程 - liteos_a
2
3## 1. 简介
4
5`arm_virt/` 子目录包含部分Qemu ARM虚拟化平台验证的OpenHarmony kernel\_liteos\_a的适配代码,含驱动配置、板端配置等。
6
7ARM 虚拟化平台是一个 `qemu-system-arm` 的目标设备,通过它来模拟一个通用的、基于ARM架构的单板。
8Qemu中machine为 **virt** 的单板就是这种可配置的,例如:选择核的类型、核的个数、内存的大小和安全特性等,单板设备的配置。
9
10这次模拟的配置是:Cortex-A7架构,1个CPU,带安全扩展,GICv2,1G内存。
11提示: 系统内存硬编码为64MB。
12
13## 2. 环境搭建
14
15参考链接: [环境搭建](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/porting/Readme-CN.md)
16
17## 3. 获取源码
18
19参考链接: [代码获取](https://gitee.com/openharmony/docs/blob/HEAD/zh-cn/device-dev/get-code/sourcecode-acquire.md)
20
21## 4. 源码构建
22
23在已经获取的源码根目录,请输入:
24
25```
26hb set
27```
28
29选择ohemu下的`qemu_small_system_demo`选项。
30
31
32然后执行构建命令如下:
33
34```
35hb build
36```
37
38在构建完成之后,对应的结果文件在out/arm_virt/qemu_small_system_demo/目录。
39
40
41## 5. 在Qemu中运行镜像
42
43a) 如果没有安装 `qemu-system-arm` ,安装请参考链接 [Qemu installation](https://gitee.com/openharmony/device_qemu/blob/HEAD/README_zh.md)
44
45提示:当前引入的功能在virt-5.1的目标machine已经完成测试,不保证所有的Qemu版本都能够运行成功,因此需要保证你的qemu-system-arm
46版本尽可能在5.1及以上。
47
48b) 制作以及运行镜像
49
50在代码根目录下,编译后会生成qemu-run脚本,可直接运行该脚本,根据脚本提示制作、运行镜像。
51
52执行`./qemu-run --help`获取帮助。
53
54网卡模拟的是无线网卡wlan0,但无真的wifi功能;默认不加参数的情况下,网络不会自动配置。
55
56当镜像文件out/smallmmc.img存在时,默认不会被重新制作。MMC镜像主要内容为rootfs和userfs,第1个分区为rootfs,第2个分区为userfs,安装在/storage目录,第3个分区为用户数据,安装在/userdata目录。
57
58c) 退出qemu环境
59
60按下`Ctrl-A + x`可退出qemu虚拟环境。
61
62## 6. gdb调试
63
64安装`gdb-multiarch`工具包:
65```
66sudo apt install gdb-multiarch
67```
68然后,
69```
70cd ohos/vendor/ohemu/qemu_small_system_demo/kernel_configs
71vim debug.config
72```
73
74将 `LOSCFG_CC_STACKPROTECTOR_ALL=y` 修改为:
75
76```
77# LOSCFG_CC_STACKPROTECTOR_ALL is not set
78LOSCFG_COMPILE_DEBUG=y
79```
80
81保存并退出,在OHOS根目录重新编译:
82
83```
84hb build -f
85```
86
87在一个窗口中输入命令:
88
89```
90./qemu-run -g
91```
92
93在另一个窗口中输入命令:
94
95```
96gdb-multiarch out/arm_virt/qemu_small_system_demo/OHOS_Image
97(gdb) target remote localhost:1234
98```
99
100更多gdb相关的调试可以查阅:[gdb指导手册](https://sourceware.org/gdb/current/onlinedocs/gdb)101
102## 7. 用法示例
103
104- [向内核传递参数](example.md#sectiondebug)
105
106- [用MMC映像传递文件](example.md#sectionfatfs)
107
108- [添加一个Hello World程序](example.md#addhelloworld)
109
110- [运行图形demo](example.md#simple_ui_demo)
111
112- [观察dsoftbus组网发现](example.md#dsoftbus_discover)
113
114- [Hack图形桌面](example.md#desktop)
115
116## FAQ:
1171. 当网络配置出现问题时,如何排查问题?
118
119   手动配置主机网桥设备。Linux系统参考以下命令:
120
121   ```
122   sudo modprobe tun tap
123   sudo ip link add br0 type bridge
124   sudo ip address add 10.0.2.2/24 dev br0
125   sudo ip link set dev br0 up
126
127   # 以下命令执行一次后即可注释掉
128   sudo mkdir -p /etc/qemu
129   echo 'allow br0' | sudo tee -a /etc/qemu/bridge.conf
130   ```
131
132   配置完成后,用ip addr检查应有如下类似显示。当br0不存在或尖括号中为DOWN时,请重新检查配置命令。
133
134   ```
135   5: br0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
136       link/ether 2e:52:52:0e:21:44 brd ff:ff:ff:ff:ff:ff
137       inet 10.0.2.2/24 scope global br0
138          valid_lft forever preferred_lft forever
139   ```
140
141   当系统安装有docker等软件时,系统防火墙可能阻止网桥访问。
142
143   `cat /proc/sys/net/bridge/bridge-nf-call-iptables`会显示结果:1
144
145   这时,可用如下命令打开访问许可:
146
147   ```
148   echo 0 | sudo tee /proc/sys/net/bridge/bridge-nf-call-iptables
149   ```
150
151   提示:系统网络硬编码为10.0.2.0/24,网关10.0.2.2,网址随机选取。不同的客户机实例应使用不同的MAC和IP地址(flash、MMC映像文件也应不同),MAC地址可通过QEMU命令行传递,IP地址可在OHOS命令行中调整,如`ifconfig wlan0 inet 10.0.2.30`,或使用其它方法。
152
1532. qemu-run提示`qemu-system-arm`运行出错时,如何排查问题?
154
155   qemu-run脚本中,完整的执行命令及参数解释如下:
156
157   ```
158   qemu-system-arm -M virt,gic-version=2,secure=on -cpu cortex-a7 -smp cpus=1 -m 1G \
159        -bios out/arm_virt/qemu_small_system_demo/OHOS_Image.bin \
160        -drive if=none,file=out/smallmmc.img,format=raw,id=mmc
161        -device virtio-blk-device,drive=mmc \
162        -netdev bridge,id=net0 \
163        -device virtio-net-device,netdev=net0,mac=12:22:33:44:55:66 \
164        -device virtio-gpu-device,xres=960,yres=480 \
165        -device virtio-tablet-device \
166        -device virtio-rng-device \
167        -vnc :20 \
168        -s -S \
169        -global virtio-mmio.force-legacy=false
170   ```
171
172   ```
173   -M                           虚拟机类型,ARM virt,GIC 2中断控制器,有安全扩展
174   -cpu                         CPU型号
175   -smp                         SMP设置,单核
176   -m                           虚拟机可使用的内存限制
177   -bios                        内核启动映像
178   -drive if=none               块设备映像文件设置
179   -netdev                      [可选]网卡后端设置,桥接类型
180   -device virtio-blk-device    块存储设备
181   -device virtio-net-device    [可选]网卡设备
182   -device virtio-gpu-device    GPU设备
183   -device virtio-tablet-device 输入设备
184   -device virtio-rng-device    随机数设备
185   -vnc :20                     [推荐]远程桌面连接,端口5920
186   -s -S                        [可选]gdb单步调试
187   -global                      QEMU配置参数,不可调整
188   ```
189
190   运行时,qemu-run遇到报错如下报错: failed to parse default acl file
191
192   可能是qemu安装方式不同,导致qemu配置文件路径存在一定差异:
193
194   - 使用源码安装默认在/usr/local/qemu/etc/qemu
195
196   - 使用部分Linux发行版安装工具进行安装时,默认在/ect/qemu/目录下
197
198   可根据实际情况,确认具体配置目录,并进行如下修改:
199
200   ```
201   echo 'allow br0' | sudo tee -a <配置文件路径>
202   ```
203
204
2053. 1.1.0LTS版本qemu运行无输出?
206
207   LTS的代码存在一个内核启动缺陷,可以参考如下PR尝试解决问题:
208
209   https://gitee.com/openharmony/kernel_liteos_a/pulls/324
210
211
2124. VNC窗口不显示光标?
213
214   virtio-tablet是个模拟平板输入的设备,QEMU不捕获设备,虚拟机不显示光标,由VNC客户端自行处理光标显示。请查看VNC客户端选项设置。