From e6ddbb76e75b61b74708b7608539ae253f159650 Mon Sep 17 00:00:00 2001 From: Berkus Decker Date: Mon, 8 Nov 2021 03:09:50 +0200 Subject: [PATCH] feat: Add zellij qemu runner with serial emulation --- Justfile | 5 +++++ emulation/.gitignore | 1 + emulation/instructions.txt | 12 ++++++++++ emulation/layout.zellij | 39 +++++++++++++++++++++++++++++++++ emulation/qemu_multi_uart.sh | 35 +++++++++++++++++++++++++++++ emulation/zellij-config.example | 5 +++++ nucleus/Makefile.toml | 15 +++++++++++++ 7 files changed, 112 insertions(+) create mode 100644 emulation/.gitignore create mode 100644 emulation/instructions.txt create mode 100644 emulation/layout.zellij create mode 100755 emulation/qemu_multi_uart.sh create mode 100644 emulation/zellij-config.example diff --git a/Justfile b/Justfile index 54be580..ebe0823 100644 --- a/Justfile +++ b/Justfile @@ -1,3 +1,8 @@ +zellij: + # Build and run kernel in QEMU with serial port emulation + cargo make zellij-config + zellij --layout-path emulation/layout.zellij + qemu: # Build and run kernel in QEMU cargo make qemu diff --git a/emulation/.gitignore b/emulation/.gitignore new file mode 100644 index 0000000..0382f27 --- /dev/null +++ b/emulation/.gitignore @@ -0,0 +1 @@ +zellij-config.sh diff --git a/emulation/instructions.txt b/emulation/instructions.txt new file mode 100644 index 0000000..c255c7d --- /dev/null +++ b/emulation/instructions.txt @@ -0,0 +1,12 @@ +######################################################### +# Welcome to the Raspi3 Emulation with # +# MiniUart and PL011UART # +# # +# # +# 1. Use the mouse to select different panes # +# and interact with the UARTS. # +# # +# 2. To quit the emulation: # +# 2.1 Select the pane in which QEMU runs (this one). # +# 2.2 CTRL-C to close qemu. # +######################################################### diff --git a/emulation/layout.zellij b/emulation/layout.zellij new file mode 100644 index 0000000..5fe4f4f --- /dev/null +++ b/emulation/layout.zellij @@ -0,0 +1,39 @@ +--- +template: + direction: Horizontal + parts: + - direction: Vertical + borderless: true + split_size: + Fixed: 1 + run: + plugin: + location: "zellij:tab-bar" + - direction: Vertical + body: true + +tabs: + - direction: Vertical + parts: + - direction: Horizontal + borderless: true + run: + command: + cmd: "bash" + args: ["-c", "bash emulation/qemu_multi_uart.sh"] + - direction: Horizontal + parts: + - direction: Vertical + split_size: + Percent: 30 + run: + command: + cmd: "bash" + args: ["-c", "clear; echo -e \"\\033]0;MiniUart\\007\"; bash /dev/ptmx FIRST=1"] + - direction: Vertical + split_size: + Percent: 70 + run: + command: + cmd: "bash" + args: ["-c", "clear; echo -e \"\\033]0;PL011 Uart\\007\"; bash /dev/ptmx SECOND=1"] diff --git a/emulation/qemu_multi_uart.sh b/emulation/qemu_multi_uart.sh new file mode 100755 index 0000000..ae14891 --- /dev/null +++ b/emulation/qemu_multi_uart.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# MIT License +# +# Copyright (c) 2018-2019 Berkus Decker +# Based on QEMU runner example by Andre Richter + +echo -e "\033]0;QEMU\007" + +clear +cat emulation/instructions.txt + +# Generated by `cargo make zellij-config` +source emulation/zellij-config.sh + +# Let the two other serials boot up +sleep 1 + +FIRST_TTY=$(ps a | grep -e [F]IRST | awk '{ print $2 }') +SECOND_TTY=$(ps a | grep -e [S]ECOND | awk '{ print $2 }') + +FIRST_PID=$(ps a | grep -e [F]IRST | awk '{ print $1 }') +SECOND_PID=$(ps a | grep -e [S]ECOND | awk '{ print $1 }') + +function cleanup() { + # Drop ptmx shells + kill $FIRST_PID + kill $SECOND_PID +} + +trap cleanup EXIT + +echo "=== Running QEMU with MiniUart ${FIRST_TTY} and PL011 Uart ${SECOND_TTY} ===" + +${QEMU} ${QEMU_OPTS} ${QEMU_RUNNER_OPTS} -dtb ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/targets/bcm2710-rpi-3-b-plus.dtb -kernel ${KERNEL_BIN} -serial /dev/tty${SECOND_TTY} -serial /dev/tty${FIRST_TTY} diff --git a/emulation/zellij-config.example b/emulation/zellij-config.example new file mode 100644 index 0000000..ce97df6 --- /dev/null +++ b/emulation/zellij-config.example @@ -0,0 +1,5 @@ +QEMU= +QEMU_OPTS= +QEMU_RUNNER_OPTS= +CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY= +KERNEL_BIN= diff --git a/nucleus/Makefile.toml b/nucleus/Makefile.toml index 02bb76c..d518354 100644 --- a/nucleus/Makefile.toml +++ b/nucleus/Makefile.toml @@ -65,6 +65,21 @@ dependencies = ["build-qemu", "kernel-binary"] extend = "qemu-runner" env = { "QEMU_RUNNER_OPTS" = "${QEMU_SERIAL_OPTS}" } +[tasks.zellij-config] +extend = "qemu-runner" +script_runner = "@duckscript" +env = { "ZELLIJ_CONFIG_FILE" = "../emulation/zellij-config.sh" } +script = [ +''' + writefile ${ZELLIJ_CONFIG_FILE} "QEMU=${QEMU}\n" + appendfile ${ZELLIJ_CONFIG_FILE} "QEMU_OPTS=\"${QEMU_OPTS}\"\n" + appendfile ${ZELLIJ_CONFIG_FILE} "QEMU_RUNNER_OPTS=${QEMU_RUNNER_OPTS}\n" + appendfile ${ZELLIJ_CONFIG_FILE} "CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY=${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}\n" + appendfile ${ZELLIJ_CONFIG_FILE} "KERNEL_BIN=${KERNEL_BIN}\n" +''' +] +install_crate = { crate_name = "zellij", binary = "zellij", test_arg = ["--help"] } + [tasks.qemu-gdb] extend = "qemu-runner" env = { "QEMU_RUNNER_OPTS" = "${QEMU_SERIAL_OPTS} ${QEMU_GDB_OPTS}" }