• Home
Name Date Size #Lines LOC

..--

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

liteos_m/12-May-2024-1,480884

BUILD.gnD12-May-2024609 1614

README.mdD12-May-20245.4 KiB153100

README_zh.mdD12-May-20244.7 KiB153100

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      Tip: Users can also skip this step by using the following instructions directly to use the compiler configured in the default environment.
18
19      To use the default environment, execute '3.Get source code' and then install the default compiler in the root directory by executing the following instructions.
20
21         ```shell
22         sh build/prebuilts_download.sh
23         ```
24
25      Optional compiler installation process:
26
27      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
28
29      b) Put the downloaded SDK package into the Linux system, go to the directory, and run the following commands:
30
31         ```shell
32         unzip esp-idf-v4.3.1.zip
33         cd esp-idf-v4.3.1/
34         ./install.sh
35         . ./export.sh
36         ```
37
38      c) Delete the default compiler path:
39
40         change esp32\liteos_m\config.gni:
41
42         ```c
43         board_toolchain_path = "$ohos_root_path/prebuilts/gcc/linux-x86/esp/esp-2019r2-8.2.0/xtensa-esp32-elf/bin/"
44         ```
45
46         to
47
48         ```c
49         board_toolchain_path = ""
50         ```
51
52      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).
53
54   2. Install esptool
55
56      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.
57         ```shell
58         esptool.py version
59         ```
60      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)
61         ```shell
62         python -m pip install esptool
63         ```
64
65   3. Compile qemu-system-xtensa
66
67      a) Install and compile
68
69         ```shell
70         git clone https://github.com/espressif/qemu.git
71         cd qemu
72         ./configure --target-list=xtensa-softmmu \
73            --enable-gcrypt \
74            --enable-debug --enable-sanitizers \
75            --disable-strip --disable-user \
76            --disable-capstone --disable-vnc \
77            --disable-sdl --disable-gtk
78         ```
79
80      b) Waitting 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):
81
82         ```shell
83         ninja -C build
84         ```
85
86      c) Add qemu to the environment variable (modify user_qemu_xxx_path to your own installation path):
87
88         ```shell
89         vim ~/.bashrc
90         export QEMU=user_qemu_xxx_path/qemu/build
91         source ~/.bashrc
92         ```
93
94      d) Installation dependencies
95
96         ```shell
97         ldd $QEMU/qemu-system-xtensa
98         ```
99
100         According to the execution result of ldd, install the missing dependent libraries
101
102         (Annotation: For more installation instructions, please refer to the following link: [Home · espressif/qemu Wiki · GitHub](https://github.com/espressif/qemu/wiki#configure))
103
104## 3.Get source code
105
106[code acquisition ](https://gitee.com/openharmony/docs/blob/master/en/device-dev/get-code/sourcecode-acquire.md)
107
108Hint : You can use the `repo` command to get the source code.
109
110## 4.Source buildding
111
112   1. Execute the hb set command and select the project `qemu_xtensa_mini_system_demo`.
113
114   2. Execute the hb clean && hb build command to build the executable file that produces `OHOS_Image`.
115
116      ```shell
117      hb set
118      hb clean && hb build
119      ```
120
121   3. After the buildding is complete, the corresponding executable file is in the home directory:
122
123      ```
124      out/esp32/qemu_xtensa_mini_system_demo/
125      ```
126
127## 5.Run the image in Qemu
128
129   1. Run qemu(Don't cooperate with GDB )
130
131      ```shell
132      ./qemu-run
133      ```
134
135   2. Run qemu(Cooperate with GDB)
136
137      a) Start the GDB server and wait for the connection
138
139         ```shell
140         ./qemu-run -g
141         ```
142
143      b) Create a new terminal and use GDB to connect to qemu
144
145         ```shell
146         xtensa-esp32-elf-gdb out/esp32/qemu_xtensa_mini_system_demo/OHOS_Image -ex "target remote :1234"
147         ```
148
149   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.
150   Annotation:The way to exit qemu : press ctrl and a, then release and press x.
151
152(Annotation:For more operating instructions, please refer to:[Home · espressif/qemu Wiki · GitHub](https://github.com/espressif/qemu/wiki#configure))
153

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