Skip to main content

QEMU RPI GPIO

Simulate GPIO in qemu-based Raspberry Pi

How it works

The script (qemu-rpi-gpio) present in this repository interacts with qemu using the built-in qtest protocol.

Wrapping the protocol and interacting with the memory of the guest operating system, it can set or reset the various GPIOs.

Note: Vanilla qemu (5.1.93) will not handle GPIO interrupts, therefore loading /sys/class/gpio/gpio$N/direction and waiting for an interrupt will not do anything.

To enable interrupt support you'll need to download and compile this qemu fork.

Installation

You can install the script via pip with

pip install qemu-rpi-gpio

Prereqisites

You need socat, python3 and pexpect library to use this script.

These can be installed under ubuntu with:

sudo apt install python3-pexpect socat

To download raspbian images you'll need 7zip

sudo apt install p7zip-full

Setup

Download a raspbian image using

./qemu-pi-setup/setup.sh

After this operation, execute the script to load the unix socket and make it available to qemu

./qemu-rpi-gpio

You will be prompted to an interactive shell, you can find the commands available in the Interacting with gpios section.

In another terminal execute the ./qemu-pi-setup/run.sh script, this will execute a virtual raspberry pi and attach it to the gpio application.

If you close the raspberry pi you can reload the socket using the command reload in the qemu-rpi-gpio prompt.

Interacting with gpios

First of all, you need to export GPIOs in your guest Linux. In a shell on your raspberry pi do:

$ sudo su -
# echo 4 >/sys/class/gpio/export
# echo in >/sys/class/gpio/direction

The main commands in the qemu-rpi-gpio application are:

command description example
get $N get the value of GPIO $N get 4
set $N $V set the value of GPIO $N to $V (1 or 0) set 4 1

You can get the full list of commands using help

For instance, let us set the value of the pre-exported gpio 4

(gpio)> set 4 1

Now you can read the value of your gpio

# cat /sys/class/gpio/value
1

If we set it to zero, it will be immediately reflected in the guest system

(gpio)> set 4 0
# cat /sys/class/gpio/value
0

Metadata

Release files for qemu-rpi-gpio 0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for qemu-rpi-gpio 0.4
File Interpreter ABI Platform Actions
qemu_rpi_gpio-0.4-py3-none-any.whl Python 3 none any Details for qemu_rpi_gpio-0.4-py3-none-any.whl

Release files / qemu_rpi_gpio-0.4-py3-none-any.whl

Download URL qemu_rpi_gpio-0.4-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
07a28bc75a44cd2c51f8ef6f24d21b6eb90692cb6b5d752adaf67891372e5037
BLAKE2b-256 checksum
How to use checksums
21344cb8af5776f9a3dcd948a5ea1eea0d54117d9f7efad2532d24cf430942bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Security for qemu-rpi-gpio 0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.4 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page