Skip to content

Commit e4cc5fd

Browse files
authored
CI: Add ESP32-C3 QEMU support (#914)
* CI: ESP32-C3: QEMU support * CI: ESP32C3: Script for preparing and running * CI: gitignore qemu.log * ESP32-C3: Example sw_and_hw output
1 parent 420ca51 commit e4cc5fd

File tree

5 files changed

+153
-3
lines changed

5 files changed

+153
-3
lines changed

.github/workflows/build.yml

+82-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ env:
1515
OLDOLDOLDSTABLE_VERSION: 0.4
1616
QEMU_VERSION: 8.2.0
1717
QEMU_URL: https://download.qemu.org/qemu-8.2.0.tar.xz
18+
QEMU_ESP: qemu_esp
19+
QEMU_ESP_URL: https://github.com/espressif/qemu/releases/download/esp-develop-8.2.0-20240122/qemu-riscv32-softmmu-esp_develop_8.2.0_20240122-x86_64-linux-gnu.tar.xz
1820

1921
jobs:
2022
# Run cargo xtask format-check
@@ -230,7 +232,7 @@ jobs:
230232
run: |
231233
sudo apt update
232234
sudo apt install -y qemu-system-arm qemu-system-riscv32
233-
sudo apt-get install git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ninja-build
235+
sudo apt install -y git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ninja-build
234236
235237
- if: ${{ steps.cache-qemu.outputs.cache-hit != 'true' }}
236238
name: Download QEMU
@@ -250,8 +252,16 @@ jobs:
250252
name: Build QEMU
251253
run: |
252254
cd qemu-${{ env.QEMU_VERSION }}
253-
make -j$(nproc)
255+
ninja -C build
254256
257+
- name: Download ESP32 QEMU
258+
run: wget "${{ env.QEMU_ESP_URL }}" --output-document=${{ env.QEMU_ESP}}.tar.xz
259+
260+
- name: Extract ESP32 QEMU
261+
run: |
262+
mkdir -p qemu-${{ env.QEMU_VERSION }}/build/esp32
263+
tar --strip-components=1 -xvJf ${{ env.QEMU_ESP }}.tar.xz -C qemu-${{ env.QEMU_VERSION }}/build/esp32 qemu
264+
255265
- name: Archive QEMU build
256266
run: |
257267
cd qemu-${{ env.QEMU_VERSION }}/build
@@ -386,6 +396,75 @@ jobs:
386396
if: ${{ matrix.backend != 'riscv32-imc-clint' }}
387397
run: cargo xtask --deny-warnings --platform hifive1 --backend ${{ matrix.backend }} qemu
388398

399+
# Platform esp32c3: verify the example output with run-pass tests
400+
testexamplesesp32c3:
401+
name: QEMU run (esp32c3)
402+
needs: buildqemu
403+
runs-on: ubuntu-22.04
404+
strategy:
405+
matrix:
406+
toolchain:
407+
- stable
408+
steps:
409+
- name: Checkout
410+
uses: actions/checkout@v4
411+
412+
- name: Install Rust ${{ matrix.toolchain }}
413+
run: |
414+
rustup set profile minimal
415+
rustup override set ${{ matrix.toolchain }}
416+
417+
- name: Configure Rust target
418+
run: |
419+
rustup target add riscv32imac-unknown-none-elf
420+
rustup target add riscv32imc-unknown-none-elf
421+
422+
- name: Add Rust component llvm-tools-preview
423+
run: rustup component add llvm-tools-preview
424+
425+
- name: Install libudev espflash dependency
426+
run: |
427+
sudo apt update
428+
sudo apt install -y libudev-dev
429+
430+
# Use precompiled binutils
431+
- name: Install cargo-binutils
432+
uses: taiki-e/install-action@v2
433+
with:
434+
tool: cargo-binutils
435+
436+
# Use precompiled if possible
437+
- name: Install cargo-binutils
438+
uses: taiki-e/install-action@v2
439+
with:
440+
tool: espflash
441+
442+
- name: Install esptool.py
443+
run: pip install esptool
444+
445+
- name: Cache Dependencies
446+
uses: Swatinem/rust-cache@v2
447+
448+
- name: Install QEMU to get dependencies
449+
run: |
450+
sudo apt update
451+
sudo apt install -y qemu-system-riscv32
452+
453+
- name: Download built QEMU
454+
uses: actions/download-artifact@v4
455+
with:
456+
name: qemu
457+
458+
- name: Extract ESP32 QEMU into local path
459+
run: sudo tar --strip-components=1 -xf qemu.tar -C /usr/local/ esp32/
460+
461+
- name: Check which QEMU is used
462+
run: |
463+
which qemu-system-riscv32
464+
465+
- name: Run-pass tests
466+
run: cargo xtask -vvv --platform esp32-c3 qemu
467+
389468
# Run test suite
390469
tests:
391470
name: tests
@@ -825,6 +904,7 @@ jobs:
825904
- checkexamplesesp32c3
826905
- testexampleslm3s6965
827906
- testexampleshifive1
907+
- testexamplesesp32c3
828908
- tests
829909
- docs
830910
- mdbook

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ book-target/
99

1010
.DS_Store
1111
.vscode/
12+
qemu.log

ci/expected/esp32c3/sw_and_hw.run

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
QEMU 8.2.0 monitor - type 'help' for more information
2+
(qemu) q
3+
ESP-ROM:esp32c3-api1-20210207
4+
Build:Feb 7 2021
5+
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
6+
SPIWP:0xee
7+
mode:DIO, clock div:2
8+
load:0x3fcd5820,len:0x1714
9+
load:0x403cc710,len:0x968
10+
load:0x403ce710,len:0x2f9c
11+
entry 0x403cc710
12+
I (0) boot: ESP-IDF v5.1.2-342-gbcf1645e44 2nd stage bootloader
13+
I (0) boot: compile time Dec 12 2023 10:50:58
14+
I (0) boot: chip revision: v0.3
15+
I (0) boot.esp32c3: SPI Speed : 40MHz
16+
I (0) boot.esp32c3: SPI Mode : SLOW READ
17+
I (0) boot.esp32c3: SPI Flash Size : 4MB
18+
I (0) boot: Enabling RNG early entropy source...
19+
I (1) boot: Partition Table:
20+
I (1) boot: ## Label Usage Type ST Offset Length
21+
I (1) boot: 0 nvs WiFi data 01 02 00009000 00006000
22+
I (1) boot: 1 phy_init RF data 01 01 0000f000 00001000
23+
I (1) boot: 2 factory factory app 00 00 00010000 003f0000
24+
I (1) boot: End of partition table
25+
I (1) esp_image: segment 0: paddr=00010020 vaddr=3c010020 size=022e4h ( 8932) map
26+
I (3) esp_image: segment 1: paddr=0001230c vaddr=40380000 size=01250h ( 4688) load
27+
I (3) esp_image: segment 2: paddr=00013564 vaddr=00000000 size=0cab4h ( 51892) 
28+
I (8) esp_image: segment 3: paddr=00020020 vaddr=42000020 size=05db4h ( 23988) map
29+
I (11) boot: Loaded app from partition at offset 0x10000
30+
I (11) boot: Disabling RNG early entropy source...
31+
init
32+
Inside high prio task, press button now!
33+
Leaving high prio task.
34+
idle
35+
Inside low prio task, press button now!
36+
Leaving low prio task.

examples/esp32c3/.cargo/config.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
[target.riscv32imc-unknown-none-elf]
2-
runner = "espflash flash --monitor"
2+
# Real hardware
3+
#runner = "espflash flash --monitor"
4+
5+
# QEMU emulator
6+
runner = "./runner.sh"
37

48
[build]
59
rustflags = [

examples/esp32c3/runner.sh

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
if [ $# -eq 0 ]
4+
then
5+
echo "No arguments supplied! Provide path to ELF as argument"
6+
fi
7+
8+
outputfilenamecargo=$1
9+
outputfilename="$outputfilenamecargo".bin
10+
11+
logfile=qemu.log
12+
13+
qemuexec=qemu-system-riscv32
14+
15+
# Building ESP32-C3 image
16+
espflash save-image --chip esp32c3 --merge "$outputfilenamecargo" "$outputfilename" 1>&2
17+
18+
# Get stats
19+
esptool.py image_info --version 2 "$outputfilename" 1>&2
20+
21+
# Run in QEMU
22+
$qemuexec -nographic -monitor tcp:127.0.0.1:55555,server,nowait -icount 3 -machine esp32c3 -drive file="$outputfilename",if=mtd,format=raw -serial file:"$logfile" &
23+
24+
# Let it run
25+
sleep 3s
26+
27+
# Kill QEMU nicely by sending 'q' (quit) over tcp
28+
echo q | nc -N 127.0.0.1 55555
29+
cat "$logfile"

0 commit comments

Comments
 (0)