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
This commit is contained in:
Henrik Tjäder 2024-04-10 20:35:14 +02:00 committed by GitHub
parent 420ca51058
commit e4cc5fd17b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 153 additions and 3 deletions

View file

@ -15,6 +15,8 @@ env:
OLDOLDOLDSTABLE_VERSION: 0.4 OLDOLDOLDSTABLE_VERSION: 0.4
QEMU_VERSION: 8.2.0 QEMU_VERSION: 8.2.0
QEMU_URL: https://download.qemu.org/qemu-8.2.0.tar.xz QEMU_URL: https://download.qemu.org/qemu-8.2.0.tar.xz
QEMU_ESP: qemu_esp
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
jobs: jobs:
# Run cargo xtask format-check # Run cargo xtask format-check
@ -230,7 +232,7 @@ jobs:
run: | run: |
sudo apt update sudo apt update
sudo apt install -y qemu-system-arm qemu-system-riscv32 sudo apt install -y qemu-system-arm qemu-system-riscv32
sudo apt-get install git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ninja-build sudo apt install -y git libglib2.0-dev libfdt-dev libpixman-1-dev zlib1g-dev ninja-build
- if: ${{ steps.cache-qemu.outputs.cache-hit != 'true' }} - if: ${{ steps.cache-qemu.outputs.cache-hit != 'true' }}
name: Download QEMU name: Download QEMU
@ -250,7 +252,15 @@ jobs:
name: Build QEMU name: Build QEMU
run: | run: |
cd qemu-${{ env.QEMU_VERSION }} cd qemu-${{ env.QEMU_VERSION }}
make -j$(nproc) ninja -C build
- name: Download ESP32 QEMU
run: wget "${{ env.QEMU_ESP_URL }}" --output-document=${{ env.QEMU_ESP}}.tar.xz
- name: Extract ESP32 QEMU
run: |
mkdir -p qemu-${{ env.QEMU_VERSION }}/build/esp32
tar --strip-components=1 -xvJf ${{ env.QEMU_ESP }}.tar.xz -C qemu-${{ env.QEMU_VERSION }}/build/esp32 qemu
- name: Archive QEMU build - name: Archive QEMU build
run: | run: |
@ -386,6 +396,75 @@ jobs:
if: ${{ matrix.backend != 'riscv32-imc-clint' }} if: ${{ matrix.backend != 'riscv32-imc-clint' }}
run: cargo xtask --deny-warnings --platform hifive1 --backend ${{ matrix.backend }} qemu run: cargo xtask --deny-warnings --platform hifive1 --backend ${{ matrix.backend }} qemu
# Platform esp32c3: verify the example output with run-pass tests
testexamplesesp32c3:
name: QEMU run (esp32c3)
needs: buildqemu
runs-on: ubuntu-22.04
strategy:
matrix:
toolchain:
- stable
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install Rust ${{ matrix.toolchain }}
run: |
rustup set profile minimal
rustup override set ${{ matrix.toolchain }}
- name: Configure Rust target
run: |
rustup target add riscv32imac-unknown-none-elf
rustup target add riscv32imc-unknown-none-elf
- name: Add Rust component llvm-tools-preview
run: rustup component add llvm-tools-preview
- name: Install libudev espflash dependency
run: |
sudo apt update
sudo apt install -y libudev-dev
# Use precompiled binutils
- name: Install cargo-binutils
uses: taiki-e/install-action@v2
with:
tool: cargo-binutils
# Use precompiled if possible
- name: Install cargo-binutils
uses: taiki-e/install-action@v2
with:
tool: espflash
- name: Install esptool.py
run: pip install esptool
- name: Cache Dependencies
uses: Swatinem/rust-cache@v2
- name: Install QEMU to get dependencies
run: |
sudo apt update
sudo apt install -y qemu-system-riscv32
- name: Download built QEMU
uses: actions/download-artifact@v4
with:
name: qemu
- name: Extract ESP32 QEMU into local path
run: sudo tar --strip-components=1 -xf qemu.tar -C /usr/local/ esp32/
- name: Check which QEMU is used
run: |
which qemu-system-riscv32
- name: Run-pass tests
run: cargo xtask -vvv --platform esp32-c3 qemu
# Run test suite # Run test suite
tests: tests:
name: tests name: tests
@ -825,6 +904,7 @@ jobs:
- checkexamplesesp32c3 - checkexamplesesp32c3
- testexampleslm3s6965 - testexampleslm3s6965
- testexampleshifive1 - testexampleshifive1
- testexamplesesp32c3
- tests - tests
- docs - docs
- mdbook - mdbook

1
.gitignore vendored
View file

@ -9,3 +9,4 @@ book-target/
.DS_Store .DS_Store
.vscode/ .vscode/
qemu.log

View file

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

View file

@ -1,5 +1,9 @@
[target.riscv32imc-unknown-none-elf] [target.riscv32imc-unknown-none-elf]
runner = "espflash flash --monitor" # Real hardware
#runner = "espflash flash --monitor"
# QEMU emulator
runner = "./runner.sh"
[build] [build]
rustflags = [ rustflags = [

29
examples/esp32c3/runner.sh Executable file
View file

@ -0,0 +1,29 @@
#!/bin/bash
if [ $# -eq 0 ]
then
echo "No arguments supplied! Provide path to ELF as argument"
fi
outputfilenamecargo=$1
outputfilename="$outputfilenamecargo".bin
logfile=qemu.log
qemuexec=qemu-system-riscv32
# Building ESP32-C3 image
espflash save-image --chip esp32c3 --merge "$outputfilenamecargo" "$outputfilename" 1>&2
# Get stats
esptool.py image_info --version 2 "$outputfilename" 1>&2
# Run in QEMU
$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" &
# Let it run
sleep 3s
# Kill QEMU nicely by sending 'q' (quit) over tcp
echo q | nc -N 127.0.0.1 55555
cat "$logfile"