Add gdb support
parent
803fb9aac8
commit
4aead8ff15
57
Dockerfile
57
Dockerfile
|
@ -1,37 +1,46 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
FROM ubuntu:kinetic
|
||||
ARG uid
|
||||
ARG gid
|
||||
ARG tag=2022.11.23
|
||||
CMD /bin/bash
|
||||
RUN apt-get update && apt-get install -y \
|
||||
autoconf \
|
||||
automake \
|
||||
autotools-dev \
|
||||
curl \
|
||||
python3 \
|
||||
libmpc-dev \
|
||||
libmpfr-dev \
|
||||
libgmp-dev \
|
||||
gawk \
|
||||
build-essential \
|
||||
bison \
|
||||
flex \
|
||||
texinfo \
|
||||
gperf \
|
||||
libtool \
|
||||
patchutils \
|
||||
bc \
|
||||
zlib1g-dev \
|
||||
libexpat-dev \
|
||||
git \
|
||||
meson
|
||||
autoconf \
|
||||
automake \
|
||||
autotools-dev \
|
||||
curl \
|
||||
python3 \
|
||||
libmpc-dev \
|
||||
libmpfr-dev \
|
||||
libgmp-dev \
|
||||
libncurses5-dev \
|
||||
gawk \
|
||||
build-essential \
|
||||
bison \
|
||||
flex \
|
||||
texinfo \
|
||||
gperf \
|
||||
libtool \
|
||||
patchutils \
|
||||
bc \
|
||||
zlib1g-dev \
|
||||
libexpat-dev \
|
||||
git \
|
||||
meson \
|
||||
nano
|
||||
|
||||
RUN git clone https://github.com/riscv-collab/riscv-gnu-toolchain /build-toolchain
|
||||
WORKDIR /build-toolchain
|
||||
RUN git clone https://github.com/riscv-collab/riscv-gnu-toolchain /build
|
||||
WORKDIR /build
|
||||
RUN git checkout ${tag}
|
||||
|
||||
# Patch the build to include the gdb TUI, this makes debugging inside docker
|
||||
# much nicer
|
||||
RUN sed -i.bak 's/--disable-gprof/--disable-gprof --enable-tui/' Makefile.in
|
||||
RUN ./configure --prefix=/usr/local \
|
||||
--with-arch=rv32gc --with-abi=ilp32d --with-abi=ilp32 && \
|
||||
make -j $(nproc) && \
|
||||
make install && \
|
||||
rm -rf /build-toolchain
|
||||
rm -rf /build
|
||||
|
||||
# groupadd will fail if the GID already exists, as is the case for macOS hosts
|
||||
# where "staff" is gid 20. That's ok. We just need the group to exist.
|
||||
|
|
30
Makefile
30
Makefile
|
@ -1,10 +1,11 @@
|
|||
.PHONY: \
|
||||
all \
|
||||
lall \
|
||||
wipe clean shell flash
|
||||
all gdb \
|
||||
lall lgdb \
|
||||
clean flash openocd shell wipe
|
||||
|
||||
DOCKER_IMAGE ?= riscv-ubuntu
|
||||
DOCKER_CMD ?= docker run --rm -it -v ${PWD}:/project ${DOCKER_IMAGE}
|
||||
DOCKER_CMD ?= docker run --rm -it -v ${PWD}:/project
|
||||
LOCALHOST ?= localhost
|
||||
|
||||
MESON_FILE := meson.build
|
||||
MESON_CROSS ?= meson_cross_riscv.txt
|
||||
|
@ -13,7 +14,7 @@ MESON_DIR ?= mbuild
|
|||
OPENOCD_DIR ?= $(dir $(shell command -v openocd))/..
|
||||
|
||||
all: .have_docker
|
||||
${DOCKER_CMD} make lall
|
||||
${DOCKER_CMD} ${DOCKER_IMAGE} make lall
|
||||
wipe: clean all
|
||||
|
||||
lall: ${MESON_DIR}
|
||||
|
@ -27,16 +28,31 @@ clean:
|
|||
rm .have_docker
|
||||
|
||||
shell: .have_docker
|
||||
${DOCKER_CMD} bash
|
||||
${DOCKER_CMD} ${DOCKER_IMAGE} bash
|
||||
|
||||
flash: all
|
||||
${OPENOCD_DIR}/bin/openocd \
|
||||
-s ${OPENOCD_DIR}/scripts \
|
||||
-f ./wch-riscv.cfg \
|
||||
-c init -c halt \
|
||||
-c "program $(shell readlink -f ${MESON_DIR}/firmware-for-makeflash.hex) verify reset" \
|
||||
-c "program $(shell readlink -f ${MESON_DIR}/firmware-for-make.hex) verify reset" \
|
||||
-c resume -c exit
|
||||
|
||||
openocd:
|
||||
${OPENOCD_DIR}/bin/openocd \
|
||||
-s ${OPENOCD_DIR}/scripts \
|
||||
-f ./wch-riscv.cfg \
|
||||
-c init
|
||||
|
||||
gdb: .have_docker
|
||||
${DOCKER_CMD} --add-host=host.docker.internal:host-gateway \
|
||||
-e COLUMNS=$(shell tput cols) -e LINES=$(shell tput lines) -e TERM \
|
||||
${DOCKER_IMAGE} make LOCALHOST=host.docker.internal lgdb
|
||||
|
||||
lgdb:
|
||||
cd ${MESON_DIR} && \
|
||||
riscv32-unknown-elf-gdb ./firmware-for-make.elf -ex "tar ext ${LOCALHOST}:3333"
|
||||
|
||||
.have_docker: Dockerfile
|
||||
docker build -t ${DOCKER_IMAGE} \
|
||||
--build-arg uid=$(shell id -u) --build-arg gid=$(shell id -g) \
|
||||
|
|
21
README.md
21
README.md
|
@ -30,6 +30,27 @@ Everything else is downloaded into the Docker container.
|
|||
`make flash` expects to find a WCH-compatible patched openocd on the system
|
||||
PATH. If yours lives elsewhere, define `OPENOCD_DIR` on the environment.
|
||||
|
||||
## Using gdb
|
||||
|
||||
The Docker container has gdb too. To debug, first launch openocd:
|
||||
|
||||
```
|
||||
make openocd
|
||||
```
|
||||
|
||||
Next, launch gdb:
|
||||
|
||||
```
|
||||
make gdb
|
||||
```
|
||||
|
||||
This make target will launch gdb inside Docker, routing openocd port 3333 from
|
||||
the container to the host, and automatically load the firmware file and connect
|
||||
to openocd.
|
||||
|
||||
As above, if you're not using Docker, `make lgdb` will launch gdb locally,
|
||||
also automatically loading the firmware and connecting.
|
||||
|
||||
## What's in here?
|
||||
|
||||
The directory tree contains:
|
||||
|
|
13
meson.build
13
meson.build
|
@ -88,12 +88,19 @@ main_hex = custom_target(
|
|||
build_by_default: true,
|
||||
)
|
||||
|
||||
# Copy the .hex to a generic name that `make flash` can find.
|
||||
# Copy files to generic names that make can find
|
||||
hex_for_make = custom_target(
|
||||
'firmware-for-makeflash.hex',
|
||||
'firmware-for-make.hex',
|
||||
command: ['cp', '@INPUT@', '@OUTPUT@'],
|
||||
input: main_hex,
|
||||
output: 'firmware-for-makeflash.hex',
|
||||
output: 'firmware-for-make.hex',
|
||||
build_by_default: true,
|
||||
)
|
||||
elf_for_make = custom_target(
|
||||
'firmware-for-make.elf',
|
||||
command: ['cp', '@INPUT@', '@OUTPUT@'],
|
||||
input: main,
|
||||
output: 'firmware-for-make.elf',
|
||||
build_by_default: true,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue