Add openocd/gdb targets to makefile

Refactor build system scripts a bit.
This commit is contained in:
Berkus Decker 2020-11-03 03:25:01 +02:00
parent 2a4eb20131
commit d38661b63f
4 changed files with 96 additions and 22 deletions

View File

@ -22,3 +22,11 @@ alias disasm := hopper
hopper:
cargo make hopper
alias ocd := openocd
openocd:
cargo make openocd
gdb:
cargo make gdb

View File

@ -8,9 +8,33 @@ min_version = "0.32.0"
default_to_workspace = true
[env]
DEFAULT_TARGET = "aarch64-vesper-metta"
#
# === User-configurable ===
#
# Pass TARGET env var if it does not match the default target above.
TARGET = { value = "${DEFAULT_TARGET}", condition = { env_not_set = ["TARGET"] } }
# AArch64 QEMU binary
QEMU = { value = "qemu-system-aarch64", condition = { env_not_set = ["QEMU"] } }
# An aarch64-enabled GDB
GDB = { value = "/usr/local/opt/gdb-8.2.1-aarhc64/bin/aarch64-linux-elf-gdb", condition = { env_not_set = ["GDB"] } }
# OpenOCD with JLink support and RTT patch from http://openocd.zylin.com/#/c/4055/11
OPENOCD = { value = "/usr/local/openocd-aeb7b327-rtt/bin/openocd", condition = { env_not_set = ["OPENOCD"] } }
# Mounted sdcard partition path
VOLUME = { value = "/Volumes/BOOT", condition = { env_not_set = ["VOLUME"] } }
#
# === Automatic ===
#
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
DEFAULT_TARGET = "aarch64-vesper-metta"
TARGET_JSON = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/targets/${TARGET}.json"
BUILD_STD = "-Zbuild-std=core,compiler_builtins,alloc"
@ -19,6 +43,7 @@ QEMU_FEATURES = "qemu"
OBJCOPY = "rust-objcopy" # Part of `cargo objcopy` in cargo-binutils
OBJCOPY_PARAMS = "--strip-all -O binary"
NM = "rust-nm" # Part of `cargo nm` in cargo-binutils
UTILS_CONTAINER = "andrerichter/raspi3-utils"
DOCKER_CMD = "docker run -it --rm -v ${PWD}:/work -w /work -p 5900:5900"
@ -31,13 +56,10 @@ QEMU_CONTAINER_CMD = "qemu-system-aarch64"
QEMU_OPTS = "-M raspi3 -d int -semihosting"
QEMU_SERIAL_OPTS = "-serial null -serial stdio"
QEMU_TESTS_OPTS = "-nographic"
QEMU = "qemu-system-aarch64"
# For gdb connection:
# - if setting this, MUST have gdb attached for SYS_WRITE0 to work, otherwise QEMU will crash.
QEMU_GDB_OPTS = "-gdb tcp::3333 -S"
TARGET_JSON = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/targets/${DEFAULT_TARGET}.json"
# - if this is set, MUST have gdb attached for SYS_WRITE0 to work, otherwise QEMU will crash.
# - port 5555 used to match JLink configuration, so we can reuse the same GDB command for both QEMU and JTAG.
QEMU_GDB_OPTS = "-gdb tcp::5555 -S"
KERNEL_ELF = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/kernel8"
KERNEL_BIN = "${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/kernel8.img"

View File

@ -32,8 +32,14 @@ Vesper has been influenced by the kernels in L4 family, notably seL4. Fawn and N
Use at least rustc nightly 2020-07-15 with cargo nightly of the same or later date. It adds support for `cargo build --build-std` feature.
Install tools: `cargo install just cargo-make`.
Install qemu (at least version 4.1.1): `brew install qemu`.
* Install tools: `cargo install just cargo-make`.
* Install qemu (at least version 4.1.1): `brew install qemu`.
* Optionally install OpenOCD with [RTT patches](http://openocd.zylin.com/#/c/4055/11).
* Install aarch64 gdb.
You can override invoked `qemu`, `openocd` and `gdb` by specifying full paths to them as env variables `QEMU`, `OPENOCD` and `GDB`, respectively.
You can override the name of mounted sdcard volume by specifying env variable `VOLUME` (it defaults to `/Volumes/BOOT`).
### To build kernel and run it in QEMU emulator
@ -41,18 +47,12 @@ Install qemu (at least version 4.1.1): `brew install qemu`.
just qemu
```
### To build kernel for Raspberry Pi and copy it to SDCard mounted at `/Volumes/BOOT/`
### To build kernel for Raspberry Pi and copy it to the mounted SDCard
```
just device
```
### To run tests (tests require QEMU)
```
just test
```
On the device boot SD card you'll need a configuration file instructing RasPi to launch in 64-bit mode.
```
@ -60,6 +60,26 @@ On the device boot SD card you'll need a configuration file instructing RasPi to
arm_64bit=1
```
### To run tests (tests require QEMU)
```
just test
```
### To launch JTAG connected JLink probe
```
just ocd
```
### To launch GDB and load kernel binary into it
```
just gdb
```
If you launch OpenOCD or QEMU before, then gdb shall connect to it and allow you to load the kernel binary directly into memory. Type `load` in gdb to do that.
### To see kernel disassembly
You need to have [Hopper](https://hopperapp.com) and hopperv4 cli helper installed.

View File

@ -16,8 +16,8 @@ args = ["test", "${BUILD_STD}", "--target=${TARGET_JSON}", "--features=${TARGET_
script_runner = "@duckscript"
script = [
'''
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/${DEFAULT_TARGET}/release/vesper ${KERNEL_ELF}
exec --fail-on-error ${OBJCOPY} %{OBJCOPY_PARAMS} ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/${DEFAULT_TARGET}/release/vesper ${KERNEL_BIN}
cp ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/${TARGET}/release/vesper ${KERNEL_ELF}
exec --fail-on-error ${OBJCOPY} %{OBJCOPY_PARAMS} ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/${TARGET}/release/vesper ${KERNEL_BIN}
'''
]
@ -57,15 +57,39 @@ script = [
'''
]
[tasks.openocd]
dependencies = ["build", "kernel-binary"]
script = [
"${OPENOCD} -f interface/jlink.cfg -f ../doc/rpi2rpi_jtag/rpi3_target.cfg"
]
[tasks.gdb]
dependencies = ["build", "kernel-binary"]
env = { "RUST_GDB" = "${GDB}" }
script_runner = "@duckscript"
script = [
'''
connectFile = set ${CARGO_MAKE_WORKSPACE_WORKING_DIRECTORY}/target/${TARGET}/gdb-connect
writefile ${connectFile} "target remote :5555\n"
exec --fail-on-error rust-gdb -x ${connectFile} ${KERNEL_ELF}
'''
]
[tasks.sdcard]
dependencies = ["build", "kernel-binary"]
command = "cp"
args = ["${KERNEL_BIN}", "/Volumes/BOOT/"]
script_runner = "@duckscript"
script = [
'''
kernelImage = basename ${KERNEL_BIN}
cp ${KERNEL_BIN} ${VOLUME}/${kernelImage}
'''
]
[tasks.sdeject]
dependencies = ["sdcard"]
command = "diskutil"
args = ["unmount", "/Volumes/BOOT/"]
script = [
"diskutil unmount ${VOLUME}"
]
[tasks.clippy]
env = { "TARGET_FEATURES" = { value = "--features=${CLIPPY_FEATURES}", condition = { env_set = ["CLIPPY_FEATURES"] } } }