• Home
Name
Date
Size
#Lines
LOC

..--

adapter/hals/utils/file/12-May-2024-10058

liteos_m/12-May-2024-1,477881

BUILD.gnD12-May-2024609 1614

README.mdD12-May-20244.8 KiB13387

README_zh.mdD12-May-20244.2 KiB13387

ohos.buildD12-May-2024146 1010

README.md

1# QEMU(Tutorials of ESP32)
2
3## 1.Introduction
4
5QEMU can simulate the kernel to run on different boards ,eliminate dependence on physical development boards. The esp32 subdirectory contains part of the OpenHarmony kernel\_liteos\_m code verified by the Qemu esp32 virtualization platform, it can be used to simulate a single-core esp32 single board.
6
7## 2.Setup Environment
8
9   1. Install esp-idf
10
11      Please refer to the installation instructions: (https://docs.espressif.com/projects/esp-idf/en/release-v4.1/get-started/index.html)
12
13      Annotation: The installation of esp-idf can be skipped. The bootloader.bin and partition-table.bin generated have been placed in the vendor\ohemu\qemu_xtensa_mini_system_demo\image folder.
14
15      Annotation: If you skip the installation of esp-idf, you can install the toolchain as follows:
16
17      Note: [Downloadable directly](https://repo.huaweicloud.com/openharmony/compiler/gcc_esp/2019r2-8.2.0/linux/esp-2019r2-8.2.0.zip)
18
19      Optional compiler installation process:
20
21      a) Download the esp official release the SDK package: https://www.espressif.com/zh-hans/support/download/sdks-demos?keys=&field_type_tid%5B%5D=13
22
23      b) Put the downloaded SDK package into the Linux system, go to the directory, and run the following commands:
24
25         ```shell
26         unzip esp-idf-v4.3.1.zip
27         cd esp-idf-v4.3.1/
28         ./install.sh
29         . ./export.sh
30         ```
31
32      Annotation: The version of the toolchain used in the test is GCC Version 8.2.0 (Crosstool-ng ESP-2019R2) or GCC Version 8.4.0 (Crosstool-ng ESP-2021R1).
33
34   2. Install esptool
35
36      a) In step 1, the export.sh script will set the esptool in the environment path, you need to ensure that the esptool version is 3.1 and above.
37         ```shell
38         esptool.py version
39         ```
40      b) If the version of the esptool that comes with esp-idf is too low, delete the environment variable corresponding to the current esptool path and run the following commands. (The recommended python version is 3.8 and above)
41         ```shell
42         python -m pip install esptool
43         ```
44
45   3. Compile qemu-system-xtensa
46
47      a) Install and compile
48
49         ```shell
50         git clone https://github.com/espressif/qemu.git
51         cd qemu
52         ./configure --target-list=xtensa-softmmu \
53            --enable-gcrypt \
54            --enable-debug --enable-sanitizers \
55            --disable-strip --disable-user \
56            --disable-capstone --disable-vnc \
57            --disable-sdl --disable-gtk
58         ```
59
60      b) Waiting for the completion of the compilation and executing the installation command (If the compilation fail, please refer to https://github.com/espressif/qemu/issues/21):
61
62         ```shell
63         ninja -C build
64         ```
65
66      c) Add qemu to the environment variable (modify user_qemu_xxx_path to your own installation path):
67
68         ```shell
69         vim ~/.bashrc
70         export QEMU=user_qemu_xxx_path/qemu/build
71         source ~/.bashrc
72         ```
73
74      d) Installation dependencies
75
76         ```shell
77         ldd $QEMU/qemu-system-xtensa
78         ```
79
80         According to the execution result of ldd, install the missing dependent libraries
81
82         (Annotation: For more installation instructions, please refer to the following link: [Home · espressif/qemu Wiki · GitHub](https://github.com/espressif/qemu/wiki#configure))
83
84## 3.Get source code
85
86[code acquisition ](https://gitee.com/openharmony/docs/blob/master/en/device-dev/get-code/sourcecode-acquire.md)
87
88Hint : You can use the `repo` command to get the source code.
89
90## 4.Source building
91
92   1. Execute the hb set command and select the project `qemu_xtensa_mini_system_demo`.
93
94   2. Execute the hb clean && hb build command to build the executable file that produces `OHOS_Image`.
95
96      ```shell
97      hb set
98      hb clean && hb build
99      ```
100
101   3. After the building is complete, the corresponding executable file is in the home directory:
102
103      ```
104      out/esp32/qemu_xtensa_mini_system_demo/
105      ```
106
107## 5.Run the image in Qemu
108
109   1. Run qemu(Don't cooperate with GDB )
110
111      ```shell
112      ./qemu-run
113      ```
114
115   2. Run qemu(Cooperate with GDB)
116
117      a) Start the GDB server and wait for the connection
118
119         ```shell
120         ./qemu-run -g
121         ```
122
123      b) Create a new terminal and use GDB to connect to qemu
124
125         ```shell
126         xtensa-esp32-elf-gdb out/esp32/qemu_xtensa_mini_system_demo/OHOS_Image -ex "target remote :1234"
127         ```
128
129   Annotation:Since the qemu-system-xtensa tool of qemu has the same name as the qemu-system-xtensa tool of esp32, the absolute path is used to execute the qemu-system-xtensa tool of esp32.
130   Annotation:The way to exit qemu : press ctrl and a, then release and press x.
131
132(Annotation:For more operating instructions, please refer to:[Home · espressif/qemu Wiki · GitHub](https://github.com/espressif/qemu/wiki#configure))
133

README_zh.md

1# QEMU(ESP32 教程)
2
3## 1.简介
4
5QEMU可以模拟内核运行在不同的单板,解除对物理开发板的依赖。esp32子目录包含部分Qemu esp32虚拟化平台验证的OpenHarmony kernel\_liteos\_m的代码,它可以用来模拟单核esp32单板。
6
7## 2.环境搭建
8
9   1. esp-idf安装
10
11      使用安装指导请参考:(https://docs.espressif.com/projects/esp-idf/zh_CN/release-v4.1/get-started/index.html)
12
13      注:esp-idf安装可以跳过,当前已将生成好的bootloader.binpartition-table.bin放入vendor\ohemu\qemu_xtensa_mini_system_demo\image文件夹中。
14
15      注:若跳过安装esp-idf可以按照下列方式安装工具链:
16
17      提示:[可直接下载](https://repo.huaweicloud.com/openharmony/compiler/gcc_esp/2019r2-8.2.0/linux/esp-2019r2-8.2.0.zip)
18
19      可选的编译器安装流程:
20
21      a) 下载官方release的SDK包:https://www.espressif.com/zh-hans/support/download/sdks-demos?keys=&field_type_tid%5B%5D=13
22
23      b) 将下载好的SDK包放入linux系统,进入目录执行如下指令:
24
25         ```shell
26         unzip esp-idf-v4.3.1.zip
27         cd esp-idf-v4.3.1/
28         ./install.sh
29         . ./export.sh
30         ```
31
32      注:本教程使用的工具链版本为gcc version 8.2.0 (crosstool-NG esp-2019r2)或gcc version 8.4.0 (crosstool-NG esp-2021r1)
33
34   2. esptool安装
35
36      a) 步骤1中export.sh脚本会设置esptool工具路径,需要确保esptool工具版本为3.1及以上。
37         ```shell
38         esptool.py version
39         ```
40      b) 如果esp-idf自带esptool工具版本过低,需删除当前esptool路径对应的环境变量,并执行以下命令。(python版本建议为3.8及以上)
41         ```shell
42         python -m pip install esptool
43         ```
44
45   3. qemu-system-xtensa编译
46
47      a) 编译安装
48
49         ```shell
50         git clone https://github.com/espressif/qemu.git
51         cd qemu
52         ./configure --target-list=xtensa-softmmu \
53            --enable-gcrypt \
54            --enable-debug --enable-sanitizers \
55            --disable-strip --disable-user \
56            --disable-capstone --disable-vnc \
57            --disable-sdl --disable-gtk
58         ```
59
60      b) 等待编译结束,执行安装命令(如果编译失败请参考https://github.com/espressif/qemu/issues/21):
61
62         ```shell
63         ninja -C build
64         ```
65
66      c) 将qemu添加到环境变量中(user_qemu_xxx_path修改为自己的安装路径):
67
68         ```shell
69         vim ~/.bashrc
70         export QEMU=user_qemu_xxx_path/qemu/build
71         source ~/.bashrc
72         ```
73
74      d) 安装依赖
75
76         ```shell
77         ldd $QEMU/qemu-system-xtensa
78         ```
79
80         根据ldd执行结果,安装缺少的依赖库
81
82         (注:更多安装指导,请参考链接:[Home · espressif/qemu Wiki · GitHub](https://github.com/espressif/qemu/wiki#configure))
83
84## 3.获取源码
85
86[代码获取](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/get-code/sourcecode-acquire.md)
87
88提示: 可以使用 `repo` 命令来获取源码。
89
90## 4.源码构建
91
92   1. 执行hb set命令并选择项目`qemu_xtensa_mini_system_demo`。
93
94   2. 执行hb clean && hb build命令构建产生 `OHOS_Image` 的可执行文件。
95
96      ```shell
97      hb set
98      hb clean && hb build
99      ```
100
101   3. 在构建完成之后,对应的可执行文件在主目录下:
102
103      ```
104      out/esp32/qemu_xtensa_mini_system_demo/
105      ```
106
107## 5.在Qemu中运行镜像
108
109   1. 运行qemu(不配合GDB)
110
111      ```shell
112      ./qemu-run
113      ```
114
115   2. 启动qemu(配合GDB)
116
117      a) 启动GDB服务器,等待连接
118
119         ```shell
120         ./qemu-run -g
121         ```
122
123      b) 新建终端并使用GDB连接qemu
124
125         ```shell
126         xtensa-esp32-elf-gdb out/esp32/qemu_xtensa_mini_system_demo/OHOS_Image -ex "target remote :1234"
127         ```
128
129   注:由于默认安装的qemu自带qemu-system-xtensa工具与当前安装的qemu-system-xtensa工具重名,因此采用绝对路径执行当前的qemu-system-xtensa工具。
130   注:qemu退出方式为:按下ctrl加a键,然后松开再按下x键。
131
132(注:更多操作指导,请参考:[Home · espressif/qemu Wiki · GitHub](https://github.com/espressif/qemu/wiki#configure))
133